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