s3:smbd: make conn_close_all() a void function
[Samba/gebeck_regimport.git] / nsswitch / libwbclient / tests / wbclient.c
blobd1055747a1658688887d8ea9a613804b28732f6c
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_library_details(struct torture_context *tctx)
68 struct wbcLibraryDetails *details;
70 torture_assert_wbc_ok(tctx, wbcLibraryDetails(&details),
71 "%s", "wbcLibraryDetails failed");
72 torture_assert(tctx, details,
73 "wbcLibraryDetails returned NULL pointer");
75 wbcFreeMemory(details);
77 return true;
80 static bool test_wbc_interface_details(struct torture_context *tctx)
82 struct wbcInterfaceDetails *details;
84 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
85 "%s", "wbcInterfaceDetails failed");
86 torture_assert(tctx, details,
87 "wbcInterfaceDetails returned NULL pointer");
89 wbcFreeMemory(details);
91 return true;
94 static bool test_wbc_sidtypestring(struct torture_context *tctx)
96 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_USE_NONE),
97 "SID_NONE", "SID_NONE failed");
98 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_USER),
99 "SID_USER", "SID_USER failed");
100 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DOM_GRP),
101 "SID_DOM_GROUP", "SID_DOM_GROUP failed");
102 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DOMAIN),
103 "SID_DOMAIN", "SID_DOMAIN failed");
104 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_ALIAS),
105 "SID_ALIAS", "SID_ALIAS failed");
106 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_WKN_GRP),
107 "SID_WKN_GROUP", "SID_WKN_GROUP failed");
108 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_DELETED),
109 "SID_DELETED", "SID_DELETED failed");
110 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_INVALID),
111 "SID_INVALID", "SID_INVALID failed");
112 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_UNKNOWN),
113 "SID_UNKNOWN", "SID_UNKNOWN failed");
114 torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_COMPUTER),
115 "SID_COMPUTER", "SID_COMPUTER failed");
116 return true;
119 static bool test_wbc_sidtostring(struct torture_context *tctx)
121 struct wbcDomainSid sid;
122 const char *sid_string = "S-1-5-32";
123 char *sid_string2;
125 torture_assert_wbc_ok(tctx, wbcStringToSid(sid_string, &sid),
126 "wbcStringToSid of %s failed", sid_string);
127 torture_assert_wbc_ok(tctx, wbcSidToString(&sid, &sid_string2),
128 "wbcSidToString of %s failed", sid_string);
129 torture_assert_str_equal(tctx, sid_string, sid_string2,
130 "sid strings differ");
131 wbcFreeMemory(sid_string2);
133 return true;
136 static bool test_wbc_guidtostring(struct torture_context *tctx)
138 struct wbcGuid guid;
139 const char *guid_string = "f7cf07b4-1487-45c7-824d-8b18cc580811";
140 char *guid_string2;
142 torture_assert_wbc_ok(tctx, wbcStringToGuid(guid_string, &guid),
143 "wbcStringToGuid of %s failed", guid_string);
144 torture_assert_wbc_ok(tctx, wbcGuidToString(&guid, &guid_string2),
145 "wbcGuidToString of %s failed", guid_string);
146 torture_assert_str_equal(tctx, guid_string, guid_string2,
147 "guid strings differ");
148 wbcFreeMemory(guid_string2);
150 return true;
153 static bool test_wbc_domain_info(struct torture_context *tctx)
155 struct wbcDomainInfo *info;
156 struct wbcInterfaceDetails *details;
158 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
159 "%s", "wbcInterfaceDetails failed");
160 torture_assert_wbc_ok(
161 tctx, wbcDomainInfo(details->netbios_domain, &info),
162 "%s", "wbcDomainInfo failed");
163 wbcFreeMemory(details);
165 torture_assert(tctx, info,
166 "wbcDomainInfo returned NULL pointer");
167 wbcFreeMemory(info);
169 return true;
172 static bool test_wbc_users(struct torture_context *tctx)
174 const char *domain_name = NULL;
175 uint32_t num_users;
176 const char **users;
177 int i;
178 struct wbcInterfaceDetails *details;
180 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
181 "%s", "wbcInterfaceDetails failed");
183 domain_name = talloc_strdup(tctx, details->netbios_domain);
184 wbcFreeMemory(details);
186 torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users),
187 "%s", "wbcListUsers failed");
188 torture_assert(tctx, !(num_users > 0 && !users),
189 "wbcListUsers returned invalid results");
191 for (i=0; i < MIN(num_users,100); i++) {
193 struct wbcDomainSid sid, *sids;
194 enum wbcSidType name_type;
195 char *domain;
196 char *name;
197 char *sid_string;
198 uint32_t num_sids;
200 torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, users[i], &sid, &name_type),
201 "wbcLookupName of %s failed", users[i]);
202 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
203 "wbcLookupName expected WBC_SID_NAME_USER");
204 wbcSidToString(&sid, &sid_string);
205 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
206 "wbcLookupSid of %s failed", sid_string);
207 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
208 "wbcLookupSid of expected WBC_SID_NAME_USER");
209 torture_assert(tctx, name,
210 "wbcLookupSid returned no name");
211 wbcFreeMemory(domain);
212 wbcFreeMemory(name);
213 torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
214 "wbcLookupUserSids of %s failed", sid_string);
215 torture_assert_wbc_ok(
216 tctx, wbcGetDisplayName(&sid, &domain, &name,
217 &name_type),
218 "wbcGetDisplayName of %s failed", sid_string);
219 wbcFreeMemory(domain);
220 wbcFreeMemory(name);
221 wbcFreeMemory(sids);
222 wbcFreeMemory(sid_string);
224 wbcFreeMemory(users);
226 return true;
229 static bool test_wbc_groups(struct torture_context *tctx)
231 const char *domain_name = NULL;
232 uint32_t num_groups;
233 const char **groups;
234 int i;
235 struct wbcInterfaceDetails *details;
237 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
238 "%s", "wbcInterfaceDetails failed");
240 domain_name = talloc_strdup(tctx, details->netbios_domain);
241 wbcFreeMemory(details);
243 torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups),
244 "wbcListGroups in %s failed", domain_name);
245 torture_assert(tctx, !(num_groups > 0 && !groups),
246 "wbcListGroups returned invalid results");
248 for (i=0; i < MIN(num_groups,100); i++) {
250 struct wbcDomainSid sid;
251 enum wbcSidType name_type;
252 char *domain;
253 char *name;
254 char *sid_string;
256 torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type),
257 "wbcLookupName for %s failed", domain_name);
258 wbcSidToString(&sid, &sid_string);
259 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
260 "wbcLookupSid of %s failed", sid_string);
261 wbcFreeMemory(sid_string);
262 torture_assert(tctx, name,
263 "wbcLookupSid returned no name");
265 wbcFreeMemory(groups);
267 return true;
270 static bool test_wbc_trusts(struct torture_context *tctx)
272 struct wbcDomainInfo *domains;
273 size_t num_domains;
274 int i;
276 torture_assert_wbc_ok(tctx, wbcListTrusts(&domains, &num_domains),
277 "%s", "wbcListTrusts failed");
278 torture_assert(tctx, !(num_domains > 0 && !domains),
279 "wbcListTrusts returned invalid results");
281 for (i=0; i < MIN(num_domains,100); i++) {
283 struct wbcAuthErrorInfo *error;
285 struct wbcDomainSid sid;
286 enum wbcSidType name_type;
287 char *domain;
288 char *name;
290 torture_assert_wbc_ok(tctx, wbcCheckTrustCredentials(domains[i].short_name, &error),
291 "%s", "wbcCheckTrustCredentials failed");
293 torture_assert_wbc_ok(tctx, wbcLookupName(domains[i].short_name, NULL, &sid, &name_type),
294 "wbcLookupName failed");
295 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
296 "wbcLookupName expected WBC_SID_NAME_DOMAIN");
297 torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
298 "wbcLookupSid failed");
299 torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_DOMAIN,
300 "wbcLookupSid expected WBC_SID_NAME_DOMAIN");
301 torture_assert(tctx, name,
302 "wbcLookupSid returned no name");
305 wbcFreeMemory(domains);
307 return true;
310 static bool test_wbc_lookupdc(struct torture_context *tctx)
312 const char *domain_name = NULL;
313 struct wbcInterfaceDetails *details;
314 struct wbcDomainControllerInfo *dc_info;
316 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
317 "%s", "wbcInterfaceDetails failed");
319 domain_name = talloc_strdup(tctx, details->netbios_domain);
320 wbcFreeMemory(details);
322 torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info),
323 "wbcLookupDomainController for %s failed", domain_name);
324 wbcFreeMemory(dc_info);
326 return true;
329 static bool test_wbc_lookupdcex(struct torture_context *tctx)
331 const char *domain_name = NULL;
332 struct wbcInterfaceDetails *details;
333 struct wbcDomainControllerInfoEx *dc_info;
335 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
336 "%s", "wbcInterfaceDetails failed");
338 domain_name = talloc_strdup(tctx, details->netbios_domain);
339 wbcFreeMemory(details);
341 torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info),
342 "wbcLookupDomainControllerEx for %s failed", domain_name);
343 wbcFreeMemory(dc_info);
345 return true;
348 static bool test_wbc_resolve_winsbyname(struct torture_context *tctx)
350 const char *name;
351 char *ip;
352 wbcErr ret;
354 name = torture_setting_string(tctx, "host", NULL);
356 ret = wbcResolveWinsByName(name, &ip);
358 if (is_ipaddress(name)) {
359 torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName of %s failed", name);
360 } else {
361 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName for %s failed", name);
364 return true;
367 static bool test_wbc_resolve_winsbyip(struct torture_context *tctx)
369 const char *ip;
370 char *name;
371 wbcErr ret;
373 ip = torture_setting_string(tctx, "host", NULL);
375 ret = wbcResolveWinsByIP(ip, &name);
377 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP for %s failed", ip);
379 wbcFreeMemory(name);
381 return true;
384 static bool test_wbc_lookup_rids(struct torture_context *tctx)
386 struct wbcDomainSid builtin;
387 uint32_t rids[2] = { 544, 545 };
388 const char *domain_name, **names;
389 enum wbcSidType *types;
390 wbcErr ret;
392 wbcStringToSid("S-1-5-32", &builtin);
394 ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names,
395 &types);
396 torture_assert_wbc_ok(tctx, ret, "%s", "wbcLookupRids for 544 and 545 failed");
398 torture_assert_str_equal(
399 tctx, names[0], "Administrators",
400 "S-1-5-32-544 not mapped to 'Administrators'");
401 torture_assert_str_equal(
402 tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'");
404 wbcFreeMemory(discard_const_p(char ,domain_name));
405 wbcFreeMemory(names);
406 wbcFreeMemory(types);
408 return true;
411 static bool test_wbc_get_sidaliases(struct torture_context *tctx)
413 struct wbcDomainSid builtin;
414 struct wbcDomainInfo *info;
415 struct wbcInterfaceDetails *details;
416 struct wbcDomainSid sids[2];
417 uint32_t *rids;
418 uint32_t num_rids;
419 wbcErr ret;
421 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
422 "%s", "wbcInterfaceDetails failed");
423 torture_assert_wbc_ok(
424 tctx, wbcDomainInfo(details->netbios_domain, &info),
425 "wbcDomainInfo of %s failed", details->netbios_domain);
426 wbcFreeMemory(details);
428 sids[0] = info->sid;
429 sids[0].sub_auths[sids[0].num_auths++] = 500;
430 sids[1] = info->sid;
431 sids[1].sub_auths[sids[1].num_auths++] = 512;
432 wbcFreeMemory(info);
434 torture_assert_wbc_ok(
435 tctx, wbcStringToSid("S-1-5-32", &builtin),
436 "wbcStringToSid of %s failed", "S-1-5-32");
438 ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids);
439 torture_assert_wbc_ok(tctx, ret, "%s", "wbcGetSidAliases failed");
441 wbcFreeMemory(rids);
443 return true;
446 static bool test_wbc_authenticate_user_int(struct torture_context *tctx,
447 const char *correct_password)
449 struct wbcAuthUserParams params;
450 struct wbcAuthUserInfo *info = NULL;
451 struct wbcAuthErrorInfo *error = NULL;
452 wbcErr ret;
454 ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password);
455 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
456 "wbcAuthenticateUser of %s failed", getenv("USERNAME"));
458 ZERO_STRUCT(params);
459 params.account_name = getenv("USERNAME");
460 params.level = WBC_AUTH_USER_LEVEL_PLAIN;
461 params.password.plaintext = correct_password;
463 ret = wbcAuthenticateUserEx(&params, &info, &error);
464 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
465 "wbcAuthenticateUserEx of %s failed", params.account_name);
466 wbcFreeMemory(info);
467 info = NULL;
469 wbcFreeMemory(error);
470 error = NULL;
472 params.password.plaintext = "wrong";
473 ret = wbcAuthenticateUserEx(&params, &info, &error);
474 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
475 "wbcAuthenticateUserEx for %s succeeded where it "
476 "should have failed", params.account_name);
477 wbcFreeMemory(info);
478 info = NULL;
480 wbcFreeMemory(error);
481 error = NULL;
483 return true;
486 static bool test_wbc_authenticate_user(struct torture_context *tctx)
488 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
491 static bool test_wbc_change_password(struct torture_context *tctx)
493 wbcErr ret;
494 const char *oldpass = getenv("PASSWORD");
495 const char *newpass = "Koo8irei";
497 struct samr_CryptPassword new_nt_password;
498 struct samr_CryptPassword new_lm_password;
499 struct samr_Password old_nt_hash_enc;
500 struct samr_Password old_lanman_hash_enc;
502 uint8_t old_nt_hash[16];
503 uint8_t old_lanman_hash[16];
504 uint8_t new_nt_hash[16];
505 uint8_t new_lanman_hash[16];
507 struct wbcChangePasswordParams params;
509 if (oldpass == NULL) {
510 torture_skip(tctx,
511 "skipping wbcChangeUserPassword test as old password cannot be retrieved\n");
514 ZERO_STRUCT(params);
516 E_md4hash(oldpass, old_nt_hash);
517 E_md4hash(newpass, new_nt_hash);
519 if (lpcfg_client_lanman_auth(tctx->lp_ctx) &&
520 E_deshash(newpass, new_lanman_hash) &&
521 E_deshash(oldpass, old_lanman_hash)) {
523 /* E_deshash returns false for 'long' passwords (> 14
524 DOS chars). This allows us to match Win2k, which
525 does not store a LM hash for these passwords (which
526 would reduce the effective password length to 14) */
528 encode_pw_buffer(new_lm_password.data, newpass, STR_UNICODE);
529 arcfour_crypt(new_lm_password.data, old_nt_hash, 516);
530 E_old_pw_hash(new_nt_hash, old_lanman_hash,
531 old_lanman_hash_enc.hash);
533 params.old_password.response.old_lm_hash_enc_length =
534 sizeof(old_lanman_hash_enc.hash);
535 params.old_password.response.old_lm_hash_enc_data =
536 old_lanman_hash_enc.hash;
537 params.new_password.response.lm_length =
538 sizeof(new_lm_password.data);
539 params.new_password.response.lm_data =
540 new_lm_password.data;
541 } else {
542 ZERO_STRUCT(new_lm_password);
543 ZERO_STRUCT(old_lanman_hash_enc);
546 encode_pw_buffer(new_nt_password.data, newpass, STR_UNICODE);
548 arcfour_crypt(new_nt_password.data, old_nt_hash, 516);
549 E_old_pw_hash(new_nt_hash, old_nt_hash, old_nt_hash_enc.hash);
551 params.old_password.response.old_nt_hash_enc_length =
552 sizeof(old_nt_hash_enc.hash);
553 params.old_password.response.old_nt_hash_enc_data =
554 old_nt_hash_enc.hash;
555 params.new_password.response.nt_length = sizeof(new_nt_password.data);
556 params.new_password.response.nt_data = new_nt_password.data;
558 params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE;
559 params.account_name = getenv("USERNAME");
560 params.domain_name = "SAMBA-TEST";
562 ret = wbcChangeUserPasswordEx(&params, NULL, NULL, NULL);
563 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
564 "wbcChangeUserPassword for %s failed", params.account_name);
566 if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) {
567 return false;
570 ret = wbcChangeUserPassword(getenv("USERNAME"), "Koo8irei",
571 getenv("PASSWORD"));
572 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
573 "wbcChangeUserPassword for %s failed", params.account_name);
575 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
578 static bool test_wbc_logon_user(struct torture_context *tctx)
580 struct wbcLogonUserParams params;
581 struct wbcLogonUserInfo *info = NULL;
582 struct wbcAuthErrorInfo *error = NULL;
583 struct wbcUserPasswordPolicyInfo *policy = NULL;
584 struct wbcInterfaceDetails *iface;
585 struct wbcDomainSid sid;
586 enum wbcSidType sidtype;
587 char *sidstr;
588 wbcErr ret;
590 ZERO_STRUCT(params);
592 ret = wbcLogonUser(&params, &info, &error, &policy);
593 torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM,
594 "%s", "wbcLogonUser succeeded for NULL where it should "
595 "have failed");
597 params.username = getenv("USERNAME");
598 params.password = getenv("PASSWORD");
600 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
601 "foo", 0, discard_const_p(uint8_t, "bar"), 4);
602 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
603 "%s", "wbcAddNamedBlob failed");
605 ret = wbcLogonUser(&params, &info, &error, &policy);
606 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
607 "wbcLogonUser for %s failed", params.username);
608 wbcFreeMemory(info); info = NULL;
609 wbcFreeMemory(error); error = NULL;
610 wbcFreeMemory(policy); policy = NULL;
612 params.password = "wrong";
614 ret = wbcLogonUser(&params, &info, &error, &policy);
615 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
616 "wbcLogonUser for %s should have failed with "
617 "WBC_ERR_AUTH_ERROR", params.username);
618 wbcFreeMemory(info); info = NULL;
619 wbcFreeMemory(error); error = NULL;
620 wbcFreeMemory(policy); policy = NULL;
622 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
623 "membership_of", 0,
624 discard_const_p(uint8_t, "S-1-2-3-4"),
625 strlen("S-1-2-3-4")+1);
626 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
627 "%s", "wbcAddNamedBlob failed");
628 params.password = getenv("PASSWORD");
629 ret = wbcLogonUser(&params, &info, &error, &policy);
630 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
631 "wbcLogonUser for %s should have failed with "
632 "WBC_ERR_AUTH_ERROR", params.username);
633 wbcFreeMemory(info); info = NULL;
634 wbcFreeMemory(error); error = NULL;
635 wbcFreeMemory(policy); policy = NULL;
636 wbcFreeMemory(params.blobs);
637 params.blobs = NULL; params.num_blobs = 0;
639 ret = wbcInterfaceDetails(&iface);
640 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
641 "%s", "wbcInterfaceDetails failed");
643 ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid,
644 &sidtype);
645 wbcFreeMemory(iface);
646 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
647 "wbcLookupName for %s failed", getenv("USERNAME"));
649 ret = wbcSidToString(&sid, &sidstr);
650 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
651 "%s", "wbcSidToString failed");
653 ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
654 "membership_of", 0,
655 (uint8_t *)sidstr, strlen(sidstr)+1);
656 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
657 "%s", "wbcAddNamedBlob failed");
658 wbcFreeMemory(sidstr);
659 params.password = getenv("PASSWORD");
660 ret = wbcLogonUser(&params, &info, &error, &policy);
661 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
662 "wbcLogonUser for %s failed", params.username);
663 wbcFreeMemory(info); info = NULL;
664 wbcFreeMemory(error); error = NULL;
665 wbcFreeMemory(policy); policy = NULL;
666 wbcFreeMemory(params.blobs);
667 params.blobs = NULL; params.num_blobs = 0;
669 return true;
672 static bool test_wbc_getgroups(struct torture_context *tctx)
674 wbcErr ret;
675 uint32_t num_groups;
676 gid_t *groups;
678 ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups);
679 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
680 "wbcGetGroups for %s failed", getenv("USERNAME"));
681 wbcFreeMemory(groups);
682 return true;
685 struct torture_suite *torture_wbclient(void)
687 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient");
689 torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
690 torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
691 torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
692 torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
693 torture_suite_add_simple_test(suite, "wbcSidTypeString", test_wbc_sidtypestring);
694 torture_suite_add_simple_test(suite, "wbcSidToString", test_wbc_sidtostring);
695 torture_suite_add_simple_test(suite, "wbcGuidToString", test_wbc_guidtostring);
696 torture_suite_add_simple_test(suite, "wbcDomainInfo", test_wbc_domain_info);
697 torture_suite_add_simple_test(suite, "wbcListUsers", test_wbc_users);
698 torture_suite_add_simple_test(suite, "wbcListGroups", test_wbc_groups);
699 torture_suite_add_simple_test(suite, "wbcListTrusts", test_wbc_trusts);
700 torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc);
701 torture_suite_add_simple_test(suite, "wbcLookupDomainControllerEx", test_wbc_lookupdcex);
702 torture_suite_add_simple_test(suite, "wbcResolveWinsByName", test_wbc_resolve_winsbyname);
703 torture_suite_add_simple_test(suite, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip);
704 torture_suite_add_simple_test(suite, "wbcLookupRids",
705 test_wbc_lookup_rids);
706 torture_suite_add_simple_test(suite, "wbcGetSidAliases",
707 test_wbc_get_sidaliases);
708 torture_suite_add_simple_test(suite, "wbcAuthenticateUser",
709 test_wbc_authenticate_user);
710 torture_suite_add_simple_test(suite, "wbcLogonUser",
711 test_wbc_logon_user);
712 torture_suite_add_simple_test(suite, "wbcChangeUserPassword",
713 test_wbc_change_password);
714 torture_suite_add_simple_test(suite, "wbcGetGroups",
715 test_wbc_getgroups);
717 return suite;