1263970Sdes/* $OpenBSD: auth.h,v 1.77 2014/01/29 06:18:35 djm 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; 56247485Sdes int server_caused_failure; 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; 63263970Sdes char *info; /* Extra info for next auth_log */ 6476259Sgreen#ifdef BSD_AUTH 6592559Sdes auth_session_t *as; 6676259Sgreen#endif 67251135Sdes char **auth_methods; /* modified from server config */ 68251135Sdes u_int num_auth_methods; 6992559Sdes#ifdef KRB5 7092559Sdes krb5_context krb5_ctx; 7192559Sdes krb5_ccache krb5_fwd_ccache; 7292559Sdes krb5_principal krb5_user; 7392559Sdes char *krb5_ticket_file; 74128460Sdes char *krb5_ccname; 7592559Sdes#endif 76147005Sdes Buffer *loginmsg; 77124211Sdes void *methoddata; 7869587Sgreen}; 79124211Sdes/* 80124211Sdes * Every authentication method has to handle authentication requests for 81124211Sdes * non-existing users, or for users that are not allowed to login. In this 82124211Sdes * case 'valid' is set to 0, but 'user' points to the username requested by 83124211Sdes * the client. 84124211Sdes */ 8569587Sgreen 8698684Sdesstruct Authmethod { 8798684Sdes char *name; 8898684Sdes int (*userauth)(Authctxt *authctxt); 8998684Sdes int *enabled; 9098684Sdes}; 9198684Sdes 9276259Sgreen/* 9392559Sdes * Keyboard interactive device: 9492559Sdes * init_ctx returns: non NULL upon success 9592559Sdes * query returns: 0 - success, otherwise failure 9692559Sdes * respond returns: 0 - success, 1 - need further interaction, 9792559Sdes * otherwise - failure 9876259Sgreen */ 9992559Sdesstruct KbdintDevice 10092559Sdes{ 10192559Sdes const char *name; 10292559Sdes void* (*init_ctx)(Authctxt*); 10392559Sdes int (*query)(void *ctx, char **name, char **infotxt, 10492559Sdes u_int *numprompts, char ***prompts, u_int **echo_on); 10592559Sdes int (*respond)(void *ctx, u_int numresp, char **responses); 10692559Sdes void (*free_ctx)(void *ctx); 10792559Sdes}; 10876259Sgreen 10998684Sdesint auth_rhosts(struct passwd *, const char *); 11076259Sgreenint 11192559Sdesauth_rhosts2(struct passwd *, const char *, const char *, const char *); 11276259Sgreen 113126277Sdesint auth_rhosts_rsa(Authctxt *, char *, Key *); 11492559Sdesint auth_password(Authctxt *, const char *); 115126277Sdesint auth_rsa(Authctxt *, BIGNUM *); 11698684Sdesint auth_rsa_challenge_dialog(Key *); 11798684SdesBIGNUM *auth_rsa_generate_challenge(Key *); 11898684Sdesint auth_rsa_verify_response(Key *, BIGNUM *, u_char[]); 11998684Sdesint auth_rsa_key_allowed(struct passwd *, BIGNUM *, Key **); 12076259Sgreen 12198684Sdesint auth_rhosts_rsa_key_allowed(struct passwd *, char *, char *, Key *); 12298684Sdesint hostbased_key_allowed(struct passwd *, const char *, char *, Key *); 12398684Sdesint user_key_allowed(struct passwd *, Key *); 124263970Sdesvoid pubkey_auth_info(Authctxt *, const Key *, const char *, ...) 125263970Sdes __attribute__((__format__ (printf, 3, 4))); 12698684Sdes 127251135Sdesstruct stat; 128251135Sdesint auth_secure_path(const char *, struct stat *, const char *, uid_t, 129251135Sdes char *, size_t); 130251135Sdes 13192559Sdes#ifdef KRB5 132106130Sdesint auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *); 13392559Sdesint auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt); 13492559Sdesint auth_krb5_password(Authctxt *authctxt, const char *password); 135126277Sdesvoid krb5_cleanup_proc(Authctxt *authctxt); 13692559Sdes#endif /* KRB5 */ 13776259Sgreen 138126277Sdes#if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE) 139126277Sdes#include <shadow.h> 140126277Sdesint auth_shadow_acctexpired(struct spwd *); 141126277Sdesint auth_shadow_pwexpired(Authctxt *); 142126277Sdes#endif 143126277Sdes 14498941Sdes#include "auth-pam.h" 145147005Sdes#include "audit.h" 146147005Sdesvoid remove_kbdint_device(const char *); 147147005Sdes 148126277Sdesvoid disable_forwarding(void); 14998941Sdes 150126277Sdesvoid do_authentication(Authctxt *); 151126277Sdesvoid do_authentication2(Authctxt *); 15260573Skris 153263970Sdesvoid auth_info(Authctxt *authctxt, const char *, ...) 154263970Sdes __attribute__((__format__ (printf, 2, 3))) 155263970Sdes __attribute__((__nonnull__ (2))); 156263970Sdesvoid auth_log(Authctxt *, int, int, const char *, const char *); 157251135Sdesvoid userauth_finish(Authctxt *, int, const char *, const char *); 158251135Sdesint auth_root_allowed(const char *); 159251135Sdes 160147005Sdesvoid userauth_send_banner(const char *); 16160573Skris 16298684Sdeschar *auth2_read_banner(void); 163251135Sdesint auth2_methods_valid(const char *, int); 164263970Sdesint auth2_update_methods_lists(Authctxt *, const char *, const char *); 165251135Sdesint auth2_setup_methods_lists(Authctxt *); 166263970Sdesint auth2_method_allowed(Authctxt *, const char *, const char *); 16798684Sdes 16898684Sdesvoid privsep_challenge_enable(void); 16998684Sdes 17092559Sdesint auth2_challenge(Authctxt *, char *); 17192559Sdesvoid auth2_challenge_stop(Authctxt *); 17298684Sdesint bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **); 17398684Sdesint bsdauth_respond(void *, u_int, char **); 17498684Sdesint skey_query(void *, char **, char **, u_int *, char ***, u_int **); 17598684Sdesint skey_respond(void *, u_int, char **); 17660573Skris 17792559Sdesint allowed_user(struct passwd *); 17898684Sdesstruct passwd * getpwnamallow(const char *user); 17976259Sgreen 18092559Sdeschar *get_challenge(Authctxt *); 18192559Sdesint verify_response(Authctxt *, const char *); 182112870Sdesvoid abandon_challenge_response(Authctxt *); 18376259Sgreen 184247485Sdeschar *expand_authorized_keys(const char *, struct passwd *pw); 185215116Sdeschar *authorized_principals_file(struct passwd *); 18692559Sdes 187181111SdesFILE *auth_openkeyfile(const char *, struct passwd *, int); 188215116SdesFILE *auth_openprincipals(const char *, struct passwd *, int); 189204917Sdesint auth_key_is_revoked(Key *); 19092559Sdes 19192559SdesHostStatus 19292559Sdescheck_key_in_hostfiles(struct passwd *, Key *, const char *, 19392559Sdes const char *, const char *); 19492559Sdes 19598684Sdes/* hostkey handling */ 19698684SdesKey *get_hostkey_by_index(int); 197263970SdesKey *get_hostkey_public_by_index(int); 198204917SdesKey *get_hostkey_public_by_type(int); 199204917SdesKey *get_hostkey_private_by_type(int); 20098684Sdesint get_hostkey_index(Key *); 20198684Sdesint ssh1_session_key(BIGNUM *); 202263970Sdesvoid sshd_hostkey_sign(Key *, Key *, u_char **, u_int *, u_char *, u_int); 20398684Sdes 20498684Sdes/* debug messages during authentication */ 20598684Sdesvoid auth_debug_add(const char *fmt,...) __attribute__((format(printf, 1, 2))); 20698684Sdesvoid auth_debug_send(void); 20798684Sdesvoid auth_debug_reset(void); 20898684Sdes 209124211Sdesstruct passwd *fakepw(void); 210124211Sdes 211147005Sdesint sys_auth_passwd(Authctxt *, const char *); 212147005Sdes 21360573Skris#define AUTH_FAIL_MSG "Too many authentication failures for %.100s" 21460573Skris 21598941Sdes#define SKEY_PROMPT "\nS/Key Password: " 216149753Sdes 217149753Sdes#if defined(KRB5) && !defined(HEIMDAL) 218149753Sdes#include <krb5.h> 219149753Sdeskrb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *); 22060573Skris#endif 22199046Sdes#endif 222