1 /* $MirOS: src/usr.bin/ssh/auth.h,v 1.14 2014/03/28 22:31:54 tg Exp $ */
2 /* $OpenBSD: auth.h,v 1.63 2009/08/15 18:56:34 fgsch Exp $ */
3 
4 /*
5  * Copyright © 2013
6  *	Thorsten “mirabilos” Glaser <tg@mirbsd.org>
7  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
31 #ifndef AUTH_H
32 #define AUTH_H
33 
34 #include <signal.h>
35 
36 #include <openssl/rsa.h>
37 
38 #ifdef BSD_AUTH
39 #include <bsd_auth.h>
40 #endif
41 
42 typedef struct Authctxt Authctxt;
43 typedef struct Authmethod Authmethod;
44 typedef struct KbdintDevice KbdintDevice;
45 
46 struct Authctxt {
47 	sig_atomic_t	 success;
48 	int		 authenticated;	/* authenticated and alarms cancelled */
49 	int		 postponed;	/* authentication needs another step */
50 	int		 valid;		/* user exists and is allowed to login */
51 	int		 attempt;
52 	int		 failures;
53 	int		 force_pwchange;
54 	char		*user;		/* username sent by the client */
55 	char		*service;
56 	struct passwd	*pw;		/* set if 'valid' */
57 	char		*style;
58 	void		*kbdintctxt;
59 #ifdef BSD_AUTH
60 	auth_session_t	*as;
61 #endif
62 	void		*methoddata;
63 };
64 /*
65  * Every authentication method has to handle authentication requests for
66  * non-existing users, or for users that are not allowed to login. In this
67  * case 'valid' is set to 0, but 'user' points to the username requested by
68  * the client.
69  */
70 
71 struct Authmethod {
72 	const char *name;
73 	int	(*userauth)(Authctxt *authctxt);
74 	int	*enabled;
75 };
76 
77 /*
78  * Keyboard interactive device:
79  * init_ctx	returns: non NULL upon success
80  * query	returns: 0 - success, otherwise failure
81  * respond	returns: 0 - success, 1 - need further interaction,
82  *		otherwise - failure
83  */
84 struct KbdintDevice
85 {
86 	const char *name;
87 	void*	(*init_ctx)(Authctxt*);
88 	int	(*query)(void *ctx, char **name, char **infotxt,
89 		    u_int *numprompts, char ***prompts, u_int **echo_on);
90 	int	(*respond)(void *ctx, u_int numresp, char **responses);
91 	void	(*free_ctx)(void *ctx);
92 };
93 
94 int      auth_rhosts(struct passwd *, const char *);
95 int
96 auth_rhosts2(struct passwd *, const char *, const char *, const char *);
97 
98 int	 auth_rhosts_rsa(Authctxt *, char *, Key *);
99 int      auth_password(Authctxt *, const char *);
100 int      auth_rsa(Authctxt *, BIGNUM *);
101 int      auth_rsa_challenge_dialog(Key *);
102 BIGNUM	*auth_rsa_generate_challenge(Key *);
103 int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
104 int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
105 
106 int	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
107 int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
108 int	 user_key_allowed(struct passwd *, Key *);
109 
110 void	do_authentication(Authctxt *);
111 void	do_authentication2(Authctxt *);
112 
113 void	auth_log(Authctxt *, int, const char *, const char *);
114 void	userauth_finish(Authctxt *, int, char *);
115 int	auth_root_allowed(const char *);
116 
117 char	*auth2_read_banner(void);
118 
119 void	privsep_challenge_enable(void);
120 
121 int	auth2_challenge(Authctxt *, char *);
122 void	auth2_challenge_stop(Authctxt *);
123 int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
124 int	bsdauth_respond(void *, u_int, char **);
125 int	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
126 int	skey_respond(void *, u_int, char **);
127 
128 int	allowed_user(struct passwd *);
129 struct passwd * getpwnamallow(const char *user);
130 
131 char	*get_challenge(Authctxt *);
132 int	verify_response(Authctxt *, const char *);
133 
134 char	*authorised_keys_file(struct passwd *);
135 char	*authorised_keys_file2(struct passwd *);
136 
137 FILE	*auth_openkeyfile(const char *, struct passwd *, int);
138 
139 HostStatus
140 check_key_in_hostfiles(struct passwd *, Key *, const char *,
141     const char *, const char *);
142 
143 /* hostkey handling */
144 Key	*get_hostkey_by_index(int);
145 Key	*get_hostkey_by_type(int);
146 int	 get_hostkey_index(Key *);
147 int	 ssh1_session_key(BIGNUM *);
148 
149 /* debug messages during authentication */
150 void	 auth_debug_add(const char *fmt,...) __attribute__((__format__(__printf__, 1, 2)));
151 void	 auth_debug_send(void);
152 void	 auth_debug_reset(void);
153 
154 struct passwd *fakepw(void);
155 
156 #define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
157 
158 #endif
159