s4/test-libnet-user: Remove test_createuser()
[kamenim/samba.git] / source4 / torture / libnet / libnet_user.c
1 /*
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 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 #include "includes.h"
22 #include "system/time.h"
23 #include "lib/cmdline/popt_common.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "librpc/gen_ndr/ndr_lsa_c.h"
27 #include "torture/rpc/torture_rpc.h"
28 #include "torture/libnet/usertest.h"
29 #include "torture/libnet/proto.h"
30 #include "param/param.h"
31 #include "lib/ldb_wrap.h"
32
33
34 /**
35  * Find out user's samAccountName for given
36  * user RDN. We need samAccountName value
37  * when deleting users.
38  */
39 static bool _get_account_name_for_user_rdn(struct torture_context *tctx,
40                                            struct dcerpc_binding_handle *b,
41                                            const char *user_rdn,
42                                            TALLOC_CTX *mem_ctx,
43                                            const char **_account_name)
44 {
45         const char *url;
46         struct ldb_context *ldb;
47         TALLOC_CTX *tmp_ctx;
48         bool test_res = true;
49         struct dcerpc_pipe *p = talloc_get_type_abort(b->private_data, struct dcerpc_pipe);
50         int ldb_ret;
51         struct ldb_result *ldb_res;
52         const char *account_name = NULL;
53         static const char *attrs[] = {
54                 "samAccountName",
55                 NULL
56         };
57
58         tmp_ctx = talloc_new(tctx);
59         torture_assert(tctx, tmp_ctx != NULL, "Failed to create temporary mem context");
60
61         url = talloc_asprintf(tmp_ctx, "ldap://%s/", p->binding->target_hostname);
62         torture_assert_goto(tctx, url != NULL, test_res, done, "Failed to allocate URL for ldb");
63
64         ldb = ldb_wrap_connect(tmp_ctx,
65                                tctx->ev, tctx->lp_ctx,
66                                url, NULL, cmdline_credentials, 0);
67         torture_assert_goto(tctx, ldb != NULL, test_res, done, "Failed to make LDB connection");
68
69         ldb_ret = ldb_search(ldb, tmp_ctx, &ldb_res,
70                              ldb_get_default_basedn(ldb), LDB_SCOPE_SUBTREE,
71                              attrs,
72                              "(&(objectClass=user)(name=%s))", user_rdn);
73         if (LDB_SUCCESS == ldb_ret && 1 == ldb_res->count) {
74                 account_name = ldb_msg_find_attr_as_string(ldb_res->msgs[0], "samAccountName", NULL);
75         }
76
77         /* return user_rdn by default */
78         if (!account_name) {
79                 account_name = user_rdn;
80         }
81
82         /* duplicate memory in parent context */
83         *_account_name = talloc_strdup(mem_ctx, account_name);
84
85 done:
86         talloc_free(tmp_ctx);
87         return test_res;
88 }
89
90 /**
91  * Deletes a user account when given user RDN name
92  *
93  * @param username RDN for the user to be deleted
94  */
95 static bool test_cleanup(struct torture_context *tctx,
96                          struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
97                          struct policy_handle *domain_handle, const char *username)
98 {
99         struct samr_LookupNames r1;
100         struct samr_OpenUser r2;
101         struct samr_DeleteUser r3;
102         struct lsa_String names[2];
103         uint32_t rid;
104         struct policy_handle user_handle;
105         struct samr_Ids rids, types;
106         const char *account_name;
107
108         if (!_get_account_name_for_user_rdn(tctx, b, username, mem_ctx, &account_name)) {
109                 torture_result(tctx, TORTURE_FAIL,
110                                __location__": Failed to find samAccountName for %s", username);
111                 return false;
112         }
113
114         names[0].string = account_name;
115
116         r1.in.domain_handle  = domain_handle;
117         r1.in.num_names      = 1;
118         r1.in.names          = names;
119         r1.out.rids          = &rids;
120         r1.out.types         = &types;
121
122         torture_comment(tctx, "user account lookup '%s'\n", account_name);
123
124         torture_assert_ntstatus_ok(tctx,
125                 dcerpc_samr_LookupNames_r(b, mem_ctx, &r1),
126                 "LookupNames failed");
127         torture_assert_ntstatus_ok(tctx, r1.out.result,
128                 "LookupNames failed");
129
130         rid = r1.out.rids->ids[0];
131
132         r2.in.domain_handle  = domain_handle;
133         r2.in.access_mask    = SEC_FLAG_MAXIMUM_ALLOWED;
134         r2.in.rid            = rid;
135         r2.out.user_handle   = &user_handle;
136
137         torture_comment(tctx, "opening user account\n");
138
139         torture_assert_ntstatus_ok(tctx,
140                 dcerpc_samr_OpenUser_r(b, mem_ctx, &r2),
141                 "OpenUser failed");
142         torture_assert_ntstatus_ok(tctx, r2.out.result,
143                 "OpenUser failed");
144
145         r3.in.user_handle  = &user_handle;
146         r3.out.user_handle = &user_handle;
147
148         torture_comment(tctx, "deleting user account\n");
149
150         torture_assert_ntstatus_ok(tctx,
151                 dcerpc_samr_DeleteUser_r(b, mem_ctx, &r3),
152                 "DeleteUser failed");
153         torture_assert_ntstatus_ok(tctx, r3.out.result,
154                 "DeleteUser failed");
155
156         return true;
157 }
158
159
160 static bool test_samr_close(struct torture_context *tctx,
161                             struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
162                             struct policy_handle *domain_handle)
163 {
164         struct samr_Close r;
165
166         r.in.handle = domain_handle;
167         r.out.handle = domain_handle;
168
169         torture_assert_ntstatus_ok(tctx,
170                 dcerpc_samr_Close_r(b, mem_ctx, &r),
171                 "Close samr domain failed");
172         torture_assert_ntstatus_ok(tctx, r.out.result,
173                 "Close samr domain failed");
174
175         return true;
176 }
177
178
179 static bool test_lsa_close(struct torture_context *tctx,
180                            struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
181                            struct policy_handle *domain_handle)
182 {
183         struct lsa_Close r;
184
185         r.in.handle = domain_handle;
186         r.out.handle = domain_handle;
187
188         torture_assert_ntstatus_ok(tctx,
189                 dcerpc_lsa_Close_r(b, mem_ctx, &r),
190                 "Close lsa domain failed");
191         torture_assert_ntstatus_ok(tctx, r.out.result,
192                 "Close lsa domain failed");
193
194         return true;
195 }
196
197
198 bool torture_createuser(struct torture_context *torture)
199 {
200         NTSTATUS status;
201         TALLOC_CTX *mem_ctx;
202         struct libnet_context *ctx;
203         struct libnet_CreateUser req;
204         bool ret = true;
205
206         mem_ctx = talloc_init("test_createuser");
207
208         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
209         ctx->cred = cmdline_credentials;
210
211         req.in.user_name = TEST_USERNAME;
212         req.in.domain_name = lp_workgroup(torture->lp_ctx);
213         req.out.error_string = NULL;
214
215         status = libnet_CreateUser(ctx, mem_ctx, &req);
216         if (!NT_STATUS_IS_OK(status)) {
217                 torture_comment(torture, "libnet_CreateUser call failed: %s\n", nt_errstr(status));
218                 ret = false;
219                 goto done;
220         }
221
222         if (!test_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) {
223                 torture_comment(torture, "cleanup failed\n");
224                 ret = false;
225                 goto done;
226         }
227
228         if (!test_samr_close(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
229                 torture_comment(torture, "domain close failed\n");
230                 ret = false;
231         }
232
233 done:
234         talloc_free(ctx);
235         talloc_free(mem_ctx);
236         return ret;
237 }
238
239
240 bool torture_deleteuser(struct torture_context *torture)
241 {
242         NTSTATUS status;
243         struct dcerpc_pipe *p;
244         TALLOC_CTX *prep_mem_ctx, *mem_ctx;
245         struct policy_handle h;
246         struct lsa_String domain_name;
247         const char *name = TEST_USERNAME;
248         struct libnet_context *ctx;
249         struct libnet_DeleteUser req;
250         bool ret = true;
251
252         prep_mem_ctx = talloc_init("prepare test_deleteuser");
253
254         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
255         ctx->cred = cmdline_credentials;
256
257         req.in.user_name = TEST_USERNAME;
258         req.in.domain_name = lp_workgroup(torture->lp_ctx);
259
260         status = torture_rpc_connection(torture,
261                                         &p,
262                                         &ndr_table_samr);
263         if (!NT_STATUS_IS_OK(status)) {
264                 ret = false;
265                 goto done;
266         }
267
268         domain_name.string = lp_workgroup(torture->lp_ctx);
269         if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) {
270                 ret = false;
271                 goto done;
272         }
273
274         if (!test_user_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) {
275                 ret = false;
276                 goto done;
277         }
278
279         mem_ctx = talloc_init("test_deleteuser");
280
281         status = libnet_DeleteUser(ctx, mem_ctx, &req);
282         if (!NT_STATUS_IS_OK(status)) {
283                 torture_comment(torture, "libnet_DeleteUser call failed: %s\n", nt_errstr(status));
284                 ret = false;
285         }
286
287         talloc_free(mem_ctx);
288
289 done:
290         talloc_free(ctx);
291         talloc_free(prep_mem_ctx);
292         return ret;
293 }
294
295
296 /*
297   Generate testing set of random changes
298 */
299
300 static void set_test_changes(struct torture_context *tctx,
301                              TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r,
302                              int num_changes, char **user_name, enum test_fields req_change)
303 {
304         const char* logon_scripts[] = { "start_login.cmd", "login.bat", "start.cmd" };
305         const char* home_dirs[] = { "\\\\srv\\home", "\\\\homesrv\\home\\user", "\\\\pdcsrv\\domain" };
306         const char* home_drives[] = { "H:", "z:", "I:", "J:", "n:" };
307         const uint32_t flags[] = { (ACB_DISABLED | ACB_NORMAL | ACB_PW_EXPIRED),
308                                    (ACB_NORMAL | ACB_PWNOEXP),
309                                    (ACB_NORMAL | ACB_PW_EXPIRED) };
310         const char *homedir, *homedrive, *logonscript;
311         struct timeval now;
312         int i, testfld;
313
314         torture_comment(tctx, "Fields to change: [");
315
316         for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) {
317                 const char *fldname;
318
319                 testfld = (req_change == none) ? (random() % USER_FIELD_LAST) + 1 : req_change;
320
321                 /* get one in case we hit time field this time */
322                 gettimeofday(&now, NULL);
323
324                 switch (testfld) {
325                 case acct_name:
326                         continue_if_field_set(r->in.account_name);
327                         r->in.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
328                                                              (int)(random() % 100));
329                         fldname = "account_name";
330
331                         /* update the test's user name in case it's about to change */
332                         *user_name = talloc_strdup(mem_ctx, r->in.account_name);
333                         break;
334
335                 case acct_full_name:
336                         continue_if_field_set(r->in.full_name);
337                         r->in.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
338                                                           (unsigned int)random(), (unsigned int)random());
339                         fldname = "full_name";
340                         break;
341
342                 case acct_description:
343                         continue_if_field_set(r->in.description);
344                         r->in.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
345                                                             (long)random());
346                         fldname = "description";
347                         break;
348
349                 case acct_home_directory:
350                         continue_if_field_set(r->in.home_directory);
351                         homedir = home_dirs[random() % ARRAY_SIZE(home_dirs)];
352                         r->in.home_directory = talloc_strdup(mem_ctx, homedir);
353                         fldname = "home_dir";
354                         break;
355
356                 case acct_home_drive:
357                         continue_if_field_set(r->in.home_drive);
358                         homedrive = home_drives[random() % ARRAY_SIZE(home_drives)];
359                         r->in.home_drive = talloc_strdup(mem_ctx, homedrive);
360                         fldname = "home_drive";
361                         break;
362
363                 case acct_comment:
364                         continue_if_field_set(r->in.comment);
365                         r->in.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
366                                                         (unsigned long)random(), (unsigned long)random());
367                         fldname = "comment";
368                         break;
369
370                 case acct_logon_script:
371                         continue_if_field_set(r->in.logon_script);
372                         logonscript = logon_scripts[random() % ARRAY_SIZE(logon_scripts)];
373                         r->in.logon_script = talloc_strdup(mem_ctx, logonscript);
374                         fldname = "logon_script";
375                         break;
376
377                 case acct_profile_path:
378                         continue_if_field_set(r->in.profile_path);
379                         r->in.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
380                                                              (unsigned long)random(), (unsigned int)random());
381                         fldname = "profile_path";
382                         break;
383
384                 case acct_expiry:
385                         continue_if_field_set(r->in.acct_expiry);
386                         now = timeval_add(&now, (random() % (31*24*60*60)), 0);
387                         r->in.acct_expiry = (struct timeval *)talloc_memdup(mem_ctx, &now, sizeof(now));
388                         fldname = "acct_expiry";
389                         break;
390
391                 case acct_flags:
392                         continue_if_field_set(r->in.acct_flags);
393                         r->in.acct_flags = flags[random() % ARRAY_SIZE(flags)];
394                         fldname = "acct_flags";
395                         break;
396
397                 default:
398                         fldname = "unknown_field";
399                 }
400
401                 torture_comment(tctx, ((i < num_changes - 1) ? "%s," : "%s"), fldname);
402
403                 /* disable requested field (it's supposed to be the only one used) */
404                 if (req_change != none) req_change = none;
405         }
406
407         torture_comment(tctx, "]\n");
408 }
409
410
411 #define TEST_STR_FLD(fld) \
412         if (!strequal(req.in.fld, user_req.out.fld)) { \
413                 torture_comment(torture, "failed to change '%s'\n", #fld); \
414                 ret = false; \
415                 goto cleanup; \
416         }
417
418 #define TEST_TIME_FLD(fld) \
419         if (timeval_compare(req.in.fld, user_req.out.fld)) { \
420                 torture_comment(torture, "failed to change '%s'\n", #fld); \
421                 ret = false; \
422                 goto cleanup; \
423         }
424
425 #define TEST_NUM_FLD(fld) \
426         if (req.in.fld != user_req.out.fld) { \
427                 torture_comment(torture, "failed to change '%s'\n", #fld); \
428                 ret = false; \
429                 goto cleanup; \
430         }
431
432
433 static bool _libnet_context_init_pipes(struct torture_context *tctx,
434                                        struct libnet_context *libnet_ctx)
435 {
436         NTSTATUS status;
437
438         /* connect SAMR pipe */
439         status = torture_rpc_connection(tctx,
440                                         &libnet_ctx->samr.pipe,
441                                         &ndr_table_samr);
442         torture_assert_ntstatus_ok(tctx, status, "Failed to open SAMR pipe");
443
444         libnet_ctx->samr.samr_handle = libnet_ctx->samr.pipe->binding_handle;
445
446
447         /* connect LSARPC pipe */
448         status = torture_rpc_connection(tctx,
449                                         &libnet_ctx->lsa.pipe,
450                                         &ndr_table_lsarpc);
451         torture_assert_ntstatus_ok(tctx, status, "Failed to open LSA pipe");
452
453         libnet_ctx->lsa.lsa_handle = libnet_ctx->lsa.pipe->binding_handle;
454
455         return true;
456 }
457
458 bool torture_modifyuser(struct torture_context *torture)
459 {
460         NTSTATUS status;
461         struct dcerpc_pipe *p;
462         TALLOC_CTX *prep_mem_ctx;
463         struct policy_handle h;
464         struct lsa_String domain_name;
465         char *name;
466         struct libnet_context *ctx;
467         struct libnet_ModifyUser req;
468         struct libnet_UserInfo user_req;
469         int fld;
470         bool ret = true;
471         struct dcerpc_binding_handle *b;
472
473         prep_mem_ctx = talloc_init("prepare test_deleteuser");
474
475         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
476         ctx->cred = cmdline_credentials;
477
478         status = torture_rpc_connection(torture,
479                                         &p,
480                                         &ndr_table_samr);
481         if (!NT_STATUS_IS_OK(status)) {
482                 ret = false;
483                 goto done;
484         }
485         b = p->binding_handle;
486
487         name = talloc_strdup(prep_mem_ctx, TEST_USERNAME);
488
489         domain_name.string = lp_workgroup(torture->lp_ctx);
490         if (!test_domain_open(torture, b, &domain_name, prep_mem_ctx, &h, NULL)) {
491                 ret = false;
492                 goto done;
493         }
494
495         if (!test_user_create(torture, b, prep_mem_ctx, &h, name, NULL)) {
496                 ret = false;
497                 goto done;
498         }
499
500         torture_comment(torture, "Testing change of all fields - each single one in turn\n");
501
502         if (!_libnet_context_init_pipes(torture, ctx)) {
503                 return false;
504         }
505
506         for (fld = USER_FIELD_FIRST; fld <= USER_FIELD_LAST; fld++) {
507                 ZERO_STRUCT(req);
508                 req.in.domain_name = lp_workgroup(torture->lp_ctx);
509                 req.in.user_name = name;
510
511                 set_test_changes(torture, torture, &req, 1, &name, fld);
512
513                 status = libnet_ModifyUser(ctx, torture, &req);
514                 if (!NT_STATUS_IS_OK(status)) {
515                         torture_comment(torture, "libnet_ModifyUser call failed: %s\n", nt_errstr(status));
516                         ret = false;
517                         continue;
518                 }
519
520                 ZERO_STRUCT(user_req);
521                 user_req.in.domain_name = lp_workgroup(torture->lp_ctx);
522                 user_req.in.data.user_name = name;
523                 user_req.in.level = USER_INFO_BY_NAME;
524
525                 status = libnet_UserInfo(ctx, torture, &user_req);
526                 if (!NT_STATUS_IS_OK(status)) {
527                         torture_comment(torture, "libnet_UserInfo call failed: %s\n", nt_errstr(status));
528                         ret = false;
529                         continue;
530                 }
531
532                 switch (fld) {
533                 case acct_name: TEST_STR_FLD(account_name);
534                         break;
535                 case acct_full_name: TEST_STR_FLD(full_name);
536                         break;
537                 case acct_comment: TEST_STR_FLD(comment);
538                         break;
539                 case acct_description: TEST_STR_FLD(description);
540                         break;
541                 case acct_home_directory: TEST_STR_FLD(home_directory);
542                         break;
543                 case acct_home_drive: TEST_STR_FLD(home_drive);
544                         break;
545                 case acct_logon_script: TEST_STR_FLD(logon_script);
546                         break;
547                 case acct_profile_path: TEST_STR_FLD(profile_path);
548                         break;
549                 case acct_expiry: TEST_TIME_FLD(acct_expiry);
550                         break;
551                 case acct_flags: TEST_NUM_FLD(acct_flags);
552                         break;
553                 default:
554                         break;
555                 }
556         }
557
558 cleanup:
559         if (!test_cleanup(torture, ctx->samr.pipe->binding_handle,
560                           torture, &ctx->samr.handle, TEST_USERNAME)) {
561                 torture_comment(torture, "cleanup failed\n");
562                 ret = false;
563                 goto done;
564         }
565
566         if (!test_samr_close(torture, ctx->samr.pipe->binding_handle, torture, &ctx->samr.handle)) {
567                 torture_comment(torture, "domain close failed\n");
568                 ret = false;
569         }
570
571 done:
572         talloc_free(ctx);
573         talloc_free(prep_mem_ctx);
574         return ret;
575 }
576
577
578 bool torture_userinfo_api(struct torture_context *torture)
579 {
580         const char *name = TEST_USERNAME;
581         bool ret = true;
582         NTSTATUS status;
583         TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
584         struct libnet_context *ctx;
585         struct dcerpc_pipe *p;
586         struct policy_handle h;
587         struct lsa_String domain_name;
588         struct libnet_UserInfo req;
589         struct dcerpc_binding_handle *b;
590
591         prep_mem_ctx = talloc_init("prepare torture user info");
592
593         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
594         ctx->cred = cmdline_credentials;
595
596         status = torture_rpc_connection(torture,
597                                         &p,
598                                         &ndr_table_samr);
599         if (!NT_STATUS_IS_OK(status)) {
600                 return false;
601         }
602         b = p->binding_handle;
603
604         domain_name.string = lp_workgroup(torture->lp_ctx);
605         if (!test_domain_open(torture, b, &domain_name, prep_mem_ctx, &h, NULL)) {
606                 ret = false;
607                 goto done;
608         }
609
610         if (!test_user_create(torture, b, prep_mem_ctx, &h, name, NULL)) {
611                 ret = false;
612                 goto done;
613         }
614
615         mem_ctx = talloc_init("torture user info");
616
617         ZERO_STRUCT(req);
618
619         req.in.domain_name = domain_name.string;
620         req.in.data.user_name   = name;
621         req.in.level = USER_INFO_BY_NAME;
622
623         status = libnet_UserInfo(ctx, mem_ctx, &req);
624         if (!NT_STATUS_IS_OK(status)) {
625                 torture_comment(torture, "libnet_UserInfo call failed: %s\n", nt_errstr(status));
626                 ret = false;
627                 goto done;
628         }
629
630         if (!test_cleanup(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) {
631                 torture_comment(torture, "cleanup failed\n");
632                 ret = false;
633                 goto done;
634         }
635
636         if (!test_samr_close(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
637                 torture_comment(torture, "domain close failed\n");
638                 ret = false;
639         }
640
641         talloc_free(ctx);
642
643 done:
644         talloc_free(mem_ctx);
645         return ret;
646 }
647
648
649 bool torture_userlist(struct torture_context *torture)
650 {
651         bool ret = true;
652         NTSTATUS status;
653         TALLOC_CTX *mem_ctx = NULL;
654         struct libnet_context *ctx;
655         struct lsa_String domain_name;
656         struct libnet_UserList req;
657         int i;
658
659         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
660         ctx->cred = cmdline_credentials;
661
662         domain_name.string = lp_workgroup(torture->lp_ctx);
663         mem_ctx = talloc_init("torture user list");
664
665         ZERO_STRUCT(req);
666
667         torture_comment(torture, "listing user accounts:\n");
668
669         do {
670
671                 req.in.domain_name = domain_name.string;
672                 req.in.page_size   = 128;
673                 req.in.resume_index = req.out.resume_index;
674
675                 status = libnet_UserList(ctx, mem_ctx, &req);
676                 if (!NT_STATUS_IS_OK(status) &&
677                     !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break;
678
679                 for (i = 0; i < req.out.count; i++) {
680                         torture_comment(torture, "\tuser: %s, sid=%s\n",
681                                req.out.users[i].username, req.out.users[i].sid);
682                 }
683
684         } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
685
686         if (!(NT_STATUS_IS_OK(status) ||
687               NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) {
688                 torture_comment(torture, "libnet_UserList call failed: %s\n", nt_errstr(status));
689                 ret = false;
690                 goto done;
691         }
692
693         if (!test_samr_close(torture, ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) {
694                 torture_comment(torture, "samr domain close failed\n");
695                 ret = false;
696                 goto done;
697         }
698
699         if (!test_lsa_close(torture, ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) {
700                 torture_comment(torture, "lsa domain close failed\n");
701                 ret = false;
702         }
703
704         talloc_free(ctx);
705
706 done:
707         talloc_free(mem_ctx);
708         return ret;
709 }