- rename libbb's password helpers as suggested in libbb.h

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
This commit is contained in:
Bernhard Reutner-Fischer 2005-09-20 21:06:17 +00:00
parent f912ebb740
commit d5bd137a24
17 changed files with 47 additions and 43 deletions

View File

@ -331,8 +331,8 @@ void fileaction_dobackup(char *filename, int fileref)
void fileaction_setowngrp(char *filename, int fileref) void fileaction_setowngrp(char *filename, int fileref)
{ {
int uid, gid; int uid, gid;
uid = my_getpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref)); uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
gid = my_getgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref)); gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
chown (filename, uid, gid); chown (filename, uid, gid);
} }

View File

@ -234,9 +234,9 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
TAR_MAGIC_LEN + TAR_VERSION_LEN); TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */ /* 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"); 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"); strcpy(header.gname, "root");
if (tbInfo->hlInfo) { if (tbInfo->hlInfo) {

View File

@ -58,7 +58,7 @@ int chgrp_main(int argc, char **argv)
argv += optind; argv += optind;
/* Find the selected group */ /* Find the selected group */
gid = get_ug_id(*argv, my_getgrnam); gid = get_ug_id(*argv, bb_xgetgrnam);
++argv; ++argv;
/* Ok, ready to do the deed now */ /* Ok, ready to do the deed now */

View File

@ -77,11 +77,11 @@ int chown_main(int argc, char **argv)
gid = -1; gid = -1;
if (groupName) { if (groupName) {
*groupName++ = '\0'; *groupName++ = '\0';
gid = get_ug_id(groupName, my_getgrnam); gid = get_ug_id(groupName, bb_xgetgrnam);
} }
/* Now check for the username */ /* Now check for the username */
uid = get_ug_id(*argv, my_getpwnam); uid = get_ug_id(*argv, bb_xgetpwnam);
++argv; ++argv;

View File

@ -80,8 +80,8 @@ extern int id_main(int argc, char **argv)
if(argv[optind]) { if(argv[optind]) {
p=getpwnam(argv[optind]); p=getpwnam(argv[optind]);
/* my_getpwnam is needed because it exits on failure */ /* bb_xgetpwnam is needed because it exits on failure */
uid = my_getpwnam(argv[optind]); uid = bb_xgetpwnam(argv[optind]);
gid = p->pw_gid; gid = p->pw_gid;
/* in this case PRINT_REAL is the same */ /* 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)) { if(flags & (JUST_GROUP | JUST_USER)) {
/* JUST_GROUP and JUST_USER are mutually exclusive */ /* JUST_GROUP and JUST_USER are mutually exclusive */
if(flags & NAME_NOT_NUMBER) { if(flags & NAME_NOT_NUMBER) {
/* my_getpwuid and my_getgrgid exit on failure so puts cannot segfault */ /* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */
puts((flags & JUST_USER) ? my_getpwuid(NULL, uid, -1 ) : my_getgrgid(NULL, gid, -1 )); puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 ));
} else { } else {
bb_printf("%u\n",(flags & JUST_USER) ? uid : gid); 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 */ /* Print full info like GNU id */
/* my_getpwuid doesn't exit on failure here */ /* bb_getpwuid doesn't exit on failure here */
status=printf_full(uid, my_getpwuid(NULL, uid, 0), 'u'); status=printf_full(uid, bb_getpwuid(NULL, uid, 0), 'u');
putchar(' '); putchar(' ');
/* my_getgrgid doesn't exit on failure here */ /* bb_getgrgid doesn't exit on failure here */
status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g'); status|=printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g');
#ifdef CONFIG_SELINUX #ifdef CONFIG_SELINUX
if ( is_selinux_enabled() ) { if ( is_selinux_enabled() ) {

View File

@ -73,8 +73,8 @@ extern int install_main(int argc, char **argv)
copy_flags |= FILEUTILS_PRESERVE_STATUS; copy_flags |= FILEUTILS_PRESERVE_STATUS;
} }
bb_parse_mode(mode_str, &mode); bb_parse_mode(mode_str, &mode);
gid = get_ug_id(gid_str, my_getgrnam); gid = get_ug_id(gid_str, bb_xgetgrnam);
uid = get_ug_id(uid_str, my_getpwnam); uid = get_ug_id(uid_str, bb_xgetpwnam);
umask(0); umask(0);
/* Create directories /* Create directories

View File

@ -692,9 +692,9 @@ static int list_single(struct dnode *dn)
break; break;
case LIST_ID_NAME: case LIST_ID_NAME:
#ifdef CONFIG_FEATURE_LS_USERNAME #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); 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); printf("%-8.8s", scratch);
column += 17; column += 17;
break; break;

View File

@ -32,7 +32,7 @@ extern int whoami_main(int argc, char **argv)
if (argc > 1) if (argc > 1)
bb_show_usage(); bb_show_usage();
puts(my_getpwuid(NULL, geteuid(), -1)); puts(bb_getpwuid(NULL, geteuid(), -1));
/* exits on error */ /* exits on error */
bb_fflush_stdout_and_exit(EXIT_SUCCESS); bb_fflush_stdout_and_exit(EXIT_SUCCESS);
} }

