4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/types.h>
38 #include "passwdutil.h"
40 #define PWADMIN "/etc/default/passwd"
46 extern repops_t files_repops
, nis_repops
, ldap_repops
, nss_repops
;
48 repops_t
*rops
[REP_LAST
+1] = {
61 free_pwd(struct passwd
*pw
)
72 free_spwd(struct spwd
*spw
)
80 dup_pw(struct passwd
**d
, struct passwd
*s
)
84 return (PWU_NOT_FOUND
);
86 if ((*d
= calloc(1, sizeof (**d
))) == NULL
)
90 if (((*d
)->pw_name
= strdup(s
->pw_name
)) == NULL
)
94 if (((*d
)->pw_passwd
= strdup(s
->pw_passwd
)) == NULL
)
97 (*d
)->pw_uid
= s
->pw_uid
;
98 (*d
)->pw_gid
= s
->pw_gid
;
101 if (((*d
)->pw_gecos
= strdup(s
->pw_gecos
)) == NULL
)
105 if (((*d
)->pw_dir
= strdup(s
->pw_dir
)) == NULL
)
109 if (((*d
)->pw_shell
= strdup(s
->pw_shell
)) == NULL
)
113 return (PWU_SUCCESS
);
122 dup_spw(struct spwd
**d
, struct spwd
*s
)
126 return (PWU_NOT_FOUND
);
128 if ((*d
= calloc(1, sizeof (**d
))) == NULL
)
134 if (((*d
)->sp_namp
= strdup(s
->sp_namp
)) == NULL
)
137 if (((*d
)->sp_pwdp
= strdup(s
->sp_pwdp
)) == NULL
)
139 return (PWU_SUCCESS
);
147 * read a value from the defaults file, and return it if it is
148 * a positive integer. If the value is not defined, or negative,
149 * return the supplied default value
152 def_getuint(char *name
, int defvalue
, void *defp
)
155 int val
= -1; /* -1 is a guard to catch undefined values */
157 if ((p
= defread_r(name
, defp
)) != NULL
)
160 return (val
>= 0 ? val
: defvalue
);
164 turn_on_default_aging(struct spwd
*spw
)
171 if ((defp
= defopen_r(PWADMIN
)) == NULL
) {
174 warnweeks
= WARNWEEKS
;
176 minweeks
= def_getuint("MINWEEKS=", MINWEEKS
, defp
);
177 maxweeks
= def_getuint("MAXWEEKS=", MAXWEEKS
, defp
);
178 warnweeks
= def_getuint("WARNWEEKS=", WARNWEEKS
, defp
);
183 * The values specified in /etc/default/passwd are interpreted
184 * in a specific way. Special cases are
185 * MINWEEKS==0 (results in sp_min = -1)
186 * MAXWEEKS==0 (results in sp_max = default)
188 spw
->sp_min
= 7 * minweeks
;
189 if (spw
->sp_min
<= 0)
192 spw
->sp_max
= 7 * maxweeks
;
193 if (spw
->sp_max
== 0)
194 spw
->sp_max
= 7 * MAXWEEKS
;
198 spw
->sp_warn
= 7 * warnweeks
;
199 if (spw
->sp_warn
<= 0)
204 * open and read a value from the defaults file,
205 * return value found or default value if not found.
208 def_getint(char *name
, int defvalue
)
213 if ((defp
= defopen_r(PWADMIN
)) == NULL
) {
216 val
= def_getuint(name
, defvalue
, defp
);