/* 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(char *name);
-extern long my_getgrnam(char *name);
+extern long my_getpwnam(const char *name);
+extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
-extern long my_getpwnamegid(char *name);
+extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
gid = strtoul(groupName, &p, 10); /* maybe it's already numeric */
if (groupName == p)
gid = my_getgrnam(groupName);
- if (gid == -1)
- goto bad_group;
} else {
groupName = strchr(*argv, '.');
if (groupName == NULL)
gid = strtoul(groupName, &p, 10);
if (groupName == p)
gid = my_getgrnam(groupName);
- if (gid == -1)
- goto bad_group;
} else
gid = -1;
}
uid = strtoul(*argv, &p, 10); /* if numeric ... */
if (*argv == p)
uid = my_getpwnam(*argv);
- if (uid == -1) {
- error_msg_and_die( "unknown user name: %s", *argv);
- }
}
}
}
return EXIT_SUCCESS;
- bad_group:
- error_msg_and_die( "unknown group name: %s", groupName);
}
/*
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
- if (gid == -1 || pwnam==-1 || grnam==-1) {
- error_msg_and_die("%s: No such user", user);
- }
if (no_group) {
if(name_not_number && user)
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
- if (gid == -1 || pwnam==-1 || grnam==-1) {
- error_msg_and_die("%s: No such user", user);
- }
if (no_group) {
if(name_not_number && user)
/* 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(char *name);
-extern long my_getgrnam(char *name);
+extern long my_getpwnam(const char *name);
+extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
-extern long my_getpwnamegid(char *name);
+extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);
#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS \
|| defined BB_TAR || defined BB_ID || defined BB_LOGGER \
|| defined BB_LOGNAME || defined BB_WHOAMI || defined BB_SH
+
+#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_ID
/* returns a uid given a username */
-long my_getpwnam(char *name)
+long my_getpwnam(const char *name)
{
struct passwd *myuser;
myuser = getpwnam(name);
if (myuser==NULL)
- return(-1);
+ error_msg_and_die("unknown user name: %s", name);
return myuser->pw_uid;
}
/* returns a gid given a group name */
-long my_getgrnam(char *name)
+long my_getgrnam(const char *name)
{
struct group *mygroup;
mygroup = getgrnam(name);
if (mygroup==NULL)
- return(-1);
+ error_msg_and_die("unknown group name: %s", name);
return (mygroup->gr_gid);
}
+#endif
/* gets a username given a uid */
void my_getpwuid(char *name, long uid)
#if defined BB_ID
/* gets a gid given a user name */
-long my_getpwnamegid(char *name)
+long my_getpwnamegid(const char *name)
{
struct group *mygroup;
struct passwd *myuser;
myuser=getpwnam(name);
if (myuser==NULL)
- error_msg_and_die( "unknown user name: %s", name);
+ error_msg_and_die("unknown user name: %s", name);
mygroup = getgrgid(myuser->pw_gid);
if (mygroup==NULL)
- error_msg_and_die( "unknown gid %ld", (long)myuser->pw_gid);
+ error_msg_and_die("unknown gid %ld", (long)myuser->pw_gid);
return mygroup->gr_gid;
}