auth.h revision 98941
198684Sdes/* $OpenBSD: auth.h,v 1.39 2002/05/31 11:35:15 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 3192559Sdes#include "key.h" 3292559Sdes#include "hostfile.h" 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 { 5092559Sdes int success; 5192559Sdes int postponed; 5292559Sdes int valid; 5392559Sdes int attempt; 5492559Sdes int failures; 5592559Sdes char *user; 5692559Sdes char *service; 5792559Sdes struct passwd *pw; 5892559Sdes char *style; 5992559Sdes void *kbdintctxt; 6076259Sgreen#ifdef BSD_AUTH 6192559Sdes auth_session_t *as; 6276259Sgreen#endif 6392559Sdes#ifdef KRB4 6492559Sdes char *krb4_ticket_file; 6592559Sdes#endif 6692559Sdes#ifdef KRB5 6792559Sdes krb5_context krb5_ctx; 6892559Sdes krb5_auth_context krb5_auth_ctx; 6992559Sdes krb5_ccache krb5_fwd_ccache; 7092559Sdes krb5_principal krb5_user; 7192559Sdes char *krb5_ticket_file; 7292559Sdes#endif 7369587Sgreen}; 7469587Sgreen 7598684Sdesstruct Authmethod { 7698684Sdes char *name; 7798684Sdes int (*userauth)(Authctxt *authctxt); 7898684Sdes int *enabled; 7998684Sdes}; 8098684Sdes 8176259Sgreen/* 8292559Sdes * Keyboard interactive device: 8392559Sdes * init_ctx returns: non NULL upon success 8492559Sdes * query returns: 0 - success, otherwise failure 8592559Sdes * respond returns: 0 - success, 1 - need further interaction, 8692559Sdes * otherwise - failure 8776259Sgreen */ 8892559Sdesstruct KbdintDevice 8992559Sdes{ 9092559Sdes const char *name; 9192559Sdes void* (*init_ctx)(Authctxt*); 9292559Sdes int (*query)(void *ctx, char **name, char **infotxt, 9392559Sdes u_int *numprompts, char ***prompts, u_int **echo_on); 9492559Sdes int (*respond)(void *ctx, u_int numresp, char **responses); 9592559Sdes void (*free_ctx)(void *ctx); 9692559Sdes}; 9776259Sgreen 9898684Sdesint auth_rhosts(struct passwd *, const char *); 9976259Sgreenint 10092559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *); 10176259Sgreen 10298684Sdesint auth_rhosts_rsa(struct passwd *, char *, Key *); 10392559Sdesint auth_password(Authctxt *, const char *); 10492559Sdesint auth_rsa(struct passwd *, BIGNUM *); 10598684Sdesint auth_rsa_challenge_dialog(Key *); 10698684SdesBIGNUM *auth_rsa_generate_challenge(Key *); 10798684Sdesint auth_rsa_verify_response(Key *, BIGNUM *, u_char[]); 10898684Sdesint auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **); 10976259Sgreen 11098684Sdesint auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 11198684Sdesint hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 11298684Sdesint user_key_allowed(struct passwd *, Key *); 11398684Sdes 11478263Smarkm#ifdef KRB4 11578263Smarkm#include <krb.h> 11692559Sdesint auth_krb4(Authctxt *, KTEXT, char **); 11792559Sdesint auth_krb4_password(Authctxt *, const char *); 11892559Sdesvoid krb4_cleanup_proc(void *); 11976262Sgreen 12076259Sgreen#ifdef AFS 12176259Sgreen#include <kafs.h> 12292559Sdesint auth_krb4_tgt(Authctxt *, const char *); 12392559Sdesint auth_afs_token(Authctxt *, const char *); 12492559Sdes#endif /* AFS */ 12576259Sgreen 12692559Sdes#endif /* KRB4 */ 12776259Sgreen 12892559Sdes#ifdef KRB5 12992559Sdesint auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client); 13092559Sdesint auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt); 13192559Sdesint auth_krb5_password(Authctxt *authctxt, const char *password); 13292559Sdesvoid krb5_cleanup_proc(void *authctxt); 13392559Sdes#endif /* KRB5 */ 13476259Sgreen 13598941Sdes#include "auth-pam.h" 13698941Sdes#include "auth2-pam.h" 13798941Sdes 13898684SdesAuthctxt *do_authentication(void); 13998684SdesAuthctxt *do_authentication2(void); 14060573Skris 14176259SgreenAuthctxt *authctxt_new(void); 14292559Sdesvoid auth_log(Authctxt *, int, char *, char *); 14392559Sdesvoid userauth_finish(Authctxt *, int, char *); 14492559Sdesint auth_root_allowed(char *); 14560573Skris 14698684Sdeschar *auth2_read_banner(void); 14798684Sdes 14898684Sdesvoid privsep_challenge_enable(void); 14998684Sdes 15092559Sdesint auth2_challenge(Authctxt *, char *); 15192559Sdesvoid auth2_challenge_stop(Authctxt *); 15298684Sdesint bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 15398684Sdesint bsdauth_respond(void *, u_int, char **); 15498684Sdesint skey_query(void *, char **, char **, u_int *, char ***, u_int **); 15598684Sdesint skey_respond(void *, u_int, char **); 15660573Skris 15792559Sdesint allowed_user(struct passwd *); 15898684Sdesstruct passwd * getpwnamallow(const char *user); 15976259Sgreen 16092559Sdeschar *get_challenge(Authctxt *); 16192559Sdesint verify_response(Authctxt *, const char *); 16276259Sgreen 16369587Sgreenstruct passwd * auth_get_user(void); 16469587Sgreen 16592559Sdeschar *expand_filename(const char *, struct passwd *); 16692559Sdeschar *authorized_keys_file(struct passwd *); 16792559Sdeschar *authorized_keys_file2(struct passwd *); 16892559Sdes 16992559Sdesint 17092559Sdessecure_filename(FILE *, const char *, struct passwd *, char *, size_t); 17192559Sdes 17292559SdesHostStatus 17392559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 17492559Sdes const char *, const char *); 17592559Sdes 17698684Sdes/* hostkey handling */ 17798684SdesKey *get_hostkey_by_index(int); 17898684SdesKey *get_hostkey_by_type(int); 17998684Sdesint get_hostkey_index(Key *); 18098684Sdesint ssh1_session_key(BIGNUM *); 18198684Sdes 18298684Sdes/* debug messages during authentication */ 18398684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 18498684Sdesvoid auth_debug_send(void); 18598684Sdesvoid auth_debug_reset(void); 18698684Sdes 18760573Skris#define AUTH_FAIL_MAX 6 18860573Skris#define AUTH_FAIL_LOG (AUTH_FAIL_MAX/2) 18960573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s" 19060573Skris 19198941Sdes#define SKEY_PROMPT "\nS/Key Password: " 19260573Skris#endif 193