xref: /onnv-gate/usr/src/lib/libpam/pam_impl.h (revision 11262:b7ebfbf2359e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52295Sgww  * Common Development and Distribution License (the "License").
62295Sgww  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10702SDarren.Moffat@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_PAM_IMPL_H
270Sstevel@tonic-gate #define	_PAM_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef __cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <limits.h>
340Sstevel@tonic-gate #include <shadow.h>
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #define	PAMTXD		"SUNW_OST_SYSOSPAM"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #define	PAM_CONFIG	"/etc/pam.conf"
400Sstevel@tonic-gate #define	PAM_ISA		"/$ISA/"
410Sstevel@tonic-gate #define	PAM_LIB_DIR	"/usr/lib/security/"
420Sstevel@tonic-gate #ifdef	_LP64
430Sstevel@tonic-gate #define	PAM_ISA_DIR	"/64/"
440Sstevel@tonic-gate #else	/* !_LP64 */
450Sstevel@tonic-gate #define	PAM_ISA_DIR	"/"
460Sstevel@tonic-gate #endif	/* _LP64 */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /* Service Module Types */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * If new service types are added, they should be named in
520Sstevel@tonic-gate  * pam_framework.c::pam_snames[] as well.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	PAM_ACCOUNT_NAME	"account"
560Sstevel@tonic-gate #define	PAM_AUTH_NAME		"auth"
570Sstevel@tonic-gate #define	PAM_PASSWORD_NAME	"password"
580Sstevel@tonic-gate #define	PAM_SESSION_NAME	"session"
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #define	PAM_ACCOUNT_MODULE	0
610Sstevel@tonic-gate #define	PAM_AUTH_MODULE		1
620Sstevel@tonic-gate #define	PAM_PASSWORD_MODULE	2
630Sstevel@tonic-gate #define	PAM_SESSION_MODULE	3
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #define	PAM_NUM_MODULE_TYPES	4
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /* Control Flags */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #define	PAM_BINDING_NAME	"binding"
700Sstevel@tonic-gate #define	PAM_INCLUDE_NAME	"include"
710Sstevel@tonic-gate #define	PAM_OPTIONAL_NAME	"optional"
720Sstevel@tonic-gate #define	PAM_REQUIRED_NAME	"required"
730Sstevel@tonic-gate #define	PAM_REQUISITE_NAME	"requisite"
740Sstevel@tonic-gate #define	PAM_SUFFICIENT_NAME	"sufficient"
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #define	PAM_BINDING	0x01
770Sstevel@tonic-gate #define	PAM_INCLUDE	0x02
780Sstevel@tonic-gate #define	PAM_OPTIONAL	0x04
790Sstevel@tonic-gate #define	PAM_REQUIRED	0x08
800Sstevel@tonic-gate #define	PAM_REQUISITE	0x10
810Sstevel@tonic-gate #define	PAM_SUFFICIENT	0x20
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #define	PAM_REQRD_BIND	(PAM_REQUIRED | PAM_BINDING)
840Sstevel@tonic-gate #define	PAM_SUFFI_BIND	(PAM_SUFFICIENT | PAM_BINDING)
850Sstevel@tonic-gate 
860Sstevel@tonic-gate /* Function Indicators */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #define	PAM_AUTHENTICATE	1
890Sstevel@tonic-gate #define	PAM_SETCRED		2
900Sstevel@tonic-gate #define	PAM_ACCT_MGMT		3
910Sstevel@tonic-gate #define	PAM_OPEN_SESSION	4
920Sstevel@tonic-gate #define	PAM_CLOSE_SESSION	5
930Sstevel@tonic-gate #define	PAM_CHAUTHTOK		6
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /* PAM tracing */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	PAM_DEBUG	"/etc/pam_debug"
980Sstevel@tonic-gate #define	LOG_PRIORITY	"log_priority="
990Sstevel@tonic-gate #define	LOG_FACILITY	"log_facility="
1000Sstevel@tonic-gate #define	DEBUG_FLAGS	"debug_flags="
1010Sstevel@tonic-gate #define	PAM_DEBUG_NONE		0x0000
1020Sstevel@tonic-gate #define	PAM_DEBUG_DEFAULT	0x0001
1030Sstevel@tonic-gate #define	PAM_DEBUG_ITEM		0x0002
1040Sstevel@tonic-gate #define	PAM_DEBUG_MODULE	0x0004
1050Sstevel@tonic-gate #define	PAM_DEBUG_CONF		0x0008
1060Sstevel@tonic-gate #define	PAM_DEBUG_DATA		0x0010
1070Sstevel@tonic-gate #define	PAM_DEBUG_CONV		0x0020
1080Sstevel@tonic-gate #define	PAM_DEBUG_AUTHTOK	0x8000
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #define	PAM_MAX_ITEMS		64	/* Max number of items */
1110Sstevel@tonic-gate #define	PAM_MAX_INCLUDE		32	/* Max include flag recursions */
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /* authentication module functions */
1140Sstevel@tonic-gate #define	PAM_SM_AUTHENTICATE	"pam_sm_authenticate"
1150Sstevel@tonic-gate #define	PAM_SM_SETCRED		"pam_sm_setcred"
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /* session module functions */
1180Sstevel@tonic-gate #define	PAM_SM_OPEN_SESSION	"pam_sm_open_session"
1190Sstevel@tonic-gate #define	PAM_SM_CLOSE_SESSION	"pam_sm_close_session"
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /* password module functions */
1220Sstevel@tonic-gate #define	PAM_SM_CHAUTHTOK		"pam_sm_chauthtok"
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /* account module functions */
1250Sstevel@tonic-gate #define	PAM_SM_ACCT_MGMT		"pam_sm_acct_mgmt"
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /* max # of authentication token attributes */
1280Sstevel@tonic-gate #define	PAM_MAX_NUM_ATTR	10
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /* max size (in chars) of an authentication token attribute */
1310Sstevel@tonic-gate #define	PAM_MAX_ATTR_SIZE	80
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate /* utility function prototypes */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /* source values when calling __pam_get_authtok() */
1360Sstevel@tonic-gate #define	PAM_PROMPT	1	/* prompt user for new password */
1370Sstevel@tonic-gate #define	PAM_HANDLE	2	/* get password from pam handle (item) */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate #if	PASS_MAX >= PAM_MAX_RESP_SIZE
1400Sstevel@tonic-gate #error	PASS_MAX > PAM_MAX_RESP_SIZE
1410Sstevel@tonic-gate #endif	/* PASS_MAX >= PAM_MAX_RESP_SIZE */
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate extern int
1440Sstevel@tonic-gate __pam_get_authtok(pam_handle_t *pamh, int source, int type, char *prompt,
1450Sstevel@tonic-gate     char **authtok);
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate extern int
1480Sstevel@tonic-gate __pam_display_msg(pam_handle_t *pamh, int msg_style, int num_msg,
1490Sstevel@tonic-gate     char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE], void *conv_apdp);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate extern void
1520Sstevel@tonic-gate __pam_log(int priority, const char *format, ...);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /* file handle for pam.conf */
1550Sstevel@tonic-gate struct pam_fh {
1560Sstevel@tonic-gate 	int	fconfig;	/* file descriptor returned by open() */
1570Sstevel@tonic-gate 	char    line[256];
1580Sstevel@tonic-gate 	size_t  bufsize;	/* size of the buffer which holds */
1590Sstevel@tonic-gate 				/* the content of pam.conf */
1600Sstevel@tonic-gate 	char   *bufferp;	/* used to process data	*/
1610Sstevel@tonic-gate 	char   *data;		/* contents of pam.conf	*/
1620Sstevel@tonic-gate };
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /* items that can be set/retrieved thru pam_[sg]et_item() */
1650Sstevel@tonic-gate struct	pam_item {
1660Sstevel@tonic-gate 	void	*pi_addr;	/* pointer to item */
1670Sstevel@tonic-gate 	int	pi_size;	/* size of item */
1680Sstevel@tonic-gate };
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* module specific data stored in the pam handle */
1710Sstevel@tonic-gate struct pam_module_data {
1720Sstevel@tonic-gate 	char *module_data_name;		/* unique module data name */
1730Sstevel@tonic-gate 	void *data;			/* the module specific data */
1740Sstevel@tonic-gate 	void (*cleanup)(pam_handle_t *pamh, void *data, int pam_status);
1750Sstevel@tonic-gate 	struct pam_module_data *next;	/* pointer to next module data */
1760Sstevel@tonic-gate };
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate /* each entry from pam.conf is stored here (in the pam handle) */
1790Sstevel@tonic-gate typedef struct pamtab {
1800Sstevel@tonic-gate 	char	*pam_service;	/* PAM service, e.g. login, rlogin */
1810Sstevel@tonic-gate 	int	pam_type;	/* AUTH, ACCOUNT, PASSWORD, SESSION */
1820Sstevel@tonic-gate 	int	pam_flag;	/* required, optional, sufficient */
1832295Sgww 	int	pam_err;	/* error if line overflow */
1840Sstevel@tonic-gate 	char	*module_path;	/* module library */
1850Sstevel@tonic-gate 	int	module_argc;	/* module specific options */
1860Sstevel@tonic-gate 	char	**module_argv;
1870Sstevel@tonic-gate 	void	*function_ptr;	/* pointer to struct holding function ptrs */
1880Sstevel@tonic-gate 	struct pamtab *next;
1890Sstevel@tonic-gate } pamtab_t;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /* list of open fd's (modules that were dlopen'd) */
1920Sstevel@tonic-gate typedef struct fd_list {
1930Sstevel@tonic-gate 	void *mh;		/* module handle */
1940Sstevel@tonic-gate 	struct fd_list *next;
1950Sstevel@tonic-gate } fd_list;
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /* list of PAM environment varialbes */
1980Sstevel@tonic-gate typedef struct env_list {
1990Sstevel@tonic-gate 	char *name;
2000Sstevel@tonic-gate 	char *value;
2010Sstevel@tonic-gate 	struct env_list *next;
2020Sstevel@tonic-gate } env_list;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate /* pam_inmodule values for pam item checking */
2050Sstevel@tonic-gate #define	RW_OK	0	/* Read Write items OK */
2060Sstevel@tonic-gate #define	RO_OK	1	/* Read Only items OK */
2070Sstevel@tonic-gate #define	WO_OK	2	/* Write Only items/data OK */
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /* the pam handle */
2100Sstevel@tonic-gate struct pam_handle {
2110Sstevel@tonic-gate 	struct  pam_item ps_item[PAM_MAX_ITEMS];	/* array of PAM items */
2120Sstevel@tonic-gate 	int	include_depth;
2130Sstevel@tonic-gate 	int	pam_inmodule;	/* Protect restricted pam_get_item calls */
2140Sstevel@tonic-gate 	char	*pam_conf_name[PAM_MAX_INCLUDE+1];
2150Sstevel@tonic-gate 	pamtab_t *pam_conf_info[PAM_MAX_INCLUDE+1][PAM_NUM_MODULE_TYPES];
2160Sstevel@tonic-gate 	pamtab_t *pam_conf_modulep[PAM_MAX_INCLUDE+1];
2170Sstevel@tonic-gate 	struct	pam_module_data *ssd;		/* module specific data */
2180Sstevel@tonic-gate 	fd_list *fd;				/* module fd's */
2190Sstevel@tonic-gate 	env_list *pam_env;			/* environment variables */
2200Sstevel@tonic-gate };
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate /*
2230Sstevel@tonic-gate  * the function_ptr field in pamtab_t
2240Sstevel@tonic-gate  * will point to one of these modules
2250Sstevel@tonic-gate  */
2260Sstevel@tonic-gate struct auth_module {
2270Sstevel@tonic-gate 	int	(*pam_sm_authenticate)(pam_handle_t *pamh, int flags, int argc,
2280Sstevel@tonic-gate 		    const char **argv);
2290Sstevel@tonic-gate 	int	(*pam_sm_setcred)(pam_handle_t *pamh, int flags, int argc,
2300Sstevel@tonic-gate 		    const char **argv);
2310Sstevel@tonic-gate };
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate struct password_module {
2340Sstevel@tonic-gate 	int	(*pam_sm_chauthtok)(pam_handle_t *pamh, int flags, int argc,
2350Sstevel@tonic-gate 		    const char **argv);
2360Sstevel@tonic-gate };
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate struct session_module {
2390Sstevel@tonic-gate 	int	(*pam_sm_open_session)(pam_handle_t *pamh, int flags, int argc,
2400Sstevel@tonic-gate 		    const char **argv);
2410Sstevel@tonic-gate 	int	(*pam_sm_close_session)(pam_handle_t *pamh, int flags, int argc,
2420Sstevel@tonic-gate 		    const char **argv);
2430Sstevel@tonic-gate };
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate struct account_module {
2460Sstevel@tonic-gate 	int	(*pam_sm_acct_mgmt)(pam_handle_t *pamh, int flags, int argc,
2470Sstevel@tonic-gate 		    const char **argv);
2480Sstevel@tonic-gate };
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate #ifdef __cplusplus
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate #endif
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate #endif	/* _PAM_IMPL_H */
255