Merge commit 'cc543d0f9e35a75cc302a4cb152756d233299564'
[unleashed.git] / usr / src / lib / libpam / pam_appl.h
blob52080dea7a73135d506547352950f48fa2a61730
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _PAM_APPL_H
27 #define _PAM_APPL_H
29 #include <sys/types.h>
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 /* Generic PAM errors */
36 #define PAM_SUCCESS 0 /* Normal function return */
37 #define PAM_OPEN_ERR 1 /* Dlopen failure */
38 #define PAM_SYMBOL_ERR 2 /* Symbol not found */
39 #define PAM_SERVICE_ERR 3 /* Error in underlying service module */
40 #define PAM_SYSTEM_ERR 4 /* System error */
41 #define PAM_BUF_ERR 5 /* Memory buffer error */
42 #define PAM_CONV_ERR 6 /* Conversation failure */
43 #define PAM_PERM_DENIED 7 /* Permission denied */
45 /* Errors returned by pam_authenticate, pam_acct_mgmt(), and pam_setcred() */
46 #define PAM_MAXTRIES 8 /* Maximum number of tries exceeded */
47 #define PAM_AUTH_ERR 9 /* Authentication failure */
48 #define PAM_NEW_AUTHTOK_REQD 10 /* Get new auth token from the user */
49 #define PAM_CRED_INSUFFICIENT 11 /* can not access auth data b/c */
50 /* of insufficient credentials */
51 #define PAM_AUTHINFO_UNAVAIL 12 /* Can not retrieve auth information */
52 #define PAM_USER_UNKNOWN 13 /* No account present for user */
54 /* Errors returned by pam_setcred() */
55 #define PAM_CRED_UNAVAIL 14 /* can not retrieve user credentials */
56 #define PAM_CRED_EXPIRED 15 /* user credentials expired */
57 #define PAM_CRED_ERR 16 /* failure setting user credentials */
59 /* Errors returned by pam_acct_mgmt() */
60 #define PAM_ACCT_EXPIRED 17 /* user account has expired */
61 #define PAM_AUTHTOK_EXPIRED 18 /* Password expired and no longer */
62 /* usable */
64 /* Errors returned by pam_open/close_session() */
65 #define PAM_SESSION_ERR 19 /* can not make/remove entry for */
66 /* specified session */
68 /* Errors returned by pam_chauthtok() */
69 #define PAM_AUTHTOK_ERR 20 /* Authentication token */
70 /* manipulation error */
71 #define PAM_AUTHTOK_RECOVERY_ERR 21 /* Old authentication token */
72 /* cannot be recovered */
73 #define PAM_AUTHTOK_LOCK_BUSY 22 /* Authentication token */
74 /* lock busy */
75 #define PAM_AUTHTOK_DISABLE_AGING 23 /* Authentication token aging */
76 /* is disabled */
78 /* Errors returned by pam_get_data */
79 #define PAM_NO_MODULE_DATA 24 /* module data not found */
81 /* Errors returned by modules */
82 #define PAM_IGNORE 25 /* ignore module */
84 #define PAM_ABORT 26 /* General PAM failure */
85 #define PAM_TRY_AGAIN 27 /* Unable to update password */
86 /* Try again another time */
87 #define PAM_TOTAL_ERRNUM 28
90 * structure pam_message is used to pass prompt, error message,
91 * or any text information from scheme to application/user.
94 struct pam_message {
95 int msg_style; /* Msg_style - see below */
96 char *msg; /* Message string */
100 * msg_style defines the interaction style between the
101 * scheme and the application.
103 #define PAM_PROMPT_ECHO_OFF 1 /* Echo off when getting response */
104 #define PAM_PROMPT_ECHO_ON 2 /* Echo on when getting response */
105 #define PAM_ERROR_MSG 3 /* Error message */
106 #define PAM_TEXT_INFO 4 /* Textual information */
109 * max # of messages passed to the application through the
110 * conversation function call
112 #define PAM_MAX_NUM_MSG 32
115 * max size (in chars) of each messages passed to the application
116 * through the conversation function call
118 #define PAM_MAX_MSG_SIZE 512
121 * max size (in chars) of each response passed from the application
122 * through the conversation function call
124 #define PAM_MAX_RESP_SIZE 512
127 * structure pam_response is used by the scheme to get the user's
128 * response back from the application/user.
131 struct pam_response {
132 char *resp; /* Response string */
133 int resp_retcode; /* Return code - for future use */
137 * structure pam_conv is used by authentication applications for passing
138 * call back function pointers and application data pointers to the scheme
140 struct pam_conv {
141 int (*conv)(int, struct pam_message **,
142 struct pam_response **, void *);
143 void *appdata_ptr; /* Application data ptr */
146 /* the pam handle */
147 typedef struct pam_handle pam_handle_t;
150 * pam_start() is called to initiate an authentication exchange
151 * with PAM.
153 extern int
154 pam_start(
155 const char *service_name, /* Service Name */
156 const char *user, /* User Name */
157 const struct pam_conv *pam_conv, /* Conversation structure */
158 pam_handle_t **pamh /* Address to store handle */
162 * pam_end() is called to end an authentication exchange with PAM.
164 extern int
165 pam_end(
166 pam_handle_t *pamh, /* handle from pam_start() */
167 int status /* the final status value that */
168 /* gets passed to cleanup functions */
172 * pam_set_item is called to store an object in PAM handle.
174 extern int
175 pam_set_item(
176 pam_handle_t *pamh, /* PAM handle */
177 int item_type, /* Type of object - see below */
178 const void *item /* Address of place to put pointer */
179 /* to object */
183 * pam_get_item is called to retrieve an object from the static data area
185 extern int
186 pam_get_item(
187 const pam_handle_t *pamh, /* PAM handle */
188 int item_type, /* Type of object - see below */
189 void ** item /* Address of place to put pointer */
190 /* to object */
193 /* Items supported by pam_[sg]et_item() calls */
194 #define PAM_SERVICE 1 /* The program/service name */
195 #define PAM_USER 2 /* The user name */
196 #define PAM_TTY 3 /* The tty name */
197 #define PAM_RHOST 4 /* The remote host name */
198 #define PAM_CONV 5 /* The conversation structure */
199 #define PAM_AUTHTOK 6 /* The authentication token */
200 #define PAM_OLDAUTHTOK 7 /* Old authentication token */
201 #define PAM_RUSER 8 /* The remote user name */
202 #define PAM_USER_PROMPT 9 /* The user prompt */
203 #define PAM_REPOSITORY 10 /* The repository to be updated */
204 #define PAM_RESOURCE 11 /* Resource management info */
205 #define PAM_AUSER 12 /* The authenticated user name */
207 /* pam repository structure */
209 struct pam_repository {
210 char *type; /* Repository type, e.g., files, nis, ldap */
211 void *scope; /* Optional scope information */
212 size_t scope_len; /* length of scope inforamtion */
215 typedef struct pam_repository pam_repository_t;
218 * pam_get_user is called to retrieve the user name (PAM_USER). If PAM_USER
219 * is not set then this call will prompt for the user name using the
220 * conversation function. This function should only be used by modules, not
221 * applications.
224 extern int
225 pam_get_user(
226 pam_handle_t *pamh, /* PAM handle */
227 char **user, /* User Name */
228 const char *prompt /* Prompt */
232 * PAM equivalent to strerror();
234 extern const char *
235 pam_strerror(
236 pam_handle_t *pamh, /* pam handle */
237 int errnum /* error number */
240 /* general flag for pam_* functions */
241 #define PAM_SILENT 0x80000000
244 * pam_authenticate is called to authenticate the current user.
246 extern int
247 pam_authenticate(
248 pam_handle_t *pamh,
249 int flags
253 * Flags for pam_authenticate
256 #define PAM_DISALLOW_NULL_AUTHTOK 0x1 /* The password must be non-null */
259 * pam_acct_mgmt is called to perform account management processing
261 extern int
262 pam_acct_mgmt(
263 pam_handle_t *pamh,
264 int flags
268 * pam_open_session is called to note the initiation of new session in the
269 * appropriate administrative data bases.
271 extern int
272 pam_open_session(
273 pam_handle_t *pamh,
274 int flags
278 * pam_close_session records the termination of a session.
280 extern int
281 pam_close_session(
282 pam_handle_t *pamh,
283 int flags
286 /* pam_setcred is called to set the credentials of the current user */
287 extern int
288 pam_setcred(
289 pam_handle_t *pamh,
290 int flags
293 /* flags for pam_setcred() */
294 #define PAM_ESTABLISH_CRED 0x1 /* set scheme specific user id */
295 #define PAM_DELETE_CRED 0x2 /* unset scheme specific user id */
296 #define PAM_REINITIALIZE_CRED 0x4 /* reinitialize user credentials */
297 /* (after a password has changed */
298 #define PAM_REFRESH_CRED 0x8 /* extend lifetime of credentials */
300 /* pam_chauthtok is called to change authentication token */
302 extern int
303 pam_chauthtok(
304 pam_handle_t *pamh,
305 int flags
309 * Be careful - there are flags defined for pam_sm_chauthtok() in
310 * pam_modules.h also:
311 * PAM_PRELIM_CHECK 0x1
312 * PAM_UPDATE_AUTHTOK 0x2
314 #define PAM_CHANGE_EXPIRED_AUTHTOK 0x4 /* update expired passwords only */
315 #define PAM_NO_AUTHTOK_CHECK 0x8 /* bypass password strength tests */
317 /* pam_putenv is called to add environment variables to the PAM handle */
319 extern int
320 pam_putenv(
321 pam_handle_t *pamh,
322 const char *name_value
325 /* pam_getenv is called to retrieve an env variable from the PAM handle */
327 extern char *
328 pam_getenv(
329 pam_handle_t *pamh,
330 const char *name
333 /* pam_getenvlist is called to retrieve all env variables from the PAM handle */
335 extern char **
336 pam_getenvlist(
337 pam_handle_t *pamh
340 #ifdef __cplusplus
342 #endif
344 #endif /* _PAM_APPL_H */