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