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 /* 220a1278f2SGary Mills * Copyright (c) 2013 Gary Mills 230a1278f2SGary 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 /* 55*7fc68ddfSAlbert Lee * useradd [-u uid [-o] | -g group | -G group [[, group]...] 56*7fc68ddfSAlbert Lee * | -d dir [-m [-z|Z]] 570523b0a4Sbasabi * | -s shell | -c comment | -k skel_dir | -b base_dir] ] 587c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]] 597c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]] 607c478bd9Sstevel@tonic-gate * [ -K key=value ] 617c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login 620523b0a4Sbasabi * useradd -D [ -g group ] [ -b base_dir | -f inactive | -e expire | 630523b0a4Sbasabi * -s shell | -k skel_dir ] 647c478bd9Sstevel@tonic-gate * [ -A authorization [, authorization ...]] 657c478bd9Sstevel@tonic-gate * [ -P profile [, profile ...]] [ -K key=value ] 667c478bd9Sstevel@tonic-gate * [ -R role [, role ...]] [-p project [, project ...]] login 677c478bd9Sstevel@tonic-gate * 687c478bd9Sstevel@tonic-gate * This command adds new user logins to the system. Arguments are: 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * uid - an integer 717c478bd9Sstevel@tonic-gate * group - an existing group's integer ID or char string name 727c478bd9Sstevel@tonic-gate * dir - home directory 737c478bd9Sstevel@tonic-gate * shell - a program to be used as a shell 747c478bd9Sstevel@tonic-gate * comment - any text string 757c478bd9Sstevel@tonic-gate * skel_dir - a skeleton directory 767c478bd9Sstevel@tonic-gate * base_dir - a directory 777c478bd9Sstevel@tonic-gate * login - a string of printable chars except colon(:) 787c478bd9Sstevel@tonic-gate * authorization - One or more comma separated authorizations defined 797c478bd9Sstevel@tonic-gate * in auth_attr(4). 807c478bd9Sstevel@tonic-gate * profile - One or more comma separated execution profiles defined 817c478bd9Sstevel@tonic-gate * in prof_attr(4) 827c478bd9Sstevel@tonic-gate * role - One or more comma-separated role names defined in user_attr(4) 837c478bd9Sstevel@tonic-gate * project - One or more comma-separated project names or numbers 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate extern struct userdefs *getusrdef(); 887c478bd9Sstevel@tonic-gate extern void dispusrdef(); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static void cleanup(); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate extern int check_perm(), valid_expire(); 937c478bd9Sstevel@tonic-gate extern int putusrdef(), valid_uid(); 947c478bd9Sstevel@tonic-gate extern int call_passmgmt(), edit_group(), create_home(); 957c478bd9Sstevel@tonic-gate extern int edit_project(); 967c478bd9Sstevel@tonic-gate extern int **valid_lgroup(); 977c478bd9Sstevel@tonic-gate extern projid_t **valid_lproject(); 987c478bd9Sstevel@tonic-gate extern void update_def(struct userdefs *); 997c478bd9Sstevel@tonic-gate extern void import_def(struct userdefs *); 100*7fc68ddfSAlbert Lee extern int get_default_zfs_flags(); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate static uid_t uid; /* new uid */ 1037c478bd9Sstevel@tonic-gate static char *logname; /* login name to add */ 1047c478bd9Sstevel@tonic-gate static struct userdefs *usrdefs; /* defaults for useradd */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate char *cmdname; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate static char homedir[ PATH_MAX + 1 ]; /* home directory */ 1097c478bd9Sstevel@tonic-gate static char gidstring[32]; /* group id string representation */ 1107c478bd9Sstevel@tonic-gate static gid_t gid; /* gid of new login */ 1117c478bd9Sstevel@tonic-gate static char uidstring[32]; /* user id string representation */ 1127c478bd9Sstevel@tonic-gate static char *uidstr = NULL; /* uid from command line */ 1137c478bd9Sstevel@tonic-gate static char *base_dir = NULL; /* base_dir from command line */ 1147c478bd9Sstevel@tonic-gate static char *group = NULL; /* group from command line */ 1157c478bd9Sstevel@tonic-gate static char *grps = NULL; /* multi groups from command line */ 1167c478bd9Sstevel@tonic-gate static char *dir = NULL; /* home dir from command line */ 1177c478bd9Sstevel@tonic-gate static char *shell = NULL; /* shell from command line */ 1187c478bd9Sstevel@tonic-gate static char *comment = NULL; /* comment from command line */ 1197c478bd9Sstevel@tonic-gate static char *skel_dir = NULL; /* skel dir from command line */ 1207c478bd9Sstevel@tonic-gate static long inact; /* inactive days */ 1217c478bd9Sstevel@tonic-gate static char *inactstr = NULL; /* inactive from command line */ 1227c478bd9Sstevel@tonic-gate static char inactstring[10]; /* inactivity string representation */ 1237c478bd9Sstevel@tonic-gate static char *expirestr = NULL; /* expiration date from command line */ 1247c478bd9Sstevel@tonic-gate static char *projects = NULL; /* project id's from command line */ 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate static char *usertype = NULL; /* type of user, either role or normal */ 1277c478bd9Sstevel@tonic-gate 1280523b0a4Sbasabi typedef enum { 1290523b0a4Sbasabi BASEDIR = 0, 1300523b0a4Sbasabi SKELDIR, 1310523b0a4Sbasabi SHELL 1320523b0a4Sbasabi } path_opt_t; 1330523b0a4Sbasabi 1340523b0a4Sbasabi 1350523b0a4Sbasabi static void valid_input(path_opt_t, const char *); 1360523b0a4Sbasabi 1377c478bd9Sstevel@tonic-gate int 1387c478bd9Sstevel@tonic-gate main(argc, argv) 1397c478bd9Sstevel@tonic-gate int argc; 1407c478bd9Sstevel@tonic-gate char *argv[]; 1417c478bd9Sstevel@tonic-gate { 142*7fc68ddfSAlbert Lee int ch, ret, mflag = 0, oflag = 0, Dflag = 0; 143*7fc68ddfSAlbert Lee int zflag = 0, Zflag = 0, **gidlist = NULL; 144a7fe1d5bSAndy Stormont projid_t **projlist = NULL; 1457c478bd9Sstevel@tonic-gate char *ptr; /* loc in a str, may be set by strtol */ 1467c478bd9Sstevel@tonic-gate struct group *g_ptr; 1477c478bd9Sstevel@tonic-gate struct project p_ptr; 1487c478bd9Sstevel@tonic-gate char mybuf[PROJECT_BUFSZ]; 1497c478bd9Sstevel@tonic-gate struct stat statbuf; /* status buffer for stat */ 1507c478bd9Sstevel@tonic-gate int warning; 1517c478bd9Sstevel@tonic-gate int busy = 0; 1527c478bd9Sstevel@tonic-gate char **nargv; /* arguments for execvp of passmgmt */ 1537c478bd9Sstevel@tonic-gate int argindex; /* argument index into nargv */ 154*7fc68ddfSAlbert Lee int zfs_flags = 0; /* create_home flags */ 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate cmdname = argv[0]; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate if (geteuid() != 0) { 1597c478bd9Sstevel@tonic-gate errmsg(M_PERM_DENIED); 1607c478bd9Sstevel@tonic-gate exit(EX_NO_PERM); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate opterr = 0; /* no print errors from getopt */ 1647c478bd9Sstevel@tonic-gate usertype = getusertype(argv[0]); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate change_key(USERATTR_TYPE_KW, usertype); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate while ((ch = getopt(argc, argv, 169*7fc68ddfSAlbert Lee "b:c:Dd:e:f:G:g:k:mzZop:s:u:A:P:R:K:")) != EOF) 1707c478bd9Sstevel@tonic-gate switch (ch) { 1717c478bd9Sstevel@tonic-gate case 'b': 1727c478bd9Sstevel@tonic-gate base_dir = optarg; 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate case 'c': 1767c478bd9Sstevel@tonic-gate comment = optarg; 1777c478bd9Sstevel@tonic-gate break; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate case 'D': 1807c478bd9Sstevel@tonic-gate Dflag++; 1817c478bd9Sstevel@tonic-gate break; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate case 'd': 1847c478bd9Sstevel@tonic-gate dir = optarg; 1857c478bd9Sstevel@tonic-gate break; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate case 'e': 1887c478bd9Sstevel@tonic-gate expirestr = optarg; 1897c478bd9Sstevel@tonic-gate break; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate case 'f': 1927c478bd9Sstevel@tonic-gate inactstr = optarg; 1937c478bd9Sstevel@tonic-gate break; 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate case 'G': 1967c478bd9Sstevel@tonic-gate grps = optarg; 1977c478bd9Sstevel@tonic-gate break; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate case 'g': 2007c478bd9Sstevel@tonic-gate group = optarg; 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate case 'k': 2047c478bd9Sstevel@tonic-gate skel_dir = optarg; 2057c478bd9Sstevel@tonic-gate break; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate case 'm': 2087c478bd9Sstevel@tonic-gate mflag++; 2097c478bd9Sstevel@tonic-gate break; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate case 'o': 2127c478bd9Sstevel@tonic-gate oflag++; 2137c478bd9Sstevel@tonic-gate break; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate case 'p': 2167c478bd9Sstevel@tonic-gate projects = optarg; 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate case 's': 2207c478bd9Sstevel@tonic-gate shell = optarg; 2217c478bd9Sstevel@tonic-gate break; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate case 'u': 2247c478bd9Sstevel@tonic-gate uidstr = optarg; 2257c478bd9Sstevel@tonic-gate break; 2267c478bd9Sstevel@tonic-gate 227*7fc68ddfSAlbert Lee case 'Z': 228*7fc68ddfSAlbert Lee Zflag++; 229*7fc68ddfSAlbert Lee break; 230*7fc68ddfSAlbert Lee 231*7fc68ddfSAlbert Lee case 'z': 232*7fc68ddfSAlbert Lee zflag++; 233*7fc68ddfSAlbert Lee break; 234*7fc68ddfSAlbert Lee 2357c478bd9Sstevel@tonic-gate case 'A': 2367c478bd9Sstevel@tonic-gate change_key(USERATTR_AUTHS_KW, optarg); 2377c478bd9Sstevel@tonic-gate break; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate case 'P': 2407c478bd9Sstevel@tonic-gate change_key(USERATTR_PROFILES_KW, optarg); 2417c478bd9Sstevel@tonic-gate break; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate case 'R': 2447c478bd9Sstevel@tonic-gate if (is_role(usertype)) { 2457c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2467c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate change_key(USERATTR_ROLES_KW, optarg); 2497c478bd9Sstevel@tonic-gate break; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate case 'K': 2527c478bd9Sstevel@tonic-gate change_key(NULL, optarg); 2537c478bd9Sstevel@tonic-gate break; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate default: 2567c478bd9Sstevel@tonic-gate case '?': 2577c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2587c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2597c478bd9Sstevel@tonic-gate else 2607c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2617c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 264*7fc68ddfSAlbert Lee if (((!mflag) && (zflag || Zflag)) || (zflag && Zflag) || 265*7fc68ddfSAlbert Lee (mflag > 1 && (zflag || Zflag))) { 266*7fc68ddfSAlbert Lee if (is_role(usertype)) 267*7fc68ddfSAlbert Lee errmsg(M_ARUSAGE); 268*7fc68ddfSAlbert Lee else 269*7fc68ddfSAlbert Lee errmsg(M_AUSAGE); 270*7fc68ddfSAlbert Lee exit(EX_SYNTAX); 271*7fc68ddfSAlbert Lee } 272*7fc68ddfSAlbert Lee 273*7fc68ddfSAlbert Lee 2747c478bd9Sstevel@tonic-gate /* get defaults for adding new users */ 2757c478bd9Sstevel@tonic-gate usrdefs = getusrdef(usertype); 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate if (Dflag) { 2787c478bd9Sstevel@tonic-gate /* DISPLAY mode */ 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* check syntax */ 2817c478bd9Sstevel@tonic-gate if (optind != argc) { 2827c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2837c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2847c478bd9Sstevel@tonic-gate else 2857c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2867c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2890523b0a4Sbasabi if (uidstr != NULL || oflag || grps != NULL || 2900523b0a4Sbasabi dir != NULL || mflag || comment != NULL) { 2917c478bd9Sstevel@tonic-gate if (is_role(usertype)) 2927c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 2937c478bd9Sstevel@tonic-gate else 2947c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 2957c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* Group must be an existing group */ 2990523b0a4Sbasabi if (group != NULL) { 3007c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) { 3017c478bd9Sstevel@tonic-gate case INVALID: 3027c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id"); 3037c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3047c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3057c478bd9Sstevel@tonic-gate case TOOBIG: 3067c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group); 3077c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3087c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3097c478bd9Sstevel@tonic-gate case RESERVED: 3107c478bd9Sstevel@tonic-gate case UNIQUE: 3117c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group); 3127c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 3137c478bd9Sstevel@tonic-gate } 3147c478bd9Sstevel@tonic-gate if (warning) 3157c478bd9Sstevel@tonic-gate warningmsg(warning, group); 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate usrdefs->defgroup = g_ptr->gr_gid; 3187c478bd9Sstevel@tonic-gate usrdefs->defgname = g_ptr->gr_name; 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* project must be an existing project */ 3230523b0a4Sbasabi if (projects != NULL) { 3247c478bd9Sstevel@tonic-gate switch (valid_project(projects, &p_ptr, mybuf, 3257c478bd9Sstevel@tonic-gate sizeof (mybuf), &warning)) { 3267c478bd9Sstevel@tonic-gate case INVALID: 3277c478bd9Sstevel@tonic-gate errmsg(M_INVALID, projects, "project id"); 3287c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3297c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3307c478bd9Sstevel@tonic-gate case TOOBIG: 3317c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "projid", projects); 3327c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3337c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 3347c478bd9Sstevel@tonic-gate case UNIQUE: 3357c478bd9Sstevel@tonic-gate errmsg(M_PROJ_NOTUSED, projects); 3367c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate if (warning) 3397c478bd9Sstevel@tonic-gate warningmsg(warning, projects); 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate usrdefs->defproj = p_ptr.pj_projid; 3427c478bd9Sstevel@tonic-gate usrdefs->defprojname = p_ptr.pj_name; 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate /* base_dir must be an existing directory */ 3460523b0a4Sbasabi if (base_dir != NULL) { 3470523b0a4Sbasabi valid_input(BASEDIR, base_dir); 3487c478bd9Sstevel@tonic-gate usrdefs->defparent = base_dir; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* inactivity period is an integer */ 3520523b0a4Sbasabi if (inactstr != NULL) { 3537c478bd9Sstevel@tonic-gate /* convert inactstr to integer */ 3547c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10); 3557c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) { 3567c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr, 3577c478bd9Sstevel@tonic-gate "inactivity period"); 3587c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate usrdefs->definact = inact; 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */ 3650523b0a4Sbasabi if (expirestr != NULL) { 3667c478bd9Sstevel@tonic-gate if (*expirestr) { 3677c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0) 3687c478bd9Sstevel@tonic-gate == INVALID) { 3697c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr, 3707c478bd9Sstevel@tonic-gate "expiration date"); 3717c478bd9Sstevel@tonic-gate exit(EX_BADARG); 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr; 3747c478bd9Sstevel@tonic-gate } else 3757c478bd9Sstevel@tonic-gate /* Unset the expiration date */ 3767c478bd9Sstevel@tonic-gate usrdefs->defexpire = ""; 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3790523b0a4Sbasabi if (shell != NULL) { 3800523b0a4Sbasabi valid_input(SHELL, shell); 3810523b0a4Sbasabi usrdefs->defshell = shell; 3820523b0a4Sbasabi } 3830523b0a4Sbasabi if (skel_dir != NULL) { 3840523b0a4Sbasabi valid_input(SKELDIR, skel_dir); 3850523b0a4Sbasabi usrdefs->defskel = skel_dir; 3860523b0a4Sbasabi } 3877c478bd9Sstevel@tonic-gate update_def(usrdefs); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate /* change defaults for useradd */ 3907c478bd9Sstevel@tonic-gate if (putusrdef(usrdefs, usertype) < 0) { 3917c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 3927c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* Now, display */ 3967c478bd9Sstevel@tonic-gate dispusrdef(stdout, (D_ALL & ~D_RID), usertype); 3977c478bd9Sstevel@tonic-gate exit(EX_SUCCESS); 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate /* ADD mode */ 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate /* check syntax */ 4040523b0a4Sbasabi if (optind != argc - 1 || (skel_dir != NULL && !mflag)) { 4057c478bd9Sstevel@tonic-gate if (is_role(usertype)) 4067c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 4077c478bd9Sstevel@tonic-gate else 4087c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 4097c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate logname = argv[optind]; 4137c478bd9Sstevel@tonic-gate switch (valid_login(logname, (struct passwd **)NULL, &warning)) { 4147c478bd9Sstevel@tonic-gate case INVALID: 4157c478bd9Sstevel@tonic-gate errmsg(M_INVALID, logname, "login name"); 4167c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4177c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate case NOTUNIQUE: 4207c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 4217c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS); 4227c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4230a1278f2SGary Mills 4240a1278f2SGary Mills case LONGNAME: 4250a1278f2SGary Mills errmsg(M_TOO_LONG, logname); 4260a1278f2SGary Mills exit(EX_BADARG); 4270a1278f2SGary Mills /*NOTREACHED*/ 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate if (warning) 4317c478bd9Sstevel@tonic-gate warningmsg(warning, logname); 4320523b0a4Sbasabi if (uidstr != NULL) { 4337c478bd9Sstevel@tonic-gate /* convert uidstr to integer */ 4347c478bd9Sstevel@tonic-gate errno = 0; 4357c478bd9Sstevel@tonic-gate uid = (uid_t)strtol(uidstr, &ptr, (int)10); 4367c478bd9Sstevel@tonic-gate if (*ptr || errno == ERANGE) { 4377c478bd9Sstevel@tonic-gate errmsg(M_INVALID, uidstr, "user id"); 4387c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate switch (valid_uid(uid, NULL)) { 4427c478bd9Sstevel@tonic-gate case NOTUNIQUE: 4437c478bd9Sstevel@tonic-gate if (!oflag) { 4447c478bd9Sstevel@tonic-gate /* override not specified */ 4457c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 4467c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate break; 4497c478bd9Sstevel@tonic-gate case RESERVED: 4507c478bd9Sstevel@tonic-gate errmsg(M_RESERVED, uid); 4517c478bd9Sstevel@tonic-gate break; 4527c478bd9Sstevel@tonic-gate case TOOBIG: 4537c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "uid", uid); 4547c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4557c478bd9Sstevel@tonic-gate break; 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate } else { 4597c478bd9Sstevel@tonic-gate 460a7fe1d5bSAndy Stormont if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) { 4617c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id", "user id"); 4627c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate 4660523b0a4Sbasabi if (group != NULL) { 4677c478bd9Sstevel@tonic-gate switch (valid_group(group, &g_ptr, &warning)) { 4687c478bd9Sstevel@tonic-gate case INVALID: 4697c478bd9Sstevel@tonic-gate errmsg(M_INVALID, group, "group id"); 4707c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4717c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4727c478bd9Sstevel@tonic-gate case TOOBIG: 4737c478bd9Sstevel@tonic-gate errmsg(M_TOOBIG, "gid", group); 4747c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4757c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4767c478bd9Sstevel@tonic-gate case RESERVED: 4777c478bd9Sstevel@tonic-gate case UNIQUE: 4787c478bd9Sstevel@tonic-gate errmsg(M_GRP_NOTUSED, group); 4797c478bd9Sstevel@tonic-gate exit(EX_NAME_NOT_EXIST); 4807c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate if (warning) 4847c478bd9Sstevel@tonic-gate warningmsg(warning, group); 4857c478bd9Sstevel@tonic-gate gid = g_ptr->gr_gid; 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate } else gid = usrdefs->defgroup; 4887c478bd9Sstevel@tonic-gate 4890523b0a4Sbasabi if (grps != NULL) { 4907c478bd9Sstevel@tonic-gate if (!*grps) 4917c478bd9Sstevel@tonic-gate /* ignore -G "" */ 4927c478bd9Sstevel@tonic-gate grps = (char *)0; 4937c478bd9Sstevel@tonic-gate else if (!(gidlist = valid_lgroup(grps, gid))) 4947c478bd9Sstevel@tonic-gate exit(EX_BADARG); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4970523b0a4Sbasabi if (projects != NULL) { 4987c478bd9Sstevel@tonic-gate if (! *projects) 4997c478bd9Sstevel@tonic-gate projects = (char *)0; 5007c478bd9Sstevel@tonic-gate else if (! (projlist = valid_lproject(projects))) 5017c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate 5040523b0a4Sbasabi /* if base_dir is provided, check its validity; otherwise default */ 5050523b0a4Sbasabi if (base_dir != NULL) 5060523b0a4Sbasabi valid_input(BASEDIR, base_dir); 5070523b0a4Sbasabi else 5080523b0a4Sbasabi base_dir = usrdefs->defparent; 5090523b0a4Sbasabi 5100523b0a4Sbasabi if (dir == NULL) { 5117c478bd9Sstevel@tonic-gate /* set homedir to home directory made from base_dir */ 5120523b0a4Sbasabi (void) sprintf(homedir, "%s/%s", base_dir, logname); 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate } else if (REL_PATH(dir)) { 5157c478bd9Sstevel@tonic-gate errmsg(M_RELPATH, dir); 5167c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate } else 5197c478bd9Sstevel@tonic-gate (void) strcpy(homedir, dir); 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate if (mflag) { 5227c478bd9Sstevel@tonic-gate /* Does home dir. already exist? */ 5237c478bd9Sstevel@tonic-gate if (stat(homedir, &statbuf) == 0) { 5247c478bd9Sstevel@tonic-gate /* directory exists - don't try to create */ 5257c478bd9Sstevel@tonic-gate mflag = 0; 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate if (check_perm(statbuf, uid, gid, S_IXOTH) != 0) 5287c478bd9Sstevel@tonic-gate errmsg(M_NO_PERM, logname, homedir); 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate } 5310523b0a4Sbasabi /* 5320523b0a4Sbasabi * if shell, skel_dir are provided, check their validity. 5330523b0a4Sbasabi * Otherwise default. 5340523b0a4Sbasabi */ 5350523b0a4Sbasabi if (shell != NULL) 5360523b0a4Sbasabi valid_input(SHELL, shell); 5370523b0a4Sbasabi else 5380523b0a4Sbasabi shell = usrdefs->defshell; 5397c478bd9Sstevel@tonic-gate 5400523b0a4Sbasabi if (skel_dir != NULL) 5410523b0a4Sbasabi valid_input(SKELDIR, skel_dir); 5420523b0a4Sbasabi else 5430523b0a4Sbasabi skel_dir = usrdefs->defskel; 5447c478bd9Sstevel@tonic-gate 5450523b0a4Sbasabi if (inactstr != NULL) { 5467c478bd9Sstevel@tonic-gate /* convert inactstr to integer */ 5477c478bd9Sstevel@tonic-gate inact = strtol(inactstr, &ptr, 10); 5487c478bd9Sstevel@tonic-gate if (*ptr || inact < 0) { 5497c478bd9Sstevel@tonic-gate errmsg(M_INVALID, inactstr, "inactivity period"); 5507c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate } else inact = usrdefs->definact; 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate /* expiration string is a date, newer than today */ 5550523b0a4Sbasabi if (expirestr != NULL) { 5567c478bd9Sstevel@tonic-gate if (*expirestr) { 5577c478bd9Sstevel@tonic-gate if (valid_expire(expirestr, (time_t *)0) == INVALID) { 5587c478bd9Sstevel@tonic-gate errmsg(M_INVALID, expirestr, "expiration date"); 5597c478bd9Sstevel@tonic-gate exit(EX_BADARG); 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate usrdefs->defexpire = expirestr; 5627c478bd9Sstevel@tonic-gate } else 5637c478bd9Sstevel@tonic-gate /* Unset the expiration date */ 5647c478bd9Sstevel@tonic-gate expirestr = (char *)0; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate } else expirestr = usrdefs->defexpire; 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate import_def(usrdefs); 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate /* must now call passmgmt */ 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate /* set up arguments to passmgmt in nargv array */ 5737c478bd9Sstevel@tonic-gate nargv = malloc((30 + nkeys * 2) * sizeof (char *)); 5747c478bd9Sstevel@tonic-gate argindex = 0; 575c651b32eSJohn Sonnenschein nargv[argindex++] = PASSMGMT; 5767c478bd9Sstevel@tonic-gate nargv[argindex++] = "-a"; /* add */ 5777c478bd9Sstevel@tonic-gate 5780523b0a4Sbasabi if (comment != NULL) { 5797c478bd9Sstevel@tonic-gate /* comment */ 5807c478bd9Sstevel@tonic-gate nargv[argindex++] = "-c"; 5817c478bd9Sstevel@tonic-gate nargv[argindex++] = comment; 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate /* flags for home directory */ 5857c478bd9Sstevel@tonic-gate nargv[argindex++] = "-h"; 5867c478bd9Sstevel@tonic-gate nargv[argindex++] = homedir; 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate /* set gid flag */ 5897c478bd9Sstevel@tonic-gate nargv[argindex++] = "-g"; 590f48205beScasper (void) sprintf(gidstring, "%u", gid); 5917c478bd9Sstevel@tonic-gate nargv[argindex++] = gidstring; 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate /* shell */ 5947c478bd9Sstevel@tonic-gate nargv[argindex++] = "-s"; 5957c478bd9Sstevel@tonic-gate nargv[argindex++] = shell; 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate /* set inactive */ 5987c478bd9Sstevel@tonic-gate nargv[argindex++] = "-f"; 5997c478bd9Sstevel@tonic-gate (void) sprintf(inactstring, "%ld", inact); 6007c478bd9Sstevel@tonic-gate nargv[argindex++] = inactstring; 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate /* set expiration date */ 6030523b0a4Sbasabi if (expirestr != NULL) { 6047c478bd9Sstevel@tonic-gate nargv[argindex++] = "-e"; 6057c478bd9Sstevel@tonic-gate nargv[argindex++] = expirestr; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate /* set uid flag */ 6097c478bd9Sstevel@tonic-gate nargv[argindex++] = "-u"; 610f48205beScasper (void) sprintf(uidstring, "%u", uid); 6117c478bd9Sstevel@tonic-gate nargv[argindex++] = uidstring; 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate if (oflag) nargv[argindex++] = "-o"; 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate if (nkeys > 1) 6167c478bd9Sstevel@tonic-gate addkey_args(nargv, &argindex); 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate /* finally - login name */ 6197c478bd9Sstevel@tonic-gate nargv[argindex++] = logname; 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate /* set the last to null */ 6227c478bd9Sstevel@tonic-gate nargv[argindex++] = NULL; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate /* now call passmgmt */ 6257c478bd9Sstevel@tonic-gate ret = PEX_FAILED; 6267c478bd9Sstevel@tonic-gate /* 6277c478bd9Sstevel@tonic-gate * If call_passmgmt fails for any reason other than PEX_BADUID, exit 6287c478bd9Sstevel@tonic-gate * is invoked with an appropriate error message. If PEX_BADUID is 6297c478bd9Sstevel@tonic-gate * returned, then if the user specified the ID, exit is invoked 6307c478bd9Sstevel@tonic-gate * with an appropriate error message. Otherwise we try to pick a 6317c478bd9Sstevel@tonic-gate * different ID and try again. If we run out of IDs, i.e. no more 6327c478bd9Sstevel@tonic-gate * users can be created, then -1 is returned and we terminate via exit. 6337c478bd9Sstevel@tonic-gate * If PEX_BUSY is returned we increment a count, since we will stop 6347c478bd9Sstevel@tonic-gate * trying if PEX_BUSY reaches 3. For PEX_SUCCESS we immediately 6357c478bd9Sstevel@tonic-gate * terminate the loop. 6367c478bd9Sstevel@tonic-gate */ 6377c478bd9Sstevel@tonic-gate while (busy < 3 && ret != PEX_SUCCESS) { 6387c478bd9Sstevel@tonic-gate switch (ret = call_passmgmt(nargv)) { 6397c478bd9Sstevel@tonic-gate case PEX_SUCCESS: 6407c478bd9Sstevel@tonic-gate break; 6417c478bd9Sstevel@tonic-gate case PEX_BUSY: 6427c478bd9Sstevel@tonic-gate busy++; 6437c478bd9Sstevel@tonic-gate break; 6447c478bd9Sstevel@tonic-gate case PEX_HOSED_FILES: 6457c478bd9Sstevel@tonic-gate errmsg(M_HOSED_FILES); 6467c478bd9Sstevel@tonic-gate exit(EX_INCONSISTENT); 6477c478bd9Sstevel@tonic-gate break; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate case PEX_SYNTAX: 6507c478bd9Sstevel@tonic-gate case PEX_BADARG: 6517c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */ 6527c478bd9Sstevel@tonic-gate if (is_role(usertype)) 6537c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 6547c478bd9Sstevel@tonic-gate else 6557c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 6567c478bd9Sstevel@tonic-gate exit(EX_SYNTAX); 6577c478bd9Sstevel@tonic-gate break; 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate case PEX_BADUID: 6607c478bd9Sstevel@tonic-gate /* 6617c478bd9Sstevel@tonic-gate * The uid has been taken. If it was specified by a 6627c478bd9Sstevel@tonic-gate * user, then we must fail. Otherwise, keep trying 6637c478bd9Sstevel@tonic-gate * to get a good uid until we run out of IDs. 6647c478bd9Sstevel@tonic-gate */ 6657c478bd9Sstevel@tonic-gate if (uidstr != NULL) { 6667c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 6677c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 6687c478bd9Sstevel@tonic-gate } else { 669a7fe1d5bSAndy Stormont if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) { 6707c478bd9Sstevel@tonic-gate errmsg(M_INVALID, "default id", 6717c478bd9Sstevel@tonic-gate "user id"); 6727c478bd9Sstevel@tonic-gate exit(EX_ID_EXISTS); 6737c478bd9Sstevel@tonic-gate } 674f48205beScasper (void) sprintf(uidstring, "%u", uid); 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate break; 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate case PEX_BADNAME: 6797c478bd9Sstevel@tonic-gate /* invalid loname */ 6807c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 6817c478bd9Sstevel@tonic-gate exit(EX_NAME_EXISTS); 6827c478bd9Sstevel@tonic-gate break; 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate default: 6857c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6867c478bd9Sstevel@tonic-gate exit(ret); 6877c478bd9Sstevel@tonic-gate break; 6887c478bd9Sstevel@tonic-gate } 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate if (busy == 3) { 6917c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6927c478bd9Sstevel@tonic-gate exit(ret); 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate /* add group entry */ 6960523b0a4Sbasabi if ((grps != NULL) && edit_group(logname, (char *)0, gidlist, 0)) { 6977c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 6987c478bd9Sstevel@tonic-gate cleanup(logname); 6997c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate /* update project database */ 7030523b0a4Sbasabi if ((projects != NULL) && 7040523b0a4Sbasabi edit_project(logname, (char *)NULL, projlist, 0)) { 7057c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 7067c478bd9Sstevel@tonic-gate cleanup(logname); 7077c478bd9Sstevel@tonic-gate exit(EX_UPDATE); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate /* create home directory */ 711*7fc68ddfSAlbert Lee if (mflag) { 712*7fc68ddfSAlbert Lee zfs_flags = get_default_zfs_flags(); 713*7fc68ddfSAlbert Lee 714*7fc68ddfSAlbert Lee if (zflag || mflag > 1) 715*7fc68ddfSAlbert Lee zfs_flags |= MANAGE_ZFS; 716*7fc68ddfSAlbert Lee else if (Zflag) 717*7fc68ddfSAlbert Lee zfs_flags &= ~MANAGE_ZFS; 718*7fc68ddfSAlbert Lee ret = create_home(homedir, skel_dir, uid, gid, zfs_flags); 719*7fc68ddfSAlbert Lee } 720*7fc68ddfSAlbert Lee if (ret != EX_SUCCESS) { 721*7fc68ddfSAlbert Lee (void) edit_project(logname, (char *)NULL, (projid_t **)NULL, 722*7fc68ddfSAlbert Lee 0); 7237c478bd9Sstevel@tonic-gate (void) edit_group(logname, (char *)0, (int **)0, 1); 7247c478bd9Sstevel@tonic-gate cleanup(logname); 7257c478bd9Sstevel@tonic-gate exit(EX_HOMEDIR); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate return (ret); 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate static void 7327c478bd9Sstevel@tonic-gate cleanup(logname) 7337c478bd9Sstevel@tonic-gate char *logname; 7347c478bd9Sstevel@tonic-gate { 7357c478bd9Sstevel@tonic-gate char *nargv[4]; 7367c478bd9Sstevel@tonic-gate 737c651b32eSJohn Sonnenschein nargv[0] = PASSMGMT; 7387c478bd9Sstevel@tonic-gate nargv[1] = "-d"; 7397c478bd9Sstevel@tonic-gate nargv[2] = logname; 7407c478bd9Sstevel@tonic-gate nargv[3] = NULL; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate switch (call_passmgmt(nargv)) { 7437c478bd9Sstevel@tonic-gate case PEX_SUCCESS: 7447c478bd9Sstevel@tonic-gate break; 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate case PEX_SYNTAX: 7477c478bd9Sstevel@tonic-gate /* should NEVER occur that passmgmt usage is wrong */ 7487c478bd9Sstevel@tonic-gate if (is_role(usertype)) 7497c478bd9Sstevel@tonic-gate errmsg(M_ARUSAGE); 7507c478bd9Sstevel@tonic-gate else 7517c478bd9Sstevel@tonic-gate errmsg(M_AUSAGE); 7527c478bd9Sstevel@tonic-gate break; 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate case PEX_BADUID: 7557c478bd9Sstevel@tonic-gate /* uid is used - shouldn't happen but print message anyway */ 7567c478bd9Sstevel@tonic-gate errmsg(M_UID_USED, uid); 7577c478bd9Sstevel@tonic-gate break; 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate case PEX_BADNAME: 7607c478bd9Sstevel@tonic-gate /* invalid loname */ 7617c478bd9Sstevel@tonic-gate errmsg(M_USED, logname); 7627c478bd9Sstevel@tonic-gate break; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate default: 7657c478bd9Sstevel@tonic-gate errmsg(M_UPDATE, "created"); 7667c478bd9Sstevel@tonic-gate break; 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate } 7690523b0a4Sbasabi 7700523b0a4Sbasabi /* Check the validity for shell, base_dir and skel_dir */ 7710523b0a4Sbasabi 7720523b0a4Sbasabi void 7730523b0a4Sbasabi valid_input(path_opt_t opt, const char *input) 7740523b0a4Sbasabi { 7750523b0a4Sbasabi struct stat statbuf; 7760523b0a4Sbasabi 7770523b0a4Sbasabi if (REL_PATH(input)) { 7780523b0a4Sbasabi errmsg(M_RELPATH, input); 7790523b0a4Sbasabi exit(EX_BADARG); 7800523b0a4Sbasabi } 7810523b0a4Sbasabi if (stat(input, &statbuf) == -1) { 7820523b0a4Sbasabi errmsg(M_INVALID, input, "path"); 7830523b0a4Sbasabi exit(EX_BADARG); 7840523b0a4Sbasabi } 7850523b0a4Sbasabi if (opt == SHELL) { 7860523b0a4Sbasabi if (!S_ISREG(statbuf.st_mode) || 7870523b0a4Sbasabi (statbuf.st_mode & 0555) != 0555) { 7880523b0a4Sbasabi errmsg(M_INVALID, input, "shell"); 7890523b0a4Sbasabi exit(EX_BADARG); 7900523b0a4Sbasabi } 7910523b0a4Sbasabi } else { 7920523b0a4Sbasabi if (!S_ISDIR(statbuf.st_mode)) { 7930523b0a4Sbasabi errmsg(M_INVALID, input, "directory"); 7940523b0a4Sbasabi exit(EX_BADARG); 7950523b0a4Sbasabi } 7960523b0a4Sbasabi } 7970523b0a4Sbasabi } 798