auth.h 6.02 KB
Newer Older
1
/* $OpenBSD: auth.h,v 1.52 2006/03/25 22:22:42 djm Exp $ */
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright (c) 2000 Markus Friedl.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 *
26
 */
27

28 29 30
#ifndef AUTH_H
#define AUTH_H

31 32
#include "key.h"
#include "hostfile.h"
33
#include "buffer.h"
34 35
#include <openssl/rsa.h>

36 37 38 39 40 41
#ifdef HAVE_LOGIN_CAP
#include <login_cap.h>
#endif
#ifdef BSD_AUTH
#include <bsd_auth.h>
#endif
42 43 44
#ifdef KRB5
#include <krb5.h>
#endif
45

46
typedef struct Authctxt Authctxt;
47
typedef struct Authmethod Authmethod;
48 49
typedef struct KbdintDevice KbdintDevice;

50
struct Authctxt {
51
	int		 success;
52 53
	int		 postponed;	/* authentication needs another step */
	int		 valid;		/* user exists and is allowed to login */
54 55
	int		 attempt;
	int		 failures;
56
	int		 force_pwchange;
57
	char		*user;		/* username sent by the client */
58
	char		*service;
59
	struct passwd	*pw;		/* set if 'valid' */
60 61
	char		*style;
	void		*kbdintctxt;
62
#ifdef BSD_AUTH
63 64 65 66 67 68 69
	auth_session_t	*as;
#endif
#ifdef KRB5
	krb5_context	 krb5_ctx;
	krb5_ccache	 krb5_fwd_ccache;
	krb5_principal	 krb5_user;
	char		*krb5_ticket_file;
70
	char		*krb5_ccname;
71
#endif
72
	Buffer		*loginmsg;
73
	void		*methoddata;
74
};
75 76 77 78 79 80
/*
 * Every authentication method has to handle authentication requests for
 * non-existing users, or for users that are not allowed to login. In this
 * case 'valid' is set to 0, but 'user' points to the username requested by
 * the client.
 */
81

82 83 84 85 86 87
struct Authmethod {
	char	*name;
	int	(*userauth)(Authctxt *authctxt);
	int	*enabled;
};

88 89
/*
 * Keyboard interactive device:
90 91
 * init_ctx	returns: non NULL upon success
 * query	returns: 0 - success, otherwise failure
92 93 94 95 96 97
 * respond	returns: 0 - success, 1 - need further interaction,
 *		otherwise - failure
 */
struct KbdintDevice
{
	const char *name;
98
	void*	(*init_ctx)(Authctxt*);
99 100
	int	(*query)(void *ctx, char **name, char **infotxt,
		    u_int *numprompts, char ***prompts, u_int **echo_on);
101 102
	int	(*respond)(void *ctx, u_int numresp, char **responses);
	void	(*free_ctx)(void *ctx);
103 104
};

105
int      auth_rhosts(struct passwd *, const char *);
106
int
107
auth_rhosts2(struct passwd *, const char *, const char *, const char *);
108

109
int	 auth_rhosts_rsa(Authctxt *, char *, Key *);
110
int      auth_password(Authctxt *, const char *);
111
int      auth_rsa(Authctxt *, BIGNUM *);
112
int      auth_rsa_challenge_dialog(Key *);
113 114 115 116 117 118 119
BIGNUM	*auth_rsa_generate_challenge(Key *);
int	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
int	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);

int	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
int	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
int	 user_key_allowed(struct passwd *, Key *);
120

121
#ifdef KRB5
122
int	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
123 124
int	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
int	auth_krb5_password(Authctxt *authctxt, const char *password);
125
void	krb5_cleanup_proc(Authctxt *authctxt);
126 127
#endif /* KRB5 */

128
#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
129
#include <shadow.h>
130
int auth_shadow_acctexpired(struct spwd *);
131 132 133
int auth_shadow_pwexpired(Authctxt *);
#endif

134
#include "auth-pam.h"
135
#include "audit.h"
136 137
void remove_kbdint_device(const char *);

138
void disable_forwarding(void);
139

Darren Tucker's avatar
Darren Tucker committed
140 141
void	do_authentication(Authctxt *);
void	do_authentication2(Authctxt *);
142

143 144
void	auth_log(Authctxt *, int, char *, char *);
void	userauth_finish(Authctxt *, int, char *);
145
void	userauth_send_banner(const char *);
146
int	auth_root_allowed(char *);
147

148 149
char	*auth2_read_banner(void);

150 151
void	privsep_challenge_enable(void);

152
int	auth2_challenge(Authctxt *, char *);
153
void	auth2_challenge_stop(Authctxt *);
154 155 156 157
int	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
int	bsdauth_respond(void *, u_int, char **);
int	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
int	skey_respond(void *, u_int, char **);
158

159
int	allowed_user(struct passwd *);
160
struct passwd * getpwnamallow(const char *user);
161

162 163
char	*get_challenge(Authctxt *);
int	verify_response(Authctxt *, const char *);
164
void	abandon_challenge_response(Authctxt *);
165

166 167
char	*authorized_keys_file(struct passwd *);
char	*authorized_keys_file2(struct passwd *);
168 169

int
170
secure_filename(FILE *, const char *, struct passwd *, char *, size_t);
171

172
HostStatus
173 174
check_key_in_hostfiles(struct passwd *, Key *, const char *,
    const char *, const char *);
175

176 177 178 179 180 181
/* hostkey handling */
Key	*get_hostkey_by_index(int);
Key	*get_hostkey_by_type(int);
int	 get_hostkey_index(Key *);
int	 ssh1_session_key(BIGNUM *);

182 183 184 185 186
/* debug messages during authentication */
void	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
void	 auth_debug_send(void);
void	 auth_debug_reset(void);

187 188
struct passwd *fakepw(void);

189 190
int	 sys_auth_passwd(Authctxt *, const char *);

191 192
#define AUTH_FAIL_MSG "Too many authentication failures for %.100s"

193
#define SKEY_PROMPT "\nS/Key Password: "
194 195 196 197 198

#if defined(KRB5) && !defined(HEIMDAL)
#include <krb5.h>
krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
#endif
199
#endif