xref: /titanic_53/usr/src/lib/passwdutil/passwdutil.h (revision dd1104fbe0f0f41434502f335b9f0b34999f771c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
547d0cd5cSgww  * Common Development and Distribution License (the "License").
647d0cd5cSgww  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*dd1104fbSMichen Chang  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_PASSWDUTIL_H
277c478bd9Sstevel@tonic-gate #define	_PASSWDUTIL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef __cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <shadow.h>
357c478bd9Sstevel@tonic-gate #include <crypt.h>		/* CRYPT_MAXCIPHERTEXTLEN max crypt length */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /* DAY_NOW_32 is a 32-bit value, independent of the architecture */
387c478bd9Sstevel@tonic-gate #ifdef _LP64
397c478bd9Sstevel@tonic-gate #include <sys/types32.h>
407c478bd9Sstevel@tonic-gate #define	DAY_NOW_32	((time32_t)DAY_NOW)
417c478bd9Sstevel@tonic-gate #else
427c478bd9Sstevel@tonic-gate #define	DAY_NOW_32	((time_t)DAY_NOW)
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef enum {
467c478bd9Sstevel@tonic-gate 	/* from plain passwd */
477c478bd9Sstevel@tonic-gate 	ATTR_NAME	= 0x1,
487c478bd9Sstevel@tonic-gate 	ATTR_PASSWD	= 0x2,
497c478bd9Sstevel@tonic-gate 	ATTR_UID	= 0x4,
507c478bd9Sstevel@tonic-gate 	ATTR_GID	= 0x8,
517c478bd9Sstevel@tonic-gate 	ATTR_AGE	= 0x10,
527c478bd9Sstevel@tonic-gate 	ATTR_COMMENT	= 0x20,
537c478bd9Sstevel@tonic-gate 	ATTR_GECOS	= 0x40,
547c478bd9Sstevel@tonic-gate 	ATTR_HOMEDIR	= 0x80,
557c478bd9Sstevel@tonic-gate 	ATTR_SHELL	= 0x100,
567c478bd9Sstevel@tonic-gate 	/* from shadow */
577c478bd9Sstevel@tonic-gate 	ATTR_LSTCHG	= 0x200,
587c478bd9Sstevel@tonic-gate 	ATTR_MIN	= 0x400,
597c478bd9Sstevel@tonic-gate 	ATTR_MAX	= 0x800,
607c478bd9Sstevel@tonic-gate 	ATTR_WARN	= 0x1000,
617c478bd9Sstevel@tonic-gate 	ATTR_INACT	= 0x2000,
627c478bd9Sstevel@tonic-gate 	ATTR_EXPIRE	= 0x4000,
637c478bd9Sstevel@tonic-gate 	ATTR_FLAG	= 0x8000,
647c478bd9Sstevel@tonic-gate 	/* special operations */
657c478bd9Sstevel@tonic-gate 	ATTR_LOCK_ACCOUNT	= 0x10000,
667c478bd9Sstevel@tonic-gate 	ATTR_EXPIRE_PASSWORD	= 0x20000,
677c478bd9Sstevel@tonic-gate 	ATTR_NOLOGIN_ACCOUNT	= 0x40000,
687c478bd9Sstevel@tonic-gate 	ATTR_UNLOCK_ACCOUNT	= 0x80000,
697c478bd9Sstevel@tonic-gate 	/* Query operations */
707c478bd9Sstevel@tonic-gate 	/* to obtain repository name that contained the info */
717c478bd9Sstevel@tonic-gate 	ATTR_REP_NAME		= 0x100000,
727c478bd9Sstevel@tonic-gate 	/* special attribute */
737c478bd9Sstevel@tonic-gate 	/* to set password following server policy */
747c478bd9Sstevel@tonic-gate 	ATTR_PASSWD_SERVER_POLICY	= 0x200000,
757c478bd9Sstevel@tonic-gate 	/* get history entry from supporting repositories */
767c478bd9Sstevel@tonic-gate 	ATTR_HISTORY	= 0x400000,
777c478bd9Sstevel@tonic-gate 	/* Failed login bookkeeping */
787c478bd9Sstevel@tonic-gate 	ATTR_FAILED_LOGINS	= 0x800000,	/* get # of failed logins */
797c478bd9Sstevel@tonic-gate 	ATTR_INCR_FAILED_LOGINS = 0x1000000,	/* increment + lock if needed */
807c478bd9Sstevel@tonic-gate 	ATTR_RST_FAILED_LOGINS	= 0x2000000	/* reset failed logins */
817c478bd9Sstevel@tonic-gate } attrtype;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate typedef struct attrlist_s {
847c478bd9Sstevel@tonic-gate 	attrtype type;
857c478bd9Sstevel@tonic-gate 	union {
867c478bd9Sstevel@tonic-gate 		char *val_s;
877c478bd9Sstevel@tonic-gate 		int val_i;
887c478bd9Sstevel@tonic-gate 	} data;
897c478bd9Sstevel@tonic-gate 	struct attrlist_s *next;
907c478bd9Sstevel@tonic-gate } attrlist;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate typedef struct {
937c478bd9Sstevel@tonic-gate 	char   *type;
947c478bd9Sstevel@tonic-gate 	void   *scope;
957c478bd9Sstevel@tonic-gate 	size_t  scope_len;
967c478bd9Sstevel@tonic-gate } pwu_repository_t;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	PWU_DEFAULT_REP (pwu_repository_t *)NULL
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	REP_NOREP	0		/* Can't find suitable repository */
1017c478bd9Sstevel@tonic-gate #define	REP_FILES	0x0001		/* /etc/passwd, /etc/shadow */
1027c478bd9Sstevel@tonic-gate #define	REP_NIS		0x0002
1037c478bd9Sstevel@tonic-gate #define	REP_NISPLUS	0x0004
1047c478bd9Sstevel@tonic-gate #define	REP_LDAP	0x0008
1057c478bd9Sstevel@tonic-gate #define	REP_NSS		0x0010
1067c478bd9Sstevel@tonic-gate #define	REP_LAST	REP_NSS
1077c478bd9Sstevel@tonic-gate #define	REP_ERANGE	0x8000		/* Unknown repository specified */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	REP_COMPAT_NIS		0x1000
1107c478bd9Sstevel@tonic-gate #define	REP_COMPAT_NISPLUS	0x2000
1117c478bd9Sstevel@tonic-gate #define	REP_COMPAT_LDAP		0x4000
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /* For the time being, these are also defined in pam_*.h */
1147c478bd9Sstevel@tonic-gate #undef	IS_NISPLUS
1157c478bd9Sstevel@tonic-gate #undef	IS_FILES
1167c478bd9Sstevel@tonic-gate #undef	IS_NIS
1177c478bd9Sstevel@tonic-gate #undef	IS_LDAP
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	IS_FILES(r)	(r.type != NULL && strcmp(r.type, "files") == 0)
1207c478bd9Sstevel@tonic-gate #define	IS_NIS(r)	(r.type != NULL && strcmp(r.type, "nis") == 0)
1217c478bd9Sstevel@tonic-gate #define	IS_NISPLUS(r)	(r.type != NULL && strcmp(r.type, "nisplus") == 0)
1227c478bd9Sstevel@tonic-gate #define	IS_LDAP(r)	(r.type != NULL && strcmp(r.type, "ldap") == 0)
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #define	MINWEEKS	-1
1257c478bd9Sstevel@tonic-gate #define	MAXWEEKS	-1
1267c478bd9Sstevel@tonic-gate #define	WARNWEEKS	-1
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #define	NISPLUS_LOOKUP	0
1297c478bd9Sstevel@tonic-gate #define	NISPLUS_UPDATE	1
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate typedef struct repops {
1327c478bd9Sstevel@tonic-gate 	int (*checkhistory)(char *, char *, pwu_repository_t *);
1337c478bd9Sstevel@tonic-gate 	int (*getattr)(char *, attrlist *, pwu_repository_t *);
1347c478bd9Sstevel@tonic-gate 	int (*getpwnam)(char *, attrlist *, pwu_repository_t *, void **);
1357c478bd9Sstevel@tonic-gate 	int (*update)(attrlist *, pwu_repository_t *, void *);
1367c478bd9Sstevel@tonic-gate 	int (*putpwnam)(char *, char *, char *, pwu_repository_t *, void *);
1377c478bd9Sstevel@tonic-gate 	int (*user_to_authenticate)(char *, pwu_repository_t *, char **, int *);
1387c478bd9Sstevel@tonic-gate 	int (*lock)(void);
1397c478bd9Sstevel@tonic-gate 	int (*unlock)(void);
1407c478bd9Sstevel@tonic-gate } repops_t;
1417c478bd9Sstevel@tonic-gate 
14203c65128Swy83408 extern repops_t files_repops, nis_repops,
14303c65128Swy83408 	nisplus_repops, ldap_repops, nss_repops;
14403c65128Swy83408 
14503c65128Swy83408 extern repops_t *rops[];
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * utils.c
1497c478bd9Sstevel@tonic-gate  */
1507c478bd9Sstevel@tonic-gate void turn_on_default_aging(struct spwd *);
1517c478bd9Sstevel@tonic-gate int def_getint(char *name, int defvalue);
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * debug.c
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate void debug_init(void);
1577c478bd9Sstevel@tonic-gate void debug(char *, ...);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * switch_utils.c
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate #define	PWU_READ	0 /* Read access to the repository */
1637c478bd9Sstevel@tonic-gate #define	PWU_WRITE	1 /* Write (update) access to the repository */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate int get_ns(pwu_repository_t *, int);
1667c478bd9Sstevel@tonic-gate struct passwd *getpwnam_from(const char *, pwu_repository_t *, int);
1677c478bd9Sstevel@tonic-gate struct passwd *getpwuid_from(uid_t, pwu_repository_t *, int);
1687c478bd9Sstevel@tonic-gate struct spwd *getspnam_from(const char *, pwu_repository_t *, int);
169*dd1104fbSMichen Chang int name_to_int(char *);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * __set_authtok_attr.c
1737c478bd9Sstevel@tonic-gate  */
1747c478bd9Sstevel@tonic-gate int __set_authtoken_attr(char *, char *, char *, pwu_repository_t *,
1757c478bd9Sstevel@tonic-gate     attrlist *, int *);
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * __get_authtokenn_attr.c
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate int __get_authtoken_attr(char *, pwu_repository_t *, attrlist *);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * __user_to_authenticate.c
1837c478bd9Sstevel@tonic-gate  */
1847c478bd9Sstevel@tonic-gate int __user_to_authenticate(char *, pwu_repository_t *, char **, int *);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * __verify_rpc_passwd.c
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate int __verify_rpc_passwd(char *, char *, pwu_repository_t *);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  *	Password history definitions
1937c478bd9Sstevel@tonic-gate  */
1947c478bd9Sstevel@tonic-gate #define	DEFHISTORY	0	/* default history depth */
1957c478bd9Sstevel@tonic-gate #define	MAXHISTORY	26	/* max depth of history 1 yr every 2 weeks */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * __check_history.c
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate int __check_history(char *, char *, pwu_repository_t *);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate int __incr_failed_count(char *, char *, int);
2037c478bd9Sstevel@tonic-gate int __rst_failed_count(char *, char *);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
20647d0cd5cSgww  * Error / return codes
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #define	PWU_SUCCESS		 0	/* update succeeded */
2097c478bd9Sstevel@tonic-gate #define	PWU_BUSY		-1	/* Password database busy */
2107c478bd9Sstevel@tonic-gate #define	PWU_STAT_FAILED		-2	/* stat of password file failed */
2117c478bd9Sstevel@tonic-gate #define	PWU_OPEN_FAILED		-3	/* password file open failed */
2127c478bd9Sstevel@tonic-gate #define	PWU_WRITE_FAILED	-4	/* can't write to password file */
2137c478bd9Sstevel@tonic-gate #define	PWU_CLOSE_FAILED	-5	/* close returned error */
2147c478bd9Sstevel@tonic-gate #define	PWU_NOT_FOUND		-6	/* user not found in database */
2157c478bd9Sstevel@tonic-gate #define	PWU_UPDATE_FAILED	-7	/* couldn't update password file */
2167c478bd9Sstevel@tonic-gate #define	PWU_NOMEM		-8	/* Not enough memory */
2177c478bd9Sstevel@tonic-gate #define	PWU_SERVER_ERROR	-9	/* NIS server errors */
2187c478bd9Sstevel@tonic-gate #define	PWU_SYSTEM_ERROR	-10	/* NIS local configuration problem */
2197c478bd9Sstevel@tonic-gate #define	PWU_DENIED		-11	/* NIS update denied */
2207c478bd9Sstevel@tonic-gate #define	PWU_NO_CHANGE		-12	/* Data hasn't changed */
2217c478bd9Sstevel@tonic-gate #define	PWU_REPOSITORY_ERROR	-13	/* Unknown repository specified */
2227c478bd9Sstevel@tonic-gate #define	PWU_AGING_DISABLED	-14	/* Modifying min/warn while max==-1 */
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /* NISPLUS specific errors */
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #define	PWU_RECOVERY_ERR	-15	/* can't recover old auth token */
2277c478bd9Sstevel@tonic-gate #define	PWU_CRED_UPDATE_ERR	-16	/* failed to update credentials */
2287c478bd9Sstevel@tonic-gate #define	PWU_ATTR_UPDATE_ERR	-17	/* failed to update attributes */
2297c478bd9Sstevel@tonic-gate #define	PWU_CRED_ERROR		-18	/* failed to obtain user credentials */
2307c478bd9Sstevel@tonic-gate #define	PWU_PARTIAL_SUCCESS	-19	/* passwd is updated, creds are not */
2317c478bd9Sstevel@tonic-gate #define	PWU_BAD_CREDPASS	-20	/* password doesn't decrypt creds */
2327c478bd9Sstevel@tonic-gate #define	PWU_NO_PRIV_CRED_UPDATE	-21	/* priv. user can't update creds */
2337c478bd9Sstevel@tonic-gate #define	PWU_UPDATED_SOME_CREDS	-22	/* some, not all, creds were updated */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /* More errors, not NISPLUS specific */
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #define	PWU_PWD_TOO_SHORT	-23	/* new passwd too short */
2387c478bd9Sstevel@tonic-gate #define	PWU_PWD_INVALID		-24	/* new passwd has invalid syntax */
2397c478bd9Sstevel@tonic-gate #define	PWU_PWD_IN_HISTORY	-25	/* new passwd in history list */
2407c478bd9Sstevel@tonic-gate #define	PWU_CHANGE_NOT_ALLOWED	-26	/* change not allowed */
2417c478bd9Sstevel@tonic-gate #define	PWU_WITHIN_MIN_AGE	-27	/* change not allowed, within min age */
24247d0cd5cSgww #define	PWU_ACCOUNT_LOCKED	-28	/* account successfully locked */
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate #endif
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate #endif	/* _PASSWDUTIL_H */
249