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 /* 22dd1104fbSMichen 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 103*36e852a1SRaja Andra #define REP_LDAP 0x0004 104*36e852a1SRaja Andra #define REP_NSS 0x0008 1057c478bd9Sstevel@tonic-gate #define REP_LAST REP_NSS 1067c478bd9Sstevel@tonic-gate #define REP_ERANGE 0x8000 /* Unknown repository specified */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define REP_COMPAT_NIS 0x1000 109*36e852a1SRaja Andra #define REP_COMPAT_LDAP 0x2000 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* For the time being, these are also defined in pam_*.h */ 1127c478bd9Sstevel@tonic-gate #undef IS_FILES 1137c478bd9Sstevel@tonic-gate #undef IS_NIS 1147c478bd9Sstevel@tonic-gate #undef IS_LDAP 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #define IS_FILES(r) (r.type != NULL && strcmp(r.type, "files") == 0) 1177c478bd9Sstevel@tonic-gate #define IS_NIS(r) (r.type != NULL && strcmp(r.type, "nis") == 0) 1187c478bd9Sstevel@tonic-gate #define IS_LDAP(r) (r.type != NULL && strcmp(r.type, "ldap") == 0) 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #define MINWEEKS -1 1217c478bd9Sstevel@tonic-gate #define MAXWEEKS -1 1227c478bd9Sstevel@tonic-gate #define WARNWEEKS -1 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate typedef struct repops { 1257c478bd9Sstevel@tonic-gate int (*checkhistory)(char *, char *, pwu_repository_t *); 1267c478bd9Sstevel@tonic-gate int (*getattr)(char *, attrlist *, pwu_repository_t *); 1277c478bd9Sstevel@tonic-gate int (*getpwnam)(char *, attrlist *, pwu_repository_t *, void **); 1287c478bd9Sstevel@tonic-gate int (*update)(attrlist *, pwu_repository_t *, void *); 129*36e852a1SRaja Andra int (*putpwnam)(char *, char *, pwu_repository_t *, void *); 1307c478bd9Sstevel@tonic-gate int (*user_to_authenticate)(char *, pwu_repository_t *, char **, int *); 1317c478bd9Sstevel@tonic-gate int (*lock)(void); 1327c478bd9Sstevel@tonic-gate int (*unlock)(void); 1337c478bd9Sstevel@tonic-gate } repops_t; 1347c478bd9Sstevel@tonic-gate 135*36e852a1SRaja Andra extern repops_t files_repops, nis_repops, ldap_repops, nss_repops; 13603c65128Swy83408 13703c65128Swy83408 extern repops_t *rops[]; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * utils.c 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate void turn_on_default_aging(struct spwd *); 1437c478bd9Sstevel@tonic-gate int def_getint(char *name, int defvalue); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * debug.c 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate void debug_init(void); 1497c478bd9Sstevel@tonic-gate void debug(char *, ...); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * switch_utils.c 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate #define PWU_READ 0 /* Read access to the repository */ 1557c478bd9Sstevel@tonic-gate #define PWU_WRITE 1 /* Write (update) access to the repository */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate int get_ns(pwu_repository_t *, int); 1587c478bd9Sstevel@tonic-gate struct passwd *getpwnam_from(const char *, pwu_repository_t *, int); 1597c478bd9Sstevel@tonic-gate struct passwd *getpwuid_from(uid_t, pwu_repository_t *, int); 1607c478bd9Sstevel@tonic-gate struct spwd *getspnam_from(const char *, pwu_repository_t *, int); 161dd1104fbSMichen Chang int name_to_int(char *); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * __set_authtok_attr.c 1657c478bd9Sstevel@tonic-gate */ 166*36e852a1SRaja Andra int __set_authtoken_attr(char *, char *, pwu_repository_t *, attrlist *, int *); 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * __get_authtokenn_attr.c 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate int __get_authtoken_attr(char *, pwu_repository_t *, attrlist *); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* 1737c478bd9Sstevel@tonic-gate * __user_to_authenticate.c 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate int __user_to_authenticate(char *, pwu_repository_t *, char **, int *); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * Password history definitions 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate #define DEFHISTORY 0 /* default history depth */ 1817c478bd9Sstevel@tonic-gate #define MAXHISTORY 26 /* max depth of history 1 yr every 2 weeks */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* 1847c478bd9Sstevel@tonic-gate * __check_history.c 1857c478bd9Sstevel@tonic-gate */ 1867c478bd9Sstevel@tonic-gate int __check_history(char *, char *, pwu_repository_t *); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate int __incr_failed_count(char *, char *, int); 1897c478bd9Sstevel@tonic-gate int __rst_failed_count(char *, char *); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 19247d0cd5cSgww * Error / return codes 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate #define PWU_SUCCESS 0 /* update succeeded */ 1957c478bd9Sstevel@tonic-gate #define PWU_BUSY -1 /* Password database busy */ 1967c478bd9Sstevel@tonic-gate #define PWU_STAT_FAILED -2 /* stat of password file failed */ 1977c478bd9Sstevel@tonic-gate #define PWU_OPEN_FAILED -3 /* password file open failed */ 1987c478bd9Sstevel@tonic-gate #define PWU_WRITE_FAILED -4 /* can't write to password file */ 1997c478bd9Sstevel@tonic-gate #define PWU_CLOSE_FAILED -5 /* close returned error */ 2007c478bd9Sstevel@tonic-gate #define PWU_NOT_FOUND -6 /* user not found in database */ 2017c478bd9Sstevel@tonic-gate #define PWU_UPDATE_FAILED -7 /* couldn't update password file */ 2027c478bd9Sstevel@tonic-gate #define PWU_NOMEM -8 /* Not enough memory */ 2037c478bd9Sstevel@tonic-gate #define PWU_SERVER_ERROR -9 /* NIS server errors */ 2047c478bd9Sstevel@tonic-gate #define PWU_SYSTEM_ERROR -10 /* NIS local configuration problem */ 2057c478bd9Sstevel@tonic-gate #define PWU_DENIED -11 /* NIS update denied */ 2067c478bd9Sstevel@tonic-gate #define PWU_NO_CHANGE -12 /* Data hasn't changed */ 2077c478bd9Sstevel@tonic-gate #define PWU_REPOSITORY_ERROR -13 /* Unknown repository specified */ 2087c478bd9Sstevel@tonic-gate #define PWU_AGING_DISABLED -14 /* Modifying min/warn while max==-1 */ 2097c478bd9Sstevel@tonic-gate 210*36e852a1SRaja Andra /* More errors */ 2117c478bd9Sstevel@tonic-gate 212*36e852a1SRaja Andra #define PWU_PWD_TOO_SHORT -15 /* new passwd too short */ 213*36e852a1SRaja Andra #define PWU_PWD_INVALID -16 /* new passwd has invalid syntax */ 214*36e852a1SRaja Andra #define PWU_PWD_IN_HISTORY -17 /* new passwd in history list */ 215*36e852a1SRaja Andra #define PWU_CHANGE_NOT_ALLOWED -18 /* change not allowed */ 216*36e852a1SRaja Andra #define PWU_WITHIN_MIN_AGE -19 /* change not allowed, within min age */ 217*36e852a1SRaja Andra #define PWU_ACCOUNT_LOCKED -20 /* account successfully locked */ 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate #endif 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate #endif /* _PASSWDUTIL_H */ 224