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