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