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*c651b32eSJohn Sonnenschein * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/stat.h> 327c478bd9Sstevel@tonic-gate #include <sys/param.h> 337c478bd9Sstevel@tonic-gate #include <stdio.h> 347c478bd9Sstevel@tonic-gate #include <stdlib.h> 357c478bd9Sstevel@tonic-gate #include <ctype.h> 367c478bd9Sstevel@tonic-gate #include <limits.h> 377c478bd9Sstevel@tonic-gate #include <string.h> 387c478bd9Sstevel@tonic-gate #include <userdefs.h> 397c478bd9Sstevel@tonic-gate #include <errno.h> 407c478bd9Sstevel@tonic-gate #include <project.h> 417c478bd9Sstevel@tonic-gate #include <unistd.h> 427c478bd9Sstevel@tonic-gate #include <user_attr.h> 437c478bd9Sstevel@tonic-gate #include "users.h" 447c478bd9Sstevel@tonic-gate #include "messages.h" 457c478bd9Sstevel@tonic-gate #include "userdisp.h" 467c478bd9Sstevel@tonic-gate #include "funcs.h" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m] 500523b0a4Sbasabi * | -s shell | -c comment | -k skel_dir | -b base_dir] ] 517c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]] 527c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]] 537c478bd9Sstevel@tonic-gate * [ -K key=value ] 547c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login 550523b0a4Sbasabi * useradd -D [ -g group ] [ -b base_dir | -f inactive | -e expire | 560523b0a4Sbasabi * -s shell | -k skel_dir ] 577c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]] 587c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]] [ -K key=value ] 597c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login 607c478bd9Sstevel@tonic-gate * 617c478bd9Sstevel@tonic-gate * This command adds new user logins to the system. Arguments are: 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * uid - an integer 647c478bd9Sstevel@tonic-gate * group - an existing group's integer ID or char string name 657c478bd9Sstevel@tonic-gate * dir - home directory 667c478bd9Sstevel@tonic-gate * shell - a program to be used as a shell 677c478bd9Sstevel@tonic-gate * comment - any text string 687c478bd9Sstevel@tonic-gate * skel_dir - a skeleton directory 697c478bd9Sstevel@tonic-gate * base_dir - a directory 707c478bd9Sstevel@tonic-gate * login - a string of printable chars except colon(:) 717c478bd9Sstevel@tonic-gate * authorization - One or more comma separated authorizations defined 727c478bd9Sstevel@tonic-gate * in auth_attr(4). 737c478bd9Sstevel@tonic-gate * profile - One or more comma separated execution profiles defined 747c478bd9Sstevel@tonic-gate * in prof_attr(4) 757c478bd9Sstevel@tonic-gate * role - One or more comma-separated role names defined in user_attr(4) 767c478bd9Sstevel@tonic-gate * project - One or more comma-separated project names or numbers 777c478bd9Sstevel@tonic-gate * 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate extern struct userdefs *getusrdef(); 817c478bd9Sstevel@tonic-gate extern void dispusrdef(); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate static void cleanup(); 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate extern uid_t findnextuid(void); 867c478bd9Sstevel@tonic-gate extern int check_perm(), valid_expire(); 877c478bd9Sstevel@tonic-gate extern int putusrdef(), valid_uid(); 887c478bd9Sstevel@tonic-gate extern int call_passmgmt(), edit_group(), create_home(); 897c478bd9Sstevel@tonic-gate extern int edit_project(); 907c478bd9Sstevel@tonic-gate extern int **valid_lgroup(); 917c478bd9Sstevel@tonic-gate extern projid_t **valid_lproject(); 927c478bd9Sstevel@tonic-gate extern void update_def(struct userdefs *); 937c478bd9Sstevel@tonic-gate extern void import_def(struct userdefs *); 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate static uid_t uid; /* new uid */ 967c478bd9Sstevel@tonic-gate static char *logname; /* login name to add */ 977c478bd9Sstevel@tonic-gate static struct userdefs *usrdefs; /* defaults for useradd */ 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate char *cmdname; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate static char homedir[ PATH_MAX + 1 ]; /* home directory */ 1027c478bd9Sstevel@tonic-gate static char gidstring[32]; /* group id string representation */ 1037c478bd9Sstevel@tonic-gate static gid_t gid; /* gid of new login */ 1047c478bd9Sstevel@tonic-gate static char uidstring[32]; /* user id string representation */ 1057c478bd9Sstevel@tonic-gate static char *uidstr = NULL; /* uid from command line */ 1067c478bd9Sstevel@tonic-gate static char *base_dir = NULL; /* base_dir from command line */ 1077c478bd9Sstevel@tonic-gate static char *group = NULL; /* group from command line */ 1087c478bd9Sstevel@tonic-gate static char *grps = NULL; /* multi groups from command line */ 1097c478bd9Sstevel@tonic-gate static char *dir = NULL; /* home dir from command line */ 1107c478bd9Sstevel@tonic-gate static char *shell = NULL; /* shell from command line */ 1117c478bd9Sstevel@tonic-gate static char *comment = NULL; /* comment from command line */ 1127c478bd9Sstevel@tonic-gate static char *skel_dir = NULL; /* skel dir from command line */ 1137c478bd9Sstevel@tonic-gate static long inact; /* inactive days */ 1147c478bd9Sstevel@tonic-gate static char *inactstr = NULL; /* inactive from command line */ 1157c478bd9Sstevel@tonic-gate static char inactstring[10]; /* inactivity string representation */ 1167c478bd9Sstevel@tonic-gate static char *expirestr = NULL; /* expiration date from command line */ 1177c478bd9Sstevel@tonic-gate static char *projects = NULL; /* project id's from command line */ 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate static char *usertype = NULL; /* type of user, either role or normal */ 1207c478bd9Sstevel@tonic-gate 1210523b0a4Sbasabi typedef enum { 1220523b0a4Sbasabi BASEDIR = 0, 1230523b0a4Sbasabi SKELDIR, 1240523b0a4Sbasabi SHELL 1250523b0a4Sbasabi } path_opt_t; 1260523b0a4Sbasabi 1270523b0a4Sbasabi 1280523b0a4Sbasabi static void valid_input(path_opt_t, const char *); 1290523b0a4Sbasabi 1307c478bd9Sstevel@tonic-gate int 1317c478bd9Sstevel@tonic-gate main(argc, argv) 1327c478bd9Sstevel@tonic-gate int argc; 1337c478bd9Sstevel@tonic-gate char *argv[]; 1347c478bd9Sstevel@tonic-gate { 1357c478bd9Sstevel@tonic-gate int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist; 1367c478bd9Sstevel@tonic-gate projid_t **projlist; 1377c478bd9Sstevel@tonic-gate char *ptr; /* loc in a str, may be set by strtol */ 1387c478bd9Sstevel@tonic-gate struct group *g_ptr; 1397c478bd9Sstevel@tonic-gate struct project p_ptr; 1407c478bd9Sstevel@tonic-gate char mybuf[PROJECT_BUFSZ]; 1417c478bd9Sstevel@tonic-gate struct stat statbuf; /* status buffer for stat */ 1427c478bd9Sstevel@tonic-gate int warning; 1437c478bd9Sstevel@tonic-gate int busy = 0; 1447c478bd9Sstevel@tonic-gate char **nargv; /* arguments for execvp of passmgmt */ 1457c478bd9Sstevel@tonic-gate int argindex; /* argument index into nargv */ 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate cmdname = argv[0]; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate if (geteuid() != 0) { 1507c478bd9Sstevel@tonic-gate errmsg(M_PERM_DENIED); 1517c478bd9Sstevel@tonic-gate exit(EX_NO_PERM); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate opterr = 0; /* no print errors from getopt */ 1557c478bd9Sstevel@tonic-gate usertype = getusertype(argv[0]); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate change_key(USERATTR_TYPE_KW, usertype); 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate while ((ch = getopt(argc, argv, 1607c478bd9Sstevel@tonic-gate "b:c:Dd:e:f:G:g:k:mop:s:u:A:P:R:K:")) != EOF) 1617c478bd9Sstevel@tonic-gate switch (ch) { 1627c478bd9Sstevel@tonic-gate case 'b': 1637c478bd9Sstevel@tonic-gate base_dir = optarg; 1647c478bd9Sstevel@tonic-gate break; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate case 'c': 1677c478bd9Sstevel@tonic-gate comment = optarg; 1687c478bd9Sstevel@tonic-gate break; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate case 'D': 1717c478bd9Sstevel@tonic-gate Dflag++; 1727c478bd9Sstevel@tonic-gate break; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate case 'd': 1757c478bd9Sstevel@tonic-gate dir = optarg; 1767c478bd9Sstevel@tonic-gate break; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate case 'e': 1797c478bd9Sstevel@tonic-gate expirestr = optarg; 1807c478bd9Sstevel@tonic-gate break; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate case 'f': 1837c478bd9Sstevel@tonic-gate inactstr = optarg; 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate case 'G': 1877c478bd9Sstevel@tonic-gate grps = optarg; 1887c478bd9Sstevel@tonic-gate break; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate case 'g': 1917c478bd9Sstevel@tonic-gate group = optarg; 1927c478bd9Sstevel@tonic-gate break; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate case 'k': 1957c478bd9Sstevel@tonic-gate skel_dir = optarg; 1967c478bd9Sstevel@tonic-gate break; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate case 'm': 1997c478bd9Sstevel@tonic-gate mflag++; 2007c478bd9Sstevel@tonic-gate break; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate case 'o': 2037c478bd9Sstevel@tonic-gate oflag++; 2047c478bd9Sstevel@tonic-gate break; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate case 'p': 2077c478bd9Sstevel@tonic-gate projects = optarg; 2087c478bd9Sstevel@tonic-gate break; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate case 's': 2117c478bd9Sstevel@tonic-gate shell = optarg; 2127c478bd9Sstevel@tonic-gate break; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate case 'u': 2157c478bd9Sstevel@tonic-gate uidstr = optarg; 2167c478bd9Sstevel@tonic-gate break; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate case 'A': 2197c478bd9Sstevel@tonic-gate change_key(USERATTR_AUTHS_KW, optarg); 2207c478bd9Sstevel@tonic-gate break; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate case 'P': 2237c478bd9Sstevel@tonic-gate change_key(USERATTR_PROFILES_KW, optarg); 2247c478bd9Sstevel@tonic-gate break; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate case 'R': 2277c478bd9Sstevel@tonic-gate if (is_role(usertype)) { 2287c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2297c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate change_key(USERATTR_ROLES_KW, optarg); 2327c478bd9Sstevel@tonic-gate break; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate case 'K': 2357c478bd9Sstevel@tonic-gate change_key(NULL, optarg); 2367c478bd9Sstevel@tonic-gate break; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate default: 2397c478bd9Sstevel@tonic-gate case '?': 2407c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2417c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2427c478bd9Sstevel@tonic-gate else 2437c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2447c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* get defaults for adding new users */ 2487c478bd9Sstevel@tonic-gate usrdefs = getusrdef(usertype); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate if (Dflag) { 2517c478bd9Sstevel@tonic-gate /* DISPLAY mode */ 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* check syntax */ 2547c478bd9Sstevel@tonic-gate if (optind != argc) { 2557c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2567c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2577c478bd9Sstevel@tonic-gate else 2587c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2597c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate 2620523b0a4Sbasabi if (uidstr != NULL || oflag || grps != NULL || 2630523b0a4Sbasabi dir != NULL || mflag || comment != NULL) { 2647c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2657c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2667c478bd9Sstevel@tonic-gate else 2677c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2687c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* Group must be an existing group */ 2720523b0a4Sbasabi if (group != NULL) { 2737c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) { 2747c478bd9Sstevel@tonic-gate case INVALID: 2757c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id"); 2767c478bd9Sstevel@tonic-gate exit(EX_BADARG); 2777c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 2787c478bd9Sstevel@tonic-gate case TOOBIG: 2797c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group); 2807c478bd9Sstevel@tonic-gate exit(EX_BADARG); 2817c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 2827c478bd9Sstevel@tonic-gate case RESERVED: 2837c478bd9Sstevel@tonic-gate case UNIQUE: 2847c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group); 2857c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate if (warning) 2887c478bd9Sstevel@tonic-gate warningmsg(warning, group); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate usrdefs->defgroup = g_ptr->gr_gid; 2917c478bd9Sstevel@tonic-gate usrdefs->defgname = g_ptr->gr_name; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* project must be an existing project */ 2960523b0a4Sbasabi if (projects != NULL) { 2977c478bd9Sstevel@tonic-gate switch (valid_project(projects, &p_ptr, mybuf, 2987c478bd9Sstevel@tonic-gate sizeof (mybuf), &warning)) { 2997c478bd9Sstevel@tonic-gate case INVALID: 3007c478bd9Sstevel@tonic-gate errmsg(M_INVALID, projects, "project id"); 3017c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3027c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3037c478bd9Sstevel@tonic-gate case TOOBIG: 3047c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "projid", projects); 3057c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3067c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3077c478bd9Sstevel@tonic-gate case UNIQUE: 3087c478bd9Sstevel@tonic-gate errmsg(M_PROJ_NOTUSED, projects); 3097c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate if (warning) 3127c478bd9Sstevel@tonic-gate warningmsg(warning, projects); 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate usrdefs->defproj = p_ptr.pj_projid; 3157c478bd9Sstevel@tonic-gate usrdefs->defprojname = p_ptr.pj_name; 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate /* base_dir must be an existing directory */ 3190523b0a4Sbasabi if (base_dir != NULL) { 3200523b0a4Sbasabi valid_input(BASEDIR, base_dir); 3217c478bd9Sstevel@tonic-gate usrdefs->defparent = base_dir; 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* inactivity period is an integer */ 3250523b0a4Sbasabi if (inactstr != NULL) { 3267c478bd9Sstevel@tonic-gate /* convert inactstr to integer */ 3277c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10); 3287c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) { 3297c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr, 3307c478bd9Sstevel@tonic-gate "inactivity period"); 3317c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate usrdefs->definact = inact; 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */ 3380523b0a4Sbasabi if (expirestr != NULL) { 3397c478bd9Sstevel@tonic-gate if (*expirestr) { 3407c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0) 3417c478bd9Sstevel@tonic-gate == INVALID) { 3427c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr, 3437c478bd9Sstevel@tonic-gate "expiration date"); 3447c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr; 3477c478bd9Sstevel@tonic-gate } else 3487c478bd9Sstevel@tonic-gate /* Unset the expiration date */ 3497c478bd9Sstevel@tonic-gate usrdefs->defexpire = ""; 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3520523b0a4Sbasabi if (shell != NULL) { 3530523b0a4Sbasabi valid_input(SHELL, shell); 3540523b0a4Sbasabi usrdefs->defshell = shell; 3550523b0a4Sbasabi } 3560523b0a4Sbasabi if (skel_dir != NULL) { 3570523b0a4Sbasabi valid_input(SKELDIR, skel_dir); 3580523b0a4Sbasabi usrdefs->defskel = skel_dir; 3590523b0a4Sbasabi } 3607c478bd9Sstevel@tonic-gate update_def(usrdefs); 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate /* change defaults for useradd */ 3637c478bd9Sstevel@tonic-gate if (putusrdef(usrdefs, usertype) < 0) { 3647c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 3657c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* Now, display */ 3697c478bd9Sstevel@tonic-gate dispusrdef(stdout, (D_ALL & ~D_RID), usertype); 3707c478bd9Sstevel@tonic-gate exit(EX_SUCCESS); 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /* ADD mode */ 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* check syntax */ 3770523b0a4Sbasabi if (optind != argc - 1 || (skel_dir != NULL && !mflag)) { 3787c478bd9Sstevel@tonic-gate if (is_role(usertype)) 3797c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 3807c478bd9Sstevel@tonic-gate else 3817c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 3827c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate logname = argv[optind]; 3867c478bd9Sstevel@tonic-gate switch (valid_login(logname, (struct passwd **)NULL, &warning)) { 3877c478bd9Sstevel@tonic-gate case INVALID: 3887c478bd9Sstevel@tonic-gate errmsg(M_INVALID, logname, "login name"); 3897c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3907c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate case NOTUNIQUE: 3937c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 3947c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS); 3957c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate if (warning) 3997c478bd9Sstevel@tonic-gate warningmsg(warning, logname); 4000523b0a4Sbasabi if (uidstr != NULL) { 4017c478bd9Sstevel@tonic-gate /* convert uidstr to integer */ 4027c478bd9Sstevel@tonic-gate errno = 0; 4037c478bd9Sstevel@tonic-gate uid = (uid_t)strtol(uidstr, &ptr, (int)10); 4047c478bd9Sstevel@tonic-gate if (*ptr || errno == ERANGE) { 4057c478bd9Sstevel@tonic-gate errmsg(M_INVALID, uidstr, "user id"); 4067c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate switch (valid_uid(uid, NULL)) { 4107c478bd9Sstevel@tonic-gate case NOTUNIQUE: 4117c478bd9Sstevel@tonic-gate if (!oflag) { 4127c478bd9Sstevel@tonic-gate /* override not specified */ 4137c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 4147c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate case RESERVED: 4187c478bd9Sstevel@tonic-gate errmsg(M_RESERVED, uid); 4197c478bd9Sstevel@tonic-gate break; 4207c478bd9Sstevel@tonic-gate case TOOBIG: 4217c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "uid", uid); 4227c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4237c478bd9Sstevel@tonic-gate break; 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate } else { 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate if ((uid = findnextuid()) < 0) { 4297c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id", "user id"); 4307c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate 4340523b0a4Sbasabi if (group != NULL) { 4357c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) { 4367c478bd9Sstevel@tonic-gate case INVALID: 4377c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id"); 4387c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4397c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4407c478bd9Sstevel@tonic-gate case TOOBIG: 4417c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group); 4427c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4437c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4447c478bd9Sstevel@tonic-gate case RESERVED: 4457c478bd9Sstevel@tonic-gate case UNIQUE: 4467c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group); 4477c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 4487c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate if (warning) 4527c478bd9Sstevel@tonic-gate warningmsg(warning, group); 4537c478bd9Sstevel@tonic-gate gid = g_ptr->gr_gid; 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate } else gid = usrdefs->defgroup; 4567c478bd9Sstevel@tonic-gate 4570523b0a4Sbasabi if (grps != NULL) { 4587c478bd9Sstevel@tonic-gate if (!*grps) 4597c478bd9Sstevel@tonic-gate /* ignore -G "" */ 4607c478bd9Sstevel@tonic-gate grps = (char *)0; 4617c478bd9Sstevel@tonic-gate else if (!(gidlist = valid_lgroup(grps, gid))) 4627c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4650523b0a4Sbasabi if (projects != NULL) { 4667c478bd9Sstevel@tonic-gate if (! *projects) 4677c478bd9Sstevel@tonic-gate projects = (char *)0; 4687c478bd9Sstevel@tonic-gate else if (! (projlist = valid_lproject(projects))) 4697c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate 4720523b0a4Sbasabi /* if base_dir is provided, check its validity; otherwise default */ 4730523b0a4Sbasabi if (base_dir != NULL) 4740523b0a4Sbasabi valid_input(BASEDIR, base_dir); 4750523b0a4Sbasabi else 4760523b0a4Sbasabi base_dir = usrdefs->defparent; 4770523b0a4Sbasabi 4780523b0a4Sbasabi if (dir == NULL) { 4797c478bd9Sstevel@tonic-gate /* set homedir to home directory made from base_dir */ 4800523b0a4Sbasabi (void) sprintf(homedir, "%s/%s", base_dir, logname); 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate } else if (REL_PATH(dir)) { 4837c478bd9Sstevel@tonic-gate errmsg(M_RELPATH, dir); 4847c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate } else 4877c478bd9Sstevel@tonic-gate (void) strcpy(homedir, dir); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate if (mflag) { 4907c478bd9Sstevel@tonic-gate /* Does home dir. already exist? */ 4917c478bd9Sstevel@tonic-gate if (stat(homedir, &statbuf) == 0) { 4927c478bd9Sstevel@tonic-gate /* directory exists - don't try to create */ 4937c478bd9Sstevel@tonic-gate mflag = 0; 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate if (check_perm(statbuf, uid, gid, S_IXOTH) != 0) 4967c478bd9Sstevel@tonic-gate errmsg(M_NO_PERM, logname, homedir); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate } 4990523b0a4Sbasabi /* 5000523b0a4Sbasabi * if shell, skel_dir are provided, check their validity. 5010523b0a4Sbasabi * Otherwise default. 5020523b0a4Sbasabi */ 5030523b0a4Sbasabi if (shell != NULL) 5040523b0a4Sbasabi valid_input(SHELL, shell); 5050523b0a4Sbasabi else 5060523b0a4Sbasabi shell = usrdefs->defshell; 5077c478bd9Sstevel@tonic-gate 5080523b0a4Sbasabi if (skel_dir != NULL) 5090523b0a4Sbasabi valid_input(SKELDIR, skel_dir); 5100523b0a4Sbasabi else 5110523b0a4Sbasabi skel_dir = usrdefs->defskel; 5127c478bd9Sstevel@tonic-gate 5130523b0a4Sbasabi if (inactstr != NULL) { 5147c478bd9Sstevel@tonic-gate /* convert inactstr to integer */ 5157c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10); 5167c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) { 5177c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr, "inactivity period"); 5187c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate } else inact = usrdefs->definact; 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */ 5230523b0a4Sbasabi if (expirestr != NULL) { 5247c478bd9Sstevel@tonic-gate if (*expirestr) { 5257c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0) == INVALID) { 5267c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr, "expiration date"); 5277c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr; 5307c478bd9Sstevel@tonic-gate } else 5317c478bd9Sstevel@tonic-gate /* Unset the expiration date */ 5327c478bd9Sstevel@tonic-gate expirestr = (char *)0; 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate } else expirestr = usrdefs->defexpire; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate import_def(usrdefs); 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* must now call passmgmt */ 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate /* set up arguments to passmgmt in nargv array */ 5417c478bd9Sstevel@tonic-gate nargv = malloc((30 + nkeys * 2) * sizeof (char *)); 5427c478bd9Sstevel@tonic-gate argindex = 0; 543*c651b32eSJohn Sonnenschein nargv[argindex++] = PASSMGMT; 5447c478bd9Sstevel@tonic-gate nargv[argindex++] = "-a"; /* add */ 5457c478bd9Sstevel@tonic-gate 5460523b0a4Sbasabi if (comment != NULL) { 5477c478bd9Sstevel@tonic-gate /* comment */ 5487c478bd9Sstevel@tonic-gate nargv[argindex++] = "-c"; 5497c478bd9Sstevel@tonic-gate nargv[argindex++] = comment; 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate /* flags for home directory */ 5537c478bd9Sstevel@tonic-gate nargv[argindex++] = "-h"; 5547c478bd9Sstevel@tonic-gate nargv[argindex++] = homedir; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate /* set gid flag */ 5577c478bd9Sstevel@tonic-gate nargv[argindex++] = "-g"; 558f48205beScasper (void) sprintf(gidstring, "%u", gid); 5597c478bd9Sstevel@tonic-gate nargv[argindex++] = gidstring; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* shell */ 5627c478bd9Sstevel@tonic-gate nargv[argindex++] = "-s"; 5637c478bd9Sstevel@tonic-gate nargv[argindex++] = shell; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate /* set inactive */ 5667c478bd9Sstevel@tonic-gate nargv[argindex++] = "-f"; 5677c478bd9Sstevel@tonic-gate (void) sprintf(inactstring, "%ld", inact); 5687c478bd9Sstevel@tonic-gate nargv[argindex++] = inactstring; 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* set expiration date */ 5710523b0a4Sbasabi if (expirestr != NULL) { 5727c478bd9Sstevel@tonic-gate nargv[argindex++] = "-e"; 5737c478bd9Sstevel@tonic-gate nargv[argindex++] = expirestr; 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate /* set uid flag */ 5777c478bd9Sstevel@tonic-gate nargv[argindex++] = "-u"; 578f48205beScasper (void) sprintf(uidstring, "%u", uid); 5797c478bd9Sstevel@tonic-gate nargv[argindex++] = uidstring; 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate if (oflag) nargv[argindex++] = "-o"; 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate if (nkeys > 1) 5847c478bd9Sstevel@tonic-gate addkey_args(nargv, &argindex); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate /* finally - login name */ 5877c478bd9Sstevel@tonic-gate nargv[argindex++] = logname; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate /* set the last to null */ 5907c478bd9Sstevel@tonic-gate nargv[argindex++] = NULL; 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate /* now call passmgmt */ 5937c478bd9Sstevel@tonic-gate ret = PEX_FAILED; 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * If call_passmgmt fails for any reason other than PEX_BADUID, exit 5967c478bd9Sstevel@tonic-gate * is invoked with an appropriate error message. If PEX_BADUID is 5977c478bd9Sstevel@tonic-gate * returned, then if the user specified the ID, exit is invoked 5987c478bd9Sstevel@tonic-gate * with an appropriate error message. Otherwise we try to pick a 5997c478bd9Sstevel@tonic-gate * different ID and try again. If we run out of IDs, i.e. no more 6007c478bd9Sstevel@tonic-gate * users can be created, then -1 is returned and we terminate via exit. 6017c478bd9Sstevel@tonic-gate * If PEX_BUSY is returned we increment a count, since we will stop 6027c478bd9Sstevel@tonic-gate * trying if PEX_BUSY reaches 3. For PEX_SUCCESS we immediately 6037c478bd9Sstevel@tonic-gate * terminate the loop. 6047c478bd9Sstevel@tonic-gate */ 6057c478bd9Sstevel@tonic-gate while (busy < 3 && ret != PEX_SUCCESS) { 6067c478bd9Sstevel@tonic-gate switch (ret = call_passmgmt(nargv)) { 6077c478bd9Sstevel@tonic-gate case PEX_SUCCESS: 6087c478bd9Sstevel@tonic-gate break; 6097c478bd9Sstevel@tonic-gate case PEX_BUSY: 6107c478bd9Sstevel@tonic-gate busy++; 6117c478bd9Sstevel@tonic-gate break; 6127c478bd9Sstevel@tonic-gate case PEX_HOSED_FILES: 6137c478bd9Sstevel@tonic-gate errmsg(M_HOSED_FILES); 6147c478bd9Sstevel@tonic-gate exit(EX_INCONSISTENT); 6157c478bd9Sstevel@tonic-gate break; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate case PEX_SYNTAX: 6187c478bd9Sstevel@tonic-gate case PEX_BADARG: 6197c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */ 6207c478bd9Sstevel@tonic-gate if (is_role(usertype)) 6217c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 6227c478bd9Sstevel@tonic-gate else 6237c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 6247c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 6257c478bd9Sstevel@tonic-gate break; 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate case PEX_BADUID: 6287c478bd9Sstevel@tonic-gate /* 6297c478bd9Sstevel@tonic-gate * The uid has been taken. If it was specified by a 6307c478bd9Sstevel@tonic-gate * user, then we must fail. Otherwise, keep trying 6317c478bd9Sstevel@tonic-gate * to get a good uid until we run out of IDs. 6327c478bd9Sstevel@tonic-gate */ 6337c478bd9Sstevel@tonic-gate if (uidstr != NULL) { 6347c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 6357c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 6367c478bd9Sstevel@tonic-gate } else { 6377c478bd9Sstevel@tonic-gate if ((uid = findnextuid()) < 0) { 6387c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id", 6397c478bd9Sstevel@tonic-gate "user id"); 6407c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 6417c478bd9Sstevel@tonic-gate } 642f48205beScasper (void) sprintf(uidstring, "%u", uid); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate break; 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate case PEX_BADNAME: 6477c478bd9Sstevel@tonic-gate /* invalid loname */ 6487c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 6497c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS); 6507c478bd9Sstevel@tonic-gate break; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate default: 6537c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6547c478bd9Sstevel@tonic-gate exit(ret); 6557c478bd9Sstevel@tonic-gate break; 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate if (busy == 3) { 6597c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6607c478bd9Sstevel@tonic-gate exit(ret); 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* add group entry */ 6640523b0a4Sbasabi if ((grps != NULL) && edit_group(logname, (char *)0, gidlist, 0)) { 6657c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6667c478bd9Sstevel@tonic-gate cleanup(logname); 6677c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* update project database */ 6710523b0a4Sbasabi if ((projects != NULL) && 6720523b0a4Sbasabi edit_project(logname, (char *)NULL, projlist, 0)) { 6737c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6747c478bd9Sstevel@tonic-gate cleanup(logname); 6757c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate /* create home directory */ 6797c478bd9Sstevel@tonic-gate if (mflag && 6807c478bd9Sstevel@tonic-gate (create_home(homedir, skel_dir, uid, gid) != EX_SUCCESS)) { 6817c478bd9Sstevel@tonic-gate (void) edit_group(logname, (char *)0, (int **)0, 1); 6827c478bd9Sstevel@tonic-gate cleanup(logname); 6837c478bd9Sstevel@tonic-gate exit(EX_HOMEDIR); 6847c478bd9Sstevel@tonic-gate } 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate return (ret); 6877c478bd9Sstevel@tonic-gate } 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate static void 6907c478bd9Sstevel@tonic-gate cleanup(logname) 6917c478bd9Sstevel@tonic-gate char *logname; 6927c478bd9Sstevel@tonic-gate { 6937c478bd9Sstevel@tonic-gate char *nargv[4]; 6947c478bd9Sstevel@tonic-gate 695*c651b32eSJohn Sonnenschein nargv[0] = PASSMGMT; 6967c478bd9Sstevel@tonic-gate nargv[1] = "-d"; 6977c478bd9Sstevel@tonic-gate nargv[2] = logname; 6987c478bd9Sstevel@tonic-gate nargv[3] = NULL; 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate switch (call_passmgmt(nargv)) { 7017c478bd9Sstevel@tonic-gate case PEX_SUCCESS: 7027c478bd9Sstevel@tonic-gate break; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate case PEX_SYNTAX: 7057c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */ 7067c478bd9Sstevel@tonic-gate if (is_role(usertype)) 7077c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 7087c478bd9Sstevel@tonic-gate else 7097c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 7107c478bd9Sstevel@tonic-gate break; 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate case PEX_BADUID: 7137c478bd9Sstevel@tonic-gate /* uid is used - shouldn't happen but print message anyway */ 7147c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 7157c478bd9Sstevel@tonic-gate break; 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate case PEX_BADNAME: 7187c478bd9Sstevel@tonic-gate /* invalid loname */ 7197c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 7207c478bd9Sstevel@tonic-gate break; 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate default: 7237c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 7247c478bd9Sstevel@tonic-gate break; 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate } 7270523b0a4Sbasabi 7280523b0a4Sbasabi /* Check the validity for shell, base_dir and skel_dir */ 7290523b0a4Sbasabi 7300523b0a4Sbasabi void 7310523b0a4Sbasabi valid_input(path_opt_t opt, const char *input) 7320523b0a4Sbasabi { 7330523b0a4Sbasabi struct stat statbuf; 7340523b0a4Sbasabi 7350523b0a4Sbasabi if (REL_PATH(input)) { 7360523b0a4Sbasabi errmsg(M_RELPATH, input); 7370523b0a4Sbasabi exit(EX_BADARG); 7380523b0a4Sbasabi } 7390523b0a4Sbasabi if (stat(input, &statbuf) == -1) { 7400523b0a4Sbasabi errmsg(M_INVALID, input, "path"); 7410523b0a4Sbasabi exit(EX_BADARG); 7420523b0a4Sbasabi } 7430523b0a4Sbasabi if (opt == SHELL) { 7440523b0a4Sbasabi if (!S_ISREG(statbuf.st_mode) || 7450523b0a4Sbasabi (statbuf.st_mode & 0555) != 0555) { 7460523b0a4Sbasabi errmsg(M_INVALID, input, "shell"); 7470523b0a4Sbasabi exit(EX_BADARG); 7480523b0a4Sbasabi } 7490523b0a4Sbasabi } else { 7500523b0a4Sbasabi if (!S_ISDIR(statbuf.st_mode)) { 7510523b0a4Sbasabi errmsg(M_INVALID, input, "directory"); 7520523b0a4Sbasabi exit(EX_BADARG); 7530523b0a4Sbasabi } 7540523b0a4Sbasabi } 7550523b0a4Sbasabi } 756