xref: /illumos-gate/usr/src/lib/libpam/pam_impl.h (revision 040524e8)
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
54ef27277Sgww  * Common Development and Distribution License (the "License").
64ef27277Sgww  * 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 /*
2238603a20SDarren J Moffat  * 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	_PAM_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_PAM_IMPL_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 <limits.h>
347c478bd9Sstevel@tonic-gate #include <shadow.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define	PAMTXD		"SUNW_OST_SYSOSPAM"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #define	PAM_CONFIG	"/etc/pam.conf"
407c478bd9Sstevel@tonic-gate #define	PAM_ISA		"/$ISA/"
417c478bd9Sstevel@tonic-gate #define	PAM_LIB_DIR	"/usr/lib/security/"
427c478bd9Sstevel@tonic-gate #ifdef	_LP64
437c478bd9Sstevel@tonic-gate #define	PAM_ISA_DIR	"/64/"
447c478bd9Sstevel@tonic-gate #else	/* !_LP64 */
457c478bd9Sstevel@tonic-gate #define	PAM_ISA_DIR	"/"
467c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /* Service Module Types */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * If new service types are added, they should be named in
527c478bd9Sstevel@tonic-gate  * pam_framework.c::pam_snames[] as well.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	PAM_ACCOUNT_NAME	"account"
567c478bd9Sstevel@tonic-gate #define	PAM_AUTH_NAME		"auth"
577c478bd9Sstevel@tonic-gate #define	PAM_PASSWORD_NAME	"password"
587c478bd9Sstevel@tonic-gate #define	PAM_SESSION_NAME	"session"
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #define	PAM_ACCOUNT_MODULE	0
617c478bd9Sstevel@tonic-gate #define	PAM_AUTH_MODULE		1
627c478bd9Sstevel@tonic-gate #define	PAM_PASSWORD_MODULE	2
637c478bd9Sstevel@tonic-gate #define	PAM_SESSION_MODULE	3
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	PAM_NUM_MODULE_TYPES	4
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /* Control Flags */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	PAM_BINDING_NAME	"binding"
707c478bd9Sstevel@tonic-gate #define	PAM_INCLUDE_NAME	"include"
717c478bd9Sstevel@tonic-gate #define	PAM_OPTIONAL_NAME	"optional"
727c478bd9Sstevel@tonic-gate #define	PAM_REQUIRED_NAME	"required"
737c478bd9Sstevel@tonic-gate #define	PAM_REQUISITE_NAME	"requisite"
747c478bd9Sstevel@tonic-gate #define	PAM_SUFFICIENT_NAME	"sufficient"
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	PAM_BINDING	0x01
777c478bd9Sstevel@tonic-gate #define	PAM_INCLUDE	0x02
787c478bd9Sstevel@tonic-gate #define	PAM_OPTIONAL	0x04
797c478bd9Sstevel@tonic-gate #define	PAM_REQUIRED	0x08
807c478bd9Sstevel@tonic-gate #define	PAM_REQUISITE	0x10
817c478bd9Sstevel@tonic-gate #define	PAM_SUFFICIENT	0x20
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #define	PAM_REQRD_BIND	(PAM_REQUIRED | PAM_BINDING)
847c478bd9Sstevel@tonic-gate #define	PAM_SUFFI_BIND	(PAM_SUFFICIENT | PAM_BINDING)
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* Function Indicators */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	PAM_AUTHENTICATE	1
897c478bd9Sstevel@tonic-gate #define	PAM_SETCRED		2
907c478bd9Sstevel@tonic-gate #define	PAM_ACCT_MGMT		3
917c478bd9Sstevel@tonic-gate #define	PAM_OPEN_SESSION	4
927c478bd9Sstevel@tonic-gate #define	PAM_CLOSE_SESSION	5
937c478bd9Sstevel@tonic-gate #define	PAM_CHAUTHTOK		6
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* PAM tracing */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	PAM_DEBUG	"/etc/pam_debug"
987c478bd9Sstevel@tonic-gate #define	LOG_PRIORITY	"log_priority="
997c478bd9Sstevel@tonic-gate #define	LOG_FACILITY	"log_facility="
1007c478bd9Sstevel@tonic-gate #define	DEBUG_FLAGS	"debug_flags="
1017c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_NONE		0x0000
1027c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_DEFAULT	0x0001
1037c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_ITEM		0x0002
1047c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_MODULE	0x0004
1057c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_CONF		0x0008
1067c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_DATA		0x0010
1077c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_CONV		0x0020
1087c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_AUTHTOK	0x8000
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #define	PAM_MAX_ITEMS		64	/* Max number of items */
1117c478bd9Sstevel@tonic-gate #define	PAM_MAX_INCLUDE		32	/* Max include flag recursions */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /* authentication module functions */
1147c478bd9Sstevel@tonic-gate #define	PAM_SM_AUTHENTICATE	"pam_sm_authenticate"
1157c478bd9Sstevel@tonic-gate #define	PAM_SM_SETCRED		"pam_sm_setcred"
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /* session module functions */
1187c478bd9Sstevel@tonic-gate #define	PAM_SM_OPEN_SESSION	"pam_sm_open_session"
1197c478bd9Sstevel@tonic-gate #define	PAM_SM_CLOSE_SESSION	"pam_sm_close_session"
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /* password module functions */
1227c478bd9Sstevel@tonic-gate #define	PAM_SM_CHAUTHTOK		"pam_sm_chauthtok"
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* account module functions */
1257c478bd9Sstevel@tonic-gate #define	PAM_SM_ACCT_MGMT		"pam_sm_acct_mgmt"
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /* max # of authentication token attributes */
1287c478bd9Sstevel@tonic-gate #define	PAM_MAX_NUM_ATTR	10
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /* max size (in chars) of an authentication token attribute */
1317c478bd9Sstevel@tonic-gate #define	PAM_MAX_ATTR_SIZE	80
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* utility function prototypes */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /* source values when calling __pam_get_authtok() */
1367c478bd9Sstevel@tonic-gate #define	PAM_PROMPT	1	/* prompt user for new password */
1377c478bd9Sstevel@tonic-gate #define	PAM_HANDLE	2	/* get password from pam handle (item) */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #if	PASS_MAX >= PAM_MAX_RESP_SIZE
1407c478bd9Sstevel@tonic-gate #error	PASS_MAX > PAM_MAX_RESP_SIZE
1417c478bd9Sstevel@tonic-gate #endif	/* PASS_MAX >= PAM_MAX_RESP_SIZE */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate extern int
1447c478bd9Sstevel@tonic-gate __pam_get_authtok(pam_handle_t *pamh, int source, int type, char *prompt,
1457c478bd9Sstevel@tonic-gate     char **authtok);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate extern int
1487c478bd9Sstevel@tonic-gate __pam_display_msg(pam_handle_t *pamh, int msg_style, int num_msg,
149*040524e8SToomas Soome     char messages[][PAM_MAX_MSG_SIZE], void *conv_apdp);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate extern void
1527c478bd9Sstevel@tonic-gate __pam_log(int priority, const char *format, ...);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /* file handle for pam.conf */
1557c478bd9Sstevel@tonic-gate struct pam_fh {
1567c478bd9Sstevel@tonic-gate 	int	fconfig;	/* file descriptor returned by open() */
1577c478bd9Sstevel@tonic-gate 	char    line[256];
1587c478bd9Sstevel@tonic-gate 	size_t  bufsize;	/* size of the buffer which holds */
1597c478bd9Sstevel@tonic-gate 				/* the content of pam.conf */
1607c478bd9Sstevel@tonic-gate 	char   *bufferp;	/* used to process data	*/
1617c478bd9Sstevel@tonic-gate 	char   *data;		/* contents of pam.conf	*/
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /* items that can be set/retrieved thru pam_[sg]et_item() */
1657c478bd9Sstevel@tonic-gate struct	pam_item {
1667c478bd9Sstevel@tonic-gate 	void	*pi_addr;	/* pointer to item */
1677c478bd9Sstevel@tonic-gate 	int	pi_size;	/* size of item */
1687c478bd9Sstevel@tonic-gate };
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /* module specific data stored in the pam handle */
1717c478bd9Sstevel@tonic-gate struct pam_module_data {
1727c478bd9Sstevel@tonic-gate 	char *module_data_name;		/* unique module data name */
1737c478bd9Sstevel@tonic-gate 	void *data;			/* the module specific data */
1747c478bd9Sstevel@tonic-gate 	void (*cleanup)(pam_handle_t *pamh, void *data, int pam_status);
1757c478bd9Sstevel@tonic-gate 	struct pam_module_data *next;	/* pointer to next module data */
1767c478bd9Sstevel@tonic-gate };
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /* each entry from pam.conf is stored here (in the pam handle) */
1797c478bd9Sstevel@tonic-gate typedef struct pamtab {
1807c478bd9Sstevel@tonic-gate 	char	*pam_service;	/* PAM service, e.g. login, rlogin */
1817c478bd9Sstevel@tonic-gate 	int	pam_type;	/* AUTH, ACCOUNT, PASSWORD, SESSION */
1827c478bd9Sstevel@tonic-gate 	int	pam_flag;	/* required, optional, sufficient */
1834ef27277Sgww 	int	pam_err;	/* error if line overflow */
1847c478bd9Sstevel@tonic-gate 	char	*module_path;	/* module library */
1857c478bd9Sstevel@tonic-gate 	int	module_argc;	/* module specific options */
1867c478bd9Sstevel@tonic-gate 	char	**module_argv;
1877c478bd9Sstevel@tonic-gate 	void	*function_ptr;	/* pointer to struct holding function ptrs */
1887c478bd9Sstevel@tonic-gate 	struct pamtab *next;
1897c478bd9Sstevel@tonic-gate } pamtab_t;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /* list of open fd's (modules that were dlopen'd) */
1927c478bd9Sstevel@tonic-gate typedef struct fd_list {
1937c478bd9Sstevel@tonic-gate 	void *mh;		/* module handle */
1947c478bd9Sstevel@tonic-gate 	struct fd_list *next;
1957c478bd9Sstevel@tonic-gate } fd_list;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /* list of PAM environment varialbes */
1987c478bd9Sstevel@tonic-gate typedef struct env_list {
1997c478bd9Sstevel@tonic-gate 	char *name;
2007c478bd9Sstevel@tonic-gate 	char *value;
2017c478bd9Sstevel@tonic-gate 	struct env_list *next;
2027c478bd9Sstevel@tonic-gate } env_list;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate /* pam_inmodule values for pam item checking */
2057c478bd9Sstevel@tonic-gate #define	RW_OK	0	/* Read Write items OK */
2067c478bd9Sstevel@tonic-gate #define	RO_OK	1	/* Read Only items OK */
2077c478bd9Sstevel@tonic-gate #define	WO_OK	2	/* Write Only items/data OK */
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /* the pam handle */
2107c478bd9Sstevel@tonic-gate struct pam_handle {
2117c478bd9Sstevel@tonic-gate 	struct  pam_item ps_item[PAM_MAX_ITEMS];	/* array of PAM items */
2127c478bd9Sstevel@tonic-gate 	int	include_depth;
2137c478bd9Sstevel@tonic-gate 	int	pam_inmodule;	/* Protect restricted pam_get_item calls */
2147c478bd9Sstevel@tonic-gate 	char	*pam_conf_name[PAM_MAX_INCLUDE+1];
2157c478bd9Sstevel@tonic-gate 	pamtab_t *pam_conf_info[PAM_MAX_INCLUDE+1][PAM_NUM_MODULE_TYPES];
2167c478bd9Sstevel@tonic-gate 	pamtab_t *pam_conf_modulep[PAM_MAX_INCLUDE+1];
2177c478bd9Sstevel@tonic-gate 	struct	pam_module_data *ssd;		/* module specific data */
2187c478bd9Sstevel@tonic-gate 	fd_list *fd;				/* module fd's */
2197c478bd9Sstevel@tonic-gate 	env_list *pam_env;			/* environment variables */
2207c478bd9Sstevel@tonic-gate };
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * the function_ptr field in pamtab_t
2247c478bd9Sstevel@tonic-gate  * will point to one of these modules
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate struct auth_module {
2277c478bd9Sstevel@tonic-gate 	int	(*pam_sm_authenticate)(pam_handle_t *pamh, int flags, int argc,
2287c478bd9Sstevel@tonic-gate 		    const char **argv);
2297c478bd9Sstevel@tonic-gate 	int	(*pam_sm_setcred)(pam_handle_t *pamh, int flags, int argc,
2307c478bd9Sstevel@tonic-gate 		    const char **argv);
2317c478bd9Sstevel@tonic-gate };
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate struct password_module {
2347c478bd9Sstevel@tonic-gate 	int	(*pam_sm_chauthtok)(pam_handle_t *pamh, int flags, int argc,
2357c478bd9Sstevel@tonic-gate 		    const char **argv);
2367c478bd9Sstevel@tonic-gate };
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate struct session_module {
2397c478bd9Sstevel@tonic-gate 	int	(*pam_sm_open_session)(pam_handle_t *pamh, int flags, int argc,
2407c478bd9Sstevel@tonic-gate 		    const char **argv);
2417c478bd9Sstevel@tonic-gate 	int	(*pam_sm_close_session)(pam_handle_t *pamh, int flags, int argc,
2427c478bd9Sstevel@tonic-gate 		    const char **argv);
2437c478bd9Sstevel@tonic-gate };
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate struct account_module {
2467c478bd9Sstevel@tonic-gate 	int	(*pam_sm_acct_mgmt)(pam_handle_t *pamh, int flags, int argc,
2477c478bd9Sstevel@tonic-gate 		    const char **argv);
2487c478bd9Sstevel@tonic-gate };
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate #endif
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate #endif	/* _PAM_IMPL_H */
255