aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-02-06 21:50:59 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-02-06 21:50:59 +0100
commitcb7edc26611f8df6b81ef4337206d5833ea98771 (patch)
treece211298be0d9f7d59d31139b47a5f915966e193
parent0cd445f4d1ff322051ca2ad869e8757bb5ac2227 (diff)
downloadbusybox-w32-cb7edc26611f8df6b81ef4337206d5833ea98771.tar.gz
busybox-w32-cb7edc26611f8df6b81ef4337206d5833ea98771.tar.bz2
busybox-w32-cb7edc26611f8df6b81ef4337206d5833ea98771.zip
adduser: copy /etc/skel to mew homes. +100 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/Kbuild1
-rw-r--r--libbb/die_if_bad_username.c12
-rw-r--r--loginutils/adduser.c18
3 files changed, 25 insertions, 6 deletions
diff --git a/coreutils/Kbuild b/coreutils/Kbuild
index 4d6bde7b9..460d62d3f 100644
--- a/coreutils/Kbuild
+++ b/coreutils/Kbuild
@@ -17,6 +17,7 @@ lib-$(CONFIG_CATV) += catv.o
17lib-$(CONFIG_CHGRP) += chgrp.o chown.o 17lib-$(CONFIG_CHGRP) += chgrp.o chown.o
18lib-$(CONFIG_CHMOD) += chmod.o 18lib-$(CONFIG_CHMOD) += chmod.o
19lib-$(CONFIG_CHOWN) += chown.o 19lib-$(CONFIG_CHOWN) += chown.o
20lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
20lib-$(CONFIG_CHROOT) += chroot.o 21lib-$(CONFIG_CHROOT) += chroot.o
21lib-$(CONFIG_CKSUM) += cksum.o 22lib-$(CONFIG_CKSUM) += cksum.o
22lib-$(CONFIG_COMM) += comm.o 23lib-$(CONFIG_COMM) += comm.o
diff --git a/libbb/die_if_bad_username.c b/libbb/die_if_bad_username.c
index c1641d376..8b4deec29 100644
--- a/libbb/die_if_bad_username.c
+++ b/libbb/die_if_bad_username.c
@@ -18,16 +18,20 @@
18 18
19void FAST_FUNC die_if_bad_username(const char *name) 19void FAST_FUNC die_if_bad_username(const char *name)
20{ 20{
21 goto skip; /* 1st char being dash isn't valid */ 21 /* 1st char being dash or dot isn't valid: */
22 goto skip;
23 /* For example, name like ".." can make adduser
24 * chown "/home/.." recursively - NOT GOOD
25 */
26
22 do { 27 do {
23 if (*name == '-') 28 if (*name == '-' || *name == '.')
24 continue; 29 continue;
25 skip: 30 skip:
26 if (isalnum(*name) 31 if (isalnum(*name)
27 || *name == '_' 32 || *name == '_'
28 || *name == '.'
29 || *name == '@' 33 || *name == '@'
30 || (*name == '$' && !*(name + 1)) 34 || (*name == '$' && !name[1])
31 ) { 35 ) {
32 continue; 36 continue;
33 } 37 }
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index da41fd7ac..f5dca929f 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -199,7 +199,21 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
199 /* set the owner and group so it is owned by the new user, 199 /* set the owner and group so it is owned by the new user,
200 * then fix up the permissions to 2755. Can't do it before 200 * then fix up the permissions to 2755. Can't do it before
201 * since chown will clear the setgid bit */ 201 * since chown will clear the setgid bit */
202 if ((mkdir(pw.pw_dir, 0755) != 0 && errno != EEXIST) 202 int mkdir_err = mkdir(pw.pw_dir, 0755);
203 if (mkdir_err == 0) {
204 /* New home. Copy /etc/skel to it */
205 const char *args[] = {
206 "chown", "-R",
207 xasprintf("%u:%u", (int)pw.pw_uid, (int)pw.pw_gid),
208 pw.pw_dir, NULL
209 };
210 /* Be silent on any errors (like: no /etc/skel) */
211 logmode = LOGMODE_NONE;
212 copy_file("/etc/skel", pw.pw_dir, FILEUTILS_RECUR);
213 logmode = LOGMODE_STDIO;
214 chown_main(4, (char**)args);
215 }
216 if ((mkdir_err != 0 && errno != EEXIST)
203 || chown(pw.pw_dir, pw.pw_uid, pw.pw_gid) != 0 217 || chown(pw.pw_dir, pw.pw_uid, pw.pw_gid) != 0
204 || chmod(pw.pw_dir, 02755) != 0 /* set setgid bit on homedir */ 218 || chmod(pw.pw_dir, 02755) != 0 /* set setgid bit on homedir */
205 ) { 219 ) {
@@ -212,5 +226,5 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
212 passwd_wrapper(pw.pw_name); 226 passwd_wrapper(pw.pw_name);
213 } 227 }
214 228
215 return 0; 229 return EXIT_SUCCESS;
216} 230}