s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[nivanova/samba-autobuild/.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 *krbtgt_attrs[];
27 extern const char *server_attrs[];
28 extern const char *user_attrs[];
29
30 union netr_Validation;
31 struct netr_SamBaseInfo;
32 struct netr_SamInfo3;
33 struct loadparm_context;
34
35 /* modules can use the following to determine if the interface has changed
36  * please increment the version number after each interface change
37  * with a comment and maybe update struct auth_critical_sizes.
38  */
39 /* version 1 - version from samba 3.0 - metze */
40 /* version 2 - initial samba4 version - metze */
41 /* version 3 - subsequent samba4 version - abartlet */
42 /* version 4 - subsequent samba4 version - metze */
43 /* version 0 - till samba4 is stable - metze */
44 #define AUTH_INTERFACE_VERSION 0
45
46 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
47 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
48 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* don't check unix account status */
49 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* don't check unix account status */
50
51 #define AUTH_SESSION_INFO_DEFAULT_GROUPS 0x01 /* Add the user to the default world and network groups */
52 #define AUTH_SESSION_INFO_AUTHENTICATED  0x02 /* Add the user to the 'authenticated users' group */
53 #define AUTH_SESSION_INFO_ENTERPRISE_DC  0x04 /* Add the user to the 'enterprise DC' group */
54
55 enum auth_password_state {
56         AUTH_PASSWORD_RESPONSE,
57         AUTH_PASSWORD_HASH,
58         AUTH_PASSWORD_PLAIN
59 };
60
61 struct auth_usersupplied_info
62 {
63         const char *workstation_name;
64         const struct tsocket_address *remote_host;
65
66         uint32_t logon_parameters;
67
68         bool mapped_state;
69         /* the values the client gives us */
70         struct {
71                 const char *account_name;
72                 const char *domain_name;
73         } client, mapped;
74
75         enum auth_password_state password_state;
76
77         union {
78                 struct {
79                         DATA_BLOB lanman;
80                         DATA_BLOB nt;
81                 } response;
82                 struct {
83                         struct samr_Password *lanman;
84                         struct samr_Password *nt;
85                 } hash;
86
87                 char *plaintext;
88         } password;
89         uint32_t flags;
90 };
91
92 struct auth_serversupplied_info
93 {
94         struct dom_sid *account_sid;
95         struct dom_sid *primary_group_sid;
96
97         size_t n_domain_groups;
98         struct dom_sid **domain_groups;
99
100         DATA_BLOB user_session_key;
101         DATA_BLOB lm_session_key;
102
103         const char *account_name;
104         const char *domain_name;
105
106         const char *full_name;
107         const char *logon_script;
108         const char *profile_path;
109         const char *home_directory;
110         const char *home_drive;
111         const char *logon_server;
112
113         NTTIME last_logon;
114         NTTIME last_logoff;
115         NTTIME acct_expiry;
116         NTTIME last_password_change;
117         NTTIME allow_password_change;
118         NTTIME force_password_change;
119
120         uint16_t logon_count;
121         uint16_t bad_password_count;
122
123         uint32_t acct_flags;
124
125         bool authenticated;
126
127         struct PAC_SIGNATURE_DATA pac_srv_sig, pac_kdc_sig;
128 };
129
130 struct auth_method_context;
131 struct auth_check_password_request;
132 struct auth_context;
133 struct auth_session_info;
134 struct ldb_dn;
135
136 struct auth_operations {
137         const char *name;
138
139         /* If you are using this interface, then you are probably
140          * getting something wrong.  This interface is only for
141          * security=server, and makes a number of compromises to allow
142          * that.  It is not compatible with being a PDC.  */
143
144         NTSTATUS (*get_challenge)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx, uint8_t chal[8]);
145
146         /* Given the user supplied info, check if this backend want to handle the password checking */
147
148         NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
149                                const struct auth_usersupplied_info *user_info);
150
151         /* Given the user supplied info, check a password */
152
153         NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
154                                    const struct auth_usersupplied_info *user_info,
155                                    struct auth_serversupplied_info **server_info);
156
157         /* Lookup a 'server info' return based only on the principal */
158         NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
159                                               struct auth_context *auth_context,
160                                               const char *principal,
161                                               struct ldb_dn *user_dn,
162                                               struct auth_serversupplied_info **server_info);
163 };
164
165 struct auth_method_context {
166         struct auth_method_context *prev, *next;
167         struct auth_context *auth_ctx;
168         const struct auth_operations *ops;
169         int depth;
170         void *private_data;
171 };
172
173 struct auth_context {
174         struct {
175                 /* Who set this up in the first place? */
176                 const char *set_by;
177
178                 bool may_be_modified;
179
180                 DATA_BLOB data;
181         } challenge;
182
183         /* methods, in the order they should be called */
184         struct auth_method_context *methods;
185
186         /* the event context to use for calls that can block */
187         struct tevent_context *event_ctx;
188
189         /* the messaging context which can be used by backends */
190         struct messaging_context *msg_ctx;
191
192         /* loadparm context */
193         struct loadparm_context *lp_ctx;
194
195         /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
196         struct ldb_context *sam_ctx;
197
198         NTSTATUS (*check_password)(struct auth_context *auth_ctx,
199                                    TALLOC_CTX *mem_ctx,
200                                    const struct auth_usersupplied_info *user_info,
201                                    struct auth_serversupplied_info **server_info);
202
203         NTSTATUS (*get_challenge)(struct auth_context *auth_ctx, uint8_t chal[8]);
204
205         bool (*challenge_may_be_modified)(struct auth_context *auth_ctx);
206
207         NTSTATUS (*set_challenge)(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
208
209         NTSTATUS (*get_server_info_principal)(TALLOC_CTX *mem_ctx,
210                                                  struct auth_context *auth_ctx,
211                                                  const char *principal,
212                                                  struct ldb_dn *user_dn,
213                                                  struct auth_serversupplied_info **server_info);
214
215         NTSTATUS (*generate_session_info)(TALLOC_CTX *mem_ctx,
216                                           struct auth_context *auth_context,
217                                           struct auth_serversupplied_info *server_info,
218                                           uint32_t session_info_flags,
219                                           struct auth_session_info **session_info);
220 };
221
222 /* this structure is used by backends to determine the size of some critical types */
223 struct auth_critical_sizes {
224         int interface_version;
225         int sizeof_auth_operations;
226         int sizeof_auth_methods;
227         int sizeof_auth_context;
228         int sizeof_auth_usersupplied_info;
229         int sizeof_auth_serversupplied_info;
230 };
231
232  NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth_context *auth_context,
233                            enum auth_password_state to_state,
234                            const struct auth_usersupplied_info *user_info_in,
235                            const struct auth_usersupplied_info **user_info_encrypted);
236
237 #include "auth/session.h"
238 #include "auth/system_session_proto.h"
239
240 struct ldb_message;
241 struct ldb_context;
242 struct gensec_security;
243
244 NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, uint8_t chal[8]);
245 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
246                             struct ldb_context *sam_ctx,
247                             uint32_t logon_parameters,
248                             struct ldb_dn *domain_dn,
249                             struct ldb_message *msg,
250                             const char *logon_workstation,
251                             const char *name_for_logs,
252                             bool allow_domain_trust,
253                             bool password_change);
254 NTSTATUS authsam_expand_nested_groups(struct ldb_context *sam_ctx,
255                                       struct ldb_val *dn_val, const bool only_childs, const char *filter,
256                                       TALLOC_CTX *res_sids_ctx, struct dom_sid ***res_sids,
257                                       unsigned int *num_res_sids);
258 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
259 NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
260                                            const char *netbios_name,
261                                            const char *domain_name,
262                                            struct ldb_dn *domain_dn,
263                                            struct ldb_message *msg,
264                                            DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
265                                   struct auth_serversupplied_info **_server_info);
266 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
267                                            struct loadparm_context *lp_ctx,
268                                            struct auth_session_info **_session_info) ;
269 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
270
271 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods,
272                                      struct tevent_context *ev,
273                                      struct messaging_context *msg,
274                                      struct loadparm_context *lp_ctx,
275                                      struct ldb_context *sam_ctx,
276                                      struct auth_context **auth_ctx);
277
278 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
279                              struct tevent_context *ev,
280                              struct messaging_context *msg,
281                              struct loadparm_context *lp_ctx,
282                              struct auth_context **auth_ctx);
283 NTSTATUS auth_context_create_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct auth_context **auth_ctx);
284
285 NTSTATUS auth_check_password(struct auth_context *auth_ctx,
286                              TALLOC_CTX *mem_ctx,
287                              const struct auth_usersupplied_info *user_info,
288                              struct auth_serversupplied_info **server_info);
289 NTSTATUS auth_init(void);
290 NTSTATUS auth_register(const struct auth_operations *ops);
291 NTSTATUS server_service_auth_init(void);
292 NTSTATUS authenticate_username_pw(TALLOC_CTX *mem_ctx,
293                                            struct tevent_context *ev,
294                                            struct messaging_context *msg,
295                                            struct loadparm_context *lp_ctx,
296                                            const char *nt4_domain,
297                                            const char *nt4_username,
298                                            const char *password,
299                                            struct auth_session_info **session_info);
300
301 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
302                                             struct tevent_context *ev,
303                                             struct auth_context *auth_ctx,
304                                             const struct auth_usersupplied_info *user_info);
305 NTSTATUS auth_check_password_recv(struct tevent_req *req,
306                                   TALLOC_CTX *mem_ctx,
307                                   struct auth_serversupplied_info **server_info);
308
309 bool auth_challenge_may_be_modified(struct auth_context *auth_ctx);
310 NTSTATUS auth_context_set_challenge(struct auth_context *auth_ctx, const uint8_t chal[8], const char *set_by);
311
312 NTSTATUS auth_get_server_info_principal(TALLOC_CTX *mem_ctx,
313                                         struct auth_context *auth_ctx,
314                                         const char *principal,
315                                         struct ldb_dn *user_dn,
316                                         struct auth_serversupplied_info **server_info);
317
318 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
319                                    struct tevent_context *event_ctx,
320                                    struct messaging_context *msg_ctx,
321                                    struct loadparm_context *lp_ctx,
322                                    struct cli_credentials *server_credentials,
323                                    const char *target_service,
324                                    struct gensec_security **gensec_context);
325
326 #endif /* _SMBAUTH_H_ */