17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50523b0a4Sbasabi * Common Development and Distribution License (the "License").
60523b0a4Sbasabi * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*0a1278f2SGary Mills * Copyright (c) 2013 Gary Mills
23*0a1278f2SGary Mills *
24c651b32eSJohn Sonnenschein * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate
31a7fe1d5bSAndy Stormont /*
32a7fe1d5bSAndy Stormont * Copyright (c) 2013 RackTop Systems.
33a7fe1d5bSAndy Stormont */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/stat.h>
377c478bd9Sstevel@tonic-gate #include <sys/param.h>
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <stdlib.h>
407c478bd9Sstevel@tonic-gate #include <ctype.h>
417c478bd9Sstevel@tonic-gate #include <limits.h>
427c478bd9Sstevel@tonic-gate #include <string.h>
437c478bd9Sstevel@tonic-gate #include <userdefs.h>
447c478bd9Sstevel@tonic-gate #include <errno.h>
457c478bd9Sstevel@tonic-gate #include <project.h>
467c478bd9Sstevel@tonic-gate #include <unistd.h>
477c478bd9Sstevel@tonic-gate #include <user_attr.h>
48a7fe1d5bSAndy Stormont #include <libcmdutils.h>
497c478bd9Sstevel@tonic-gate #include "users.h"
507c478bd9Sstevel@tonic-gate #include "messages.h"
517c478bd9Sstevel@tonic-gate #include "userdisp.h"
527c478bd9Sstevel@tonic-gate #include "funcs.h"
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate * useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m]
560523b0a4Sbasabi * | -s shell | -c comment | -k skel_dir | -b base_dir] ]
577c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]]
587c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]]
597c478bd9Sstevel@tonic-gate * [ -K key=value ]
607c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login
610523b0a4Sbasabi * useradd -D [ -g group ] [ -b base_dir | -f inactive | -e expire |
620523b0a4Sbasabi * -s shell | -k skel_dir ]
637c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]]
647c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]] [ -K key=value ]
657c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login
667c478bd9Sstevel@tonic-gate *
677c478bd9Sstevel@tonic-gate * This command adds new user logins to the system. Arguments are:
687c478bd9Sstevel@tonic-gate *
697c478bd9Sstevel@tonic-gate * uid - an integer
707c478bd9Sstevel@tonic-gate * group - an existing group's integer ID or char string name
717c478bd9Sstevel@tonic-gate * dir - home directory
727c478bd9Sstevel@tonic-gate * shell - a program to be used as a shell
737c478bd9Sstevel@tonic-gate * comment - any text string
747c478bd9Sstevel@tonic-gate * skel_dir - a skeleton directory
757c478bd9Sstevel@tonic-gate * base_dir - a directory
767c478bd9Sstevel@tonic-gate * login - a string of printable chars except colon(:)
777c478bd9Sstevel@tonic-gate * authorization - One or more comma separated authorizations defined
787c478bd9Sstevel@tonic-gate * in auth_attr(4).
797c478bd9Sstevel@tonic-gate * profile - One or more comma separated execution profiles defined
807c478bd9Sstevel@tonic-gate * in prof_attr(4)
817c478bd9Sstevel@tonic-gate * role - One or more comma-separated role names defined in user_attr(4)
827c478bd9Sstevel@tonic-gate * project - One or more comma-separated project names or numbers
837c478bd9Sstevel@tonic-gate *
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate extern struct userdefs *getusrdef();
877c478bd9Sstevel@tonic-gate extern void dispusrdef();
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static void cleanup();
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate extern int check_perm(), valid_expire();
927c478bd9Sstevel@tonic-gate extern int putusrdef(), valid_uid();
937c478bd9Sstevel@tonic-gate extern int call_passmgmt(), edit_group(), create_home();
947c478bd9Sstevel@tonic-gate extern int edit_project();
957c478bd9Sstevel@tonic-gate extern int **valid_lgroup();
967c478bd9Sstevel@tonic-gate extern projid_t **valid_lproject();
977c478bd9Sstevel@tonic-gate extern void update_def(struct userdefs *);
987c478bd9Sstevel@tonic-gate extern void import_def(struct userdefs *);
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate static uid_t uid; /* new uid */
1017c478bd9Sstevel@tonic-gate static char *logname; /* login name to add */
1027c478bd9Sstevel@tonic-gate static struct userdefs *usrdefs; /* defaults for useradd */
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate char *cmdname;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate static char homedir[ PATH_MAX + 1 ]; /* home directory */
1077c478bd9Sstevel@tonic-gate static char gidstring[32]; /* group id string representation */
1087c478bd9Sstevel@tonic-gate static gid_t gid; /* gid of new login */
1097c478bd9Sstevel@tonic-gate static char uidstring[32]; /* user id string representation */
1107c478bd9Sstevel@tonic-gate static char *uidstr = NULL; /* uid from command line */
1117c478bd9Sstevel@tonic-gate static char *base_dir = NULL; /* base_dir from command line */
1127c478bd9Sstevel@tonic-gate static char *group = NULL; /* group from command line */
1137c478bd9Sstevel@tonic-gate static char *grps = NULL; /* multi groups from command line */
1147c478bd9Sstevel@tonic-gate static char *dir = NULL; /* home dir from command line */
1157c478bd9Sstevel@tonic-gate static char *shell = NULL; /* shell from command line */
1167c478bd9Sstevel@tonic-gate static char *comment = NULL; /* comment from command line */
1177c478bd9Sstevel@tonic-gate static char *skel_dir = NULL; /* skel dir from command line */
1187c478bd9Sstevel@tonic-gate static long inact; /* inactive days */
1197c478bd9Sstevel@tonic-gate static char *inactstr = NULL; /* inactive from command line */
1207c478bd9Sstevel@tonic-gate static char inactstring[10]; /* inactivity string representation */
1217c478bd9Sstevel@tonic-gate static char *expirestr = NULL; /* expiration date from command line */
1227c478bd9Sstevel@tonic-gate static char *projects = NULL; /* project id's from command line */
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate static char *usertype = NULL; /* type of user, either role or normal */
1257c478bd9Sstevel@tonic-gate
1260523b0a4Sbasabi typedef enum {
1270523b0a4Sbasabi BASEDIR = 0,
1280523b0a4Sbasabi SKELDIR,
1290523b0a4Sbasabi SHELL
1300523b0a4Sbasabi } path_opt_t;
1310523b0a4Sbasabi
1320523b0a4Sbasabi
1330523b0a4Sbasabi static void valid_input(path_opt_t, const char *);
1340523b0a4Sbasabi
1357c478bd9Sstevel@tonic-gate int
main(argc,argv)1367c478bd9Sstevel@tonic-gate main(argc, argv)
1377c478bd9Sstevel@tonic-gate int argc;
1387c478bd9Sstevel@tonic-gate char *argv[];
1397c478bd9Sstevel@tonic-gate {
140a7fe1d5bSAndy Stormont int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
141a7fe1d5bSAndy Stormont projid_t **projlist = NULL;
1427c478bd9Sstevel@tonic-gate char *ptr; /* loc in a str, may be set by strtol */
1437c478bd9Sstevel@tonic-gate struct group *g_ptr;
1447c478bd9Sstevel@tonic-gate struct project p_ptr;
1457c478bd9Sstevel@tonic-gate char mybuf[PROJECT_BUFSZ];
1467c478bd9Sstevel@tonic-gate struct stat statbuf; /* status buffer for stat */
1477c478bd9Sstevel@tonic-gate int warning;
1487c478bd9Sstevel@tonic-gate int busy = 0;
1497c478bd9Sstevel@tonic-gate char **nargv; /* arguments for execvp of passmgmt */
1507c478bd9Sstevel@tonic-gate int argindex; /* argument index into nargv */
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate cmdname = argv[0];
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if (geteuid() != 0) {
1557c478bd9Sstevel@tonic-gate errmsg(M_PERM_DENIED);
1567c478bd9Sstevel@tonic-gate exit(EX_NO_PERM);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate opterr = 0; /* no print errors from getopt */
1607c478bd9Sstevel@tonic-gate usertype = getusertype(argv[0]);
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate change_key(USERATTR_TYPE_KW, usertype);
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate while ((ch = getopt(argc, argv,
1657c478bd9Sstevel@tonic-gate "b:c:Dd:e:f:G:g:k:mop:s:u:A:P:R:K:")) != EOF)
1667c478bd9Sstevel@tonic-gate switch (ch) {
1677c478bd9Sstevel@tonic-gate case 'b':
1687c478bd9Sstevel@tonic-gate base_dir = optarg;
1697c478bd9Sstevel@tonic-gate break;
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate case 'c':
1727c478bd9Sstevel@tonic-gate comment = optarg;
1737c478bd9Sstevel@tonic-gate break;
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate case 'D':
1767c478bd9Sstevel@tonic-gate Dflag++;
1777c478bd9Sstevel@tonic-gate break;
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate case 'd':
1807c478bd9Sstevel@tonic-gate dir = optarg;
1817c478bd9Sstevel@tonic-gate break;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate case 'e':
1847c478bd9Sstevel@tonic-gate expirestr = optarg;
1857c478bd9Sstevel@tonic-gate break;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate case 'f':
1887c478bd9Sstevel@tonic-gate inactstr = optarg;
1897c478bd9Sstevel@tonic-gate break;
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate case 'G':
1927c478bd9Sstevel@tonic-gate grps = optarg;
1937c478bd9Sstevel@tonic-gate break;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate case 'g':
1967c478bd9Sstevel@tonic-gate group = optarg;
1977c478bd9Sstevel@tonic-gate break;
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate case 'k':
2007c478bd9Sstevel@tonic-gate skel_dir = optarg;
2017c478bd9Sstevel@tonic-gate break;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate case 'm':
2047c478bd9Sstevel@tonic-gate mflag++;
2057c478bd9Sstevel@tonic-gate break;
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate case 'o':
2087c478bd9Sstevel@tonic-gate oflag++;
2097c478bd9Sstevel@tonic-gate break;
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate case 'p':
2127c478bd9Sstevel@tonic-gate projects = optarg;
2137c478bd9Sstevel@tonic-gate break;
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate case 's':
2167c478bd9Sstevel@tonic-gate shell = optarg;
2177c478bd9Sstevel@tonic-gate break;
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate case 'u':
2207c478bd9Sstevel@tonic-gate uidstr = optarg;
2217c478bd9Sstevel@tonic-gate break;
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate case 'A':
2247c478bd9Sstevel@tonic-gate change_key(USERATTR_AUTHS_KW, optarg);
2257c478bd9Sstevel@tonic-gate break;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate case 'P':
2287c478bd9Sstevel@tonic-gate change_key(USERATTR_PROFILES_KW, optarg);
2297c478bd9Sstevel@tonic-gate break;
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate case 'R':
2327c478bd9Sstevel@tonic-gate if (is_role(usertype)) {
2337c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
2347c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate change_key(USERATTR_ROLES_KW, optarg);
2377c478bd9Sstevel@tonic-gate break;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate case 'K':
2407c478bd9Sstevel@tonic-gate change_key(NULL, optarg);
2417c478bd9Sstevel@tonic-gate break;
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate default:
2447c478bd9Sstevel@tonic-gate case '?':
2457c478bd9Sstevel@tonic-gate if (is_role(usertype))
2467c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
2477c478bd9Sstevel@tonic-gate else
2487c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
2497c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate /* get defaults for adding new users */
2537c478bd9Sstevel@tonic-gate usrdefs = getusrdef(usertype);
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate if (Dflag) {
2567c478bd9Sstevel@tonic-gate /* DISPLAY mode */
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate /* check syntax */
2597c478bd9Sstevel@tonic-gate if (optind != argc) {
2607c478bd9Sstevel@tonic-gate if (is_role(usertype))
2617c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
2627c478bd9Sstevel@tonic-gate else
2637c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
2647c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2670523b0a4Sbasabi if (uidstr != NULL || oflag || grps != NULL ||
2680523b0a4Sbasabi dir != NULL || mflag || comment != NULL) {
2697c478bd9Sstevel@tonic-gate if (is_role(usertype))
2707c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
2717c478bd9Sstevel@tonic-gate else
2727c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
2737c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /* Group must be an existing group */
2770523b0a4Sbasabi if (group != NULL) {
2787c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) {
2797c478bd9Sstevel@tonic-gate case INVALID:
2807c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id");
2817c478bd9Sstevel@tonic-gate exit(EX_BADARG);
2827c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2837c478bd9Sstevel@tonic-gate case TOOBIG:
2847c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group);
2857c478bd9Sstevel@tonic-gate exit(EX_BADARG);
2867c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2877c478bd9Sstevel@tonic-gate case RESERVED:
2887c478bd9Sstevel@tonic-gate case UNIQUE:
2897c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group);
2907c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate if (warning)
2937c478bd9Sstevel@tonic-gate warningmsg(warning, group);
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate usrdefs->defgroup = g_ptr->gr_gid;
2967c478bd9Sstevel@tonic-gate usrdefs->defgname = g_ptr->gr_name;
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate /* project must be an existing project */
3010523b0a4Sbasabi if (projects != NULL) {
3027c478bd9Sstevel@tonic-gate switch (valid_project(projects, &p_ptr, mybuf,
3037c478bd9Sstevel@tonic-gate sizeof (mybuf), &warning)) {
3047c478bd9Sstevel@tonic-gate case INVALID:
3057c478bd9Sstevel@tonic-gate errmsg(M_INVALID, projects, "project id");
3067c478bd9Sstevel@tonic-gate exit(EX_BADARG);
3077c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3087c478bd9Sstevel@tonic-gate case TOOBIG:
3097c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "projid", projects);
3107c478bd9Sstevel@tonic-gate exit(EX_BADARG);
3117c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3127c478bd9Sstevel@tonic-gate case UNIQUE:
3137c478bd9Sstevel@tonic-gate errmsg(M_PROJ_NOTUSED, projects);
3147c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate if (warning)
3177c478bd9Sstevel@tonic-gate warningmsg(warning, projects);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate usrdefs->defproj = p_ptr.pj_projid;
3207c478bd9Sstevel@tonic-gate usrdefs->defprojname = p_ptr.pj_name;
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate /* base_dir must be an existing directory */
3240523b0a4Sbasabi if (base_dir != NULL) {
3250523b0a4Sbasabi valid_input(BASEDIR, base_dir);
3267c478bd9Sstevel@tonic-gate usrdefs->defparent = base_dir;
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /* inactivity period is an integer */
3300523b0a4Sbasabi if (inactstr != NULL) {
3317c478bd9Sstevel@tonic-gate /* convert inactstr to integer */
3327c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10);
3337c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) {
3347c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr,
3357c478bd9Sstevel@tonic-gate "inactivity period");
3367c478bd9Sstevel@tonic-gate exit(EX_BADARG);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate usrdefs->definact = inact;
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */
3430523b0a4Sbasabi if (expirestr != NULL) {
3447c478bd9Sstevel@tonic-gate if (*expirestr) {
3457c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0)
3467c478bd9Sstevel@tonic-gate == INVALID) {
3477c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr,
3487c478bd9Sstevel@tonic-gate "expiration date");
3497c478bd9Sstevel@tonic-gate exit(EX_BADARG);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr;
3527c478bd9Sstevel@tonic-gate } else
3537c478bd9Sstevel@tonic-gate /* Unset the expiration date */
3547c478bd9Sstevel@tonic-gate usrdefs->defexpire = "";
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
3570523b0a4Sbasabi if (shell != NULL) {
3580523b0a4Sbasabi valid_input(SHELL, shell);
3590523b0a4Sbasabi usrdefs->defshell = shell;
3600523b0a4Sbasabi }
3610523b0a4Sbasabi if (skel_dir != NULL) {
3620523b0a4Sbasabi valid_input(SKELDIR, skel_dir);
3630523b0a4Sbasabi usrdefs->defskel = skel_dir;
3640523b0a4Sbasabi }
3657c478bd9Sstevel@tonic-gate update_def(usrdefs);
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /* change defaults for useradd */
3687c478bd9Sstevel@tonic-gate if (putusrdef(usrdefs, usertype) < 0) {
3697c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
3707c478bd9Sstevel@tonic-gate exit(EX_UPDATE);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate /* Now, display */
3747c478bd9Sstevel@tonic-gate dispusrdef(stdout, (D_ALL & ~D_RID), usertype);
3757c478bd9Sstevel@tonic-gate exit(EX_SUCCESS);
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /* ADD mode */
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate /* check syntax */
3820523b0a4Sbasabi if (optind != argc - 1 || (skel_dir != NULL && !mflag)) {
3837c478bd9Sstevel@tonic-gate if (is_role(usertype))
3847c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
3857c478bd9Sstevel@tonic-gate else
3867c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
3877c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate logname = argv[optind];
3917c478bd9Sstevel@tonic-gate switch (valid_login(logname, (struct passwd **)NULL, &warning)) {
3927c478bd9Sstevel@tonic-gate case INVALID:
3937c478bd9Sstevel@tonic-gate errmsg(M_INVALID, logname, "login name");
3947c478bd9Sstevel@tonic-gate exit(EX_BADARG);
3957c478bd9Sstevel@tonic-gate /*NOTREACHED*/
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate case NOTUNIQUE:
3987c478bd9Sstevel@tonic-gate errmsg(M_USED, logname);
3997c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS);
4007c478bd9Sstevel@tonic-gate /*NOTREACHED*/
401*0a1278f2SGary Mills
402*0a1278f2SGary Mills case LONGNAME:
403*0a1278f2SGary Mills errmsg(M_TOO_LONG, logname);
404*0a1278f2SGary Mills exit(EX_BADARG);
405*0a1278f2SGary Mills /*NOTREACHED*/
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate if (warning)
4097c478bd9Sstevel@tonic-gate warningmsg(warning, logname);
4100523b0a4Sbasabi if (uidstr != NULL) {
4117c478bd9Sstevel@tonic-gate /* convert uidstr to integer */
4127c478bd9Sstevel@tonic-gate errno = 0;
4137c478bd9Sstevel@tonic-gate uid = (uid_t)strtol(uidstr, &ptr, (int)10);
4147c478bd9Sstevel@tonic-gate if (*ptr || errno == ERANGE) {
4157c478bd9Sstevel@tonic-gate errmsg(M_INVALID, uidstr, "user id");
4167c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate switch (valid_uid(uid, NULL)) {
4207c478bd9Sstevel@tonic-gate case NOTUNIQUE:
4217c478bd9Sstevel@tonic-gate if (!oflag) {
4227c478bd9Sstevel@tonic-gate /* override not specified */
4237c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid);
4247c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate break;
4277c478bd9Sstevel@tonic-gate case RESERVED:
4287c478bd9Sstevel@tonic-gate errmsg(M_RESERVED, uid);
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate case TOOBIG:
4317c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "uid", uid);
4327c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4337c478bd9Sstevel@tonic-gate break;
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate } else {
4377c478bd9Sstevel@tonic-gate
438a7fe1d5bSAndy Stormont if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
4397c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id", "user id");
4407c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS);
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate
4440523b0a4Sbasabi if (group != NULL) {
4457c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) {
4467c478bd9Sstevel@tonic-gate case INVALID:
4477c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id");
4487c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4497c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4507c478bd9Sstevel@tonic-gate case TOOBIG:
4517c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group);
4527c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4537c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4547c478bd9Sstevel@tonic-gate case RESERVED:
4557c478bd9Sstevel@tonic-gate case UNIQUE:
4567c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group);
4577c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST);
4587c478bd9Sstevel@tonic-gate /*NOTREACHED*/
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate if (warning)
4627c478bd9Sstevel@tonic-gate warningmsg(warning, group);
4637c478bd9Sstevel@tonic-gate gid = g_ptr->gr_gid;
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate } else gid = usrdefs->defgroup;
4667c478bd9Sstevel@tonic-gate
4670523b0a4Sbasabi if (grps != NULL) {
4687c478bd9Sstevel@tonic-gate if (!*grps)
4697c478bd9Sstevel@tonic-gate /* ignore -G "" */
4707c478bd9Sstevel@tonic-gate grps = (char *)0;
4717c478bd9Sstevel@tonic-gate else if (!(gidlist = valid_lgroup(grps, gid)))
4727c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate
4750523b0a4Sbasabi if (projects != NULL) {
4767c478bd9Sstevel@tonic-gate if (! *projects)
4777c478bd9Sstevel@tonic-gate projects = (char *)0;
4787c478bd9Sstevel@tonic-gate else if (! (projlist = valid_lproject(projects)))
4797c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate
4820523b0a4Sbasabi /* if base_dir is provided, check its validity; otherwise default */
4830523b0a4Sbasabi if (base_dir != NULL)
4840523b0a4Sbasabi valid_input(BASEDIR, base_dir);
4850523b0a4Sbasabi else
4860523b0a4Sbasabi base_dir = usrdefs->defparent;
4870523b0a4Sbasabi
4880523b0a4Sbasabi if (dir == NULL) {
4897c478bd9Sstevel@tonic-gate /* set homedir to home directory made from base_dir */
4900523b0a4Sbasabi (void) sprintf(homedir, "%s/%s", base_dir, logname);
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate } else if (REL_PATH(dir)) {
4937c478bd9Sstevel@tonic-gate errmsg(M_RELPATH, dir);
4947c478bd9Sstevel@tonic-gate exit(EX_BADARG);
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate } else
4977c478bd9Sstevel@tonic-gate (void) strcpy(homedir, dir);
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate if (mflag) {
5007c478bd9Sstevel@tonic-gate /* Does home dir. already exist? */
5017c478bd9Sstevel@tonic-gate if (stat(homedir, &statbuf) == 0) {
5027c478bd9Sstevel@tonic-gate /* directory exists - don't try to create */
5037c478bd9Sstevel@tonic-gate mflag = 0;
5047c478bd9Sstevel@tonic-gate
5057c478bd9Sstevel@tonic-gate if (check_perm(statbuf, uid, gid, S_IXOTH) != 0)
5067c478bd9Sstevel@tonic-gate errmsg(M_NO_PERM, logname, homedir);
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate }
5090523b0a4Sbasabi /*
5100523b0a4Sbasabi * if shell, skel_dir are provided, check their validity.
5110523b0a4Sbasabi * Otherwise default.
5120523b0a4Sbasabi */
5130523b0a4Sbasabi if (shell != NULL)
5140523b0a4Sbasabi valid_input(SHELL, shell);
5150523b0a4Sbasabi else
5160523b0a4Sbasabi shell = usrdefs->defshell;
5177c478bd9Sstevel@tonic-gate
5180523b0a4Sbasabi if (skel_dir != NULL)
5190523b0a4Sbasabi valid_input(SKELDIR, skel_dir);
5200523b0a4Sbasabi else
5210523b0a4Sbasabi skel_dir = usrdefs->defskel;
5227c478bd9Sstevel@tonic-gate
5230523b0a4Sbasabi if (inactstr != NULL) {
5247c478bd9Sstevel@tonic-gate /* convert inactstr to integer */
5257c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10);
5267c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) {
5277c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr, "inactivity period");
5287c478bd9Sstevel@tonic-gate exit(EX_BADARG);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate } else inact = usrdefs->definact;
5317c478bd9Sstevel@tonic-gate
5327c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */
5330523b0a4Sbasabi if (expirestr != NULL) {
5347c478bd9Sstevel@tonic-gate if (*expirestr) {
5357c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0) == INVALID) {
5367c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr, "expiration date");
5377c478bd9Sstevel@tonic-gate exit(EX_BADARG);
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr;
5407c478bd9Sstevel@tonic-gate } else
5417c478bd9Sstevel@tonic-gate /* Unset the expiration date */
5427c478bd9Sstevel@tonic-gate expirestr = (char *)0;
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate } else expirestr = usrdefs->defexpire;
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate import_def(usrdefs);
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate /* must now call passmgmt */
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate /* set up arguments to passmgmt in nargv array */
5517c478bd9Sstevel@tonic-gate nargv = malloc((30 + nkeys * 2) * sizeof (char *));
5527c478bd9Sstevel@tonic-gate argindex = 0;
553c651b32eSJohn Sonnenschein nargv[argindex++] = PASSMGMT;
5547c478bd9Sstevel@tonic-gate nargv[argindex++] = "-a"; /* add */
5557c478bd9Sstevel@tonic-gate
5560523b0a4Sbasabi if (comment != NULL) {
5577c478bd9Sstevel@tonic-gate /* comment */
5587c478bd9Sstevel@tonic-gate nargv[argindex++] = "-c";
5597c478bd9Sstevel@tonic-gate nargv[argindex++] = comment;
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate /* flags for home directory */
5637c478bd9Sstevel@tonic-gate nargv[argindex++] = "-h";
5647c478bd9Sstevel@tonic-gate nargv[argindex++] = homedir;
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate /* set gid flag */
5677c478bd9Sstevel@tonic-gate nargv[argindex++] = "-g";
568f48205beScasper (void) sprintf(gidstring, "%u", gid);
5697c478bd9Sstevel@tonic-gate nargv[argindex++] = gidstring;
5707c478bd9Sstevel@tonic-gate
5717c478bd9Sstevel@tonic-gate /* shell */
5727c478bd9Sstevel@tonic-gate nargv[argindex++] = "-s";
5737c478bd9Sstevel@tonic-gate nargv[argindex++] = shell;
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate /* set inactive */
5767c478bd9Sstevel@tonic-gate nargv[argindex++] = "-f";
5777c478bd9Sstevel@tonic-gate (void) sprintf(inactstring, "%ld", inact);
5787c478bd9Sstevel@tonic-gate nargv[argindex++] = inactstring;
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate /* set expiration date */
5810523b0a4Sbasabi if (expirestr != NULL) {
5827c478bd9Sstevel@tonic-gate nargv[argindex++] = "-e";
5837c478bd9Sstevel@tonic-gate nargv[argindex++] = expirestr;
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate /* set uid flag */
5877c478bd9Sstevel@tonic-gate nargv[argindex++] = "-u";
588f48205beScasper (void) sprintf(uidstring, "%u", uid);
5897c478bd9Sstevel@tonic-gate nargv[argindex++] = uidstring;
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate if (oflag) nargv[argindex++] = "-o";
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate if (nkeys > 1)
5947c478bd9Sstevel@tonic-gate addkey_args(nargv, &argindex);
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate /* finally - login name */
5977c478bd9Sstevel@tonic-gate nargv[argindex++] = logname;
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate /* set the last to null */
6007c478bd9Sstevel@tonic-gate nargv[argindex++] = NULL;
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate /* now call passmgmt */
6037c478bd9Sstevel@tonic-gate ret = PEX_FAILED;
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate * If call_passmgmt fails for any reason other than PEX_BADUID, exit
6067c478bd9Sstevel@tonic-gate * is invoked with an appropriate error message. If PEX_BADUID is
6077c478bd9Sstevel@tonic-gate * returned, then if the user specified the ID, exit is invoked
6087c478bd9Sstevel@tonic-gate * with an appropriate error message. Otherwise we try to pick a
6097c478bd9Sstevel@tonic-gate * different ID and try again. If we run out of IDs, i.e. no more
6107c478bd9Sstevel@tonic-gate * users can be created, then -1 is returned and we terminate via exit.
6117c478bd9Sstevel@tonic-gate * If PEX_BUSY is returned we increment a count, since we will stop
6127c478bd9Sstevel@tonic-gate * trying if PEX_BUSY reaches 3. For PEX_SUCCESS we immediately
6137c478bd9Sstevel@tonic-gate * terminate the loop.
6147c478bd9Sstevel@tonic-gate */
6157c478bd9Sstevel@tonic-gate while (busy < 3 && ret != PEX_SUCCESS) {
6167c478bd9Sstevel@tonic-gate switch (ret = call_passmgmt(nargv)) {
6177c478bd9Sstevel@tonic-gate case PEX_SUCCESS:
6187c478bd9Sstevel@tonic-gate break;
6197c478bd9Sstevel@tonic-gate case PEX_BUSY:
6207c478bd9Sstevel@tonic-gate busy++;
6217c478bd9Sstevel@tonic-gate break;
6227c478bd9Sstevel@tonic-gate case PEX_HOSED_FILES:
6237c478bd9Sstevel@tonic-gate errmsg(M_HOSED_FILES);
6247c478bd9Sstevel@tonic-gate exit(EX_INCONSISTENT);
6257c478bd9Sstevel@tonic-gate break;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate case PEX_SYNTAX:
6287c478bd9Sstevel@tonic-gate case PEX_BADARG:
6297c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */
6307c478bd9Sstevel@tonic-gate if (is_role(usertype))
6317c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
6327c478bd9Sstevel@tonic-gate else
6337c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
6347c478bd9Sstevel@tonic-gate exit(EX_SYNTAX);
6357c478bd9Sstevel@tonic-gate break;
6367c478bd9Sstevel@tonic-gate
6377c478bd9Sstevel@tonic-gate case PEX_BADUID:
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate * The uid has been taken. If it was specified by a
6407c478bd9Sstevel@tonic-gate * user, then we must fail. Otherwise, keep trying
6417c478bd9Sstevel@tonic-gate * to get a good uid until we run out of IDs.
6427c478bd9Sstevel@tonic-gate */
6437c478bd9Sstevel@tonic-gate if (uidstr != NULL) {
6447c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid);
6457c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS);
6467c478bd9Sstevel@tonic-gate } else {
647a7fe1d5bSAndy Stormont if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
6487c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id",
6497c478bd9Sstevel@tonic-gate "user id");
6507c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS);
6517c478bd9Sstevel@tonic-gate }
652f48205beScasper (void) sprintf(uidstring, "%u", uid);
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate break;
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate case PEX_BADNAME:
6577c478bd9Sstevel@tonic-gate /* invalid loname */
6587c478bd9Sstevel@tonic-gate errmsg(M_USED, logname);
6597c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS);
6607c478bd9Sstevel@tonic-gate break;
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate default:
6637c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
6647c478bd9Sstevel@tonic-gate exit(ret);
6657c478bd9Sstevel@tonic-gate break;
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate if (busy == 3) {
6697c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
6707c478bd9Sstevel@tonic-gate exit(ret);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate /* add group entry */
6740523b0a4Sbasabi if ((grps != NULL) && edit_group(logname, (char *)0, gidlist, 0)) {
6757c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
6767c478bd9Sstevel@tonic-gate cleanup(logname);
6777c478bd9Sstevel@tonic-gate exit(EX_UPDATE);
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate
6807c478bd9Sstevel@tonic-gate /* update project database */
6810523b0a4Sbasabi if ((projects != NULL) &&
6820523b0a4Sbasabi edit_project(logname, (char *)NULL, projlist, 0)) {
6837c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
6847c478bd9Sstevel@tonic-gate cleanup(logname);
6857c478bd9Sstevel@tonic-gate exit(EX_UPDATE);
6867c478bd9Sstevel@tonic-gate }
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate /* create home directory */
6897c478bd9Sstevel@tonic-gate if (mflag &&
6907c478bd9Sstevel@tonic-gate (create_home(homedir, skel_dir, uid, gid) != EX_SUCCESS)) {
6917c478bd9Sstevel@tonic-gate (void) edit_group(logname, (char *)0, (int **)0, 1);
6927c478bd9Sstevel@tonic-gate cleanup(logname);
6937c478bd9Sstevel@tonic-gate exit(EX_HOMEDIR);
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate return (ret);
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate
6997c478bd9Sstevel@tonic-gate static void
cleanup(logname)7007c478bd9Sstevel@tonic-gate cleanup(logname)
7017c478bd9Sstevel@tonic-gate char *logname;
7027c478bd9Sstevel@tonic-gate {
7037c478bd9Sstevel@tonic-gate char *nargv[4];
7047c478bd9Sstevel@tonic-gate
705c651b32eSJohn Sonnenschein nargv[0] = PASSMGMT;
7067c478bd9Sstevel@tonic-gate nargv[1] = "-d";
7077c478bd9Sstevel@tonic-gate nargv[2] = logname;
7087c478bd9Sstevel@tonic-gate nargv[3] = NULL;
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate switch (call_passmgmt(nargv)) {
7117c478bd9Sstevel@tonic-gate case PEX_SUCCESS:
7127c478bd9Sstevel@tonic-gate break;
7137c478bd9Sstevel@tonic-gate
7147c478bd9Sstevel@tonic-gate case PEX_SYNTAX:
7157c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */
7167c478bd9Sstevel@tonic-gate if (is_role(usertype))
7177c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE);
7187c478bd9Sstevel@tonic-gate else
7197c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE);
7207c478bd9Sstevel@tonic-gate break;
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate case PEX_BADUID:
7237c478bd9Sstevel@tonic-gate /* uid is used - shouldn't happen but print message anyway */
7247c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid);
7257c478bd9Sstevel@tonic-gate break;
7267c478bd9Sstevel@tonic-gate
7277c478bd9Sstevel@tonic-gate case PEX_BADNAME:
7287c478bd9Sstevel@tonic-gate /* invalid loname */
7297c478bd9Sstevel@tonic-gate errmsg(M_USED, logname);
7307c478bd9Sstevel@tonic-gate break;
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate default:
7337c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created");
7347c478bd9Sstevel@tonic-gate break;
7357c478bd9Sstevel@tonic-gate }
7367c478bd9Sstevel@tonic-gate }
7370523b0a4Sbasabi
7380523b0a4Sbasabi /* Check the validity for shell, base_dir and skel_dir */
7390523b0a4Sbasabi
7400523b0a4Sbasabi void
valid_input(path_opt_t opt,const char * input)7410523b0a4Sbasabi valid_input(path_opt_t opt, const char *input)
7420523b0a4Sbasabi {
7430523b0a4Sbasabi struct stat statbuf;
7440523b0a4Sbasabi
7450523b0a4Sbasabi if (REL_PATH(input)) {
7460523b0a4Sbasabi errmsg(M_RELPATH, input);
7470523b0a4Sbasabi exit(EX_BADARG);
7480523b0a4Sbasabi }
7490523b0a4Sbasabi if (stat(input, &statbuf) == -1) {
7500523b0a4Sbasabi errmsg(M_INVALID, input, "path");
7510523b0a4Sbasabi exit(EX_BADARG);
7520523b0a4Sbasabi }
7530523b0a4Sbasabi if (opt == SHELL) {
7540523b0a4Sbasabi if (!S_ISREG(statbuf.st_mode) ||
7550523b0a4Sbasabi (statbuf.st_mode & 0555) != 0555) {
7560523b0a4Sbasabi errmsg(M_INVALID, input, "shell");
7570523b0a4Sbasabi exit(EX_BADARG);
7580523b0a4Sbasabi }
7590523b0a4Sbasabi } else {
7600523b0a4Sbasabi if (!S_ISDIR(statbuf.st_mode)) {
7610523b0a4Sbasabi errmsg(M_INVALID, input, "directory");
7620523b0a4Sbasabi exit(EX_BADARG);
7630523b0a4Sbasabi }
7640523b0a4Sbasabi }
7650523b0a4Sbasabi }
766