adduser: allow adding to group 0; don't _create_ /etc/shadow,
only append data if it exists. function old new delta adduser_main 642 667 +25
This commit is contained in:
parent
319fe129a1
commit
f478fde33c
@ -33,18 +33,17 @@ static void passwd_study(struct passwd *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check for a free uid (and maybe gid) */
|
/* check for a free uid (and maybe gid) */
|
||||||
while (getpwuid(p->pw_uid) || (!p->pw_gid && getgrgid(p->pw_uid)))
|
while (getpwuid(p->pw_uid) || (p->pw_gid == (gid_t)-1 && getgrgid(p->pw_uid))) {
|
||||||
p->pw_uid++;
|
p->pw_uid++;
|
||||||
|
if (p->pw_uid > max)
|
||||||
|
bb_error_msg_and_die("no free uids left");
|
||||||
|
}
|
||||||
|
|
||||||
if (!p->pw_gid) {
|
if (p->pw_gid == (gid_t)-1) {
|
||||||
/* new gid = uid */
|
p->pw_gid = p->pw_uid; /* new gid = uid */
|
||||||
p->pw_gid = p->pw_uid;
|
|
||||||
if (getgrnam(p->pw_name))
|
if (getgrnam(p->pw_name))
|
||||||
bb_error_msg_and_die("group name '%s' is in use", p->pw_name);
|
bb_error_msg_and_die("group name '%s' is in use", p->pw_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->pw_uid > max)
|
|
||||||
bb_error_msg_and_die("no free uids left");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addgroup_wrapper(struct passwd *p)
|
static void addgroup_wrapper(struct passwd *p)
|
||||||
@ -90,6 +89,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
struct passwd pw;
|
struct passwd pw;
|
||||||
const char *usegroup = NULL;
|
const char *usegroup = NULL;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
int fd;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
|
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
|
||||||
applet_long_options = adduser_longopts;
|
applet_long_options = adduser_longopts;
|
||||||
@ -117,7 +117,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
pw.pw_dir = xasprintf("/home/%s", argv[0]);
|
pw.pw_dir = xasprintf("/home/%s", argv[0]);
|
||||||
}
|
}
|
||||||
pw.pw_passwd = (char *)"x";
|
pw.pw_passwd = (char *)"x";
|
||||||
pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */
|
pw.pw_gid = usegroup ? xgroup2gid(usegroup) : -1; /* exits on failure */
|
||||||
|
|
||||||
/* make sure everything is kosher and setup uid && maybe gid */
|
/* make sure everything is kosher and setup uid && maybe gid */
|
||||||
passwd_study(&pw);
|
passwd_study(&pw);
|
||||||
@ -134,17 +134,19 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||||
/* add to shadow if necessary */
|
/* add to shadow if necessary */
|
||||||
file = fopen_or_warn(bb_path_shadow_file, "a");
|
/* fopen(..., "a"); would create shadow file, which is wrong.
|
||||||
if (file) {
|
* If shadow file doesn't exist, admin probably does not want it */
|
||||||
//fseek(file, 0, SEEK_END);
|
fd = open_or_warn(bb_path_shadow_file, O_WRONLY | O_APPEND);
|
||||||
fprintf(file, "%s:!:%u:0:99999:7:::\n",
|
if (fd >= 0) {
|
||||||
|
char *s = xasprintf("%s:!:%u:0:99999:7:::\n",
|
||||||
pw.pw_name, /* username */
|
pw.pw_name, /* username */
|
||||||
(unsigned)(time(NULL) / 86400) /* sp->sp_lstchg */
|
(unsigned)(time(NULL) / 86400) /* sp->sp_lstchg */
|
||||||
/*0,*/ /* sp->sp_min */
|
/*0,*/ /* sp->sp_min */
|
||||||
/*99999,*/ /* sp->sp_max */
|
/*99999,*/ /* sp->sp_max */
|
||||||
/*7*/ /* sp->sp_warn */
|
/*7*/ /* sp->sp_warn */
|
||||||
);
|
);
|
||||||
fclose(file);
|
xwrite(fd, s, strlen(s));
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user