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(NULL, 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) : ""); \
56 #define _STRUCT_NOOP do {} while(0);
57 #define DO_STRUCT_REQ_REP(op,req,rep) do { \
58 DO_STRUCT_REQ_REP_EXT(op,req,rep,NSS_STATUS_SUCCESS,true, _STRUCT_NOOP, NULL); \
61 static bool torture_winbind_struct_interface_version(struct torture_context
*torture
)
63 struct winbindd_request req
;
64 struct winbindd_response rep
;
69 torture_comment(torture
, "Running WINBINDD_INTERFACE_VERSION (struct based)\n");
71 DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION
, &req
, &rep
);
73 torture_assert_int_equal(torture
,
74 rep
.data
.interface_version
,
75 WINBIND_INTERFACE_VERSION
,
76 "winbind server and client doesn't match");
81 static bool torture_winbind_struct_ping(struct torture_context
*torture
)
83 struct timeval tv
= timeval_current();
84 int timelimit
= torture_setting_int(torture
, "timelimit", 5);
87 torture_comment(torture
,
88 "Running WINBINDD_PING (struct based) for %d seconds\n",
91 while (timeval_elapsed(&tv
) < timelimit
) {
92 DO_STRUCT_REQ_REP(WINBINDD_PING
, NULL
, NULL
);
96 torture_comment(torture
,
97 "%u (%.1f/s) WINBINDD_PING (struct based)\n",
98 total
, total
/ timeval_elapsed(&tv
));
104 static char winbind_separator(struct torture_context
*torture
)
106 struct winbindd_response rep
;
110 DO_STRUCT_REQ_REP(WINBINDD_INFO
, NULL
, &rep
);
112 return rep
.data
.info
.winbind_separator
;
115 static bool torture_winbind_struct_info(struct torture_context
*torture
)
117 struct winbindd_response rep
;
118 const char *separator
;
122 torture_comment(torture
, "Running WINBINDD_INFO (struct based)\n");
124 DO_STRUCT_REQ_REP(WINBINDD_INFO
, NULL
, &rep
);
126 separator
= torture_setting_string(torture
,
127 "winbindd_separator",
128 lpcfg_winbind_separator(torture
->lp_ctx
));
130 torture_assert_int_equal(torture
,
131 rep
.data
.info
.winbind_separator
,
133 "winbind separator doesn't match");
135 torture_comment(torture
, "Samba Version '%s'\n",
136 rep
.data
.info
.samba_version
);
141 static bool torture_winbind_struct_priv_pipe_dir(struct torture_context
*torture
)
143 struct winbindd_response rep
;
148 torture_comment(torture
, "Running WINBINDD_PRIV_PIPE_DIR (struct based)\n");
150 DO_STRUCT_REQ_REP(WINBINDD_PRIV_PIPE_DIR
, NULL
, &rep
);
152 got_dir
= (const char *)rep
.extra_data
.data
;
154 torture_assert(torture
, got_dir
, "NULL WINBINDD_PRIV_PIPE_DIR\n");
156 SAFE_FREE(rep
.extra_data
.data
);
160 static bool torture_winbind_struct_netbios_name(struct torture_context
*torture
)
162 struct winbindd_response rep
;
163 const char *expected
;
167 torture_comment(torture
, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
169 DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME
, NULL
, &rep
);
171 expected
= torture_setting_string(torture
,
172 "winbindd_netbios_name",
173 lpcfg_netbios_name(torture
->lp_ctx
));
174 expected
= strupper_talloc(torture
, expected
);
176 torture_assert_str_equal(torture
,
177 rep
.data
.netbios_name
, expected
,
178 "winbindd's netbios name doesn't match");
183 static bool get_winbind_domain(struct torture_context
*torture
, char **domain
)
185 struct winbindd_response rep
;
189 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME
, NULL
, &rep
);
191 *domain
= talloc_strdup(torture
, rep
.data
.domain_name
);
192 torture_assert(torture
, domain
, "talloc error");
197 static bool torture_winbind_struct_domain_name(struct torture_context
*torture
)
199 const char *expected
;
202 torture_comment(torture
, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
204 expected
= torture_setting_string(torture
,
205 "winbindd_netbios_domain",
206 lpcfg_workgroup(torture
->lp_ctx
));
208 get_winbind_domain(torture
, &domain
);
210 torture_assert_str_equal(torture
, domain
, expected
,
211 "winbindd's netbios domain doesn't match");
216 static bool torture_winbind_struct_check_machacc(struct torture_context
*torture
)
219 bool strict
= torture_setting_bool(torture
, "strict mode", false);
220 struct winbindd_response rep
;
224 torture_comment(torture
, "Running WINBINDD_CHECK_MACHACC (struct based)\n");
227 DO_STRUCT_REQ_REP_EXT(WINBINDD_CHECK_MACHACC
, NULL
, &rep
,
228 NSS_STATUS_SUCCESS
, strict
, ok
= false,
229 "WINBINDD_CHECK_MACHACC");
232 torture_assert(torture
,
233 strlen(rep
.data
.auth
.nt_status_string
)>0,
234 "Failed with empty nt_status_string");
236 torture_warning(torture
,"%s:%s:%s:%d\n",
237 nt_errstr(NT_STATUS(rep
.data
.auth
.nt_status
)),
238 rep
.data
.auth
.nt_status_string
,
239 rep
.data
.auth
.error_string
,
240 rep
.data
.auth
.pam_error
);
244 torture_assert_ntstatus_ok(torture
,
245 NT_STATUS(rep
.data
.auth
.nt_status
),
246 "WINBINDD_CHECK_MACHACC ok: nt_status");
248 torture_assert_str_equal(torture
,
249 rep
.data
.auth
.nt_status_string
,
250 nt_errstr(NT_STATUS_OK
),
251 "WINBINDD_CHECK_MACHACC ok:nt_status_string");
253 torture_assert_str_equal(torture
,
254 rep
.data
.auth
.error_string
,
255 get_friendly_nt_error_msg(NT_STATUS_OK
),
256 "WINBINDD_CHECK_MACHACC ok: error_string");
258 torture_assert_int_equal(torture
,
259 rep
.data
.auth
.pam_error
,
260 nt_status_to_pam(NT_STATUS_OK
),
261 "WINBINDD_CHECK_MACHACC ok: pam_error");
266 struct torture_trust_domain
{
267 const char *netbios_name
;
268 const char *dns_name
;
272 static bool get_trusted_domains(struct torture_context
*torture
,
273 struct torture_trust_domain
**_d
)
275 struct winbindd_request req
;
276 struct winbindd_response rep
;
277 struct torture_trust_domain
*d
= NULL
;
280 const char *extra_data
;
285 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
287 extra_data
= (char *)rep
.extra_data
.data
;
292 torture_assert(torture
, extra_data
, "NULL trust list");
294 while (next_token(&extra_data
, line
, "\n", sizeof(line
))) {
297 d
= talloc_realloc(torture
, d
,
298 struct torture_trust_domain
,
300 ZERO_STRUCT(d
[dcount
+1]);
303 p
= strchr(lp
, '\\');
304 torture_assert(torture
, p
, "missing 1st '\\' in line");
306 d
[dcount
].netbios_name
= talloc_strdup(d
, lp
);
307 torture_assert(torture
, strlen(d
[dcount
].netbios_name
) > 0,
308 "empty netbios_name");
311 p
= strchr(lp
, '\\');
312 torture_assert(torture
, p
, "missing 2nd '\\' in line");
314 d
[dcount
].dns_name
= talloc_strdup(d
, lp
);
315 /* it's ok to have an empty dns_name */
318 d
[dcount
].sid
= dom_sid_parse_talloc(d
, lp
);
319 torture_assert(torture
, d
[dcount
].sid
,
320 "failed to parse sid");
324 SAFE_FREE(rep
.extra_data
.data
);
326 torture_assert(torture
, dcount
>= 2,
327 "The list of trusted domain should contain 2 entries");
333 static bool torture_winbind_struct_list_trustdom(struct torture_context
*torture
)
335 struct winbindd_request req
;
336 struct winbindd_response rep
;
340 struct torture_trust_domain
*listd
= NULL
;
343 torture_comment(torture
, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n");
348 req
.data
.list_all_domains
= false;
350 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
352 list1
= (char *)rep
.extra_data
.data
;
354 torture_comment(torture
, "%s\n", list1
);
359 req
.data
.list_all_domains
= true;
361 DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM
, &req
, &rep
);
363 list2
= (char *)rep
.extra_data
.data
;
366 * The list_all_domains parameter should be ignored
368 torture_assert_str_equal(torture
, list2
, list1
, "list_all_domains not ignored");
373 ok
= get_trusted_domains(torture
, &listd
);
374 torture_assert(torture
, ok
, "failed to get trust list");
376 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
378 struct dom_sid
*builtin_sid
;
380 builtin_sid
= dom_sid_parse_talloc(torture
, SID_BUILTIN
);
382 torture_assert_str_equal(torture
,
383 listd
[i
].netbios_name
,
385 "first domain should be 'BUILTIN'");
387 torture_assert_str_equal(torture
,
390 "BUILTIN domain should not have a dns name");
392 ok
= dom_sid_equal(builtin_sid
,
394 torture_assert(torture
, ok
, "BUILTIN domain should have S-1-5-32");
400 * TODO: verify the content of the 2nd and 3rd (in member server mode)
408 static bool torture_winbind_struct_domain_info(struct torture_context
*torture
)
411 struct torture_trust_domain
*listd
= NULL
;
414 torture_comment(torture
, "Running WINBINDD_DOMAIN_INFO (struct based)\n");
416 ok
= get_trusted_domains(torture
, &listd
);
417 torture_assert(torture
, ok
, "failed to get trust list");
419 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
420 struct winbindd_request req
;
421 struct winbindd_response rep
;
423 char *flagstr
= talloc_strdup(torture
," ");
428 fstrcpy(req
.domain_name
, listd
[i
].netbios_name
);
430 DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO
, &req
, &rep
);
432 if (rep
.data
.domain_info
.primary
) {
433 flagstr
= talloc_strdup_append(flagstr
, "PR ");
436 if (rep
.data
.domain_info
.active_directory
) {
437 torture_assert(torture
,
438 strlen(rep
.data
.domain_info
.alt_name
)>0,
439 "Active Directory without DNS name");
440 flagstr
= talloc_strdup_append(flagstr
, "AD ");
443 if (rep
.data
.domain_info
.native_mode
) {
444 torture_assert(torture
,
445 rep
.data
.domain_info
.active_directory
,
446 "Native-Mode, but no Active Directory");
447 flagstr
= talloc_strdup_append(flagstr
, "NA ");
450 torture_comment(torture
, "DOMAIN '%s' => '%s' [%s] [%s]\n",
451 rep
.data
.domain_info
.name
,
452 rep
.data
.domain_info
.alt_name
,
454 rep
.data
.domain_info
.sid
);
456 sid
= dom_sid_parse_talloc(torture
, rep
.data
.domain_info
.sid
);
457 torture_assert(torture
, sid
, "Failed to parse SID");
459 ok
= dom_sid_equal(listd
[i
].sid
, sid
);
460 torture_assert(torture
, ok
, "SID's doesn't match");
462 torture_assert_str_equal(torture
,
463 rep
.data
.domain_info
.name
,
464 listd
[i
].netbios_name
,
465 "Netbios domain name doesn't match");
467 torture_assert_str_equal(torture
,
468 rep
.data
.domain_info
.alt_name
,
470 "DNS domain name doesn't match");
476 static bool torture_winbind_struct_getdcname(struct torture_context
*torture
)
479 bool strict
= torture_setting_bool(torture
, "strict mode", false);
480 const char *domain_name
= torture_setting_string(torture
,
481 "winbindd_netbios_domain",
482 lpcfg_workgroup(torture
->lp_ctx
));
483 struct torture_trust_domain
*listd
= NULL
;
484 uint32_t i
, count
= 0;
486 torture_comment(torture
, "Running WINBINDD_GETDCNAME (struct based)\n");
488 ok
= get_trusted_domains(torture
, &listd
);
489 torture_assert(torture
, ok
, "failed to get trust list");
491 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
492 struct winbindd_request req
;
493 struct winbindd_response rep
;
495 /* getdcname is not expected to work on "BUILTIN" or our own
497 if (strequal(listd
[i
].netbios_name
, "BUILTIN") ||
498 strequal(listd
[i
].netbios_name
, domain_name
)) {
505 fstrcpy(req
.domain_name
, listd
[i
].netbios_name
);
508 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME
, &req
, &rep
,
510 (i
<2 || strict
), ok
= false,
511 talloc_asprintf(torture
, "DOMAIN '%s'",
515 /* TODO: check rep.data.dc_name; */
516 torture_comment(torture
, "DOMAIN '%s' => DCNAME '%s'\n",
517 req
.domain_name
, rep
.data
.dc_name
);
522 torture_assert(torture
, count
> 0,
523 "WiNBINDD_GETDCNAME was not tested");
528 static bool torture_winbind_struct_dsgetdcname(struct torture_context
*torture
)
531 bool strict
= torture_setting_bool(torture
, "strict mode", false);
532 struct torture_trust_domain
*listd
= NULL
;
536 torture_comment(torture
, "Running WINBINDD_DSGETDCNAME (struct based)\n");
538 ok
= get_trusted_domains(torture
, &listd
);
539 torture_assert(torture
, ok
, "failed to get trust list");
541 for (i
=0; listd
&& listd
[i
].netbios_name
; i
++) {
542 struct winbindd_request req
;
543 struct winbindd_response rep
;
548 if (strlen(listd
[i
].dns_name
) == 0) continue;
551 * TODO: remove this and let winbindd give no dns name
554 if (strcmp(listd
[i
].dns_name
, listd
[i
].netbios_name
) == 0) {
558 fstrcpy(req
.domain_name
, listd
[i
].dns_name
);
560 /* TODO: test more flag combinations */
561 req
.flags
= DS_DIRECTORY_SERVICE_REQUIRED
;
564 DO_STRUCT_REQ_REP_EXT(WINBINDD_DSGETDCNAME
, &req
, &rep
,
567 talloc_asprintf(torture
, "DOMAIN '%s'",
571 /* TODO: check rep.data.dc_name; */
572 torture_comment(torture
, "DOMAIN '%s' => DCNAME '%s'\n",
573 req
.domain_name
, rep
.data
.dc_name
);
579 torture_warning(torture
, "WINBINDD_DSGETDCNAME"
580 " was not tested with %d non-AD domains",
585 torture_assert(torture
, count
> 0,
586 "WiNBINDD_DSGETDCNAME was not tested");
592 static bool get_user_list(struct torture_context
*torture
, char ***users
)
594 struct winbindd_request req
;
595 struct winbindd_response rep
;
599 const char *extra_data
;
604 DO_STRUCT_REQ_REP(WINBINDD_LIST_USERS
, &req
, &rep
);
606 extra_data
= (char *)rep
.extra_data
.data
;
607 torture_assert(torture
, extra_data
, "NULL extra data");
610 next_token(&extra_data
, name
, ",", sizeof(name
));
613 u
= talloc_realloc(torture
, u
, char *, count
+ 2);
615 u
[count
] = talloc_strdup(u
, name
);
618 SAFE_FREE(rep
.extra_data
.data
);
624 static bool torture_winbind_struct_list_users(struct torture_context
*torture
)
630 torture_comment(torture
, "Running WINBINDD_LIST_USERS (struct based)\n");
632 ok
= get_user_list(torture
, &users
);
633 torture_assert(torture
, ok
, "failed to get user list");
635 for (count
= 0; users
[count
]; count
++) { }
637 torture_comment(torture
, "got %d users\n", count
);
642 static bool get_group_list(struct torture_context
*torture
,
643 unsigned int *num_entries
,
646 struct winbindd_request req
;
647 struct winbindd_response rep
;
651 const char *extra_data
;
656 DO_STRUCT_REQ_REP(WINBINDD_LIST_GROUPS
, &req
, &rep
);
657 extra_data
= (char *)rep
.extra_data
.data
;
659 *num_entries
= rep
.data
.num_entries
;
661 if (*num_entries
== 0) {
662 torture_assert(torture
, extra_data
== NULL
,
663 "extra data is null for >0 reported entries\n");
668 torture_assert(torture
, extra_data
, "NULL extra data");
671 next_token(&extra_data
, name
, ",", sizeof(name
));
674 g
= talloc_realloc(torture
, g
, char *, count
+ 2);
676 g
[count
] = talloc_strdup(g
, name
);
679 SAFE_FREE(rep
.extra_data
.data
);
681 torture_assert_int_equal(torture
, *num_entries
, count
,
682 "Wrong number of group entries reported.");
688 static bool torture_winbind_struct_list_groups(struct torture_context
*torture
)
694 torture_comment(torture
, "Running WINBINDD_LIST_GROUPS (struct based)\n");
696 ok
= get_group_list(torture
, &count
, &groups
);
697 torture_assert(torture
, ok
, "failed to get group list");
699 torture_comment(torture
, "got %d groups\n", count
);
704 struct torture_domain_sequence
{
705 const char *netbios_name
;
709 static bool get_sequence_numbers(struct torture_context
*torture
,
710 struct torture_domain_sequence
**seqs
)
712 struct winbindd_request req
;
713 struct winbindd_response rep
;
714 const char *extra_data
;
717 struct torture_domain_sequence
*s
= NULL
;
722 DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE
, &req
, &rep
);
724 extra_data
= (char *)rep
.extra_data
.data
;
725 torture_assert(torture
, extra_data
, "NULL sequence list");
727 while (next_token(&extra_data
, line
, "\n", sizeof(line
))) {
731 s
= talloc_realloc(torture
, s
, struct torture_domain_sequence
,
733 ZERO_STRUCT(s
[count
+1]);
737 torture_assert(torture
, p
, "invalid line format");
739 s
[count
].netbios_name
= talloc_strdup(s
, lp
);
742 torture_assert(torture
, strncmp(lp
, ": ", 2) == 0,
743 "invalid line format");
745 if (strcmp(lp
, "DISCONNECTED") == 0) {
748 seq
= (uint32_t)strtol(lp
, &p
, 10);
749 torture_assert(torture
, (*p
== '\0'),
750 "invalid line format");
751 torture_assert(torture
, (seq
!= (uint32_t)-1),
752 "sequence number -1 encountered");
758 SAFE_FREE(rep
.extra_data
.data
);
760 torture_assert(torture
, count
>= 2, "The list of domain sequence "
761 "numbers should contain 2 entries");
767 static bool torture_winbind_struct_show_sequence(struct torture_context
*torture
)
771 struct torture_trust_domain
*domlist
= NULL
;
772 struct torture_domain_sequence
*s
= NULL
;
774 torture_comment(torture
, "Running WINBINDD_SHOW_SEQUENCE (struct based)\n");
776 ok
= get_sequence_numbers(torture
, &s
);
777 torture_assert(torture
, ok
, "failed to get list of sequence numbers");
779 ok
= get_trusted_domains(torture
, &domlist
);
780 torture_assert(torture
, ok
, "failed to get trust list");
782 for (i
=0; domlist
[i
].netbios_name
; i
++) {
783 struct winbindd_request req
;
784 struct winbindd_response rep
;
787 torture_assert(torture
, s
[i
].netbios_name
,
788 "more domains received in second run");
789 torture_assert_str_equal(torture
, domlist
[i
].netbios_name
,
791 "inconsistent order of domain lists");
795 fstrcpy(req
.domain_name
, domlist
[i
].netbios_name
);
797 DO_STRUCT_REQ_REP(WINBINDD_SHOW_SEQUENCE
, &req
, &rep
);
799 seq
= rep
.data
.sequence_number
;
802 torture_assert(torture
, (seq
!= (uint32_t)-1),
803 "BUILTIN domain disconnected");
805 torture_assert(torture
, (seq
!= (uint32_t)-1),
806 "local domain disconnected");
810 if (seq
== (uint32_t)-1) {
811 torture_comment(torture
, " * %s : DISCONNECTED\n",
814 torture_comment(torture
, " * %s : %d\n",
815 req
.domain_name
, seq
);
817 torture_assert(torture
, (seq
>= s
[i
].seq
),
818 "illegal sequence number encountered");
824 static bool torture_winbind_struct_setpwent(struct torture_context
*torture
)
826 struct winbindd_request req
;
827 struct winbindd_response rep
;
829 torture_comment(torture
, "Running WINBINDD_SETPWENT (struct based)\n");
834 DO_STRUCT_REQ_REP(WINBINDD_SETPWENT
, &req
, &rep
);
839 static bool torture_winbind_struct_getpwent(struct torture_context
*torture
)
841 struct winbindd_request req
;
842 struct winbindd_response rep
;
843 struct winbindd_pw
*pwent
;
845 torture_comment(torture
, "Running WINBINDD_GETPWENT (struct based)\n");
847 torture_comment(torture
, " - Running WINBINDD_SETPWENT first\n");
850 DO_STRUCT_REQ_REP(WINBINDD_SETPWENT
, &req
, &rep
);
852 torture_comment(torture
, " - Running WINBINDD_GETPWENT now\n");
855 req
.data
.num_entries
= 1;
856 if (torture_setting_bool(torture
, "samba3", false)) {
857 DO_STRUCT_REQ_REP_EXT(WINBINDD_GETPWENT
, &req
, &rep
,
858 NSS_STATUS_SUCCESS
, false, _STRUCT_NOOP
,
861 DO_STRUCT_REQ_REP(WINBINDD_GETPWENT
, &req
, &rep
);
863 pwent
= (struct winbindd_pw
*)rep
.extra_data
.data
;
864 if (!torture_setting_bool(torture
, "samba3", false)) {
865 torture_assert(torture
, (pwent
!= NULL
), "NULL pwent");
868 torture_comment(torture
, "name: %s, uid: %d, gid: %d, shell: %s\n",
869 pwent
->pw_name
, pwent
->pw_uid
, pwent
->pw_gid
,
876 static bool torture_winbind_struct_endpwent(struct torture_context
*torture
)
878 struct winbindd_request req
;
879 struct winbindd_response rep
;
881 torture_comment(torture
, "Running WINBINDD_ENDPWENT (struct based)\n");
886 DO_STRUCT_REQ_REP(WINBINDD_ENDPWENT
, &req
, &rep
);
891 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
892 form DOMAIN/user into a domain and a user */
894 static bool parse_domain_user(struct torture_context
*torture
,
895 const char *domuser
, fstring domain
,
898 char *p
= strchr(domuser
, winbind_separator(torture
));
902 /* Maybe it was a UPN? */
903 if ((p
= strchr(domuser
, '@')) != NULL
) {
905 fstrcpy(user
, domuser
);
909 fstrcpy(user
, domuser
);
910 get_winbind_domain(torture
, &dom
);
911 fstrcpy(domain
, dom
);
916 fstrcpy(domain
, domuser
);
917 domain
[PTR_DIFF(p
, domuser
)] = 0;
922 static bool lookup_name_sid_list(struct torture_context
*torture
, char **list
)
926 for (count
= 0; list
[count
]; count
++) {
927 struct winbindd_request req
;
928 struct winbindd_response rep
;
931 const char *domain_name
= torture_setting_string(torture
,
932 "winbindd_netbios_domain",
933 lpcfg_workgroup(torture
->lp_ctx
));
938 parse_domain_user(torture
, list
[count
], req
.data
.name
.dom_name
,
941 DO_STRUCT_REQ_REP(WINBINDD_LOOKUPNAME
, &req
, &rep
);
943 sid
= talloc_strdup(torture
, rep
.data
.sid
.sid
);
948 fstrcpy(req
.data
.sid
, sid
);
950 DO_STRUCT_REQ_REP(WINBINDD_LOOKUPSID
, &req
, &rep
);
952 if (strequal(rep
.data
.name
.dom_name
, domain_name
)) {
953 name
= talloc_asprintf(torture
, "%s",
956 name
= talloc_asprintf(torture
, "%s%c%s",
957 rep
.data
.name
.dom_name
,
958 winbind_separator(torture
),
962 torture_assert_casestr_equal(torture
, list
[count
], name
,
963 "LOOKUP_SID after LOOKUP_NAME != id");
966 torture_comment(torture
, " %s -> %s -> %s\n", list
[count
],
977 static bool name_is_in_list(const char *name
, char **list
)
981 for (count
= 0; list
&& list
[count
]; count
++) {
982 if (strequal(name
, list
[count
])) {
989 static bool torture_winbind_struct_lookup_name_sid(struct torture_context
*torture
)
991 struct winbindd_request req
;
992 struct winbindd_response rep
;
993 const char *invalid_sid
= "S-0-0-7";
995 const char *invalid_user
= "noone";
997 bool strict
= torture_setting_bool(torture
, "strict mode", false);
1000 uint32_t count
, num_groups
;
1003 torture_comment(torture
, "Running WINBINDD_LOOKUP_NAME_SID (struct based)\n");
1005 ok
= get_user_list(torture
, &users
);
1006 torture_assert(torture
, ok
, "failed to retrieve list of users");
1007 lookup_name_sid_list(torture
, users
);
1009 ok
= get_group_list(torture
, &num_groups
, &groups
);
1010 torture_assert(torture
, ok
, "failed to retrieve list of groups");
1011 if (num_groups
> 0) {
1012 lookup_name_sid_list(torture
, groups
);
1018 fstrcpy(req
.data
.sid
, invalid_sid
);
1021 DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPSID
, &req
, &rep
,
1022 NSS_STATUS_NOTFOUND
,
1025 talloc_asprintf(torture
,
1026 "invalid sid %s was resolved",
1032 /* try to find an invalid name... */
1035 get_winbind_domain(torture
, &domain
);
1038 invalid_name
= talloc_asprintf(torture
, "%s/%s%u",
1040 invalid_user
, count
);
1041 } while(name_is_in_list(invalid_name
, users
) ||
1042 name_is_in_list(invalid_name
, groups
));
1044 fstrcpy(req
.data
.name
.dom_name
, domain
);
1045 fstrcpy(req
.data
.name
.name
,
1046 talloc_asprintf(torture
, "%s%u", invalid_user
,
1050 DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPNAME
, &req
, &rep
,
1051 NSS_STATUS_NOTFOUND
,
1054 talloc_asprintf(torture
,
1055 "invalid name %s was resolved",
1059 talloc_free(groups
);
1064 struct torture_suite
*torture_winbind_struct_init(void)
1066 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "struct");
1068 torture_suite_add_simple_test(suite
, "interface_version", torture_winbind_struct_interface_version
);
1069 torture_suite_add_simple_test(suite
, "ping", torture_winbind_struct_ping
);
1070 torture_suite_add_simple_test(suite
, "info", torture_winbind_struct_info
);
1071 torture_suite_add_simple_test(suite
, "priv_pipe_dir", torture_winbind_struct_priv_pipe_dir
);
1072 torture_suite_add_simple_test(suite
, "netbios_name", torture_winbind_struct_netbios_name
);
1073 torture_suite_add_simple_test(suite
, "domain_name", torture_winbind_struct_domain_name
);
1074 torture_suite_add_simple_test(suite
, "check_machacc", torture_winbind_struct_check_machacc
);
1075 torture_suite_add_simple_test(suite
, "list_trustdom", torture_winbind_struct_list_trustdom
);
1076 torture_suite_add_simple_test(suite
, "domain_info", torture_winbind_struct_domain_info
);
1077 torture_suite_add_simple_test(suite
, "getdcname", torture_winbind_struct_getdcname
);
1078 torture_suite_add_simple_test(suite
, "dsgetdcname", torture_winbind_struct_dsgetdcname
);
1079 torture_suite_add_simple_test(suite
, "list_users", torture_winbind_struct_list_users
);
1080 torture_suite_add_simple_test(suite
, "list_groups", torture_winbind_struct_list_groups
);
1081 torture_suite_add_simple_test(suite
, "show_sequence", torture_winbind_struct_show_sequence
);
1082 torture_suite_add_simple_test(suite
, "setpwent", torture_winbind_struct_setpwent
);
1083 torture_suite_add_simple_test(suite
, "getpwent", torture_winbind_struct_getpwent
);
1084 torture_suite_add_simple_test(suite
, "endpwent", torture_winbind_struct_endpwent
);
1085 torture_suite_add_simple_test(suite
, "lookup_name_sid", torture_winbind_struct_lookup_name_sid
);
1087 suite
->description
= talloc_strdup(suite
, "WINBIND - struct based protocol tests");