Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/loginutils/adduser.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/loginutils/adduser.c
r3232 r3621 8 8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 */ 10 //config:config ADDUSER 11 //config: bool "adduser" 12 //config: default y 13 //config: help 14 //config: Utility for creating a new user account. 15 //config: 16 //config:config FEATURE_ADDUSER_LONG_OPTIONS 17 //config: bool "Enable long options" 18 //config: default y 19 //config: depends on ADDUSER && LONG_OPTS 20 //config: help 21 //config: Support long options for the adduser applet. 22 //config: 23 //config:config FEATURE_CHECK_NAMES 24 //config: bool "Enable sanity check on user/group names in adduser and addgroup" 25 //config: default n 26 //config: depends on ADDUSER || ADDGROUP 27 //config: help 28 //config: Enable sanity check on user and group names in adduser and addgroup. 29 //config: To avoid problems, the user or group name should consist only of 30 //config: letters, digits, underscores, periods, at signs and dashes, 31 //config: and not start with a dash (as defined by IEEE Std 1003.1-2001). 32 //config: For compatibility with Samba machine accounts "$" is also supported 33 //config: at the end of the user or group name. 34 //config: 35 //config:config LAST_ID 36 //config: int "Last valid uid or gid for adduser and addgroup" 37 //config: depends on ADDUSER || ADDGROUP 38 //config: default 60000 39 //config: help 40 //config: Last valid uid or gid for adduser and addgroup 41 //config: 42 //config:config FIRST_SYSTEM_ID 43 //config: int "First valid system uid or gid for adduser and addgroup" 44 //config: depends on ADDUSER || ADDGROUP 45 //config: range 0 LAST_ID 46 //config: default 100 47 //config: help 48 //config: First valid system uid or gid for adduser and addgroup 49 //config: 50 //config:config LAST_SYSTEM_ID 51 //config: int "Last valid system uid or gid for adduser and addgroup" 52 //config: depends on ADDUSER || ADDGROUP 53 //config: range FIRST_SYSTEM_ID LAST_ID 54 //config: default 999 55 //config: help 56 //config: Last valid system uid or gid for adduser and addgroup 57 58 //applet:IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP)) 59 60 //kbuild:lib-$(CONFIG_ADDUSER) += adduser.o 10 61 11 62 //usage:#define adduser_trivial_usage … … 21 72 //usage: "\n -H Don't create home directory" 22 73 //usage: "\n -u UID User id" 74 //usage: "\n -k SKEL Skeleton directory (/etc/skel)" 23 75 24 76 #include "libbb.h" … … 27 79 #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config 28 80 #endif 81 #if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID 82 #error Bad LAST_ID or LAST_SYSTEM_ID in .config 83 #endif 84 29 85 30 86 /* #define OPT_HOME (1 << 0) */ /* unused */ … … 36 92 #define OPT_DONT_MAKE_HOME (1 << 6) 37 93 #define OPT_UID (1 << 7) 38 39 /* We assume UID_T_MAX == INT_MAX */ 94 #define OPT_SKEL (1 << 8) 95 40 96 /* remix */ 41 97 /* recoded such that the uid may be passed in *p */ 42 98 static void passwd_study(struct passwd *p) 43 99 { 44 int max = UINT_MAX;100 int max = CONFIG_LAST_ID; 45 101 46 102 if (getpwnam(p->pw_name)) { … … 55 111 } else { 56 112 p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1; 57 max = 64999;58 113 } 59 114 } … … 133 188 "no-create-home\0" No_argument "H" 134 189 "uid\0" Required_argument "u" 190 "skel\0" Required_argument "k" 135 191 ; 136 192 #endif … … 148 204 char *p; 149 205 unsigned opts; 206 char *uid; 207 const char *skel = "/etc/skel"; 150 208 151 209 #if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS … … 163 221 pw.pw_dir = NULL; 164 222 165 /* at most two non-option args */223 /* at least one and at most two non-option args */ 166 224 /* disable interactive passwd for system accounts */ 167 opt_complementary = "?2:SD:u+"; 168 if (sizeof(pw.pw_uid) == sizeof(int)) { 169 opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid); 170 } else { 171 unsigned uid; 172 opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid); 173 if (opts & OPT_UID) { 174 pw.pw_uid = uid; 175 } 176 } 225 opt_complementary = "-1:?2:SD"; 226 opts = getopt32(argv, "h:g:s:G:DSHu:k:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid, &skel); 227 if (opts & OPT_UID) 228 pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID); 229 177 230 argv += optind; 178 231 pw.pw_name = argv[0]; … … 253 306 }; 254 307 /* Be silent on any errors (like: no /etc/skel) */ 255 logmode = LOGMODE_NONE; 256 copy_file("/etc/skel", pw.pw_dir, FILEUTILS_RECUR); 308 if (!(opts & OPT_SKEL)) 309 logmode = LOGMODE_NONE; 310 copy_file(skel, pw.pw_dir, FILEUTILS_RECUR); 257 311 logmode = LOGMODE_STDIO; 258 312 chown_main(4, (char**)args);
Note:
See TracChangeset
for help on using the changeset viewer.