4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 * Copyright (c) 2013 RackTop Systems.
37 #include <sys/types.h>
41 #include <user_attr.h>
51 /* Print out a NL when the line gets too long */
53 if (outcount > 40) { \
55 (void) fprintf(fptr, "\n"); \
58 #define SKIPWS(ptr) while (*ptr && (*ptr == ' ' || *ptr == '\t')) ptr++
60 static char *dup_to_nl(char *);
62 static struct userdefs defaults
= {
63 DEFRID
, DEFGROUP
, DEFGNAME
, DEFPARENT
, DEFSKL
,
64 DEFSHL
, DEFINACT
, DEFEXPIRE
, DEFAUTH
, DEFPROF
,
65 DEFROLE
, DEFPROJ
, DEFPROJNAME
, DEFLIMPRIV
,
66 DEFDFLTPRIV
, DEFLOCK_AFTER_RETRIES
73 #define DEFOFF(field) offsetof(struct userdefs, field)
74 #define FIELD(up, pe, type) (*(type *)((char *)(up) + (pe)->off))
76 typedef struct parsent
{
77 const char *name
; /* deffoo= */
78 const size_t nmsz
; /* length of def= string (excluding \0) */
79 const int type
; /* type of entry */
80 const ptrdiff_t off
; /* offset in userdefs structure */
81 const char *uakey
; /* user_attr key, if defined */
84 static const parsent_t tab
[] = {
85 { GIDSTR
, sizeof (GIDSTR
) - 1, INT
, DEFOFF(defgroup
) },
86 { GNAMSTR
, sizeof (GNAMSTR
) - 1, STR
, DEFOFF(defgname
) },
87 { PARSTR
, sizeof (PARSTR
) - 1, STR
, DEFOFF(defparent
) },
88 { SKLSTR
, sizeof (SKLSTR
) - 1, STR
, DEFOFF(defskel
) },
89 { SHELLSTR
, sizeof (SHELLSTR
) - 1, STR
, DEFOFF(defshell
) },
90 { INACTSTR
, sizeof (INACTSTR
) - 1, INT
, DEFOFF(definact
) },
91 { EXPIRESTR
, sizeof (EXPIRESTR
) - 1, STR
, DEFOFF(defexpire
) },
92 { AUTHSTR
, sizeof (AUTHSTR
) - 1, STR
, DEFOFF(defauth
),
94 { ROLESTR
, sizeof (ROLESTR
) - 1, STR
, DEFOFF(defrole
),
96 { PROFSTR
, sizeof (PROFSTR
) - 1, STR
, DEFOFF(defprof
),
97 USERATTR_PROFILES_KW
},
98 { PROJSTR
, sizeof (PROJSTR
) - 1, PROJID
, DEFOFF(defproj
) },
99 { PROJNMSTR
, sizeof (PROJNMSTR
) - 1, STR
, DEFOFF(defprojname
) },
100 { LIMPRSTR
, sizeof (LIMPRSTR
) - 1, STR
, DEFOFF(deflimpriv
),
101 USERATTR_LIMPRIV_KW
},
102 { DFLTPRSTR
, sizeof (DFLTPRSTR
) - 1, STR
, DEFOFF(defdfltpriv
),
103 USERATTR_DFLTPRIV_KW
},
104 { LOCK_AFTER_RETRIESSTR
, sizeof (LOCK_AFTER_RETRIESSTR
) - 1,
105 STR
, DEFOFF(deflock_after_retries
),
106 USERATTR_LOCK_AFTER_RETRIES_KW
},
109 #define NDEF (sizeof (tab) / sizeof (parsent_t))
111 static const parsent_t
*
114 static int ind
= NDEF
- 1;
115 char *cur_p
= *start_p
;
118 if (!*cur_p
|| *cur_p
== '\n' || *cur_p
== '#')
122 * The magic in this loop is remembering the last index when
123 * reentering the function; the entries above are also used to
124 * order the output to the default file.
130 if (strncmp(cur_p
, tab
[ind
].name
, tab
[ind
].nmsz
) == 0) {
131 *start_p
= cur_p
+ tab
[ind
].nmsz
;
134 } while (ind
!= lastind
);
140 * getusrdef - returns default values of values in userdefs.h.
144 getusrdef(char *usertype
)
150 dup_to_nl(char *from
)
152 char *res
= strdup(from
);
154 char *p
= strchr(res
, '\n');
162 dispusrdef(FILE *fptr
, unsigned flags
, char *usertype
)
164 struct userdefs
*deflts
= getusrdef(usertype
);
167 /* Print out values */
169 if (flags
& D_GROUP
) {
170 outcount
+= fprintf(fptr
, "group=%s,%ld ",
171 deflts
->defgname
, deflts
->defgroup
);
175 if (flags
& D_PROJ
) {
176 outcount
+= fprintf(fptr
, "project=%s,%ld ",
177 deflts
->defprojname
, deflts
->defproj
);
181 if (flags
& D_BASEDIR
) {
182 outcount
+= fprintf(fptr
, "basedir=%s ", deflts
->defparent
);
187 outcount
+= fprintf(fptr
, "rid=%ld ", deflts
->defrid
);
191 if (flags
& D_SKEL
) {
192 outcount
+= fprintf(fptr
, "skel=%s ", deflts
->defskel
);
196 if (flags
& D_SHELL
) {
197 outcount
+= fprintf(fptr
, "shell=%s ", deflts
->defshell
);
201 if (flags
& D_INACT
) {
202 outcount
+= fprintf(fptr
, "inactive=%d ", deflts
->definact
);
206 if (flags
& D_EXPIRE
) {
207 outcount
+= fprintf(fptr
, "expire=%s ", deflts
->defexpire
);
211 if (flags
& D_AUTH
) {
212 outcount
+= fprintf(fptr
, "auths=%s ", deflts
->defauth
);
216 if (flags
& D_PROF
) {
217 outcount
+= fprintf(fptr
, "profiles=%s ", deflts
->defprof
);
221 if ((flags
& D_ROLE
) &&
222 (!is_role(usertype
))) {
223 outcount
+= fprintf(fptr
, "roles=%s ", deflts
->defrole
);
227 if (flags
& D_LPRIV
) {
228 outcount
+= fprintf(fptr
, "limitpriv=%s ",
233 if (flags
& D_DPRIV
) {
234 outcount
+= fprintf(fptr
, "defaultpriv=%s ",
235 deflts
->defdfltpriv
);
239 if (flags
& D_LOCK
) {
240 outcount
+= fprintf(fptr
, "lock_after_retries=%s ",
241 deflts
->deflock_after_retries
);
245 (void) fprintf(fptr
, "\n");
248 /* Import default keys for ordinary useradd */
250 import_def(struct userdefs
*ud
)
254 for (i
= 0; i
< NDEF
; i
++) {
255 if (tab
[i
].uakey
!= NULL
&& tab
[i
].type
== STR
) {
256 char *val
= FIELD(ud
, &tab
[i
], char *);
257 if (val
== getsetdefval(tab
[i
].uakey
, val
))