auth.h revision 147005
1137019Sdes/* $OpenBSD: auth.h,v 1.50 2004/05/23 23:59:53 dtucker Exp $ */ 299046Sdes/* $FreeBSD: head/crypto/openssh/auth.h 147005 2005-06-05 15:46:09Z des $ */ 392559Sdes 465668Skris/* 565668Skris * Copyright (c) 2000 Markus Friedl. All rights reserved. 665668Skris * 765668Skris * Redistribution and use in source and binary forms, with or without 865668Skris * modification, are permitted provided that the following conditions 965668Skris * are met: 1065668Skris * 1. Redistributions of source code must retain the above copyright 1165668Skris * notice, this list of conditions and the following disclaimer. 1265668Skris * 2. Redistributions in binary form must reproduce the above copyright 1365668Skris * notice, this list of conditions and the following disclaimer in the 1465668Skris * documentation and/or other materials provided with the distribution. 1565668Skris * 1665668Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1765668Skris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1865668Skris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1965668Skris * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2065668Skris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2165668Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2265668Skris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2365668Skris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2465668Skris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2565668Skris * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2669587Sgreen * 2765668Skris */ 2892559Sdes 2960573Skris#ifndef AUTH_H 3060573Skris#define AUTH_H 3160573Skris 3292559Sdes#include "key.h" 3392559Sdes#include "hostfile.h" 34147005Sdes#include "buffer.h" 3576259Sgreen#include <openssl/rsa.h> 3676259Sgreen 3776259Sgreen#ifdef HAVE_LOGIN_CAP 3876259Sgreen#include <login_cap.h> 3976259Sgreen#endif 4076259Sgreen#ifdef BSD_AUTH 4176259Sgreen#include <bsd_auth.h> 4276259Sgreen#endif 4392559Sdes#ifdef KRB5 4492559Sdes#include <krb5.h> 4592559Sdes#endif 4676259Sgreen 4769587Sgreentypedef struct Authctxt Authctxt; 4898684Sdestypedef struct Authmethod Authmethod; 4992559Sdestypedef struct KbdintDevice KbdintDevice; 5092559Sdes 5169587Sgreenstruct Authctxt { 5292559Sdes int success; 53124211Sdes int postponed; /* authentication needs another step */ 54124211Sdes int valid; /* user exists and is allowed to login */ 5592559Sdes int attempt; 5692559Sdes int failures; 57126277Sdes int force_pwchange; 58124211Sdes char *user; /* username sent by the client */ 5992559Sdes char *service; 60124211Sdes struct passwd *pw; /* set if 'valid' */ 6192559Sdes char *style; 6292559Sdes void *kbdintctxt; 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 16092559Sdesint allowed_user(struct passwd *); 16198684Sdesstruct passwd * getpwnamallow(const char *user); 16276259Sgreen 16392559Sdeschar *get_challenge(Authctxt *); 16492559Sdesint verify_response(Authctxt *, const char *); 165112870Sdesvoid abandon_challenge_response(Authctxt *); 16676259Sgreen 16792559Sdeschar *expand_filename(const char *, struct passwd *); 16892559Sdeschar *authorized_keys_file(struct passwd *); 16992559Sdeschar *authorized_keys_file2(struct passwd *); 17092559Sdes 17192559Sdesint 17292559Sdessecure_filename(FILE *, const char *, struct passwd *, char *, size_t); 17392559Sdes 17492559SdesHostStatus 17592559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 17692559Sdes const char *, const char *); 17792559Sdes 17898684Sdes/* hostkey handling */ 17998684SdesKey *get_hostkey_by_index(int); 18098684SdesKey *get_hostkey_by_type(int); 18198684Sdesint get_hostkey_index(Key *); 18298684Sdesint ssh1_session_key(BIGNUM *); 18398684Sdes 18498684Sdes/* debug messages during authentication */ 18598684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 18698684Sdesvoid auth_debug_send(void); 18798684Sdesvoid auth_debug_reset(void); 18898684Sdes 189124211Sdesstruct passwd *fakepw(void); 190124211Sdes 191147005Sdesint sys_auth_passwd(Authctxt *, const char *); 192147005Sdes 19360573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s" 19460573Skris 19599046Sdes#ifdef SKEY 19699046Sdes#ifdef OPIE 19799046Sdes#define SKEY_PROMPT "\nOPIE Password: " 19899046Sdes#else 19998941Sdes#define SKEY_PROMPT "\nS/Key Password: " 20060573Skris#endif 20199046Sdes#endif 20299046Sdes 20399046Sdes#endif 204