2 Unix SMB/CIFS implementation.
4 Copyright (C) Guenther Deschner 2009-2010
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.
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.
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/>.
20 #include "lib/replace/replace.h"
21 #include "libcli/util/ntstatus.h"
22 #include "libcli/util/werror.h"
23 #include "lib/util/data_blob.h"
24 #include "lib/util/time.h"
25 #include "nsswitch/libwbclient/wbclient.h"
26 #include "torture/smbtorture.h"
27 #include "torture/winbind/proto.h"
28 #include "lib/util/util_net.h"
29 #include "lib/util/charset/charset.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "lib/param/param.h"
32 #include "lib/util/samba_util.h"
33 #include "lib/crypto/arcfour.h"
34 #include "auth/credentials/credentials.h"
35 #include "lib/cmdline/popt_common.h"
37 #define WBC_ERROR_EQUAL(x,y) (x == y)
39 #define torture_assert_wbc_equal(torture_ctx, got, expected, cmt, cmt_arg) \
40 do { wbcErr __got = got, __expected = expected; \
41 if (!WBC_ERROR_EQUAL(__got, __expected)) { \
42 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: " cmt, wbcErrorString(__got), wbcErrorString(__expected), cmt_arg); \
47 #define torture_assert_wbc_ok(torture_ctx,expr,cmt,cmt_arg) \
48 torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt,cmt_arg)
50 static bool test_wbc_ping(struct torture_context
*tctx
)
52 torture_assert_wbc_ok(tctx
, wbcPing(),
53 "%s", "wbcPing failed");
58 static bool test_wbc_pingdc(struct torture_context
*tctx
)
60 struct wbcInterfaceDetails
*details
;
62 torture_assert_wbc_equal(tctx
, wbcPingDc("random_string", NULL
), WBC_ERR_DOMAIN_NOT_FOUND
,
63 "%s", "wbcPingDc failed");
64 torture_assert_wbc_ok(tctx
, wbcPingDc(NULL
, NULL
),
65 "%s", "wbcPingDc failed");
67 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
68 "%s", "wbcInterfaceDetails failed");
69 torture_assert(tctx
, details
,
70 "wbcInterfaceDetails returned NULL pointer");
71 torture_assert(tctx
, details
->netbios_domain
,
72 "wbcInterfaceDetails returned NULL netbios_domain");
74 torture_assert_wbc_ok(tctx
, wbcPingDc(details
->netbios_domain
, NULL
),
75 "wbcPingDc(%s) failed", details
->netbios_domain
);
77 torture_assert_wbc_ok(tctx
, wbcPingDc("BUILTIN", NULL
),
78 "%s", "wbcPingDc(BUILTIN) failed");
80 wbcFreeMemory(details
);
84 static bool test_wbc_pingdc2(struct torture_context
*tctx
)
86 struct wbcInterfaceDetails
*details
;
89 torture_assert_wbc_equal(tctx
, wbcPingDc2("random_string", NULL
, &name
),
90 WBC_ERR_DOMAIN_NOT_FOUND
, "%s",
92 torture_assert_wbc_ok(tctx
, wbcPingDc2(NULL
, NULL
, &name
), "%s",
97 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
98 "%s", "wbcInterfaceDetails failed");
99 torture_assert(tctx
, details
,
100 "wbcInterfaceDetails returned NULL pointer");
101 torture_assert(tctx
, details
->netbios_domain
,
102 "wbcInterfaceDetails returned NULL netbios_domain");
104 torture_assert_wbc_ok(tctx
, wbcPingDc2(details
->netbios_domain
, NULL
, &name
),
105 "wbcPingDc2(%s) failed", details
->netbios_domain
);
108 torture_assert_wbc_ok(tctx
, wbcPingDc2("BUILTIN", NULL
, &name
),
109 "%s", "wbcPingDc2(BUILTIN) failed");
112 wbcFreeMemory(details
);
117 static bool test_wbc_library_details(struct torture_context
*tctx
)
119 struct wbcLibraryDetails
*details
;
121 torture_assert_wbc_ok(tctx
, wbcLibraryDetails(&details
),
122 "%s", "wbcLibraryDetails failed");
123 torture_assert(tctx
, details
,
124 "wbcLibraryDetails returned NULL pointer");
126 wbcFreeMemory(details
);
131 static bool test_wbc_interface_details(struct torture_context
*tctx
)
133 struct wbcInterfaceDetails
*details
;
135 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
136 "%s", "wbcInterfaceDetails failed");
137 torture_assert(tctx
, details
,
138 "wbcInterfaceDetails returned NULL pointer");
140 wbcFreeMemory(details
);
145 static bool test_wbc_sidtypestring(struct torture_context
*tctx
)
147 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_USE_NONE
),
148 "SID_NONE", "SID_NONE failed");
149 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_USER
),
150 "SID_USER", "SID_USER failed");
151 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DOM_GRP
),
152 "SID_DOM_GROUP", "SID_DOM_GROUP failed");
153 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DOMAIN
),
154 "SID_DOMAIN", "SID_DOMAIN failed");
155 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_ALIAS
),
156 "SID_ALIAS", "SID_ALIAS failed");
157 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_WKN_GRP
),
158 "SID_WKN_GROUP", "SID_WKN_GROUP failed");
159 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_DELETED
),
160 "SID_DELETED", "SID_DELETED failed");
161 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_INVALID
),
162 "SID_INVALID", "SID_INVALID failed");
163 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_UNKNOWN
),
164 "SID_UNKNOWN", "SID_UNKNOWN failed");
165 torture_assert_str_equal(tctx
, wbcSidTypeString(WBC_SID_NAME_COMPUTER
),
166 "SID_COMPUTER", "SID_COMPUTER failed");
170 static bool test_wbc_sidtostring(struct torture_context
*tctx
)
172 struct wbcDomainSid sid
;
173 const char *sid_string
= "S-1-5-32";
176 torture_assert_wbc_ok(tctx
, wbcStringToSid(sid_string
, &sid
),
177 "wbcStringToSid of %s failed", sid_string
);
178 torture_assert_wbc_ok(tctx
, wbcSidToString(&sid
, &sid_string2
),
179 "wbcSidToString of %s failed", sid_string
);
180 torture_assert_str_equal(tctx
, sid_string
, sid_string2
,
181 "sid strings differ");
182 wbcFreeMemory(sid_string2
);
187 static bool test_wbc_guidtostring(struct torture_context
*tctx
)
190 const char *guid_string
= "f7cf07b4-1487-45c7-824d-8b18cc580811";
193 torture_assert_wbc_ok(tctx
, wbcStringToGuid(guid_string
, &guid
),
194 "wbcStringToGuid of %s failed", guid_string
);
195 torture_assert_wbc_ok(tctx
, wbcGuidToString(&guid
, &guid_string2
),
196 "wbcGuidToString of %s failed", guid_string
);
197 torture_assert_str_equal(tctx
, guid_string
, guid_string2
,
198 "guid strings differ");
199 wbcFreeMemory(guid_string2
);
204 static bool test_wbc_domain_info(struct torture_context
*tctx
)
206 struct wbcDomainInfo
*info
;
207 struct wbcInterfaceDetails
*details
;
209 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
210 "%s", "wbcInterfaceDetails failed");
211 torture_assert_wbc_ok(
212 tctx
, wbcDomainInfo(details
->netbios_domain
, &info
),
213 "%s", "wbcDomainInfo failed");
214 wbcFreeMemory(details
);
216 torture_assert(tctx
, info
,
217 "wbcDomainInfo returned NULL pointer");
223 static bool test_wbc_users(struct torture_context
*tctx
)
225 const char *domain_name
= NULL
;
229 struct wbcInterfaceDetails
*details
;
231 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
232 "%s", "wbcInterfaceDetails failed");
234 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
235 wbcFreeMemory(details
);
237 torture_assert_wbc_ok(tctx
, wbcListUsers(domain_name
, &num_users
, &users
),
238 "%s", "wbcListUsers failed");
239 torture_assert(tctx
, !(num_users
> 0 && !users
),
240 "wbcListUsers returned invalid results");
242 for (i
=0; i
< MIN(num_users
,100); i
++) {
244 struct wbcDomainSid sid
, *sids
;
245 enum wbcSidType name_type
;
251 torture_assert_wbc_ok(tctx
, wbcLookupName(domain_name
, users
[i
], &sid
, &name_type
),
252 "wbcLookupName of %s failed", users
[i
]);
253 torture_assert_int_equal(tctx
, name_type
, WBC_SID_NAME_USER
,
254 "wbcLookupName expected WBC_SID_NAME_USER");
255 wbcSidToString(&sid
, &sid_string
);
256 torture_assert_wbc_ok(tctx
, wbcLookupSid(&sid
, &domain
, &name
, &name_type
),
257 "wbcLookupSid of %s failed", sid_string
);
258 torture_assert_int_equal(tctx
, name_type
, WBC_SID_NAME_USER
,
259 "wbcLookupSid of expected WBC_SID_NAME_USER");
260 torture_assert(tctx
, name
,
261 "wbcLookupSid returned no name");
262 wbcFreeMemory(domain
);
264 torture_assert_wbc_ok(tctx
, wbcLookupUserSids(&sid
, true, &num_sids
, &sids
),
265 "wbcLookupUserSids of %s failed", sid_string
);
266 torture_assert_wbc_ok(
267 tctx
, wbcGetDisplayName(&sid
, &domain
, &name
,
269 "wbcGetDisplayName of %s failed", sid_string
);
270 wbcFreeMemory(domain
);
273 wbcFreeMemory(sid_string
);
275 wbcFreeMemory(users
);
280 static bool test_wbc_groups(struct torture_context
*tctx
)
282 const char *domain_name
= NULL
;
286 struct wbcInterfaceDetails
*details
;
288 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
289 "%s", "wbcInterfaceDetails failed");
291 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
292 wbcFreeMemory(details
);
294 torture_assert_wbc_ok(tctx
, wbcListGroups(domain_name
, &num_groups
, &groups
),
295 "wbcListGroups in %s failed", domain_name
);
296 torture_assert(tctx
, !(num_groups
> 0 && !groups
),
297 "wbcListGroups returned invalid results");
299 for (i
=0; i
< MIN(num_groups
,100); i
++) {
301 struct wbcDomainSid sid
;
302 enum wbcSidType name_type
;
307 torture_assert_wbc_ok(tctx
, wbcLookupName(domain_name
, groups
[i
], &sid
, &name_type
),
308 "wbcLookupName for %s failed", domain_name
);
309 wbcSidToString(&sid
, &sid_string
);
310 torture_assert_wbc_ok(tctx
, wbcLookupSid(&sid
, &domain
, &name
, &name_type
),
311 "wbcLookupSid of %s failed", sid_string
);
312 wbcFreeMemory(sid_string
);
313 torture_assert(tctx
, name
,
314 "wbcLookupSid returned no name");
316 wbcFreeMemory(groups
);
321 static bool test_wbc_trusts(struct torture_context
*tctx
)
323 struct wbcDomainInfo
*domains
;
327 torture_assert_wbc_ok(tctx
, wbcListTrusts(&domains
, &num_domains
),
328 "%s", "wbcListTrusts failed");
329 torture_assert(tctx
, !(num_domains
> 0 && !domains
),
330 "wbcListTrusts returned invalid results");
332 for (i
=0; i
< MIN(num_domains
,100); i
++) {
334 struct wbcAuthErrorInfo
*error
;
336 struct wbcDomainSid sid;
337 enum wbcSidType name_type;
341 torture_assert_wbc_ok(tctx
, wbcCheckTrustCredentials(domains
[i
].short_name
, &error
),
342 "%s", "wbcCheckTrustCredentials failed");
344 torture_assert_wbc_ok(tctx, wbcLookupName(domains[i].short_name, NULL, &sid, &name_type),
345 "wbcLookupName failed");
346 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
347 "wbcLookupName expected WBC_SID_NAME_DOMAIN");
348 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
349 "wbcLookupSid failed");
350 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
351 "wbcLookupSid expected WBC_SID_NAME_DOMAIN");
352 torture_assert(tctx, name,
353 "wbcLookupSid returned no name");
356 wbcFreeMemory(domains
);
361 static bool test_wbc_lookupdc(struct torture_context
*tctx
)
363 const char *domain_name
= NULL
;
364 struct wbcInterfaceDetails
*details
;
365 struct wbcDomainControllerInfo
*dc_info
;
367 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
368 "%s", "wbcInterfaceDetails failed");
370 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
371 wbcFreeMemory(details
);
373 torture_assert_wbc_ok(tctx
, wbcLookupDomainController(domain_name
, 0, &dc_info
),
374 "wbcLookupDomainController for %s failed", domain_name
);
375 wbcFreeMemory(dc_info
);
380 static bool test_wbc_lookupdcex(struct torture_context
*tctx
)
382 const char *domain_name
= NULL
;
383 struct wbcInterfaceDetails
*details
;
384 struct wbcDomainControllerInfoEx
*dc_info
;
386 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
387 "%s", "wbcInterfaceDetails failed");
389 domain_name
= talloc_strdup(tctx
, details
->netbios_domain
);
390 wbcFreeMemory(details
);
392 torture_assert_wbc_ok(tctx
, wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
, 0, &dc_info
),
393 "wbcLookupDomainControllerEx for %s failed", domain_name
);
394 wbcFreeMemory(dc_info
);
399 static bool test_wbc_resolve_winsbyname(struct torture_context
*tctx
)
405 name
= torture_setting_string(tctx
, "host", NULL
);
407 ret
= wbcResolveWinsByName(name
, &ip
);
409 if (is_ipaddress(name
)) {
410 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_DOMAIN_NOT_FOUND
, "wbcResolveWinsByName of %s failed", name
);
412 torture_assert_wbc_ok(tctx
, ret
, "wbcResolveWinsByName for %s failed", name
);
418 static bool test_wbc_resolve_winsbyip(struct torture_context
*tctx
)
424 ip
= torture_setting_string(tctx
, "host", NULL
);
426 ret
= wbcResolveWinsByIP(ip
, &name
);
428 torture_assert_wbc_ok(tctx
, ret
, "wbcResolveWinsByIP for %s failed", ip
);
435 static bool test_wbc_lookup_rids(struct torture_context
*tctx
)
437 struct wbcDomainSid builtin
;
438 uint32_t rids
[2] = { 544, 545 };
439 const char *domain_name
, **names
;
440 enum wbcSidType
*types
;
443 wbcStringToSid("S-1-5-32", &builtin
);
445 ret
= wbcLookupRids(&builtin
, 2, rids
, &domain_name
, &names
,
447 torture_assert_wbc_ok(tctx
, ret
, "%s", "wbcLookupRids for 544 and 545 failed");
449 torture_assert_str_equal(
450 tctx
, names
[0], "Administrators",
451 "S-1-5-32-544 not mapped to 'Administrators'");
452 torture_assert_str_equal(
453 tctx
, names
[1], "Users", "S-1-5-32-545 not mapped to 'Users'");
455 wbcFreeMemory(discard_const_p(char ,domain_name
));
456 wbcFreeMemory(names
);
457 wbcFreeMemory(types
);
462 static bool test_wbc_get_sidaliases(struct torture_context
*tctx
)
464 struct wbcDomainSid builtin
;
465 struct wbcDomainInfo
*info
;
466 struct wbcInterfaceDetails
*details
;
467 struct wbcDomainSid sids
[2];
472 torture_assert_wbc_ok(tctx
, wbcInterfaceDetails(&details
),
473 "%s", "wbcInterfaceDetails failed");
474 torture_assert_wbc_ok(
475 tctx
, wbcDomainInfo(details
->netbios_domain
, &info
),
476 "wbcDomainInfo of %s failed", details
->netbios_domain
);
477 wbcFreeMemory(details
);
480 sids
[0].sub_auths
[sids
[0].num_auths
++] = 500;
482 sids
[1].sub_auths
[sids
[1].num_auths
++] = 512;
485 torture_assert_wbc_ok(
486 tctx
, wbcStringToSid("S-1-5-32", &builtin
),
487 "wbcStringToSid of %s failed", "S-1-5-32");
489 ret
= wbcGetSidAliases(&builtin
, sids
, 2, &rids
, &num_rids
);
490 torture_assert_wbc_ok(tctx
, ret
, "%s", "wbcGetSidAliases failed");
497 static bool test_wbc_authenticate_user_int(struct torture_context
*tctx
,
498 const char *correct_password
)
500 struct wbcAuthUserParams params
;
501 struct wbcAuthUserInfo
*info
= NULL
;
502 struct wbcAuthErrorInfo
*error
= NULL
;
505 ret
= wbcAuthenticateUser(cli_credentials_get_username(cmdline_credentials
), correct_password
);
506 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
507 "wbcAuthenticateUser of %s failed",
508 cli_credentials_get_username(cmdline_credentials
));
511 params
.account_name
= cli_credentials_get_username(cmdline_credentials
);
512 params
.level
= WBC_AUTH_USER_LEVEL_PLAIN
;
513 params
.password
.plaintext
= correct_password
;
515 ret
= wbcAuthenticateUserEx(¶ms
, &info
, &error
);
516 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
517 "wbcAuthenticateUserEx of %s failed", params
.account_name
);
521 wbcFreeMemory(error
);
524 params
.password
.plaintext
= "wrong";
525 ret
= wbcAuthenticateUserEx(¶ms
, &info
, &error
);
526 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_AUTH_ERROR
,
527 "wbcAuthenticateUserEx for %s succeeded where it "
528 "should have failed", params
.account_name
);
532 wbcFreeMemory(error
);
538 static bool test_wbc_authenticate_user(struct torture_context
*tctx
)
540 return test_wbc_authenticate_user_int(tctx
, cli_credentials_get_password(cmdline_credentials
));
543 static bool test_wbc_change_password(struct torture_context
*tctx
)
546 const char *oldpass
= cli_credentials_get_password(cmdline_credentials
);
547 const char *newpass
= "Koo8irei%$";
549 struct samr_CryptPassword new_nt_password
;
550 struct samr_CryptPassword new_lm_password
;
551 struct samr_Password old_nt_hash_enc
;
552 struct samr_Password old_lanman_hash_enc
;
554 uint8_t old_nt_hash
[16];
555 uint8_t old_lanman_hash
[16];
556 uint8_t new_nt_hash
[16];
557 uint8_t new_lanman_hash
[16];
559 struct wbcChangePasswordParams params
;
561 if (oldpass
== NULL
) {
563 "skipping wbcChangeUserPassword test as old password cannot be retrieved\n");
568 E_md4hash(oldpass
, old_nt_hash
);
569 E_md4hash(newpass
, new_nt_hash
);
571 if (lpcfg_client_lanman_auth(tctx
->lp_ctx
) &&
572 E_deshash(newpass
, new_lanman_hash
) &&
573 E_deshash(oldpass
, old_lanman_hash
)) {
575 /* E_deshash returns false for 'long' passwords (> 14
576 DOS chars). This allows us to match Win2k, which
577 does not store a LM hash for these passwords (which
578 would reduce the effective password length to 14) */
580 encode_pw_buffer(new_lm_password
.data
, newpass
, STR_UNICODE
);
581 arcfour_crypt(new_lm_password
.data
, old_nt_hash
, 516);
582 E_old_pw_hash(new_nt_hash
, old_lanman_hash
,
583 old_lanman_hash_enc
.hash
);
585 params
.old_password
.response
.old_lm_hash_enc_length
=
586 sizeof(old_lanman_hash_enc
.hash
);
587 params
.old_password
.response
.old_lm_hash_enc_data
=
588 old_lanman_hash_enc
.hash
;
589 params
.new_password
.response
.lm_length
=
590 sizeof(new_lm_password
.data
);
591 params
.new_password
.response
.lm_data
=
592 new_lm_password
.data
;
594 ZERO_STRUCT(new_lm_password
);
595 ZERO_STRUCT(old_lanman_hash_enc
);
598 encode_pw_buffer(new_nt_password
.data
, newpass
, STR_UNICODE
);
600 arcfour_crypt(new_nt_password
.data
, old_nt_hash
, 516);
601 E_old_pw_hash(new_nt_hash
, old_nt_hash
, old_nt_hash_enc
.hash
);
603 params
.old_password
.response
.old_nt_hash_enc_length
=
604 sizeof(old_nt_hash_enc
.hash
);
605 params
.old_password
.response
.old_nt_hash_enc_data
=
606 old_nt_hash_enc
.hash
;
607 params
.new_password
.response
.nt_length
= sizeof(new_nt_password
.data
);
608 params
.new_password
.response
.nt_data
= new_nt_password
.data
;
610 params
.level
= WBC_CHANGE_PASSWORD_LEVEL_RESPONSE
;
611 params
.account_name
= cli_credentials_get_username(cmdline_credentials
);
612 params
.domain_name
= cli_credentials_get_domain(cmdline_credentials
);
614 ret
= wbcChangeUserPasswordEx(¶ms
, NULL
, NULL
, NULL
);
615 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
616 "wbcChangeUserPassword for %s failed", params
.account_name
);
618 if (!test_wbc_authenticate_user_int(tctx
, newpass
)) {
622 ret
= wbcChangeUserPassword(cli_credentials_get_username(cmdline_credentials
), newpass
,
623 cli_credentials_get_password(cmdline_credentials
));
624 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
625 "wbcChangeUserPassword for %s failed", params
.account_name
);
627 return test_wbc_authenticate_user_int(tctx
, cli_credentials_get_password(cmdline_credentials
));
630 static bool test_wbc_logon_user(struct torture_context
*tctx
)
632 struct wbcLogonUserParams params
;
633 struct wbcLogonUserInfo
*info
= NULL
;
634 struct wbcAuthErrorInfo
*error
= NULL
;
635 struct wbcUserPasswordPolicyInfo
*policy
= NULL
;
636 struct wbcInterfaceDetails
*iface
;
637 struct wbcDomainSid sid
;
638 enum wbcSidType sidtype
;
644 ret
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
645 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_INVALID_PARAM
,
646 "%s", "wbcLogonUser succeeded for NULL where it should "
649 params
.username
= cli_credentials_get_username(cmdline_credentials
);
650 params
.password
= cli_credentials_get_password(cmdline_credentials
);
652 ret
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
653 "foo", 0, discard_const_p(uint8_t, "bar"), 4);
654 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
655 "%s", "wbcAddNamedBlob failed");
657 ret
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
658 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
659 "wbcLogonUser for %s failed", params
.username
);
660 wbcFreeMemory(info
); info
= NULL
;
661 wbcFreeMemory(error
); error
= NULL
;
662 wbcFreeMemory(policy
); policy
= NULL
;
664 params
.password
= "wrong";
666 ret
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
667 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_AUTH_ERROR
,
668 "wbcLogonUser for %s should have failed with "
669 "WBC_ERR_AUTH_ERROR", params
.username
);
670 wbcFreeMemory(info
); info
= NULL
;
671 wbcFreeMemory(error
); error
= NULL
;
672 wbcFreeMemory(policy
); policy
= NULL
;
674 ret
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
676 discard_const_p(uint8_t, "S-1-2-3-4"),
677 strlen("S-1-2-3-4")+1);
678 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
679 "%s", "wbcAddNamedBlob failed");
680 params
.password
= cli_credentials_get_password(cmdline_credentials
);
681 ret
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
682 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_AUTH_ERROR
,
683 "wbcLogonUser for %s should have failed with "
684 "WBC_ERR_AUTH_ERROR", params
.username
);
685 wbcFreeMemory(info
); info
= NULL
;
686 wbcFreeMemory(error
); error
= NULL
;
687 wbcFreeMemory(policy
); policy
= NULL
;
688 wbcFreeMemory(params
.blobs
);
689 params
.blobs
= NULL
; params
.num_blobs
= 0;
691 ret
= wbcInterfaceDetails(&iface
);
692 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
693 "%s", "wbcInterfaceDetails failed");
695 ret
= wbcLookupName(iface
->netbios_domain
, cli_credentials_get_username(cmdline_credentials
), &sid
,
697 wbcFreeMemory(iface
);
698 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
699 "wbcLookupName for %s failed", cli_credentials_get_username(cmdline_credentials
));
701 ret
= wbcSidToString(&sid
, &sidstr
);
702 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
703 "%s", "wbcSidToString failed");
705 ret
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
707 (uint8_t *)sidstr
, strlen(sidstr
)+1);
708 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
709 "%s", "wbcAddNamedBlob failed");
710 wbcFreeMemory(sidstr
);
711 params
.password
= cli_credentials_get_password(cmdline_credentials
);
712 ret
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
713 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
714 "wbcLogonUser for %s failed", params
.username
);
715 wbcFreeMemory(info
); info
= NULL
;
716 wbcFreeMemory(error
); error
= NULL
;
717 wbcFreeMemory(policy
); policy
= NULL
;
718 wbcFreeMemory(params
.blobs
);
719 params
.blobs
= NULL
; params
.num_blobs
= 0;
724 static bool test_wbc_getgroups(struct torture_context
*tctx
)
730 ret
= wbcGetGroups(cli_credentials_get_username(cmdline_credentials
), &num_groups
, &groups
);
731 torture_assert_wbc_equal(tctx
, ret
, WBC_ERR_SUCCESS
,
732 "wbcGetGroups for %s failed", cli_credentials_get_username(cmdline_credentials
));
733 wbcFreeMemory(groups
);
737 struct torture_suite
*torture_wbclient(void)
739 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "wbclient");
741 torture_suite_add_simple_test(suite
, "wbcPing", test_wbc_ping
);
742 torture_suite_add_simple_test(suite
, "wbcPingDc", test_wbc_pingdc
);
743 torture_suite_add_simple_test(suite
, "wbcPingDc2", test_wbc_pingdc2
);
744 torture_suite_add_simple_test(suite
, "wbcLibraryDetails", test_wbc_library_details
);
745 torture_suite_add_simple_test(suite
, "wbcInterfaceDetails", test_wbc_interface_details
);
746 torture_suite_add_simple_test(suite
, "wbcSidTypeString", test_wbc_sidtypestring
);
747 torture_suite_add_simple_test(suite
, "wbcSidToString", test_wbc_sidtostring
);
748 torture_suite_add_simple_test(suite
, "wbcGuidToString", test_wbc_guidtostring
);
749 torture_suite_add_simple_test(suite
, "wbcDomainInfo", test_wbc_domain_info
);
750 torture_suite_add_simple_test(suite
, "wbcListUsers", test_wbc_users
);
751 torture_suite_add_simple_test(suite
, "wbcListGroups", test_wbc_groups
);
752 torture_suite_add_simple_test(suite
, "wbcListTrusts", test_wbc_trusts
);
753 torture_suite_add_simple_test(suite
, "wbcLookupDomainController", test_wbc_lookupdc
);
754 torture_suite_add_simple_test(suite
, "wbcLookupDomainControllerEx", test_wbc_lookupdcex
);
755 torture_suite_add_simple_test(suite
, "wbcResolveWinsByName", test_wbc_resolve_winsbyname
);
756 torture_suite_add_simple_test(suite
, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip
);
757 torture_suite_add_simple_test(suite
, "wbcLookupRids",
758 test_wbc_lookup_rids
);
759 torture_suite_add_simple_test(suite
, "wbcGetSidAliases",
760 test_wbc_get_sidaliases
);
761 torture_suite_add_simple_test(suite
, "wbcAuthenticateUser",
762 test_wbc_authenticate_user
);
763 torture_suite_add_simple_test(suite
, "wbcLogonUser",
764 test_wbc_logon_user
);
765 torture_suite_add_simple_test(suite
, "wbcChangeUserPassword",
766 test_wbc_change_password
);
767 torture_suite_add_simple_test(suite
, "wbcGetGroups",