2 Unix SMB/CIFS implementation.
3 SMB torture tester - winbind struct based protocol
4 Copyright (C) Stefan Metzmacher 2007
5 Copyright (C) Michael Adam 2007
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.
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.
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/>.
22 #include "torture/torture.h"
23 #include "nsswitch/winbind_client.h"
24 #include "libcli/security/security.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "param/param.h"
27 #include "../libcli/auth/pam_errors.h"
28 #include "torture/winbind/proto.h"
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); \
36 torture_result(torture, TORTURE_FAIL, \
37 __location__ ": " __STRING(op) \
38 " returned %d, expected %d%s%s", \
40 (__cmt) ? ": " : "", \
41 (__cmt) ? (__cmt) : ""); \
44 torture_warning(torture, \
45 __location__ ": " __STRING(op) \
46 " returned %d, expected %d%s%s", \
48 (__cmt) ? ": " : "", \
49 (__cmt) ? (__cmt) : ""); \
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); \
60 static bool torture_winbind_struct_interface_version(struct torture_context
*torture
)
62 struct winbindd_request req
;
63 struct winbindd_response rep
;
68 torture_comment(torture
, "Running WINBINDD_INTERFACE_VERSION (struct based)\n");
70 DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION
, &req
, &rep
);
72 torture_assert_int_equal(torture
,
73 rep
.data
.interface_version
,
74 WINBIND_INTERFACE_VERSION
,
75 "winbind server and client doesn't match");
80 static bool torture_winbind_struct_ping(struct torture_context
*torture
)
82 struct timeval tv
= timeval_current();
83 int timelimit
= torture_setting_int(torture
, "timelimit", 5);
86 torture_comment(torture
,
87 "Running WINBINDD_PING (struct based) for %d seconds\n",
90 while (timeval_elapsed(&tv
) < timelimit
) {
91 DO_STRUCT_REQ_REP(WINBINDD_PING
, NULL
, NULL
);
95 torture_comment(torture
,
96 "%u (%.1f/s) WINBINDD_PING (struct based)\n",
97 total
, total
/ timeval_elapsed(&tv
));
103 static char winbind_separator(struct torture_context
*torture
)
105 struct winbindd_response rep
;
109 DO_STRUCT_REQ_REP(WINBINDD_INFO
, NULL
, &rep
);
111 return rep
.data
.info
.winbind_separator
;
114 static bool torture_winbind_struct_info(struct torture_context
*torture
)
116 struct winbindd_response rep
;
117 const char *separator
;
121 torture_comment(torture
, "Running WINBINDD_INFO (struct based)\n");
123 DO_STRUCT_REQ_REP(WINBINDD_INFO
, NULL
, &rep
);
125 separator
= torture_setting_string(torture
,
126 "winbindd_separator",
127 lpcfg_winbind_separator(torture
->lp_ctx
));
129 torture_assert_int_equal(torture
,
130 rep
.data
.info
.winbind_separator
,
132 "winbind separator doesn't match");
134 torture_comment(torture
, "Samba Version '%s'\n",
135 rep
.data
.info
.samba_version
);
140 static bool torture_winbind_struct_priv_pipe_dir(struct torture_context
*torture
)
142 struct winbindd_response rep
;
147 torture_comment(torture
, "Running WINBINDD_PRIV_PIPE_DIR (struct based)\n");
149 DO_STRUCT_REQ_REP(WINBINDD_PRIV_PIPE_DIR
, NULL
, &rep
);
151 got_dir
= (const char *)rep
.extra_data
.data
;
153 torture_assert(torture
, got_dir
, "NULL WINBINDD_PRIV_PIPE_DIR\n");
155 SAFE_FREE(rep
.extra_data
.data
);
159 static bool torture_winbind_struct_netbios_name(struct torture_context
*torture
)
161 struct winbindd_response rep
;
162 const char *expected
;
166 torture_comment(torture
, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
168 DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME
, NULL
, &rep
);
170 expected
= torture_setting_string(torture
,
171 "winbindd_netbios_name",
172 lpcfg_netbios_name(torture
->lp_ctx
));
173 expected
= strupper_talloc(torture
, expected
);
175 torture_assert_str_equal(torture
,
176 rep
.data
.netbios_name
, expected
,
177 "winbindd's netbios name doesn't match");
182 static bool get_winbind_domain(struct torture_context
*torture
, char **domain
)
184 struct winbindd_response rep
;
188 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME
, NULL
, &rep
);
190 *domain
= talloc_strdup(torture
, rep
.data
.domain_name
);
191 torture_assert(torture
, domain
, "talloc error");
196 static bool torture_winbind_struct_domain_name(struct torture_context
*torture
)
198 const char *expected
;
201 torture_comment(torture
, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
203 expected
= torture_setting_string(torture
,
204 "winbindd_netbios_domain",
205 lpcfg_workgroup(torture
->lp_ctx
));
207 get_winbind_domain(torture
, &domain
);
209 torture_assert_str_equal(torture
, domain
, expected
,
210 "winbindd's netbios domain doesn't match");
215 static bool torture_winbind_struct_check_machacc(struct torture_context
*torture
)
218 bool strict
= torture_setting_bool(torture
, "strict mode", false);
219 struct winbindd_response rep
;
223 torture_comment(torture
, "Running WINBINDD_CHECK_MACHACC (struct based)\n");
226 DO_STRUCT_REQ_REP_EXT(WINBINDD_CHECK_MACHACC
, NULL
, &rep
,
227 NSS_STATUS_SUCCESS
, strict
, ok
= false,
228 "WINBINDD_CHECK_MACHACC");
231 torture_assert(torture
,
232 strlen(rep
.data
.auth
.nt_status_string
)>0,
233 "Failed with empty nt_status_string");
235 torture_warning(torture
,"%s:%s:%s:%d\n",
236 nt_errstr(NT_STATUS(rep
.data
.auth
.nt_status
)),
237 rep
.data
.auth
.nt_status_string
,
238 rep
.data
.auth
.error_string
,
239 rep
.data
.auth
.pam_error
);
243 torture_assert_ntstatus_ok(torture
,
244 NT_STATUS(rep
.data
.auth
.nt_status
),
245 "WINBINDD_CHECK_MACHACC ok: nt_status");
247 torture_assert_str_equal(torture
,
248 rep
.data
.auth
.nt_status_string
,
249 nt_errstr(NT_STATUS_OK
),
250 "WINBINDD_CHECK_MACHACC ok:nt_status_string");
252 torture_assert_str_equal(torture
,
253 rep
.data
.auth
.error_string
,
254 get_friendly_nt_error_msg(NT_STATUS_OK
),
255 "WINBINDD_CHECK_MACHACC ok: error_string");
257 torture_assert_int_equal(torture
,
258 rep
.data
.auth
.pam_error
,
259 nt_status_to_pam(NT_STATUS_OK
),
260 "WINBINDD_CHECK_MACHACC ok: pam_error");
265 struct torture_trust_domain
{
266 const char *netbios_name
;
267 const char *dns_name
;
271 static bool get_trusted_domains(struct torture_context
*torture
,
272 struct torture_trust_domain
**_d
)
274 struct winbindd_request req
;
275 struct winbindd_response rep
;
276 struct torture_trust_domain
*d
= NULL
;
279 const char *extra_data
;
284 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
286 extra_data
= (char *)rep
.extra_data
.data
;
291 torture_assert(torture
, extra_data
, "NULL trust list");
293 while (next_token(&extra_data
, line
, "\n", sizeof(line
))) {
296 d
= talloc_realloc(torture
, d
,
297 struct torture_trust_domain
,
299 ZERO_STRUCT(d
[dcount
+1]);
302 p
= strchr(lp
, '\\');
303 torture_assert(torture
, p
, "missing 1st '\\' in line");
305 d
[dcount
].netbios_name
= talloc_strdup(d
, lp
);
306 torture_assert(torture
, strlen(d
[dcount
].netbios_name
) > 0,
307 "empty netbios_name");
310 p
= strchr(lp
, '\\');
311 torture_assert(torture
, p
, "missing 2nd '\\' in line");
313 d
[dcount
].dns_name
= talloc_strdup(d
, lp
);
314 /* it's ok to have an empty dns_name */
317 d
[dcount
].sid
= dom_sid_parse_talloc(d
, lp
);
318 torture_assert(torture
, d
[dcount
].sid
,
319 "failed to parse sid");
323 SAFE_FREE(rep
.extra_data
.data
);
325 torture_assert(torture
, dcount
>= 2,
326 "The list of trusted domain should contain 2 entries");
332 static bool torture_winbind_struct_list_trustdom(struct torture_context
*torture
)
334 struct winbindd_request req
;
335 struct winbindd_response rep
;
339 struct torture_trust_domain
*listd
= NULL
;
342 torture_comment(torture
, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n");
347 req
.data
.list_all_domains
= false;
349 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
351 list1
= (char *)rep
.extra_data
.data
;
353 torture_comment(torture
, "%s\n", list1
);
358 req
.data
.list_all_domains
= true;
360 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
362 list2
= (char *)rep
.extra_data
.data
;
365 * The list_all_domains parameter should be ignored
367 torture_assert_str_equal(torture
, list2
, list1
, "list_all_domains not ignored");
372 ok
= get_trusted_domains(torture
, &listd
);
373 torture_assert(torture
, ok
, "failed to get trust list");
375 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
377 struct dom_sid
*builtin_sid
;
379 builtin_sid
= dom_sid_parse_talloc(torture
, SID_BUILTIN
);
381 torture_assert_str_equal(torture
,
382 listd
[i
].netbios_name
,
384 "first domain should be 'BUILTIN'");
386 torture_assert_str_equal(torture
,
389 "BUILTIN domain should not have a dns name");
391 ok
= dom_sid_equal(builtin_sid
,
393 torture_assert(torture
, ok
, "BUILTIN domain should have S-1-5-32");
399 * TODO: verify the content of the 2nd and 3rd (in member server mode)
407 static bool torture_winbind_struct_domain_info(struct torture_context
*torture
)
410 struct torture_trust_domain
*listd
= NULL
;
413 torture_comment(torture
, "Running WINBINDD_DOMAIN_INFO (struct based)\n");
415 ok
= get_trusted_domains(torture
, &listd
);
416 torture_assert(torture
, ok
, "failed to get trust list");
418 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
419 struct winbindd_request req
;
420 struct winbindd_response rep
;
422 char *flagstr
= talloc_strdup(torture
," ");
427 fstrcpy(req
.domain_name
, listd
[i
].netbios_name
);
429 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO
, &req
, &rep
);
431 torture_assert_str_equal(torture
,
432 rep
.data
.domain_info
.name
,
433 listd
[i
].netbios_name
,
434 "Netbios domain name doesn't match");
436 torture_assert_str_equal(torture
,
437 rep
.data
.domain_info
.alt_name
,
439 "DNS domain name doesn't match");
441 sid
= dom_sid_parse_talloc(torture
, rep
.data
.domain_info
.sid
);
442 torture_assert(torture
, sid
, "Failed to parse SID");
444 ok
= dom_sid_equal(listd
[i
].sid
, sid
);
445 torture_assert(torture
, ok
, "SID's doesn't match");
447 if (rep
.data
.domain_info
.primary
) {
448 flagstr
= talloc_strdup_append(flagstr
, "PR ");
451 if (rep
.data
.domain_info
.active_directory
) {
452 torture_assert(torture
,
453 strlen(rep
.data
.domain_info
.alt_name
)>0,
454 "Active Directory without DNS name");
455 flagstr
= talloc_strdup_append(flagstr
, "AD ");
458 if (rep
.data
.domain_info
.native_mode
) {
459 torture_assert(torture
,
460 rep
.data
.domain_info
.active_directory
,
461 "Native-Mode, but no Active Directory");
462 flagstr
= talloc_strdup_append(flagstr
, "NA ");
465 torture_comment(torture
, "DOMAIN '%s' => '%s' [%s]\n",
466 rep
.data
.domain_info
.name
,
467 rep
.data
.domain_info
.alt_name
,
474 static bool torture_winbind_struct_getdcname(struct torture_context
*torture
)
477 bool strict
= torture_setting_bool(torture
, "strict mode", false);
478 const char *domain_name
= torture_setting_string(torture
,
479 "winbindd_netbios_domain",
480 lpcfg_workgroup(torture
->lp_ctx
));
481 struct torture_trust_domain
*listd
= NULL
;
482 uint32_t i
, count
= 0;
484 torture_comment(torture
, "Running WINBINDD_GETDCNAME (struct based)\n");
486 ok
= get_trusted_domains(torture
, &listd
);
487 torture_assert(torture
, ok
, "failed to get trust list");
489 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
490 struct winbindd_request req
;
491 struct winbindd_response rep
;
493 /* getdcname is not expected to work on "BUILTIN" or our own
495 if (strequal(listd
[i
].netbios_name
, "BUILTIN") ||
496 strequal(listd
[i
].netbios_name
, domain_name
)) {
503 fstrcpy(req
.domain_name
, listd
[i
].netbios_name
);
506 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME
, &req
, &rep
,
508 (i
<2 || strict
), ok
= false,
509 talloc_asprintf(torture
, "DOMAIN '%s'",
513 /* TODO: check rep.data.dc_name; */
514 torture_comment(torture
, "DOMAIN '%s' => DCNAME '%s'\n",
515 req
.domain_name
, rep
.data
.dc_name
);
520 torture_assert(torture
, count
> 0,
521 "WiNBINDD_GETDCNAME was not tested");
526 static bool torture_winbind_struct_dsgetdcname(struct torture_context
*torture
)
529 bool strict
= torture_setting_bool(torture
, "strict mode", false);
530 struct torture_trust_domain
*listd
= NULL
;
534 torture_comment(torture
, "Running WINBINDD_DSGETDCNAME (struct based)\n");
536 ok
= get_trusted_domains(torture
, &listd
);
537 torture_assert(torture
, ok
, "failed to get trust list");
539 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
540 struct winbindd_request req
;
541 struct winbindd_response rep
;
546 if (strlen(listd
[i
].dns_name
) == 0) continue;
549 * TODO: remove this and let winbindd give no dns name
552 if (strcmp(listd
[i
].dns_name
, listd
[i
].netbios_name
) == 0) {
556 fstrcpy(req
.domain_name
, listd
[i
].dns_name
);
558 /* TODO: test more flag combinations */
559 req
.flags
= DS_DIRECTORY_SERVICE_REQUIRED
;
562 DO_STRUCT_REQ_REP_EXT(WINBINDD_DSGETDCNAME
, &req
, &rep
,
565 talloc_asprintf(torture
, "DOMAIN '%s'",
569 /* TODO: check rep.data.dc_name; */
570 torture_comment(torture
, "DOMAIN '%s' => DCNAME '%s'\n",
571 req
.domain_name
, rep
.data
.dc_name
);
577 torture_warning(torture
, "WINBINDD_DSGETDCNAME"
578 " was not tested with %d non-AD domains",
583 torture_assert(torture
, count
> 0,
584 "WiNBINDD_DSGETDCNAME was not tested");
590 static bool get_user_list(struct torture_context
*torture
, char ***users
)
592 struct winbindd_request req
;
593 struct winbindd_response rep
;
597 const char *extra_data
;
602 DO_STRUCT_REQ_REP(WINBINDD_LIST_USERS
, &req
, &rep
);
604 extra_data
= (char *)rep
.extra_data
.data
;
605 torture_assert(torture
, extra_data
, "NULL extra data");
608 next_token(&extra_data
, name
, ",", sizeof(name
));
611 u
= talloc_realloc(torture
, u
, char *, count
+ 2);
613 u
[count
] = talloc_strdup(u
, name
);
616 SAFE_FREE(rep
.extra_data
.data
);
622 static bool torture_winbind_struct_list_users(struct torture_context
*torture
)
628 torture_comment(torture
, "Running WINBINDD_LIST_USERS (struct based)\n");
630 ok
= get_user_list(torture
, &users
);
631 torture_assert(torture
, ok
, "failed to get user list");
633 for (count
= 0; users
[count
]; count
++) { }
635 torture_comment(torture
, "got %d users\n", count
);
640 static bool get_group_list(struct torture_context
*torture
,
641 unsigned int *num_entries
,
644 struct winbindd_request req
;
645 struct winbindd_response rep
;
649 const char *extra_data
;
654 DO_STRUCT_REQ_REP(WINBINDD_LIST_GROUPS
, &req
, &rep
);
655 extra_data
= (char *)rep
.extra_data
.data
;
657 *num_entries
= rep
.data
.num_entries
;
659 if (*num_entries
== 0) {
660 torture_assert(torture
, extra_data
== NULL
,
661 "extra data is null for >0 reported entries\n");
666 torture_assert(torture
, extra_data
, "NULL extra data");
669 next_token(&extra_data
, name
, ",", sizeof(name
));
672 g
= talloc_realloc(torture
, g
, char *, count
+ 2);
674 g
[count
] = talloc_strdup(g
, name
);
677 SAFE_FREE(rep
.extra_data
.data
);
679 torture_assert_int_equal(torture
, *num_entries
, count
,
680 "Wrong number of group entries reported.");
686 static bool torture_winbind_struct_list_groups(struct torture_context
*torture
)
692 torture_comment(torture
, "Running WINBINDD_LIST_GROUPS (struct based)\n");
694 ok
= get_group_list(torture
, &count
, &groups
);
695 torture_assert(torture
, ok
, "failed to get group list");
697 torture_comment(torture
, "got %d groups\n", count
);
702 struct torture_domain_sequence
{
703 const char *netbios_name
;
707 static bool get_sequence_numbers(struct torture_context
*torture
,
708 struct torture_domain_sequence
**seqs
)
710 struct winbindd_request req
;
711 struct winbindd_response rep
;
712 const char *extra_data
;
715 struct torture_domain_sequence
*s
= NULL
;
720 DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE
, &req
, &rep
);
722 extra_data
= (char *)rep
.extra_data
.data
;
723 torture_assert(torture
, extra_data
, "NULL sequence list");
725 while (next_token(&extra_data
, line
, "\n", sizeof(line
))) {
729 s
= talloc_realloc(torture
, s
, struct torture_domain_sequence
,
731 ZERO_STRUCT(s
[count
+1]);
735 torture_assert(torture
, p
, "invalid line format");
737 s
[count
].netbios_name
= talloc_strdup(s
, lp
);
740 torture_assert(torture
, strncmp(lp
, ": ", 2) == 0,
741 "invalid line format");
743 if (strcmp(lp
, "DISCONNECTED") == 0) {
746 seq
= (uint32_t)strtol(lp
, &p
, 10);
747 torture_assert(torture
, (*p
== '\0'),
748 "invalid line format");
749 torture_assert(torture
, (seq
!= (uint32_t)-1),
750 "sequence number -1 encountered");
756 SAFE_FREE(rep
.extra_data
.data
);
758 torture_assert(torture
, count
>= 2, "The list of domain sequence "
759 "numbers should contain 2 entries");
765 static bool torture_winbind_struct_show_sequence(struct torture_context
*torture
)
769 struct torture_trust_domain
*domlist
= NULL
;
770 struct torture_domain_sequence
*s
= NULL
;
772 torture_comment(torture
, "Running WINBINDD_SHOW_SEQUENCE (struct based)\n");
774 ok
= get_sequence_numbers(torture
, &s
);
775 torture_assert(torture
, ok
, "failed to get list of sequence numbers");
777 ok
= get_trusted_domains(torture
, &domlist
);
778 torture_assert(torture
, ok
, "failed to get trust list");
780 for (i
=0; domlist
[i
].netbios_name
; i
++) {
781 struct winbindd_request req
;
782 struct winbindd_response rep
;
785 torture_assert(torture
, s
[i
].netbios_name
,
786 "more domains received in second run");
787 torture_assert_str_equal(torture
, domlist
[i
].netbios_name
,
789 "inconsistent order of domain lists");
793 fstrcpy(req
.domain_name
, domlist
[i
].netbios_name
);
795 DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE
, &req
, &rep
);
797 seq
= rep
.data
.sequence_number
;
800 torture_assert(torture
, (seq
!= (uint32_t)-1),
801 "BUILTIN domain disconnected");
803 torture_assert(torture
, (seq
!= (uint32_t)-1),
804 "local domain disconnected");
808 if (seq
== (uint32_t)-1) {
809 torture_comment(torture
, " * %s : DISCONNECTED\n",
812 torture_comment(torture
, " * %s : %d\n",
813 req
.domain_name
, seq
);
815 torture_assert(torture
, (seq
>= s
[i
].seq
),
816 "illegal sequence number encountered");
822 static bool torture_winbind_struct_setpwent(struct torture_context
*torture
)
824 struct winbindd_request req
;
825 struct winbindd_response rep
;
827 torture_comment(torture
, "Running WINBINDD_SETPWENT (struct based)\n");
832 DO_STRUCT_REQ_REP(WINBINDD_SETPWENT
, &req
, &rep
);
837 static bool torture_winbind_struct_getpwent(struct torture_context
*torture
)
839 struct winbindd_request req
;
840 struct winbindd_response rep
;
841 struct winbindd_pw
*pwent
;
843 torture_comment(torture
, "Running WINBINDD_GETPWENT (struct based)\n");
845 torture_comment(torture
, " - Running WINBINDD_SETPWENT first\n");
848 DO_STRUCT_REQ_REP(WINBINDD_SETPWENT
, &req
, &rep
);
850 torture_comment(torture
, " - Running WINBINDD_GETPWENT now\n");
853 req
.data
.num_entries
= 1;
854 if (torture_setting_bool(torture
, "samba3", false)) {
856 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETPWENT
, &req
, &rep
,
857 NSS_STATUS_SUCCESS
, false, __noop
=true,
860 DO_STRUCT_REQ_REP(WINBINDD_GETPWENT
, &req
, &rep
);
862 pwent
= (struct winbindd_pw
*)rep
.extra_data
.data
;
863 if (!torture_setting_bool(torture
, "samba3", false)) {
864 torture_assert(torture
, (pwent
!= NULL
), "NULL pwent");
867 torture_comment(torture
, "name: %s, uid: %d, gid: %d, shell: %s\n",
868 pwent
->pw_name
, pwent
->pw_uid
, pwent
->pw_gid
,
875 static bool torture_winbind_struct_endpwent(struct torture_context
*torture
)
877 struct winbindd_request req
;
878 struct winbindd_response rep
;
880 torture_comment(torture
, "Running WINBINDD_ENDPWENT (struct based)\n");
885 DO_STRUCT_REQ_REP(WINBINDD_ENDPWENT
, &req
, &rep
);
890 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
891 form DOMAIN/user into a domain and a user */
893 static bool parse_domain_user(struct torture_context
*torture
,
894 const char *domuser
, fstring domain
,
897 char *p
= strchr(domuser
, winbind_separator(torture
));
901 /* Maybe it was a UPN? */
902 if ((p
= strchr(domuser
, '@')) != NULL
) {
904 fstrcpy(user
, domuser
);
908 fstrcpy(user
, domuser
);
909 get_winbind_domain(torture
, &dom
);
910 fstrcpy(domain
, dom
);
915 fstrcpy(domain
, domuser
);
916 domain
[PTR_DIFF(p
, domuser
)] = 0;
921 static bool lookup_name_sid_list(struct torture_context
*torture
, char **list
)
925 for (count
= 0; list
[count
]; count
++) {
926 struct winbindd_request req
;
927 struct winbindd_response rep
;
930 const char *domain_name
= torture_setting_string(torture
,
931 "winbindd_netbios_domain",
932 lpcfg_workgroup(torture
->lp_ctx
));
937 parse_domain_user(torture
, list
[count
], req
.data
.name
.dom_name
,
940 DO_STRUCT_REQ_REP(WINBINDD_LOOKUPNAME
, &req
, &rep
);
942 sid
= talloc_strdup(torture
, rep
.data
.sid
.sid
);
947 fstrcpy(req
.data
.sid
, sid
);
949 DO_STRUCT_REQ_REP(WINBINDD_LOOKUPSID
, &req
, &rep
);
951 if (strequal(rep
.data
.name
.dom_name
, domain_name
)) {
952 name
= talloc_asprintf(torture
, "%s",
955 name
= talloc_asprintf(torture
, "%s%c%s",
956 rep
.data
.name
.dom_name
,
957 winbind_separator(torture
),
961 torture_assert_casestr_equal(torture
, list
[count
], name
,
962 "LOOKUP_SID after LOOKUP_NAME != id");
965 torture_comment(torture
, " %s -> %s -> %s\n", list
[count
],
976 static bool name_is_in_list(const char *name
, const char **list
)
980 for (count
= 0; list
&& list
[count
]; count
++) {
981 if (strequal(name
, list
[count
])) {
988 static bool torture_winbind_struct_lookup_name_sid(struct torture_context
*torture
)
990 struct winbindd_request req
;
991 struct winbindd_response rep
;
992 const char *invalid_sid
= "S-0-0-7";
994 const char *invalid_user
= "noone";
996 bool strict
= torture_setting_bool(torture
, "strict mode", false);
999 uint32_t count
, num_groups
;
1002 torture_comment(torture
, "Running WINBINDD_LOOKUP_NAME_SID (struct based)\n");
1004 ok
= get_user_list(torture
, &users
);
1005 torture_assert(torture
, ok
, "failed to retrieve list of users");
1006 lookup_name_sid_list(torture
, users
);
1008 ok
= get_group_list(torture
, &num_groups
, &groups
);
1009 torture_assert(torture
, ok
, "failed to retrieve list of groups");
1010 if (num_groups
> 0) {
1011 lookup_name_sid_list(torture
, groups
);
1017 fstrcpy(req
.data
.sid
, invalid_sid
);
1020 DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPSID
, &req
, &rep
,
1021 NSS_STATUS_NOTFOUND
,
1024 talloc_asprintf(torture
,
1025 "invalid sid %s was resolved",
1031 /* try to find an invalid name... */
1034 get_winbind_domain(torture
, &domain
);
1037 invalid_name
= talloc_asprintf(torture
, "%s\\%s%u",
1039 invalid_user
, count
);
1040 } while(name_is_in_list(invalid_name
, (const char **)users
) ||
1041 name_is_in_list(invalid_name
, (const char **)groups
));
1043 fstrcpy(req
.data
.name
.dom_name
, domain
);
1044 fstrcpy(req
.data
.name
.name
,
1045 talloc_asprintf(torture
, "%s%u", invalid_user
,
1049 DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPNAME
, &req
, &rep
,
1050 NSS_STATUS_NOTFOUND
,
1053 talloc_asprintf(torture
,
1054 "invalid name %s was resolved",
1058 talloc_free(groups
);
1063 struct torture_suite
*torture_winbind_struct_init(void)
1065 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "struct");
1067 torture_suite_add_simple_test(suite
, "interface_version", torture_winbind_struct_interface_version
);
1068 torture_suite_add_simple_test(suite
, "ping", torture_winbind_struct_ping
);
1069 torture_suite_add_simple_test(suite
, "info", torture_winbind_struct_info
);
1070 torture_suite_add_simple_test(suite
, "priv_pipe_dir", torture_winbind_struct_priv_pipe_dir
);
1071 torture_suite_add_simple_test(suite
, "netbios_name", torture_winbind_struct_netbios_name
);
1072 torture_suite_add_simple_test(suite
, "domain_name", torture_winbind_struct_domain_name
);
1073 torture_suite_add_simple_test(suite
, "check_machacc", torture_winbind_struct_check_machacc
);
1074 torture_suite_add_simple_test(suite
, "list_trustdom", torture_winbind_struct_list_trustdom
);
1075 torture_suite_add_simple_test(suite
, "domain_info", torture_winbind_struct_domain_info
);
1076 torture_suite_add_simple_test(suite
, "getdcname", torture_winbind_struct_getdcname
);
1077 torture_suite_add_simple_test(suite
, "dsgetdcname", torture_winbind_struct_dsgetdcname
);
1078 torture_suite_add_simple_test(suite
, "list_users", torture_winbind_struct_list_users
);
1079 torture_suite_add_simple_test(suite
, "list_groups", torture_winbind_struct_list_groups
);
1080 torture_suite_add_simple_test(suite
, "show_sequence", torture_winbind_struct_show_sequence
);
1081 torture_suite_add_simple_test(suite
, "setpwent", torture_winbind_struct_setpwent
);
1082 torture_suite_add_simple_test(suite
, "getpwent", torture_winbind_struct_getpwent
);
1083 torture_suite_add_simple_test(suite
, "endpwent", torture_winbind_struct_endpwent
);
1084 torture_suite_add_simple_test(suite
, "lookup_name_sid", torture_winbind_struct_lookup_name_sid
);
1086 suite
->description
= talloc_strdup(suite
, "WINBIND - struct based protocol tests");