auth.h revision 181111
1181111Sdes/* $OpenBSD: auth.h,v 1.61 2008/07/02 12:03:51 dtucker 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; 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; 70128460Sdes char *krb5_ccname; 7192559Sdes#endif 72147005Sdes Buffer *loginmsg; 73124211Sdes void *methoddata; 7469587Sgreen}; 75124211Sdes/* 76124211Sdes * Every authentication method has to handle authentication requests for 77124211Sdes * non-existing users, or for users that are not allowed to login. In this 78124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by 79124211Sdes * the client. 80124211Sdes */ 8169587Sgreen 8298684Sdesstruct Authmethod { 8398684Sdes char *name; 8498684Sdes int (*userauth)(Authctxt *authctxt); 8598684Sdes int *enabled; 8698684Sdes}; 8798684Sdes 8876259Sgreen/* 8992559Sdes * Keyboard interactive device: 9092559Sdes * init_ctx returns: non NULL upon success 9192559Sdes * query returns: 0 - success, otherwise failure 9292559Sdes * respond returns: 0 - success, 1 - need further interaction, 9392559Sdes * otherwise - failure 9476259Sgreen */ 9592559Sdesstruct KbdintDevice 9692559Sdes{ 9792559Sdes const char *name; 9892559Sdes void* (*init_ctx)(Authctxt*); 9992559Sdes int (*query)(void *ctx, char **name, char **infotxt, 10092559Sdes u_int *numprompts, char ***prompts, u_int **echo_on); 10192559Sdes int (*respond)(void *ctx, u_int numresp, char **responses); 10292559Sdes void (*free_ctx)(void *ctx); 10392559Sdes}; 10476259Sgreen 10598684Sdesint auth_rhosts(struct passwd *, const char *); 10676259Sgreenint 10792559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *); 10876259Sgreen 109126277Sdesint auth_rhosts_rsa(Authctxt *, char *, Key *); 11092559Sdesint auth_password(Authctxt *, const char *); 111126277Sdesint auth_rsa(Authctxt *, BIGNUM *); 11298684Sdesint auth_rsa_challenge_dialog(Key *); 11398684SdesBIGNUM *auth_rsa_generate_challenge(Key *); 11498684Sdesint auth_rsa_verify_response(Key *, BIGNUM *, u_char[]); 11598684Sdesint auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **); 11676259Sgreen 11798684Sdesint auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 11898684Sdesint hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 11998684Sdesint user_key_allowed(struct passwd *, Key *); 12098684Sdes 12192559Sdes#ifdef KRB5 122106130Sdesint auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *); 12392559Sdesint auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt); 12492559Sdesint auth_krb5_password(Authctxt *authctxt, const char *password); 125126277Sdesvoid krb5_cleanup_proc(Authctxt *authctxt); 12692559Sdes#endif /* KRB5 */ 12776259Sgreen 128126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE) 129126277Sdes#include <shadow.h> 130126277Sdesint auth_shadow_acctexpired(struct spwd *); 131126277Sdesint auth_shadow_pwexpired(Authctxt *); 132126277Sdes#endif 133126277Sdes 13498941Sdes#include "auth-pam.h" 135147005Sdes#include "audit.h" 136147005Sdesvoid remove_kbdint_device(const char *); 137147005Sdes 138126277Sdesvoid disable_forwarding(void); 13998941Sdes 140126277Sdesvoid do_authentication(Authctxt *); 141126277Sdesvoid do_authentication2(Authctxt *); 14260573Skris 14392559Sdesvoid auth_log(Authctxt *, int, char *, char *); 14492559Sdesvoid userauth_finish(Authctxt *, int, char *); 145147005Sdesvoid userauth_send_banner(const char *); 14692559Sdesint auth_root_allowed(char *); 14760573Skris 14898684Sdeschar *auth2_read_banner(void); 14998684Sdes 15098684Sdesvoid privsep_challenge_enable(void); 15198684Sdes 15292559Sdesint auth2_challenge(Authctxt *, char *); 15392559Sdesvoid auth2_challenge_stop(Authctxt *); 15498684Sdesint bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 15598684Sdesint bsdauth_respond(void *, u_int, char **); 15698684Sdesint skey_query(void *, char **, char **, u_int *, char ***, u_int **); 15798684Sdesint skey_respond(void *, u_int, char **); 15860573Skris 15992559Sdesint allowed_user(struct passwd *); 16098684Sdesstruct passwd * getpwnamallow(const char *user); 16176259Sgreen 16292559Sdeschar *get_challenge(Authctxt *); 16392559Sdesint verify_response(Authctxt *, const char *); 164112870Sdesvoid abandon_challenge_response(Authctxt *); 16576259Sgreen 16692559Sdeschar *authorized_keys_file(struct passwd *); 16792559Sdeschar *authorized_keys_file2(struct passwd *); 16892559Sdes 169181111SdesFILE *auth_openkeyfile(const char *, struct passwd *, int); 17092559Sdes 17192559SdesHostStatus 17292559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 17392559Sdes const char *, const char *); 17492559Sdes 17598684Sdes/* hostkey handling */ 17698684SdesKey *get_hostkey_by_index(int); 17798684SdesKey *get_hostkey_by_type(int); 17898684Sdesint get_hostkey_index(Key *); 17998684Sdesint ssh1_session_key(BIGNUM *); 18098684Sdes 18198684Sdes/* debug messages during authentication */ 18298684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 18398684Sdesvoid auth_debug_send(void); 18498684Sdesvoid auth_debug_reset(void); 18598684Sdes 186124211Sdesstruct passwd *fakepw(void); 187124211Sdes 188147005Sdesint sys_auth_passwd(Authctxt *, const char *); 189147005Sdes 19060573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s" 19160573Skris 19298941Sdes#define SKEY_PROMPT "\nS/Key Password: " 193149753Sdes 194149753Sdes#if defined(KRB5) && !defined(HEIMDAL) 195149753Sdes#include <krb5.h> 196149753Sdeskrb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *); 19760573Skris#endif 19899046Sdes#endif 199