aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-01-12 09:20:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-01-12 09:20:49 +0000
commitf478fde33ce182f8826dc498f1998a49bfa01fa2 (patch)
tree39794a97a71238976d19795f9d8bdbfe1d6eeceb
parent319fe129a15278193625eeb05752511d576c5588 (diff)
downloadbusybox-w32-f478fde33ce182f8826dc498f1998a49bfa01fa2.tar.gz
busybox-w32-f478fde33ce182f8826dc498f1998a49bfa01fa2.tar.bz2
busybox-w32-f478fde33ce182f8826dc498f1998a49bfa01fa2.zip
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
-rw-r--r--loginutils/adduser.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index 3154806b6..d4b50130c 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -33,18 +33,17 @@ static void passwd_study(struct passwd *p)
33 } 33 }
34 34
35 /* check for a free uid (and maybe gid) */ 35 /* check for a free uid (and maybe gid) */
36 while (getpwuid(p->pw_uid) || (!p->pw_gid && getgrgid(p->pw_uid))) 36 while (getpwuid(p->pw_uid) || (p->pw_gid == (gid_t)-1 && getgrgid(p->pw_uid))) {
37 p->pw_uid++; 37 p->pw_uid++;
38 if (p->pw_uid > max)
39 bb_error_msg_and_die("no free uids left");
40 }
38 41
39 if (!p->pw_gid) { 42 if (p->pw_gid == (gid_t)-1) {
40 /* new gid = uid */ 43 p->pw_gid = p->pw_uid; /* new gid = uid */
41 p->pw_gid = p->pw_uid;
42 if (getgrnam(p->pw_name)) 44 if (getgrnam(p->pw_name))
43 bb_error_msg_and_die("group name '%s' is in use", p->pw_name); 45 bb_error_msg_and_die("group name '%s' is in use", p->pw_name);
44 } 46 }
45
46 if (p->pw_uid > max)
47 bb_error_msg_and_die("no free uids left");
48} 47}
49 48
50static void addgroup_wrapper(struct passwd *p) 49static void addgroup_wrapper(struct passwd *p)
@@ -90,6 +89,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
90 struct passwd pw; 89 struct passwd pw;
91 const char *usegroup = NULL; 90 const char *usegroup = NULL;
92 FILE *file; 91 FILE *file;
92 int fd;
93 93
94#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS 94#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
95 applet_long_options = adduser_longopts; 95 applet_long_options = adduser_longopts;
@@ -117,7 +117,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
117 pw.pw_dir = xasprintf("/home/%s", argv[0]); 117 pw.pw_dir = xasprintf("/home/%s", argv[0]);
118 } 118 }
119 pw.pw_passwd = (char *)"x"; 119 pw.pw_passwd = (char *)"x";
120 pw.pw_gid = usegroup ? xgroup2gid(usegroup) : 0; /* exits on failure */ 120 pw.pw_gid = usegroup ? xgroup2gid(usegroup) : -1; /* exits on failure */
121 121
122 /* make sure everything is kosher and setup uid && maybe gid */ 122 /* make sure everything is kosher and setup uid && maybe gid */
123 passwd_study(&pw); 123 passwd_study(&pw);
@@ -134,17 +134,19 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
134 134
135#if ENABLE_FEATURE_SHADOWPASSWDS 135#if ENABLE_FEATURE_SHADOWPASSWDS
136 /* add to shadow if necessary */ 136 /* add to shadow if necessary */
137 file = fopen_or_warn(bb_path_shadow_file, "a"); 137 /* fopen(..., "a"); would create shadow file, which is wrong.
138 if (file) { 138 * If shadow file doesn't exist, admin probably does not want it */
139 //fseek(file, 0, SEEK_END); 139 fd = open_or_warn(bb_path_shadow_file, O_WRONLY | O_APPEND);
140 fprintf(file, "%s:!:%u:0:99999:7:::\n", 140 if (fd >= 0) {
141 char *s = xasprintf("%s:!:%u:0:99999:7:::\n",
141 pw.pw_name, /* username */ 142 pw.pw_name, /* username */
142 (unsigned)(time(NULL) / 86400) /* sp->sp_lstchg */ 143 (unsigned)(time(NULL) / 86400) /* sp->sp_lstchg */
143 /*0,*/ /* sp->sp_min */ 144 /*0,*/ /* sp->sp_min */
144 /*99999,*/ /* sp->sp_max */ 145 /*99999,*/ /* sp->sp_max */
145 /*7*/ /* sp->sp_warn */ 146 /*7*/ /* sp->sp_warn */
146 ); 147 );
147 fclose(file); 148 xwrite(fd, s, strlen(s));
149 close(fd);
148 } 150 }
149#endif 151#endif
150 152