View File

@ -265,7 +265,7 @@ start_stop_daemon_main(int argc, char **argv)
argv += optind; argv += optind;
if (userspec && sscanf(userspec, "%d", &user_id) != 1) if (userspec && sscanf(userspec, "%d", &user_id) != 1)
user_id = my_getpwnam(userspec); user_id = bb_xgetpwnam(userspec);
if (opt & SSD_CTX_STOP) { if (opt & SSD_CTX_STOP) {
do_stop(); do_stop();

View File

@ -221,16 +221,14 @@ extern unsigned long bb_xparse_number(const char *numstr,
const struct suffix_mult *suffixes); const struct suffix_mult *suffixes);
//#warning change names?
/* These parse entries in /etc/passwd and /etc/group. This is desirable /* 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 * for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */ * increases target size and is often not needed on embedded systems. */
extern long my_getpwnam(const char *name); extern long bb_xgetpwnam(const char *name);
extern long my_getgrnam(const char *name); extern long bb_xgetgrnam(const char *name);
extern char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix); extern char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);
extern char * my_getpwuid(char *name, long uid, int bufsize); extern char * bb_getpwuid(char *name, long uid, int bufsize);
extern char * my_getgrgid(char *group, long gid, int bufsize); extern char * bb_getgrgid(char *group, long gid, int bufsize);
extern char *bb_askpass(int timeout, const char * prompt); extern char *bb_askpass(int timeout, const char * prompt);
extern int device_open(const char *device, int mode); extern int device_open(const char *device, int mode);
@ -471,7 +469,7 @@ extern void print_login_prompt(void);
extern void vfork_daemon_rexec(int nochdir, int noclose, extern void vfork_daemon_rexec(int nochdir, int noclose,
int argc, char **argv, char *foreground_opt); int argc, char **argv, char *foreground_opt);
extern int get_terminal_width_height(int fd, int *width, int *height); 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_SHA1 1
#define HASH_MD5 2 #define HASH_MD5 2

View File

