xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth.h (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: auth.h,v 1.6 2013/03/29 16:19:44 christos Exp $	*/
2 /* $OpenBSD: auth.h,v 1.72 2012/12/02 20:34:09 djm Exp $ */
3 
4 /*
5  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef AUTH_H
30 #define AUTH_H
31 
32 #include <signal.h>
33 
34 #include <openssl/rsa.h>
35 
36 #ifdef HAVE_LOGIN_CAP
37 #include <login_cap.h>
38 #endif
39 #ifdef BSD_AUTH
40 #include <bsd_auth.h>
41 #endif
42 #ifdef KRB5
43 #include <krb5.h>
44 #endif
45 
46 typedef struct Authctxt Authctxt;
47 typedef struct Authmethod Authmethod;
48 typedef struct KbdintDevice KbdintDevice;
49 
50 struct Authctxt {
51 	sig_atomic_t	 success;
52 	int		 authenticated;	/* authenticated and alarms cancelled */
53 	int		 postponed;	/* authentication needs another step */
54 	int		 valid;		/* user exists and is allowed to login */
55 	int		 attempt;
56 	int		 failures;
57 	int		 server_caused_failure;
58 	int		 force_pwchange;
59 	char		*user;		/* username sent by the client */
60 	char		*service;
61 	struct passwd	*pw;		/* set if 'valid' */
62 	char		*style;
63 	void		*kbdintctxt;
64 	void		*jpake_ctx;
65 #ifdef BSD_AUTH
66 	auth_session_t	*as;
67 #endif
68 #ifdef KRB4
69 	char		*krb4_ticket_file;
70 #endif
71 	char		**auth_methods;	/* modified from server config */
72 	u_int		 num_auth_methods;
73 #ifdef KRB5
74 	krb5_context	 krb5_ctx;
75 	krb5_auth_context krb5_auth_ctx;
76 	krb5_ccache	 krb5_fwd_ccache;
77 	krb5_principal	 krb5_user;
78 	char		*krb5_ticket_file;
79 #endif
80 	void		*methoddata;
81 };
82 /*
83  * Every authentication method has to handle authentication requests for
84  * non-existing users, or for users that are not allowed to login. In this
85  * case 'valid' is set to 0, but 'user' points to the username requested by
86  * the client.
87  */
88 
89 #ifdef USE_PAM
90 #include "auth-pam.h"
91 #endif
92 
93 struct Authmethod {
94 	const char	*name;
95 	int	(*userauth)(Authctxt *authctxt);
96 	int	*enabled;
97 };
98 
99 /*
100  * Keyboard interactive device:
101  * init_ctx	returns: non NULL upon success
102  * query	returns: 0 - success, otherwise failure
103  * respond	returns: 0 - success, 1 - need further interaction,
104  *		otherwise - failure
105  */
106 struct KbdintDevice
107 {
108 	const char *name;
109 	void*	(*init_ctx)(Authctxt*);
110 	int	(*query)(void *ctx, char **name, char **infotxt,
111 		    u_int *numprompts, char ***prompts, u_int **echo_on);
112 	int	(*respond)(void *ctx, u_int numresp, char **responses);
113 	void	(*free_ctx)(void *ctx);
114 };
115 
116 void 	 disable_forwarding(void);
117 int      auth_rhosts(struct passwd *, const char *);
118 int
119 auth_rhosts2(struct passwd *, const char *, const char *, const char *);
120 
121 int	 auth_rhosts_rsa(Authctxt *, char *, Key *);
122 int      auth_password(Authctxt *, const char *);
123 int      auth_rsa(Authctxt *, BIGNUM *);
124 int      auth_rsa_challenge_dialog(Key *);
125 BIGNUM	*auth_rsa_generate_challenge(Key *);
126 int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
127 int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
128 
129 int	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
130 int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
131 int	 user_key_allowed(struct passwd *, Key *);
132 
133 #ifdef KRB4
134 #include <krb.h>
135 int     auth_krb4(Authctxt *, KTEXT, char **, KTEXT);
136 int	auth_krb4_password(Authctxt *, const char *);
137 void    krb4_cleanup_proc(void *);
138 
139 #ifdef AFS
140 #include <kafs.h>
141 int     auth_krb4_tgt(Authctxt *, const char *);
142 int     auth_afs_token(Authctxt *, const char *);
143 #endif /* AFS */
144 
145 #endif /* KRB4 */
146 
147 struct stat;
148 int	 auth_secure_path(const char *, struct stat *, const char *, uid_t,
149     char *, size_t);
150 
151 #ifdef KRB5
152 int	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
153 int	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
154 int	auth_krb5_password(Authctxt *authctxt, const char *password);
155 void	krb5_cleanup_proc(Authctxt *authctxt);
156 #endif /* KRB5 */
157 
158 void	do_authentication(Authctxt *);
159 void	do_authentication2(Authctxt *);
160 
161 void	auth_log(Authctxt *, int, int, const char *, const char *,
162     const char *);
163 void	userauth_finish(Authctxt *, int, const char *, const char *);
164 int	auth_root_allowed(const char *);
165 
166 char	*auth2_read_banner(void);
167 int	 auth2_methods_valid(const char *, int);
168 int	 auth2_update_methods_lists(Authctxt *, const char *);
169 int	 auth2_setup_methods_lists(Authctxt *);
170 
171 void	privsep_challenge_enable(void);
172 
173 int	auth2_challenge(Authctxt *, char *);
174 void	auth2_challenge_stop(Authctxt *);
175 int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
176 int	bsdauth_respond(void *, u_int, char **);
177 int	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
178 int	skey_respond(void *, u_int, char **);
179 
180 void	auth2_jpake_get_pwdata(Authctxt *, BIGNUM **, char **, char **);
181 void	auth2_jpake_stop(Authctxt *);
182 
183 int	allowed_user(struct passwd *);
184 struct passwd * getpwnamallow(const char *user);
185 
186 char	*get_challenge(Authctxt *);
187 int	verify_response(Authctxt *, const char *);
188 
189 char	*expand_authorized_keys(const char *, struct passwd *pw);
190 char	*authorized_principals_file(struct passwd *);
191 
192 FILE	*auth_openkeyfile(const char *, struct passwd *, int);
193 FILE	*auth_openprincipals(const char *, struct passwd *, int);
194 int	 auth_key_is_revoked(Key *);
195 
196 HostStatus
197 check_key_in_hostfiles(struct passwd *, Key *, const char *,
198     const char *, const char *);
199 
200 /* hostkey handling */
201 Key	*get_hostkey_by_index(int);
202 Key	*get_hostkey_public_by_type(int);
203 Key	*get_hostkey_private_by_type(int);
204 int	 get_hostkey_index(Key *);
205 int	 ssh1_session_key(BIGNUM *);
206 
207 /* debug messages during authentication */
208 void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
209 void	 auth_debug_send(void);
210 void	 auth_debug_reset(void);
211 
212 struct passwd *fakepw(void);
213 
214 #define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
215 
216 #define SKEY_PROMPT "\nS/Key Password: "
217 
218 #if defined(KRB5) && !defined(HEIMDAL)
219 #include <krb5.h>
220 krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
221 #endif
222 #endif
223