[patch] consolidate libbb's pwd helpers [was: Re: warnings in libbb.h]
Bernhard Fischer
rep.nop at aon.at
Sat Sep 17 20:11:26 UTC 2005
On Mon, Sep 12, 2005 at 01:51:04PM +0200, Tito wrote:
>On Monday 12 September 2005 10:31, Bernhard Fischer wrote:
>> On Sun, Sep 11, 2005 at 08:37:43PM -0500, Rob Landley wrote:
>> >On Sunday 11 September 2005 16:15, Bernhard Fischer wrote:
>
>> >> //#warning change names?
>> >> my_getpwnam, my_getgrnam, my_getug, my_getpwuid, my_getgrgid
>> >>
>> >> I'd rename them to bb_*(), fwiw.
>> >
>> >bb_xgetgrnam() seems more likely for the first one, since the x generally
>> >seems to mean "die if this isn't found"...
>> >
>> >Tito was the last guy to play with these. :)
>>
>> Tito, would you look into renaming them or do you prefer me to look into
>> making a patch for this?
>Hi,
>
>my_getpwnam() -> bb_xgetpwnam() /* dies on error */
>my_getgrnam() -> bb_xgetgrnam() /* dies on error */
>my_getgrgid() -> bb_getgrgid
>my_getpwuid() -> bb_getpwuid
>my_getug() -> bb_getug() /* used only by my_getgrgid and my_getpwuid so far */
>
>maybe something like this, but it is just a hint so feel free to change it.
>Just try to differentiate somehow the two that always die on error and
>go for the patch. :-)
Attached does exactly this; thanks for the hint :)
archival/rpm.c | 4 -
archival/tar.c | 4 -
coreutils/chgrp.c | 2
coreutils/chown.c | 4 -
coreutils/id.c | 16 ++--
coreutils/install.c | 4 -
coreutils/ls.c | 4 -
coreutils/whoami.c | 2
debianutils/start_stop_daemon.c | 2
include/libbb.h | 14 +--
libbb/Makefile.in | 16 ++--
libbb/bb_pwd.c | 158 ++++++++++++++++++++++++++++++++++++++++
libbb/my_getgrgid.c | 57 --------------
libbb/my_getgrnam.c | 49 ------------
libbb/my_getpwnam.c | 49 ------------
libbb/my_getpwuid.c | 56 --------------
libbb/my_getug.c | 64 ----------------
libbb/procps.c | 2
loginutils/adduser.c | 2
loginutils/passwd.c | 2
miscutils/makedevs.c | 4 -
networking/httpd.c | 2
sysklogd/logger.c | 2
23 files changed, 203 insertions(+), 316 deletions(-)
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)
Tested. Please apply,
Bernhard
-------------- next part --------------
diff -X excl -rduNp busybox.oorig/archival/rpm.c busybox/archival/rpm.c
--- busybox.oorig/archival/rpm.c 2005-08-17 01:36:31.000000000 +0200
+++ busybox/archival/rpm.c 2005-09-17 21:39:35.000000000 +0200
@@ -331,8 +331,8 @@ void fileaction_dobackup(char *filename,
void fileaction_setowngrp(char *filename, int fileref)
{
int uid, gid;
- uid = my_getpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
- gid = my_getgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
+ uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
+ gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
chown (filename, uid, gid);
}
diff -X excl -rduNp busybox.oorig/archival/tar.c busybox/archival/tar.c
--- busybox.oorig/archival/tar.c 2005-09-05 21:44:14.000000000 +0200
+++ busybox/archival/tar.c 2005-09-17 21:39:35.000000000 +0200
@@ -234,9 +234,9 @@ static inline int writeTarHeader(struct
TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */
- if (my_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL)
+ if (bb_getpwuid(header.uname, statbuf->st_uid, sizeof(header.uname)) == NULL)
strcpy(header.uname, "root");
- if (my_getgrgid(header.gname, statbuf->st_gid, sizeof(header.gname)) == NULL)
+ if (bb_getgrgid(header.gname, statbuf->st_gid, sizeof(header.gname)) == NULL)
strcpy(header.gname, "root");
if (tbInfo->hlInfo) {
diff -X excl -rduNp busybox.oorig/coreutils/chgrp.c busybox/coreutils/chgrp.c
--- busybox.oorig/coreutils/chgrp.c 2005-04-01 22:05:44.000000000 +0200
+++ busybox/coreutils/chgrp.c 2005-09-17 21:39:35.000000000 +0200
@@ -58,7 +58,7 @@ int chgrp_main(int argc, char **argv)
argv += optind;
/* Find the selected group */
- gid = get_ug_id(*argv, my_getgrnam);
+ gid = get_ug_id(*argv, bb_xgetgrnam);
++argv;
/* Ok, ready to do the deed now */
diff -X excl -rduNp busybox.oorig/coreutils/chown.c busybox/coreutils/chown.c
--- busybox.oorig/coreutils/chown.c 2005-04-01 22:05:44.000000000 +0200
+++ busybox/coreutils/chown.c 2005-09-17 21:39:35.000000000 +0200
@@ -77,11 +77,11 @@ int chown_main(int argc, char **argv)
gid = -1;
if (groupName) {
*groupName++ = '\0';
- gid = get_ug_id(groupName, my_getgrnam);
+ gid = get_ug_id(groupName, bb_xgetgrnam);
}
/* Now check for the username */
- uid = get_ug_id(*argv, my_getpwnam);
+ uid = get_ug_id(*argv, bb_xgetpwnam);
++argv;
diff -X excl -rduNp busybox.oorig/coreutils/id.c busybox/coreutils/id.c
--- busybox.oorig/coreutils/id.c 2005-09-05 21:44:17.000000000 +0200
+++ busybox/coreutils/id.c 2005-09-17 21:39:35.000000000 +0200
@@ -80,8 +80,8 @@ extern int id_main(int argc, char **argv
if(argv[optind]) {
p=getpwnam(argv[optind]);
- /* my_getpwnam is needed because it exits on failure */
- uid = my_getpwnam(argv[optind]);
+ /* bb_xgetpwnam is needed because it exits on failure */
+ uid = bb_xgetpwnam(argv[optind]);
gid = p->pw_gid;
/* in this case PRINT_REAL is the same */
}
@@ -89,8 +89,8 @@ extern int id_main(int argc, char **argv
if(flags & (JUST_GROUP | JUST_USER)) {
/* JUST_GROUP and JUST_USER are mutually exclusive */
if(flags & NAME_NOT_NUMBER) {
- /* my_getpwuid and my_getgrgid exit on failure so puts cannot segfault */
- puts((flags & JUST_USER) ? my_getpwuid(NULL, uid, -1 ) : my_getgrgid(NULL, gid, -1 ));
+ /* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */
+ puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 ));
} else {
bb_printf("%u\n",(flags & JUST_USER) ? uid : gid);
}
@@ -99,11 +99,11 @@ extern int id_main(int argc, char **argv
}
/* Print full info like GNU id */
- /* my_getpwuid doesn't exit on failure here */
- status=printf_full(uid, my_getpwuid(NULL, uid, 0), 'u');
+ /* bb_getpwuid doesn't exit on failure here */
+ status=printf_full(uid, bb_getpwuid(NULL, uid, 0), 'u');
putchar(' ');
- /* my_getgrgid doesn't exit on failure here */
- status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g');
+ /* bb_getgrgid doesn't exit on failure here */
+ status|=printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g');
#ifdef CONFIG_SELINUX
if ( is_selinux_enabled() ) {
diff -X excl -rduNp busybox.oorig/coreutils/install.c busybox/coreutils/install.c
--- busybox.oorig/coreutils/install.c 2005-09-11 10:03:24.000000000 +0200
+++ busybox/coreutils/install.c 2005-09-17 21:39:35.000000000 +0200
@@ -73,8 +73,8 @@ extern int install_main(int argc, char *
copy_flags |= FILEUTILS_PRESERVE_STATUS;
}
bb_parse_mode(mode_str, &mode);
- gid = get_ug_id(gid_str, my_getgrnam);
- uid = get_ug_id(uid_str, my_getpwnam);
+ gid = get_ug_id(gid_str, bb_xgetgrnam);
+ uid = get_ug_id(uid_str, bb_xgetpwnam);
umask(0);
/* Create directories
diff -X excl -rduNp busybox.oorig/coreutils/ls.c busybox/coreutils/ls.c
--- busybox.oorig/coreutils/ls.c 2005-09-11 10:03:24.000000000 +0200
+++ busybox/coreutils/ls.c 2005-09-17 21:39:35.000000000 +0200
@@ -692,9 +692,9 @@ static int list_single(struct dnode *dn)
break;
case LIST_ID_NAME:
#ifdef CONFIG_FEATURE_LS_USERNAME
- my_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
+ bb_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
printf("%-8.8s ", scratch);
- my_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
+ bb_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
printf("%-8.8s", scratch);
column += 17;
break;
diff -X excl -rduNp busybox.oorig/coreutils/whoami.c busybox/coreutils/whoami.c
--- busybox.oorig/coreutils/whoami.c 2005-04-01 22:05:44.000000000 +0200
+++ busybox/coreutils/whoami.c 2005-09-17 21:39:35.000000000 +0200
@@ -32,7 +32,7 @@ extern int whoami_main(int argc, char **
if (argc > 1)
bb_show_usage();
- puts(my_getpwuid(NULL, geteuid(), -1));
+ puts(bb_getpwuid(NULL, geteuid(), -1));
/* exits on error */
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
diff -X excl -rduNp busybox.oorig/debianutils/start_stop_daemon.c busybox/debianutils/start_stop_daemon.c
--- busybox.oorig/debianutils/start_stop_daemon.c 2005-09-11 10:03:23.000000000 +0200
+++ busybox/debianutils/start_stop_daemon.c 2005-09-17 21:39:35.000000000 +0200
@@ -265,7 +265,7 @@ start_stop_daemon_main(int argc, char **
argv += optind;
if (userspec && sscanf(userspec, "%d", &user_id) != 1)
- user_id = my_getpwnam(userspec);
+ user_id = bb_xgetpwnam(userspec);
if (opt & SSD_CTX_STOP) {
do_stop();
diff -X excl -rduNp busybox.oorig/include/libbb.h busybox/include/libbb.h
--- busybox.oorig/include/libbb.h 2005-09-17 12:01:58.000000000 +0200
+++ busybox/include/libbb.h 2005-09-17 22:04:59.000000000 +0200
@@ -224,16 +224,14 @@ extern unsigned long bb_xparse_number(co
const struct suffix_mult *suffixes);
-//#warning change names?
-
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
- * increases target size and is often not needed embedded systems. */
-extern long my_getpwnam(const char *name);
-extern long my_getgrnam(const char *name);
-extern char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix);
-extern char * my_getpwuid(char *name, long uid, int bufsize);
-extern char * my_getgrgid(char *group, long gid, int bufsize);
+ * increases target size and is often not needed on embedded systems. */
+extern long bb_xgetpwnam(const char *name);
+extern long bb_xgetgrnam(const char *name);
+extern char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);
+extern char * bb_getpwuid(char *name, long uid, int bufsize);
+extern char * bb_getgrgid(char *group, long gid, int bufsize);
extern char *bb_askpass(int timeout, const char * prompt);
extern int device_open(const char *device, int mode);
diff -X excl -rduNp busybox.oorig/libbb/bb_pwd.c busybox/libbb/bb_pwd.c
--- busybox.oorig/libbb/bb_pwd.c 1970-01-01 01:00:00.000000000 +0100
+++ busybox/libbb/bb_pwd.c 2005-09-17 21:52:57.000000000 +0200
@@ -0,0 +1,158 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * password utility routines.
+ *
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
+ *
+ * Licensed under the GPL v2, see the file LICENSE in this tarball.
+ */
+
+
+#ifdef L_bb_getgrgid
+ /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
+ * flexible :
+ *
+ * if bufsize is > 0 char *group cannot be set to NULL.
+ * On success groupname is written on static allocated buffer
+ * group (and a pointer to it is returned).
+ * On failure gid as string is written to static allocated
+ * buffer group and NULL is returned.
+ * if bufsize is = 0 char *group can be set to NULL.
+ * On success groupname is returned.
+ * On failure NULL is returned.
+ * if bufsize is < 0 char *group can be set to NULL.
+ * On success groupname is returned.
+ * On failure an error message is printed and
+ * the program exits.
+ */
+
+#include "libbb.h"
+#include "grp_.h"
+
+/* gets a groupname given a gid */
+char * bb_getgrgid(char *group, long gid, int bufsize)
+{
+ struct group *mygroup = getgrgid(gid);
+
+ return bb_getug(group, (mygroup) ?
+ mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g');
+}
+#endif /* L_bb_getgrgid */
+
+#ifdef L_bb_xgetgrnam
+#include <stdio.h>
+#include <string.h>
+#include "libbb.h"
+#include "pwd_.h"
+#include "grp_.h"
+
+
+/* returns a gid given a group name */
+long bb_xgetgrnam(const char *name)
+{
+ struct group *mygroup;
+
+ mygroup = getgrnam(name);
+ if (mygroup==NULL)
+ bb_error_msg_and_die("unknown group name: %s", name);
+
+ return (mygroup->gr_gid);
+}
+#endif /* L_bb_xgetgrnam */
+
+#ifdef L_bb_xgetpwnam
+#include <stdio.h>
+#include <string.h>
+#include "libbb.h"
+#include "pwd_.h"
+#include "grp_.h"
+
+
+/* returns a uid given a username */
+long bb_xgetpwnam(const char *name)
+{
+ struct passwd *myuser;
+
+ myuser = getpwnam(name);
+ if (myuser==NULL)
+ bb_error_msg_and_die("unknown user name: %s", name);
+
+ return myuser->pw_uid;
+}
+#endif /* L_bb_xgetpwnam */
+
+#ifdef L_bb_getpwuid
+ /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
+ * flexible :
+ *
+ * if bufsize is > 0 char *name can not be set to NULL.
+ * On success username is written on the static allocated
+ * buffer name (and a pointer to it is returned).
+ * On failure uid as string is written to the static
+ * allocated buffer name and NULL is returned.
+ * if bufsize is = 0 char *name can be set to NULL.
+ * On success username is returned.
+ * On failure NULL is returned.
+ * if bufsize is < 0 char *name can be set to NULL
+ * On success username is returned.
+ * On failure an error message is printed and
+ * the program exits.
+ */
+
+#include "libbb.h"
+#include "pwd_.h"
+
+/* gets a username given a uid */
+char * bb_getpwuid(char *name, long uid, int bufsize)
+{
+ struct passwd *myuser = getpwuid(uid);
+
+ return bb_getug(name, (myuser) ?
+ myuser->pw_name : (char *)myuser , uid, bufsize, 'u');
+}
+#endif /* L_bb_getpwuid */
+
+#ifdef L_bb_getug
+ /*
+ * if bufsize is > 0 char *buffer can not be set to NULL.
+ * If idname is not NULL it is written on the static
+ * allocated buffer (and a pointer to it is returned).
+ * if idname is NULL, id as string is written to the static
+ * allocated buffer and NULL is returned.
+ * if bufsize is = 0 char *buffer can be set to NULL.
+ * If idname exists a pointer to it is returned,
+ * else NULL is returned.
+ * if bufsize is < 0 char *buffer can be set to NULL.
+ * If idname exists a pointer to it is returned,
+ * else an error message is printed and the program exits.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include "libbb.h"
+
+
+/* internal function for bb_getpwuid and bb_getgrgid */
+char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
+{
+ if(bufsize > 0 ) {
+ assert(buffer!=NULL);
+ if(idname) {
+ return safe_strncpy(buffer, idname, bufsize);
+ }
+ snprintf(buffer, bufsize, "%ld", id);
+ } else if(bufsize < 0 && !idname) {
+ bb_error_msg_and_die("unknown %cid %ld", prefix, id);
+ }
+ return idname;
+}
+#endif /* L_bb_getug */
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff -X excl -rduNp busybox.oorig/libbb/Makefile.in busybox/libbb/Makefile.in
--- busybox.oorig/libbb/Makefile.in 2005-09-07 21:27:49.000000000 +0200
+++ busybox/libbb/Makefile.in 2005-09-17 21:47:27.000000000 +0200
@@ -33,8 +33,7 @@ LIBBB_SRC:= \
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 \
make_directory.c mode_string.c mtab.c mtab_file.c \
- my_getgrgid.c my_getgrnam.c my_getpwnam.c my_getug.c\
- my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \
+ obscure.c parse_mode.c parse_number.c perror_msg.c \
perror_msg_and_die.c print_file.c get_console.c \
process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c qmodule.c \
read_package_field.c recursive_action.c remove_file.c \
@@ -75,18 +74,22 @@ LIBBB_MOBJ3:=xgetularg_bnd_sfx.o xgetlar
LIBBB_MSRC4:=$(srcdir)/safe_strtol.c
LIBBB_MOBJ4:=safe_strtoi.o safe_strtod.o safe_strtol.o safe_strtoul.o
+LIBBB_MSRC5:=$(srcdir)/bb_pwd.c
+LIBBB_MOBJ5:=bb_xgetpwnam.o bb_xgetgrnam.o bb_getgrgid.o bb_getpwuid.o \
+ bb_getug.o
+
LIBBB_MOBJS0=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ0))
LIBBB_MOBJS1=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ1))
LIBBB_MOBJS2=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ2))
LIBBB_MOBJS3=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ3))
LIBBB_MOBJS4=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ4))
+LIBBB_MOBJS5=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ5))
libraries-y+=$(LIBBB_DIR)$(LIBBB_AR)
$(LIBBB_DIR)$(LIBBB_AR): $(LIBBB_OBJS) $(LIBBB_MOBJS0) $(LIBBB_MOBJS1) \
- $(LIBBB_MOBJS2) $(LIBBB_MOBJS3) $(LIBBB_MOBJS4)
- $(AR) $(ARFLAGS) $@ $(LIBBB_OBJS) $(LIBBB_MOBJS0) $(LIBBB_MOBJS1) \
- $(LIBBB_MOBJS2) $(LIBBB_MOBJS3) $(LIBBB_MOBJS4)
+ $(LIBBB_MOBJS2) $(LIBBB_MOBJS3) $(LIBBB_MOBJS4) $(LIBBB_MOBJS5)
+ $(AR) $(ARFLAGS) $(@) $(LIBBB_OBJS) $(^)
$(LIBBB_DIR)%.o: $(srcdir)/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
@@ -106,3 +109,6 @@ $(LIBBB_MOBJS3): $(LIBBB_MSRC3)
$(LIBBB_MOBJS4): $(LIBBB_MSRC4)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@
+$(LIBBB_MOBJS5): $(LIBBB_MSRC5)
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@
+
diff -X excl -rduNp busybox.oorig/libbb/my_getgrgid.c busybox/libbb/my_getgrgid.c
--- busybox.oorig/libbb/my_getgrgid.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/my_getgrgid.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,57 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
- *
- * 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
- * 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
- */
-
- /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
- * flexible :
- *
- * if bufsize is > 0 char *group cannot be set to NULL.
- * On success groupname is written on static allocated buffer group
- * (and a pointer to it is returned).
- * On failure gid as string is written to static allocated buffer
- * group and NULL is returned.
- * if bufsize is = 0 char *group can be set to NULL.
- * On success groupname is returned.
- * On failure NULL is returned.
- * if bufsize is < 0 char *group can be set to NULL.
- * On success groupname is returned.
- * On failure an error message is printed and the program exits.
- */
-
-#include "libbb.h"
-#include "grp_.h"
-
-/* gets a groupname given a gid */
-char * my_getgrgid(char *group, long gid, int bufsize)
-{
- struct group *mygroup = getgrgid(gid);
-
- return my_getug(group, (mygroup) ? mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g');
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff -X excl -rduNp busybox.oorig/libbb/my_getgrnam.c busybox/libbb/my_getgrnam.c
--- busybox.oorig/libbb/my_getgrnam.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/my_getgrnam.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,49 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
- *
- * 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
- * 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 <stdio.h>
-#include <string.h>
-#include "libbb.h"
-#include "pwd_.h"
-#include "grp_.h"
-
-
-/* returns a gid given a group name */
-long my_getgrnam(const char *name)
-{
- struct group *mygroup;
-
- mygroup = getgrnam(name);
- if (mygroup==NULL)
- bb_error_msg_and_die("unknown group name: %s", name);
-
- return (mygroup->gr_gid);
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff -X excl -rduNp busybox.oorig/libbb/my_getpwnam.c busybox/libbb/my_getpwnam.c
--- busybox.oorig/libbb/my_getpwnam.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/my_getpwnam.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,49 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
- *
- * 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
- * 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 <stdio.h>
-#include <string.h>
-#include "libbb.h"
-#include "pwd_.h"
-#include "grp_.h"
-
-
-/* returns a uid given a username */
-long my_getpwnam(const char *name)
-{
- struct passwd *myuser;
-
- myuser = getpwnam(name);
- if (myuser==NULL)
- bb_error_msg_and_die("unknown user name: %s", name);
-
- return myuser->pw_uid;
-}
-
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff -X excl -rduNp busybox.oorig/libbb/my_getpwuid.c busybox/libbb/my_getpwuid.c
--- busybox.oorig/libbb/my_getpwuid.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/my_getpwuid.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,56 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen at codepoet.org>
- *
- * 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
- * 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
- */
-
- /* Hacked by Tito Ragusa (c) 2004 <farmatito at tiscali.it> to make it more
- * flexible :
- *
- * if bufsize is > 0 char *name can not be set to NULL.
- * On success username is written on the static allocated buffer name
- * (and a pointer to it is returned).
- * On failure uid as string is written to the static allocated buffer name
- * and NULL is returned.
- * if bufsize is = 0 char *name can be set to NULL.
- * On success username is returned.
- * On failure NULL is returned.
- * if bufsize is < 0 char *name can be set to NULL
- * On success username is returned.
- * On failure an error message is printed and the program exits.
- */
-
-#include "libbb.h"
-#include "pwd_.h"
-
-/* gets a username given a uid */
-char * my_getpwuid(char *name, long uid, int bufsize)
-{
- struct passwd *myuser = getpwuid(uid);
-
- return my_getug(name, (myuser) ? myuser->pw_name : (char *)myuser , uid, bufsize, 'u');
-}
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff -X excl -rduNp busybox.oorig/libbb/my_getug.c busybox/libbb/my_getug.c
--- busybox.oorig/libbb/my_getug.c 2005-04-01 22:05:47.000000000 +0200
+++ busybox/libbb/my_getug.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,64 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 2004 by Tito Ragusa <farmatito at tiscali.it>
- *
- * 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
- * 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
- */
-
- /*
- *
- * if bufsize is > 0 char *buffer can not be set to NULL.
- * If idname is not NULL it is written on the static allocated buffer
- * (and a pointer to it is returned).
- * if idname is NULL, id as string is written to the static allocated buffer
- * and NULL is returned.
- * if bufsize is = 0 char *buffer can be set to NULL.
- * If idname exists a pointer to it is returned,
- * else NULL is returned.
- * if bufsize is < 0 char *buffer can be set to NULL.
- * If idname exists a pointer to it is returned,
- * else an error message is printed and the program exits.
- */
-
-#include <stdio.h>
-#include <assert.h>
-#include "libbb.h"
-
-
-/* internal function for my_getpwuid and my_getgrgid */
-char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
-{
- if(bufsize > 0 ) {
- assert(buffer!=NULL);
- if(idname) {
- return safe_strncpy(buffer, idname, bufsize);
- }
- snprintf(buffer, bufsize, "%ld", id);
- } else if(bufsize < 0 && !idname) {
- bb_error_msg_and_die("unknown %cid %ld", prefix, id);
- }
- return idname;
-}
-
-/* END CODE */
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/
diff -X excl -rduNp busybox.oorig/libbb/procps.c busybox/libbb/procps.c
--- busybox.oorig/libbb/procps.c 2005-09-17 12:01:57.000000000 +0200
+++ busybox/libbb/procps.c 2005-09-17 21:39:35.000000000 +0200
@@ -53,7 +53,7 @@ extern procps_status_t * procps_scan(int
sprintf(status, "/proc/%d", pid);
if(stat(status, &sb))
continue;
- my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
+ bb_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
sprintf(status, "/proc/%d/stat", pid);
diff -X excl -rduNp busybox.oorig/loginutils/adduser.c busybox/loginutils/adduser.c
--- busybox.oorig/loginutils/adduser.c 2005-04-01 22:05:50.000000000 +0200
+++ busybox/loginutils/adduser.c 2005-09-17 21:39:35.000000000 +0200
@@ -305,7 +305,7 @@ int adduser_main(int argc, char **argv)
if (usegroup) {
/* Add user to a group that already exists */
- pw.pw_gid = my_getgrnam(usegroup);
+ pw.pw_gid = bb_xgetgrnam(usegroup);
/* exits on error */
}
diff -X excl -rduNp busybox.oorig/loginutils/passwd.c busybox/loginutils/passwd.c
--- busybox.oorig/loginutils/passwd.c 2005-04-16 22:13:24.000000000 +0200
+++ busybox/loginutils/passwd.c 2005-09-17 21:39:35.000000000 +0200
@@ -168,7 +168,7 @@ extern int passwd_main(int argc, char **
bb_show_usage();
}
}
- myname = (char *) bb_xstrdup(my_getpwuid(NULL, getuid(), -1));
+ myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1));
/* exits on error */
if (optind < argc) {
name = argv[optind];
diff -X excl -rduNp busybox.oorig/miscutils/makedevs.c busybox/miscutils/makedevs.c
--- busybox.oorig/miscutils/makedevs.c 2005-07-28 18:51:59.000000000 +0200
+++ busybox/miscutils/makedevs.c 2005-09-17 21:39:35.000000000 +0200
@@ -160,12 +160,12 @@ extern int makedevs_main(int argc, char
continue;
}
if (group) {
- gid = get_ug_id(group, my_getgrnam);
+ gid = get_ug_id(group, bb_xgetgrnam);
} else {
gid = getgid();
}
if (user) {
- uid = get_ug_id(user, my_getpwnam);
+ uid = get_ug_id(user, bb_xgetpwnam);
} else {
uid = getuid();
}
diff -X excl -rduNp busybox.oorig/networking/httpd.c busybox/networking/httpd.c
--- busybox.oorig/networking/httpd.c 2005-09-02 09:45:27.000000000 +0200
+++ busybox/networking/httpd.c 2005-09-17 21:39:35.000000000 +0200
@@ -2047,7 +2047,7 @@ int httpd_main(int argc, char *argv[])
uid = strtol(s_uid, &e, 0);
if(*e != '\0') {
/* not integer */
- uid = my_getpwnam(s_uid);
+ uid = bb_xgetpwnam(s_uid);
}
}
#endif
diff -X excl -rduNp busybox.oorig/sysklogd/logger.c busybox/sysklogd/logger.c
--- busybox.oorig/sysklogd/logger.c 2005-04-08 21:58:44.000000000 +0200
+++ busybox/sysklogd/logger.c 2005-09-17 21:39:35.000000000 +0200
@@ -108,7 +108,7 @@ extern int logger_main(int argc, char **
char buf[1024], name[128];
/* Fill out the name string early (may be overwritten later) */
- my_getpwuid(name, geteuid(), sizeof(name));
+ bb_getpwuid(name, geteuid(), sizeof(name));
/* Parse any options */
while ((opt = getopt(argc, argv, "p:st:")) > 0) {
More information about the busybox
mailing list