1323124Sdes/* $OpenBSD: auth.h,v 1.88 2016/05/04 14:04:40 markus Exp $ */
292559Sdes
365668Skris/*
465668Skris * Copyright (c) 2000 Markus Friedl.  All rights reserved.
565668Skris *
665668Skris * Redistribution and use in source and binary forms, with or without
765668Skris * modification, are permitted provided that the following conditions
865668Skris * are met:
965668Skris * 1. Redistributions of source code must retain the above copyright
1065668Skris *    notice, this list of conditions and the following disclaimer.
1165668Skris * 2. Redistributions in binary form must reproduce the above copyright
1265668Skris *    notice, this list of conditions and the following disclaimer in the
1365668Skris *    documentation and/or other materials provided with the distribution.
1465668Skris *
1565668Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1665668Skris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1765668Skris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1865668Skris * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1965668Skris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2065668Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2165668Skris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2265668Skris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2365668Skris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2465668Skris * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2569587Sgreen *
2665668Skris */
2792559Sdes
2860573Skris#ifndef AUTH_H
2960573Skris#define AUTH_H
3060573Skris
31162856Sdes#include <signal.h>
32162856Sdes
3376259Sgreen#include <openssl/rsa.h>
3476259Sgreen
3576259Sgreen#ifdef HAVE_LOGIN_CAP
3676259Sgreen#include <login_cap.h>
3776259Sgreen#endif
3876259Sgreen#ifdef BSD_AUTH
3976259Sgreen#include <bsd_auth.h>
4076259Sgreen#endif
4192559Sdes#ifdef KRB5
4292559Sdes#include <krb5.h>
4392559Sdes#endif
4476259Sgreen
45295367Sdesstruct ssh;
46295367Sdesstruct sshkey;
47295367Sdes
4869587Sgreentypedef struct Authctxt Authctxt;
4998684Sdestypedef struct Authmethod Authmethod;
5092559Sdestypedef struct KbdintDevice KbdintDevice;
5192559Sdes
5269587Sgreenstruct Authctxt {
53162856Sdes	sig_atomic_t	 success;
54162856Sdes	int		 authenticated;	/* authenticated and alarms cancelled */
55124211Sdes	int		 postponed;	/* authentication needs another step */
56124211Sdes	int		 valid;		/* user exists and is allowed to login */
5792559Sdes	int		 attempt;
5892559Sdes	int		 failures;
59295367Sdes	int		 server_caused_failure;
60126277Sdes	int		 force_pwchange;
61124211Sdes	char		*user;		/* username sent by the client */
6292559Sdes	char		*service;
63124211Sdes	struct passwd	*pw;		/* set if 'valid' */
6492559Sdes	char		*style;
6592559Sdes	void		*kbdintctxt;
66255767Sdes	char		*info;		/* Extra info for next auth_log */
6776259Sgreen#ifdef BSD_AUTH
6892559Sdes	auth_session_t	*as;
6976259Sgreen#endif
70248619Sdes	char		**auth_methods;	/* modified from server config */
71248619Sdes	u_int		 num_auth_methods;
7292559Sdes#ifdef KRB5
7392559Sdes	krb5_context	 krb5_ctx;
7492559Sdes	krb5_ccache	 krb5_fwd_ccache;
7592559Sdes	krb5_principal	 krb5_user;
7692559Sdes	char		*krb5_ticket_file;
77128460Sdes	char		*krb5_ccname;
7892559Sdes#endif
79147005Sdes	Buffer		*loginmsg;
80124211Sdes	void		*methoddata;
81295367Sdes
82295367Sdes	struct sshkey	**prev_userkeys;
83295367Sdes	u_int		 nprev_userkeys;
8469587Sgreen};
85124211Sdes/*
86124211Sdes * Every authentication method has to handle authentication requests for
87124211Sdes * non-existing users, or for users that are not allowed to login. In this
88124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by
89124211Sdes * the client.
90124211Sdes */
9169587Sgreen
9298684Sdesstruct Authmethod {
9398684Sdes	char	*name;
9498684Sdes	int	(*userauth)(Authctxt *authctxt);
9598684Sdes	int	*enabled;
9698684Sdes};
9798684Sdes
9876259Sgreen/*
9992559Sdes * Keyboard interactive device:
10092559Sdes * init_ctx	returns: non NULL upon success
10192559Sdes * query	returns: 0 - success, otherwise failure
10292559Sdes * respond	returns: 0 - success, 1 - need further interaction,
10392559Sdes *		otherwise - failure
10476259Sgreen */
10592559Sdesstruct KbdintDevice
10692559Sdes{
10792559Sdes	const char *name;
10892559Sdes	void*	(*init_ctx)(Authctxt*);
10992559Sdes	int	(*query)(void *ctx, char **name, char **infotxt,
11092559Sdes		    u_int *numprompts, char ***prompts, u_int **echo_on);
11192559Sdes	int	(*respond)(void *ctx, u_int numresp, char **responses);
11292559Sdes	void	(*free_ctx)(void *ctx);
11392559Sdes};
11476259Sgreen
11598684Sdesint      auth_rhosts(struct passwd *, const char *);
11676259Sgreenint
11792559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *);
11876259Sgreen
119126277Sdesint	 auth_rhosts_rsa(Authctxt *, char *, Key *);
12092559Sdesint      auth_password(Authctxt *, const char *);
121126277Sdesint      auth_rsa(Authctxt *, BIGNUM *);
12298684Sdesint      auth_rsa_challenge_dialog(Key *);
12398684SdesBIGNUM	*auth_rsa_generate_challenge(Key *);
12498684Sdesint	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
12598684Sdesint	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
12676259Sgreen
127323124Sdesint	 auth_rhosts_rsa_key_allowed(struct passwd *, const char *,
128323124Sdes    const char *, Key *);
12998684Sdesint	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
130295367Sdesint	 user_key_allowed(struct passwd *, Key *, int);
131255767Sdesvoid	 pubkey_auth_info(Authctxt *, const Key *, const char *, ...)
132255767Sdes	    __attribute__((__format__ (printf, 3, 4)));
133295367Sdesvoid	 auth2_record_userkey(Authctxt *, struct sshkey *);
134295367Sdesint	 auth2_userkey_already_used(Authctxt *, struct sshkey *);
13598684Sdes
136248619Sdesstruct stat;
137248619Sdesint	 auth_secure_path(const char *, struct stat *, const char *, uid_t,
138248619Sdes    char *, size_t);
139248619Sdes
14092559Sdes#ifdef KRB5
141106130Sdesint	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
14292559Sdesint	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
14392559Sdesint	auth_krb5_password(Authctxt *authctxt, const char *password);
144126277Sdesvoid	krb5_cleanup_proc(Authctxt *authctxt);
14592559Sdes#endif /* KRB5 */
14676259Sgreen
147126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
148126277Sdes#include <shadow.h>
149126277Sdesint auth_shadow_acctexpired(struct spwd *);
150126277Sdesint auth_shadow_pwexpired(Authctxt *);
151126277Sdes#endif
152126277Sdes
15398941Sdes#include "auth-pam.h"
154147005Sdes#include "audit.h"
155147005Sdesvoid remove_kbdint_device(const char *);
156147005Sdes
157126277Sdesvoid disable_forwarding(void);
15898941Sdes
159126277Sdesvoid	do_authentication(Authctxt *);
160126277Sdesvoid	do_authentication2(Authctxt *);
16160573Skris
162255767Sdesvoid	auth_info(Authctxt *authctxt, const char *, ...)
163255767Sdes	    __attribute__((__format__ (printf, 2, 3)))
164255767Sdes	    __attribute__((__nonnull__ (2)));
165255767Sdesvoid	auth_log(Authctxt *, int, int, const char *, const char *);
166295367Sdesvoid	auth_maxtries_exceeded(Authctxt *) __attribute__((noreturn));
167248619Sdesvoid	userauth_finish(Authctxt *, int, const char *, const char *);
168248619Sdesint	auth_root_allowed(const char *);
169248619Sdes
170147005Sdesvoid	userauth_send_banner(const char *);
17160573Skris
17298684Sdeschar	*auth2_read_banner(void);
173248619Sdesint	 auth2_methods_valid(const char *, int);
174255767Sdesint	 auth2_update_methods_lists(Authctxt *, const char *, const char *);
175248619Sdesint	 auth2_setup_methods_lists(Authctxt *);
176255767Sdesint	 auth2_method_allowed(Authctxt *, const char *, const char *);
17798684Sdes
17898684Sdesvoid	privsep_challenge_enable(void);
17998684Sdes
18092559Sdesint	auth2_challenge(Authctxt *, char *);
18192559Sdesvoid	auth2_challenge_stop(Authctxt *);
18298684Sdesint	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
18398684Sdesint	bsdauth_respond(void *, u_int, char **);
18498684Sdesint	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
18598684Sdesint	skey_respond(void *, u_int, char **);
18660573Skris
18792559Sdesint	allowed_user(struct passwd *);
18898684Sdesstruct passwd * getpwnamallow(const char *user);
18976259Sgreen
19092559Sdeschar	*get_challenge(Authctxt *);
19192559Sdesint	verify_response(Authctxt *, const char *);
192112870Sdesvoid	abandon_challenge_response(Authctxt *);
19376259Sgreen
194226046Sdeschar	*expand_authorized_keys(const char *, struct passwd *pw);
195215116Sdeschar	*authorized_principals_file(struct passwd *);
19692559Sdes
197181111SdesFILE	*auth_openkeyfile(const char *, struct passwd *, int);
198215116SdesFILE	*auth_openprincipals(const char *, struct passwd *, int);
199204917Sdesint	 auth_key_is_revoked(Key *);
20092559Sdes
201323124Sdesconst char	*auth_get_canonical_hostname(struct ssh *, int);
202323124Sdes
20392559SdesHostStatus
20492559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *,
20592559Sdes    const char *, const char *);
20692559Sdes
20798684Sdes/* hostkey handling */
20898684SdesKey	*get_hostkey_by_index(int);
209295367SdesKey	*get_hostkey_public_by_index(int, struct ssh *);
210295367SdesKey	*get_hostkey_public_by_type(int, int, struct ssh *);
211295367SdesKey	*get_hostkey_private_by_type(int, int, struct ssh *);
212295367Sdesint	 get_hostkey_index(Key *, int, struct ssh *);
21398684Sdesint	 ssh1_session_key(BIGNUM *);
214295367Sdesint	 sshd_hostkey_sign(Key *, Key *, u_char **, size_t *,
215296781Sdes	     const u_char *, size_t, const char *, u_int);
21698684Sdes
21798684Sdes/* debug messages during authentication */
21898684Sdesvoid	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
21998684Sdesvoid	 auth_debug_send(void);
22098684Sdesvoid	 auth_debug_reset(void);
22198684Sdes
222124211Sdesstruct passwd *fakepw(void);
223124211Sdes
224147005Sdesint	 sys_auth_passwd(Authctxt *, const char *);
225147005Sdes
22698941Sdes#define SKEY_PROMPT "\nS/Key Password: "
227149753Sdes
228149753Sdes#if defined(KRB5) && !defined(HEIMDAL)
229149753Sdes#include <krb5.h>
230149753Sdeskrb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
23160573Skris#endif
23299046Sdes#endif
233