10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*108Sbasabi
23*108Sbasabi /*
24*108Sbasabi * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25*108Sbasabi * Use is subject to license terms.
26*108Sbasabi */
27*108Sbasabi
280Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate
310Sstevel@tonic-gate
32*108Sbasabi #pragma ident "%Z%%M% %I% %E% SMI"
330Sstevel@tonic-gate
340Sstevel@tonic-gate /*LINTLIBRARY*/
350Sstevel@tonic-gate
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <stdio.h>
380Sstevel@tonic-gate #include <string.h>
390Sstevel@tonic-gate #include <userdefs.h>
400Sstevel@tonic-gate #include <user_attr.h>
410Sstevel@tonic-gate #include <limits.h>
420Sstevel@tonic-gate #include <stdlib.h>
430Sstevel@tonic-gate #include <stddef.h>
440Sstevel@tonic-gate #include <time.h>
450Sstevel@tonic-gate #include <unistd.h>
460Sstevel@tonic-gate #include "userdisp.h"
470Sstevel@tonic-gate #include "funcs.h"
480Sstevel@tonic-gate #include "messages.h"
490Sstevel@tonic-gate
500Sstevel@tonic-gate /* Print out a NL when the line gets too long */
510Sstevel@tonic-gate #define PRINTNL() \
520Sstevel@tonic-gate if (outcount > 40) { \
530Sstevel@tonic-gate outcount = 0; \
540Sstevel@tonic-gate (void) fprintf(fptr, "\n"); \
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate #define SKIPWS(ptr) while (*ptr && *ptr == ' ' || *ptr == '\t') ptr++
580Sstevel@tonic-gate
590Sstevel@tonic-gate static char *dup_to_nl(char *);
600Sstevel@tonic-gate
610Sstevel@tonic-gate static struct userdefs defaults = {
620Sstevel@tonic-gate DEFRID, DEFGROUP, DEFGNAME, DEFPARENT, DEFSKL,
630Sstevel@tonic-gate DEFSHL, DEFINACT, DEFEXPIRE, DEFAUTH, DEFPROF,
640Sstevel@tonic-gate DEFROLE, DEFPROJ, DEFPROJNAME, DEFLIMPRIV,
650Sstevel@tonic-gate DEFDFLTPRIV, DEFLOCK_AFTER_RETRIES
660Sstevel@tonic-gate };
670Sstevel@tonic-gate
680Sstevel@tonic-gate #define INT 0
690Sstevel@tonic-gate #define STR 1
700Sstevel@tonic-gate #define PROJID 2
710Sstevel@tonic-gate
720Sstevel@tonic-gate #define DEFOFF(field) offsetof(struct userdefs, field)
730Sstevel@tonic-gate #define FIELD(up, pe, type) (*(type *)((char *)(up) + (pe)->off))
740Sstevel@tonic-gate
750Sstevel@tonic-gate typedef struct parsent {
760Sstevel@tonic-gate const char *name; /* deffoo= */
770Sstevel@tonic-gate const size_t nmsz; /* length of def= string (excluding \0) */
780Sstevel@tonic-gate const int type; /* type of entry */
790Sstevel@tonic-gate const ptrdiff_t off; /* offset in userdefs structure */
800Sstevel@tonic-gate const char *uakey; /* user_attr key, if defined */
810Sstevel@tonic-gate } parsent_t;
820Sstevel@tonic-gate
830Sstevel@tonic-gate static const parsent_t tab[] = {
840Sstevel@tonic-gate { GIDSTR, sizeof (GIDSTR) - 1, INT, DEFOFF(defgroup) },
850Sstevel@tonic-gate { GNAMSTR, sizeof (GNAMSTR) - 1, STR, DEFOFF(defgname) },
860Sstevel@tonic-gate { PARSTR, sizeof (PARSTR) - 1, STR, DEFOFF(defparent) },
870Sstevel@tonic-gate { SKLSTR, sizeof (SKLSTR) - 1, STR, DEFOFF(defskel) },
880Sstevel@tonic-gate { SHELLSTR, sizeof (SHELLSTR) - 1, STR, DEFOFF(defshell) },
890Sstevel@tonic-gate { INACTSTR, sizeof (INACTSTR) - 1, INT, DEFOFF(definact) },
900Sstevel@tonic-gate { EXPIRESTR, sizeof (EXPIRESTR) - 1, STR, DEFOFF(defexpire) },
910Sstevel@tonic-gate { AUTHSTR, sizeof (AUTHSTR) - 1, STR, DEFOFF(defauth),
920Sstevel@tonic-gate USERATTR_AUTHS_KW },
930Sstevel@tonic-gate { ROLESTR, sizeof (ROLESTR) - 1, STR, DEFOFF(defrole),
940Sstevel@tonic-gate USERATTR_ROLES_KW },
950Sstevel@tonic-gate { PROFSTR, sizeof (PROFSTR) - 1, STR, DEFOFF(defprof),
960Sstevel@tonic-gate USERATTR_PROFILES_KW },
970Sstevel@tonic-gate { PROJSTR, sizeof (PROJSTR) - 1, PROJID, DEFOFF(defproj) },
980Sstevel@tonic-gate { PROJNMSTR, sizeof (PROJNMSTR) - 1, STR, DEFOFF(defprojname) },
990Sstevel@tonic-gate { LIMPRSTR, sizeof (LIMPRSTR) - 1, STR, DEFOFF(deflimpriv),
1000Sstevel@tonic-gate USERATTR_LIMPRIV_KW },
1010Sstevel@tonic-gate { DFLTPRSTR, sizeof (DFLTPRSTR) - 1, STR, DEFOFF(defdfltpriv),
1020Sstevel@tonic-gate USERATTR_DFLTPRIV_KW },
1030Sstevel@tonic-gate { LOCK_AFTER_RETRIESSTR, sizeof (LOCK_AFTER_RETRIESSTR) - 1,
1040Sstevel@tonic-gate STR, DEFOFF(deflock_after_retries),
1050Sstevel@tonic-gate USERATTR_LOCK_AFTER_RETRIES_KW },
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate #define NDEF (sizeof (tab) / sizeof (parsent_t))
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate FILE *defptr; /* default file - fptr */
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate static const parsent_t *
scan(char ** start_p)1130Sstevel@tonic-gate scan(char **start_p)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate static int ind = NDEF - 1;
1160Sstevel@tonic-gate char *cur_p = *start_p;
1170Sstevel@tonic-gate int lastind = ind;
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate if (!*cur_p || *cur_p == '\n' || *cur_p == '#')
1200Sstevel@tonic-gate return (NULL);
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate /*
1230Sstevel@tonic-gate * The magic in this loop is remembering the last index when
1240Sstevel@tonic-gate * reentering the function; the entries above are also used to
1250Sstevel@tonic-gate * order the output to the default file.
1260Sstevel@tonic-gate */
1270Sstevel@tonic-gate do {
1280Sstevel@tonic-gate ind++;
1290Sstevel@tonic-gate ind %= NDEF;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate if (strncmp(cur_p, tab[ind].name, tab[ind].nmsz) == 0) {
1320Sstevel@tonic-gate *start_p = cur_p + tab[ind].nmsz;
1330Sstevel@tonic-gate return (&tab[ind]);
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate } while (ind != lastind);
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate return (NULL);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate * getusrdef - access the user defaults file. If it doesn't exist,
1420Sstevel@tonic-gate * then returns default values of (values in userdefs.h):
1430Sstevel@tonic-gate * defrid = 100
1440Sstevel@tonic-gate * defgroup = 1
1450Sstevel@tonic-gate * defgname = other
1460Sstevel@tonic-gate * defparent = /home
1470Sstevel@tonic-gate * defskel = /usr/sadm/skel
1480Sstevel@tonic-gate * defshell = /bin/sh
1490Sstevel@tonic-gate * definact = 0
1500Sstevel@tonic-gate * defexpire = 0
1510Sstevel@tonic-gate * defauth = 0
1520Sstevel@tonic-gate * defprof = 0
1530Sstevel@tonic-gate * defrole = 0
1540Sstevel@tonic-gate *
1550Sstevel@tonic-gate * If getusrdef() is unable to access the defaults file, it
1560Sstevel@tonic-gate * returns a NULL pointer.
1570Sstevel@tonic-gate *
1580Sstevel@tonic-gate * If user defaults file exists, then getusrdef uses values
1590Sstevel@tonic-gate * in it to override the above values.
1600Sstevel@tonic-gate */
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate struct userdefs *
getusrdef(char * usertype)1630Sstevel@tonic-gate getusrdef(char *usertype)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate char instr[512], *ptr;
1660Sstevel@tonic-gate const parsent_t *pe;
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate if (is_role(usertype)) {
1690Sstevel@tonic-gate if ((defptr = fopen(DEFROLEFILE, "r")) == NULL) {
1700Sstevel@tonic-gate defaults.defshell = DEFROLESHL;
1710Sstevel@tonic-gate defaults.defprof = DEFROLEPROF;
1720Sstevel@tonic-gate return (&defaults);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate } else {
1750Sstevel@tonic-gate if ((defptr = fopen(DEFFILE, "r")) == NULL)
1760Sstevel@tonic-gate return (&defaults);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate
1790Sstevel@tonic-gate while (fgets(instr, sizeof (instr), defptr) != NULL) {
1800Sstevel@tonic-gate ptr = instr;
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate SKIPWS(ptr);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate if (*ptr == '#')
1850Sstevel@tonic-gate continue;
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate pe = scan(&ptr);
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate if (pe != NULL) {
1900Sstevel@tonic-gate switch (pe->type) {
1910Sstevel@tonic-gate case INT:
1920Sstevel@tonic-gate FIELD(&defaults, pe, int) =
1930Sstevel@tonic-gate (int)strtol(ptr, NULL, 10);
1940Sstevel@tonic-gate break;
1950Sstevel@tonic-gate case PROJID:
1960Sstevel@tonic-gate FIELD(&defaults, pe, projid_t) =
1970Sstevel@tonic-gate (projid_t)strtol(ptr, NULL, 10);
1980Sstevel@tonic-gate break;
1990Sstevel@tonic-gate case STR:
2000Sstevel@tonic-gate FIELD(&defaults, pe, char *) = dup_to_nl(ptr);
2010Sstevel@tonic-gate break;
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate (void) fclose(defptr);
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate return (&defaults);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate static char *
dup_to_nl(char * from)2120Sstevel@tonic-gate dup_to_nl(char *from)
2130Sstevel@tonic-gate {
2140Sstevel@tonic-gate char *res = strdup(from);
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate char *p = strchr(res, '\n');
2170Sstevel@tonic-gate if (p)
2180Sstevel@tonic-gate *p = '\0';
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate return (res);
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate void
dispusrdef(FILE * fptr,unsigned flags,char * usertype)224*108Sbasabi dispusrdef(FILE *fptr, unsigned flags, char *usertype)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate struct userdefs *deflts = getusrdef(usertype);
227*108Sbasabi int outcount = 0;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate /* Print out values */
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate if (flags & D_GROUP) {
2320Sstevel@tonic-gate outcount += fprintf(fptr, "group=%s,%ld ",
2330Sstevel@tonic-gate deflts->defgname, deflts->defgroup);
2340Sstevel@tonic-gate PRINTNL();
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate if (flags & D_PROJ) {
2380Sstevel@tonic-gate outcount += fprintf(fptr, "project=%s,%ld ",
2390Sstevel@tonic-gate deflts->defprojname, deflts->defproj);
2400Sstevel@tonic-gate PRINTNL();
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate if (flags & D_BASEDIR) {
2440Sstevel@tonic-gate outcount += fprintf(fptr, "basedir=%s ", deflts->defparent);
2450Sstevel@tonic-gate PRINTNL();
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate
2480Sstevel@tonic-gate if (flags & D_RID) {
2490Sstevel@tonic-gate outcount += fprintf(fptr, "rid=%ld ", deflts->defrid);
2500Sstevel@tonic-gate PRINTNL();
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate if (flags & D_SKEL) {
2540Sstevel@tonic-gate outcount += fprintf(fptr, "skel=%s ", deflts->defskel);
2550Sstevel@tonic-gate PRINTNL();
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate if (flags & D_SHELL) {
2590Sstevel@tonic-gate outcount += fprintf(fptr, "shell=%s ", deflts->defshell);
2600Sstevel@tonic-gate PRINTNL();
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate if (flags & D_INACT) {
2640Sstevel@tonic-gate outcount += fprintf(fptr, "inactive=%d ", deflts->definact);
2650Sstevel@tonic-gate PRINTNL();
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate if (flags & D_EXPIRE) {
2690Sstevel@tonic-gate outcount += fprintf(fptr, "expire=%s ", deflts->defexpire);
2700Sstevel@tonic-gate PRINTNL();
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate if (flags & D_AUTH) {
2740Sstevel@tonic-gate outcount += fprintf(fptr, "auths=%s ", deflts->defauth);
2750Sstevel@tonic-gate PRINTNL();
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate if (flags & D_PROF) {
2790Sstevel@tonic-gate outcount += fprintf(fptr, "profiles=%s ", deflts->defprof);
2800Sstevel@tonic-gate PRINTNL();
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate if ((flags & D_ROLE) &&
2840Sstevel@tonic-gate (!is_role(usertype))) {
2850Sstevel@tonic-gate outcount += fprintf(fptr, "roles=%s ", deflts->defrole);
2860Sstevel@tonic-gate PRINTNL();
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate if (flags & D_LPRIV) {
2900Sstevel@tonic-gate outcount += fprintf(fptr, "limitpriv=%s ",
2910Sstevel@tonic-gate deflts->deflimpriv);
2920Sstevel@tonic-gate PRINTNL();
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate if (flags & D_DPRIV) {
2960Sstevel@tonic-gate outcount += fprintf(fptr, "defaultpriv=%s ",
2970Sstevel@tonic-gate deflts->defdfltpriv);
2980Sstevel@tonic-gate PRINTNL();
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate if (flags & D_LOCK) {
3020Sstevel@tonic-gate outcount += fprintf(fptr, "lock_after_retries=%s ",
3030Sstevel@tonic-gate deflts->deflock_after_retries);
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate if (outcount > 0)
3070Sstevel@tonic-gate (void) fprintf(fptr, "\n");
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /*
3110Sstevel@tonic-gate * putusrdef -
3120Sstevel@tonic-gate * changes default values in defadduser file
3130Sstevel@tonic-gate */
3140Sstevel@tonic-gate int
putusrdef(struct userdefs * defs,char * usertype)3150Sstevel@tonic-gate putusrdef(struct userdefs *defs, char *usertype)
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate time_t timeval; /* time value from time */
3180Sstevel@tonic-gate int i;
3190Sstevel@tonic-gate ptrdiff_t skip;
3200Sstevel@tonic-gate char *hdr;
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate /*
3230Sstevel@tonic-gate * file format is:
3240Sstevel@tonic-gate * #<tab>Default values for adduser. Changed mm/dd/yy hh:mm:ss.
3250Sstevel@tonic-gate * defgroup=m (m=default group id)
3260Sstevel@tonic-gate * defgname=str1 (str1=default group name)
3270Sstevel@tonic-gate * defparent=str2 (str2=default base directory)
3280Sstevel@tonic-gate * definactive=x (x=default inactive)
3290Sstevel@tonic-gate * defexpire=y (y=default expire)
3300Sstevel@tonic-gate * defproj=z (z=numeric project id)
3310Sstevel@tonic-gate * defprojname=str3 (str3=default project name)
3320Sstevel@tonic-gate * ... etc ...
3330Sstevel@tonic-gate */
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate if (is_role(usertype)) {
3360Sstevel@tonic-gate if ((defptr = fopen(DEFROLEFILE, "w")) == NULL) {
3370Sstevel@tonic-gate errmsg(M_FAILED);
3380Sstevel@tonic-gate return (EX_UPDATE);
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate } else {
3410Sstevel@tonic-gate if ((defptr = fopen(DEFFILE, "w")) == NULL) {
3420Sstevel@tonic-gate errmsg(M_FAILED);
3430Sstevel@tonic-gate return (EX_UPDATE);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate
3470Sstevel@tonic-gate if (lockf(fileno(defptr), F_LOCK, 0) != 0) {
3480Sstevel@tonic-gate /* print error if can't lock whole of DEFFILE */
3490Sstevel@tonic-gate errmsg(M_UPDATE, "created");
3500Sstevel@tonic-gate return (EX_UPDATE);
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate if (is_role(usertype)) {
3540Sstevel@tonic-gate /* If it's a role, we must skip the defrole field */
3550Sstevel@tonic-gate skip = offsetof(struct userdefs, defrole);
3560Sstevel@tonic-gate hdr = FHEADER_ROLE;
3570Sstevel@tonic-gate } else {
3580Sstevel@tonic-gate skip = -1;
3590Sstevel@tonic-gate hdr = FHEADER;
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate /* get time */
3630Sstevel@tonic-gate timeval = time(NULL);
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate /* write it to file */
3660Sstevel@tonic-gate if (fprintf(defptr, "%s%s\n", hdr, ctime(&timeval)) <= 0) {
3670Sstevel@tonic-gate errmsg(M_UPDATE, "created");
3680Sstevel@tonic-gate return (EX_UPDATE);
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate for (i = 0; i < NDEF; i++) {
3720Sstevel@tonic-gate int res = 0;
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate if (tab[i].off == skip)
3750Sstevel@tonic-gate continue;
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate switch (tab[i].type) {
3780Sstevel@tonic-gate case INT:
3790Sstevel@tonic-gate res = fprintf(defptr, "%s%d\n", tab[i].name,
3800Sstevel@tonic-gate FIELD(defs, &tab[i], int));
3810Sstevel@tonic-gate break;
3820Sstevel@tonic-gate case STR:
3830Sstevel@tonic-gate res = fprintf(defptr, "%s%s\n", tab[i].name,
3840Sstevel@tonic-gate FIELD(defs, &tab[i], char *));
3850Sstevel@tonic-gate break;
3860Sstevel@tonic-gate case PROJID:
3870Sstevel@tonic-gate res = fprintf(defptr, "%s%d\n", tab[i].name,
3880Sstevel@tonic-gate (int)FIELD(defs, &tab[i], projid_t));
3890Sstevel@tonic-gate break;
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate if (res <= 0) {
3930Sstevel@tonic-gate errmsg(M_UPDATE, "created");
3940Sstevel@tonic-gate return (EX_UPDATE);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate (void) lockf(fileno(defptr), F_ULOCK, 0);
3990Sstevel@tonic-gate (void) fclose(defptr);
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate return (EX_SUCCESS);
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate /* Export command line keys to defaults for useradd -D */
4050Sstevel@tonic-gate void
update_def(struct userdefs * ud)4060Sstevel@tonic-gate update_def(struct userdefs *ud)
4070Sstevel@tonic-gate {
4080Sstevel@tonic-gate int i;
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate for (i = 0; i < NDEF; i++) {
4110Sstevel@tonic-gate char *val;
4120Sstevel@tonic-gate if (tab[i].uakey != NULL &&
4130Sstevel@tonic-gate (val = getsetdefval(tab[i].uakey, NULL)) != NULL)
4140Sstevel@tonic-gate FIELD(ud, &tab[i], char *) = val;
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate /* Import default keys for ordinary useradd */
4190Sstevel@tonic-gate void
import_def(struct userdefs * ud)4200Sstevel@tonic-gate import_def(struct userdefs *ud)
4210Sstevel@tonic-gate {
4220Sstevel@tonic-gate int i;
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate for (i = 0; i < NDEF; i++) {
4250Sstevel@tonic-gate if (tab[i].uakey != NULL && tab[i].type == STR) {
4260Sstevel@tonic-gate char *val = FIELD(ud, &tab[i], char *);
4270Sstevel@tonic-gate if (val == getsetdefval(tab[i].uakey, val))
4280Sstevel@tonic-gate nkeys ++;
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate }
432