diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /loginutils/adduser.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'loginutils/adduser.c')
-rw-r--r-- | loginutils/adduser.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c index 3485611cc..cfaf860e0 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c | |||
@@ -66,7 +66,7 @@ static int passwd_study(const char *filename, struct passwd *p) | |||
66 | const int min = 500; | 66 | const int min = 500; |
67 | const int max = 65000; | 67 | const int max = 65000; |
68 | 68 | ||
69 | passwd = wfopen(filename, "r"); | 69 | passwd = bb_wfopen(filename, "r"); |
70 | if (!passwd) | 70 | if (!passwd) |
71 | return 4; | 71 | return 4; |
72 | 72 | ||
@@ -112,7 +112,7 @@ static void addgroup_wrapper(const char *login, gid_t gid) | |||
112 | { | 112 | { |
113 | char *cmd; | 113 | char *cmd; |
114 | 114 | ||
115 | bb_asprintf(&cmd, "addgroup -g %d %s", gid, login); | 115 | bb_xasprintf(&cmd, "addgroup -g %d %s", gid, login); |
116 | system(cmd); | 116 | system(cmd); |
117 | free(cmd); | 117 | free(cmd); |
118 | } | 118 | } |
@@ -123,7 +123,7 @@ static void passwd_wrapper(const char *login) | |||
123 | { | 123 | { |
124 | static const char prog[] = "passwd"; | 124 | static const char prog[] = "passwd"; |
125 | execlp(prog, prog, login, NULL); | 125 | execlp(prog, prog, login, NULL); |
126 | error_msg_and_die("Failed to execute '%s', you must set the password for '%s' manually", prog, login); | 126 | bb_error_msg_and_die("Failed to execute '%s', you must set the password for '%s' manually", prog, login); |
127 | } | 127 | } |
128 | 128 | ||
129 | /* putpwent(3) remix */ | 129 | /* putpwent(3) remix */ |
@@ -137,7 +137,7 @@ static int adduser(const char *filename, struct passwd *p) | |||
137 | #endif | 137 | #endif |
138 | 138 | ||
139 | /* make sure everything is kosher and setup uid && gid */ | 139 | /* make sure everything is kosher and setup uid && gid */ |
140 | passwd = wfopen(filename, "a"); | 140 | passwd = bb_wfopen(filename, "a"); |
141 | if (passwd == NULL) { | 141 | if (passwd == NULL) { |
142 | return 1; | 142 | return 1; |
143 | } | 143 | } |
@@ -147,13 +147,13 @@ static int adduser(const char *filename, struct passwd *p) | |||
147 | r = passwd_study(filename, p); | 147 | r = passwd_study(filename, p); |
148 | if (r) { | 148 | if (r) { |
149 | if (r == 1) | 149 | if (r == 1) |
150 | error_msg("%s: login already in use", p->pw_name); | 150 | bb_error_msg("%s: login already in use", p->pw_name); |
151 | else if (r == 2) | 151 | else if (r == 2) |
152 | error_msg("illegal uid or no uids left"); | 152 | bb_error_msg("illegal uid or no uids left"); |
153 | else if (r == 3) | 153 | else if (r == 3) |
154 | error_msg("group name %s already in use", p->pw_name); | 154 | bb_error_msg("group name %s already in use", p->pw_name); |
155 | else | 155 | else |
156 | error_msg("generic error."); | 156 | bb_error_msg("generic error."); |
157 | return 1; | 157 | return 1; |
158 | } | 158 | } |
159 | 159 | ||
@@ -166,7 +166,7 @@ static int adduser(const char *filename, struct passwd *p) | |||
166 | #ifdef CONFIG_FEATURE_SHADOWPASSWDS | 166 | #ifdef CONFIG_FEATURE_SHADOWPASSWDS |
167 | /* add to shadow if necessary */ | 167 | /* add to shadow if necessary */ |
168 | if (shadow_enabled) { | 168 | if (shadow_enabled) { |
169 | shadow = wfopen(shadow_file, "a"); | 169 | shadow = bb_wfopen(bb_path_shadow_file, "a"); |
170 | if (shadow == NULL) { | 170 | if (shadow == NULL) { |
171 | return 1; | 171 | return 1; |
172 | } | 172 | } |
@@ -191,16 +191,16 @@ static int adduser(const char *filename, struct passwd *p) | |||
191 | 191 | ||
192 | /* mkdir */ | 192 | /* mkdir */ |
193 | if (mkdir(p->pw_dir, 0755)) { | 193 | if (mkdir(p->pw_dir, 0755)) { |
194 | perror_msg("%s", p->pw_dir); | 194 | bb_perror_msg("%s", p->pw_dir); |
195 | } | 195 | } |
196 | /* Set the owner and group so it is owned by the new user. */ | 196 | /* Set the owner and group so it is owned by the new user. */ |
197 | if (chown(p->pw_dir, p->pw_uid, p->pw_gid)) { | 197 | if (chown(p->pw_dir, p->pw_uid, p->pw_gid)) { |
198 | perror_msg("%s", p->pw_dir); | 198 | bb_perror_msg("%s", p->pw_dir); |
199 | } | 199 | } |
200 | /* Now fix up the permissions to 2755. Can't do it before now | 200 | /* Now fix up the permissions to 2755. Can't do it before now |
201 | * since chown will clear the setgid bit */ | 201 | * since chown will clear the setgid bit */ |
202 | if (chmod(p->pw_dir, 02755)) { | 202 | if (chmod(p->pw_dir, 02755)) { |
203 | perror_msg("%s", p->pw_dir); | 203 | bb_perror_msg("%s", p->pw_dir); |
204 | } | 204 | } |
205 | /* interactively set passwd */ | 205 | /* interactively set passwd */ |
206 | passwd_wrapper(p->pw_name); | 206 | passwd_wrapper(p->pw_name); |
@@ -234,7 +234,7 @@ int adduser_main(int argc, char **argv) | |||
234 | 234 | ||
235 | /* init */ | 235 | /* init */ |
236 | if (argc < 2) { | 236 | if (argc < 2) { |
237 | show_usage(); | 237 | bb_show_usage(); |
238 | } | 238 | } |
239 | gecos = default_gecos; | 239 | gecos = default_gecos; |
240 | shell = default_shell; | 240 | shell = default_shell; |
@@ -252,18 +252,18 @@ int adduser_main(int argc, char **argv) | |||
252 | shell = optarg; | 252 | shell = optarg; |
253 | break; | 253 | break; |
254 | default: | 254 | default: |
255 | show_usage (); | 255 | bb_show_usage(); |
256 | break; | 256 | break; |
257 | } | 257 | } |
258 | 258 | ||
259 | /* got root? */ | 259 | /* got root? */ |
260 | if (i_am_not_root()) { | 260 | if (i_am_not_root()) { |
261 | error_msg_and_die( "Only root may add a user or group to the system."); | 261 | bb_error_msg_and_die( "Only root may add a user or group to the system."); |
262 | } | 262 | } |
263 | 263 | ||
264 | /* get login */ | 264 | /* get login */ |
265 | if (optind >= argc) { | 265 | if (optind >= argc) { |
266 | error_msg_and_die( "no user specified"); | 266 | bb_error_msg_and_die( "no user specified"); |
267 | } | 267 | } |
268 | login = argv[optind]; | 268 | login = argv[optind]; |
269 | 269 | ||
@@ -273,7 +273,7 @@ int adduser_main(int argc, char **argv) | |||
273 | } | 273 | } |
274 | #ifdef CONFIG_FEATURE_SHADOWPASSWDS | 274 | #ifdef CONFIG_FEATURE_SHADOWPASSWDS |
275 | /* is /etc/shadow in use? */ | 275 | /* is /etc/shadow in use? */ |
276 | shadow_enabled = (0 == access(shadow_file, F_OK)); | 276 | shadow_enabled = (0 == access(bb_path_shadow_file, F_OK)); |
277 | #endif | 277 | #endif |
278 | 278 | ||
279 | /* create a passwd struct */ | 279 | /* create a passwd struct */ |
@@ -286,7 +286,7 @@ int adduser_main(int argc, char **argv) | |||
286 | pw.pw_shell = (char *)shell; | 286 | pw.pw_shell = (char *)shell; |
287 | 287 | ||
288 | /* grand finale */ | 288 | /* grand finale */ |
289 | return adduser(passwd_file, &pw); | 289 | return adduser(bb_path_passwd_file, &pw); |
290 | } | 290 | } |
291 | 291 | ||
292 | /* $Id: adduser.c,v 1.4 2002/09/16 06:22:24 andersen Exp $ */ | 292 | /* $Id: adduser.c,v 1.5 2003/03/19 09:12:20 mjn3 Exp $ */ |