Changeset 740 for vendor/current/nsswitch/libwbclient/tests
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/nsswitch/libwbclient/tests/wbclient.c
r414 r740 2 2 Unix SMB/CIFS implementation. 3 3 SMB torture tester 4 Copyright (C) Guenther Deschner 2009 4 Copyright (C) Guenther Deschner 2009-2010 5 5 6 6 This program is free software; you can redistribute it and/or modify … … 18 18 */ 19 19 20 #include "includes.h" 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" 21 25 #include "nsswitch/libwbclient/wbclient.h" 22 26 #include "torture/smbtorture.h" 23 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 "source4/param/param.h" 32 #include "lib/util/util.h" 33 #include "lib/crypto/arcfour.h" 24 34 25 35 #define WBC_ERROR_EQUAL(x,y) (x == y) … … 40 50 torture_assert_wbc_ok(tctx, wbcPing(), 41 51 "wbcPing failed"); 52 53 return true; 54 } 55 56 static bool test_wbc_pingdc(struct torture_context *tctx) 57 { 58 torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_NOT_IMPLEMENTED, 59 "wbcPingDc failed"); 60 torture_assert_wbc_ok(tctx, wbcPingDc(NULL, NULL), 61 "wbcPingDc failed"); 42 62 43 63 return true; … … 109 129 torture_assert_str_equal(tctx, sid_string, sid_string2, 110 130 "sid strings differ"); 131 wbcFreeMemory(sid_string2); 111 132 112 133 return true; … … 125 146 torture_assert_str_equal(tctx, guid_string, guid_string2, 126 147 "guid strings differ"); 148 wbcFreeMemory(guid_string2); 127 149 128 150 return true; … … 131 153 static bool test_wbc_domain_info(struct torture_context *tctx) 132 154 { 133 const char *domain_name = NULL;134 155 struct wbcDomainInfo *info; 135 156 struct wbcInterfaceDetails *details; … … 137 158 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), 138 159 "wbcInterfaceDetails failed"); 139 140 domain_name = talloc_strdup(tctx, details->netbios_domain); 160 torture_assert_wbc_ok( 161 tctx, wbcDomainInfo(details->netbios_domain, &info), 162 "wbcDomainInfo failed"); 141 163 wbcFreeMemory(details); 142 164 143 torture_assert_wbc_ok(tctx, wbcDomainInfo(domain_name, &info),144 "wbcDomainInfo failed");145 165 torture_assert(tctx, info, 146 166 "wbcDomainInfo returned NULL pointer"); 167 wbcFreeMemory(info); 147 168 148 169 return true; … … 186 207 torture_assert(tctx, name, 187 208 "wbcLookupSid returned no name"); 209 wbcFreeMemory(domain); 210 wbcFreeMemory(name); 188 211 torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids), 189 212 "wbcLookupUserSids failed"); 213 torture_assert_wbc_ok( 214 tctx, wbcGetDisplayName(&sid, &domain, &name, 215 &name_type), 216 "wbcGetDisplayName failed"); 217 wbcFreeMemory(domain); 218 wbcFreeMemory(name); 219 wbcFreeMemory(sids); 190 220 } 221 wbcFreeMemory(users); 191 222 192 223 return true; … … 226 257 "wbcLookupSid returned no name"); 227 258 } 259 wbcFreeMemory(groups); 228 260 229 261 return true; … … 265 297 */ 266 298 } 299 wbcFreeMemory(domains); 267 300 268 301 return true; … … 283 316 torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info), 284 317 "wbcLookupDomainController failed"); 318 wbcFreeMemory(dc_info); 285 319 286 320 return true; … … 301 335 torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info), 302 336 "wbcLookupDomainControllerEx failed"); 303 304 return true; 305 } 306 337 wbcFreeMemory(dc_info); 338 339 return true; 340 } 341 342 static bool test_wbc_resolve_winsbyname(struct torture_context *tctx) 343 { 344 const char *name; 345 char *ip; 346 wbcErr ret; 347 348 name = torture_setting_string(tctx, "host", NULL); 349 350 ret = wbcResolveWinsByName(name, &ip); 351 352 if (is_ipaddress(name)) { 353 torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName failed"); 354 } else { 355 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName failed"); 356 } 357 358 return true; 359 } 360 361 static bool test_wbc_resolve_winsbyip(struct torture_context *tctx) 362 { 363 const char *ip; 364 char *name; 365 wbcErr ret; 366 367 ip = torture_setting_string(tctx, "host", NULL); 368 369 ret = wbcResolveWinsByIP(ip, &name); 370 371 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP failed"); 372 373 wbcFreeMemory(name); 374 375 return true; 376 } 377 378 static bool test_wbc_lookup_rids(struct torture_context *tctx) 379 { 380 struct wbcDomainSid builtin; 381 uint32_t rids[2] = { 544, 545 }; 382 const char *domain_name, **names; 383 enum wbcSidType *types; 384 wbcErr ret; 385 386 wbcStringToSid("S-1-5-32", &builtin); 387 388 ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names, 389 &types); 390 torture_assert_wbc_ok(tctx, ret, "wbcLookupRids failed"); 391 392 torture_assert_str_equal( 393 tctx, names[0], "Administrators", 394 "S-1-5-32-544 not mapped to 'Administrators'"); 395 torture_assert_str_equal( 396 tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'"); 397 398 wbcFreeMemory((char *)domain_name); 399 wbcFreeMemory(names); 400 wbcFreeMemory(types); 401 402 return true; 403 } 404 405 static bool test_wbc_get_sidaliases(struct torture_context *tctx) 406 { 407 struct wbcDomainSid builtin; 408 struct wbcDomainInfo *info; 409 struct wbcInterfaceDetails *details; 410 struct wbcDomainSid sids[2]; 411 uint32_t *rids; 412 uint32_t num_rids; 413 wbcErr ret; 414 415 torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), 416 "wbcInterfaceDetails failed"); 417 torture_assert_wbc_ok( 418 tctx, wbcDomainInfo(details->netbios_domain, &info), 419 "wbcDomainInfo failed"); 420 wbcFreeMemory(details); 421 422 sids[0] = info->sid; 423 sids[0].sub_auths[sids[0].num_auths++] = 500; 424 sids[1] = info->sid; 425 sids[1].sub_auths[sids[1].num_auths++] = 512; 426 wbcFreeMemory(info); 427 428 torture_assert_wbc_ok( 429 tctx, wbcStringToSid("S-1-5-32", &builtin), 430 "wbcStringToSid failed"); 431 432 ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids); 433 torture_assert_wbc_ok(tctx, ret, "wbcGetSidAliases failed"); 434 435 wbcFreeMemory(rids); 436 437 return true; 438 } 439 440 static bool test_wbc_authenticate_user_int(struct torture_context *tctx, 441 const char *correct_password) 442 { 443 struct wbcAuthUserParams params; 444 struct wbcAuthUserInfo *info = NULL; 445 struct wbcAuthErrorInfo *error = NULL; 446 wbcErr ret; 447 448 ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password); 449 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 450 "wbcAuthenticateUser failed"); 451 452 ZERO_STRUCT(params); 453 params.account_name = getenv("USERNAME"); 454 params.level = WBC_AUTH_USER_LEVEL_PLAIN; 455 params.password.plaintext = correct_password; 456 457 ret = wbcAuthenticateUserEx(¶ms, &info, &error); 458 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 459 "wbcAuthenticateUserEx failed"); 460 wbcFreeMemory(info); 461 info = NULL; 462 463 wbcFreeMemory(error); 464 error = NULL; 465 466 params.password.plaintext = "wrong"; 467 ret = wbcAuthenticateUserEx(¶ms, &info, &error); 468 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, 469 "wbcAuthenticateUserEx succeeded where it " 470 "should have failed"); 471 wbcFreeMemory(info); 472 info = NULL; 473 474 wbcFreeMemory(error); 475 error = NULL; 476 477 return true; 478 } 479 480 static bool test_wbc_authenticate_user(struct torture_context *tctx) 481 { 482 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD")); 483 } 484 485 static bool test_wbc_change_password(struct torture_context *tctx) 486 { 487 wbcErr ret; 488 const char *oldpass = getenv("PASSWORD"); 489 const char *newpass = "Koo8irei"; 490 491 struct samr_CryptPassword new_nt_password; 492 struct samr_CryptPassword new_lm_password; 493 struct samr_Password old_nt_hash_enc; 494 struct samr_Password old_lanman_hash_enc; 495 496 uint8_t old_nt_hash[16]; 497 uint8_t old_lanman_hash[16]; 498 uint8_t new_nt_hash[16]; 499 uint8_t new_lanman_hash[16]; 500 501 struct wbcChangePasswordParams params; 502 503 if (oldpass == NULL) { 504 torture_skip(tctx, 505 "skipping wbcChangeUserPassword test as old password cannot be retrieved\n"); 506 } 507 508 ZERO_STRUCT(params); 509 510 E_md4hash(oldpass, old_nt_hash); 511 E_md4hash(newpass, new_nt_hash); 512 513 if (lpcfg_client_lanman_auth(tctx->lp_ctx) && 514 E_deshash(newpass, new_lanman_hash) && 515 E_deshash(oldpass, old_lanman_hash)) { 516 517 /* E_deshash returns false for 'long' passwords (> 14 518 DOS chars). This allows us to match Win2k, which 519 does not store a LM hash for these passwords (which 520 would reduce the effective password length to 14) */ 521 522 encode_pw_buffer(new_lm_password.data, newpass, STR_UNICODE); 523 arcfour_crypt(new_lm_password.data, old_nt_hash, 516); 524 E_old_pw_hash(new_nt_hash, old_lanman_hash, 525 old_lanman_hash_enc.hash); 526 527 params.old_password.response.old_lm_hash_enc_length = 528 sizeof(old_lanman_hash_enc.hash); 529 params.old_password.response.old_lm_hash_enc_data = 530 old_lanman_hash_enc.hash; 531 params.new_password.response.lm_length = 532 sizeof(new_lm_password.data); 533 params.new_password.response.lm_data = 534 new_lm_password.data; 535 } else { 536 ZERO_STRUCT(new_lm_password); 537 ZERO_STRUCT(old_lanman_hash_enc); 538 } 539 540 encode_pw_buffer(new_nt_password.data, newpass, STR_UNICODE); 541 542 arcfour_crypt(new_nt_password.data, old_nt_hash, 516); 543 E_old_pw_hash(new_nt_hash, old_nt_hash, old_nt_hash_enc.hash); 544 545 params.old_password.response.old_nt_hash_enc_length = 546 sizeof(old_nt_hash_enc.hash); 547 params.old_password.response.old_nt_hash_enc_data = 548 old_nt_hash_enc.hash; 549 params.new_password.response.nt_length = sizeof(new_nt_password.data); 550 params.new_password.response.nt_data = new_nt_password.data; 551 552 params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE; 553 params.account_name = getenv("USERNAME"); 554 params.domain_name = "SAMBA-TEST"; 555 556 ret = wbcChangeUserPasswordEx(¶ms, NULL, NULL, NULL); 557 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 558 "wbcChangeUserPassword failed"); 559 560 if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) { 561 return false; 562 } 563 564 ret = wbcChangeUserPassword(getenv("USERNAME"), "Koo8irei", 565 getenv("PASSWORD")); 566 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 567 "wbcChangeUserPassword failed"); 568 569 return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD")); 570 } 571 572 static bool test_wbc_logon_user(struct torture_context *tctx) 573 { 574 struct wbcLogonUserParams params; 575 struct wbcLogonUserInfo *info = NULL; 576 struct wbcAuthErrorInfo *error = NULL; 577 struct wbcUserPasswordPolicyInfo *policy = NULL; 578 struct wbcInterfaceDetails *iface; 579 struct wbcDomainSid sid; 580 enum wbcSidType sidtype; 581 char *sidstr; 582 wbcErr ret; 583 584 ZERO_STRUCT(params); 585 586 ret = wbcLogonUser(¶ms, &info, &error, &policy); 587 torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM, 588 "wbcLogonUser succeeded where it should " 589 "have failed"); 590 591 params.username = getenv("USERNAME"); 592 params.password = getenv("PASSWORD"); 593 594 ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, 595 "foo", 0, discard_const_p(uint8_t, "bar"), 4); 596 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 597 "wbcAddNamedBlob failed"); 598 599 ret = wbcLogonUser(¶ms, &info, &error, &policy); 600 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 601 "wbcLogonUser failed"); 602 wbcFreeMemory(info); info = NULL; 603 wbcFreeMemory(error); error = NULL; 604 wbcFreeMemory(policy); policy = NULL; 605 606 params.password = "wrong"; 607 608 ret = wbcLogonUser(¶ms, &info, &error, &policy); 609 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, 610 "wbcLogonUser should have failed with " 611 "WBC_ERR_AUTH_ERROR"); 612 wbcFreeMemory(info); info = NULL; 613 wbcFreeMemory(error); error = NULL; 614 wbcFreeMemory(policy); policy = NULL; 615 616 ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, 617 "membership_of", 0, 618 discard_const_p(uint8_t, "S-1-2-3-4"), 619 strlen("S-1-2-3-4")+1); 620 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 621 "wbcAddNamedBlob failed"); 622 params.password = getenv("PASSWORD"); 623 ret = wbcLogonUser(¶ms, &info, &error, &policy); 624 torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, 625 "wbcLogonUser should have failed with " 626 "WBC_ERR_AUTH_ERROR"); 627 wbcFreeMemory(info); info = NULL; 628 wbcFreeMemory(error); error = NULL; 629 wbcFreeMemory(policy); policy = NULL; 630 wbcFreeMemory(params.blobs); 631 params.blobs = NULL; params.num_blobs = 0; 632 633 ret = wbcInterfaceDetails(&iface); 634 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 635 "wbcInterfaceDetails failed"); 636 637 ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid, 638 &sidtype); 639 wbcFreeMemory(iface); 640 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 641 "wbcLookupName failed"); 642 643 ret = wbcSidToString(&sid, &sidstr); 644 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 645 "wbcSidToString failed"); 646 647 ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, 648 "membership_of", 0, 649 (uint8_t *)sidstr, strlen(sidstr)+1); 650 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 651 "wbcAddNamedBlob failed"); 652 wbcFreeMemory(sidstr); 653 params.password = getenv("PASSWORD"); 654 ret = wbcLogonUser(¶ms, &info, &error, &policy); 655 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 656 "wbcLogonUser failed"); 657 wbcFreeMemory(info); info = NULL; 658 wbcFreeMemory(error); error = NULL; 659 wbcFreeMemory(policy); policy = NULL; 660 wbcFreeMemory(params.blobs); 661 params.blobs = NULL; params.num_blobs = 0; 662 663 return true; 664 } 665 666 static bool test_wbc_getgroups(struct torture_context *tctx) 667 { 668 wbcErr ret; 669 uint32_t num_groups; 670 gid_t *groups; 671 672 ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups); 673 torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, 674 "wbcGetGroups failed"); 675 wbcFreeMemory(groups); 676 return true; 677 } 307 678 308 679 struct torture_suite *torture_wbclient(void) 309 680 { 310 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), " WBCLIENT");681 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient"); 311 682 312 683 torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping); 684 torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc); 313 685 torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details); 314 686 torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details); … … 322 694 torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc); 323 695 torture_suite_add_simple_test(suite, "wbcLookupDomainControllerEx", test_wbc_lookupdcex); 696 torture_suite_add_simple_test(suite, "wbcResolveWinsByName", test_wbc_resolve_winsbyname); 697 torture_suite_add_simple_test(suite, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip); 698 torture_suite_add_simple_test(suite, "wbcLookupRids", 699 test_wbc_lookup_rids); 700 torture_suite_add_simple_test(suite, "wbcGetSidAliases", 701 test_wbc_get_sidaliases); 702 torture_suite_add_simple_test(suite, "wbcAuthenticateUser", 703 test_wbc_authenticate_user); 704 torture_suite_add_simple_test(suite, "wbcLogonUser", 705 test_wbc_logon_user); 706 torture_suite_add_simple_test(suite, "wbcChangeUserPassword", 707 test_wbc_change_password); 708 torture_suite_add_simple_test(suite, "wbcGetGroups", 709 test_wbc_getgroups); 324 710 325 711 return suite;
Note:
See TracChangeset
for help on using the changeset viewer.