@ -28,13 +28,12 @@ LIBBB_SRC:= \
correct_password.c create_icmp_socket.c create_icmp6_socket.c \ 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 \ 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 \ 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 \ hash_fd.c herror_msg.c herror_msg_and_die.c \
human_readable.c inet_common.c inode_hash.c interface.c isdirectory.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 \ 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 \ make_directory.c mode_string.c mtab.c mtab_file.c \
my_getgrgid.c my_getgrnam.c my_getpwnam.c my_getug.c\ obscure.c parse_mode.c parse_number.c perror_msg.c \
my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \
perror_msg_and_die.c print_file.c get_console.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 \ process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c qmodule.c \
read_package_field.c recursive_action.c remove_file.c \ read_package_field.c recursive_action.c remove_file.c \
@ -75,18 +74,22 @@ LIBBB_MOBJ3:=xgetularg_bnd_sfx.o xgetlarg_bnd_sfx.o getlarg10_sfx.o \
LIBBB_MSRC4:=$(srcdir)/safe_strtol.c LIBBB_MSRC4:=$(srcdir)/safe_strtol.c
LIBBB_MOBJ4:=safe_strtoi.o safe_strtod.o safe_strtol.o safe_strtoul.o 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 get_ug_id.o
LIBBB_MOBJS0=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ0)) LIBBB_MOBJS0=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ0))
LIBBB_MOBJS1=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ1)) LIBBB_MOBJS1=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ1))
LIBBB_MOBJS2=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ2)) LIBBB_MOBJS2=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ2))
LIBBB_MOBJS3=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ3)) LIBBB_MOBJS3=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ3))
LIBBB_MOBJS4=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ4)) LIBBB_MOBJS4=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ4))
LIBBB_MOBJS5=$(patsubst %,$(LIBBB_DIR)%, $(LIBBB_MOBJ5))
libraries-y+=$(LIBBB_DIR)$(LIBBB_AR) libraries-y+=$(LIBBB_DIR)$(LIBBB_AR)
$(LIBBB_DIR)$(LIBBB_AR): $(LIBBB_OBJS) $(LIBBB_MOBJS0) $(LIBBB_MOBJS1) \ $(LIBBB_DIR)$(LIBBB_AR): $(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_MOBJS0) $(LIBBB_MOBJS1) \ $(AR) $(ARFLAGS) $(@) $(LIBBB_OBJS) $(^)
$(LIBBB_MOBJS2) $(LIBBB_MOBJS3) $(LIBBB_MOBJS4)
$(LIBBB_DIR)%.o: $(srcdir)/%.c $(LIBBB_DIR)%.o: $(srcdir)/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
@ -106,3 +109,6 @@ $(LIBBB_MOBJS3): $(LIBBB_MSRC3)
$(LIBBB_MOBJS4): $(LIBBB_MSRC4) $(LIBBB_MOBJS4): $(LIBBB_MSRC4)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@
$(LIBBB_MOBJS5): $(LIBBB_MSRC5)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DL_$(notdir $*) -c $< -o $@

View File

@ -53,7 +53,7 @@ extern procps_status_t * procps_scan(int save_user_arg0)
sprintf(status, "/proc/%d", pid); sprintf(status, "/proc/%d", pid);
if(stat(status, &sb)) if(stat(status, &sb))
continue; 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); sprintf(status, "/proc/%d/stat", pid);

View File

@ -305,7 +305,7 @@ int adduser_main(int argc, char **argv)
if (usegroup) { if (usegroup) {
/* Add user to a group that already exists */ /* Add user to a group that already exists */
pw.pw_gid = my_getgrnam(usegroup); pw.pw_gid = bb_xgetgrnam(usegroup);
/* exits on error */ /* exits on error */
} }

View File

@ -168,7 +168,7 @@ extern int passwd_main(int argc, char **argv)
bb_show_usage(); bb_show_usage();
} }
} }
myname = (char *) bb_xstrdup(my_getpwuid(NULL, getuid(), -1)); myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1));
/* exits on error */ /* exits on error */
if (optind < argc) { if (optind < argc) {
name = argv[optind]; name = argv[optind];

View File

@ -160,12 +160,12 @@ extern int makedevs_main(int argc, char **argv)
continue; continue;
} }
if (group) { if (group) {
gid = get_ug_id(group, my_getgrnam); gid = get_ug_id(group, bb_xgetgrnam);
} else { } else {
gid = getgid(); gid = getgid();
} }
if (user) { if (user) {
uid = get_ug_id(user, my_getpwnam); uid = get_ug_id(user, bb_xgetpwnam);
} else { } else {
uid = getuid(); uid = getuid();
} }

View File

@ -2050,7 +2050,7 @@ int httpd_main(int argc, char *argv[])
uid = strtol(s_uid, &e, 0); uid = strtol(s_uid, &e, 0);
if(*e != '\0') { if(*e != '\0') {
/* not integer */ /* not integer */
uid = my_getpwnam(s_uid); uid = bb_xgetpwnam(s_uid);
} }
} }
#endif #endif

View File

@ -108,7 +108,7 @@ extern int logger_main(int argc, char **argv)
char buf[1024], name[128]; char buf[1024], name[128];
/* Fill out the name string early (may be overwritten later) */ /* 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 */ /* Parse any options */
while ((opt = getopt(argc, argv, "p:st:")) > 0) { while ((opt = getopt(argc, argv, "p:st:")) > 0) {