[patch] consolidate libbb's pwd helpers [was: Re: warnings in libbb.h]

Bernhard Fischer rep.nop at aon.at
Sat Sep 17 21:54:35 UTC 2005


On Sat, Sep 17, 2005 at 10:38:02PM +0200, Tito wrote:
>On Saturday 17 September 2005 22:11, Bernhard Fischer wrote:
>> 
>> Do you think that get_ug_id() should be moved to libbb/bb_pwd.c too? (I
>> wouldn't rename it but just move it there)
>I think it is a good idea to have them all in one place!!!

ACK. Incremental patch is attached.

Full patch is temporarily also saved here:
http://members.aon.at/berny_f/busybox/busybox.consolidate-bb_pwd-utils.02all.diff.bz2

Oh, and applets/applets.c::parse_config_file() says:
/* We can't use get_ug_id here since it would exit()
 * if a uid or gid was not found.  Oh well... */
{ /* hand-crafted bb_xgetpwnam(name,0) */

Do you think that providing a second arg to the x functions would be
worthwhile which indicate if exiting is desired or not?
Something along the lines of
extern long bb_xgetpwnam(const char *name, int x_on_failure);
and obviously if (x_on_failure && mygroup==NULL)

If so, would you be so kind and provide a follow-up incremental patch on
these? TIA.

Tested. Please apply,
Bernhard
-------------- next part --------------
diff -X excl -rduNp busybox.oorig/include/libbb.h busybox/include/libbb.h
--- busybox.oorig/include/libbb.h	2005-09-17 22:04:59.000000000 +0200
+++ busybox/include/libbb.h	2005-09-17 23:31:12.000000000 +0200
@@ -472,7 +472,7 @@ extern void print_login_prompt(void);
 extern void vfork_daemon_rexec(int nochdir, int noclose,
 		int argc, char **argv, char *foreground_opt);
 extern int get_terminal_width_height(int fd, int *width, int *height);
-extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *));
+extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
 
 #define HASH_SHA1	1
 #define HASH_MD5	2
diff -X excl -rduNp busybox.oorig/libbb/bb_pwd.c busybox/libbb/bb_pwd.c
--- busybox.oorig/libbb/bb_pwd.c	2005-09-17 21:52:57.000000000 +0200
+++ busybox/libbb/bb_pwd.c	2005-09-17 23:14:20.000000000 +0200
@@ -148,6 +148,26 @@ char * bb_getug(char *buffer, char *idna
 }
 #endif /* L_bb_getug */
 
+
+#ifdef L_get_ug_id
+/* indirect dispatcher for pwd helpers.  */
+#include <stdlib.h>
+
+extern unsigned long get_ug_id(const char *s,
+		long (*__bb_getxxnam)(const char *))
+{
+	unsigned long r;
+	char *p;
+
+	r = strtoul(s, &p, 10);
+	if (*p || (s == p)) {
+		r = __bb_getxxnam(s);
+	}
+
+	return r;
+}
+#endif /* L_get_ug_id */
+
 /* END CODE */
 /*
 Local Variables:
@@ -156,3 +176,4 @@ c-basic-offset: 4
 tab-width: 4
 End:
 */
+
diff -X excl -rduNp busybox.oorig/libbb/get_ug_id.c busybox/libbb/get_ug_id.c
--- busybox.oorig/libbb/get_ug_id.c	2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/get_ug_id.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,30 +0,0 @@
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <stdlib.h>
-
-extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *))
-{
-	unsigned long r;
-	char *p;
-
-	r = strtoul(s, &p, 10);
-	if (*p || (s == p)) {
-		r = my_getxxnam(s);
-	}
-
-	return r;
-}
diff -X excl -rduNp busybox.oorig/libbb/Makefile.in busybox/libbb/Makefile.in
--- busybox.oorig/libbb/Makefile.in	2005-09-17 21:47:27.000000000 +0200
+++ busybox/libbb/Makefile.in	2005-09-17 23:15:05.000000000 +0200
@@ -28,7 +28,7 @@ LIBBB_SRC:= \
 	correct_password.c create_icmp_socket.c create_icmp6_socket.c \
 	device_open.c dump.c error_msg.c error_msg_and_die.c find_mount_point.c \
 	find_pid_by_name.c find_root_device.c fgets_str.c full_read.c \
-	full_write.c get_last_path_component.c get_line_from_file.c get_ug_id.c \
+	full_write.c get_last_path_component.c get_line_from_file.c \
 	hash_fd.c herror_msg.c herror_msg_and_die.c \
 	human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \
 	kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \
@@ -76,7 +76,7 @@ LIBBB_MOBJ4:=safe_strtoi.o safe_strtod.o
 
 LIBBB_MSRC5:=$(srcdir)/bb_pwd.c
 LIBBB_MOBJ5:=bb_xgetpwnam.o bb_xgetgrnam.o bb_getgrgid.o bb_getpwuid.o \
-	bb_getug.o
+	bb_getug.o get_ug_id.o
 
 LIBBB_MOBJS0=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ0))
 LIBBB_MOBJS1=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ1))


More information about the busybox mailing list