auth: make auth4_context common to provide access to generate_session_info_pac()
[metze/samba/wip.git] / auth / common_auth.h
1 /*
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett 2001-2010
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef AUTH_COMMON_AUTH_H
21 #define AUTH_COMMON_AUTH_H
22
23 #include "librpc/gen_ndr/auth.h"
24
25 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
26 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
27 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* don't check unix account status */
28 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* don't check unix account status */
29
30 enum auth_password_state {
31         AUTH_PASSWORD_PLAIN = 1,
32         AUTH_PASSWORD_HASH = 2,
33         AUTH_PASSWORD_RESPONSE = 3
34 };
35
36 struct auth_usersupplied_info
37 {
38         const char *workstation_name;
39         const struct tsocket_address *remote_host;
40
41         uint32_t logon_parameters;
42
43         bool mapped_state;
44         bool was_mapped;
45         /* the values the client gives us */
46         struct {
47                 const char *account_name;
48                 const char *domain_name;
49         } client, mapped;
50
51         enum auth_password_state password_state;
52
53         struct {
54                 struct {
55                         DATA_BLOB lanman;
56                         DATA_BLOB nt;
57                 } response;
58                 struct {
59                         struct samr_Password *lanman;
60                         struct samr_Password *nt;
61                 } hash;
62
63                 char *plaintext;
64         } password;
65         uint32_t flags;
66 };
67
68 struct auth_method_context;
69 struct tevent_context;
70 struct imessaging_context;
71 struct loadparm_context;
72 struct ldb_context;
73 struct smb_krb5_context;
74
75 struct auth4_context {
76         struct {
77                 /* Who set this up in the first place? */
78                 const char *set_by;
79
80                 bool may_be_modified;
81
82                 DATA_BLOB data;
83         } challenge;
84
85         /* methods, in the order they should be called */
86         struct auth_method_context *methods;
87
88         /* the event context to use for calls that can block */
89         struct tevent_context *event_ctx;
90
91         /* the messaging context which can be used by backends */
92         struct imessaging_context *msg_ctx;
93
94         /* loadparm context */
95         struct loadparm_context *lp_ctx;
96
97         /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
98         struct ldb_context *sam_ctx;
99
100         NTSTATUS (*check_password)(struct auth4_context *auth_ctx,
101                                    TALLOC_CTX *mem_ctx,
102                                    const struct auth_usersupplied_info *user_info,
103                                    struct auth_user_info_dc **user_info_dc);
104
105         NTSTATUS (*get_challenge)(struct auth4_context *auth_ctx, uint8_t chal[8]);
106
107         bool (*challenge_may_be_modified)(struct auth4_context *auth_ctx);
108
109         NTSTATUS (*set_challenge)(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
110
111         NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
112                                           struct auth4_context *auth_context,
113                                           struct auth_user_info_dc *user_info_dc,
114                                           uint32_t session_info_flags,
115                                           struct auth_session_info **session_info);
116
117         NTSTATUS (*generate_session_info_pac)(struct auth4_context *auth_ctx,
118                                               TALLOC_CTX *mem_ctx,
119                                               struct smb_krb5_context *smb_krb5_context,
120                                               DATA_BLOB *pac_blob,
121                                               const char *principal_name,
122                                               const struct tsocket_address *remote_address,
123                                               uint32_t session_info_flags,
124                                               struct auth_session_info **session_info);
125 };
126
127 #endif