auth.h revision 126277
1126277Sdes/* $OpenBSD: auth.h,v 1.49 2004/01/30 09:48:57 markus Exp $ */ 299046Sdes/* $FreeBSD: head/crypto/openssh/auth.h 126277 2004-02-26 10:52:33Z 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" 3476259Sgreen#include <openssl/rsa.h> 3576259Sgreen 3676259Sgreen#ifdef HAVE_LOGIN_CAP 3776259Sgreen#include <login_cap.h> 3876259Sgreen#endif 3976259Sgreen#ifdef BSD_AUTH 4076259Sgreen#include <bsd_auth.h> 4176259Sgreen#endif 4292559Sdes#ifdef KRB5 4392559Sdes#include <krb5.h> 4492559Sdes#endif 4576259Sgreen 4669587Sgreentypedef struct Authctxt Authctxt; 4798684Sdestypedef struct Authmethod Authmethod; 4892559Sdestypedef struct KbdintDevice KbdintDevice; 4992559Sdes 5069587Sgreenstruct Authctxt { 5192559Sdes int success; 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; 6276259Sgreen#ifdef BSD_AUTH 6392559Sdes auth_session_t *as; 6476259Sgreen#endif 6592559Sdes#ifdef KRB5 6692559Sdes krb5_context krb5_ctx; 6792559Sdes krb5_ccache krb5_fwd_ccache; 6892559Sdes krb5_principal krb5_user; 6992559Sdes char *krb5_ticket_file; 7092559Sdes#endif 71124211Sdes void *methoddata; 7269587Sgreen}; 73124211Sdes/* 74124211Sdes * Every authentication method has to handle authentication requests for 75124211Sdes * non-existing users, or for users that are not allowed to login. In this 76124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by 77124211Sdes * the client. 78124211Sdes */ 7969587Sgreen 8098684Sdesstruct Authmethod { 8198684Sdes char *name; 8298684Sdes int (*userauth)(Authctxt *authctxt); 8398684Sdes int *enabled; 8498684Sdes}; 8598684Sdes 8676259Sgreen/* 8792559Sdes * Keyboard interactive device: 8892559Sdes * init_ctx returns: non NULL upon success 8992559Sdes * query returns: 0 - success, otherwise failure 9092559Sdes * respond returns: 0 - success, 1 - need further interaction, 9192559Sdes * otherwise - failure 9276259Sgreen */ 9392559Sdesstruct KbdintDevice 9492559Sdes{ 9592559Sdes const char *name; 9692559Sdes void* (*init_ctx)(Authctxt*); 9792559Sdes int (*query)(void *ctx, char **name, char **infotxt, 9892559Sdes u_int *numprompts, char ***prompts, u_int **echo_on); 9992559Sdes int (*respond)(void *ctx, u_int numresp, char **responses); 10092559Sdes void (*free_ctx)(void *ctx); 10192559Sdes}; 10276259Sgreen 10398684Sdesint auth_rhosts(struct passwd *, const char *); 10476259Sgreenint 10592559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *); 10676259Sgreen 107126277Sdesint auth_rhosts_rsa(Authctxt *, char *, Key *); 10892559Sdesint auth_password(Authctxt *, const char *); 109126277Sdesint auth_rsa(Authctxt *, BIGNUM *); 11098684Sdesint auth_rsa_challenge_dialog(Key *); 11198684SdesBIGNUM *auth_rsa_generate_challenge(Key *); 11298684Sdesint auth_rsa_verify_response(Key *, BIGNUM *, u_char[]); 11398684Sdesint auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **); 11476259Sgreen 11598684Sdesint auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 11698684Sdesint hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 11798684Sdesint user_key_allowed(struct passwd *, Key *); 11898684Sdes 11992559Sdes#ifdef KRB5 120106130Sdesint auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *); 12192559Sdesint auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt); 12292559Sdesint auth_krb5_password(Authctxt *authctxt, const char *password); 123126277Sdesvoid krb5_cleanup_proc(Authctxt *authctxt); 12492559Sdes#endif /* KRB5 */ 12576259Sgreen 126126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE) 127126277Sdes#include <shadow.h> 128126277Sdesint auth_shadow_acctexpired(struct spwd *); 129126277Sdesint auth_shadow_pwexpired(Authctxt *); 130126277Sdes#endif 131126277Sdes 13298941Sdes#include "auth-pam.h" 133126277Sdesvoid disable_forwarding(void); 13498941Sdes 135126277Sdesvoid do_authentication(Authctxt *); 136126277Sdesvoid do_authentication2(Authctxt *); 13760573Skris 13892559Sdesvoid auth_log(Authctxt *, int, char *, char *); 13992559Sdesvoid userauth_finish(Authctxt *, int, char *); 14092559Sdesint auth_root_allowed(char *); 14160573Skris 14298684Sdeschar *auth2_read_banner(void); 14398684Sdes 14498684Sdesvoid privsep_challenge_enable(void); 14598684Sdes 14692559Sdesint auth2_challenge(Authctxt *, char *); 14792559Sdesvoid auth2_challenge_stop(Authctxt *); 14898684Sdesint bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 14998684Sdesint bsdauth_respond(void *, u_int, char **); 15098684Sdesint skey_query(void *, char **, char **, u_int *, char ***, u_int **); 15198684Sdesint skey_respond(void *, u_int, char **); 15260573Skris 15392559Sdesint allowed_user(struct passwd *); 15498684Sdesstruct passwd * getpwnamallow(const char *user); 15576259Sgreen 15692559Sdeschar *get_challenge(Authctxt *); 15792559Sdesint verify_response(Authctxt *, const char *); 158112870Sdesvoid abandon_challenge_response(Authctxt *); 15976259Sgreen 16092559Sdeschar *expand_filename(const char *, struct passwd *); 16192559Sdeschar *authorized_keys_file(struct passwd *); 16292559Sdeschar *authorized_keys_file2(struct passwd *); 16392559Sdes 16492559Sdesint 16592559Sdessecure_filename(FILE *, const char *, struct passwd *, char *, size_t); 16692559Sdes 16792559SdesHostStatus 16892559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 16992559Sdes const char *, const char *); 17092559Sdes 17198684Sdes/* hostkey handling */ 17298684SdesKey *get_hostkey_by_index(int); 17398684SdesKey *get_hostkey_by_type(int); 17498684Sdesint get_hostkey_index(Key *); 17598684Sdesint ssh1_session_key(BIGNUM *); 17698684Sdes 17798684Sdes/* debug messages during authentication */ 17898684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 17998684Sdesvoid auth_debug_send(void); 18098684Sdesvoid auth_debug_reset(void); 18198684Sdes 182124211Sdesstruct passwd *fakepw(void); 183124211Sdes 18460573Skris#define AUTH_FAIL_MAX 6 18560573Skris#define AUTH_FAIL_LOG (AUTH_FAIL_MAX/2) 18660573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s" 18760573Skris 18899046Sdes#ifdef SKEY 18999046Sdes#ifdef OPIE 19099046Sdes#define SKEY_PROMPT "\nOPIE Password: " 19199046Sdes#else 19298941Sdes#define SKEY_PROMPT "\nS/Key Password: " 19360573Skris#endif 19499046Sdes#endif 19599046Sdes 19699046Sdes#endif 197