/* chown-like handling of "user[:[group]" */
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 group* xgetgrnam(const char *name) FAST_FUNC;
struct passwd* xgetpwuid(uid_t uid) FAST_FUNC;
struct group* xgetgrgid(gid_t gid) FAST_FUNC;
char* xuid2uname(uid_t uid) FAST_FUNC;
return pw;
}
-/* xgetgrnam too? */
+struct group* FAST_FUNC xgetgrnam(const char *name)
+{
+ struct group *gr = getgrnam(name);
+ if (!gr)
+ bb_error_msg_and_die("unknown group %s", name);
+ return gr;
+}
+
struct passwd* FAST_FUNC xgetpwuid(uid_t uid)
{
{
struct group *mygroup;
- mygroup = getgrnam(name);
- if (mygroup == NULL)
- bb_error_msg_and_die("unknown group %s", name);
-
+ mygroup = xgetgrnam(name);
return mygroup->gr_gid;
}
/* check if group and user exist */
xuname2uid(argv[0]); /* unknown user: exit */
- xgroup2gid(argv[1]); /* unknown group: exit */
-// race here!
+ gr = xgetgrnam(argv[1]); /* unknown group: exit */
/* check if user is already in this group */
- gr = getgrnam(argv[1]);
for (; *(gr->gr_mem) != NULL; (gr->gr_mem)++) {
if (!strcmp(argv[0], *(gr->gr_mem))) {
/* user is already in group: do nothing */