xref: /netbsd-src/crypto/external/bsd/openssh/dist/auth.h (revision a24efa7dea9f1f56c3bdb15a927d3516792ace1c)
1 /*	$NetBSD: auth.h,v 1.12 2016/03/11 01:55:00 christos Exp $	*/
2 /* $OpenBSD: auth.h,v 1.86 2015/12/04 16:41:28 markus 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 struct ssh;
47 struct sshkey;
48 
49 typedef struct Authctxt Authctxt;
50 typedef struct Authmethod Authmethod;
51 typedef struct KbdintDevice KbdintDevice;
52 
53 struct Authctxt {
54 	sig_atomic_t	 success;
55 	int		 authenticated;	/* authenticated and alarms cancelled */
56 	int		 postponed;	/* authentication needs another step */
57 	int		 valid;		/* user exists and is allowed to login */
58 	int		 attempt;
59 	int		 failures;
60 	int		 server_caused_failure;
61 	int		 force_pwchange;
62 	char		*user;		/* username sent by the client */
63 	char		*service;
64 	struct passwd	*pw;		/* set if 'valid' */
65 	char		*style;
66 	void		*kbdintctxt;
67 	char		*info;		/* Extra info for next auth_log */
68 #ifdef BSD_AUTH
69 	auth_session_t	*as;
70 #endif
71 #ifdef KRB4
72 	char		*krb4_ticket_file;
73 #endif
74 	char		**auth_methods;	/* modified from server config */
75 	u_int		 num_auth_methods;
76 #ifdef KRB5
77 	krb5_context	 krb5_ctx;
78 	krb5_auth_context krb5_auth_ctx;
79 	krb5_ccache	 krb5_fwd_ccache;
80 	krb5_principal	 krb5_user;
81 	char		*krb5_ticket_file;
82 #endif
83 	void		*methoddata;
84 
85 	struct sshkey	**prev_userkeys;
86 	u_int		 nprev_userkeys;
87 };
88 /*
89  * Every authentication method has to handle authentication requests for
90  * non-existing users, or for users that are not allowed to login. In this
91  * case 'valid' is set to 0, but 'user' points to the username requested by
92  * the client.
93  */
94 
95 #ifdef USE_PAM
96 #include "auth-pam.h"
97 #endif
98 
99 struct Authmethod {
100 	const char	*name;
101 	int	(*userauth)(Authctxt *authctxt);
102 	int	*enabled;
103 };
104 
105 /*
106  * Keyboard interactive device:
107  * init_ctx	returns: non NULL upon success
108  * query	returns: 0 - success, otherwise failure
109  * respond	returns: 0 - success, 1 - need further interaction,
110  *		otherwise - failure
111  */
112 struct KbdintDevice
113 {
114 	const char *name;
115 	void*	(*init_ctx)(Authctxt*);
116 	int	(*query)(void *ctx, char **name, char **infotxt,
117 		    u_int *numprompts, char ***prompts, u_int **echo_on);
118 	int	(*respond)(void *ctx, u_int numresp, char **responses);
119 	void	(*free_ctx)(void *ctx);
120 };
121 
122 void 	 disable_forwarding(void);
123 int      auth_rhosts(struct passwd *, const char *);
124 int
125 auth_rhosts2(struct passwd *, const char *, const char *, const char *);
126 
127 int	 auth_rhosts_rsa(Authctxt *, char *, Key *);
128 int      auth_password(Authctxt *, const char *);
129 int      auth_rsa(Authctxt *, BIGNUM *);
130 int      auth_rsa_challenge_dialog(Key *);
131 BIGNUM	*auth_rsa_generate_challenge(Key *);
132 int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
133 int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
134 
135 int	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
136 int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
137 int	 user_key_allowed(struct passwd *, Key *, int);
138 void	 pubkey_auth_info(Authctxt *, const Key *, const char *, ...)
139 	    __attribute__((__format__ (printf, 3, 4)));
140 void	 auth2_record_userkey(Authctxt *, struct sshkey *);
141 int	 auth2_userkey_already_used(Authctxt *, struct sshkey *);
142 
143 #ifdef KRB4
144 #include <krb.h>
145 int     auth_krb4(Authctxt *, KTEXT, char **, KTEXT);
146 int	auth_krb4_password(Authctxt *, const char *);
147 void    krb4_cleanup_proc(void *);
148 
149 #ifdef AFS
150 #include <kafs.h>
151 int     auth_krb4_tgt(Authctxt *, const char *);
152 int     auth_afs_token(Authctxt *, const char *);
153 #endif /* AFS */
154 
155 #endif /* KRB4 */
156 
157 struct stat;
158 int	 auth_secure_path(const char *, struct stat *, const char *, uid_t,
159     char *, size_t);
160 
161 #ifdef KRB5
162 int	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
163 int	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
164 int	auth_krb5_password(Authctxt *authctxt, const char *password);
165 void	krb5_cleanup_proc(Authctxt *authctxt);
166 #endif /* KRB5 */
167 
168 void	do_authentication(Authctxt *);
169 void	do_authentication2(Authctxt *);
170 
171 void	auth_info(Authctxt *authctxt, const char *, ...)
172 	    __attribute__((__format__ (printf, 2, 3)))
173 	    __attribute__((__nonnull__ (2)));
174 void	auth_log(Authctxt *, int, int, const char *, const char *);
175 void	auth_maxtries_exceeded(Authctxt *) __attribute__((noreturn));
176 void	userauth_finish(Authctxt *, int, const char *, const char *);
177 int	auth_root_allowed(const char *);
178 
179 char	*auth2_read_banner(void);
180 int	 auth2_methods_valid(const char *, int);
181 int	 auth2_update_methods_lists(Authctxt *, const char *, const char *);
182 int	 auth2_setup_methods_lists(Authctxt *);
183 int	 auth2_method_allowed(Authctxt *, const char *, const char *);
184 
185 void	privsep_challenge_enable(void);
186 
187 int	auth2_challenge(Authctxt *, char *);
188 void	auth2_challenge_stop(Authctxt *);
189 int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
190 int	bsdauth_respond(void *, u_int, char **);
191 
192 int	allowed_user(struct passwd *);
193 struct passwd * getpwnamallow(const char *user);
194 
195 char	*get_challenge(Authctxt *);
196 int	verify_response(Authctxt *, const char *);
197 
198 char	*expand_authorized_keys(const char *, struct passwd *pw);
199 char	*authorized_principals_file(struct passwd *);
200 
201 FILE	*auth_openkeyfile(const char *, struct passwd *, int);
202 FILE	*auth_openprincipals(const char *, struct passwd *, int);
203 int	 auth_key_is_revoked(Key *);
204 
205 HostStatus
206 check_key_in_hostfiles(struct passwd *, Key *, const char *,
207     const char *, const char *);
208 
209 /* hostkey handling */
210 Key	*get_hostkey_by_index(int);
211 Key	*get_hostkey_public_by_index(int, struct ssh *);
212 Key	*get_hostkey_public_by_type(int, int, struct ssh *);
213 Key	*get_hostkey_private_by_type(int, int, struct ssh *);
214 int	 get_hostkey_index(Key *, int, struct ssh *);
215 int	 ssh1_session_key(BIGNUM *);
216 int	 sshd_hostkey_sign(Key *, Key *, u_char **, size_t *,
217 	     const u_char *, size_t, const char *, u_int);
218 
219 /* debug messages during authentication */
220 void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
221 void	 auth_debug_send(void);
222 void	 auth_debug_reset(void);
223 
224 struct passwd *fakepw(void);
225 
226 #define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
227 
228 #define SKEY_PROMPT "\nS/Key Password: "
229 
230 #if defined(KRB5) && !defined(HEIMDAL)
231 #include <krb5.h>
232 krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
233 #endif
234 #endif
235