r25446: Merge some changes I made on the way home from SFO:
[ira/wip.git] / source4 / torture / winbind / struct_based.c
1 /*
2    Unix SMB/CIFS implementation.
3    SMB torture tester - winbind struct based protocol
4    Copyright (C) Stefan Metzmacher 2007
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "pstring.h"
22 #include "torture/torture.h"
23 #include "torture/winbind/proto.h"
24 #include "nsswitch/winbind_client.h"
25 #include "libcli/security/security.h"
26 #include "librpc/gen_ndr/netlogon.h"
27 #include "param/param.h"
28 #include "auth/pam_errors.h"
29
30 #define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \
31         NSS_STATUS __got, __expected = (expected); \
32         __got = winbindd_request_response(op, req, rep); \
33         if (__got != __expected) { \
34                 const char *__cmt = (cmt); \
35                 if (strict) { \
36                         torture_result(torture, TORTURE_FAIL, \
37                                 __location__ ": " __STRING(op) \
38                                 " returned %d, expected %d%s%s", \
39                                 __got, __expected, \
40                                 (__cmt) ? ": " : "", \
41                                 (__cmt) ? (__cmt) : ""); \
42                         return false; \
43                 } else { \
44                         torture_warning(torture, \
45                                 __location__ ": " __STRING(op) \
46                                 " returned %d, expected %d%s%s", \
47                                 __got, __expected, \
48                                 (__cmt) ? ": " : "", \
49                                 (__cmt) ? (__cmt) : ""); \
50                         warnaction; \
51                 } \
52         } \
53 } while(0)
54
55 #define DO_STRUCT_REQ_REP(op,req,rep) do { \
56         bool __noop = false; \
57         DO_STRUCT_REQ_REP_EXT(op,req,rep,NSS_STATUS_SUCCESS,true,__noop=true,NULL); \
58 } while (0)
59
60 static bool torture_winbind_struct_interface_version(struct torture_context *torture)
61 {
62         struct winbindd_request req;
63         struct winbindd_response rep;
64
65         ZERO_STRUCT(req);
66         ZERO_STRUCT(rep);
67
68         torture_comment(torture, "Running WINBINDD_INTERFACE_VERSION (struct based)\n");
69
70         DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION, &req, &rep);
71
72         torture_assert_int_equal(torture,
73                                  rep.data.interface_version,
74                                  WINBIND_INTERFACE_VERSION,
75                                  "winbind server and client doesn't match");
76
77         return true;
78 }
79
80 static bool torture_winbind_struct_ping(struct torture_context *torture)
81 {
82         struct timeval tv = timeval_current();
83         int timelimit = torture_setting_int(torture, "timelimit", 5);
84         uint32_t total = 0;
85
86         torture_comment(torture,
87                         "Running WINBINDD_PING (struct based) for %d seconds\n",
88                         timelimit);
89
90         while (timeval_elapsed(&tv) < timelimit) {
91                 DO_STRUCT_REQ_REP(WINBINDD_PING, NULL, NULL);
92                 total++;
93         }
94
95         torture_comment(torture,
96                         "%u (%.1f/s) WINBINDD_PING (struct based)\n",
97                         total, total / timeval_elapsed(&tv));
98
99         return true;
100 }
101
102 static bool torture_winbind_struct_info(struct torture_context *torture)
103 {
104         struct winbindd_response rep;
105         const char *separator;
106
107         ZERO_STRUCT(rep);
108
109         torture_comment(torture, "Running WINBINDD_INFO (struct based)\n");
110
111         DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep);
112
113         separator = torture_setting_string(torture,
114                                            "winbindd separator",
115                                            lp_winbind_separator(global_loadparm));
116         torture_assert_int_equal(torture,
117                                  rep.data.info.winbind_separator,
118                                  *separator,
119                                  "winbind separator doesn't match");
120
121         torture_comment(torture, "Samba Version '%s'\n",
122                         rep.data.info.samba_version);
123
124         return true;
125 }
126
127 static bool torture_winbind_struct_priv_pipe_dir(struct torture_context *torture)
128 {
129         struct winbindd_response rep;
130         const char *default_dir;
131         const char *expected_dir;
132         const char *got_dir;
133
134         ZERO_STRUCT(rep);
135
136         torture_comment(torture, "Running WINBINDD_PRIV_PIPE_DIR (struct based)\n");
137
138         DO_STRUCT_REQ_REP(WINBINDD_PRIV_PIPE_DIR, NULL, &rep);
139
140         got_dir = (const char *)rep.extra_data.data;
141
142         torture_assert(torture, got_dir, "NULL WINBINDD_PRIV_PIPE_DIR\n");
143
144         default_dir = lock_path(torture, global_loadparm, 
145                                 WINBINDD_PRIV_SOCKET_SUBDIR);
146         expected_dir = torture_setting_string(torture,
147                                               "winbindd private pipe dir",
148                                               default_dir);
149
150         torture_assert_str_equal(torture, got_dir, expected_dir,
151                                  "WINBINDD_PRIV_PIPE_DIR doesn't match");
152
153         SAFE_FREE(rep.extra_data.data);
154         return true;
155 }
156
157 static bool torture_winbind_struct_netbios_name(struct torture_context *torture)
158 {
159         struct winbindd_response rep;
160         const char *expected;
161
162         ZERO_STRUCT(rep);
163
164         torture_comment(torture, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
165
166         DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, NULL, &rep);
167
168         expected = torture_setting_string(torture,
169                                           "winbindd netbios name",
170                                           lp_netbios_name(global_loadparm));
171
172         torture_assert_str_equal(torture,
173                                  rep.data.netbios_name, expected,
174                                  "winbindd's netbios name doesn't match");
175
176         return true;
177 }
178
179 static bool torture_winbind_struct_domain_name(struct torture_context *torture)
180 {
181         struct winbindd_response rep;
182         const char *expected;
183
184         ZERO_STRUCT(rep);
185
186         torture_comment(torture, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
187
188         DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME, NULL, &rep);
189
190         expected = torture_setting_string(torture,
191                                           "winbindd netbios domain",
192                                           lp_workgroup(global_loadparm));
193
194         torture_assert_str_equal(torture,
195                                  rep.data.domain_name, expected,
196                                  "winbindd's netbios domain doesn't match");
197
198         return true;
199 }
200
201 static bool torture_winbind_struct_check_machacc(struct torture_context *torture)
202 {
203         bool ok;
204         bool strict = torture_setting_bool(torture, "strict mode", false);
205         struct winbindd_response rep;
206
207         ZERO_STRUCT(rep);
208
209         torture_comment(torture, "Running WINBINDD_CHECK_MACHACC (struct based)\n");
210
211         ok = true;
212         DO_STRUCT_REQ_REP_EXT(WINBINDD_CHECK_MACHACC, NULL, &rep,
213                               NSS_STATUS_SUCCESS, strict, ok = false,
214                               "WINBINDD_CHECK_MACHACC");
215
216         if (!ok) {
217                 torture_assert(torture,
218                                strlen(rep.data.auth.nt_status_string)>0,
219                                "Failed with empty nt_status_string");
220
221                 torture_warning(torture,"%s:%s:%s:%d\n",
222                                 nt_errstr(NT_STATUS(rep.data.auth.nt_status)),
223                                 rep.data.auth.nt_status_string,
224                                 rep.data.auth.error_string,
225                                 rep.data.auth.pam_error);
226                 return true;
227         }
228
229         torture_assert_ntstatus_ok(torture,
230                                    NT_STATUS(rep.data.auth.nt_status),
231                                    "WINBINDD_CHECK_MACHACC ok: nt_status");
232
233         torture_assert_str_equal(torture,
234                                  rep.data.auth.nt_status_string,
235                                  nt_errstr(NT_STATUS_OK),
236                                  "WINBINDD_CHECK_MACHACC ok:nt_status_string");
237
238         torture_assert_str_equal(torture,
239                                  rep.data.auth.error_string,
240                                  nt_errstr(NT_STATUS_OK),
241                                  "WINBINDD_CHECK_MACHACC ok: error_string");
242
243         torture_assert_int_equal(torture,
244                                  rep.data.auth.pam_error,
245                                  nt_status_to_pam(NT_STATUS_OK),
246                                  "WINBINDD_CHECK_MACHACC ok: pam_error");
247
248         return true;
249 }
250
251 struct torture_trust_domain {
252         const char *netbios_name;
253         const char *dns_name;
254         struct dom_sid *sid;
255 };
256
257 static bool get_trusted_domains(struct torture_context *torture,
258                                 struct torture_trust_domain **_d)
259 {
260         struct winbindd_request req;
261         struct winbindd_response rep;
262         struct torture_trust_domain *d = NULL;
263         uint32_t dcount = 0;
264         fstring line;
265         const char *extra_data;
266
267         ZERO_STRUCT(req);
268         ZERO_STRUCT(rep);
269
270         DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
271
272         extra_data = (char *)rep.extra_data.data;
273         torture_assert(torture, extra_data, "NULL trust list");
274
275         while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
276                 char *p, *lp;
277
278                 d = talloc_realloc(torture, d,
279                                    struct torture_trust_domain,
280                                    dcount + 2);
281                 ZERO_STRUCT(d[dcount+1]);
282
283                 lp = line;
284                 p = strchr(lp, '\\');
285                 torture_assert(torture, p, "missing 1st '\\' in line");
286                 *p = 0;
287                 d[dcount].netbios_name = talloc_strdup(d, lp);
288                 torture_assert(torture, strlen(d[dcount].netbios_name) > 0,
289                                "empty netbios_name");
290
291                 lp = p+1;
292                 p = strchr(lp, '\\');
293                 torture_assert(torture, p, "missing 2nd '\\' in line");
294                 *p = 0;
295                 d[dcount].dns_name = talloc_strdup(d, lp);
296                 /* it's ok to have an empty dns_name */
297
298                 lp = p+1;
299                 d[dcount].sid = dom_sid_parse_talloc(d, lp);
300                 torture_assert(torture, d[dcount].sid,
301                                "failed to parse sid");
302
303                 dcount++;
304         }
305         SAFE_FREE(rep.extra_data.data);
306
307         torture_assert(torture, dcount >= 2,
308                        "The list of trusted domain should contain 2 entries");
309
310         *_d = d;
311         return true;
312 }
313
314 static bool torture_winbind_struct_list_trustdom(struct torture_context *torture)
315 {
316         struct winbindd_request req;
317         struct winbindd_response rep;
318         char *list1;
319         char *list2;
320         bool ok;
321         struct torture_trust_domain *listd = NULL;
322         uint32_t i;
323
324         torture_comment(torture, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n");
325
326         ZERO_STRUCT(req);
327         ZERO_STRUCT(rep);
328
329         req.data.list_all_domains = false;
330
331         DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
332
333         list1 = (char *)rep.extra_data.data;
334         torture_assert(torture, list1, "NULL trust list");
335
336         torture_comment(torture, "%s\n", list1);
337
338         ZERO_STRUCT(req);
339         ZERO_STRUCT(rep);
340
341         req.data.list_all_domains = true;
342
343         DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
344
345         list2 = (char *)rep.extra_data.data;
346         torture_assert(torture, list2, "NULL trust list");
347
348         /*
349          * The list_all_domains parameter should be ignored
350          */
351         torture_assert_str_equal(torture, list2, list1, "list_all_domains not ignored");
352
353         SAFE_FREE(list1);
354         SAFE_FREE(list2);
355
356         ok = get_trusted_domains(torture, &listd);
357         torture_assert(torture, ok, "failed to get trust list");
358
359         for (i=0; listd[i].netbios_name; i++) {
360                 if (i == 0) {
361                         struct dom_sid *builtin_sid;
362
363                         builtin_sid = dom_sid_parse_talloc(torture, SID_BUILTIN);
364
365                         torture_assert_str_equal(torture,
366                                                  listd[i].netbios_name,
367                                                  NAME_BUILTIN,
368                                                  "first domain should be 'BUILTIN'");
369
370                         torture_assert_str_equal(torture,
371                                                  listd[i].dns_name,
372                                                  "",
373                                                  "BUILTIN domain should not have a dns name");
374
375                         ok = dom_sid_equal(builtin_sid,
376                                            listd[i].sid);
377                         torture_assert(torture, ok, "BUILTIN domain should have S-1-5-32");
378
379                         continue;
380                 }
381
382                 /*
383                  * TODO: verify the content of the 2nd and 3rd (in member server mode)
384                  *       domain entries
385                  */
386         }
387
388         return true;
389 }
390
391 static bool torture_winbind_struct_domain_info(struct torture_context *torture)
392 {
393         bool ok;
394         struct torture_trust_domain *listd = NULL;
395         uint32_t i;
396
397         torture_comment(torture, "Running WINBINDD_DOMAIN_INFO (struct based)\n");
398
399         ok = get_trusted_domains(torture, &listd);
400         torture_assert(torture, ok, "failed to get trust list");
401
402         for (i=0; listd[i].netbios_name; i++) {
403                 struct winbindd_request req;
404                 struct winbindd_response rep;
405                 struct dom_sid *sid;
406                 char *flagstr = talloc_strdup(torture," ");
407
408                 ZERO_STRUCT(req);
409                 ZERO_STRUCT(rep);
410
411                 fstrcpy(req.domain_name, listd[i].netbios_name);
412
413                 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO, &req, &rep);
414
415                 torture_assert_str_equal(torture,
416                                          rep.data.domain_info.name,
417                                          listd[i].netbios_name,
418                                          "Netbios domain name doesn't match");
419
420                 torture_assert_str_equal(torture,
421                                          rep.data.domain_info.alt_name,
422                                          listd[i].dns_name,
423                                          "DNS domain name doesn't match");
424
425                 sid = dom_sid_parse_talloc(torture, rep.data.domain_info.sid);
426                 torture_assert(torture, sid, "Failed to parse SID");
427
428                 ok = dom_sid_equal(listd[i].sid, sid);
429                 torture_assert(torture, ok, "SID's doesn't match");
430
431                 if (rep.data.domain_info.primary) {
432                         flagstr = talloc_strdup_append(flagstr, "PR ");
433                 }
434
435                 if (rep.data.domain_info.active_directory) {
436                         torture_assert(torture,
437                                        strlen(rep.data.domain_info.alt_name)>0,
438                                        "Active Directory without DNS name");
439                         flagstr = talloc_strdup_append(flagstr, "AD ");
440                 }
441
442                 if (rep.data.domain_info.native_mode) {
443                         torture_assert(torture,
444                                        rep.data.domain_info.active_directory,
445                                        "Native-Mode, but no Active Directory");
446                         flagstr = talloc_strdup_append(flagstr, "NA ");
447                 }
448
449                 torture_comment(torture, "DOMAIN '%s' => '%s' [%s]\n",
450                                 rep.data.domain_info.name,
451                                 rep.data.domain_info.alt_name,
452                                 flagstr);
453         }
454
455         return true;
456 }
457
458 static bool torture_winbind_struct_getdcname(struct torture_context *torture)
459 {
460         bool ok;
461         bool strict = torture_setting_bool(torture, "strict mode", false);
462         struct torture_trust_domain *listd = NULL;
463         uint32_t i;
464
465         torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n");
466
467         ok = get_trusted_domains(torture, &listd);
468         torture_assert(torture, ok, "failed to get trust list");
469
470         for (i=0; listd[i].netbios_name; i++) {
471                 struct winbindd_request req;
472                 struct winbindd_response rep;
473
474                 ZERO_STRUCT(req);
475                 ZERO_STRUCT(rep);
476
477                 fstrcpy(req.domain_name, listd[i].netbios_name);
478
479                 ok = true;
480                 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME, &req, &rep,
481                                       NSS_STATUS_SUCCESS,
482                                       (i <2 || strict), ok = false,
483                                       talloc_asprintf(torture, "DOMAIN '%s'",
484                                                       req.domain_name));
485                 if (!ok) continue;
486
487                 /* TODO: check rep.data.dc_name; */
488                 torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
489                                 req.domain_name, rep.data.dc_name);
490         }
491
492         return true;
493 }
494
495 static bool torture_winbind_struct_dsgetdcname(struct torture_context *torture)
496 {
497         bool ok;
498         bool strict = torture_setting_bool(torture, "strict mode", false);
499         struct torture_trust_domain *listd = NULL;
500         uint32_t i;
501         uint32_t count = 0;
502
503         torture_comment(torture, "Running WINBINDD_DSGETDCNAME (struct based)\n");
504
505         ok = get_trusted_domains(torture, &listd);
506         torture_assert(torture, ok, "failed to get trust list");
507
508         for (i=0; listd[i].netbios_name; i++) {
509                 struct winbindd_request req;
510                 struct winbindd_response rep;
511
512                 ZERO_STRUCT(req);
513                 ZERO_STRUCT(rep);
514
515                 if (strlen(listd[i].dns_name) == 0) continue;
516
517                 /*
518                  * TODO: remove this and let winbindd give no dns name
519                  *       for NT4 domains
520                  */
521                 if (strcmp(listd[i].dns_name, listd[i].netbios_name) == 0) {
522                         continue;
523                 }
524
525                 fstrcpy(req.domain_name, listd[i].dns_name);
526
527                 /* TODO: test more flag combinations */
528                 req.flags = DS_DIRECTORY_SERVICE_REQUIRED;
529
530                 ok = true;
531                 DO_STRUCT_REQ_REP_EXT(WINBINDD_DSGETDCNAME, &req, &rep,
532                                       NSS_STATUS_SUCCESS,
533                                       strict, ok = false,
534                                       talloc_asprintf(torture, "DOMAIN '%s'",
535                                                       req.domain_name));
536                 if (!ok) continue;
537
538                 /* TODO: check rep.data.dc_name; */
539                 torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
540                                 req.domain_name, rep.data.dc_name);
541
542                 count++;
543         }
544
545         if (count == 0) {
546                 torture_warning(torture, "WINBINDD_DSGETDCNAME"
547                                 " was not tested with %d non-AD domains",
548                                 i);
549         }
550
551         if (strict) {
552                 torture_assert(torture, count > 0,
553                                "WiNBINDD_DSGETDCNAME was not tested");
554         }
555
556         return true;
557 }
558
559 static bool torture_winbind_struct_list_users(struct torture_context *torture)
560 {
561         struct winbindd_request req;
562         struct winbindd_response rep;
563
564         torture_comment(torture, "Running WINBINDD_LIST_USERS (struct based)\n");
565
566         ZERO_STRUCT(req);
567         ZERO_STRUCT(rep);
568
569         DO_STRUCT_REQ_REP(WINBINDD_LIST_USERS, &req, &rep);
570
571         return true;
572 }
573
574 static bool torture_winbind_struct_list_groups(struct torture_context *torture)
575 {
576         struct winbindd_request req;
577         struct winbindd_response rep;
578
579         torture_comment(torture, "Running WINBINDD_LIST_GROUPS (struct based)\n");
580
581         ZERO_STRUCT(req);
582         ZERO_STRUCT(rep);
583
584         DO_STRUCT_REQ_REP(WINBINDD_LIST_GROUPS, &req, &rep);
585
586         return true;
587 }
588
589 struct torture_domain_sequence {
590         const char *netbios_name;
591         uint32_t seq;
592 };
593
594 static bool torture_winbind_struct_show_sequence(struct torture_context *torture)
595 {
596         struct winbindd_request req;
597         struct winbindd_response rep;
598         bool ok;
599         const char *extra_data;
600         fstring line;
601         uint32_t i;
602         uint32_t count = 0;
603         struct torture_trust_domain *domlist = NULL;
604         struct torture_domain_sequence *s = NULL;
605
606         torture_comment(torture, "Running WINBINDD_SHOW_SEQUENCE (struct based)\n");
607
608         torture_comment(torture, " - Running WINBINDD_SHOW_SEQUENCE without domain:\n");
609
610         ZERO_STRUCT(req);
611         ZERO_STRUCT(rep);
612
613         DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE, &req, &rep);
614
615         extra_data = (char *)rep.extra_data.data;
616         torture_assert(torture, extra_data, "NULL sequence list");
617
618         torture_comment(torture, "%s", extra_data);
619
620         while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
621                 char *p, *lp;
622                 uint32_t seq;
623
624                 s = talloc_realloc(torture, s, struct torture_domain_sequence,
625                                    count + 2);
626                 ZERO_STRUCT(s[count+1]);
627
628                 lp = line;
629                 p = strchr(lp, ' ');
630                 torture_assert(torture, p, "invalid line format");
631                 *p = 0;
632                 s[count].netbios_name = talloc_strdup(s, lp);
633
634                 lp = p+1;
635                 torture_assert(torture, strncmp(lp, ": ", 2) == 0, "invalid line format");
636                 lp += 2;
637                 if (strcmp(lp, "DISCONNECTED") == 0) {
638                         seq = (uint32_t)-1;
639                 } else {
640                         seq = (uint32_t)strtol(lp, &p, 10);
641                         torture_assert(torture, (*p == '\0'), "invalid line format");
642                         torture_assert(torture, (seq != (uint32_t)-1),
643                                        "sequence number -1 encountered");
644                 }
645                 s[count].seq = seq;
646
647                 count++;
648         }
649
650         torture_comment(torture, " - getting list of trusted domains\n");
651         ok = get_trusted_domains(torture, &domlist);
652         torture_assert(torture, ok, "failed to get trust list");
653
654         for (i=0; domlist[i].netbios_name; i++) {
655                 uint32_t seq;
656
657                 ok = (s[i].netbios_name != NULL);
658                 torture_assert(torture, ok, "more domains recieved in second run");
659                 ok = (strcmp(domlist[i].netbios_name, s[i].netbios_name) == 0);
660                 torture_assert(torture, ok, "inconsistent order of domain lists");
661
662                 ZERO_STRUCT(req);
663                 ZERO_STRUCT(rep);
664
665                 fstrcpy(req.domain_name, domlist[i].netbios_name);
666
667                 torture_comment(torture, " - Running WINBINDD_SHOW_SEQUENCE "
668                                 "for domain %s:\n", req.domain_name);
669
670                 DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE, &req, &rep);
671                 seq = rep.data.sequence_number;
672
673                 torture_comment(torture, "%s : ", req.domain_name);
674                 if (seq == (uint32_t)-1) {
675                         torture_comment(torture, "DISCONNECTED\n");
676                 } else {
677                         torture_comment(torture, "%d\n", seq);
678                 }
679                 torture_assert(torture, (seq >= s[i].seq),
680                                "illegal sequence number encountered");
681         }
682
683         return true;
684 }
685
686 static bool torture_winbind_struct_setpwent(struct torture_context *torture)
687 {
688         struct winbindd_request req;
689         struct winbindd_response rep;
690
691         torture_comment(torture, "Running WINBINDD_SETPWENT (struct based)\n");
692
693         ZERO_STRUCT(req);
694         ZERO_STRUCT(rep);
695
696         DO_STRUCT_REQ_REP(WINBINDD_SETPWENT, &req, &rep);
697
698         return true;
699 }
700
701 static bool torture_winbind_struct_getpwent(struct torture_context *torture)
702 {
703         struct winbindd_request req;
704         struct winbindd_response rep;
705         struct winbindd_pw *pwent;
706
707         torture_comment(torture, "Running WINBINDD_GETPWENT (struct based)\n");
708
709         torture_comment(torture, " - Running WINBINDD_SETPWENT first\n");
710         ZERO_STRUCT(req);
711         ZERO_STRUCT(rep);
712         DO_STRUCT_REQ_REP(WINBINDD_SETPWENT, &req, &rep);
713
714         torture_comment(torture, " - Running WINBINDD_GETPWENT now\n");
715         ZERO_STRUCT(req);
716         ZERO_STRUCT(rep);
717         req.data.num_entries = 1;
718         DO_STRUCT_REQ_REP(WINBINDD_GETPWENT, &req, &rep);
719         pwent = (struct winbindd_pw *)rep.extra_data.data;
720         torture_assert(torture, (pwent != NULL), "NULL pwent");
721         torture_comment(torture, "name: %s, uid: %d, gid: %d, shell: %s\n",
722                         pwent->pw_name, pwent->pw_uid, pwent->pw_gid,
723                         pwent->pw_shell);
724
725         return true;
726 }
727
728 static bool torture_winbind_struct_endpwent(struct torture_context *torture)
729 {
730         struct winbindd_request req;
731         struct winbindd_response rep;
732
733         torture_comment(torture, "Running WINBINDD_ENDPWENT (struct based)\n");
734
735         ZERO_STRUCT(req);
736         ZERO_STRUCT(rep);
737
738         DO_STRUCT_REQ_REP(WINBINDD_ENDPWENT, &req, &rep);
739
740         return true;
741 }
742
743 struct torture_suite *torture_winbind_struct_init(void)
744 {
745         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "STRUCT");
746
747         torture_suite_add_simple_test(suite, "INTERFACE_VERSION", torture_winbind_struct_interface_version);
748         torture_suite_add_simple_test(suite, "PING", torture_winbind_struct_ping);
749         torture_suite_add_simple_test(suite, "INFO", torture_winbind_struct_info);
750         torture_suite_add_simple_test(suite, "PRIV_PIPE_DIR", torture_winbind_struct_priv_pipe_dir);
751         torture_suite_add_simple_test(suite, "NETBIOS_NAME", torture_winbind_struct_netbios_name);
752         torture_suite_add_simple_test(suite, "DOMAIN_NAME", torture_winbind_struct_domain_name);
753         torture_suite_add_simple_test(suite, "CHECK_MACHACC", torture_winbind_struct_check_machacc);
754         torture_suite_add_simple_test(suite, "LIST_TRUSTDOM", torture_winbind_struct_list_trustdom);
755         torture_suite_add_simple_test(suite, "DOMAIN_INFO", torture_winbind_struct_domain_info);
756         torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
757         torture_suite_add_simple_test(suite, "DSGETDCNAME", torture_winbind_struct_dsgetdcname);
758         torture_suite_add_simple_test(suite, "LIST_USERS", torture_winbind_struct_list_users);
759         torture_suite_add_simple_test(suite, "LIST_GROUPS", torture_winbind_struct_list_groups);
760         torture_suite_add_simple_test(suite, "SHOW_SEQUENCE", torture_winbind_struct_show_sequence);
761         torture_suite_add_simple_test(suite, "SETPWENT", torture_winbind_struct_setpwent);
762         torture_suite_add_simple_test(suite, "GETPWENT", torture_winbind_struct_getpwent);
763         torture_suite_add_simple_test(suite, "ENDPWENT", torture_winbind_struct_endpwent);
764
765         suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests");
766
767         return suite;
768 }