xref: /titanic_53/usr/src/lib/libpam/pam_impl.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 2005 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	_PAM_IMPL_H
28*7c478bd9Sstevel@tonic-gate #define	_PAM_IMPL_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 <limits.h>
37*7c478bd9Sstevel@tonic-gate #include <shadow.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #define	PAMTXD		"SUNW_OST_SYSOSPAM"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #define	PAM_CONFIG	"/etc/pam.conf"
43*7c478bd9Sstevel@tonic-gate #define	PAM_ISA		"/$ISA/"
44*7c478bd9Sstevel@tonic-gate #define	PAM_LIB_DIR	"/usr/lib/security/"
45*7c478bd9Sstevel@tonic-gate #ifdef	_LP64
46*7c478bd9Sstevel@tonic-gate #define	PAM_ISA_DIR	"/64/"
47*7c478bd9Sstevel@tonic-gate #else	/* !_LP64 */
48*7c478bd9Sstevel@tonic-gate #define	PAM_ISA_DIR	"/"
49*7c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /* Service Module Types */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * If new service types are added, they should be named in
55*7c478bd9Sstevel@tonic-gate  * pam_framework.c::pam_snames[] as well.
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate #define	PAM_ACCOUNT_NAME	"account"
59*7c478bd9Sstevel@tonic-gate #define	PAM_AUTH_NAME		"auth"
60*7c478bd9Sstevel@tonic-gate #define	PAM_PASSWORD_NAME	"password"
61*7c478bd9Sstevel@tonic-gate #define	PAM_SESSION_NAME	"session"
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #define	PAM_ACCOUNT_MODULE	0
64*7c478bd9Sstevel@tonic-gate #define	PAM_AUTH_MODULE		1
65*7c478bd9Sstevel@tonic-gate #define	PAM_PASSWORD_MODULE	2
66*7c478bd9Sstevel@tonic-gate #define	PAM_SESSION_MODULE	3
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate #define	PAM_NUM_MODULE_TYPES	4
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /* Control Flags */
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #define	PAM_BINDING_NAME	"binding"
73*7c478bd9Sstevel@tonic-gate #define	PAM_INCLUDE_NAME	"include"
74*7c478bd9Sstevel@tonic-gate #define	PAM_OPTIONAL_NAME	"optional"
75*7c478bd9Sstevel@tonic-gate #define	PAM_REQUIRED_NAME	"required"
76*7c478bd9Sstevel@tonic-gate #define	PAM_REQUISITE_NAME	"requisite"
77*7c478bd9Sstevel@tonic-gate #define	PAM_SUFFICIENT_NAME	"sufficient"
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate #define	PAM_BINDING	0x01
80*7c478bd9Sstevel@tonic-gate #define	PAM_INCLUDE	0x02
81*7c478bd9Sstevel@tonic-gate #define	PAM_OPTIONAL	0x04
82*7c478bd9Sstevel@tonic-gate #define	PAM_REQUIRED	0x08
83*7c478bd9Sstevel@tonic-gate #define	PAM_REQUISITE	0x10
84*7c478bd9Sstevel@tonic-gate #define	PAM_SUFFICIENT	0x20
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate #define	PAM_REQRD_BIND	(PAM_REQUIRED | PAM_BINDING)
87*7c478bd9Sstevel@tonic-gate #define	PAM_SUFFI_BIND	(PAM_SUFFICIENT | PAM_BINDING)
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /* Function Indicators */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #define	PAM_AUTHENTICATE	1
92*7c478bd9Sstevel@tonic-gate #define	PAM_SETCRED		2
93*7c478bd9Sstevel@tonic-gate #define	PAM_ACCT_MGMT		3
94*7c478bd9Sstevel@tonic-gate #define	PAM_OPEN_SESSION	4
95*7c478bd9Sstevel@tonic-gate #define	PAM_CLOSE_SESSION	5
96*7c478bd9Sstevel@tonic-gate #define	PAM_CHAUTHTOK		6
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /* PAM tracing */
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG	"/etc/pam_debug"
101*7c478bd9Sstevel@tonic-gate #define	LOG_PRIORITY	"log_priority="
102*7c478bd9Sstevel@tonic-gate #define	LOG_FACILITY	"log_facility="
103*7c478bd9Sstevel@tonic-gate #define	DEBUG_FLAGS	"debug_flags="
104*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_NONE		0x0000
105*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_DEFAULT	0x0001
106*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_ITEM		0x0002
107*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_MODULE	0x0004
108*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_CONF		0x0008
109*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_DATA		0x0010
110*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_CONV		0x0020
111*7c478bd9Sstevel@tonic-gate #define	PAM_DEBUG_AUTHTOK	0x8000
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate #define	PAM_MAX_ITEMS		64	/* Max number of items */
114*7c478bd9Sstevel@tonic-gate #define	PAM_MAX_INCLUDE		32	/* Max include flag recursions */
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /* authentication module functions */
117*7c478bd9Sstevel@tonic-gate #define	PAM_SM_AUTHENTICATE	"pam_sm_authenticate"
118*7c478bd9Sstevel@tonic-gate #define	PAM_SM_SETCRED		"pam_sm_setcred"
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate /* session module functions */
121*7c478bd9Sstevel@tonic-gate #define	PAM_SM_OPEN_SESSION	"pam_sm_open_session"
122*7c478bd9Sstevel@tonic-gate #define	PAM_SM_CLOSE_SESSION	"pam_sm_close_session"
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /* password module functions */
125*7c478bd9Sstevel@tonic-gate #define	PAM_SM_CHAUTHTOK		"pam_sm_chauthtok"
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /* account module functions */
128*7c478bd9Sstevel@tonic-gate #define	PAM_SM_ACCT_MGMT		"pam_sm_acct_mgmt"
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /*
131*7c478bd9Sstevel@tonic-gate  * Definitions shared by passwd.c and the UNIX module
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #define	PAM_REP_DEFAULT	0x0
135*7c478bd9Sstevel@tonic-gate #define	PAM_REP_FILES	0x01
136*7c478bd9Sstevel@tonic-gate #define	PAM_REP_NIS	0x02
137*7c478bd9Sstevel@tonic-gate #define	PAM_REP_NISPLUS	0x04
138*7c478bd9Sstevel@tonic-gate #define	PAM_REP_LDAP	0x10
139*7c478bd9Sstevel@tonic-gate #define	PAM_OPWCMD	0x08	/* for nispasswd, yppasswd */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /* max # of authentication token attributes */
142*7c478bd9Sstevel@tonic-gate #define	PAM_MAX_NUM_ATTR	10
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /* max size (in chars) of an authentication token attribute */
145*7c478bd9Sstevel@tonic-gate #define	PAM_MAX_ATTR_SIZE	80
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /* utility function prototypes */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate /* source values when calling __pam_get_authtok() */
150*7c478bd9Sstevel@tonic-gate #define	PAM_PROMPT	1	/* prompt user for new password */
151*7c478bd9Sstevel@tonic-gate #define	PAM_HANDLE	2	/* get password from pam handle (item) */
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate #if	PASS_MAX >= PAM_MAX_RESP_SIZE
154*7c478bd9Sstevel@tonic-gate #error	PASS_MAX > PAM_MAX_RESP_SIZE
155*7c478bd9Sstevel@tonic-gate #endif	/* PASS_MAX >= PAM_MAX_RESP_SIZE */
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate extern int
158*7c478bd9Sstevel@tonic-gate __pam_get_authtok(pam_handle_t *pamh, int source, int type, char *prompt,
159*7c478bd9Sstevel@tonic-gate     char **authtok);
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate extern int
162*7c478bd9Sstevel@tonic-gate __pam_display_msg(pam_handle_t *pamh, int msg_style, int num_msg,
163*7c478bd9Sstevel@tonic-gate     char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE], void *conv_apdp);
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate extern void
166*7c478bd9Sstevel@tonic-gate __pam_log(int priority, const char *format, ...);
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /* file handle for pam.conf */
169*7c478bd9Sstevel@tonic-gate struct pam_fh {
170*7c478bd9Sstevel@tonic-gate 	int	fconfig;	/* file descriptor returned by open() */
171*7c478bd9Sstevel@tonic-gate 	char    line[256];
172*7c478bd9Sstevel@tonic-gate 	size_t  bufsize;	/* size of the buffer which holds */
173*7c478bd9Sstevel@tonic-gate 				/* the content of pam.conf */
174*7c478bd9Sstevel@tonic-gate 	char   *bufferp;	/* used to process data	*/
175*7c478bd9Sstevel@tonic-gate 	char   *data;		/* contents of pam.conf	*/
176*7c478bd9Sstevel@tonic-gate };
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate /* items that can be set/retrieved thru pam_[sg]et_item() */
179*7c478bd9Sstevel@tonic-gate struct	pam_item {
180*7c478bd9Sstevel@tonic-gate 	void	*pi_addr;	/* pointer to item */
181*7c478bd9Sstevel@tonic-gate 	int	pi_size;	/* size of item */
182*7c478bd9Sstevel@tonic-gate };
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate /* module specific data stored in the pam handle */
185*7c478bd9Sstevel@tonic-gate struct pam_module_data {
186*7c478bd9Sstevel@tonic-gate 	char *module_data_name;		/* unique module data name */
187*7c478bd9Sstevel@tonic-gate 	void *data;			/* the module specific data */
188*7c478bd9Sstevel@tonic-gate 	void (*cleanup)(pam_handle_t *pamh, void *data, int pam_status);
189*7c478bd9Sstevel@tonic-gate 	struct pam_module_data *next;	/* pointer to next module data */
190*7c478bd9Sstevel@tonic-gate };
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate /* each entry from pam.conf is stored here (in the pam handle) */
193*7c478bd9Sstevel@tonic-gate typedef struct pamtab {
194*7c478bd9Sstevel@tonic-gate 	char	*pam_service;	/* PAM service, e.g. login, rlogin */
195*7c478bd9Sstevel@tonic-gate 	int	pam_type;	/* AUTH, ACCOUNT, PASSWORD, SESSION */
196*7c478bd9Sstevel@tonic-gate 	int	pam_flag;	/* required, optional, sufficient */
197*7c478bd9Sstevel@tonic-gate 	char	*module_path;	/* module library */
198*7c478bd9Sstevel@tonic-gate 	int	module_argc;	/* module specific options */
199*7c478bd9Sstevel@tonic-gate 	char	**module_argv;
200*7c478bd9Sstevel@tonic-gate 	void	*function_ptr;	/* pointer to struct holding function ptrs */
201*7c478bd9Sstevel@tonic-gate 	struct pamtab *next;
202*7c478bd9Sstevel@tonic-gate } pamtab_t;
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate /* list of open fd's (modules that were dlopen'd) */
205*7c478bd9Sstevel@tonic-gate typedef struct fd_list {
206*7c478bd9Sstevel@tonic-gate 	void *mh;		/* module handle */
207*7c478bd9Sstevel@tonic-gate 	struct fd_list *next;
208*7c478bd9Sstevel@tonic-gate } fd_list;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate /* list of PAM environment varialbes */
211*7c478bd9Sstevel@tonic-gate typedef struct env_list {
212*7c478bd9Sstevel@tonic-gate 	char *name;
213*7c478bd9Sstevel@tonic-gate 	char *value;
214*7c478bd9Sstevel@tonic-gate 	struct env_list *next;
215*7c478bd9Sstevel@tonic-gate } env_list;
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate /* pam_inmodule values for pam item checking */
218*7c478bd9Sstevel@tonic-gate #define	RW_OK	0	/* Read Write items OK */
219*7c478bd9Sstevel@tonic-gate #define	RO_OK	1	/* Read Only items OK */
220*7c478bd9Sstevel@tonic-gate #define	WO_OK	2	/* Write Only items/data OK */
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate /* the pam handle */
223*7c478bd9Sstevel@tonic-gate struct pam_handle {
224*7c478bd9Sstevel@tonic-gate 	struct  pam_item ps_item[PAM_MAX_ITEMS];	/* array of PAM items */
225*7c478bd9Sstevel@tonic-gate 	int	include_depth;
226*7c478bd9Sstevel@tonic-gate 	int	pam_inmodule;	/* Protect restricted pam_get_item calls */
227*7c478bd9Sstevel@tonic-gate 	char	*pam_conf_name[PAM_MAX_INCLUDE+1];
228*7c478bd9Sstevel@tonic-gate 	pamtab_t *pam_conf_info[PAM_MAX_INCLUDE+1][PAM_NUM_MODULE_TYPES];
229*7c478bd9Sstevel@tonic-gate 	pamtab_t *pam_conf_modulep[PAM_MAX_INCLUDE+1];
230*7c478bd9Sstevel@tonic-gate 	struct	pam_module_data *ssd;		/* module specific data */
231*7c478bd9Sstevel@tonic-gate 	fd_list *fd;				/* module fd's */
232*7c478bd9Sstevel@tonic-gate 	env_list *pam_env;			/* environment variables */
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate 	/*
235*7c478bd9Sstevel@tonic-gate 	 * XXX -- Contracted Consolidation Private
236*7c478bd9Sstevel@tonic-gate 	 *	  to be eliminated when dtlogin contract is terminated
237*7c478bd9Sstevel@tonic-gate 	 * Version number requested by PAM's client
238*7c478bd9Sstevel@tonic-gate 	 */
239*7c478bd9Sstevel@tonic-gate 	char	*pam_client_message_version_number;
240*7c478bd9Sstevel@tonic-gate };
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate /*
243*7c478bd9Sstevel@tonic-gate  * the function_ptr field in pamtab_t
244*7c478bd9Sstevel@tonic-gate  * will point to one of these modules
245*7c478bd9Sstevel@tonic-gate  */
246*7c478bd9Sstevel@tonic-gate struct auth_module {
247*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_authenticate)(pam_handle_t *pamh, int flags, int argc,
248*7c478bd9Sstevel@tonic-gate 		    const char **argv);
249*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_setcred)(pam_handle_t *pamh, int flags, int argc,
250*7c478bd9Sstevel@tonic-gate 		    const char **argv);
251*7c478bd9Sstevel@tonic-gate };
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate struct password_module {
254*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_chauthtok)(pam_handle_t *pamh, int flags, int argc,
255*7c478bd9Sstevel@tonic-gate 		    const char **argv);
256*7c478bd9Sstevel@tonic-gate };
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate struct session_module {
259*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_open_session)(pam_handle_t *pamh, int flags, int argc,
260*7c478bd9Sstevel@tonic-gate 		    const char **argv);
261*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_close_session)(pam_handle_t *pamh, int flags, int argc,
262*7c478bd9Sstevel@tonic-gate 		    const char **argv);
263*7c478bd9Sstevel@tonic-gate };
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate struct account_module {
266*7c478bd9Sstevel@tonic-gate 	int	(*pam_sm_acct_mgmt)(pam_handle_t *pamh, int flags, int argc,
267*7c478bd9Sstevel@tonic-gate 		    const char **argv);
268*7c478bd9Sstevel@tonic-gate };
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
271*7c478bd9Sstevel@tonic-gate }
272*7c478bd9Sstevel@tonic-gate #endif
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate #endif	/* _PAM_IMPL_H */
275