Remove auth/ntlm as a dependency of GENSEC by means of function pointers.
[samba.git] / source4 / auth / auth.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett   2001
5    Copyright (C) Stefan Metzmacher 2005
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _SAMBA_AUTH_H
22 #define _SAMBA_AUTH_H
23
24 #include "librpc/gen_ndr/ndr_krb5pac.h"
25
26 extern const char *user_attrs[];
27
28 union netr_Validation;
29 struct netr_SamBaseInfo;
30 struct netr_SamInfo3;
31 struct loadparm_context;
32
33 /* modules can use the following to determine if the interface has changed
34  * please increment the version number after each interface change
35  * with a comment and maybe update struct auth_critical_sizes.
36  */
37 /* version 1 - version from samba 3.0 - metze */
38 /* version 2 - initial samba4 version - metze */
39 /* version 3 - subsequent samba4 version - abartlet */
40 /* version 4 - subsequent samba4 version - metze */
41 /* version 0 - till samba4 is stable - metze */
42 #define AUTH_INTERFACE_VERSION 0
43
44 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
45 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
46 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* dont check unix account status */
47 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* dont check unix account status */
48
49 enum auth_password_state {
50         AUTH_PASSWORD_RESPONSE,
51         AUTH_PASSWORD_HASH,
52         AUTH_PASSWORD_PLAIN
53 };
54
55 struct auth_usersupplied_info
56 {
57         const char *workstation_name;
58         struct socket_address *remote_host;
59
60         uint32_t logon_parameters;
61
62         bool mapped_state;
63         /* the values the client gives us */
64         struct {
65                 const char *account_name;
66                 const char *domain_name;
67         } client, mapped;
68
69         enum auth_password_state password_state;
70
71         union {
72                 struct {
73                         DATA_BLOB lanman;
74                         DATA_BLOB nt;
75                 } response;
76                 struct {
77                         struct samr_Password *lanman;
78                         struct samr_Password *nt;
79                 } hash;
80                 
81                 char *plaintext;
82         } password;
83         uint32_t flags;
84 };
85
86 struct auth_serversupplied_info 
87 {
88         struct dom_sid *account_sid;
89         struct dom_sid *primary_group_sid;
90
91         size_t n_domain_groups;
92         struct dom_sid **domain_groups;
93
94         DATA_BLOB user_session_key;
95         DATA_BLOB lm_session_key;
96
97         const char *account_name;
98         const char *domain_name;
99
100         const char *full_name;
101         const char *logon_script;
102         const char *profile_path;
103         const char *home_directory;
104         const char *home_drive;
105         const char *logon_server;
106         
107         NTTIME last_logon;
108         NTTIME last_logoff;
109         NTTIME acct_expiry;
110         NTTIME last_password_change;
111         NTTIME allow_password_change;
112         NTTIME force_password_change;
113
114         uint16_t logon_count;
115         uint16_t bad_password_count;
116
117         uint32_t acct_flags;
118
119         bool authenticated;
120
121         struct PAC_SIGNATURE_DATA pac_srv_sig, pac_kdc_sig;
122 };
123
124 struct auth_method_context;
125 struct auth_check_password_request;
126
127 struct auth_operations {
128         const char *name;
129
130         /* If you are using this interface, then you are probably
131          * getting something wrong.  This interface is only for
132          * security=server, and makes a number of compromises to allow
133          * that.  It is not compatible with being a PDC.  */
134
135         NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, DATA_BLOB *challenge);
136
137         /* Given the user supplied info, check if this backend want to handle the password checking */
138
139         NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
140                                const struct auth_usersupplied_info *user_info);
141
142         /* Given the user supplied info, check a password */
143
144         NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
145                                    const struct auth_usersupplied_info *user_info,
146                                    struct auth_serversupplied_info **server_info);
147 };
148
149 struct auth_method_context {
150         struct auth_method_context *prev, *next;
151         struct auth_context *auth_ctx;
152         const struct auth_operations *ops;
153         int depth;
154         void *private_data;
155 };
156
157 struct auth_context {
158         struct {
159                 /* Who set this up in the first place? */ 
160                 const char *set_by;
161
162                 bool may_be_modified;
163
164                 DATA_BLOB data; 
165         } challenge;
166
167         /* methods, in the order they should be called */
168         struct auth_method_context *methods;
169
170         /* the event context to use for calls that can block */
171         struct tevent_context *event_ctx;
172
173         /* the messaging context which can be used by backends */
174         struct messaging_context *msg_ctx;
175
176         /* loadparm context */
177         struct loadparm_context *lp_ctx;
178
179         NTSTATUS (*check_password)(struct auth_context *auth_ctx,
180                                    TALLOC_CTX *mem_ctx,
181                                    const struct auth_usersupplied_info *user_info, 
182                                    struct auth_serversupplied_info **server_info);
183         
184         NTSTATUS (*get_challenge)(struct auth_context *auth_ctx, const uint8_t **_chal);
185
186         bool (*challenge_may_be_modified)(struct auth_context *auth_ctx);
187
188         NTSTATUS (*set_challenge)(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
189         
190         
191
192 };
193
194 /* this structure is used by backends to determine the size of some critical types */
195 struct auth_critical_sizes {
196         int interface_version;
197         int sizeof_auth_operations;
198         int sizeof_auth_methods;
199         int sizeof_auth_context;
200         int sizeof_auth_usersupplied_info;
201         int sizeof_auth_serversupplied_info;
202 };
203
204  NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context, 
205                            enum auth_password_state to_state,
206                            const struct auth_usersupplied_info *user_info_in,
207                            const struct auth_usersupplied_info **user_info_encrypted);
208
209 #include "auth/session.h"
210 #include "auth/system_session_proto.h"
211
212 struct ldb_message;
213 struct ldb_context;
214 struct gensec_security;
215
216 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, const uint8_t **_chal);
217 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
218                             struct ldb_context *sam_ctx,
219                             uint32_t logon_parameters,
220                             struct ldb_message *msg,
221                             struct ldb_message *msg_domain_ref,
222                             const char *logon_workstation,
223                             const char *name_for_logs,
224                             bool allow_domain_trust);
225 struct auth_session_info *system_session(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
226 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
227                                            const char *netbios_name,
228                                            struct ldb_message *msg,
229                                            struct ldb_message *msg_domain_ref,
230                                            DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
231                                            struct auth_serversupplied_info **_server_info);
232 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx, 
233                                            struct loadparm_context *lp_ctx,
234                                            struct auth_session_info **_session_info) ;
235 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
236
237 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods, 
238                                      struct tevent_context *ev,
239                                      struct messaging_context *msg,
240                                      struct loadparm_context *lp_ctx,
241                                      struct auth_context **auth_ctx);
242
243 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx, 
244                              struct tevent_context *ev,
245                              struct messaging_context *msg,
246                              struct loadparm_context *lp_ctx,
247                              struct auth_context **auth_ctx);
248
249 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
250                              TALLOC_CTX *mem_ctx,
251                              const struct auth_usersupplied_info *user_info, 
252                              struct auth_serversupplied_info **server_info);
253 NTSTATUS auth_init(void);
254 NTSTATUS auth_register(const struct auth_operations *ops);
255 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
256                                            struct tevent_context *ev,
257                                            struct messaging_context *msg,
258                                            struct loadparm_context *lp_ctx,
259                                            const char *nt4_domain,
260                                            const char *nt4_username,
261                                            const char *password,
262                                            struct auth_session_info **session_info);
263 NTSTATUS auth_check_password_recv(struct auth_check_password_request *req,
264                                   TALLOC_CTX *mem_ctx,
265                                   struct auth_serversupplied_info **server_info);
266
267 void auth_check_password_send(struct auth_context *auth_ctx,
268                               const struct auth_usersupplied_info *user_info,
269                               void (*callback)(struct auth_check_password_request *req, void *private_data),
270                               void *private_data);
271 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
272
273 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
274                                    struct tevent_context *event_ctx,
275                                    struct messaging_context *msg_ctx,
276                                    struct loadparm_context *lp_ctx,
277                                    struct cli_credentials *server_credentials,
278                                    const char *target_service,
279                                    struct gensec_security **gensec_context);
280
281 #endif /* _SMBAUTH_H_ */