1296853Sdes/* $OpenBSD: auth.h,v 1.86 2015/12/04 16:41:28 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 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 45295367Sdesstruct ssh; 46295367Sdesstruct sshkey; 47295367Sdes 4869587Sgreentypedef struct Authctxt Authctxt; 4998684Sdestypedef struct Authmethod Authmethod; 5092559Sdestypedef struct KbdintDevice KbdintDevice; 5192559Sdes 5269587Sgreenstruct Authctxt { 53162856Sdes sig_atomic_t success; 54162856Sdes int authenticated; /* authenticated and alarms cancelled */ 55124211Sdes int postponed; /* authentication needs another step */ 56124211Sdes int valid; /* user exists and is allowed to login */ 5792559Sdes int attempt; 5892559Sdes int failures; 59295367Sdes int server_caused_failure; 60126277Sdes int force_pwchange; 61124211Sdes char *user; /* username sent by the client */ 6292559Sdes char *service; 63124211Sdes struct passwd *pw; /* set if 'valid' */ 6492559Sdes char *style; 6592559Sdes void *kbdintctxt; 66255767Sdes char *info; /* Extra info for next auth_log */ 6776259Sgreen#ifdef BSD_AUTH 6892559Sdes auth_session_t *as; 6976259Sgreen#endif 70248619Sdes char **auth_methods; /* modified from server config */ 71248619Sdes u_int num_auth_methods; 7292559Sdes#ifdef KRB5 7392559Sdes krb5_context krb5_ctx; 7492559Sdes krb5_ccache krb5_fwd_ccache; 7592559Sdes krb5_principal krb5_user; 7692559Sdes char *krb5_ticket_file; 77128460Sdes char *krb5_ccname; 7892559Sdes#endif 79147005Sdes Buffer *loginmsg; 80124211Sdes void *methoddata; 81295367Sdes 82295367Sdes struct sshkey **prev_userkeys; 83295367Sdes u_int nprev_userkeys; 8469587Sgreen}; 85124211Sdes/* 86124211Sdes * Every authentication method has to handle authentication requests for 87124211Sdes * non-existing users, or for users that are not allowed to login. In this 88124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by 89124211Sdes * the client. 90124211Sdes */ 9169587Sgreen 9298684Sdesstruct Authmethod { 9398684Sdes char *name; 9498684Sdes int (*userauth)(Authctxt *authctxt); 9598684Sdes int *enabled; 9698684Sdes}; 9798684Sdes 9876259Sgreen/* 9992559Sdes * Keyboard interactive device: 10092559Sdes * init_ctx returns: non NULL upon success 10192559Sdes * query returns: 0 - success, otherwise failure 10292559Sdes * respond returns: 0 - success, 1 - need further interaction, 10392559Sdes * otherwise - failure 10476259Sgreen */ 10592559Sdesstruct KbdintDevice 10692559Sdes{ 10792559Sdes const char *name; 10892559Sdes void* (*init_ctx)(Authctxt*); 10992559Sdes int (*query)(void *ctx, char **name, char **infotxt, 11092559Sdes u_int *numprompts, char ***prompts, u_int **echo_on); 11192559Sdes int (*respond)(void *ctx, u_int numresp, char **responses); 11292559Sdes void (*free_ctx)(void *ctx); 11392559Sdes}; 11476259Sgreen 11598684Sdesint auth_rhosts(struct passwd *, const char *); 11676259Sgreenint 11792559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *); 11876259Sgreen 119126277Sdesint auth_rhosts_rsa(Authctxt *, char *, Key *); 12092559Sdesint auth_password(Authctxt *, const char *); 121126277Sdesint auth_rsa(Authctxt *, BIGNUM *); 12298684Sdesint auth_rsa_challenge_dialog(Key *); 12398684SdesBIGNUM *auth_rsa_generate_challenge(Key *); 12498684Sdesint auth_rsa_verify_response(Key *, BIGNUM *, u_char[]); 12598684Sdesint auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **); 12676259Sgreen 12798684Sdesint auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 12898684Sdesint hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 129295367Sdesint user_key_allowed(struct passwd *, Key *, int); 130255767Sdesvoid pubkey_auth_info(Authctxt *, const Key *, const char *, ...) 131255767Sdes __attribute__((__format__ (printf, 3, 4))); 132295367Sdesvoid auth2_record_userkey(Authctxt *, struct sshkey *); 133295367Sdesint auth2_userkey_already_used(Authctxt *, struct sshkey *); 13498684Sdes 135248619Sdesstruct stat; 136248619Sdesint auth_secure_path(const char *, struct stat *, const char *, uid_t, 137248619Sdes char *, size_t); 138248619Sdes 13992559Sdes#ifdef KRB5 140106130Sdesint auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *); 14192559Sdesint auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt); 14292559Sdesint auth_krb5_password(Authctxt *authctxt, const char *password); 143126277Sdesvoid krb5_cleanup_proc(Authctxt *authctxt); 14492559Sdes#endif /* KRB5 */ 14576259Sgreen 146126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE) 147126277Sdes#include <shadow.h> 148126277Sdesint auth_shadow_acctexpired(struct spwd *); 149126277Sdesint auth_shadow_pwexpired(Authctxt *); 150126277Sdes#endif 151126277Sdes 15298941Sdes#include "auth-pam.h" 153147005Sdes#include "audit.h" 154147005Sdesvoid remove_kbdint_device(const char *); 155147005Sdes 156126277Sdesvoid disable_forwarding(void); 15798941Sdes 158126277Sdesvoid do_authentication(Authctxt *); 159126277Sdesvoid do_authentication2(Authctxt *); 16060573Skris 161255767Sdesvoid auth_info(Authctxt *authctxt, const char *, ...) 162255767Sdes __attribute__((__format__ (printf, 2, 3))) 163255767Sdes __attribute__((__nonnull__ (2))); 164255767Sdesvoid auth_log(Authctxt *, int, int, const char *, const char *); 165295367Sdesvoid auth_maxtries_exceeded(Authctxt *) __attribute__((noreturn)); 166248619Sdesvoid userauth_finish(Authctxt *, int, const char *, const char *); 167248619Sdesint auth_root_allowed(const char *); 168248619Sdes 169147005Sdesvoid userauth_send_banner(const char *); 17060573Skris 17198684Sdeschar *auth2_read_banner(void); 172248619Sdesint auth2_methods_valid(const char *, int); 173255767Sdesint auth2_update_methods_lists(Authctxt *, const char *, const char *); 174248619Sdesint auth2_setup_methods_lists(Authctxt *); 175255767Sdesint auth2_method_allowed(Authctxt *, const char *, const char *); 17698684Sdes 17798684Sdesvoid privsep_challenge_enable(void); 17898684Sdes 17992559Sdesint auth2_challenge(Authctxt *, char *); 18092559Sdesvoid auth2_challenge_stop(Authctxt *); 18198684Sdesint bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 18298684Sdesint bsdauth_respond(void *, u_int, char **); 18398684Sdesint skey_query(void *, char **, char **, u_int *, char ***, u_int **); 18498684Sdesint skey_respond(void *, u_int, char **); 18560573Skris 18692559Sdesint allowed_user(struct passwd *); 18798684Sdesstruct passwd * getpwnamallow(const char *user); 18876259Sgreen 18992559Sdeschar *get_challenge(Authctxt *); 19092559Sdesint verify_response(Authctxt *, const char *); 191112870Sdesvoid abandon_challenge_response(Authctxt *); 19276259Sgreen 193226046Sdeschar *expand_authorized_keys(const char *, struct passwd *pw); 194215116Sdeschar *authorized_principals_file(struct passwd *); 19592559Sdes 196181111SdesFILE *auth_openkeyfile(const char *, struct passwd *, int); 197215116SdesFILE *auth_openprincipals(const char *, struct passwd *, int); 198204917Sdesint auth_key_is_revoked(Key *); 19992559Sdes 20092559SdesHostStatus 20192559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 20292559Sdes const char *, const char *); 20392559Sdes 20498684Sdes/* hostkey handling */ 20598684SdesKey *get_hostkey_by_index(int); 206295367SdesKey *get_hostkey_public_by_index(int, struct ssh *); 207295367SdesKey *get_hostkey_public_by_type(int, int, struct ssh *); 208295367SdesKey *get_hostkey_private_by_type(int, int, struct ssh *); 209295367Sdesint get_hostkey_index(Key *, int, struct ssh *); 21098684Sdesint ssh1_session_key(BIGNUM *); 211295367Sdesint sshd_hostkey_sign(Key *, Key *, u_char **, size_t *, 212296853Sdes const u_char *, size_t, const char *, u_int); 21398684Sdes 21498684Sdes/* debug messages during authentication */ 21598684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 21698684Sdesvoid auth_debug_send(void); 21798684Sdesvoid auth_debug_reset(void); 21898684Sdes 219124211Sdesstruct passwd *fakepw(void); 220124211Sdes 221147005Sdesint sys_auth_passwd(Authctxt *, const char *); 222147005Sdes 22398941Sdes#define SKEY_PROMPT "\nS/Key Password: " 224149753Sdes 225149753Sdes#if defined(KRB5) && !defined(HEIMDAL) 226149753Sdes#include <krb5.h> 227149753Sdeskrb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *); 22860573Skris#endif 22999046Sdes#endif 230