Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/oamuser/user/useradd.c
+++ new/usr/src/cmd/oamuser/user/useradd.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 + * Copyright (c) 2013 Gary Mills
23 + *
22 24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 25 * Use is subject to license terms.
24 26 */
25 27
26 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 29 /* All Rights Reserved */
28 30
29 31
30 32 #include <sys/types.h>
31 33 #include <sys/stat.h>
32 34 #include <sys/param.h>
33 35 #include <stdio.h>
34 36 #include <stdlib.h>
35 37 #include <ctype.h>
36 38 #include <limits.h>
37 39 #include <string.h>
38 40 #include <userdefs.h>
39 41 #include <errno.h>
40 42 #include <project.h>
41 43 #include <unistd.h>
42 44 #include <user_attr.h>
43 45 #include "users.h"
44 46 #include "messages.h"
45 47 #include "userdisp.h"
46 48 #include "funcs.h"
47 49
48 50 /*
49 51 * useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m]
50 52 * | -s shell | -c comment | -k skel_dir | -b base_dir] ]
51 53 * [ -A authorization [, authorization ...]]
52 54 * [ -P profile [, profile ...]]
53 55 * [ -K key=value ]
54 56 * [ -R role [, role ...]] [-p project [, project ...]] login
55 57 * useradd -D [ -g group ] [ -b base_dir | -f inactive | -e expire |
56 58 * -s shell | -k skel_dir ]
57 59 * [ -A authorization [, authorization ...]]
58 60 * [ -P profile [, profile ...]] [ -K key=value ]
59 61 * [ -R role [, role ...]] [-p project [, project ...]] login
60 62 *
61 63 * This command adds new user logins to the system. Arguments are:
62 64 *
63 65 * uid - an integer
64 66 * group - an existing group's integer ID or char string name
65 67 * dir - home directory
66 68 * shell - a program to be used as a shell
67 69 * comment - any text string
68 70 * skel_dir - a skeleton directory
69 71 * base_dir - a directory
70 72 * login - a string of printable chars except colon(:)
71 73 * authorization - One or more comma separated authorizations defined
72 74 * in auth_attr(4).
73 75 * profile - One or more comma separated execution profiles defined
74 76 * in prof_attr(4)
75 77 * role - One or more comma-separated role names defined in user_attr(4)
76 78 * project - One or more comma-separated project names or numbers
77 79 *
78 80 */
79 81
80 82 extern struct userdefs *getusrdef();
81 83 extern void dispusrdef();
82 84
83 85 static void cleanup();
84 86
85 87 extern uid_t findnextuid(void);
86 88 extern int check_perm(), valid_expire();
87 89 extern int putusrdef(), valid_uid();
88 90 extern int call_passmgmt(), edit_group(), create_home();
89 91 extern int edit_project();
90 92 extern int **valid_lgroup();
91 93 extern projid_t **valid_lproject();
92 94 extern void update_def(struct userdefs *);
93 95 extern void import_def(struct userdefs *);
94 96
95 97 static uid_t uid; /* new uid */
96 98 static char *logname; /* login name to add */
97 99 static struct userdefs *usrdefs; /* defaults for useradd */
98 100
99 101 char *cmdname;
100 102
101 103 static char homedir[ PATH_MAX + 1 ]; /* home directory */
102 104 static char gidstring[32]; /* group id string representation */
103 105 static gid_t gid; /* gid of new login */
104 106 static char uidstring[32]; /* user id string representation */
105 107 static char *uidstr = NULL; /* uid from command line */
106 108 static char *base_dir = NULL; /* base_dir from command line */
107 109 static char *group = NULL; /* group from command line */
108 110 static char *grps = NULL; /* multi groups from command line */
109 111 static char *dir = NULL; /* home dir from command line */
110 112 static char *shell = NULL; /* shell from command line */
111 113 static char *comment = NULL; /* comment from command line */
112 114 static char *skel_dir = NULL; /* skel dir from command line */
113 115 static long inact; /* inactive days */
114 116 static char *inactstr = NULL; /* inactive from command line */
115 117 static char inactstring[10]; /* inactivity string representation */
116 118 static char *expirestr = NULL; /* expiration date from command line */
117 119 static char *projects = NULL; /* project id's from command line */
118 120
119 121 static char *usertype = NULL; /* type of user, either role or normal */
120 122
121 123 typedef enum {
122 124 BASEDIR = 0,
123 125 SKELDIR,
124 126 SHELL
125 127 } path_opt_t;
126 128
127 129
128 130 static void valid_input(path_opt_t, const char *);
129 131
130 132 int
131 133 main(argc, argv)
132 134 int argc;
133 135 char *argv[];
134 136 {
135 137 int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist;
136 138 projid_t **projlist;
137 139 char *ptr; /* loc in a str, may be set by strtol */
138 140 struct group *g_ptr;
139 141 struct project p_ptr;
140 142 char mybuf[PROJECT_BUFSZ];
141 143 struct stat statbuf; /* status buffer for stat */
142 144 int warning;
143 145 int busy = 0;
144 146 char **nargv; /* arguments for execvp of passmgmt */
145 147 int argindex; /* argument index into nargv */
146 148
147 149 cmdname = argv[0];
148 150
149 151 if (geteuid() != 0) {
150 152 errmsg(M_PERM_DENIED);
151 153 exit(EX_NO_PERM);
152 154 }
153 155
154 156 opterr = 0; /* no print errors from getopt */
155 157 usertype = getusertype(argv[0]);
156 158
157 159 change_key(USERATTR_TYPE_KW, usertype);
158 160
159 161 while ((ch = getopt(argc, argv,
160 162 "b:c:Dd:e:f:G:g:k:mop:s:u:A:P:R:K:")) != EOF)
161 163 switch (ch) {
162 164 case 'b':
163 165 base_dir = optarg;
164 166 break;
165 167
166 168 case 'c':
167 169 comment = optarg;
168 170 break;
169 171
170 172 case 'D':
171 173 Dflag++;
172 174 break;
173 175
174 176 case 'd':
175 177 dir = optarg;
176 178 break;
177 179
178 180 case 'e':
179 181 expirestr = optarg;
180 182 break;
181 183
182 184 case 'f':
183 185 inactstr = optarg;
184 186 break;
185 187
186 188 case 'G':
187 189 grps = optarg;
188 190 break;
189 191
190 192 case 'g':
191 193 group = optarg;
192 194 break;
193 195
194 196 case 'k':
195 197 skel_dir = optarg;
196 198 break;
197 199
198 200 case 'm':
199 201 mflag++;
200 202 break;
201 203
202 204 case 'o':
203 205 oflag++;
204 206 break;
205 207
206 208 case 'p':
207 209 projects = optarg;
208 210 break;
209 211
210 212 case 's':
211 213 shell = optarg;
212 214 break;
213 215
214 216 case 'u':
215 217 uidstr = optarg;
216 218 break;
217 219
218 220 case 'A':
219 221 change_key(USERATTR_AUTHS_KW, optarg);
220 222 break;
221 223
222 224 case 'P':
223 225 change_key(USERATTR_PROFILES_KW, optarg);
224 226 break;
225 227
226 228 case 'R':
227 229 if (is_role(usertype)) {
228 230 errmsg(M_ARUSAGE);
229 231 exit(EX_SYNTAX);
230 232 }
231 233 change_key(USERATTR_ROLES_KW, optarg);
232 234 break;
233 235
234 236 case 'K':
235 237 change_key(NULL, optarg);
236 238 break;
237 239
238 240 default:
239 241 case '?':
240 242 if (is_role(usertype))
241 243 errmsg(M_ARUSAGE);
242 244 else
243 245 errmsg(M_AUSAGE);
244 246 exit(EX_SYNTAX);
245 247 }
246 248
247 249 /* get defaults for adding new users */
248 250 usrdefs = getusrdef(usertype);
249 251
250 252 if (Dflag) {
251 253 /* DISPLAY mode */
252 254
253 255 /* check syntax */
254 256 if (optind != argc) {
255 257 if (is_role(usertype))
256 258 errmsg(M_ARUSAGE);
257 259 else
258 260 errmsg(M_AUSAGE);
259 261 exit(EX_SYNTAX);
260 262 }
261 263
262 264 if (uidstr != NULL || oflag || grps != NULL ||
263 265 dir != NULL || mflag || comment != NULL) {
264 266 if (is_role(usertype))
265 267 errmsg(M_ARUSAGE);
266 268 else
267 269 errmsg(M_AUSAGE);
268 270 exit(EX_SYNTAX);
269 271 }
270 272
271 273 /* Group must be an existing group */
272 274 if (group != NULL) {
273 275 switch (valid_group(group, &g_ptr, &warning)) {
274 276 case INVALID:
275 277 errmsg(M_INVALID, group, "group id");
276 278 exit(EX_BADARG);
277 279 /*NOTREACHED*/
278 280 case TOOBIG:
279 281 errmsg(M_TOOBIG, "gid", group);
280 282 exit(EX_BADARG);
281 283 /*NOTREACHED*/
282 284 case RESERVED:
283 285 case UNIQUE:
284 286 errmsg(M_GRP_NOTUSED, group);
285 287 exit(EX_NAME_NOT_EXIST);
286 288 }
287 289 if (warning)
288 290 warningmsg(warning, group);
289 291
290 292 usrdefs->defgroup = g_ptr->gr_gid;
291 293 usrdefs->defgname = g_ptr->gr_name;
292 294
293 295 }
294 296
295 297 /* project must be an existing project */
296 298 if (projects != NULL) {
297 299 switch (valid_project(projects, &p_ptr, mybuf,
298 300 sizeof (mybuf), &warning)) {
299 301 case INVALID:
300 302 errmsg(M_INVALID, projects, "project id");
301 303 exit(EX_BADARG);
302 304 /*NOTREACHED*/
303 305 case TOOBIG:
304 306 errmsg(M_TOOBIG, "projid", projects);
305 307 exit(EX_BADARG);
306 308 /*NOTREACHED*/
307 309 case UNIQUE:
308 310 errmsg(M_PROJ_NOTUSED, projects);
309 311 exit(EX_NAME_NOT_EXIST);
310 312 }
311 313 if (warning)
312 314 warningmsg(warning, projects);
313 315
314 316 usrdefs->defproj = p_ptr.pj_projid;
315 317 usrdefs->defprojname = p_ptr.pj_name;
316 318 }
317 319
318 320 /* base_dir must be an existing directory */
319 321 if (base_dir != NULL) {
320 322 valid_input(BASEDIR, base_dir);
321 323 usrdefs->defparent = base_dir;
322 324 }
323 325
324 326 /* inactivity period is an integer */
325 327 if (inactstr != NULL) {
326 328 /* convert inactstr to integer */
327 329 inact = strtol(inactstr, &ptr, 10);
328 330 if (*ptr || inact < 0) {
329 331 errmsg(M_INVALID, inactstr,
330 332 "inactivity period");
331 333 exit(EX_BADARG);
332 334 }
333 335
334 336 usrdefs->definact = inact;
335 337 }
336 338
337 339 /* expiration string is a date, newer than today */
338 340 if (expirestr != NULL) {
339 341 if (*expirestr) {
340 342 if (valid_expire(expirestr, (time_t *)0)
341 343 == INVALID) {
342 344 errmsg(M_INVALID, expirestr,
343 345 "expiration date");
344 346 exit(EX_BADARG);
345 347 }
346 348 usrdefs->defexpire = expirestr;
347 349 } else
348 350 /* Unset the expiration date */
349 351 usrdefs->defexpire = "";
350 352 }
351 353
352 354 if (shell != NULL) {
353 355 valid_input(SHELL, shell);
354 356 usrdefs->defshell = shell;
355 357 }
356 358 if (skel_dir != NULL) {
357 359 valid_input(SKELDIR, skel_dir);
358 360 usrdefs->defskel = skel_dir;
359 361 }
360 362 update_def(usrdefs);
361 363
362 364 /* change defaults for useradd */
363 365 if (putusrdef(usrdefs, usertype) < 0) {
364 366 errmsg(M_UPDATE, "created");
365 367 exit(EX_UPDATE);
366 368 }
367 369
368 370 /* Now, display */
369 371 dispusrdef(stdout, (D_ALL & ~D_RID), usertype);
370 372 exit(EX_SUCCESS);
371 373
372 374 }
373 375
374 376 /* ADD mode */
375 377
376 378 /* check syntax */
377 379 if (optind != argc - 1 || (skel_dir != NULL && !mflag)) {
378 380 if (is_role(usertype))
379 381 errmsg(M_ARUSAGE);
380 382 else
381 383 errmsg(M_AUSAGE);
382 384 exit(EX_SYNTAX);
383 385 }
384 386
385 387 logname = argv[optind];
↓ open down ↓ |
354 lines elided |
↑ open up ↑ |
386 388 switch (valid_login(logname, (struct passwd **)NULL, &warning)) {
387 389 case INVALID:
388 390 errmsg(M_INVALID, logname, "login name");
389 391 exit(EX_BADARG);
390 392 /*NOTREACHED*/
391 393
392 394 case NOTUNIQUE:
393 395 errmsg(M_USED, logname);
394 396 exit(EX_NAME_EXISTS);
395 397 /*NOTREACHED*/
398 +
399 + case LONGNAME:
400 + errmsg(M_TOO_LONG, logname);
401 + exit(EX_BADARG);
402 + /*NOTREACHED*/
396 403 }
397 404
398 405 if (warning)
399 406 warningmsg(warning, logname);
400 407 if (uidstr != NULL) {
401 408 /* convert uidstr to integer */
402 409 errno = 0;
403 410 uid = (uid_t)strtol(uidstr, &ptr, (int)10);
404 411 if (*ptr || errno == ERANGE) {
405 412 errmsg(M_INVALID, uidstr, "user id");
406 413 exit(EX_BADARG);
407 414 }
408 415
409 416 switch (valid_uid(uid, NULL)) {
410 417 case NOTUNIQUE:
411 418 if (!oflag) {
412 419 /* override not specified */
413 420 errmsg(M_UID_USED, uid);
414 421 exit(EX_ID_EXISTS);
415 422 }
416 423 break;
417 424 case RESERVED:
418 425 errmsg(M_RESERVED, uid);
419 426 break;
420 427 case TOOBIG:
421 428 errmsg(M_TOOBIG, "uid", uid);
422 429 exit(EX_BADARG);
423 430 break;
424 431 }
425 432
426 433 } else {
427 434
428 435 if ((uid = findnextuid()) < 0) {
429 436 errmsg(M_INVALID, "default id", "user id");
430 437 exit(EX_ID_EXISTS);
431 438 }
432 439 }
433 440
434 441 if (group != NULL) {
435 442 switch (valid_group(group, &g_ptr, &warning)) {
436 443 case INVALID:
437 444 errmsg(M_INVALID, group, "group id");
438 445 exit(EX_BADARG);
439 446 /*NOTREACHED*/
440 447 case TOOBIG:
441 448 errmsg(M_TOOBIG, "gid", group);
442 449 exit(EX_BADARG);
443 450 /*NOTREACHED*/
444 451 case RESERVED:
445 452 case UNIQUE:
446 453 errmsg(M_GRP_NOTUSED, group);
447 454 exit(EX_NAME_NOT_EXIST);
448 455 /*NOTREACHED*/
449 456 }
450 457
451 458 if (warning)
452 459 warningmsg(warning, group);
453 460 gid = g_ptr->gr_gid;
454 461
455 462 } else gid = usrdefs->defgroup;
456 463
457 464 if (grps != NULL) {
458 465 if (!*grps)
459 466 /* ignore -G "" */
460 467 grps = (char *)0;
461 468 else if (!(gidlist = valid_lgroup(grps, gid)))
462 469 exit(EX_BADARG);
463 470 }
464 471
465 472 if (projects != NULL) {
466 473 if (! *projects)
467 474 projects = (char *)0;
468 475 else if (! (projlist = valid_lproject(projects)))
469 476 exit(EX_BADARG);
470 477 }
471 478
472 479 /* if base_dir is provided, check its validity; otherwise default */
473 480 if (base_dir != NULL)
474 481 valid_input(BASEDIR, base_dir);
475 482 else
476 483 base_dir = usrdefs->defparent;
477 484
478 485 if (dir == NULL) {
479 486 /* set homedir to home directory made from base_dir */
480 487 (void) sprintf(homedir, "%s/%s", base_dir, logname);
481 488
482 489 } else if (REL_PATH(dir)) {
483 490 errmsg(M_RELPATH, dir);
484 491 exit(EX_BADARG);
485 492
486 493 } else
487 494 (void) strcpy(homedir, dir);
488 495
489 496 if (mflag) {
490 497 /* Does home dir. already exist? */
491 498 if (stat(homedir, &statbuf) == 0) {
492 499 /* directory exists - don't try to create */
493 500 mflag = 0;
494 501
495 502 if (check_perm(statbuf, uid, gid, S_IXOTH) != 0)
496 503 errmsg(M_NO_PERM, logname, homedir);
497 504 }
498 505 }
499 506 /*
500 507 * if shell, skel_dir are provided, check their validity.
501 508 * Otherwise default.
502 509 */
503 510 if (shell != NULL)
504 511 valid_input(SHELL, shell);
505 512 else
506 513 shell = usrdefs->defshell;
507 514
508 515 if (skel_dir != NULL)
509 516 valid_input(SKELDIR, skel_dir);
510 517 else
511 518 skel_dir = usrdefs->defskel;
512 519
513 520 if (inactstr != NULL) {
514 521 /* convert inactstr to integer */
515 522 inact = strtol(inactstr, &ptr, 10);
516 523 if (*ptr || inact < 0) {
517 524 errmsg(M_INVALID, inactstr, "inactivity period");
518 525 exit(EX_BADARG);
519 526 }
520 527 } else inact = usrdefs->definact;
521 528
522 529 /* expiration string is a date, newer than today */
523 530 if (expirestr != NULL) {
524 531 if (*expirestr) {
525 532 if (valid_expire(expirestr, (time_t *)0) == INVALID) {
526 533 errmsg(M_INVALID, expirestr, "expiration date");
527 534 exit(EX_BADARG);
528 535 }
529 536 usrdefs->defexpire = expirestr;
530 537 } else
531 538 /* Unset the expiration date */
532 539 expirestr = (char *)0;
533 540
534 541 } else expirestr = usrdefs->defexpire;
535 542
536 543 import_def(usrdefs);
537 544
538 545 /* must now call passmgmt */
539 546
540 547 /* set up arguments to passmgmt in nargv array */
541 548 nargv = malloc((30 + nkeys * 2) * sizeof (char *));
542 549 argindex = 0;
543 550 nargv[argindex++] = PASSMGMT;
544 551 nargv[argindex++] = "-a"; /* add */
545 552
546 553 if (comment != NULL) {
547 554 /* comment */
548 555 nargv[argindex++] = "-c";
549 556 nargv[argindex++] = comment;
550 557 }
551 558
552 559 /* flags for home directory */
553 560 nargv[argindex++] = "-h";
554 561 nargv[argindex++] = homedir;
555 562
556 563 /* set gid flag */
557 564 nargv[argindex++] = "-g";
558 565 (void) sprintf(gidstring, "%u", gid);
559 566 nargv[argindex++] = gidstring;
560 567
561 568 /* shell */
562 569 nargv[argindex++] = "-s";
563 570 nargv[argindex++] = shell;
564 571
565 572 /* set inactive */
566 573 nargv[argindex++] = "-f";
567 574 (void) sprintf(inactstring, "%ld", inact);
568 575 nargv[argindex++] = inactstring;
569 576
570 577 /* set expiration date */
571 578 if (expirestr != NULL) {
572 579 nargv[argindex++] = "-e";
573 580 nargv[argindex++] = expirestr;
574 581 }
575 582
576 583 /* set uid flag */
577 584 nargv[argindex++] = "-u";
578 585 (void) sprintf(uidstring, "%u", uid);
579 586 nargv[argindex++] = uidstring;
580 587
581 588 if (oflag) nargv[argindex++] = "-o";
582 589
583 590 if (nkeys > 1)
584 591 addkey_args(nargv, &argindex);
585 592
586 593 /* finally - login name */
587 594 nargv[argindex++] = logname;
588 595
589 596 /* set the last to null */
590 597 nargv[argindex++] = NULL;
591 598
592 599 /* now call passmgmt */
593 600 ret = PEX_FAILED;
594 601 /*
595 602 * If call_passmgmt fails for any reason other than PEX_BADUID, exit
596 603 * is invoked with an appropriate error message. If PEX_BADUID is
597 604 * returned, then if the user specified the ID, exit is invoked
598 605 * with an appropriate error message. Otherwise we try to pick a
599 606 * different ID and try again. If we run out of IDs, i.e. no more
600 607 * users can be created, then -1 is returned and we terminate via exit.
601 608 * If PEX_BUSY is returned we increment a count, since we will stop
602 609 * trying if PEX_BUSY reaches 3. For PEX_SUCCESS we immediately
603 610 * terminate the loop.
604 611 */
605 612 while (busy < 3 && ret != PEX_SUCCESS) {
606 613 switch (ret = call_passmgmt(nargv)) {
607 614 case PEX_SUCCESS:
608 615 break;
609 616 case PEX_BUSY:
610 617 busy++;
611 618 break;
612 619 case PEX_HOSED_FILES:
613 620 errmsg(M_HOSED_FILES);
614 621 exit(EX_INCONSISTENT);
615 622 break;
616 623
617 624 case PEX_SYNTAX:
618 625 case PEX_BADARG:
619 626 /* should NEVER occur that passmgmt usage is wrong */
620 627 if (is_role(usertype))
621 628 errmsg(M_ARUSAGE);
622 629 else
623 630 errmsg(M_AUSAGE);
624 631 exit(EX_SYNTAX);
625 632 break;
626 633
627 634 case PEX_BADUID:
628 635 /*
629 636 * The uid has been taken. If it was specified by a
630 637 * user, then we must fail. Otherwise, keep trying
631 638 * to get a good uid until we run out of IDs.
632 639 */
633 640 if (uidstr != NULL) {
634 641 errmsg(M_UID_USED, uid);
635 642 exit(EX_ID_EXISTS);
636 643 } else {
637 644 if ((uid = findnextuid()) < 0) {
638 645 errmsg(M_INVALID, "default id",
639 646 "user id");
640 647 exit(EX_ID_EXISTS);
641 648 }
642 649 (void) sprintf(uidstring, "%u", uid);
643 650 }
644 651 break;
645 652
646 653 case PEX_BADNAME:
647 654 /* invalid loname */
648 655 errmsg(M_USED, logname);
649 656 exit(EX_NAME_EXISTS);
650 657 break;
651 658
652 659 default:
653 660 errmsg(M_UPDATE, "created");
654 661 exit(ret);
655 662 break;
656 663 }
657 664 }
658 665 if (busy == 3) {
659 666 errmsg(M_UPDATE, "created");
660 667 exit(ret);
661 668 }
662 669
663 670 /* add group entry */
664 671 if ((grps != NULL) && edit_group(logname, (char *)0, gidlist, 0)) {
665 672 errmsg(M_UPDATE, "created");
666 673 cleanup(logname);
667 674 exit(EX_UPDATE);
668 675 }
669 676
670 677 /* update project database */
671 678 if ((projects != NULL) &&
672 679 edit_project(logname, (char *)NULL, projlist, 0)) {
673 680 errmsg(M_UPDATE, "created");
674 681 cleanup(logname);
675 682 exit(EX_UPDATE);
676 683 }
677 684
678 685 /* create home directory */
679 686 if (mflag &&
680 687 (create_home(homedir, skel_dir, uid, gid) != EX_SUCCESS)) {
681 688 (void) edit_group(logname, (char *)0, (int **)0, 1);
682 689 cleanup(logname);
683 690 exit(EX_HOMEDIR);
684 691 }
685 692
686 693 return (ret);
687 694 }
688 695
689 696 static void
690 697 cleanup(logname)
691 698 char *logname;
692 699 {
693 700 char *nargv[4];
694 701
695 702 nargv[0] = PASSMGMT;
696 703 nargv[1] = "-d";
697 704 nargv[2] = logname;
698 705 nargv[3] = NULL;
699 706
700 707 switch (call_passmgmt(nargv)) {
701 708 case PEX_SUCCESS:
702 709 break;
703 710
704 711 case PEX_SYNTAX:
705 712 /* should NEVER occur that passmgmt usage is wrong */
706 713 if (is_role(usertype))
707 714 errmsg(M_ARUSAGE);
708 715 else
709 716 errmsg(M_AUSAGE);
710 717 break;
711 718
712 719 case PEX_BADUID:
713 720 /* uid is used - shouldn't happen but print message anyway */
714 721 errmsg(M_UID_USED, uid);
715 722 break;
716 723
717 724 case PEX_BADNAME:
718 725 /* invalid loname */
719 726 errmsg(M_USED, logname);
720 727 break;
721 728
722 729 default:
723 730 errmsg(M_UPDATE, "created");
724 731 break;
725 732 }
726 733 }
727 734
728 735 /* Check the validity for shell, base_dir and skel_dir */
729 736
730 737 void
731 738 valid_input(path_opt_t opt, const char *input)
732 739 {
733 740 struct stat statbuf;
734 741
735 742 if (REL_PATH(input)) {
736 743 errmsg(M_RELPATH, input);
737 744 exit(EX_BADARG);
738 745 }
739 746 if (stat(input, &statbuf) == -1) {
740 747 errmsg(M_INVALID, input, "path");
741 748 exit(EX_BADARG);
742 749 }
743 750 if (opt == SHELL) {
744 751 if (!S_ISREG(statbuf.st_mode) ||
745 752 (statbuf.st_mode & 0555) != 0555) {
746 753 errmsg(M_INVALID, input, "shell");
747 754 exit(EX_BADARG);
748 755 }
749 756 } else {
750 757 if (!S_ISDIR(statbuf.st_mode)) {
751 758 errmsg(M_INVALID, input, "directory");
752 759 exit(EX_BADARG);
753 760 }
754 761 }
755 762 }
↓ open down ↓ |
350 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX