pdbtest: Call make_auth_context_subsystem directly
[vlendec/samba-autobuild/.git] / source3 / torture / pdbtest.c
1 /* 
2    Unix SMB/CIFS implementation.
3    passdb testing utility
4
5    Copyright (C) Wilco Baan Hofman 2006
6    Copyright (C) Jelmer Vernooij 2006
7    Copyright (C) Andrew Bartlett 2012
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23
24 #include "includes.h"
25 #include "popt_common.h"
26 #include "passdb.h"
27
28 #include "../librpc/gen_ndr/drsblobs.h"
29 #include "../librpc/gen_ndr/ndr_drsblobs.h"
30 #include "../libcli/security/dom_sid.h"
31 #include "../libcli/auth/libcli_auth.h"
32 #include "../auth/common_auth.h"
33 #include "lib/tsocket/tsocket.h"
34 #include "include/auth.h"
35
36 #define TRUST_DOM "trustdom"
37 #define TRUST_PWD "trustpwd1232"
38 #define TRUST_SID "S-1-5-21-1111111111-2222222222-3333333333"
39
40 static bool samu_correct(struct samu *s1, struct samu *s2)
41 {
42         bool ret = True;
43         uint32_t s1_len, s2_len;
44         const char *s1_buf, *s2_buf;
45         const uint8_t *d1_buf, *d2_buf;
46         const struct dom_sid *s1_sid, *s2_sid;
47
48         /* Check Unix username */
49         s1_buf = pdb_get_username(s1);
50         s2_buf = pdb_get_username(s2);
51         if (s2_buf == NULL && s1_buf != NULL) {
52                 DEBUG(0, ("Username is not set\n"));
53                 ret = False;
54         } else if (s1_buf == NULL) {
55                 /* Do nothing */
56         } else if (strcmp(s1_buf,s2_buf)) {
57                 DEBUG(0, ("Username not written correctly, want %s, got \"%s\"\n",
58                                         pdb_get_username(s1),
59                                         pdb_get_username(s2)));
60                 ret = False;
61         }
62
63         /* Check NT username */
64         s1_buf = pdb_get_nt_username(s1);
65         s2_buf = pdb_get_nt_username(s2);
66         if (s2_buf == NULL && s1_buf != NULL) {
67                 DEBUG(0, ("NT Username is not set\n"));
68                 ret = False;
69         } else if (s1_buf == NULL) {
70                 /* Do nothing */
71         } else if (strcmp(s1_buf, s2_buf)) {
72                 DEBUG(0, ("NT Username not written correctly, want \"%s\", got \"%s\"\n",
73                                         pdb_get_nt_username(s1),
74                                         pdb_get_nt_username(s2)));
75                 ret = False;
76         }
77
78         /* Check acct ctrl */
79         if (pdb_get_acct_ctrl(s1) != pdb_get_acct_ctrl(s2)) {
80                 DEBUG(0, ("Acct ctrl field not written correctly, want %d (0x%X), got %d (0x%X)\n",
81                                         pdb_get_acct_ctrl(s1),
82                                         pdb_get_acct_ctrl(s1),
83                                         pdb_get_acct_ctrl(s2),
84                                         pdb_get_acct_ctrl(s2)));
85                 ret = False;
86         }
87
88         /* Check NT password */
89         d1_buf = pdb_get_nt_passwd(s1);
90         d2_buf = pdb_get_nt_passwd(s2);
91         if (d2_buf == NULL && d1_buf != NULL) {
92                 DEBUG(0, ("NT password is not set\n"));
93                 ret = False;
94         } else if (d1_buf == NULL) {
95                 /* Do nothing */
96         } else if (memcmp(d1_buf, d2_buf, NT_HASH_LEN)) {
97                 DEBUG(0, ("NT password not written correctly\n"));
98                 ret = False;
99         }
100
101         /* Check lanman password */
102         d1_buf = pdb_get_lanman_passwd(s1);
103         d2_buf = pdb_get_lanman_passwd(s2);
104         if (d2_buf == NULL && d1_buf != NULL) {
105                 DEBUG(0, ("Lanman password is not set\n"));
106         } else if (d1_buf == NULL) {
107                 /* Do nothing */
108         } else if (memcmp(d1_buf, d2_buf, NT_HASH_LEN)) {
109                 DEBUG(0, ("Lanman password not written correctly\n"));
110                 ret = False;
111         }
112
113         /* Check password history */
114         d1_buf = pdb_get_pw_history(s1, &s1_len);
115         d2_buf = pdb_get_pw_history(s2, &s2_len);
116         if (d2_buf == NULL && d1_buf != NULL) {
117                 DEBUG(0, ("Password history is not set\n"));
118         } else if (d1_buf == NULL) {
119                 /* Do nothing */
120         } else if (s1_len != s2_len) {
121                 DEBUG(0, ("Password history not written correctly, lengths differ, want %d, got %d\n",
122                                         s1_len, s2_len));
123                 ret = False;
124         } else if (strncmp(s1_buf, s2_buf, s1_len)) {
125                 DEBUG(0, ("Password history not written correctly\n"));
126                 ret = False;
127         }
128
129         /* Check logon time */
130         if (pdb_get_logon_time(s1) != pdb_get_logon_time(s2)) {
131                 DEBUG(0, ("Logon time is not written correctly\n"));
132                 ret = False;
133         }
134
135         /* Check logoff time */
136         if (pdb_get_logoff_time(s1) != pdb_get_logoff_time(s2)) {
137                 DEBUG(0, ("Logoff time is not written correctly: %s vs %s \n",
138                           http_timestring(talloc_tos(), pdb_get_logoff_time(s1)),
139                           http_timestring(talloc_tos(), pdb_get_logoff_time(s2))));
140                 ret = False;
141         }
142
143         /* Check kickoff time */
144         if (pdb_get_kickoff_time(s1) != pdb_get_kickoff_time(s2)) {
145                 DEBUG(0, ("Kickoff time is not written correctly: %s vs %s \n",
146                           http_timestring(talloc_tos(), pdb_get_kickoff_time(s1)),
147                           http_timestring(talloc_tos(), pdb_get_kickoff_time(s2))));
148                 ret = False;
149         }
150
151         /* Check bad password time */
152         if (pdb_get_bad_password_time(s1) != pdb_get_bad_password_time(s2)) {
153                 DEBUG(0, ("Bad password time is not written correctly\n"));
154                 ret = False;
155         }
156
157         /* Check password last set time */
158         if (pdb_get_pass_last_set_time(s1) != pdb_get_pass_last_set_time(s2)) {
159                 DEBUG(0, ("Password last set time is not written correctly: %s vs %s \n",
160                           http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s1)),
161                           http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s2))));
162                 ret = False;
163         }
164
165         /* Check password can change time */
166         if (pdb_get_pass_can_change_time(s1) != pdb_get_pass_can_change_time(s2)) {
167                 DEBUG(0, ("Password can change time is not written correctly %s vs %s \n",
168                           http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s1)),
169                           http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s2))));
170                 ret = False;
171         }
172
173         /* Check password must change time */
174         if (pdb_get_pass_must_change_time(s1) != pdb_get_pass_must_change_time(s2)) {
175                 DEBUG(0, ("Password must change time is not written correctly\n"));
176                 ret = False;
177         }
178
179         /* Check logon divs */
180         if (pdb_get_logon_divs(s1) != pdb_get_logon_divs(s2)) {
181                 DEBUG(0, ("Logon divs not written correctly\n"));
182                 ret = False;
183         }
184
185         /* Check logon hours */
186         if (pdb_get_hours_len(s1) != pdb_get_hours_len(s2)) {
187                 DEBUG(0, ("Logon hours length not written correctly\n"));
188                 ret = False;
189         } else if (pdb_get_hours_len(s1) != 0) {
190                 d1_buf = pdb_get_hours(s1);
191                 d2_buf = pdb_get_hours(s2);
192                 if (d2_buf == NULL && d2_buf != NULL) {
193                         DEBUG(0, ("Logon hours is not set\n"));
194                         ret = False;
195                 } else if (d1_buf == NULL) {
196                         /* Do nothing */
197                 } else if (memcmp(d1_buf, d2_buf, MAX_HOURS_LEN)) {
198                         DEBUG(0, ("Logon hours is not written correctly\n"));
199                         ret = False;
200                 }
201         }
202
203         /* Check profile path */
204         s1_buf = pdb_get_profile_path(s1);
205         s2_buf = pdb_get_profile_path(s2);
206         if (s2_buf == NULL && s1_buf != NULL) {
207                 DEBUG(0, ("Profile path is not set\n"));
208                 ret = False;
209         } else if (s1_buf == NULL) {
210                 /* Do nothing */
211         } else if (strcmp(s1_buf, s2_buf)) {
212                 DEBUG(0, ("Profile path is not written correctly\n"));
213                 ret = False;
214         }
215
216         /* Check home dir */
217         s1_buf = pdb_get_homedir(s1);
218         s2_buf = pdb_get_homedir(s2);
219         if (s2_buf == NULL && s1_buf != NULL) {
220                 DEBUG(0, ("Home dir is not set\n"));
221                 ret = False;
222         } else if (s1_buf == NULL) {
223                 /* Do nothing */
224         } else if (strcmp(s1_buf, s2_buf)) {
225                 DEBUG(0, ("Home dir is not written correctly\n"));
226                 ret = False;
227         }
228
229         /* Check logon script */
230         s1_buf = pdb_get_logon_script(s1);
231         s2_buf = pdb_get_logon_script(s2);
232         if (s2_buf == NULL && s1_buf != NULL) {
233                 DEBUG(0, ("Logon script not set\n"));
234                 ret = False;
235         } else if (s1_buf == NULL) {
236                 /* Do nothing */
237         } else if (strcmp(s1_buf, s2_buf)) {
238                 DEBUG(0, ("Logon script is not written correctly\n"));
239                 ret = False;
240         }
241
242         /* Check user and group sids */
243         s1_sid = pdb_get_user_sid(s1);
244         s2_sid = pdb_get_user_sid(s2);
245         if (s2_sid == NULL && s1_sid != NULL) {
246                 DEBUG(0, ("USER SID not set\n"));
247                 ret = False;
248         } else if (s1_sid == NULL) {
249                 /* Do nothing */
250         } else if (!dom_sid_equal(s1_sid, s2_sid)) {
251                 DEBUG(0, ("USER SID is not written correctly\n"));
252                 ret = False;
253         }
254
255         return ret;     
256 }
257
258 static bool test_auth(TALLOC_CTX *mem_ctx, struct samu *pdb_entry)
259 {
260         struct auth_usersupplied_info *user_info;
261         struct auth_context *auth_context;
262         static const uint8_t challenge_8[8] = {1, 2, 3, 4, 5, 6, 7, 8};
263         DATA_BLOB challenge = data_blob_const(challenge_8, sizeof(challenge_8));
264         struct tsocket_address *tsocket_address;
265         unsigned char local_nt_response[24];
266         DATA_BLOB nt_resp = data_blob_const(local_nt_response, sizeof(local_nt_response));
267         unsigned char local_nt_session_key[16];
268         struct netr_SamInfo3 *info3_sam, *info3_auth;
269         struct auth_serversupplied_info *server_info;
270         NTSTATUS status;
271         bool ok;
272         
273         SMBOWFencrypt(pdb_get_nt_passwd(pdb_entry), challenge_8,
274                       local_nt_response);
275         SMBsesskeygen_ntv1(pdb_get_nt_passwd(pdb_entry), local_nt_session_key);
276
277         if (tsocket_address_inet_from_strings(NULL, "ip", NULL, 0, &tsocket_address) != 0) {
278                 return False;
279         }
280         
281         status = make_user_info(mem_ctx,
282                                 &user_info, pdb_get_username(pdb_entry), pdb_get_username(pdb_entry),
283                                 pdb_get_domain(pdb_entry), pdb_get_domain(pdb_entry), lp_netbios_name(), 
284                                 tsocket_address, NULL, &nt_resp, NULL, NULL, NULL, 
285                                 AUTH_PASSWORD_RESPONSE);
286         if (!NT_STATUS_IS_OK(status)) {
287                 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
288                 return False;
289         }
290
291         status = check_sam_security_info3(&challenge, NULL, user_info, &info3_sam);
292         if (!NT_STATUS_IS_OK(status)) {
293                 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
294                 return False;
295         }
296
297         if (memcmp(info3_sam->base.key.key, local_nt_session_key, 16) != 0) {
298                 DEBUG(0, ("Returned NT session key is incorrect\n"));
299                 return False;
300         }
301
302         status = make_auth_context_subsystem(NULL, &auth_context);
303
304         if (!NT_STATUS_IS_OK(status)) {
305                 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status)));
306                 return False;
307         }
308
309         ok = auth3_context_set_challenge(
310                 auth_context, challenge.data, "fixed");
311         if (!ok) {
312                 DBG_ERR("auth3_context_set_challenge failed\n");
313                 return false;
314         }
315
316         status = auth_check_ntlm_password(mem_ctx,
317                                           auth_context,
318                                           user_info,
319                                           &server_info);
320
321         if (!NT_STATUS_IS_OK(status)) {
322                 DEBUG(0, ("Failed to test authentication with auth module: %s\n", nt_errstr(status)));
323                 return False;
324         }
325         
326         info3_auth = talloc_zero(mem_ctx, struct netr_SamInfo3);
327         if (info3_auth == NULL) {
328                 return False;
329         }
330
331         status = serverinfo_to_SamInfo3(server_info, info3_auth);
332         if (!NT_STATUS_IS_OK(status)) {
333                 DEBUG(0, ("serverinfo_to_SamInfo3 failed: %s\n",
334                           nt_errstr(status)));
335                 return False;
336         }
337
338         if (memcmp(info3_auth->base.key.key, local_nt_session_key, 16) != 0) {
339                 DEBUG(0, ("Returned NT session key is incorrect\n"));
340                 return False;
341         }
342
343         if (!dom_sid_equal(info3_sam->base.domain_sid, info3_auth->base.domain_sid)) {
344                 DEBUG(0, ("domain_sid in SAM info3 %s does not match domain_sid in AUTH info3 %s\n", 
345                           dom_sid_string(NULL, info3_sam->base.domain_sid),
346                           dom_sid_string(NULL, info3_auth->base.domain_sid)));
347                 return False;
348         }
349         
350         /* TODO: 
351          * Compre more details from the two info3 structures,
352          * then test that an expired/disabled/pwdmustchange account
353          * returns the correct errors
354          */
355
356         return True;
357 }
358
359 static bool test_trusted_domains(TALLOC_CTX *ctx,
360                                  struct pdb_methods *pdb,
361                                  bool *error)
362 {
363         NTSTATUS rv;
364         /* test trustdom calls */
365         struct pdb_trusted_domain *td;
366         struct pdb_trusted_domain *new_td;
367         struct trustAuthInOutBlob taiob;
368         struct AuthenticationInformation aia;
369         enum ndr_err_code ndr_err;
370
371         td = talloc_zero(ctx ,struct pdb_trusted_domain);
372         if (!td) {
373                 fprintf(stderr, "talloc failed\n");
374                 return false;
375         }
376
377         td->domain_name = talloc_strdup(td, TRUST_DOM);
378         td->netbios_name = talloc_strdup(td, TRUST_DOM);
379         if (!td->domain_name || !td->netbios_name) {
380                 fprintf(stderr, "talloc failed\n");
381                 return false;
382         }
383
384         td->trust_auth_incoming = data_blob_null;
385
386         ZERO_STRUCT(taiob);
387         ZERO_STRUCT(aia);
388         taiob.count = 1;
389         taiob.current.count = 1;
390         taiob.current.array = &aia;
391         unix_to_nt_time(&aia.LastUpdateTime, time(NULL));
392         aia.AuthType = TRUST_AUTH_TYPE_CLEAR;
393         aia.AuthInfo.clear.password = (uint8_t *) talloc_strdup(ctx, TRUST_PWD);
394         aia.AuthInfo.clear.size = strlen(TRUST_PWD);
395
396         taiob.previous.count = 0;
397         taiob.previous.array = NULL;
398
399         ndr_err = ndr_push_struct_blob(&td->trust_auth_outgoing,
400                                         td, &taiob,
401                         (ndr_push_flags_fn_t) ndr_push_trustAuthInOutBlob);
402         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
403                 fprintf(stderr, "ndr_push_struct_blob failed.\n");
404                 return false;
405         }
406
407         td->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND;
408         td->trust_type = LSA_TRUST_TYPE_DOWNLEVEL;
409         td->trust_attributes = 0;
410         td->trust_forest_trust_info = data_blob_null;
411
412         rv = pdb->set_trusted_domain(pdb, TRUST_DOM, td);
413         if (!NT_STATUS_IS_OK(rv)) {
414                 fprintf(stderr, "Error in set_trusted_domain %s\n",
415                                 get_friendly_nt_error_msg(rv));
416                 *error = true;
417         }
418
419         rv = pdb->get_trusted_domain(pdb, ctx, TRUST_DOM, &new_td);
420         if (!NT_STATUS_IS_OK(rv)) {
421                 fprintf(stderr, "Error in set_trusted_domain %s\n",
422                                 get_friendly_nt_error_msg(rv));
423                 *error = true;
424         }
425
426         if (!strequal(td->domain_name, new_td->domain_name) ||
427             !strequal(td->netbios_name, new_td->netbios_name) ||
428             !dom_sid_equal(&td->security_identifier,
429                            &new_td->security_identifier) ||
430             td->trust_direction != new_td->trust_direction ||
431             td->trust_type != new_td->trust_type ||
432             td->trust_attributes != new_td->trust_attributes ||
433             td->trust_auth_incoming.length != new_td->trust_auth_incoming.length ||
434             td->trust_forest_trust_info.length != new_td->trust_forest_trust_info.length ||
435             data_blob_cmp(&td->trust_auth_outgoing, &new_td->trust_auth_outgoing) != 0) {
436                 fprintf(stderr, "Old and new trusdet domain data do not match\n");
437                 *error = true;
438         }
439
440         return true;
441 }
442
443
444 int main(int argc, const char **argv)
445 {
446         TALLOC_CTX *ctx;
447         struct samu *out = NULL;
448         struct samu *in = NULL;
449         NTSTATUS rv;
450         int i;
451         struct timeval tv;
452         bool error = False;
453         struct passwd *pwd;
454         uint8_t *buf;
455         uint32_t expire, min_age, history;
456         struct pdb_methods *pdb;
457         poptContext pc;
458         static const char *backend = NULL;
459         static const char *unix_user = "nobody";
460         struct poptOption long_options[] = {
461                 {"username", 'u', POPT_ARG_STRING, &unix_user, 0, "Unix user to use for testing", "USERNAME" },
462                 {"backend", 'b', POPT_ARG_STRING, &backend, 0, "Backend to use if not default", "BACKEND[:SETTINGS]" },
463                 POPT_AUTOHELP
464                 POPT_COMMON_SAMBA
465                 POPT_TABLEEND
466         };
467
468         ctx = talloc_stackframe();
469
470         smb_init_locale();
471
472         pc = poptGetContext("pdbtest", argc, argv, long_options, 0);
473
474         poptSetOtherOptionHelp(pc, "backend[:settings] username");
475
476         while(poptGetNextOpt(pc) != -1);
477
478         poptFreeContext(pc);
479
480         /* Load configuration */
481         lp_load_global(get_dyn_CONFIGFILE());
482         setup_logging("pdbtest", DEBUG_STDOUT);
483         init_names();
484
485         if (backend == NULL) {
486                 backend = lp_passdb_backend();
487         }
488
489         rv = make_pdb_method_name(&pdb, backend);
490         if (NT_STATUS_IS_ERR(rv)) {
491                 fprintf(stderr, "Error initializing '%s': %s\n", backend, get_friendly_nt_error_msg(rv));
492                 exit(1);
493         }
494
495         if (!(out = samu_new(ctx))) {
496                 fprintf(stderr, "Can't create samu structure.\n");
497                 exit(1);
498         }
499
500         if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) {
501                 fprintf(stderr, "Error getting user information for %s\n", unix_user);
502                 exit(1);
503         }
504
505         samu_set_unix(out, pwd);
506
507         pdb_set_profile_path(out, "\\\\torture\\profile", PDB_SET);
508         pdb_set_homedir(out, "\\\\torture\\home", PDB_SET);
509         pdb_set_logon_script(out, "torture_script.cmd", PDB_SET);
510
511         pdb_set_acct_ctrl(out, ACB_NORMAL, PDB_SET);
512
513         pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &history);
514         if (history * PW_HISTORY_ENTRY_LEN < NT_HASH_LEN) {
515                 buf = (uint8_t *)TALLOC(ctx, NT_HASH_LEN);
516         } else {
517                 buf = (uint8_t *)TALLOC(ctx, history * PW_HISTORY_ENTRY_LEN);
518         }
519
520         /* Generate some random hashes */
521         GetTimeOfDay(&tv);
522         srand(tv.tv_usec);
523         for (i = 0; i < NT_HASH_LEN; i++) {
524                 buf[i] = (uint8_t) rand();
525         }
526         pdb_set_nt_passwd(out, buf, PDB_SET);
527         for (i = 0; i < LM_HASH_LEN; i++) {
528                 buf[i] = (uint8_t) rand();
529         }
530         pdb_set_lanman_passwd(out, buf, PDB_SET);
531         for (i = 0; i < history * PW_HISTORY_ENTRY_LEN; i++) {
532                 buf[i] = (uint8_t) rand();
533         }
534         pdb_set_pw_history(out, buf, history, PDB_SET);
535
536         pdb_get_account_policy(PDB_POLICY_MAX_PASSWORD_AGE, &expire);
537         pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_AGE, &min_age);
538         pdb_set_pass_last_set_time(out, time(NULL), PDB_SET);
539
540         if (min_age == (uint32_t)-1) {
541                 pdb_set_pass_can_change_time(out, 0, PDB_SET);
542         } else {
543                 pdb_set_pass_can_change_time(out, time(NULL)+min_age, PDB_SET);
544         }
545
546         pdb_set_logon_time(out, time(NULL)-3600, PDB_SET);
547
548         pdb_set_logoff_time(out, time(NULL), PDB_SET);
549
550         pdb_set_kickoff_time(out, time(NULL)+3600, PDB_SET);
551
552         /* Create account */
553         if (!NT_STATUS_IS_OK(rv = pdb->add_sam_account(pdb, out))) {
554                 fprintf(stderr, "Error in add_sam_account: %s\n", 
555                                 get_friendly_nt_error_msg(rv));
556                 exit(1);
557         }
558
559         if (!(in = samu_new(ctx))) {
560                 fprintf(stderr, "Can't create samu structure.\n");
561                 exit(1);
562         }
563
564         /* Get account information through getsampwnam() */
565         rv = pdb->getsampwnam(pdb, in, out->username);
566         if (NT_STATUS_IS_ERR(rv)) {
567                 fprintf(stderr, "Error getting sampw of added user %s: %s\n",
568                         out->username, nt_errstr(rv));
569                 if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) {
570                         fprintf(stderr, "Error in delete_sam_account %s\n", 
571                                         get_friendly_nt_error_msg(rv));
572                 }
573                 TALLOC_FREE(ctx);
574                 exit(1);
575         }
576
577         /* Verify integrity */
578         if (samu_correct(out, in)) {
579                 printf("User info written correctly\n");
580         } else {
581                 printf("User info NOT written correctly\n");
582                 error = True;
583         }
584
585         if (test_auth(ctx, out)) {
586                 printf("Authentication module test passed\n");
587         } else {
588                 printf("Authentication module test failed!\n");
589                 error = True;
590         }
591                         
592
593         /* Delete account */
594         if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) {
595                 fprintf(stderr, "Error in delete_sam_account %s\n", 
596                                         get_friendly_nt_error_msg(rv));
597         }
598
599         if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) {
600                 if (!test_trusted_domains(ctx, pdb, &error)) {
601                         fprintf(stderr, "failed testing trusted domains.\n");
602                         exit(1);
603                 }
604         }
605
606         TALLOC_FREE(ctx);
607
608         if (error) {
609                 return 1;
610         }
611         return 0;
612 }