s3:net_idmap_delete do not lock two records at the same time
[Samba/gebeck_regimport.git] / nsswitch / libwbclient / tests / wbclient.c
blobcd44d692628305ccb2076aec6c74425b25318776
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
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"
35 #define WBC_ERROR_EQUAL(x,y) (x == y)
37 #define torture_assert_wbc_equal(torture_ctx, got, expected, cmt, cmt_arg) \
38 do { wbcErr __got = got, __expected = expected; \
39 if (!WBC_ERROR_EQUAL(__got, __expected)) { \
40 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: " cmt, wbcErrorString(__got), wbcErrorString(__expected), cmt_arg); \
41 return false; \
42 } \
43 } while (0)
45 #define torture_assert_wbc_ok(torture_ctx,expr,cmt,cmt_arg) \
46 torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt,cmt_arg)
48 static bool test_wbc_ping(struct torture_context *tctx)
50 torture_assert_wbc_ok(tctx, wbcPing(),
51 "%s", "wbcPing failed");
53 return true;
56 static bool test_wbc_pingdc(struct torture_context *tctx)
58 torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_NOT_IMPLEMENTED,
59 "%s", "wbcPingDc failed");
60 torture_assert_wbc_ok(tctx, wbcPingDc(NULL, NULL),
61 "%s", "wbcPingDc failed");
63 return true;
66 static bool test_wbc_pingdc2(struct torture_context *tctx)
68 char *name = NULL;
70 torture_assert_wbc_equal(tctx, wbcPingDc2("random_string", NULL, &name),
71 WBC_ERR_NOT_IMPLEMENTED, "%s",
72 "wbcPingDc2 failed");
73 torture_assert_wbc_ok(tctx, wbcPingDc2(NULL, NULL, &name), "%s",
74 "wbcPingDc2 failed");
76 return true;
79 static bool test_wbc_library_details(struct torture_context *tctx)
81 struct wbcLibraryDetails *details;
83 torture_assert_wbc_ok(tctx, wbcLibraryDetails(&details),
84 "%s", "wbcLibraryDetails failed");
85 torture_assert(tctx, details,
86 "wbcLibraryDetails returned NULL pointer");
88 wbcFreeMemory(details);
90 return true;
93 static bool test_wbc_interface_details(struct torture_context *tctx)
95 struct wbcInterfaceDetails *details;
97 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
98 "%s", "wbcInterfaceDetails failed");
99 torture_assert(tctx, details,
100 "wbcInterfaceDetails returned NULL pointer");
102 wbcFreeMemory(details);
104 return true;
107 static bool test_wbc_sidtypestring(struct torture_context *tctx)
109 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_USE_NONE),
110 "SID_NONE", "SID_NONE failed");
111 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_USER),
112 "SID_USER", "SID_USER failed");
113 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DOM_GRP),
114 "SID_DOM_GROUP", "SID_DOM_GROUP failed");
115 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DOMAIN),
116 "SID_DOMAIN", "SID_DOMAIN failed");
117 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_ALIAS),
118 "SID_ALIAS", "SID_ALIAS failed");
119 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_WKN_GRP),
120 "SID_WKN_GROUP", "SID_WKN_GROUP failed");
121 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DELETED),
122 "SID_DELETED", "SID_DELETED failed");
123 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_INVALID),
124 "SID_INVALID", "SID_INVALID failed");
125 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_UNKNOWN),
126 "SID_UNKNOWN", "SID_UNKNOWN failed");
127 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_COMPUTER),
128 "SID_COMPUTER", "SID_COMPUTER failed");
129 return true;
132 static bool test_wbc_sidtostring(struct torture_context *tctx)
134 struct wbcDomainSid sid;
135 const char *sid_string = "S-1-5-32";
136 char *sid_string2;
138 torture_assert_wbc_ok(tctx, wbcStringToSid(sid_string, &sid),
139 "wbcStringToSid of %s failed", sid_string);
140 torture_assert_wbc_ok(tctx, wbcSidToString(&sid, &sid_string2),
141 "wbcSidToString of %s failed", sid_string);
142 torture_assert_str_equal(tctx, sid_string, sid_string2,
143 "sid strings differ");
144 wbcFreeMemory(sid_string2);
146 return true;
149 static bool test_wbc_guidtostring(struct torture_context *tctx)
151 struct wbcGuid guid;
152 const char *guid_string = "f7cf07b4-1487-45c7-824d-8b18cc580811";
153 char *guid_string2;
155 torture_assert_wbc_ok(tctx, wbcStringToGuid(guid_string, &guid),
156 "wbcStringToGuid of %s failed", guid_string);
157 torture_assert_wbc_ok(tctx, wbcGuidToString(&guid, &guid_string2),
158 "wbcGuidToString of %s failed", guid_string);
159 torture_assert_str_equal(tctx, guid_string, guid_string2,
160 "guid strings differ");
161 wbcFreeMemory(guid_string2);
163 return true;
166 static bool test_wbc_domain_info(struct torture_context *tctx)
168 struct wbcDomainInfo *info;
169 struct wbcInterfaceDetails *details;
171 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
172 "%s", "wbcInterfaceDetails failed");
173 torture_assert_wbc_ok(
174 tctx, wbcDomainInfo(details->netbios_domain, &info),
175 "%s", "wbcDomainInfo failed");
176 wbcFreeMemory(details);
178 torture_assert(tctx, info,
179 "wbcDomainInfo returned NULL pointer");
180 wbcFreeMemory(info);
182 return true;
185 static bool test_wbc_users(struct torture_context *tctx)
187 const char *domain_name = NULL;
188 uint32_t num_users;
189 const char **users;
190 int i;
191 struct wbcInterfaceDetails *details;
193 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
194 "%s", "wbcInterfaceDetails failed");
196 domain_name = talloc_strdup(tctx, details->netbios_domain);
197 wbcFreeMemory(details);
199 torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users),
200 "%s", "wbcListUsers failed");
201 torture_assert(tctx, !(num_users > 0 && !users),
202 "wbcListUsers returned invalid results");
204 for (i=0; i < MIN(num_users,100); i++) {
206 struct wbcDomainSid sid, *sids;
207 enum wbcSidType name_type;
208 char *domain;
209 char *name;
210 char *sid_string;
211 uint32_t num_sids;
213 torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, users[i], &sid, &name_type),
214 "wbcLookupName of %s failed", users[i]);
215 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
216 "wbcLookupName expected WBC_SID_NAME_USER");
217 wbcSidToString(&sid, &sid_string);
218 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
219 "wbcLookupSid of %s failed", sid_string);
220 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
221 "wbcLookupSid of expected WBC_SID_NAME_USER");
222 torture_assert(tctx, name,
223 "wbcLookupSid returned no name");
224 wbcFreeMemory(domain);
225 wbcFreeMemory(name);
226 torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
227 "wbcLookupUserSids of %s failed", sid_string);
228 torture_assert_wbc_ok(
229 tctx, wbcGetDisplayName(&sid, &domain, &name,
230 &name_type),
231 "wbcGetDisplayName of %s failed", sid_string);
232 wbcFreeMemory(domain);
233 wbcFreeMemory(name);
234 wbcFreeMemory(sids);
235 wbcFreeMemory(sid_string);
237 wbcFreeMemory(users);
239 return true;
242 static bool test_wbc_groups(struct torture_context *tctx)
244 const char *domain_name = NULL;
245 uint32_t num_groups;
246 const char **groups;
247 int i;
248 struct wbcInterfaceDetails *details;
250 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
251 "%s", "wbcInterfaceDetails failed");
253 domain_name = talloc_strdup(tctx, details->netbios_domain);
254 wbcFreeMemory(details);
256 torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups),
257 "wbcListGroups in %s failed", domain_name);
258 torture_assert(tctx, !(num_groups > 0 && !groups),
259 "wbcListGroups returned invalid results");
261 for (i=0; i < MIN(num_groups,100); i++) {
263 struct wbcDomainSid sid;
264 enum wbcSidType name_type;
265 char *domain;
266 char *name;
267 char *sid_string;
269 torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type),
270 "wbcLookupName for %s failed", domain_name);
271 wbcSidToString(&sid, &sid_string);
272 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
273 "wbcLookupSid of %s failed", sid_string);
274 wbcFreeMemory(sid_string);
275 torture_assert(tctx, name,
276 "wbcLookupSid returned no name");
278 wbcFreeMemory(groups);
280 return true;
283 static bool test_wbc_trusts(struct torture_context *tctx)
285 struct wbcDomainInfo *domains;
286 size_t num_domains;
287 int i;
289 torture_assert_wbc_ok(tctx, wbcListTrusts(&domains, &num_domains),
290 "%s", "wbcListTrusts failed");
291 torture_assert(tctx, !(num_domains > 0 && !domains),
292 "wbcListTrusts returned invalid results");
294 for (i=0; i < MIN(num_domains,100); i++) {
296 struct wbcAuthErrorInfo *error;
298 struct wbcDomainSid sid;
299 enum wbcSidType name_type;
300 char *domain;
301 char *name;
303 torture_assert_wbc_ok(tctx, wbcCheckTrustCredentials(domains[i].short_name, &error),
304 "%s", "wbcCheckTrustCredentials failed");
306 torture_assert_wbc_ok(tctx, wbcLookupName(domains[i].short_name, NULL, &sid, &name_type),
307 "wbcLookupName failed");
308 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
309 "wbcLookupName expected WBC_SID_NAME_DOMAIN");
310 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
311 "wbcLookupSid failed");
312 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
313 "wbcLookupSid expected WBC_SID_NAME_DOMAIN");
314 torture_assert(tctx, name,
315 "wbcLookupSid returned no name");
318 wbcFreeMemory(domains);
320 return true;
323 static bool test_wbc_lookupdc(struct torture_context *tctx)
325 const char *domain_name = NULL;
326 struct wbcInterfaceDetails *details;
327 struct wbcDomainControllerInfo *dc_info;
329 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
330 "%s", "wbcInterfaceDetails failed");
332 domain_name = talloc_strdup(tctx, details->netbios_domain);
333 wbcFreeMemory(details);
335 torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info),
336 "wbcLookupDomainController for %s failed", domain_name);
337 wbcFreeMemory(dc_info);
339 return true;
342 static bool test_wbc_lookupdcex(struct torture_context *tctx)
344 const char *domain_name = NULL;
345 struct wbcInterfaceDetails *details;
346 struct wbcDomainControllerInfoEx *dc_info;
348 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
349 "%s", "wbcInterfaceDetails failed");
351 domain_name = talloc_strdup(tctx, details->netbios_domain);
352 wbcFreeMemory(details);
354 torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info),
355 "wbcLookupDomainControllerEx for %s failed", domain_name);
356 wbcFreeMemory(dc_info);
358 return true;
361 static bool test_wbc_resolve_winsbyname(struct torture_context *tctx)
363 const char *name;
364 char *ip;
365 wbcErr ret;
367 name = torture_setting_string(tctx, "host", NULL);
369 ret = wbcResolveWinsByName(name, &ip);
371 if (is_ipaddress(name)) {
372 torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName of %s failed", name);
373 } else {
374 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName for %s failed", name);
377 return true;
380 static bool test_wbc_resolve_winsbyip(struct torture_context *tctx)
382 const char *ip;
383 char *name;
384 wbcErr ret;
386 ip = torture_setting_string(tctx, "host", NULL);
388 ret = wbcResolveWinsByIP(ip, &name);
390 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP for %s failed", ip);
392 wbcFreeMemory(name);
394 return true;
397 static bool test_wbc_lookup_rids(struct torture_context *tctx)
399 struct wbcDomainSid builtin;
400 uint32_t rids[2] = { 544, 545 };
401 const char *domain_name, **names;
402 enum wbcSidType *types;
403 wbcErr ret;
405 wbcStringToSid("S-1-5-32", &builtin);
407 ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names,
408 &types);
409 torture_assert_wbc_ok(tctx, ret, "%s", "wbcLookupRids for 544 and 545 failed");
411 torture_assert_str_equal(
412 tctx, names[0], "Administrators",
413 "S-1-5-32-544 not mapped to 'Administrators'");
414 torture_assert_str_equal(
415 tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'");
417 wbcFreeMemory(discard_const_p(char ,domain_name));
418 wbcFreeMemory(names);
419 wbcFreeMemory(types);
421 return true;
424 static bool test_wbc_get_sidaliases(struct torture_context *tctx)
426 struct wbcDomainSid builtin;
427 struct wbcDomainInfo *info;
428 struct wbcInterfaceDetails *details;
429 struct wbcDomainSid sids[2];
430 uint32_t *rids;
431 uint32_t num_rids;
432 wbcErr ret;
434 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
435 "%s", "wbcInterfaceDetails failed");
436 torture_assert_wbc_ok(
437 tctx, wbcDomainInfo(details->netbios_domain, &info),
438 "wbcDomainInfo of %s failed", details->netbios_domain);
439 wbcFreeMemory(details);
441 sids[0] = info->sid;
442 sids[0].sub_auths[sids[0].num_auths++] = 500;
443 sids[1] = info->sid;
444 sids[1].sub_auths[sids[1].num_auths++] = 512;
445 wbcFreeMemory(info);
447 torture_assert_wbc_ok(
448 tctx, wbcStringToSid("S-1-5-32", &builtin),
449 "wbcStringToSid of %s failed", "S-1-5-32");
451 ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids);
452 torture_assert_wbc_ok(tctx, ret, "%s", "wbcGetSidAliases failed");
454 wbcFreeMemory(rids);
456 return true;
459 static bool test_wbc_authenticate_user_int(struct torture_context *tctx,
460 const char *correct_password)
462 struct wbcAuthUserParams params;
463 struct wbcAuthUserInfo *info = NULL;
464 struct wbcAuthErrorInfo *error = NULL;
465 wbcErr ret;
467 ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password);
468 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
469 "wbcAuthenticateUser of %s failed", getenv("USERNAME"));
471 ZERO_STRUCT(params);
472 params.account_name = getenv("USERNAME");
473 params.level = WBC_AUTH_USER_LEVEL_PLAIN;
474 params.password.plaintext = correct_password;
476 ret = wbcAuthenticateUserEx(&params, &info, &error);
477 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
478 "wbcAuthenticateUserEx of %s failed", params.account_name);
479 wbcFreeMemory(info);
480 info = NULL;
482 wbcFreeMemory(error);
483 error = NULL;
485 params.password.plaintext = "wrong";
486 ret = wbcAuthenticateUserEx(&params, &info, &error);
487 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
488 "wbcAuthenticateUserEx for %s succeeded where it "
489 "should have failed", params.account_name);
490 wbcFreeMemory(info);
491 info = NULL;
493 wbcFreeMemory(error);
494 error = NULL;
496 return true;
499 static bool test_wbc_authenticate_user(struct torture_context *tctx)
501 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
504 static bool test_wbc_change_password(struct torture_context *tctx)
506 wbcErr ret;
507 const char *oldpass = getenv("PASSWORD");
508 const char *newpass = "Koo8irei";
510 struct samr_CryptPassword new_nt_password;
511 struct samr_CryptPassword new_lm_password;
512 struct samr_Password old_nt_hash_enc;
513 struct samr_Password old_lanman_hash_enc;
515 uint8_t old_nt_hash[16];
516 uint8_t old_lanman_hash[16];
517 uint8_t new_nt_hash[16];
518 uint8_t new_lanman_hash[16];
520 struct wbcChangePasswordParams params;
522 if (oldpass == NULL) {
523 torture_skip(tctx,
524 "skipping wbcChangeUserPassword test as old password cannot be retrieved\n");
527 ZERO_STRUCT(params);
529 E_md4hash(oldpass, old_nt_hash);
530 E_md4hash(newpass, new_nt_hash);
532 if (lpcfg_client_lanman_auth(tctx->lp_ctx) &&
533 E_deshash(newpass, new_lanman_hash) &&
534 E_deshash(oldpass, old_lanman_hash)) {
536 /* E_deshash returns false for 'long' passwords (> 14
537 DOS chars). This allows us to match Win2k, which
538 does not store a LM hash for these passwords (which
539 would reduce the effective password length to 14) */
541 encode_pw_buffer(new_lm_password.data, newpass, STR_UNICODE);
542 arcfour_crypt(new_lm_password.data, old_nt_hash, 516);
543 E_old_pw_hash(new_nt_hash, old_lanman_hash,
544 old_lanman_hash_enc.hash);
546 params.old_password.response.old_lm_hash_enc_length =
547 sizeof(old_lanman_hash_enc.hash);
548 params.old_password.response.old_lm_hash_enc_data =
549 old_lanman_hash_enc.hash;
550 params.new_password.response.lm_length =
551 sizeof(new_lm_password.data);
552 params.new_password.response.lm_data =
553 new_lm_password.data;
554 } else {
555 ZERO_STRUCT(new_lm_password);
556 ZERO_STRUCT(old_lanman_hash_enc);
559 encode_pw_buffer(new_nt_password.data, newpass, STR_UNICODE);
561 arcfour_crypt(new_nt_password.data, old_nt_hash, 516);
562 E_old_pw_hash(new_nt_hash, old_nt_hash, old_nt_hash_enc.hash);
564 params.old_password.response.old_nt_hash_enc_length =
565 sizeof(old_nt_hash_enc.hash);
566 params.old_password.response.old_nt_hash_enc_data =
567 old_nt_hash_enc.hash;
568 params.new_password.response.nt_length = sizeof(new_nt_password.data);
569 params.new_password.response.nt_data = new_nt_password.data;
571 params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE;
572 params.account_name = getenv("USERNAME");
573 params.domain_name = "SAMBA-TEST";
575 ret = wbcChangeUserPasswordEx(&params, NULL, NULL, NULL);
576 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
577 "wbcChangeUserPassword for %s failed", params.account_name);
579 if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) {
580 return false;
583 ret = wbcChangeUserPassword(getenv("USERNAME"), "Koo8irei",
584 getenv("PASSWORD"));
585 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
586 "wbcChangeUserPassword for %s failed", params.account_name);
588 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
591 static bool test_wbc_logon_user(struct torture_context *tctx)
593 struct wbcLogonUserParams params;
594 struct wbcLogonUserInfo *info = NULL;
595 struct wbcAuthErrorInfo *error = NULL;
596 struct wbcUserPasswordPolicyInfo *policy = NULL;
597 struct wbcInterfaceDetails *iface;
598 struct wbcDomainSid sid;
599 enum wbcSidType sidtype;
600 char *sidstr;
601 wbcErr ret;
603 ZERO_STRUCT(params);
605 ret = wbcLogonUser(&params, &info, &error, &policy);
606 torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM,
607 "%s", "wbcLogonUser succeeded for NULL where it should "
608 "have failed");
610 params.username = getenv("USERNAME");
611 params.password = getenv("PASSWORD");
613 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
614 "foo", 0, discard_const_p(uint8_t, "bar"), 4);
615 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
616 "%s", "wbcAddNamedBlob failed");
618 ret = wbcLogonUser(&params, &info, &error, &policy);
619 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
620 "wbcLogonUser for %s failed", params.username);
621 wbcFreeMemory(info); info = NULL;
622 wbcFreeMemory(error); error = NULL;
623 wbcFreeMemory(policy); policy = NULL;
625 params.password = "wrong";
627 ret = wbcLogonUser(&params, &info, &error, &policy);
628 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
629 "wbcLogonUser for %s should have failed with "
630 "WBC_ERR_AUTH_ERROR", params.username);
631 wbcFreeMemory(info); info = NULL;
632 wbcFreeMemory(error); error = NULL;
633 wbcFreeMemory(policy); policy = NULL;
635 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
636 "membership_of", 0,
637 discard_const_p(uint8_t, "S-1-2-3-4"),
638 strlen("S-1-2-3-4")+1);
639 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
640 "%s", "wbcAddNamedBlob failed");
641 params.password = getenv("PASSWORD");
642 ret = wbcLogonUser(&params, &info, &error, &policy);
643 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
644 "wbcLogonUser for %s should have failed with "
645 "WBC_ERR_AUTH_ERROR", params.username);
646 wbcFreeMemory(info); info = NULL;
647 wbcFreeMemory(error); error = NULL;
648 wbcFreeMemory(policy); policy = NULL;
649 wbcFreeMemory(params.blobs);
650 params.blobs = NULL; params.num_blobs = 0;
652 ret = wbcInterfaceDetails(&iface);
653 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
654 "%s", "wbcInterfaceDetails failed");
656 ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid,
657 &sidtype);
658 wbcFreeMemory(iface);
659 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
660 "wbcLookupName for %s failed", getenv("USERNAME"));
662 ret = wbcSidToString(&sid, &sidstr);
663 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
664 "%s", "wbcSidToString failed");
666 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
667 "membership_of", 0,
668 (uint8_t *)sidstr, strlen(sidstr)+1);
669 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
670 "%s", "wbcAddNamedBlob failed");
671 wbcFreeMemory(sidstr);
672 params.password = getenv("PASSWORD");
673 ret = wbcLogonUser(&params, &info, &error, &policy);
674 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
675 "wbcLogonUser for %s failed", params.username);
676 wbcFreeMemory(info); info = NULL;
677 wbcFreeMemory(error); error = NULL;
678 wbcFreeMemory(policy); policy = NULL;
679 wbcFreeMemory(params.blobs);
680 params.blobs = NULL; params.num_blobs = 0;
682 return true;
685 static bool test_wbc_getgroups(struct torture_context *tctx)
687 wbcErr ret;
688 uint32_t num_groups;
689 gid_t *groups;
691 ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups);
692 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
693 "wbcGetGroups for %s failed", getenv("USERNAME"));
694 wbcFreeMemory(groups);
695 return true;
698 struct torture_suite *torture_wbclient(void)
700 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient");
702 torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
703 torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
704 torture_suite_add_simple_test(suite, "wbcPingDc2", test_wbc_pingdc);
705 torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
706 torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
707 torture_suite_add_simple_test(suite, "wbcSidTypeString", test_wbc_sidtypestring);
708 torture_suite_add_simple_test(suite, "wbcSidToString", test_wbc_sidtostring);
709 torture_suite_add_simple_test(suite, "wbcGuidToString", test_wbc_guidtostring);
710 torture_suite_add_simple_test(suite, "wbcDomainInfo", test_wbc_domain_info);
711 torture_suite_add_simple_test(suite, "wbcListUsers", test_wbc_users);
712 torture_suite_add_simple_test(suite, "wbcListGroups", test_wbc_groups);
713 torture_suite_add_simple_test(suite, "wbcListTrusts", test_wbc_trusts);
714 torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc);
715 torture_suite_add_simple_test(suite, "wbcLookupDomainControllerEx", test_wbc_lookupdcex);
716 torture_suite_add_simple_test(suite, "wbcResolveWinsByName", test_wbc_resolve_winsbyname);
717 torture_suite_add_simple_test(suite, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip);
718 torture_suite_add_simple_test(suite, "wbcLookupRids",
719 test_wbc_lookup_rids);
720 torture_suite_add_simple_test(suite, "wbcGetSidAliases",
721 test_wbc_get_sidaliases);
722 torture_suite_add_simple_test(suite, "wbcAuthenticateUser",
723 test_wbc_authenticate_user);
724 torture_suite_add_simple_test(suite, "wbcLogonUser",
725 test_wbc_logon_user);
726 torture_suite_add_simple_test(suite, "wbcChangeUserPassword",
727 test_wbc_change_password);
728 torture_suite_add_simple_test(suite, "wbcGetGroups",
729 test_wbc_getgroups);
731 return suite;