summaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorDenis Vlasenko2009-01-12 09:20:49 +0000
committerDenis Vlasenko2009-01-12 09:20:49 +0000
commitf478fde33ce182f8826dc498f1998a49bfa01fa2 (patch)
tree39794a97a71238976d19795f9d8bdbfe1d6eeceb /loginutils
parent319fe129a15278193625eeb05752511d576c5588 (diff)
downloadbusybox-f478fde33ce182f8826dc498f1998a49bfa01fa2.zip
busybox-f478fde33ce182f8826dc498f1998a49bfa01fa2.tar.gz
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
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/adduser.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index 3154806..d4b5013 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -33,18 +33,17 @@ static void passwd_study(struct passwd *p)
}
/* 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++;
+ if (p->pw_uid > max)
+ bb_error_msg_and_die("no free uids left");
+ }
- if (!p->pw_gid) {
- /* new gid = uid */
- p->pw_gid = p->pw_uid;
+ if (p->pw_gid == (gid_t)-1) {
+ p->pw_gid = p->pw_uid; /* new gid = uid */
if (getgrnam(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)
@@ -90,6 +89,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
struct passwd pw;
const char *usegroup = NULL;
FILE *file;
+ int fd;
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
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_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 */
passwd_study(&pw);
@@ -134,17 +134,19 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_SHADOWPASSWDS
/* add to shadow if necessary */
- file = fopen_or_warn(bb_path_shadow_file, "a");
- if (file) {
- //fseek(file, 0, SEEK_END);
- fprintf(file, "%s:!:%u:0:99999:7:::\n",
+ /* fopen(..., "a"); would create shadow file, which is wrong.
+ * If shadow file doesn't exist, admin probably does not want it */
+ fd = open_or_warn(bb_path_shadow_file, O_WRONLY | O_APPEND);
+ if (fd >= 0) {
+ char *s = xasprintf("%s:!:%u:0:99999:7:::\n",
pw.pw_name, /* username */
(unsigned)(time(NULL) / 86400) /* sp->sp_lstchg */
/*0,*/ /* sp->sp_min */
/*99999,*/ /* sp->sp_max */
/*7*/ /* sp->sp_warn */
);
- fclose(file);
+ xwrite(fd, s, strlen(s));
+ close(fd);
}
#endif