r3447: more include/system/XXX.h include files
[samba.git] / source4 / auth / auth_sam.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Password and authentication handling
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2004
5    Copyright (C) Gerald Carter                             2003
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_samr.h"
24 #include "system/time.h"
25
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_AUTH
28
29 /****************************************************************************
30  Do a specific test for an smb password being correct, given a smb_password and
31  the lanman and NT responses.
32 ****************************************************************************/
33
34 static NTSTATUS sam_password_ok(const struct auth_context *auth_context,
35                                 TALLOC_CTX *mem_ctx,
36                                 const char *username,
37                                 uint16_t acct_flags,
38                                 const struct samr_Password *lm_pwd, 
39                                 const struct samr_Password *nt_pwd,
40                                 const struct auth_usersupplied_info *user_info, 
41                                 DATA_BLOB *user_sess_key, 
42                                 DATA_BLOB *lm_sess_key)
43 {
44         NTSTATUS status;
45
46         if (acct_flags & ACB_PWNOTREQ) {
47                 if (lp_null_passwords()) {
48                         DEBUG(3,("Account for user '%s' has no password and null passwords are allowed.\n", 
49                                  username));
50                         return NT_STATUS_OK;
51                 } else {
52                         DEBUG(3,("Account for user '%s' has no password and null passwords are NOT allowed.\n", 
53                                  username));
54                         return NT_STATUS_LOGON_FAILURE;
55                 }               
56         }
57
58         status = ntlm_password_check(mem_ctx, &auth_context->challenge, 
59                                    &user_info->lm_resp, &user_info->nt_resp, 
60                                    &user_info->lm_interactive_password, 
61                                    &user_info->nt_interactive_password,
62                                    username, 
63                                    user_info->smb_name.str, 
64                                    user_info->client_domain.str, 
65                                    lm_pwd->hash, nt_pwd->hash, user_sess_key, lm_sess_key);
66
67         if (NT_STATUS_IS_OK(status)) {
68                 if (user_sess_key && user_sess_key->data) {
69                         talloc_steal(auth_context, user_sess_key->data);
70                 }
71                 if (lm_sess_key && lm_sess_key->data) {
72                         talloc_steal(auth_context, lm_sess_key->data);
73                 }
74         }
75
76         return status;
77 }
78
79
80 /****************************************************************************
81  Do a specific test for a SAM_ACCOUNT being vaild for this connection 
82  (ie not disabled, expired and the like).
83 ****************************************************************************/
84
85 static NTSTATUS sam_account_ok(TALLOC_CTX *mem_ctx,
86                                const char *username,
87                                uint16_t acct_flags,
88                                NTTIME *acct_expiry,
89                                NTTIME *must_change_time,
90                                NTTIME *last_set_time,
91                                const char *workstation_list,
92                                const struct auth_usersupplied_info *user_info)
93 {
94         DEBUG(4,("sam_account_ok: Checking SMB password for user %s\n", username));
95
96         /* Quit if the account was disabled. */
97         if (acct_flags & ACB_DISABLED) {
98                 DEBUG(1,("sam_account_ok: Account for user '%s' was disabled.\n", username));
99                 return NT_STATUS_ACCOUNT_DISABLED;
100         }
101
102         /* Quit if the account was locked out. */
103         if (acct_flags & ACB_AUTOLOCK) {
104                 DEBUG(1,("sam_account_ok: Account for user %s was locked out.\n", username));
105                 return NT_STATUS_ACCOUNT_LOCKED_OUT;
106         }
107
108         /* Test account expire time */
109         if ((*acct_expiry) != -1 && time(NULL) > nt_time_to_unix(*acct_expiry)) {
110                 DEBUG(1,("sam_account_ok: Account for user '%s' has expired.\n", username));
111                 DEBUG(3,("sam_account_ok: Account expired at '%s'.\n", 
112                          nt_time_string(mem_ctx, *acct_expiry)));
113                 return NT_STATUS_ACCOUNT_EXPIRED;
114         }
115
116         if (!(acct_flags & ACB_PWNOEXP)) {
117
118                 /* check for immediate expiry "must change at next logon" */
119                 if (*must_change_time == 0 && *last_set_time != 0) {
120                         DEBUG(1,("sam_account_ok: Account for user '%s' password must change!.\n", 
121                                  username));
122                         return NT_STATUS_PASSWORD_MUST_CHANGE;
123                 }
124
125                 /* check for expired password */
126                 if ((*must_change_time) != 0 && nt_time_to_unix(*must_change_time) < time(NULL)) {
127                         DEBUG(1,("sam_account_ok: Account for user '%s' password expired!.\n", 
128                                  username));
129                         DEBUG(1,("sam_account_ok: Password expired at '%s' unix time.\n", 
130                                  nt_time_string(mem_ctx, *must_change_time)));
131                         return NT_STATUS_PASSWORD_EXPIRED;
132                 }
133         }
134
135         /* Test workstation. Workstation list is comma separated. */
136
137         if (workstation_list && *workstation_list) {
138                 BOOL invalid_ws = True;
139                 const char *s = workstation_list;
140                         
141                 fstring tok;
142                         
143                 while (next_token(&s, tok, ",", sizeof(tok))) {
144                         DEBUG(10,("sam_account_ok: checking for workstation match %s and %s (len=%d)\n",
145                                   tok, user_info->wksta_name.str, user_info->wksta_name.len));
146                         
147                         if(strequal(tok, user_info->wksta_name.str)) {
148                                 invalid_ws = False;
149
150                                 break;
151                         }
152                 }
153                 
154                 if (invalid_ws) 
155                         return NT_STATUS_INVALID_WORKSTATION;
156         }
157
158         if (acct_flags & ACB_DOMTRUST) {
159                 DEBUG(2,("sam_account_ok: Domain trust account %s denied by server\n", username));
160                 return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
161         }
162         
163         if (acct_flags & ACB_SVRTRUST) {
164                 DEBUG(2,("sam_account_ok: Server trust account %s denied by server\n", username));
165                 return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
166         }
167         
168         if (acct_flags & ACB_WSTRUST) {
169                 DEBUG(4,("sam_account_ok: Wksta trust account %s denied by server\n", username));
170                 return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
171         }
172         
173         return NT_STATUS_OK;
174 }
175
176 /****************************************************************************
177  Look for the specified user in the sam, return ldb result structures
178 ****************************************************************************/
179
180 static NTSTATUS sam_search_user(const char *username, const char *domain, 
181                                 TALLOC_CTX *mem_ctx, void *sam_ctx, 
182                                 struct ldb_message ***ret_msgs, 
183                                 struct ldb_message ***ret_msgs_domain)
184 {
185         struct ldb_message **msgs;
186         struct ldb_message **msgs_domain;
187
188         uint_t ret;
189         uint_t ret_domain;
190
191         const char *domain_dn = NULL;
192         const char *domain_sid;
193
194         const char *attrs[] = {"unicodePwd", "lmPwdHash", "ntPwdHash", 
195                                "userAccountControl",
196                                "pwdLastSet",
197                                "accountExpires",
198                                "objectSid",
199                                "userWorkstations",
200                                
201                                /* required for server_info, not access control: */
202                                "sAMAccountName",
203                                "displayName",
204                                "scriptPath",
205                                "profilePath",
206                                "homeDirectory",
207                                "homeDrive",
208                                "lastLogon",
209                                "lastLogoff",
210                                "accountExpires",
211                                "badPwdCount",
212                                "logonCount",
213                                "primaryGroupID",
214                                NULL,
215         };
216
217         const char *domain_attrs[] =  {"name", "objectSid"};
218
219         if (domain) {
220                 /* find the domain's DN */
221                 ret_domain = samdb_search(sam_ctx, mem_ctx, NULL, &msgs_domain, domain_attrs,
222                                           "(&(|(realm=%s)(name=%s))(objectclass=domain))", 
223                                           domain, domain);
224                 
225                 if (ret_domain == 0) {
226                         DEBUG(3,("check_sam_security: Couldn't find domain [%s] in passdb file.\n", 
227                                  domain));
228                         return NT_STATUS_NO_SUCH_USER;
229                 }
230                 
231                 if (ret_domain > 1) {
232                         DEBUG(0,("Found %d records matching domain [%s]\n", 
233                                  ret_domain, domain));
234                         return NT_STATUS_INTERNAL_DB_CORRUPTION;
235                 }
236
237                 domain_dn = msgs_domain[0]->dn;
238
239         }
240         /* pull the user attributes */
241         ret = samdb_search(sam_ctx, mem_ctx, domain_dn, &msgs, attrs,
242                            "(&(sAMAccountName=%s)(objectclass=user))", 
243                            username);
244
245         if (ret == 0) {
246                 DEBUG(3,("check_sam_security: Couldn't find user [%s] in passdb file.\n", 
247                          username));
248                 return NT_STATUS_NO_SUCH_USER;
249         }
250
251         if (ret > 1) {
252                 DEBUG(0,("Found %d records matching user [%s]\n", ret, username));
253                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
254         }
255         
256         if (!domain) {
257                 domain_sid = samdb_result_sid_prefix(mem_ctx, msgs[0], "objectSid");
258                 if (!domain_sid) {
259                         return NT_STATUS_INTERNAL_DB_CORRUPTION;
260                 }
261
262                 /* find the domain's DN */
263                 ret_domain = samdb_search(sam_ctx, mem_ctx, NULL, &msgs_domain, domain_attrs,
264                                           "(&(objectSid=%s)(objectclass=domain))", 
265                                           domain_sid);
266                 
267                 if (ret_domain == 0) {
268                         DEBUG(3,("check_sam_security: Couldn't find domain [%s] in passdb file.\n", 
269                                  domain_sid));
270                         return NT_STATUS_NO_SUCH_USER;
271                 }
272                 
273                 if (ret_domain > 1) {
274                         DEBUG(0,("Found %d records matching domain [%s]\n", 
275                                  ret_domain, domain_sid));
276                         return NT_STATUS_INTERNAL_DB_CORRUPTION;
277                 }
278
279                 domain_dn = msgs_domain[0]->dn;
280         }
281         *ret_msgs = msgs;
282         *ret_msgs_domain = msgs_domain;
283         
284         return NT_STATUS_OK;
285 }
286
287 NTSTATUS sam_check_password(const struct auth_context *auth_context, 
288                             const char *username,
289                             TALLOC_CTX *mem_ctx, void *sam_ctx, 
290                             struct ldb_message **msgs,
291                             const char *domain_dn,
292                             const struct auth_usersupplied_info *user_info, 
293                             DATA_BLOB *user_sess_key, DATA_BLOB *lm_sess_key) 
294 {
295
296         uint16_t acct_flags;
297         const char *workstation_list;
298         NTTIME acct_expiry;
299         NTTIME must_change_time;
300         NTTIME last_set_time;
301         struct samr_Password *lm_pwd, *nt_pwd;
302
303         NTSTATUS nt_status;
304
305
306         acct_flags = samdb_result_acct_flags(msgs[0], "sAMAcctFlags");
307         
308         /* Quit if the account was locked out. */
309         if (acct_flags & ACB_AUTOLOCK) {
310                 DEBUG(3,("check_sam_security: Account for user %s was locked out.\n", 
311                          username));
312                 return NT_STATUS_ACCOUNT_LOCKED_OUT;
313         }
314
315         if (!NT_STATUS_IS_OK(nt_status = samdb_result_passwords(mem_ctx, msgs[0], 
316                                                                 &lm_pwd, &nt_pwd))) {
317                 return nt_status;
318         }
319
320         nt_status = sam_password_ok(auth_context, mem_ctx, 
321                                     username, acct_flags, 
322                                     lm_pwd, nt_pwd,
323                                     user_info, user_sess_key, lm_sess_key);
324         
325         if (!NT_STATUS_IS_OK(nt_status)) {
326                 return nt_status;
327         }
328
329         acct_expiry = samdb_result_nttime(msgs[0], "accountExpires", 0);
330         must_change_time = samdb_result_force_password_change(sam_ctx, mem_ctx, 
331                                                               domain_dn, msgs[0], 
332                                                               "pwdLastSet");
333         last_set_time = samdb_result_nttime(msgs[0], "pwdLastSet", 0);
334
335         workstation_list = samdb_result_string(msgs[0], "userWorkstations", NULL);
336
337         nt_status = sam_account_ok(mem_ctx, username, acct_flags, 
338                                    &acct_expiry, 
339                                    &must_change_time, 
340                                    &last_set_time, 
341                                    workstation_list,
342                                    user_info);
343
344         return nt_status;
345 }
346
347 NTSTATUS sam_make_server_info(TALLOC_CTX *mem_ctx, void *sam_ctx, 
348                               struct ldb_message **msgs, struct ldb_message **msgs_domain, 
349                               struct auth_serversupplied_info **server_info) 
350 {
351
352         struct ldb_message **group_msgs;
353         int group_ret;
354         const char *group_attrs[3] = { "sAMAccountType", "objectSid", NULL }; 
355         /* find list of sids */
356         struct dom_sid **groupSIDs = NULL;
357         struct dom_sid *user_sid;
358         struct dom_sid *primary_group_sid;
359         const char *sidstr;
360         int i;
361         uint_t rid;
362         
363         NTSTATUS nt_status;
364
365         if (!NT_STATUS_IS_OK(nt_status = make_server_info(mem_ctx, server_info, 
366                                                           samdb_result_string(msgs[0], "sAMAccountName", "")))) {               
367                 DEBUG(0,("check_sam_security: make_server_info_sam() failed with '%s'\n", nt_errstr(nt_status)));
368                 return nt_status;
369         }
370         
371         group_ret = samdb_search(sam_ctx,
372                                  mem_ctx, NULL, &group_msgs, group_attrs,
373                                  "(&(member=%s)(sAMAccountType=*))", 
374                                  msgs[0]->dn);
375         if (group_ret == -1) {
376                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
377         }
378         
379         if (group_ret > 0 && 
380             !(groupSIDs = talloc_array_p(*server_info, struct dom_sid *, group_ret))) {
381                 talloc_free(*server_info);
382                 return NT_STATUS_NO_MEMORY;
383         }
384         
385         /* Need to unroll some nested groups, but not aliases */
386         for (i = 0; i < group_ret; i++) {
387                 sidstr = ldb_msg_find_string(group_msgs[i], "objectSid", NULL);
388                 groupSIDs[i] = dom_sid_parse_talloc(*server_info, sidstr);
389         }
390         
391         sidstr = ldb_msg_find_string(msgs[0], "objectSid", NULL);
392         user_sid = dom_sid_parse_talloc(*server_info, sidstr);
393         primary_group_sid = dom_sid_parse_talloc(*server_info, sidstr);
394         rid = samdb_result_uint(msgs[0], "primaryGroupID", ~0);
395         if (rid == ~0) {
396                 if (group_ret > 0) {
397                         primary_group_sid = groupSIDs[0];
398                 } else {
399                         primary_group_sid = NULL;
400                 }
401         } else {
402                 primary_group_sid->sub_auths[primary_group_sid->num_auths-1] = rid;
403         }
404         
405         (*server_info)->user_sid = user_sid;
406         (*server_info)->primary_group_sid = primary_group_sid;
407         
408         (*server_info)->n_domain_groups = group_ret;
409         (*server_info)->domain_groups = groupSIDs;
410
411         (*server_info)->account_name 
412                 = talloc_strdup(*server_info, 
413                                 samdb_result_string(msgs[0], "sAMAccountName", ""));
414
415         (*server_info)->domain
416                 = talloc_strdup(*server_info, 
417                                 samdb_result_string(msgs_domain[0], "name", ""));
418
419         (*server_info)->full_name 
420                 = talloc_strdup(*server_info, 
421                                 samdb_result_string(msgs[0], "displayName", ""));
422
423         (*server_info)->logon_script 
424                 = talloc_strdup(*server_info, 
425                                 samdb_result_string(msgs[0], "scriptPath", ""));
426         (*server_info)->profile_path 
427                 = talloc_strdup(*server_info, 
428                                 samdb_result_string(msgs[0], "profilePath", ""));
429         (*server_info)->home_directory 
430                 = talloc_strdup(*server_info, 
431                                 samdb_result_string(msgs[0], "homeDirectory", ""));
432
433         (*server_info)->home_drive 
434                 = talloc_strdup(*server_info, 
435                                 samdb_result_string(msgs[0], "homeDrive", ""));
436
437         (*server_info)->last_logon = samdb_result_nttime(msgs[0], "lastLogon", 0);
438         (*server_info)->last_logoff = samdb_result_nttime(msgs[0], "lastLogoff", 0);
439         (*server_info)->acct_expiry = samdb_result_nttime(msgs[0], "accountExpires", 0);
440         (*server_info)->last_password_change = samdb_result_nttime(msgs[0], "pwdLastSet", 0);
441         (*server_info)->allow_password_change
442                 = samdb_result_allow_password_change(sam_ctx, mem_ctx, 
443                                                      msgs_domain[0]->dn, msgs[0], "pwdLastSet");
444         (*server_info)->force_password_change
445                 = samdb_result_force_password_change(sam_ctx, mem_ctx, 
446                                                      msgs_domain[0]->dn, msgs[0], "pwdLastSet");
447
448         (*server_info)->logon_count = samdb_result_uint(msgs[0], "logonCount", 0);
449         (*server_info)->bad_password_count = samdb_result_uint(msgs[0], "badPwdCount", 0);
450
451         (*server_info)->acct_flags = samdb_result_acct_flags(msgs[0], "userAccountControl");
452
453         (*server_info)->guest = False;
454
455         if (!(*server_info)->account_name 
456             || !(*server_info)->full_name 
457             || !(*server_info)->logon_script
458             || !(*server_info)->profile_path
459             || !(*server_info)->home_directory
460             || !(*server_info)->home_drive) {
461                 talloc_destroy(*server_info);
462                 return NT_STATUS_NO_MEMORY;
463         }
464
465         return nt_status;
466 }
467
468 NTSTATUS sam_get_server_info(const char *username, const char *domain, TALLOC_CTX *mem_ctx,
469                              struct auth_serversupplied_info **server_info)
470 {
471         NTSTATUS nt_status;
472
473         struct ldb_message **msgs;
474         struct ldb_message **domain_msgs;
475         void *sam_ctx;
476
477         sam_ctx = samdb_connect(mem_ctx);
478         if (sam_ctx == NULL) {
479                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
480         }
481
482         nt_status = sam_search_user(username, domain, mem_ctx, sam_ctx, &msgs, &domain_msgs);
483         if (!NT_STATUS_IS_OK(nt_status)) {
484                 return nt_status;
485         }
486
487         nt_status = sam_make_server_info(mem_ctx, sam_ctx, msgs, domain_msgs, server_info);
488         if (!NT_STATUS_IS_OK(nt_status)) {
489                 return nt_status;
490         }
491
492         return NT_STATUS_OK;
493 }
494
495 static NTSTATUS check_sam_security_internals(const struct auth_context *auth_context,
496                                              const char *domain,
497                                              TALLOC_CTX *mem_ctx,
498                                              const struct auth_usersupplied_info *user_info, 
499                                              struct auth_serversupplied_info **server_info)
500 {
501         NTSTATUS nt_status;
502
503         const char *username = user_info->internal_username.str;
504         struct ldb_message **msgs;
505         struct ldb_message **domain_msgs;
506         void *sam_ctx;
507         DATA_BLOB user_sess_key, lm_sess_key;
508
509         sam_ctx = samdb_connect(mem_ctx);
510         if (sam_ctx == NULL) {
511                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
512         }
513
514         nt_status = sam_search_user(username, domain, mem_ctx, sam_ctx, &msgs, &domain_msgs);
515         if (!NT_STATUS_IS_OK(nt_status)) {
516                 return nt_status;
517         }
518
519         nt_status = sam_check_password(auth_context, username, mem_ctx, sam_ctx, msgs, domain_msgs[0]->dn, user_info,
520                                        &user_sess_key, &lm_sess_key);
521         if (!NT_STATUS_IS_OK(nt_status)) {
522                 return nt_status;
523         }
524         
525         nt_status = sam_make_server_info(mem_ctx, sam_ctx, msgs, domain_msgs, server_info);
526         if (!NT_STATUS_IS_OK(nt_status)) {
527                 return nt_status;
528         }
529
530         talloc_reference(auth_context, *server_info);
531
532         (*server_info)->user_session_key = user_sess_key;
533         (*server_info)->lm_session_key = lm_sess_key;
534         return NT_STATUS_OK;
535 }
536
537 static NTSTATUS check_sam_security(const struct auth_context *auth_context,
538                                    void *my_private_data, 
539                                    TALLOC_CTX *mem_ctx,
540                                    const struct auth_usersupplied_info *user_info, 
541                                    struct auth_serversupplied_info **server_info)
542 {
543         return check_sam_security_internals(auth_context, NULL,
544                                             mem_ctx, user_info, server_info);
545 }
546
547 /* module initialisation */
548 static NTSTATUS auth_init_sam_ignoredomain(struct auth_context *auth_context, 
549                                            const char *param, 
550                                            struct auth_methods **auth_method) 
551 {
552         if (!make_auth_methods(auth_context, auth_method)) {
553                 return NT_STATUS_NO_MEMORY;
554         }
555
556         (*auth_method)->auth = check_sam_security;      
557         (*auth_method)->name = "sam_ignoredomain";
558         return NT_STATUS_OK;
559 }
560
561
562 /****************************************************************************
563 Check SAM security (above) but with a few extra checks.
564 ****************************************************************************/
565
566 static NTSTATUS check_samstrict_security(const struct auth_context *auth_context,
567                                          void *my_private_data, 
568                                          TALLOC_CTX *mem_ctx,
569                                          const struct auth_usersupplied_info *user_info, 
570                                          struct auth_serversupplied_info **server_info)
571 {
572         const char *domain;
573         BOOL is_local_name, is_my_domain;
574
575         if (!user_info || !auth_context) {
576                 return NT_STATUS_LOGON_FAILURE;
577         }
578
579         is_local_name = is_myname(user_info->domain.str);
580         is_my_domain  = strequal(user_info->domain.str, lp_workgroup());
581
582         /* check whether or not we service this domain/workgroup name */
583         
584         switch ( lp_server_role() ) {
585                 case ROLE_STANDALONE:
586                 case ROLE_DOMAIN_MEMBER:
587                         if ( !is_local_name ) {
588                                 DEBUG(6,("check_samstrict_security: %s is not one of my local names (%s)\n",
589                                         user_info->domain.str, (lp_server_role() == ROLE_DOMAIN_MEMBER 
590                                         ? "ROLE_DOMAIN_MEMBER" : "ROLE_STANDALONE") ));
591                                 return NT_STATUS_NOT_IMPLEMENTED;
592                         }
593                         domain = lp_netbios_name();
594                         break;
595                 case ROLE_DOMAIN_PDC:
596                 case ROLE_DOMAIN_BDC:
597                         if ( !is_local_name && !is_my_domain ) {
598                                 DEBUG(6,("check_samstrict_security: %s is not one of my local names or domain name (DC)\n",
599                                         user_info->domain.str));
600                                 return NT_STATUS_NOT_IMPLEMENTED;
601                         }
602                         domain = lp_workgroup();
603                         break;
604                 default: /* name is ok */
605                         domain = user_info->domain.str;
606                         break;
607         }
608         
609         return check_sam_security_internals(auth_context, domain, mem_ctx, user_info, server_info);
610 }
611
612 /* module initialisation */
613 static NTSTATUS auth_init_sam(struct auth_context *auth_context, 
614                               const char *param, 
615                               struct auth_methods **auth_method) 
616 {
617         if (!make_auth_methods(auth_context, auth_method)) {
618                 return NT_STATUS_NO_MEMORY;
619         }
620
621         (*auth_method)->auth = check_samstrict_security;
622         (*auth_method)->name = "sam";
623         return NT_STATUS_OK;
624 }
625
626 NTSTATUS auth_sam_init(void)
627 {
628         NTSTATUS ret;
629         struct auth_operations ops;
630
631         ops.name = "sam";
632         ops.init = auth_init_sam;
633         ret = register_backend("auth", &ops);
634         if (!NT_STATUS_IS_OK(ret)) {
635                 DEBUG(0,("Failed to register '%s' auth backend!\n",
636                         ops.name));
637                 return ret;
638         }
639
640         ops.name = "sam_ignoredomain";
641         ops.init = auth_init_sam_ignoredomain;
642         ret = register_backend("auth", &ops);
643         if (!NT_STATUS_IS_OK(ret)) {
644                 DEBUG(0,("Failed to register '%s' auth backend!\n",
645                         ops.name));
646                 return ret;
647         }
648
649         return ret;
650 }