aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-19 23:15:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-19 23:15:26 +0000
commita7d6c8bab919e1a537f8b7db7b8676484e60f550 (patch)
treefd5d442775f7551b76d22563816d30b4fc6a6029
parentcf7cf622046b0e1a2817e1da4aa8bc6f513b0153 (diff)
downloadbusybox-w32-a7d6c8bab919e1a537f8b7db7b8676484e60f550.tar.gz
busybox-w32-a7d6c8bab919e1a537f8b7db7b8676484e60f550.tar.bz2
busybox-w32-a7d6c8bab919e1a537f8b7db7b8676484e60f550.zip
adduser/addgroup: check username for invalid chars
(by Tito <farmatito AT tiscali.it>). +129 bytes when enabled.
-rw-r--r--include/libbb.h6
-rw-r--r--libbb/Kbuild1
-rw-r--r--loginutils/Config.in12
-rw-r--r--loginutils/addgroup.c3
-rw-r--r--loginutils/adduser.c1
5 files changed, 22 insertions, 1 deletions
diff --git a/include/libbb.h b/include/libbb.h
index d059ac9de..19b3bba5f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -637,7 +637,11 @@ const char* get_cached_groupname(gid_t gid);
637void clear_username_cache(void); 637void clear_username_cache(void);
638/* internally usernames are saved in fixed-sized char[] buffers */ 638/* internally usernames are saved in fixed-sized char[] buffers */
639enum { USERNAME_MAX_SIZE = 16 - sizeof(int) }; 639enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };
640 640#if ENABLE_FEATURE_CHECK_NAMES
641void die_if_bad_username(const char* name);
642#else
643#define die_if_bad_username(name) ((void)(name))
644#endif
641 645
642int execable_file(const char *name); 646int execable_file(const char *name);
643char *find_execable(const char *filename); 647char *find_execable(const char *filename);
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 654722cd6..5740d9247 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -122,6 +122,7 @@ lib-$(CONFIG_MKFS_MINIX) += find_mount_point.o
122lib-$(CONFIG_SELINUX) += selinux_common.o 122lib-$(CONFIG_SELINUX) += selinux_common.o
123lib-$(CONFIG_HWCLOCK) += rtc.o 123lib-$(CONFIG_HWCLOCK) += rtc.o
124lib-$(CONFIG_RTCWAKE) += rtc.o 124lib-$(CONFIG_RTCWAKE) += rtc.o
125lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o
125 126
126# We shouldn't build xregcomp.c if we don't need it - this ensures we don't 127# We shouldn't build xregcomp.c if we don't need it - this ensures we don't
127# require regex.h to be in the include dir even if we don't need it thereby 128# require regex.h to be in the include dir even if we don't need it thereby
diff --git a/loginutils/Config.in b/loginutils/Config.in
index 81d05ef89..c57d9976e 100644
--- a/loginutils/Config.in
+++ b/loginutils/Config.in
@@ -82,6 +82,18 @@ config FEATURE_DEL_USER_FROM_GROUP
82 If called with two non-option arguments, deluser 82 If called with two non-option arguments, deluser
83 or delgroup will remove an user from a specified group. 83 or delgroup will remove an user from a specified group.
84 84
85config FEATURE_CHECK_NAMES
86 bool "Enable sanity check on user/group names in adduser and addgroup"
87 default n
88 depends on ADDUSER || ADDGROUP
89 help
90 Enable sanity check on user and group names in adduser and addgroup.
91 To avoid problems, the user or group name should consist only of
92 letters, digits, underscores, periods, at signs and dashes,
93 and not start with a dash (as defined by IEEE Std 1003.1-2001).
94 For compatibility with Samba machine accounts "$" is also supported
95 at the end of the user or group name.
96
85config ADDUSER 97config ADDUSER
86 bool "adduser" 98 bool "adduser"
87 default n 99 default n
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index b25f8171d..367c6b9f0 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -173,8 +173,11 @@ int addgroup_main(int argc ATTRIBUTE_UNUSED, char **argv)
173#endif 173#endif
174 } else 174 } else
175#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ 175#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
176 {
177 die_if_bad_username(argv[0]);
176 new_group(argv[0], gid); 178 new_group(argv[0], gid);
177 179
180 }
178 /* Reached only on success */ 181 /* Reached only on success */
179 return EXIT_SUCCESS; 182 return EXIT_SUCCESS;
180} 183}
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index d409eabb9..cd68015d1 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -111,6 +111,7 @@ int adduser_main(int argc ATTRIBUTE_UNUSED, char **argv)
111 111
112 /* fill in the passwd struct */ 112 /* fill in the passwd struct */
113 pw.pw_name = argv[0]; 113 pw.pw_name = argv[0];
114 die_if_bad_username(pw.pw_name);
114 if (!pw.pw_dir) { 115 if (!pw.pw_dir) {
115 /* create string for $HOME if not specified already */ 116 /* create string for $HOME if not specified already */
116 pw.pw_dir = xasprintf("/home/%s", argv[0]); 117 pw.pw_dir = xasprintf("/home/%s", argv[0]);