xref: /onnv-gate/usr/src/lib/libpam/pam_appl.h (revision 10702:ca0edf2daf1c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52815Sgww  * Common Development and Distribution License (the "License").
62815Sgww  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10702SDarren.Moffat@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _PAM_APPL_H
270Sstevel@tonic-gate #define	_PAM_APPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /* Generic PAM errors */
360Sstevel@tonic-gate #define	PAM_SUCCESS		0	/* Normal function return */
370Sstevel@tonic-gate #define	PAM_OPEN_ERR		1	/* Dlopen failure */
380Sstevel@tonic-gate #define	PAM_SYMBOL_ERR		2	/* Symbol not found */
390Sstevel@tonic-gate #define	PAM_SERVICE_ERR		3	/* Error in underlying service module */
400Sstevel@tonic-gate #define	PAM_SYSTEM_ERR		4	/* System error */
410Sstevel@tonic-gate #define	PAM_BUF_ERR		5	/* Memory buffer error */
420Sstevel@tonic-gate #define	PAM_CONV_ERR		6	/* Conversation failure */
430Sstevel@tonic-gate #define	PAM_PERM_DENIED		7	/* Permission denied */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /* Errors returned by pam_authenticate, pam_acct_mgmt(), and pam_setcred() */
460Sstevel@tonic-gate #define	PAM_MAXTRIES		8	/* Maximum number of tries exceeded */
470Sstevel@tonic-gate #define	PAM_AUTH_ERR		9	/* Authentication failure */
480Sstevel@tonic-gate #define	PAM_NEW_AUTHTOK_REQD	10	/* Get new auth token from the user */
490Sstevel@tonic-gate #define	PAM_CRED_INSUFFICIENT	11	/* can not access auth data b/c */
500Sstevel@tonic-gate 					/* of insufficient credentials  */
510Sstevel@tonic-gate #define	PAM_AUTHINFO_UNAVAIL	12	/* Can not retrieve auth information */
520Sstevel@tonic-gate #define	PAM_USER_UNKNOWN	13	/* No account present for user */
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /* Errors returned by pam_setcred() */
550Sstevel@tonic-gate #define	PAM_CRED_UNAVAIL	14	/* can not retrieve user credentials */
560Sstevel@tonic-gate #define	PAM_CRED_EXPIRED	15	/* user credentials expired */
570Sstevel@tonic-gate #define	PAM_CRED_ERR		16	/* failure setting user credentials */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* Errors returned by pam_acct_mgmt() */
600Sstevel@tonic-gate #define	PAM_ACCT_EXPIRED	17	/* user account has expired */
610Sstevel@tonic-gate #define	PAM_AUTHTOK_EXPIRED 	18	/* Password expired and no longer */
620Sstevel@tonic-gate 					/* usable */
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /* Errors returned by pam_open/close_session() */
650Sstevel@tonic-gate #define	PAM_SESSION_ERR		19	/* can not make/remove entry for */
660Sstevel@tonic-gate 					/* specified session */
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* Errors returned by pam_chauthtok() */
690Sstevel@tonic-gate #define	PAM_AUTHTOK_ERR		  20	/* Authentication token */
700Sstevel@tonic-gate 					/*   manipulation error */
710Sstevel@tonic-gate #define	PAM_AUTHTOK_RECOVERY_ERR  21	/* Old authentication token */
720Sstevel@tonic-gate 					/*   cannot be recovered */
730Sstevel@tonic-gate #define	PAM_AUTHTOK_LOCK_BUSY	  22	/* Authentication token */
740Sstevel@tonic-gate 					/*   lock busy */
750Sstevel@tonic-gate #define	PAM_AUTHTOK_DISABLE_AGING 23	/* Authentication token aging */
760Sstevel@tonic-gate 					/*   is disabled */
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /* Errors returned by pam_get_data */
790Sstevel@tonic-gate #define	PAM_NO_MODULE_DATA	24	/* module data not found */
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /* Errors returned by modules */
820Sstevel@tonic-gate #define	PAM_IGNORE		25	/* ignore module */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #define	PAM_ABORT		26	/* General PAM failure */
850Sstevel@tonic-gate #define	PAM_TRY_AGAIN		27	/* Unable to update password */
860Sstevel@tonic-gate 					/* Try again another time */
870Sstevel@tonic-gate #define	PAM_TOTAL_ERRNUM	28
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * structure pam_message is used to pass prompt, error message,
910Sstevel@tonic-gate  * or any text information from scheme to application/user.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate struct pam_message {
950Sstevel@tonic-gate 	int msg_style;		/* Msg_style - see below */
960Sstevel@tonic-gate 	char *msg; 		/* Message string */
970Sstevel@tonic-gate };
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * msg_style defines the interaction style between the
1010Sstevel@tonic-gate  * scheme and the application.
1020Sstevel@tonic-gate  */
1030Sstevel@tonic-gate #define	PAM_PROMPT_ECHO_OFF	1	/* Echo off when getting response */
1040Sstevel@tonic-gate #define	PAM_PROMPT_ECHO_ON	2 	/* Echo on when getting response */
1050Sstevel@tonic-gate #define	PAM_ERROR_MSG		3	/* Error message */
1060Sstevel@tonic-gate #define	PAM_TEXT_INFO		4	/* Textual information */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * max # of messages passed to the application through the
1100Sstevel@tonic-gate  * conversation function call
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate #define	PAM_MAX_NUM_MSG	32
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate  * max size (in chars) of each messages passed to the application
1160Sstevel@tonic-gate  * through the conversation function call
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate #define	PAM_MAX_MSG_SIZE	512
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate /*
1210Sstevel@tonic-gate  * max size (in chars) of each response passed from the application
1220Sstevel@tonic-gate  * through the conversation function call
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate #define	PAM_MAX_RESP_SIZE	512
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * structure pam_response is used by the scheme to get the user's
1280Sstevel@tonic-gate  * response back from the application/user.
1290Sstevel@tonic-gate  */
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate struct pam_response {
1320Sstevel@tonic-gate 	char *resp;		/* Response string */
1330Sstevel@tonic-gate 	int resp_retcode;	/* Return code - for future use */
1340Sstevel@tonic-gate };
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /*
1370Sstevel@tonic-gate  * structure pam_conv is used by authentication applications for passing
1380Sstevel@tonic-gate  * call back function pointers and application data pointers to the scheme
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate struct pam_conv {
1410Sstevel@tonic-gate 	int (*conv)(int, struct pam_message **,
1420Sstevel@tonic-gate 	    struct pam_response **, void *);
1430Sstevel@tonic-gate 	void *appdata_ptr;		/* Application data ptr */
1440Sstevel@tonic-gate };
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /* the pam handle */
1470Sstevel@tonic-gate typedef struct pam_handle pam_handle_t;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * pam_start() is called to initiate an authentication exchange
1510Sstevel@tonic-gate  * with PAM.
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate extern int
1540Sstevel@tonic-gate pam_start(
1550Sstevel@tonic-gate 	const char *service_name,		/* Service Name */
1560Sstevel@tonic-gate 	const char *user,			/* User Name */
1570Sstevel@tonic-gate 	const struct pam_conv *pam_conv,	/* Conversation structure */
1580Sstevel@tonic-gate 	pam_handle_t **pamh		/* Address to store handle */
1590Sstevel@tonic-gate );
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /*
1620Sstevel@tonic-gate  * pam_end() is called to end an authentication exchange with PAM.
1630Sstevel@tonic-gate  */
1640Sstevel@tonic-gate extern int
1650Sstevel@tonic-gate pam_end(
1660Sstevel@tonic-gate 	pam_handle_t *pamh,		/* handle from pam_start() */
1670Sstevel@tonic-gate 	int status			/* the final status value that */
1680Sstevel@tonic-gate 					/* gets passed to cleanup functions */
1690Sstevel@tonic-gate );
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * pam_set_item is called to store an object in PAM handle.
1730Sstevel@tonic-gate  */
1740Sstevel@tonic-gate extern int
1750Sstevel@tonic-gate pam_set_item(
1760Sstevel@tonic-gate 	pam_handle_t *pamh,		/* PAM handle */
1770Sstevel@tonic-gate 	int item_type, 			/* Type of object - see below */
1780Sstevel@tonic-gate 	const void *item		/* Address of place to put pointer */
1790Sstevel@tonic-gate 					/*   to object */
1800Sstevel@tonic-gate );
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate  * pam_get_item is called to retrieve an object from the static data area
1840Sstevel@tonic-gate  */
1850Sstevel@tonic-gate extern int
1860Sstevel@tonic-gate pam_get_item(
1870Sstevel@tonic-gate 	const pam_handle_t *pamh, 	/* PAM handle */
1880Sstevel@tonic-gate 	int item_type, 			/* Type of object - see below */
1890Sstevel@tonic-gate 	void **	item			/* Address of place to put pointer */
1900Sstevel@tonic-gate 					/*   to object */
1910Sstevel@tonic-gate );
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate /* Items supported by pam_[sg]et_item() calls */
1940Sstevel@tonic-gate #define	PAM_SERVICE	1		/* The program/service name */
1950Sstevel@tonic-gate #define	PAM_USER	2		/* The user name */
1960Sstevel@tonic-gate #define	PAM_TTY		3		/* The tty name */
1970Sstevel@tonic-gate #define	PAM_RHOST	4		/* The remote host name */
1980Sstevel@tonic-gate #define	PAM_CONV	5		/* The conversation structure */
1990Sstevel@tonic-gate #define	PAM_AUTHTOK	6		/* The authentication token */
2000Sstevel@tonic-gate #define	PAM_OLDAUTHTOK	7		/* Old authentication token */
2010Sstevel@tonic-gate #define	PAM_RUSER	8		/* The remote user name */
2020Sstevel@tonic-gate #define	PAM_USER_PROMPT	9		/* The user prompt */
2030Sstevel@tonic-gate #define	PAM_REPOSITORY	10		/* The repository to be updated */
2040Sstevel@tonic-gate #define	PAM_RESOURCE	11		/* Resource management info */
2052815Sgww #define	PAM_AUSER	12		/* The authenticated user name */
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate /* pam repository structure */
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate struct pam_repository {
2100Sstevel@tonic-gate 	char   *type;		/* Repository type, e.g., files, nis, ldap */
2110Sstevel@tonic-gate 	void   *scope;		/* Optional scope information */
2120Sstevel@tonic-gate 	size_t  scope_len;	/* length of scope inforamtion */
2130Sstevel@tonic-gate };
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate typedef struct pam_repository pam_repository_t;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate /*
2180Sstevel@tonic-gate  * pam_get_user is called to retrieve the user name (PAM_USER). If PAM_USER
2190Sstevel@tonic-gate  * is not set then this call will prompt for the user name using the
2200Sstevel@tonic-gate  * conversation function. This function should only be used by modules, not
2210Sstevel@tonic-gate  * applications.
2220Sstevel@tonic-gate  */
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate extern int
2250Sstevel@tonic-gate pam_get_user(
2260Sstevel@tonic-gate 	pam_handle_t *pamh,		/* PAM handle */
2270Sstevel@tonic-gate 	char **user, 			/* User Name */
2280Sstevel@tonic-gate 	const char *prompt		/* Prompt */
2290Sstevel@tonic-gate );
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate  * PAM equivalent to strerror();
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate extern const char *
2350Sstevel@tonic-gate pam_strerror(
2360Sstevel@tonic-gate 	pam_handle_t *pamh,	/* pam handle */
2370Sstevel@tonic-gate 	int errnum		/* error number */
2380Sstevel@tonic-gate );
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /* general flag for pam_* functions */
2410Sstevel@tonic-gate #define	PAM_SILENT	0x80000000
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate  * pam_authenticate is called to authenticate the current user.
2450Sstevel@tonic-gate  */
2460Sstevel@tonic-gate extern int
2470Sstevel@tonic-gate pam_authenticate(
2480Sstevel@tonic-gate 	pam_handle_t *pamh,
2490Sstevel@tonic-gate 	int flags
2500Sstevel@tonic-gate );
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /*
2530Sstevel@tonic-gate  * Flags for pam_authenticate
2540Sstevel@tonic-gate  */
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate #define	PAM_DISALLOW_NULL_AUTHTOK 0x1	/* The password must be non-null */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * pam_acct_mgmt is called to perform account management processing
2600Sstevel@tonic-gate  */
2610Sstevel@tonic-gate extern int
2620Sstevel@tonic-gate pam_acct_mgmt(
2630Sstevel@tonic-gate 	pam_handle_t *pamh,
2640Sstevel@tonic-gate 	int flags
2650Sstevel@tonic-gate );
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate  * pam_open_session is called to note the initiation of new session in the
2690Sstevel@tonic-gate  * appropriate administrative data bases.
2700Sstevel@tonic-gate  */
2710Sstevel@tonic-gate extern int
2720Sstevel@tonic-gate pam_open_session(
2730Sstevel@tonic-gate 	pam_handle_t *pamh,
2740Sstevel@tonic-gate 	int flags
2750Sstevel@tonic-gate );
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate  * pam_close_session records the termination of a session.
2790Sstevel@tonic-gate  */
2800Sstevel@tonic-gate extern int
2810Sstevel@tonic-gate pam_close_session(
2820Sstevel@tonic-gate 	pam_handle_t	*pamh,
2830Sstevel@tonic-gate 	int		flags
2840Sstevel@tonic-gate );
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate /* pam_setcred is called to set the credentials of the current user */
2870Sstevel@tonic-gate extern int
2880Sstevel@tonic-gate pam_setcred(
2890Sstevel@tonic-gate 	pam_handle_t *pamh,
2900Sstevel@tonic-gate 	int flags
2910Sstevel@tonic-gate );
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate /* flags for pam_setcred() */
2940Sstevel@tonic-gate #define	PAM_ESTABLISH_CRED	0x1	/* set scheme specific user id */
2950Sstevel@tonic-gate #define	PAM_DELETE_CRED		0x2	/* unset scheme specific user id */
2960Sstevel@tonic-gate #define	PAM_REINITIALIZE_CRED	0x4	/* reinitialize user credentials */
2970Sstevel@tonic-gate 					/* (after a password has changed */
2980Sstevel@tonic-gate #define	PAM_REFRESH_CRED	0x8	/* extend lifetime of credentials */
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate /* pam_chauthtok is called to change authentication token */
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate extern int
3030Sstevel@tonic-gate pam_chauthtok(
3040Sstevel@tonic-gate 	pam_handle_t	*pamh,
3050Sstevel@tonic-gate 	int		flags
3060Sstevel@tonic-gate );
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate /*
3090Sstevel@tonic-gate  * Be careful - there are flags defined for pam_sm_chauthtok() in
3100Sstevel@tonic-gate  * pam_modules.h also:
3110Sstevel@tonic-gate  * PAM_PRELIM_CHECK	0x1
3120Sstevel@tonic-gate  * PAM_UPDATE_AUTHTOK	0x2
3130Sstevel@tonic-gate  */
3140Sstevel@tonic-gate #define	PAM_CHANGE_EXPIRED_AUTHTOK	0x4 /* update expired passwords only */
3150Sstevel@tonic-gate #define	PAM_NO_AUTHTOK_CHECK		0x8 /* bypass password strength tests */
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate /* pam_putenv is called to add environment variables to the PAM handle */
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate extern int
3200Sstevel@tonic-gate pam_putenv(
3210Sstevel@tonic-gate 	pam_handle_t	*pamh,
3220Sstevel@tonic-gate 	const char	*name_value
3230Sstevel@tonic-gate );
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate /* pam_getenv is called to retrieve an env variable from the PAM handle */
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate extern char *
3280Sstevel@tonic-gate pam_getenv(
3290Sstevel@tonic-gate 	pam_handle_t	*pamh,
3300Sstevel@tonic-gate 	const char	*name
3310Sstevel@tonic-gate );
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate /* pam_getenvlist is called to retrieve all env variables from the PAM handle */
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate extern char **
3360Sstevel@tonic-gate pam_getenvlist(
3370Sstevel@tonic-gate 	pam_handle_t	*pamh
3380Sstevel@tonic-gate );
3390Sstevel@tonic-gate 
3400Sstevel@tonic-gate #ifdef	__cplusplus
3410Sstevel@tonic-gate }
3420Sstevel@tonic-gate #endif
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate #endif /* _PAM_APPL_H */
345