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