xref: /titanic_41/usr/src/lib/libpam/pam_appl.h (revision e4603304e8bd084dd25a0dbafdd438ac250d5f56)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _PAM_APPL_H
27 #define	_PAM_APPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /* Generic PAM errors */
38 #define	PAM_SUCCESS		0	/* Normal function return */
39 #define	PAM_OPEN_ERR		1	/* Dlopen failure */
40 #define	PAM_SYMBOL_ERR		2	/* Symbol not found */
41 #define	PAM_SERVICE_ERR		3	/* Error in underlying service module */
42 #define	PAM_SYSTEM_ERR		4	/* System error */
43 #define	PAM_BUF_ERR		5	/* Memory buffer error */
44 #define	PAM_CONV_ERR		6	/* Conversation failure */
45 #define	PAM_PERM_DENIED		7	/* Permission denied */
46 
47 /* Errors returned by pam_authenticate, pam_acct_mgmt(), and pam_setcred() */
48 #define	PAM_MAXTRIES		8	/* Maximum number of tries exceeded */
49 #define	PAM_AUTH_ERR		9	/* Authentication failure */
50 #define	PAM_NEW_AUTHTOK_REQD	10	/* Get new auth token from the user */
51 #define	PAM_CRED_INSUFFICIENT	11	/* can not access auth data b/c */
52 					/* of insufficient credentials  */
53 #define	PAM_AUTHINFO_UNAVAIL	12	/* Can not retrieve auth information */
54 #define	PAM_USER_UNKNOWN	13	/* No account present for user */
55 
56 /* Errors returned by pam_setcred() */
57 #define	PAM_CRED_UNAVAIL	14	/* can not retrieve user credentials */
58 #define	PAM_CRED_EXPIRED	15	/* user credentials expired */
59 #define	PAM_CRED_ERR		16	/* failure setting user credentials */
60 
61 /* Errors returned by pam_acct_mgmt() */
62 #define	PAM_ACCT_EXPIRED	17	/* user account has expired */
63 #define	PAM_AUTHTOK_EXPIRED 	18	/* Password expired and no longer */
64 					/* usable */
65 
66 /* Errors returned by pam_open/close_session() */
67 #define	PAM_SESSION_ERR		19	/* can not make/remove entry for */
68 					/* specified session */
69 
70 /* Errors returned by pam_chauthtok() */
71 #define	PAM_AUTHTOK_ERR		  20	/* Authentication token */
72 					/*   manipulation error */
73 #define	PAM_AUTHTOK_RECOVERY_ERR  21	/* Old authentication token */
74 					/*   cannot be recovered */
75 #define	PAM_AUTHTOK_LOCK_BUSY	  22	/* Authentication token */
76 					/*   lock busy */
77 #define	PAM_AUTHTOK_DISABLE_AGING 23	/* Authentication token aging */
78 					/*   is disabled */
79 
80 /* Errors returned by pam_get_data */
81 #define	PAM_NO_MODULE_DATA	24	/* module data not found */
82 
83 /* Errors returned by modules */
84 #define	PAM_IGNORE		25	/* ignore module */
85 
86 #define	PAM_ABORT		26	/* General PAM failure */
87 #define	PAM_TRY_AGAIN		27	/* Unable to update password */
88 					/* Try again another time */
89 #define	PAM_TOTAL_ERRNUM	28
90 
91 /*
92  * structure pam_message is used to pass prompt, error message,
93  * or any text information from scheme to application/user.
94  */
95 
96 struct pam_message {
97 	int msg_style;		/* Msg_style - see below */
98 	char *msg; 		/* Message string */
99 };
100 
101 /*
102  * msg_style defines the interaction style between the
103  * scheme and the application.
104  */
105 #define	PAM_PROMPT_ECHO_OFF	1	/* Echo off when getting response */
106 #define	PAM_PROMPT_ECHO_ON	2 	/* Echo on when getting response */
107 #define	PAM_ERROR_MSG		3	/* Error message */
108 #define	PAM_TEXT_INFO		4	/* Textual information */
109 
110 /*
111  * Sun's proprietary message types
112  * Can these new new message types supported in version 2
113  * have the numbers like -XXX (ie., negative numbers).
114  * Hence will not clash with new proposals from X/OPEN
115  */
116 #define	PAM_MSG_NOCONF		2001	/* No confirmation from user */
117 #define	PAM_CONV_INTERRUPT	2002	/* Return from conv() */
118 
119 /*
120  * max # of messages passed to the application through the
121  * conversation function call
122  */
123 #define	PAM_MAX_NUM_MSG	32
124 
125 /*
126  * max size (in chars) of each messages passed to the application
127  * through the conversation function call
128  */
129 #define	PAM_MAX_MSG_SIZE	512
130 
131 /*
132  * max size (in chars) of each response passed from the application
133  * through the conversation function call
134  */
135 #define	PAM_MAX_RESP_SIZE	512
136 
137 /*
138  * structure pam_response is used by the scheme to get the user's
139  * response back from the application/user.
140  */
141 
142 struct pam_response {
143 	char *resp;		/* Response string */
144 	int resp_retcode;	/* Return code - for future use */
145 };
146 
147 /*
148  * structure pam_conv is used by authentication applications for passing
149  * call back function pointers and application data pointers to the scheme
150  */
151 struct pam_conv {
152 	int (*conv)(int, struct pam_message **,
153 	    struct pam_response **, void *);
154 	void *appdata_ptr;		/* Application data ptr */
155 };
156 
157 /* the pam handle */
158 typedef struct pam_handle pam_handle_t;
159 
160 /*
161  * pam_start() is called to initiate an authentication exchange
162  * with PAM.
163  */
164 extern int
165 pam_start(
166 	const char *service_name,		/* Service Name */
167 	const char *user,			/* User Name */
168 	const struct pam_conv *pam_conv,	/* Conversation structure */
169 	pam_handle_t **pamh		/* Address to store handle */
170 );
171 
172 /*
173  * pam_end() is called to end an authentication exchange with PAM.
174  */
175 extern int
176 pam_end(
177 	pam_handle_t *pamh,		/* handle from pam_start() */
178 	int status			/* the final status value that */
179 					/* gets passed to cleanup functions */
180 );
181 
182 /*
183  * pam_set_item is called to store an object in PAM handle.
184  */
185 extern int
186 pam_set_item(
187 	pam_handle_t *pamh,		/* PAM handle */
188 	int item_type, 			/* Type of object - see below */
189 	const void *item		/* Address of place to put pointer */
190 					/*   to object */
191 );
192 
193 /*
194  * pam_get_item is called to retrieve an object from the static data area
195  */
196 extern int
197 pam_get_item(
198 	const pam_handle_t *pamh, 	/* PAM handle */
199 	int item_type, 			/* Type of object - see below */
200 	void **	item			/* Address of place to put pointer */
201 					/*   to object */
202 );
203 
204 /* Items supported by pam_[sg]et_item() calls */
205 #define	PAM_SERVICE	1		/* The program/service name */
206 #define	PAM_USER	2		/* The user name */
207 #define	PAM_TTY		3		/* The tty name */
208 #define	PAM_RHOST	4		/* The remote host name */
209 #define	PAM_CONV	5		/* The conversation structure */
210 #define	PAM_AUTHTOK	6		/* The authentication token */
211 #define	PAM_OLDAUTHTOK	7		/* Old authentication token */
212 #define	PAM_RUSER	8		/* The remote user name */
213 #define	PAM_USER_PROMPT	9		/* The user prompt */
214 #define	PAM_REPOSITORY	10		/* The repository to be updated */
215 #define	PAM_RESOURCE	11		/* Resource management info */
216 #define	PAM_AUSER	12		/* The authenticated user name */
217 
218 /* pam repository structure */
219 
220 struct pam_repository {
221 	char   *type;		/* Repository type, e.g., files, nis, ldap */
222 	void   *scope;		/* Optional scope information */
223 	size_t  scope_len;	/* length of scope inforamtion */
224 };
225 
226 typedef struct pam_repository pam_repository_t;
227 
228 /*
229  * PAM message version.
230  * Sun proprietary pam_[sg]et_item() extension
231  */
232 #define	PAM_MSG_VERSION	3001		/* PAM message version supported */
233 #define	PAM_MSG_VERSION_V2 "2.0"	/* PAM 2.0 message version */
234 
235 /*
236  * pam_get_user is called to retrieve the user name (PAM_USER). If PAM_USER
237  * is not set then this call will prompt for the user name using the
238  * conversation function. This function should only be used by modules, not
239  * applications.
240  */
241 
242 extern int
243 pam_get_user(
244 	pam_handle_t *pamh,		/* PAM handle */
245 	char **user, 			/* User Name */
246 	const char *prompt		/* Prompt */
247 );
248 
249 /*
250  * PAM equivalent to strerror();
251  */
252 extern const char *
253 pam_strerror(
254 	pam_handle_t *pamh,	/* pam handle */
255 	int errnum		/* error number */
256 );
257 
258 /* general flag for pam_* functions */
259 #define	PAM_SILENT	0x80000000
260 
261 /*
262  * pam_authenticate is called to authenticate the current user.
263  */
264 extern int
265 pam_authenticate(
266 	pam_handle_t *pamh,
267 	int flags
268 );
269 
270 /*
271  * Flags for pam_authenticate
272  */
273 
274 #define	PAM_DISALLOW_NULL_AUTHTOK 0x1	/* The password must be non-null */
275 
276 /*
277  * pam_acct_mgmt is called to perform account management processing
278  */
279 extern int
280 pam_acct_mgmt(
281 	pam_handle_t *pamh,
282 	int flags
283 );
284 
285 /*
286  * pam_open_session is called to note the initiation of new session in the
287  * appropriate administrative data bases.
288  */
289 extern int
290 pam_open_session(
291 	pam_handle_t *pamh,
292 	int flags
293 );
294 
295 /*
296  * pam_close_session records the termination of a session.
297  */
298 extern int
299 pam_close_session(
300 	pam_handle_t	*pamh,
301 	int		flags
302 );
303 
304 /* pam_setcred is called to set the credentials of the current user */
305 extern int
306 pam_setcred(
307 	pam_handle_t *pamh,
308 	int flags
309 );
310 
311 /* flags for pam_setcred() */
312 #define	PAM_ESTABLISH_CRED	0x1	/* set scheme specific user id */
313 #define	PAM_DELETE_CRED		0x2	/* unset scheme specific user id */
314 #define	PAM_REINITIALIZE_CRED	0x4	/* reinitialize user credentials */
315 					/* (after a password has changed */
316 #define	PAM_REFRESH_CRED	0x8	/* extend lifetime of credentials */
317 
318 /* pam_chauthtok is called to change authentication token */
319 
320 extern int
321 pam_chauthtok(
322 	pam_handle_t	*pamh,
323 	int		flags
324 );
325 
326 /*
327  * Be careful - there are flags defined for pam_sm_chauthtok() in
328  * pam_modules.h also:
329  * PAM_PRELIM_CHECK	0x1
330  * PAM_UPDATE_AUTHTOK	0x2
331  */
332 #define	PAM_CHANGE_EXPIRED_AUTHTOK	0x4 /* update expired passwords only */
333 #define	PAM_NO_AUTHTOK_CHECK		0x8 /* bypass password strength tests */
334 
335 /* pam_putenv is called to add environment variables to the PAM handle */
336 
337 extern int
338 pam_putenv(
339 	pam_handle_t	*pamh,
340 	const char	*name_value
341 );
342 
343 /* pam_getenv is called to retrieve an env variable from the PAM handle */
344 
345 extern char *
346 pam_getenv(
347 	pam_handle_t	*pamh,
348 	const char	*name
349 );
350 
351 /* pam_getenvlist is called to retrieve all env variables from the PAM handle */
352 
353 extern char **
354 pam_getenvlist(
355 	pam_handle_t	*pamh
356 );
357 
358 #ifdef	__cplusplus
359 }
360 #endif
361 
362 #endif /* _PAM_APPL_H */
363