blob: c7175405d83d3e165c0ad95592575267f5ff4c85 [file] [log] [blame]
Ben Lindstrom05764b92002-03-05 01:53:02 +00001/* $OpenBSD: auth.h,v 1.29 2002/03/04 17:27:39 stevesk Exp $ */
2
Damien Millere4340be2000-09-16 13:29:08 +11003/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ben Lindstrom4dccfa52000-12-28 16:40:05 +000025 *
Damien Millere4340be2000-09-16 13:29:08 +110026 */
Ben Lindstrom05764b92002-03-05 01:53:02 +000027
Damien Millerb38eff82000-04-01 11:09:21 +100028#ifndef AUTH_H
29#define AUTH_H
30
Ben Lindstrom83647ce2001-06-25 04:30:16 +000031#include "key.h"
32#include "hostfile.h"
Ben Lindstrom226cfa02001-01-22 05:34:40 +000033#include <openssl/rsa.h>
34
Damien Miller60396b02001-02-18 17:01:00 +110035#ifdef HAVE_LOGIN_CAP
36#include <login_cap.h>
37#endif
38#ifdef BSD_AUTH
39#include <bsd_auth.h>
40#endif
Ben Lindstromec95ed92001-07-04 04:21:14 +000041#ifdef KRB5
42#include <krb5.h>
43#endif
Damien Miller60396b02001-02-18 17:01:00 +110044
Damien Miller874d77b2000-10-14 16:23:11 +110045typedef struct Authctxt Authctxt;
Ben Lindstrom551ea372001-06-05 18:56:16 +000046typedef struct KbdintDevice KbdintDevice;
47
Damien Miller874d77b2000-10-14 16:23:11 +110048struct Authctxt {
Ben Lindstromec95ed92001-07-04 04:21:14 +000049 int success;
50 int postponed;
51 int valid;
52 int attempt;
53 int failures;
54 char *user;
55 char *service;
56 struct passwd *pw;
57 char *style;
58 void *kbdintctxt;
Damien Miller60396b02001-02-18 17:01:00 +110059#ifdef BSD_AUTH
Ben Lindstromec95ed92001-07-04 04:21:14 +000060 auth_session_t *as;
61#endif
62#ifdef KRB4
63 char *krb4_ticket_file;
64#endif
65#ifdef KRB5
66 krb5_context krb5_ctx;
67 krb5_auth_context krb5_auth_ctx;
68 krb5_ccache krb5_fwd_ccache;
69 krb5_principal krb5_user;
70 char *krb5_ticket_file;
Damien Miller60396b02001-02-18 17:01:00 +110071#endif
Damien Miller874d77b2000-10-14 16:23:11 +110072};
73
Ben Lindstrom226cfa02001-01-22 05:34:40 +000074/*
Ben Lindstrom551ea372001-06-05 18:56:16 +000075 * Keyboard interactive device:
Damien Miller9f0f5c62001-12-21 14:45:46 +110076 * init_ctx returns: non NULL upon success
77 * query returns: 0 - success, otherwise failure
Ben Lindstrom551ea372001-06-05 18:56:16 +000078 * respond returns: 0 - success, 1 - need further interaction,
79 * otherwise - failure
80 */
81struct KbdintDevice
82{
83 const char *name;
Damien Millerb0462112002-02-19 15:24:43 +110084 void* (*init_ctx)(Authctxt*);
Damien Millera93c6d82002-02-19 15:25:29 +110085 int (*query)(void *ctx, char **name, char **infotxt,
86 u_int *numprompts, char ***prompts, u_int **echo_on);
Damien Millerb0462112002-02-19 15:24:43 +110087 int (*respond)(void *ctx, u_int numresp, char **responses);
88 void (*free_ctx)(void *ctx);
Ben Lindstrom551ea372001-06-05 18:56:16 +000089};
90
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000091int auth_rhosts(struct passwd *, const char *);
Ben Lindstrom5eabda32001-04-12 23:34:34 +000092int
Ben Lindstrom16ae3d02001-07-04 04:02:36 +000093auth_rhosts2(struct passwd *, const char *, const char *, const char *);
Ben Lindstrom5eabda32001-04-12 23:34:34 +000094
Damien Millerd221ca62002-01-22 23:11:00 +110095int auth_rhosts_rsa(struct passwd *, const char *, Key *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000096int auth_password(Authctxt *, const char *);
97int auth_rsa(struct passwd *, BIGNUM *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +000098int auth_rsa_challenge_dialog(RSA *);
Ben Lindstrom226cfa02001-01-22 05:34:40 +000099
100#ifdef KRB4
101#include <krb.h>
Ben Lindstromec95ed92001-07-04 04:21:14 +0000102int auth_krb4(Authctxt *, KTEXT, char **);
103int auth_krb4_password(Authctxt *, const char *);
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000104void krb4_cleanup_proc(void *);
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000105
106#ifdef AFS
107#include <kafs.h>
Ben Lindstromec95ed92001-07-04 04:21:14 +0000108int auth_krb4_tgt(Authctxt *, const char *);
109int auth_afs_token(Authctxt *, const char *);
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000110#endif /* AFS */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000111
Ben Lindstrom4cc240d2001-07-04 04:46:56 +0000112#endif /* KRB4 */
Ben Lindstrom226cfa02001-01-22 05:34:40 +0000113
Ben Lindstromec95ed92001-07-04 04:21:14 +0000114#ifdef KRB5
115int auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client);
116int auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
117int auth_krb5_password(Authctxt *authctxt, const char *password);
118void krb5_cleanup_proc(void *authctxt);
119#endif /* KRB5 */
120
Damien Millerb8481582000-12-03 11:51:51 +1100121#include "auth-pam.h"
122#include "auth2-pam.h"
123
Damien Millerb38eff82000-04-01 11:09:21 +1000124void do_authentication(void);
Damien Millerefb4afe2000-04-12 18:45:05 +1000125void do_authentication2(void);
126
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000127Authctxt *authctxt_new(void);
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000128void auth_log(Authctxt *, int, char *, char *);
129void userauth_finish(Authctxt *, int, char *);
130int auth_root_allowed(char *);
Damien Millerb38eff82000-04-01 11:09:21 +1000131
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000132int auth2_challenge(Authctxt *, char *);
Damien Milleree116252001-12-21 12:42:34 +1100133void auth2_challenge_stop(Authctxt *);
Damien Miller874d77b2000-10-14 16:23:11 +1100134
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000135int allowed_user(struct passwd *);
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000136
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000137char *get_challenge(Authctxt *);
138int verify_response(Authctxt *, const char *);
Ben Lindstromdb65e8f2001-01-19 04:26:52 +0000139
Damien Miller874d77b2000-10-14 16:23:11 +1100140struct passwd * auth_get_user(void);
Damien Millereba71ba2000-04-29 23:57:08 +1000141
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000142char *expand_filename(const char *, struct passwd *);
143char *authorized_keys_file(struct passwd *);
144char *authorized_keys_file2(struct passwd *);
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000145
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000146int
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000147secure_filename(FILE *, const char *, struct passwd *, char *, size_t);
Ben Lindstrombfb3a0e2001-06-05 20:25:05 +0000148
Ben Lindstrom83647ce2001-06-25 04:30:16 +0000149HostStatus
Ben Lindstrom16ae3d02001-07-04 04:02:36 +0000150check_key_in_hostfiles(struct passwd *, Key *, const char *,
151 const char *, const char *);
Ben Lindstrom83647ce2001-06-25 04:30:16 +0000152
Damien Millereba71ba2000-04-29 23:57:08 +1000153#define AUTH_FAIL_MAX 6
154#define AUTH_FAIL_LOG (AUTH_FAIL_MAX/2)
155#define AUTH_FAIL_MSG "Too many authentication failures for %.100s"
156
Damien Millerb38eff82000-04-01 11:09:21 +1000157#endif