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