auth.h revision 204917
1204917Sdes/* $OpenBSD: auth.h,v 1.65 2010/03/04 10:36:03 djm 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
4569587Sgreentypedef struct Authctxt Authctxt;
4698684Sdestypedef struct Authmethod Authmethod;
4792559Sdestypedef struct KbdintDevice KbdintDevice;
4892559Sdes
4969587Sgreenstruct Authctxt {
50162856Sdes	sig_atomic_t	 success;
51162856Sdes	int		 authenticated;	/* authenticated and alarms cancelled */
52124211Sdes	int		 postponed;	/* authentication needs another step */
53124211Sdes	int		 valid;		/* user exists and is allowed to login */
5492559Sdes	int		 attempt;
5592559Sdes	int		 failures;
56126277Sdes	int		 force_pwchange;
57124211Sdes	char		*user;		/* username sent by the client */
5892559Sdes	char		*service;
59124211Sdes	struct passwd	*pw;		/* set if 'valid' */
6092559Sdes	char		*style;
6192559Sdes	void		*kbdintctxt;
62192595Sdes	void		*jpake_ctx;
6376259Sgreen#ifdef BSD_AUTH
6492559Sdes	auth_session_t	*as;
6576259Sgreen#endif
6692559Sdes#ifdef KRB5
6792559Sdes	krb5_context	 krb5_ctx;
6892559Sdes	krb5_ccache	 krb5_fwd_ccache;
6992559Sdes	krb5_principal	 krb5_user;
7092559Sdes	char		*krb5_ticket_file;
71128460Sdes	char		*krb5_ccname;
7292559Sdes#endif
73147005Sdes	Buffer		*loginmsg;
74124211Sdes	void		*methoddata;
7569587Sgreen};
76124211Sdes/*
77124211Sdes * Every authentication method has to handle authentication requests for
78124211Sdes * non-existing users, or for users that are not allowed to login. In this
79124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by
80124211Sdes * the client.
81124211Sdes */
8269587Sgreen
8398684Sdesstruct Authmethod {
8498684Sdes	char	*name;
8598684Sdes	int	(*userauth)(Authctxt *authctxt);
8698684Sdes	int	*enabled;
8798684Sdes};
8898684Sdes
8976259Sgreen/*
9092559Sdes * Keyboard interactive device:
9192559Sdes * init_ctx	returns: non NULL upon success
9292559Sdes * query	returns: 0 - success, otherwise failure
9392559Sdes * respond	returns: 0 - success, 1 - need further interaction,
9492559Sdes *		otherwise - failure
9576259Sgreen */
9692559Sdesstruct KbdintDevice
9792559Sdes{
9892559Sdes	const char *name;
9992559Sdes	void*	(*init_ctx)(Authctxt*);
10092559Sdes	int	(*query)(void *ctx, char **name, char **infotxt,
10192559Sdes		    u_int *numprompts, char ***prompts, u_int **echo_on);
10292559Sdes	int	(*respond)(void *ctx, u_int numresp, char **responses);
10392559Sdes	void	(*free_ctx)(void *ctx);
10492559Sdes};
10576259Sgreen
10698684Sdesint      auth_rhosts(struct passwd *, const char *);
10776259Sgreenint
10892559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *);
10976259Sgreen
110126277Sdesint	 auth_rhosts_rsa(Authctxt *, char *, Key *);
11192559Sdesint      auth_password(Authctxt *, const char *);
112126277Sdesint      auth_rsa(Authctxt *, BIGNUM *);
11398684Sdesint      auth_rsa_challenge_dialog(Key *);
11498684SdesBIGNUM	*auth_rsa_generate_challenge(Key *);
11598684Sdesint	 auth_rsa_verify_response(Key *, BIGNUM *, u_char[]);
11698684Sdesint	 auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **);
11776259Sgreen
11898684Sdesint	 auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *);
11998684Sdesint	 hostbased_key_allowed(struct passwd *, const char *, char *, Key *);
12098684Sdesint	 user_key_allowed(struct passwd *, Key *);
12198684Sdes
12292559Sdes#ifdef KRB5
123106130Sdesint	auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
12492559Sdesint	auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
12592559Sdesint	auth_krb5_password(Authctxt *authctxt, const char *password);
126126277Sdesvoid	krb5_cleanup_proc(Authctxt *authctxt);
12792559Sdes#endif /* KRB5 */
12876259Sgreen
129126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
130126277Sdes#include <shadow.h>
131126277Sdesint auth_shadow_acctexpired(struct spwd *);
132126277Sdesint auth_shadow_pwexpired(Authctxt *);
133126277Sdes#endif
134126277Sdes
13598941Sdes#include "auth-pam.h"
136147005Sdes#include "audit.h"
137147005Sdesvoid remove_kbdint_device(const char *);
138147005Sdes
139126277Sdesvoid disable_forwarding(void);
14098941Sdes
141126277Sdesvoid	do_authentication(Authctxt *);
142126277Sdesvoid	do_authentication2(Authctxt *);
14360573Skris
14492559Sdesvoid	auth_log(Authctxt *, int, char *, char *);
14592559Sdesvoid	userauth_finish(Authctxt *, int, char *);
146147005Sdesvoid	userauth_send_banner(const char *);
14792559Sdesint	auth_root_allowed(char *);
14860573Skris
14998684Sdeschar	*auth2_read_banner(void);
15098684Sdes
15198684Sdesvoid	privsep_challenge_enable(void);
15298684Sdes
15392559Sdesint	auth2_challenge(Authctxt *, char *);
15492559Sdesvoid	auth2_challenge_stop(Authctxt *);
15598684Sdesint	bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
15698684Sdesint	bsdauth_respond(void *, u_int, char **);
15798684Sdesint	skey_query(void *, char **, char **, u_int *, char ***, u_int **);
15898684Sdesint	skey_respond(void *, u_int, char **);
15960573Skris
160192595Sdesvoid	auth2_jpake_get_pwdata(Authctxt *, BIGNUM **, char **, char **);
161192595Sdesvoid	auth2_jpake_stop(Authctxt *);
162192595Sdes
16392559Sdesint	allowed_user(struct passwd *);
16498684Sdesstruct passwd * getpwnamallow(const char *user);
16576259Sgreen
16692559Sdeschar	*get_challenge(Authctxt *);
16792559Sdesint	verify_response(Authctxt *, const char *);
168112870Sdesvoid	abandon_challenge_response(Authctxt *);
16976259Sgreen
17092559Sdeschar	*authorized_keys_file(struct passwd *);
17192559Sdeschar	*authorized_keys_file2(struct passwd *);
17292559Sdes
173181111SdesFILE	*auth_openkeyfile(const char *, struct passwd *, int);
174204917Sdesint	 auth_key_is_revoked(Key *);
17592559Sdes
17692559SdesHostStatus
17792559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *,
17892559Sdes    const char *, const char *);
17992559Sdes
18098684Sdes/* hostkey handling */
18198684SdesKey	*get_hostkey_by_index(int);
182204917SdesKey	*get_hostkey_public_by_type(int);
183204917SdesKey	*get_hostkey_private_by_type(int);
18498684Sdesint	 get_hostkey_index(Key *);
18598684Sdesint	 ssh1_session_key(BIGNUM *);
18698684Sdes
18798684Sdes/* debug messages during authentication */
18898684Sdesvoid	 auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2)));
18998684Sdesvoid	 auth_debug_send(void);
19098684Sdesvoid	 auth_debug_reset(void);
19198684Sdes
192124211Sdesstruct passwd *fakepw(void);
193124211Sdes
194147005Sdesint	 sys_auth_passwd(Authctxt *, const char *);
195147005Sdes
19660573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
19760573Skris
19898941Sdes#define SKEY_PROMPT "\nS/Key Password: "
199149753Sdes
200149753Sdes#if defined(KRB5) && !defined(HEIMDAL)
201149753Sdes#include <krb5.h>
202149753Sdeskrb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
20360573Skris#endif
20499046Sdes#endif
205