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