mirror of
https://github.com/sheumann/hush.git
synced 2025-01-14 12:30:40 +00:00
libbb: introduce and use xgetpwnam. ~ -150 bytes.
This commit is contained in:
parent
ac1c96f673
commit
d7a805efaf
@ -124,9 +124,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
username = argv[optind];
|
username = argv[optind];
|
||||||
if (username) {
|
if (username) {
|
||||||
struct passwd *p = getpwnam(username);
|
struct passwd *p = xgetpwnam(username);
|
||||||
if (!p)
|
|
||||||
bb_error_msg_and_die("unknown user %s", username);
|
|
||||||
euid = ruid = p->pw_uid;
|
euid = ruid = p->pw_uid;
|
||||||
egid = rgid = p->pw_gid;
|
egid = rgid = p->pw_gid;
|
||||||
} else {
|
} else {
|
||||||
|
@ -702,6 +702,7 @@ int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC;
|
|||||||
void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
|
void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC;
|
||||||
/* chown-like handling of "user[:[group]" */
|
/* chown-like handling of "user[:[group]" */
|
||||||
void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
|
void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC;
|
||||||
|
struct passwd* xgetpwnam(const char *name) FAST_FUNC;
|
||||||
struct passwd* xgetpwuid(uid_t uid) FAST_FUNC;
|
struct passwd* xgetpwuid(uid_t uid) FAST_FUNC;
|
||||||
struct group* xgetgrgid(gid_t gid) FAST_FUNC;
|
struct group* xgetgrgid(gid_t gid) FAST_FUNC;
|
||||||
char* xuid2uname(uid_t uid) FAST_FUNC;
|
char* xuid2uname(uid_t uid) FAST_FUNC;
|
||||||
|
@ -15,7 +15,15 @@
|
|||||||
* pointers to static data (getpwuid)
|
* pointers to static data (getpwuid)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO: add xgetpwnam, this construct is used a lot */
|
struct passwd* FAST_FUNC xgetpwnam(const char *name)
|
||||||
|
{
|
||||||
|
struct passwd *pw = getpwnam(name);
|
||||||
|
if (!pw)
|
||||||
|
bb_error_msg_and_die("unknown user %s", name);
|
||||||
|
return pw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* xgetgrnam too? */
|
||||||
|
|
||||||
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
|
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
|
||||||
{
|
{
|
||||||
@ -73,10 +81,7 @@ long FAST_FUNC xuname2uid(const char *name)
|
|||||||
{
|
{
|
||||||
struct passwd *myuser;
|
struct passwd *myuser;
|
||||||
|
|
||||||
myuser = getpwnam(name);
|
myuser = xgetpwnam(name);
|
||||||
if (myuser == NULL)
|
|
||||||
bb_error_msg_and_die("unknown user %s", name);
|
|
||||||
|
|
||||||
return myuser->pw_uid;
|
return myuser->pw_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
/* check if group and user exist */
|
/* check if group and user exist */
|
||||||
xuname2uid(argv[0]); /* unknown user: exit */
|
xuname2uid(argv[0]); /* unknown user: exit */
|
||||||
xgroup2gid(argv[1]); /* unknown group: exit */
|
xgroup2gid(argv[1]); /* unknown group: exit */
|
||||||
|
// race here!
|
||||||
/* check if user is already in this group */
|
/* check if user is already in this group */
|
||||||
gr = getgrnam(argv[1]);
|
gr = getgrnam(argv[1]);
|
||||||
for (; *(gr->gr_mem) != NULL; (gr->gr_mem)++) {
|
for (; *(gr->gr_mem) != NULL; (gr->gr_mem)++) {
|
||||||
|
@ -118,9 +118,7 @@ int passwd_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
myname = xstrdup(xuid2uname(myuid));
|
myname = xstrdup(xuid2uname(myuid));
|
||||||
name = argv[0] ? argv[0] : myname;
|
name = argv[0] ? argv[0] : myname;
|
||||||
|
|
||||||
pw = getpwnam(name);
|
pw = xgetpwnam(name);
|
||||||
if (!pw)
|
|
||||||
bb_error_msg_and_die("unknown user %s", name);
|
|
||||||
if (myuid && pw->pw_uid != myuid) {
|
if (myuid && pw->pw_uid != myuid) {
|
||||||
/* LOGMODE_BOTH */
|
/* LOGMODE_BOTH */
|
||||||
bb_error_msg_and_die("%s can't change password for %s", myname, name);
|
bb_error_msg_and_die("%s can't change password for %s", myname, name);
|
||||||
|
@ -48,9 +48,7 @@ int su_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
openlog(applet_name, 0, LOG_AUTH);
|
openlog(applet_name, 0, LOG_AUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
pw = getpwnam(opt_username);
|
pw = xgetpwnam(opt_username);
|
||||||
if (!pw)
|
|
||||||
bb_error_msg_and_die("unknown id: %s", opt_username);
|
|
||||||
|
|
||||||
/* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER
|
/* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER
|
||||||
is a username that is retrieved via NIS (YP), but that doesn't have
|
is a username that is retrieved via NIS (YP), but that doesn't have
|
||||||
|
@ -126,9 +126,7 @@ int crontab_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opt_ler & OPT_u) {
|
if (opt_ler & OPT_u) {
|
||||||
pas = getpwnam(user_name);
|
pas = xgetpwnam(user_name);
|
||||||
if (!pas)
|
|
||||||
bb_error_msg_and_die("user %s is not known", user_name);
|
|
||||||
} else {
|
} else {
|
||||||
pas = xgetpwuid(getuid());
|
pas = xgetpwuid(getuid());
|
||||||
}
|
}
|
||||||
|
@ -223,9 +223,7 @@ static int tftp_protocol(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user_opt) {
|
if (user_opt) {
|
||||||
struct passwd *pw = getpwnam(user_opt);
|
struct passwd *pw = xgetpwnam(user_opt);
|
||||||
if (!pw)
|
|
||||||
bb_error_msg_and_die("unknown user %s", user_opt);
|
|
||||||
change_identity(pw); /* initgroups, setgid, setuid */
|
change_identity(pw); /* initgroups, setgid, setuid */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user