xref: /titanic_50/usr/src/lib/passwdutil/passwdutil.h (revision 2bd70d4be73561631df9cb3d9eb4c65fa94fa665)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_PASSWDUTIL_H
27 #define	_PASSWDUTIL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <shadow.h>
37 #include <crypt.h>		/* CRYPT_MAXCIPHERTEXTLEN max crypt length */
38 
39 /* DAY_NOW_32 is a 32-bit value, independent of the architecture */
40 #ifdef _LP64
41 #include <sys/types32.h>
42 #define	DAY_NOW_32	((time32_t)DAY_NOW)
43 #else
44 #define	DAY_NOW_32	((time_t)DAY_NOW)
45 #endif
46 
47 typedef enum {
48 	/* from plain passwd */
49 	ATTR_NAME	= 0x1,
50 	ATTR_PASSWD	= 0x2,
51 	ATTR_UID	= 0x4,
52 	ATTR_GID	= 0x8,
53 	ATTR_AGE	= 0x10,
54 	ATTR_COMMENT	= 0x20,
55 	ATTR_GECOS	= 0x40,
56 	ATTR_HOMEDIR	= 0x80,
57 	ATTR_SHELL	= 0x100,
58 	/* from shadow */
59 	ATTR_LSTCHG	= 0x200,
60 	ATTR_MIN	= 0x400,
61 	ATTR_MAX	= 0x800,
62 	ATTR_WARN	= 0x1000,
63 	ATTR_INACT	= 0x2000,
64 	ATTR_EXPIRE	= 0x4000,
65 	ATTR_FLAG	= 0x8000,
66 	/* special operations */
67 	ATTR_LOCK_ACCOUNT	= 0x10000,
68 	ATTR_EXPIRE_PASSWORD	= 0x20000,
69 	ATTR_NOLOGIN_ACCOUNT	= 0x40000,
70 	ATTR_UNLOCK_ACCOUNT	= 0x80000,
71 	/* Query operations */
72 	/* to obtain repository name that contained the info */
73 	ATTR_REP_NAME		= 0x100000,
74 	/* special attribute */
75 	/* to set password following server policy */
76 	ATTR_PASSWD_SERVER_POLICY	= 0x200000,
77 	/* get history entry from supporting repositories */
78 	ATTR_HISTORY	= 0x400000,
79 	/* Failed login bookkeeping */
80 	ATTR_FAILED_LOGINS	= 0x800000,	/* get # of failed logins */
81 	ATTR_INCR_FAILED_LOGINS = 0x1000000,	/* increment + lock if needed */
82 	ATTR_RST_FAILED_LOGINS	= 0x2000000	/* reset failed logins */
83 } attrtype;
84 
85 typedef struct attrlist_s {
86 	attrtype type;
87 	union {
88 		char *val_s;
89 		int val_i;
90 	} data;
91 	struct attrlist_s *next;
92 } attrlist;
93 
94 typedef struct {
95 	char   *type;
96 	void   *scope;
97 	size_t  scope_len;
98 } pwu_repository_t;
99 
100 #define	PWU_DEFAULT_REP (pwu_repository_t *)NULL
101 
102 #define	REP_NOREP	0		/* Can't find suitable repository */
103 #define	REP_FILES	0x0001		/* /etc/passwd, /etc/shadow */
104 #define	REP_NIS		0x0002
105 #define	REP_NISPLUS	0x0004
106 #define	REP_LDAP	0x0008
107 #define	REP_NSS		0x0010
108 #define	REP_LAST	REP_NSS
109 #define	REP_ERANGE	0x8000		/* Unknown repository specified */
110 
111 #define	REP_COMPAT_NIS		0x1000
112 #define	REP_COMPAT_NISPLUS	0x2000
113 #define	REP_COMPAT_LDAP		0x4000
114 
115 /* For the time being, these are also defined in pam_*.h */
116 #undef	IS_NISPLUS
117 #undef	IS_FILES
118 #undef	IS_NIS
119 #undef	IS_LDAP
120 
121 #define	IS_FILES(r)	(r.type != NULL && strcmp(r.type, "files") == 0)
122 #define	IS_NIS(r)	(r.type != NULL && strcmp(r.type, "nis") == 0)
123 #define	IS_NISPLUS(r)	(r.type != NULL && strcmp(r.type, "nisplus") == 0)
124 #define	IS_LDAP(r)	(r.type != NULL && strcmp(r.type, "ldap") == 0)
125 
126 #define	MINWEEKS	-1
127 #define	MAXWEEKS	-1
128 #define	WARNWEEKS	-1
129 
130 #define	NISPLUS_LOOKUP	0
131 #define	NISPLUS_UPDATE	1
132 
133 typedef struct repops {
134 	int (*checkhistory)(char *, char *, pwu_repository_t *);
135 	int (*getattr)(char *, attrlist *, pwu_repository_t *);
136 	int (*getpwnam)(char *, attrlist *, pwu_repository_t *, void **);
137 	int (*update)(attrlist *, pwu_repository_t *, void *);
138 	int (*putpwnam)(char *, char *, char *, pwu_repository_t *, void *);
139 	int (*user_to_authenticate)(char *, pwu_repository_t *, char **, int *);
140 	int (*lock)(void);
141 	int (*unlock)(void);
142 } repops_t;
143 
144 extern repops_t files_repops, nis_repops,
145 	nisplus_repops, ldap_repops, nss_repops;
146 
147 extern repops_t *rops[];
148 
149 /*
150  * utils.c
151  */
152 void turn_on_default_aging(struct spwd *);
153 int def_getint(char *name, int defvalue);
154 
155 /*
156  * debug.c
157  */
158 void debug_init(void);
159 void debug(char *, ...);
160 
161 /*
162  * bsd-strsep.c
163  */
164 char *strsep(char **, const char *);
165 
166 /*
167  * switch_utils.c
168  */
169 #define	PWU_READ	0 /* Read access to the repository */
170 #define	PWU_WRITE	1 /* Write (update) access to the repository */
171 
172 int get_ns(pwu_repository_t *, int);
173 struct passwd *getpwnam_from(const char *, pwu_repository_t *, int);
174 struct passwd *getpwuid_from(uid_t, pwu_repository_t *, int);
175 struct spwd *getspnam_from(const char *, pwu_repository_t *, int);
176 
177 /*
178  * __set_authtok_attr.c
179  */
180 int __set_authtoken_attr(char *, char *, char *, pwu_repository_t *,
181     attrlist *, int *);
182 /*
183  * __get_authtokenn_attr.c
184  */
185 int __get_authtoken_attr(char *, pwu_repository_t *, attrlist *);
186 
187 /*
188  * __user_to_authenticate.c
189  */
190 int __user_to_authenticate(char *, pwu_repository_t *, char **, int *);
191 
192 /*
193  * __verify_rpc_passwd.c
194  */
195 int __verify_rpc_passwd(char *, char *, pwu_repository_t *);
196 
197 /*
198  *	Password history definitions
199  */
200 #define	DEFHISTORY	0	/* default history depth */
201 #define	MAXHISTORY	26	/* max depth of history 1 yr every 2 weeks */
202 
203 /*
204  * __check_history.c
205  */
206 int __check_history(char *, char *, pwu_repository_t *);
207 
208 int __incr_failed_count(char *, char *, int);
209 int __rst_failed_count(char *, char *);
210 
211 /*
212  * Error / return codes
213  */
214 #define	PWU_SUCCESS		 0	/* update succeeded */
215 #define	PWU_BUSY		-1	/* Password database busy */
216 #define	PWU_STAT_FAILED		-2	/* stat of password file failed */
217 #define	PWU_OPEN_FAILED		-3	/* password file open failed */
218 #define	PWU_WRITE_FAILED	-4	/* can't write to password file */
219 #define	PWU_CLOSE_FAILED	-5	/* close returned error */
220 #define	PWU_NOT_FOUND		-6	/* user not found in database */
221 #define	PWU_UPDATE_FAILED	-7	/* couldn't update password file */
222 #define	PWU_NOMEM		-8	/* Not enough memory */
223 #define	PWU_SERVER_ERROR	-9	/* NIS server errors */
224 #define	PWU_SYSTEM_ERROR	-10	/* NIS local configuration problem */
225 #define	PWU_DENIED		-11	/* NIS update denied */
226 #define	PWU_NO_CHANGE		-12	/* Data hasn't changed */
227 #define	PWU_REPOSITORY_ERROR	-13	/* Unknown repository specified */
228 #define	PWU_AGING_DISABLED	-14	/* Modifying min/warn while max==-1 */
229 
230 /* NISPLUS specific errors */
231 
232 #define	PWU_RECOVERY_ERR	-15	/* can't recover old auth token */
233 #define	PWU_CRED_UPDATE_ERR	-16	/* failed to update credentials */
234 #define	PWU_ATTR_UPDATE_ERR	-17	/* failed to update attributes */
235 #define	PWU_CRED_ERROR		-18	/* failed to obtain user credentials */
236 #define	PWU_PARTIAL_SUCCESS	-19	/* passwd is updated, creds are not */
237 #define	PWU_BAD_CREDPASS	-20	/* password doesn't decrypt creds */
238 #define	PWU_NO_PRIV_CRED_UPDATE	-21	/* priv. user can't update creds */
239 #define	PWU_UPDATED_SOME_CREDS	-22	/* some, not all, creds were updated */
240 
241 /* More errors, not NISPLUS specific */
242 
243 #define	PWU_PWD_TOO_SHORT	-23	/* new passwd too short */
244 #define	PWU_PWD_INVALID		-24	/* new passwd has invalid syntax */
245 #define	PWU_PWD_IN_HISTORY	-25	/* new passwd in history list */
246 #define	PWU_CHANGE_NOT_ALLOWED	-26	/* change not allowed */
247 #define	PWU_WITHIN_MIN_AGE	-27	/* change not allowed, within min age */
248 #define	PWU_ACCOUNT_LOCKED	-28	/* account successfully locked */
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #endif	/* _PASSWDUTIL_H */
255