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