summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2010-02-06 21:50:59 +0100
committerDenys Vlasenko2010-02-06 21:50:59 +0100
commitcb7edc26611f8df6b81ef4337206d5833ea98771 (patch)
treece211298be0d9f7d59d31139b47a5f915966e193
parent0cd445f4d1ff322051ca2ad869e8757bb5ac2227 (diff)
downloadbusybox-cb7edc26611f8df6b81ef4337206d5833ea98771.zip
busybox-cb7edc26611f8df6b81ef4337206d5833ea98771.tar.gz
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 4d6bde7..460d62d 100644
--- a/coreutils/Kbuild
+++ b/coreutils/Kbuild
@@ -17,6 +17,7 @@ lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
lib-$(CONFIG_CHOWN) += chown.o
+lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
lib-$(CONFIG_CHROOT) += chroot.o
lib-$(CONFIG_CKSUM) += cksum.o
lib-$(CONFIG_COMM) += comm.o
diff --git a/libbb/die_if_bad_username.c b/libbb/die_if_bad_username.c
index c1641d3..8b4deec 100644
--- a/libbb/die_if_bad_username.c
+++ b/libbb/die_if_bad_username.c
@@ -18,16 +18,20 @@
void FAST_FUNC die_if_bad_username(const char *name)
{
- goto skip; /* 1st char being dash isn't valid */
+ /* 1st char being dash or dot isn't valid: */
+ goto skip;
+ /* For example, name like ".." can make adduser
+ * chown "/home/.." recursively - NOT GOOD
+ */
+
do {
- if (*name == '-')
+ if (*name == '-' || *name == '.')
continue;
skip:
if (isalnum(*name)
|| *name == '_'
- || *name == '.'
|| *name == '@'
- || (*name == '$' && !*(name + 1))
+ || (*name == '$' && !name[1])
) {
continue;
}
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index da41fd7..f5dca92 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -199,7 +199,21 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
/* set the owner and group so it is owned by the new user,
* then fix up the permissions to 2755. Can't do it before
* since chown will clear the setgid bit */
- if ((mkdir(pw.pw_dir, 0755) != 0 && errno != EEXIST)
+ int mkdir_err = mkdir(pw.pw_dir, 0755);
+ if (mkdir_err == 0) {
+ /* New home. Copy /etc/skel to it */
+ const char *args[] = {
+ "chown", "-R",
+ xasprintf("%u:%u", (int)pw.pw_uid, (int)pw.pw_gid),
+ pw.pw_dir, NULL
+ };
+ /* Be silent on any errors (like: no /etc/skel) */
+ logmode = LOGMODE_NONE;
+ copy_file("/etc/skel", pw.pw_dir, FILEUTILS_RECUR);
+ logmode = LOGMODE_STDIO;
+ chown_main(4, (char**)args);
+ }
+ if ((mkdir_err != 0 && errno != EEXIST)
|| chown(pw.pw_dir, pw.pw_uid, pw.pw_gid) != 0
|| chmod(pw.pw_dir, 02755) != 0 /* set setgid bit on homedir */
) {
@@ -212,5 +226,5 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
passwd_wrapper(pw.pw_name);
}
- return 0;
+ return EXIT_SUCCESS;
}