xref: /onnv-gate/usr/src/cmd/ssh/include/auth.h (revision 11251:ff36d9f84a57)
10Sstevel@tonic-gate /*	$OpenBSD: auth.h,v 1.41 2002/09/26 11:38:43 markus Exp $	*/
20Sstevel@tonic-gate 
30Sstevel@tonic-gate #ifndef	_AUTH_H
40Sstevel@tonic-gate #define	_AUTH_H
50Sstevel@tonic-gate 
60Sstevel@tonic-gate #ifdef __cplusplus
70Sstevel@tonic-gate extern "C" {
80Sstevel@tonic-gate #endif
90Sstevel@tonic-gate 
100Sstevel@tonic-gate 
110Sstevel@tonic-gate /*
120Sstevel@tonic-gate  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
150Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
160Sstevel@tonic-gate  * are met:
170Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
180Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
190Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
200Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
210Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
220Sstevel@tonic-gate  *
230Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
240Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
250Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
260Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
270Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
280Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
290Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
300Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
310Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
320Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate /*
36*11251SErik.Trauschke@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
370Sstevel@tonic-gate  * Use is subject to license terms.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include "key.h"
410Sstevel@tonic-gate #include "hostfile.h"
420Sstevel@tonic-gate #include <openssl/rsa.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #ifdef USE_PAM
450Sstevel@tonic-gate #include <security/pam_appl.h>
460Sstevel@tonic-gate #endif /* USE_PAM */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifdef HAVE_LOGIN_CAP
490Sstevel@tonic-gate #include <login_cap.h>
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate #ifdef BSD_AUTH
520Sstevel@tonic-gate #include <bsd_auth.h>
530Sstevel@tonic-gate #endif
540Sstevel@tonic-gate #ifdef KRB5
550Sstevel@tonic-gate #include <krb5.h>
560Sstevel@tonic-gate #endif
570Sstevel@tonic-gate 
580Sstevel@tonic-gate typedef struct Authctxt Authctxt;
590Sstevel@tonic-gate typedef struct Authmethod Authmethod;
600Sstevel@tonic-gate typedef struct KbdintDevice KbdintDevice;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #ifdef USE_PAM
630Sstevel@tonic-gate typedef struct pam_stuff pam_stuff;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate struct pam_stuff {
660Sstevel@tonic-gate 	Authctxt	*authctxt;
670Sstevel@tonic-gate 	pam_handle_t	*h;
680Sstevel@tonic-gate 	int		state;
690Sstevel@tonic-gate 	int		last_pam_retval;
700Sstevel@tonic-gate };
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /* See auth-pam.h and auth-pam.c */
730Sstevel@tonic-gate 
740Sstevel@tonic-gate #define PAM_S_DONE_ACCT_MGMT		0x01 /* acct_mgmt done */
750Sstevel@tonic-gate #define PAM_S_DONE_SETCRED		0x02 /* setcred done */
760Sstevel@tonic-gate #define PAM_S_DONE_OPEN_SESSION		0x04 /* open_session done */
770Sstevel@tonic-gate #define PAM_S_DONE			0x07 /* all done */
780Sstevel@tonic-gate #endif /* USE_PAM */
790Sstevel@tonic-gate 
800Sstevel@tonic-gate struct Authctxt {
810Sstevel@tonic-gate 	int		 success;
820Sstevel@tonic-gate 	int		 valid;
830Sstevel@tonic-gate 	int		 attempt;	/* all userauth attempt count */
840Sstevel@tonic-gate 	int		 init_attempt;	/* passwd/kbd-int attempt count */
850Sstevel@tonic-gate 	int		 failures;
860Sstevel@tonic-gate 	int		 init_failures;
870Sstevel@tonic-gate 	int		 unwind_dispatch_loop;
880Sstevel@tonic-gate 	int		 v1_auth_type;
890Sstevel@tonic-gate 	char		*v1_auth_name;
900Sstevel@tonic-gate 	Authmethod	*method;
910Sstevel@tonic-gate 	char		*user;
920Sstevel@tonic-gate 	char		*service;
930Sstevel@tonic-gate 	struct passwd	*pw;
940Sstevel@tonic-gate 	char		*style;
950Sstevel@tonic-gate 	void		*kbdintctxt;	/* XXX Switch to method_data;
960Sstevel@tonic-gate 					   v1 still needs this*/
970Sstevel@tonic-gate #ifdef USE_PAM
980Sstevel@tonic-gate 	pam_stuff	*pam;
993908Sjp161948 	char		*cuser; /* client side user, needed for setting
1003908Sjp161948 				   PAM_AUSER for hostbased authentication
1013908Sjp161948 				   using roles */
1020Sstevel@tonic-gate 	u_long		 last_login_time; /* need to get the time of
1030Sstevel@tonic-gate 					     last login before calling
1040Sstevel@tonic-gate 					     pam_open_session() */
1050Sstevel@tonic-gate 	char		 last_login_host[MAXHOSTNAMELEN];
1060Sstevel@tonic-gate 	int		 pam_retval;	/* pam_stuff is cleaned before
1070Sstevel@tonic-gate 					   BSM login failure auditing */
1080Sstevel@tonic-gate #endif /* USE_PAM */
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	/* SUNW - What follows remains to reduce diffs with OpenSSH but
1110Sstevel@tonic-gate 	 *	  is not used in Solaris.  The Solaris SSH internal
1120Sstevel@tonic-gate 	 *	  architecture requires that this stuff move into the
1130Sstevel@tonic-gate 	 *	  Authmethod method_data.
1140Sstevel@tonic-gate 	 */
1150Sstevel@tonic-gate #ifndef	SUNW_SSH
1160Sstevel@tonic-gate #ifdef BSD_AUTH
1170Sstevel@tonic-gate 	auth_session_t	*as;
1180Sstevel@tonic-gate #endif
1190Sstevel@tonic-gate #ifdef KRB4
1200Sstevel@tonic-gate 	char		*krb4_ticket_file;
1210Sstevel@tonic-gate #endif
1220Sstevel@tonic-gate #ifdef KRB5
1230Sstevel@tonic-gate 	krb5_context	 krb5_ctx;
1240Sstevel@tonic-gate 	krb5_auth_context krb5_auth_ctx;
1250Sstevel@tonic-gate 	krb5_ccache	 krb5_fwd_ccache;
1260Sstevel@tonic-gate 	krb5_principal	 krb5_user;
1270Sstevel@tonic-gate 	char		*krb5_ticket_file;
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate 	void *methoddata;
1300Sstevel@tonic-gate #endif /* SUNW_SSH */
1310Sstevel@tonic-gate };
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate struct Authmethod {
1340Sstevel@tonic-gate 	char	*name;
1350Sstevel@tonic-gate 	int	*enabled;
1360Sstevel@tonic-gate 	/*
1370Sstevel@tonic-gate 	 * Userauth method state tracking fields updated in
1380Sstevel@tonic-gate 	 * input_userauth_request() and auth-pam.c.
1390Sstevel@tonic-gate 	 *
1400Sstevel@tonic-gate 	 * The "void (*userauth)(Authctxt *authctxt)" function
1410Sstevel@tonic-gate 	 * communicates the userauth result (success, failure,
1420Sstevel@tonic-gate 	 * "postponed," abandoned) through the 'authenticated',
1430Sstevel@tonic-gate 	 * 'postponed' and 'abandoned' fields.  Partial success is
1440Sstevel@tonic-gate 	 * indicated by requiring other userauths to be used by setting
1450Sstevel@tonic-gate 	 * their 'required' or 'sufficient' fields.
1460Sstevel@tonic-gate 	 *
1470Sstevel@tonic-gate 	 * Individual methods should only ever set 'not_again' if it
1480Sstevel@tonic-gate 	 * makes no sense to complete the same userauth more than once,
1490Sstevel@tonic-gate 	 * and they should set any methods' sufficient or required flags
1500Sstevel@tonic-gate 	 * in order to force partial authentication and require that
1510Sstevel@tonic-gate 	 * more userauths be tried.  The (void *) 'method_data' and
1520Sstevel@tonic-gate 	 * 'hist_method_data' pointers can be used by methods such as
1530Sstevel@tonic-gate 	 * pubkey which may make sense to run more than once during
1540Sstevel@tonic-gate 	 * userauth or which may require multiple round tripes (e.g.,
1550Sstevel@tonic-gate 	 * keyboard-interactive) and which need to keep some state;
1560Sstevel@tonic-gate 	 * 'hist_method_data' is there specifically for pubkey userauth
1570Sstevel@tonic-gate 	 * where multiple successful attempts should all use different
1580Sstevel@tonic-gate 	 * keys.
1590Sstevel@tonic-gate 	 *
1600Sstevel@tonic-gate 	 * The "attempts," "abandons," "successes" and "failures" fields
1610Sstevel@tonic-gate 	 * count the number of times a method has been attempted,
1620Sstevel@tonic-gate 	 * abandoned, and has succeeded or failed.  Note that pubkey
1630Sstevel@tonic-gate 	 * userauth does not double-count sig-less probes that are
1640Sstevel@tonic-gate 	 * followed by a pubkey request for the same pubkey anw with a
1650Sstevel@tonic-gate 	 * signature.
1660Sstevel@tonic-gate 	 */
1670Sstevel@tonic-gate 	void		(*userauth)(Authctxt *authctxt);
1680Sstevel@tonic-gate 	void		(*abandon)(Authctxt *, Authmethod *);
1690Sstevel@tonic-gate 	void		*method_data;
1700Sstevel@tonic-gate 	void		*hist_method_data;
1710Sstevel@tonic-gate 	unsigned int	 is_initial;
1720Sstevel@tonic-gate 	unsigned int	 attempts:8;
1730Sstevel@tonic-gate 	unsigned int	 abandons:8;
1740Sstevel@tonic-gate 	unsigned int	 successes:8;
1750Sstevel@tonic-gate 	unsigned int	 failures:8;
1760Sstevel@tonic-gate 	/*
1770Sstevel@tonic-gate 	 * Post-attempt state booleans (authenticated, abandoned, etc...)
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate 	unsigned int	 authenticated:1;
1800Sstevel@tonic-gate 	unsigned int	 not_again:1;
1810Sstevel@tonic-gate 	unsigned int	 sufficient:1;
1820Sstevel@tonic-gate 	unsigned int	 required:1;
1830Sstevel@tonic-gate 	unsigned int	 postponed:1;
1840Sstevel@tonic-gate 	unsigned int	 abandoned:1;
1850Sstevel@tonic-gate 	/*
1860Sstevel@tonic-gate 	 * NOTE: multi-round-trip userauth methods can either
1870Sstevel@tonic-gate 	 *       recursively call dispatch_run and detect abandonment
1880Sstevel@tonic-gate 	 *       within their message handlers (as PAM kbd-int does) or
1890Sstevel@tonic-gate 	 *       set the postponed flag and let input_userauth_request()
1900Sstevel@tonic-gate 	 *       detect abandonment (i.e., initiation of some userauth
1910Sstevel@tonic-gate 	 *       method before completion of a started, multi-round-trip
1920Sstevel@tonic-gate 	 *       userauth method).
1930Sstevel@tonic-gate 	 *
1940Sstevel@tonic-gate 	 */
1950Sstevel@tonic-gate };
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate  * Keyboard interactive device:
1990Sstevel@tonic-gate  * init_ctx	returns: non NULL upon success
2000Sstevel@tonic-gate  * query	returns: 0 - success, otherwise failure
2010Sstevel@tonic-gate  * respond	returns: 0 - success, 1 - need further interaction,
2020Sstevel@tonic-gate  *		otherwise - failure
2030Sstevel@tonic-gate  */
2040Sstevel@tonic-gate struct KbdintDevice
2050Sstevel@tonic-gate {
2060Sstevel@tonic-gate 	const char *name;
2070Sstevel@tonic-gate 	void*	(*init_ctx)(Authctxt*);
2080Sstevel@tonic-gate 	int	(*query)(void *ctx, char **name, char **infotxt,
2090Sstevel@tonic-gate 		    u_int *numprompts, char ***prompts, u_int **echo_on);
2100Sstevel@tonic-gate 	int	(*respond)(void *ctx, u_int numresp, char **responses);
2110Sstevel@tonic-gate 	void	(*free_ctx)(void *ctx);
2120Sstevel@tonic-gate };
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate int      auth_rhosts(struct passwd *, const char *);
2150Sstevel@tonic-gate int
2160Sstevel@tonic-gate auth_rhosts2(struct passwd *, const char *, const char *, const char *);
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate int	 auth_rhosts_rsa(struct passwd *, char *, Key *);
2190Sstevel@tonic-gate int      auth_password(Authctxt *, const char *);
2200Sstevel@tonic-gate int      auth_rsa(struct passwd *, BIGNUM *);
2210Sstevel@tonic-gate int      auth_rsa_challenge_dialog(Key *);
2220Sstevel@tonic-gate BIGNUM	*auth_rsa_generate_challenge(Key *);
2230Sstevel@tonic-gate int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
2240Sstevel@tonic-gate int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate int	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
2270Sstevel@tonic-gate int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
2280Sstevel@tonic-gate int	 user_key_allowed(struct passwd *, Key *);
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate #ifdef KRB4
2310Sstevel@tonic-gate #include <krb.h>
2320Sstevel@tonic-gate int     auth_krb4(Authctxt *, KTEXT, char **, KTEXT);
2330Sstevel@tonic-gate int	auth_krb4_password(Authctxt *, const char *);
2340Sstevel@tonic-gate void    krb4_cleanup_proc(void *);
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate #ifdef AFS
2370Sstevel@tonic-gate #include <kafs.h>
2380Sstevel@tonic-gate int     auth_krb4_tgt(Authctxt *, const char *);
2390Sstevel@tonic-gate int     auth_afs_token(Authctxt *, const char *);
2400Sstevel@tonic-gate #endif /* AFS */
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate #endif /* KRB4 */
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate #ifdef KRB5
2450Sstevel@tonic-gate int	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
2460Sstevel@tonic-gate int	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
2470Sstevel@tonic-gate int	auth_krb5_password(Authctxt *authctxt, const char *password);
2480Sstevel@tonic-gate void	krb5_cleanup_proc(void *authctxt);
2490Sstevel@tonic-gate #endif /* KRB5 */
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate #include "auth-pam.h"
2520Sstevel@tonic-gate #include "auth2-pam.h"
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate Authctxt *do_authentication(void);
2550Sstevel@tonic-gate Authctxt *do_authentication2(void);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate #ifdef HAVE_BSM
2580Sstevel@tonic-gate void	audit_failed_login_cleanup(void *);
2590Sstevel@tonic-gate #endif /* HAVE_BSM */
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate int	userauth_check_partial_failure(Authctxt *authctxt);
2620Sstevel@tonic-gate void	userauth_force_kbdint(void);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate Authctxt *authctxt_new(void);
2650Sstevel@tonic-gate void	auth_log(Authctxt *, int, char *, char *);
2660Sstevel@tonic-gate void	userauth_finish(Authctxt *, char *);
2670Sstevel@tonic-gate void	userauth_user_svc_change(Authctxt *authctxt,
2680Sstevel@tonic-gate 				 char *user,
2690Sstevel@tonic-gate 				 char *service);
2700Sstevel@tonic-gate int	auth_root_allowed(char *);
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate char	*auth2_read_banner(void);
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate void	privsep_challenge_enable(void);
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate void	auth2_challenge(Authctxt *, char *);
2770Sstevel@tonic-gate void	auth2_challenge_abandon(Authctxt *);
2780Sstevel@tonic-gate int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
2790Sstevel@tonic-gate int	bsdauth_respond(void *, u_int, char **);
2800Sstevel@tonic-gate int	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
2810Sstevel@tonic-gate int	skey_respond(void *, u_int, char **);
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate struct passwd * getpwnamallow(const char *user);
2840Sstevel@tonic-gate 
285*11251SErik.Trauschke@Sun.COM int	run_auth_hook(const char *, const char *, const char *);
286*11251SErik.Trauschke@Sun.COM 
2870Sstevel@tonic-gate char	*get_challenge(Authctxt *);
2880Sstevel@tonic-gate int	verify_response(Authctxt *, const char *);
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate struct passwd * auth_get_user(void);
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate char	*authorized_keys_file(struct passwd *);
2930Sstevel@tonic-gate char	*authorized_keys_file2(struct passwd *);
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate int
2960Sstevel@tonic-gate secure_filename(FILE *, const char *, struct passwd *, char *, size_t);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate HostStatus
2990Sstevel@tonic-gate check_key_in_hostfiles(struct passwd *, Key *, const char *,
3000Sstevel@tonic-gate     const char *, const char *);
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate /* hostkey handling */
3030Sstevel@tonic-gate #ifndef lint
3040Sstevel@tonic-gate Key	*get_hostkey_by_index(int);
3050Sstevel@tonic-gate Key	*get_hostkey_by_type(int);
3060Sstevel@tonic-gate int	 get_hostkey_index(Key *);
3070Sstevel@tonic-gate #endif /* lint */
3080Sstevel@tonic-gate int	 ssh1_session_key(BIGNUM *);
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate /* debug messages during authentication */
3110Sstevel@tonic-gate void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
3120Sstevel@tonic-gate void	 auth_debug_send(void);
3130Sstevel@tonic-gate void	 auth_debug_reset(void);
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate #define AUTH_FAIL_MAX 6
3160Sstevel@tonic-gate #define AUTH_FAIL_LOG (AUTH_FAIL_MAX/2)
3170Sstevel@tonic-gate #define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate #define SKEY_PROMPT "\nS/Key Password: "
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate #ifdef __cplusplus
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate #endif
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate #endif /* _AUTH_H */
326