Changeset 740 for vendor/current/nsswitch
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/nsswitch
- Files:
-
- 5 added
- 7 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/nsswitch/libwbclient/libwbclient.h
r414 r740 32 32 #include "nsswitch/winbind_struct_protocol.h" 33 33 34 #include <talloc.h>35 36 34 /* Public headers */ 37 35 38 36 #include "wbclient.h" 39 #include "wbc_async.h"40 37 41 38 /* Private headers */ -
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; -
vendor/current/nsswitch/libwbclient/wbc_guid.c
r414 r740 30 30 char **guid_string) 31 31 { 32 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;32 char *result; 33 33 34 if (!guid) {35 wbc_status = WBC_ERR_INVALID_PARAM;36 BAIL_ON_WBC_ERROR(wbc_status);34 result = (char *)wbcAllocateMemory(37, 1, NULL); 35 if (result == NULL) { 36 return WBC_ERR_NO_MEMORY; 37 37 } 38 snprintf(result, 37, 39 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", 40 guid->time_low, guid->time_mid, 41 guid->time_hi_and_version, 42 guid->clock_seq[0], 43 guid->clock_seq[1], 44 guid->node[0], guid->node[1], 45 guid->node[2], guid->node[3], 46 guid->node[4], guid->node[5]); 47 *guid_string = result; 38 48 39 *guid_string = talloc_asprintf(NULL, 40 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", 41 guid->time_low, guid->time_mid, 42 guid->time_hi_and_version, 43 guid->clock_seq[0], 44 guid->clock_seq[1], 45 guid->node[0], guid->node[1], 46 guid->node[2], guid->node[3], 47 guid->node[4], guid->node[5]); 48 BAIL_ON_PTR_ERROR((*guid_string), wbc_status); 49 50 wbc_status = WBC_ERR_SUCCESS; 51 52 done: 53 return wbc_status; 49 return WBC_ERR_SUCCESS; 54 50 } 55 51 -
vendor/current/nsswitch/libwbclient/wbc_idmap.c
r478 r740 5 5 6 6 Copyright (C) Gerald (Jerry) Carter 2007 7 8 7 9 8 This library is free software; you can redistribute it and/or … … 25 24 #include "replace.h" 26 25 #include "libwbclient.h" 26 #include "../winbind_client.h" 27 27 28 28 /* Convert a Windows SID to a Unix uid, allocating an uid if needed */ … … 31 31 struct winbindd_request request; 32 32 struct winbindd_response response; 33 char *sid_string = NULL;34 33 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 35 34 … … 44 43 ZERO_STRUCT(response); 45 44 46 wbc_status = wbcSidToString(sid, &sid_string); 47 BAIL_ON_WBC_ERROR(wbc_status); 48 49 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 50 wbcFreeMemory(sid_string); 45 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 51 46 52 47 /* Make request */ … … 126 121 struct winbindd_response response; 127 122 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 128 char *sid_string = NULL;129 123 130 124 if (!sid || !pgid) { … … 138 132 ZERO_STRUCT(response); 139 133 140 wbc_status = wbcSidToString(sid, &sid_string); 141 BAIL_ON_WBC_ERROR(wbc_status); 142 143 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 144 wbcFreeMemory(sid_string); 134 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 145 135 146 136 /* Make request */ … … 159 149 } 160 150 151 161 152 /* Convert a Windows SID to a Unix gid if there already is a mapping */ 162 153 … … 166 157 return WBC_ERR_NOT_IMPLEMENTED; 167 158 } 159 168 160 169 161 /* Convert a Unix gid to a Windows SID, allocating a SID if needed */ … … 271 263 #define _ID_TYPE_GID 2 272 264 273 /* Set an user id mapping */265 /* Set an user id mapping - not implemented any more */ 274 266 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid) 275 267 { 276 struct winbindd_request request; 277 struct winbindd_response response; 278 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 279 char *sid_string = NULL; 280 281 if (!sid) { 282 return WBC_ERR_INVALID_PARAM; 283 } 284 285 /* Initialise request */ 286 287 ZERO_STRUCT(request); 288 ZERO_STRUCT(response); 289 290 /* Make request */ 291 292 request.data.dual_idmapset.id = uid; 293 request.data.dual_idmapset.type = _ID_TYPE_UID; 294 295 wbc_status = wbcSidToString(sid, &sid_string); 296 BAIL_ON_WBC_ERROR(wbc_status); 297 298 strncpy(request.data.dual_idmapset.sid, sid_string, 299 sizeof(request.data.dual_idmapset.sid)-1); 300 wbcFreeMemory(sid_string); 301 302 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_MAPPING, 303 &request, &response); 304 BAIL_ON_WBC_ERROR(wbc_status); 305 306 done: 307 return wbc_status; 308 } 309 310 /* Set a group id mapping */ 268 return WBC_ERR_NOT_IMPLEMENTED; 269 } 270 271 /* Set a group id mapping - not implemented any more */ 311 272 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid) 312 273 { 313 struct winbindd_request request; 314 struct winbindd_response response; 315 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 316 char *sid_string = NULL; 317 318 if (!sid) { 319 return WBC_ERR_INVALID_PARAM; 320 } 321 322 /* Initialise request */ 323 324 ZERO_STRUCT(request); 325 ZERO_STRUCT(response); 326 327 /* Make request */ 328 329 request.data.dual_idmapset.id = gid; 330 request.data.dual_idmapset.type = _ID_TYPE_GID; 331 332 wbc_status = wbcSidToString(sid, &sid_string); 333 BAIL_ON_WBC_ERROR(wbc_status); 334 335 strncpy(request.data.dual_idmapset.sid, sid_string, 336 sizeof(request.data.dual_idmapset.sid)-1); 337 wbcFreeMemory(sid_string); 338 339 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_MAPPING, 340 &request, &response); 341 BAIL_ON_WBC_ERROR(wbc_status); 342 343 done: 344 return wbc_status; 345 } 346 347 /* Remove a user id mapping */ 274 return WBC_ERR_NOT_IMPLEMENTED; 275 } 276 277 /* Remove a user id mapping - not implemented any more */ 348 278 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid) 349 279 { 350 struct winbindd_request request; 351 struct winbindd_response response; 352 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 353 char *sid_string = NULL; 354 355 if (!sid) { 356 return WBC_ERR_INVALID_PARAM; 357 } 358 359 /* Initialise request */ 360 361 ZERO_STRUCT(request); 362 ZERO_STRUCT(response); 363 364 /* Make request */ 365 366 request.data.dual_idmapset.id = uid; 367 request.data.dual_idmapset.type = _ID_TYPE_UID; 368 369 wbc_status = wbcSidToString(sid, &sid_string); 370 BAIL_ON_WBC_ERROR(wbc_status); 371 372 strncpy(request.data.dual_idmapset.sid, sid_string, 373 sizeof(request.data.dual_idmapset.sid)-1); 374 wbcFreeMemory(sid_string); 375 376 wbc_status = wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING, 377 &request, &response); 378 BAIL_ON_WBC_ERROR(wbc_status); 379 380 done: 381 return wbc_status; 382 } 383 384 /* Remove a group id mapping */ 280 return WBC_ERR_NOT_IMPLEMENTED; 281 } 282 283 /* Remove a group id mapping - not implemented any more */ 385 284 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid) 386 285 { 387 struct winbindd_request request; 388 struct winbindd_response response; 389 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 390 char *sid_string = NULL; 391 392 if (!sid) { 393 return WBC_ERR_INVALID_PARAM; 394 } 395 396 /* Initialise request */ 397 398 ZERO_STRUCT(request); 399 ZERO_STRUCT(response); 400 401 /* Make request */ 402 403 request.data.dual_idmapset.id = gid; 404 request.data.dual_idmapset.type = _ID_TYPE_GID; 405 406 wbc_status = wbcSidToString(sid, &sid_string); 407 BAIL_ON_WBC_ERROR(wbc_status); 408 409 strncpy(request.data.dual_idmapset.sid, sid_string, 410 sizeof(request.data.dual_idmapset.sid)-1); 411 wbcFreeMemory(sid_string); 412 413 wbc_status = wbcRequestResponsePriv(WINBINDD_REMOVE_MAPPING, 414 &request, &response); 415 BAIL_ON_WBC_ERROR(wbc_status); 416 417 done: 418 return wbc_status; 419 } 420 421 /* Set the highwater mark for allocated uids. */ 286 return WBC_ERR_NOT_IMPLEMENTED; 287 } 288 289 /* Set the highwater mark for allocated uids - not implemented any more */ 422 290 wbcErr wbcSetUidHwm(uid_t uid_hwm) 423 291 { 424 struct winbindd_request request; 425 struct winbindd_response response; 426 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 427 428 /* Initialise request */ 429 430 ZERO_STRUCT(request); 431 ZERO_STRUCT(response); 432 433 /* Make request */ 434 435 request.data.dual_idmapset.id = uid_hwm; 436 request.data.dual_idmapset.type = _ID_TYPE_UID; 437 438 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_HWM, 439 &request, &response); 440 BAIL_ON_WBC_ERROR(wbc_status); 441 442 done: 443 return wbc_status; 444 } 445 446 /* Set the highwater mark for allocated gids. */ 292 return WBC_ERR_NOT_IMPLEMENTED; 293 } 294 295 /* Set the highwater mark for allocated gids - not implemented any more */ 447 296 wbcErr wbcSetGidHwm(gid_t gid_hwm) 448 297 { 449 struct winbindd_request request; 450 struct winbindd_response response; 451 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 452 453 /* Initialise request */ 454 455 ZERO_STRUCT(request); 456 ZERO_STRUCT(response); 457 458 /* Make request */ 459 460 request.data.dual_idmapset.id = gid_hwm; 461 request.data.dual_idmapset.type = _ID_TYPE_GID; 462 463 wbc_status = wbcRequestResponsePriv(WINBINDD_SET_HWM, 464 &request, &response); 465 BAIL_ON_WBC_ERROR(wbc_status); 466 467 done: 468 return wbc_status; 469 } 298 return WBC_ERR_NOT_IMPLEMENTED; 299 } 300 301 /* Convert a list of SIDs */ 302 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids, 303 struct wbcUnixId *ids) 304 { 305 struct winbindd_request request; 306 struct winbindd_response response; 307 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 308 int buflen, extra_len; 309 uint32_t i; 310 char *sidlist, *p, *extra_data; 311 312 buflen = num_sids * (WBC_SID_STRING_BUFLEN + 1) + 1; 313 314 sidlist = (char *)malloc(buflen); 315 if (sidlist == NULL) { 316 return WBC_ERR_NO_MEMORY; 317 } 318 319 p = sidlist; 320 321 for (i=0; i<num_sids; i++) { 322 int remaining; 323 int len; 324 325 remaining = buflen - (p - sidlist); 326 327 len = wbcSidToStringBuf(&sids[i], p, remaining); 328 if (len > remaining) { 329 free(sidlist); 330 return WBC_ERR_UNKNOWN_FAILURE; 331 } 332 333 p += len; 334 *p++ = '\n'; 335 } 336 *p++ = '\0'; 337 338 ZERO_STRUCT(request); 339 ZERO_STRUCT(response); 340 341 request.extra_data.data = sidlist; 342 request.extra_len = p - sidlist; 343 344 wbc_status = wbcRequestResponse(WINBINDD_SIDS_TO_XIDS, 345 &request, &response); 346 free(sidlist); 347 if (!WBC_ERROR_IS_OK(wbc_status)) { 348 return wbc_status; 349 } 350 351 extra_len = response.length - sizeof(struct winbindd_response); 352 extra_data = (char *)response.extra_data.data; 353 354 if ((extra_len <= 0) || (extra_data[extra_len-1] != '\0')) { 355 goto wbc_err_invalid; 356 } 357 358 p = extra_data; 359 360 for (i=0; i<num_sids; i++) { 361 struct wbcUnixId *id = &ids[i]; 362 char *q; 363 364 switch (p[0]) { 365 case 'U': 366 id->type = WBC_ID_TYPE_UID; 367 id->id.uid = strtoul(p+1, &q, 10); 368 break; 369 case 'G': 370 id->type = WBC_ID_TYPE_GID; 371 id->id.gid = strtoul(p+1, &q, 10); 372 break; 373 default: 374 id->type = WBC_ID_TYPE_NOT_SPECIFIED; 375 q = p; 376 break; 377 }; 378 if (q[0] != '\n') { 379 goto wbc_err_invalid; 380 } 381 p = q+1; 382 } 383 wbc_status = WBC_ERR_SUCCESS; 384 goto done; 385 386 wbc_err_invalid: 387 wbc_status = WBC_ERR_INVALID_RESPONSE; 388 done: 389 winbindd_free_response(&response); 390 return wbc_status; 391 } -
vendor/current/nsswitch/libwbclient/wbc_pam.c
r597 r740 26 26 #include "replace.h" 27 27 #include "libwbclient.h" 28 #include "../winbind_client.h" 28 29 29 30 /* Authenticate a username/password pair */ … … 47 48 } 48 49 49 static wbcErr wbc_create_auth_info(TALLOC_CTX *mem_ctx, 50 const struct winbindd_response *resp, 50 static bool sid_attr_compose(struct wbcSidWithAttr *s, 51 const struct wbcDomainSid *d, 52 uint32_t rid, uint32_t attr) 53 { 54 if (d->num_auths >= WBC_MAXSUBAUTHS) { 55 return false; 56 } 57 s->sid = *d; 58 s->sid.sub_auths[s->sid.num_auths++] = rid; 59 s->attributes = attr; 60 return true; 61 } 62 63 static void wbcAuthUserInfoDestructor(void *ptr) 64 { 65 struct wbcAuthUserInfo *i = (struct wbcAuthUserInfo *)ptr; 66 free(i->account_name); 67 free(i->user_principal); 68 free(i->full_name); 69 free(i->domain_name); 70 free(i->dns_domain_name); 71 free(i->logon_server); 72 free(i->logon_script); 73 free(i->profile_path); 74 free(i->home_directory); 75 free(i->home_drive); 76 free(i->sids); 77 } 78 79 static wbcErr wbc_create_auth_info(const struct winbindd_response *resp, 51 80 struct wbcAuthUserInfo **_i) 52 81 { … … 58 87 uint32_t j; 59 88 60 i = talloc(mem_ctx, struct wbcAuthUserInfo); 89 i = (struct wbcAuthUserInfo *)wbcAllocateMemory( 90 1, sizeof(struct wbcAuthUserInfo), 91 wbcAuthUserInfoDestructor); 61 92 BAIL_ON_PTR_ERROR(i, wbc_status); 62 93 63 94 i->user_flags = resp->data.auth.info3.user_flgs; 64 95 65 i->account_name = talloc_strdup(i,resp->data.auth.info3.user_name);96 i->account_name = strdup(resp->data.auth.info3.user_name); 66 97 BAIL_ON_PTR_ERROR(i->account_name, wbc_status); 67 98 i->user_principal= NULL; 68 i->full_name = talloc_strdup(i,resp->data.auth.info3.full_name);99 i->full_name = strdup(resp->data.auth.info3.full_name); 69 100 BAIL_ON_PTR_ERROR(i->full_name, wbc_status); 70 i->domain_name = talloc_strdup(i,resp->data.auth.info3.logon_dom);101 i->domain_name = strdup(resp->data.auth.info3.logon_dom); 71 102 BAIL_ON_PTR_ERROR(i->domain_name, wbc_status); 72 103 i->dns_domain_name= NULL; … … 90 121 i->pass_must_change_time= resp->data.auth.info3.pass_must_change_time; 91 122 92 i->logon_server = talloc_strdup(i,resp->data.auth.info3.logon_srv);123 i->logon_server = strdup(resp->data.auth.info3.logon_srv); 93 124 BAIL_ON_PTR_ERROR(i->logon_server, wbc_status); 94 i->logon_script = talloc_strdup(i,resp->data.auth.info3.logon_script);125 i->logon_script = strdup(resp->data.auth.info3.logon_script); 95 126 BAIL_ON_PTR_ERROR(i->logon_script, wbc_status); 96 i->profile_path = talloc_strdup(i,resp->data.auth.info3.profile_path);127 i->profile_path = strdup(resp->data.auth.info3.profile_path); 97 128 BAIL_ON_PTR_ERROR(i->profile_path, wbc_status); 98 i->home_directory= talloc_strdup(i,resp->data.auth.info3.home_dir);129 i->home_directory= strdup(resp->data.auth.info3.home_dir); 99 130 BAIL_ON_PTR_ERROR(i->home_directory, wbc_status); 100 i->home_drive = talloc_strdup(i,resp->data.auth.info3.dir_drive);131 i->home_drive = strdup(resp->data.auth.info3.dir_drive); 101 132 BAIL_ON_PTR_ERROR(i->home_drive, wbc_status); 102 133 … … 105 136 i->num_sids += resp->data.auth.info3.num_other_sids; 106 137 107 i->sids = talloc_array(i, struct wbcSidWithAttr, i->num_sids); 138 i->sids = (struct wbcSidWithAttr *)calloc( 139 sizeof(struct wbcSidWithAttr), i->num_sids); 108 140 BAIL_ON_PTR_ERROR(i->sids, wbc_status); 109 141 … … 112 144 BAIL_ON_WBC_ERROR(wbc_status); 113 145 114 #define _SID_COMPOSE(s, d, r, a) { \115 (s).sid = d; \116 if ((s).sid.num_auths < WBC_MAXSUBAUTHS) { \117 (s).sid.sub_auths[(s).sid.num_auths++] = r; \118 } else { \119 wbc_status = WBC_ERR_INVALID_SID; \120 BAIL_ON_WBC_ERROR(wbc_status); \121 } \122 (s).attributes = a; \123 } while (0)124 125 146 sn = 0; 126 _SID_COMPOSE(i->sids[sn], domain_sid, 127 resp->data.auth.info3.user_rid, 128 0); 147 if (!sid_attr_compose(&i->sids[sn], &domain_sid, 148 resp->data.auth.info3.user_rid, 0)) { 149 wbc_status = WBC_ERR_INVALID_SID; 150 goto done; 151 } 129 152 sn++; 130 _SID_COMPOSE(i->sids[sn], domain_sid, 131 resp->data.auth.info3.group_rid, 132 0); 153 if (!sid_attr_compose(&i->sids[sn], &domain_sid, 154 resp->data.auth.info3.group_rid, 0)) { 155 wbc_status = WBC_ERR_INVALID_SID; 156 goto done; 157 } 133 158 sn++; 134 159 … … 158 183 } 159 184 160 _SID_COMPOSE(i->sids[sn], domain_sid, 161 rid, attrs); 185 if (!sid_attr_compose(&i->sids[sn], &domain_sid, 186 rid, attrs)) { 187 wbc_status = WBC_ERR_INVALID_SID; 188 goto done; 189 } 162 190 sn++; 163 191 } … … 203 231 i = NULL; 204 232 done: 205 talloc_free(i); 206 return wbc_status; 207 } 208 209 static wbcErr wbc_create_error_info(TALLOC_CTX *mem_ctx, 210 const struct winbindd_response *resp, 211 struct wbcAuthErrorInfo **_e) 233 wbcFreeMemory(i); 234 return wbc_status; 235 } 236 237 static void wbcAuthErrorInfoDestructor(void *ptr) 238 { 239 struct wbcAuthErrorInfo *e = (struct wbcAuthErrorInfo *)ptr; 240 free(e->nt_string); 241 free(e->display_string); 242 } 243 244 static wbcErr wbc_create_error_info(const struct winbindd_response *resp, 245 struct wbcAuthErrorInfo **_e) 212 246 { 213 247 wbcErr wbc_status = WBC_ERR_SUCCESS; 214 248 struct wbcAuthErrorInfo *e; 215 249 216 e = talloc(mem_ctx, struct wbcAuthErrorInfo); 250 e = (struct wbcAuthErrorInfo *)wbcAllocateMemory( 251 1, sizeof(struct wbcAuthErrorInfo), 252 wbcAuthErrorInfoDestructor); 217 253 BAIL_ON_PTR_ERROR(e, wbc_status); 218 254 219 255 e->nt_status = resp->data.auth.nt_status; 220 256 e->pam_error = resp->data.auth.pam_error; 221 e->nt_string = talloc_strdup(e,resp->data.auth.nt_status_string);257 e->nt_string = strdup(resp->data.auth.nt_status_string); 222 258 BAIL_ON_PTR_ERROR(e->nt_string, wbc_status); 223 259 224 e->display_string = talloc_strdup(e,resp->data.auth.error_string);260 e->display_string = strdup(resp->data.auth.error_string); 225 261 BAIL_ON_PTR_ERROR(e->display_string, wbc_status); 226 262 … … 229 265 230 266 done: 231 talloc_free(e); 232 return wbc_status; 233 } 234 235 static wbcErr wbc_create_password_policy_info(TALLOC_CTX *mem_ctx, 236 const struct winbindd_response *resp, 267 wbcFreeMemory(e); 268 return wbc_status; 269 } 270 271 static wbcErr wbc_create_password_policy_info(const struct winbindd_response *resp, 237 272 struct wbcUserPasswordPolicyInfo **_i) 238 273 { … … 240 275 struct wbcUserPasswordPolicyInfo *i; 241 276 242 i = talloc(mem_ctx, struct wbcUserPasswordPolicyInfo); 277 i = (struct wbcUserPasswordPolicyInfo *)wbcAllocateMemory( 278 1, sizeof(struct wbcUserPasswordPolicyInfo), NULL); 243 279 BAIL_ON_PTR_ERROR(i, wbc_status); 244 280 … … 253 289 254 290 done: 255 talloc_free(i); 256 return wbc_status; 257 } 258 259 static wbcErr wbc_create_logon_info(TALLOC_CTX *mem_ctx, 260 struct winbindd_response *resp, 291 wbcFreeMemory(i); 292 return wbc_status; 293 } 294 295 static void wbcLogonUserInfoDestructor(void *ptr) 296 { 297 struct wbcLogonUserInfo *i = (struct wbcLogonUserInfo *)ptr; 298 wbcFreeMemory(i->info); 299 wbcFreeMemory(i->blobs); 300 } 301 302 static wbcErr wbc_create_logon_info(struct winbindd_response *resp, 261 303 struct wbcLogonUserInfo **_i) 262 304 { … … 264 306 struct wbcLogonUserInfo *i; 265 307 266 i = talloc_zero(mem_ctx, struct wbcLogonUserInfo); 308 i = (struct wbcLogonUserInfo *)wbcAllocateMemory( 309 1, sizeof(struct wbcLogonUserInfo), 310 wbcLogonUserInfoDestructor); 267 311 BAIL_ON_PTR_ERROR(i, wbc_status); 268 312 269 wbc_status = wbc_create_auth_info( i,resp, &i->info);313 wbc_status = wbc_create_auth_info(resp, &i->info); 270 314 BAIL_ON_WBC_ERROR(wbc_status); 271 315 272 if (resp->data.auth.krb5ccname && 273 strlen(resp->data.auth.krb5ccname)) { 316 if (resp->data.auth.krb5ccname[0] != '\0') { 274 317 wbc_status = wbcAddNamedBlob(&i->num_blobs, 275 318 &i->blobs, … … 281 324 } 282 325 283 if (resp->data.auth.unix_username && 284 strlen(resp->data.auth.unix_username)) { 326 if (resp->data.auth.unix_username[0] != '\0') { 285 327 wbc_status = wbcAddNamedBlob(&i->num_blobs, 286 328 &i->blobs, … … 295 337 i = NULL; 296 338 done: 297 if (!WBC_ERROR_IS_OK(wbc_status) && i) { 298 wbcFreeMemory(i->blobs); 299 } 300 301 talloc_free(i); 302 return wbc_status; 303 } 339 wbcFreeMemory(i); 340 return wbc_status; 341 } 342 304 343 305 344 /* Authenticate with more detailed information */ … … 437 476 request.flags |= WBFLAG_BIG_NTLMV2_BLOB; 438 477 request.extra_len = params->password.response.nt_length; 439 request.extra_data.data = talloc_zero_array(NULL, char, request.extra_len); 478 request.extra_data.data = (char *)malloc( 479 request.extra_len); 440 480 if (request.extra_data.data == NULL) { 441 481 wbc_status = WBC_ERR_NO_MEMORY; … … 471 511 if (response.data.auth.nt_status != 0) { 472 512 if (error) { 473 wbc_status = wbc_create_error_info(NULL, 474 &response, 513 wbc_status = wbc_create_error_info(&response, 475 514 error); 476 515 BAIL_ON_WBC_ERROR(wbc_status); … … 483 522 484 523 if (info) { 485 wbc_status = wbc_create_auth_info(NULL, 486 &response, 487 info); 524 wbc_status = wbc_create_auth_info(&response, info); 488 525 BAIL_ON_WBC_ERROR(wbc_status); 489 526 } 490 527 491 528 done: 492 if (response.extra_data.data) 493 free(response.extra_data.data); 494 495 talloc_free(request.extra_data.data); 529 winbindd_free_response(&response); 530 531 free(request.extra_data.data); 496 532 497 533 return wbc_status; … … 520 556 if (response.data.auth.nt_status != 0) { 521 557 if (error) { 522 wbc_status = wbc_create_error_info(NULL, 523 &response, 558 wbc_status = wbc_create_error_info(&response, 524 559 error); 525 560 BAIL_ON_WBC_ERROR(wbc_status); … … 557 592 if (response.data.auth.nt_status != 0) { 558 593 if (error) { 559 wbc_status = wbc_create_error_info(NULL, 560 &response, 594 wbc_status = wbc_create_error_info(&response, 561 595 error); 562 596 BAIL_ON_WBC_ERROR(wbc_status); … … 601 635 if (response.data.auth.nt_status != 0) { 602 636 if (error) { 603 wbc_status = wbc_create_error_info(NULL, 604 &response, 637 wbc_status = wbc_create_error_info(&response, 605 638 error); 606 639 BAIL_ON_WBC_ERROR(wbc_status); … … 688 721 if (response.data.auth.nt_status != 0) { 689 722 if (error) { 690 wbc_status = wbc_create_error_info(NULL, 691 &response, 723 wbc_status = wbc_create_error_info(&response, 692 724 error); 693 725 BAIL_ON_WBC_ERROR(wbc_status); … … 758 790 if (!params->account_name) { 759 791 wbc_status = WBC_ERR_INVALID_PARAM; 760 BAIL_ON_WBC_ERROR(wbc_status);792 goto done; 761 793 } 762 794 … … 782 814 if (!params->account_name) { 783 815 wbc_status = WBC_ERR_INVALID_PARAM; 784 BAIL_ON_WBC_ERROR(wbc_status);816 goto done; 785 817 } 786 818 … … 806 838 if (!params->account_name || !params->domain_name) { 807 839 wbc_status = WBC_ERR_INVALID_PARAM; 808 BAIL_ON_WBC_ERROR(wbc_status);840 goto done; 809 841 } 810 842 … … 812 844 !params->old_password.response.old_lm_hash_enc_data) { 813 845 wbc_status = WBC_ERR_INVALID_PARAM; 814 BAIL_ON_WBC_ERROR(wbc_status);846 goto done; 815 847 } 816 848 … … 818 850 params->old_password.response.old_lm_hash_enc_data) { 819 851 wbc_status = WBC_ERR_INVALID_PARAM; 820 BAIL_ON_WBC_ERROR(wbc_status);852 goto done; 821 853 } 822 854 … … 824 856 !params->old_password.response.old_nt_hash_enc_data) { 825 857 wbc_status = WBC_ERR_INVALID_PARAM; 826 BAIL_ON_WBC_ERROR(wbc_status);858 goto done; 827 859 } 828 860 … … 830 862 params->old_password.response.old_nt_hash_enc_data) { 831 863 wbc_status = WBC_ERR_INVALID_PARAM; 832 BAIL_ON_WBC_ERROR(wbc_status);864 goto done; 833 865 } 834 866 … … 836 868 !params->new_password.response.lm_data) { 837 869 wbc_status = WBC_ERR_INVALID_PARAM; 838 BAIL_ON_WBC_ERROR(wbc_status);870 goto done; 839 871 } 840 872 … … 842 874 params->new_password.response.lm_data) { 843 875 wbc_status = WBC_ERR_INVALID_PARAM; 844 BAIL_ON_WBC_ERROR(wbc_status);876 goto done; 845 877 } 846 878 … … 848 880 !params->new_password.response.nt_data) { 849 881 wbc_status = WBC_ERR_INVALID_PARAM; 850 BAIL_ON_WBC_ERROR(wbc_status);882 goto done; 851 883 } 852 884 … … 854 886 params->new_password.response.nt_data) { 855 887 wbc_status = WBC_ERR_INVALID_PARAM; 856 BAIL_ON_WBC_ERROR(wbc_status);888 goto done; 857 889 } 858 890 … … 900 932 default: 901 933 wbc_status = WBC_ERR_INVALID_PARAM; 902 BAIL_ON_WBC_ERROR(wbc_status);934 goto done; 903 935 break; 904 936 } … … 917 949 if (response.data.auth.nt_status != 0) { 918 950 if (error) { 919 wbc_status = wbc_create_error_info(NULL, 920 &response, 951 wbc_status = wbc_create_error_info(&response, 921 952 error); 922 953 BAIL_ON_WBC_ERROR(wbc_status); … … 926 957 927 958 if (policy) { 928 wbc_status = wbc_create_password_policy_info(NULL, 929 &response, 959 wbc_status = wbc_create_password_policy_info(&response, 930 960 policy); 931 961 BAIL_ON_WBC_ERROR(wbc_status); … … 975 1005 { 976 1006 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 977 int cmd = 0;978 1007 struct winbindd_request request; 979 1008 struct winbindd_response response; … … 1014 1043 /* Initialize request */ 1015 1044 1016 cmd = WINBINDD_PAM_AUTH;1017 1045 request.flags = WBFLAG_PAM_INFO3_TEXT | 1018 1046 WBFLAG_PAM_USER_SESSION_KEY | … … 1076 1104 } 1077 1105 1078 wbc_status = wbcRequestResponse( cmd,1106 wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH, 1079 1107 &request, 1080 1108 &response); … … 1082 1110 if (response.data.auth.nt_status != 0) { 1083 1111 if (error) { 1084 wbc_status = wbc_create_error_info(NULL, 1085 &response, 1112 wbc_status = wbc_create_error_info(&response, 1086 1113 error); 1087 1114 BAIL_ON_WBC_ERROR(wbc_status); … … 1094 1121 1095 1122 if (info) { 1096 wbc_status = wbc_create_logon_info(NULL, 1097 &response, 1123 wbc_status = wbc_create_logon_info(&response, 1098 1124 info); 1099 1125 BAIL_ON_WBC_ERROR(wbc_status); … … 1101 1127 1102 1128 if (policy) { 1103 wbc_status = wbc_create_password_policy_info(NULL, 1104 &response, 1129 wbc_status = wbc_create_password_policy_info(&response, 1105 1130 policy); 1106 1131 BAIL_ON_WBC_ERROR(wbc_status); … … 1108 1133 1109 1134 done: 1110 if (response.extra_data.data) 1111 free(response.extra_data.data); 1112 1113 return wbc_status; 1135 winbindd_free_response(&response); 1136 1137 return wbc_status; 1138 } 1139 1140 static void wbcCredentialCacheInfoDestructor(void *ptr) 1141 { 1142 struct wbcCredentialCacheInfo *i = 1143 (struct wbcCredentialCacheInfo *)ptr; 1144 wbcFreeMemory(i->blobs); 1114 1145 } 1115 1146 … … 1187 1218 1188 1219 if (request.extra_len != 0) { 1189 request.extra_data.data = talloc_array( 1190 NULL, char, request.extra_len); 1220 request.extra_data.data = (char *)malloc(request.extra_len); 1191 1221 if (request.extra_data.data == NULL) { 1192 1222 status = WBC_ERR_NO_MEMORY; … … 1211 1241 } 1212 1242 1213 result = talloc(NULL, struct wbcCredentialCacheInfo); 1243 result = (struct wbcCredentialCacheInfo *)wbcAllocateMemory( 1244 1, sizeof(struct wbcCredentialCacheInfo), 1245 wbcCredentialCacheInfoDestructor); 1214 1246 if (result == NULL) { 1215 1247 status = WBC_ERR_NO_MEMORY; … … 1217 1249 } 1218 1250 result->num_blobs = 0; 1219 result->blobs = talloc(result, struct wbcNamedBlob); 1220 if (result->blobs == NULL) { 1221 status = WBC_ERR_NO_MEMORY; 1222 goto fail; 1223 } 1251 result->blobs = NULL; 1224 1252 status = wbcAddNamedBlob(&result->num_blobs, &result->blobs, 1225 1253 "auth_blob", 0, … … 1237 1265 } 1238 1266 1239 if (response.extra_data.data)1240 free(response.extra_data.data);1241 1267 *info = result; 1242 re turn WBC_ERR_SUCCESS;1243 1268 result = NULL; 1269 status = WBC_ERR_SUCCESS; 1244 1270 fail: 1245 TALLOC_FREE(request.extra_data.data); 1246 if (response.extra_data.data) 1247 free(response.extra_data.data); 1248 talloc_free(result); 1271 free(request.extra_data.data); 1272 winbindd_free_response(&response); 1273 wbcFreeMemory(result); 1249 1274 return status; 1250 1275 } -
vendor/current/nsswitch/libwbclient/wbc_pwd.c
r414 r740 25 25 #include "replace.h" 26 26 #include "libwbclient.h" 27 #include "../winbind_client.h" 27 28 28 29 /** @brief The maximum number of pwent structs to get from winbindd … … 40 41 **/ 41 42 43 static void wbcPasswdDestructor(void *ptr) 44 { 45 struct passwd *pw = (struct passwd *)ptr; 46 free(pw->pw_name); 47 free(pw->pw_passwd); 48 free(pw->pw_gecos); 49 free(pw->pw_shell); 50 free(pw->pw_dir); 51 } 52 42 53 static struct passwd *copy_passwd_entry(struct winbindd_pw *p) 43 54 { 44 struct passwd *pwd = NULL; 45 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 46 47 pwd = talloc(NULL, struct passwd); 48 BAIL_ON_PTR_ERROR(pwd, wbc_status); 49 50 pwd->pw_name = talloc_strdup(pwd,p->pw_name); 51 BAIL_ON_PTR_ERROR(pwd->pw_name, wbc_status); 52 53 pwd->pw_passwd = talloc_strdup(pwd, p->pw_passwd); 54 BAIL_ON_PTR_ERROR(pwd->pw_passwd, wbc_status); 55 56 pwd->pw_gecos = talloc_strdup(pwd, p->pw_gecos); 57 BAIL_ON_PTR_ERROR(pwd->pw_gecos, wbc_status); 58 59 pwd->pw_shell = talloc_strdup(pwd, p->pw_shell); 60 BAIL_ON_PTR_ERROR(pwd->pw_shell, wbc_status); 61 62 pwd->pw_dir = talloc_strdup(pwd, p->pw_dir); 63 BAIL_ON_PTR_ERROR(pwd->pw_dir, wbc_status); 64 65 pwd->pw_uid = p->pw_uid; 66 pwd->pw_gid = p->pw_gid; 67 68 done: 69 if (!WBC_ERROR_IS_OK(wbc_status)) { 70 talloc_free(pwd); 71 pwd = NULL; 72 } 73 74 return pwd; 55 struct passwd *pw = NULL; 56 57 pw = (struct passwd *)wbcAllocateMemory(1, sizeof(struct passwd), 58 wbcPasswdDestructor); 59 if (pw == NULL) { 60 return NULL; 61 } 62 pw->pw_name = strdup(p->pw_name); 63 if (pw->pw_name == NULL) { 64 goto fail; 65 } 66 pw->pw_passwd = strdup(p->pw_passwd); 67 if (pw->pw_passwd == NULL) { 68 goto fail; 69 } 70 pw->pw_gecos = strdup(p->pw_gecos); 71 if (pw->pw_gecos == NULL) { 72 goto fail; 73 } 74 pw->pw_shell = strdup(p->pw_shell); 75 if (pw->pw_shell == NULL) { 76 goto fail; 77 } 78 pw->pw_dir = strdup(p->pw_dir); 79 if (pw->pw_dir == NULL) { 80 goto fail; 81 } 82 pw->pw_uid = p->pw_uid; 83 pw->pw_gid = p->pw_gid; 84 return pw; 85 86 fail: 87 wbcFreeMemory(pw); 88 return NULL; 75 89 } 76 90 … … 78 92 * 79 93 **/ 94 95 static void wbcGroupDestructor(void *ptr) 96 { 97 struct group *gr = (struct group *)ptr; 98 int i; 99 100 free(gr->gr_name); 101 free(gr->gr_passwd); 102 103 /* if the array was partly created this can be NULL */ 104 if (gr->gr_mem == NULL) { 105 return; 106 } 107 108 for (i=0; gr->gr_mem[i] != NULL; i++) { 109 free(gr->gr_mem[i]); 110 } 111 free(gr->gr_mem); 112 } 80 113 81 114 static struct group *copy_group_entry(struct winbindd_gr *g, 82 115 char *mem_buf) 83 116 { 84 struct group *grp = NULL; 85 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 117 struct group *gr = NULL; 86 118 int i; 87 119 char *mem_p, *mem_q; 88 120 89 grp = talloc(NULL, struct group); 90 BAIL_ON_PTR_ERROR(grp, wbc_status); 91 92 grp->gr_name = talloc_strdup(grp, g->gr_name); 93 BAIL_ON_PTR_ERROR(grp->gr_name, wbc_status); 94 95 grp->gr_passwd = talloc_strdup(grp, g->gr_passwd); 96 BAIL_ON_PTR_ERROR(grp->gr_passwd, wbc_status); 97 98 grp->gr_gid = g->gr_gid; 99 100 grp->gr_mem = talloc_array(grp, char*, g->num_gr_mem+1); 121 gr = (struct group *)wbcAllocateMemory( 122 1, sizeof(struct group), wbcGroupDestructor); 123 if (gr == NULL) { 124 return NULL; 125 } 126 127 gr->gr_name = strdup(g->gr_name); 128 if (gr->gr_name == NULL) { 129 goto fail; 130 } 131 gr->gr_passwd = strdup(g->gr_passwd); 132 if (gr->gr_passwd == NULL) { 133 goto fail; 134 } 135 gr->gr_gid = g->gr_gid; 136 137 gr->gr_mem = (char **)calloc(g->num_gr_mem+1, sizeof(char *)); 138 if (gr->gr_mem == NULL) { 139 goto fail; 140 } 101 141 102 142 mem_p = mem_q = mem_buf; 103 143 for (i=0; i<g->num_gr_mem && mem_p; i++) { 104 if ((mem_q = strchr(mem_p, ',')) != NULL) { 144 mem_q = strchr(mem_p, ','); 145 if (mem_q != NULL) { 105 146 *mem_q = '\0'; 106 147 } 107 148 108 grp->gr_mem[i] = talloc_strdup(grp, mem_p); 109 BAIL_ON_PTR_ERROR(grp->gr_mem[i], wbc_status); 149 gr->gr_mem[i] = strdup(mem_p); 150 if (gr->gr_mem[i] == NULL) { 151 goto fail; 152 } 110 153 111 154 if (mem_q == NULL) { … … 115 158 mem_p = mem_q + 1; 116 159 } 117 grp->gr_mem[i] = NULL; 118 119 wbc_status = WBC_ERR_SUCCESS; 120 121 done: 122 if (!WBC_ERROR_IS_OK(wbc_status)) { 123 talloc_free(grp); 124 grp = NULL; 125 } 126 127 return grp; 160 gr->gr_mem[i] = NULL; 161 162 return gr; 163 164 fail: 165 wbcFreeMemory(gr); 166 return NULL; 128 167 } 129 168 … … 198 237 struct winbindd_request request; 199 238 struct winbindd_response response; 200 char * sid_string = NULL;201 239 202 240 if (!pwd) { … … 205 243 } 206 244 207 wbc_status = wbcSidToString(sid, &sid_string);208 BAIL_ON_WBC_ERROR(wbc_status);209 210 245 /* Initialize request */ 211 246 … … 213 248 ZERO_STRUCT(response); 214 249 215 strncpy(request.data.sid, sid_string, sizeof(request.data.sid));250 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 216 251 217 252 wbc_status = wbcRequestResponse(WINBINDD_GETPWSID, … … 224 259 225 260 done: 226 if (sid_string) {227 wbcFreeMemory(sid_string);228 }229 230 261 return wbc_status; 231 262 } … … 262 293 263 294 done: 264 if (response.extra_data.data) 265 free(response.extra_data.data); 295 winbindd_free_response(&response); 266 296 267 297 return wbc_status; … … 297 327 298 328 done: 299 if (response.extra_data.data) 300 free(response.extra_data.data); 329 winbindd_free_response(&response); 301 330 302 331 return wbc_status; … … 325 354 if (pw_cache_size > 0) { 326 355 pw_cache_idx = pw_cache_size = 0; 327 if (pw_response.extra_data.data) { 328 free(pw_response.extra_data.data); 329 } 356 winbindd_free_response(&pw_response); 330 357 } 331 358 … … 347 374 if (pw_cache_size > 0) { 348 375 pw_cache_idx = pw_cache_size = 0; 349 if (pw_response.extra_data.data) { 350 free(pw_response.extra_data.data); 351 } 376 winbindd_free_response(&pw_response); 352 377 } 353 378 … … 376 401 pw_cache_idx = 0; 377 402 378 if (pw_response.extra_data.data) { 379 free(pw_response.extra_data.data); 380 ZERO_STRUCT(pw_response); 381 } 403 winbindd_free_response(&pw_response); 382 404 383 405 ZERO_STRUCT(request); … … 427 449 if (gr_cache_size > 0) { 428 450 gr_cache_idx = gr_cache_size = 0; 429 if (gr_response.extra_data.data) { 430 free(gr_response.extra_data.data); 431 } 451 winbindd_free_response(&gr_response); 432 452 } 433 453 … … 449 469 if (gr_cache_size > 0) { 450 470 gr_cache_idx = gr_cache_size = 0; 451 if (gr_response.extra_data.data) { 452 free(gr_response.extra_data.data); 453 } 471 winbindd_free_response(&gr_response); 454 472 } 455 473 … … 479 497 gr_cache_idx = 0; 480 498 481 if (gr_response.extra_data.data) { 482 free(gr_response.extra_data.data); 483 ZERO_STRUCT(gr_response); 484 } 499 winbindd_free_response(&gr_response); 485 500 486 501 ZERO_STRUCT(request); … … 528 543 gr_cache_idx = 0; 529 544 530 if (gr_response.extra_data.data) { 531 free(gr_response.extra_data.data); 532 ZERO_STRUCT(gr_response); 533 } 545 winbindd_free_response(&gr_response); 546 ZERO_STRUCT(gr_response); 534 547 535 548 ZERO_STRUCT(request); … … 587 600 BAIL_ON_WBC_ERROR(wbc_status); 588 601 589 groups = talloc_array(NULL, gid_t, response.data.num_entries); 602 groups = (gid_t *)wbcAllocateMemory( 603 response.data.num_entries, sizeof(gid_t), NULL); 590 604 BAIL_ON_PTR_ERROR(groups, wbc_status); 591 605 … … 601 615 602 616 done: 603 if (response.extra_data.data) { 604 free(response.extra_data.data); 605 } 606 if (groups) { 607 talloc_free(groups); 608 } 609 610 return wbc_status; 611 } 617 winbindd_free_response(&response); 618 wbcFreeMemory(groups); 619 return wbc_status; 620 } -
vendor/current/nsswitch/libwbclient/wbc_sid.c
r414 r740 5 5 6 6 Copyright (C) Gerald (Jerry) Carter 2007 7 Copyright (C) Volker Lendecke 2010 7 8 8 9 … … 25 26 #include "replace.h" 26 27 #include "libwbclient.h" 27 28 29 /* Convert a binary SID to a character string */30 wbcErr wbcSidToString(const struct wbcDomainSid *sid, 31 char **sid_string) 32 { 33 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 28 #include "../winbind_client.h" 29 30 /* Convert a sid to a string into a buffer. Return the string 31 * length. If buflen is too small, return the string length that would 32 * result if it was long enough. */ 33 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen) 34 { 34 35 uint32_t id_auth; 35 int i; 36 char *tmp = NULL; 36 int i, ofs; 37 37 38 38 if (!sid) { 39 wbc_status = WBC_ERR_INVALID_SID; 40 BAIL_ON_WBC_ERROR(wbc_status); 41 } 39 strlcpy(buf, "(NULL SID)", buflen); 40 return 10; /* strlen("(NULL SID)") */ 41 } 42 43 /* 44 * BIG NOTE: this function only does SIDS where the identauth is not 45 * >= ^32 in a range of 2^48. 46 */ 42 47 43 48 id_auth = sid->id_auth[5] + … … 46 51 (sid->id_auth[2] << 24); 47 52 48 tmp = talloc_asprintf(NULL, "S-%d-%d", sid->sid_rev_num, id_auth); 49 BAIL_ON_PTR_ERROR(tmp, wbc_status); 50 51 for (i=0; i<sid->num_auths; i++) { 52 char *tmp2; 53 tmp2 = talloc_asprintf_append(tmp, "-%u", sid->sub_auths[i]); 54 BAIL_ON_PTR_ERROR(tmp2, wbc_status); 55 56 tmp = tmp2; 57 } 58 59 *sid_string = tmp; 60 tmp = NULL; 61 62 wbc_status = WBC_ERR_SUCCESS; 63 64 done: 65 talloc_free(tmp); 66 67 return wbc_status; 53 ofs = snprintf(buf, buflen, "S-%u-%lu", 54 (unsigned int)sid->sid_rev_num, (unsigned long)id_auth); 55 56 for (i = 0; i < sid->num_auths; i++) { 57 ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%lu", 58 (unsigned long)sid->sub_auths[i]); 59 } 60 return ofs; 61 } 62 63 /* Convert a binary SID to a character string */ 64 wbcErr wbcSidToString(const struct wbcDomainSid *sid, 65 char **sid_string) 66 { 67 char buf[WBC_SID_STRING_BUFLEN]; 68 char *result; 69 int len; 70 71 if (!sid) { 72 return WBC_ERR_INVALID_SID; 73 } 74 75 len = wbcSidToStringBuf(sid, buf, sizeof(buf)); 76 77 if (len+1 > sizeof(buf)) { 78 return WBC_ERR_INVALID_SID; 79 } 80 81 result = (char *)wbcAllocateMemory(len+1, 1, NULL); 82 if (result == NULL) { 83 return WBC_ERR_NO_MEMORY; 84 } 85 memcpy(result, buf, len+1); 86 87 *sid_string = result; 88 return WBC_ERR_SUCCESS; 68 89 } 69 90 … … 132 153 sid->sub_auths[sid->num_auths++] = x; 133 154 134 if ( (*q!='-') || (*q=='\0'))155 if (*q != '-') { 135 156 break; 157 } 136 158 p = q + 1; 137 159 } … … 150 172 151 173 } 174 152 175 153 176 /* Convert a domain and name to SID */ … … 194 217 } 195 218 219 196 220 /* Convert a SID to a domain and name */ 197 221 wbcErr wbcLookupSid(const struct wbcDomainSid *sid, … … 203 227 struct winbindd_response response; 204 228 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 205 char *sid_string = NULL; 206 char *domain = NULL; 207 char *name = NULL; 208 enum wbcSidType name_type = WBC_SID_NAME_USE_NONE; 229 char *domain, *name; 209 230 210 231 if (!sid) { 211 wbc_status = WBC_ERR_INVALID_PARAM; 212 BAIL_ON_WBC_ERROR(wbc_status); 232 return WBC_ERR_INVALID_PARAM; 213 233 } 214 234 … … 218 238 ZERO_STRUCT(response); 219 239 220 /* dst is already null terminated from the memset above */ 221 222 wbc_status = wbcSidToString(sid, &sid_string); 223 BAIL_ON_WBC_ERROR(wbc_status); 224 225 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 226 wbcFreeMemory(sid_string); 240 wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); 227 241 228 242 /* Make request */ 229 243 230 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, 231 &request, 232 &response); 233 BAIL_ON_WBC_ERROR(wbc_status); 244 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, &request, 245 &response); 246 if (!WBC_ERROR_IS_OK(wbc_status)) { 247 return wbc_status; 248 } 234 249 235 250 /* Copy out result */ 236 251 237 domain = talloc_strdup(NULL, response.data.name.dom_name); 238 BAIL_ON_PTR_ERROR(domain, wbc_status); 239 240 name = talloc_strdup(NULL, response.data.name.name); 241 BAIL_ON_PTR_ERROR(name, wbc_status); 242 243 name_type = (enum wbcSidType)response.data.name.type; 244 252 wbc_status = WBC_ERR_NO_MEMORY; 253 domain = NULL; 254 name = NULL; 255 256 domain = wbcStrDup(response.data.name.dom_name); 257 if (domain == NULL) { 258 goto done; 259 } 260 name = wbcStrDup(response.data.name.name); 261 if (name == NULL) { 262 goto done; 263 } 264 if (pdomain != NULL) { 265 *pdomain = domain; 266 domain = NULL; 267 } 268 if (pname != NULL) { 269 *pname = name; 270 name = NULL; 271 } 272 if (pname_type != NULL) { 273 *pname_type = (enum wbcSidType)response.data.name.type; 274 } 245 275 wbc_status = WBC_ERR_SUCCESS; 246 247 done: 248 if (WBC_ERROR_IS_OK(wbc_status)) { 249 if (pdomain != NULL) { 250 *pdomain = domain; 251 } else { 252 TALLOC_FREE(domain); 253 } 254 if (pname != NULL) { 255 *pname = name; 256 } else { 257 TALLOC_FREE(name); 258 } 259 if (pname_type != NULL) { 260 *pname_type = name_type; 261 } 262 } 263 else { 264 #if 0 265 /* 266 * Found by Coverity: In this particular routine we can't end 267 * up here with a non-NULL name. Further up there are just two 268 * exit paths that lead here, neither of which leave an 269 * allocated name. If you add more paths up there, re-activate 270 * this. 271 */ 272 if (name != NULL) { 273 talloc_free(name); 274 } 275 #endif 276 if (domain != NULL) { 277 talloc_free(domain); 278 } 279 } 280 276 done: 277 wbcFreeMemory(name); 278 wbcFreeMemory(domain); 279 return wbc_status; 280 } 281 282 static void wbcDomainInfosDestructor(void *ptr) 283 { 284 struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; 285 286 while (i->short_name != NULL) { 287 wbcFreeMemory(i->short_name); 288 wbcFreeMemory(i->dns_name); 289 i += 1; 290 } 291 } 292 293 static void wbcTranslatedNamesDestructor(void *ptr) 294 { 295 struct wbcTranslatedName *n = (struct wbcTranslatedName *)ptr; 296 297 while (n->name != NULL) { 298 free(n->name); 299 n += 1; 300 } 301 } 302 303 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids, 304 struct wbcDomainInfo **pdomains, int *pnum_domains, 305 struct wbcTranslatedName **pnames) 306 { 307 struct winbindd_request request; 308 struct winbindd_response response; 309 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 310 int buflen, i, extra_len, num_domains, num_names; 311 char *sidlist, *p, *q, *extra_data; 312 struct wbcDomainInfo *domains = NULL; 313 struct wbcTranslatedName *names = NULL; 314 315 buflen = num_sids * (WBC_SID_STRING_BUFLEN + 1) + 1; 316 317 sidlist = (char *)malloc(buflen); 318 if (sidlist == NULL) { 319 return WBC_ERR_NO_MEMORY; 320 } 321 322 p = sidlist; 323 324 for (i=0; i<num_sids; i++) { 325 int remaining; 326 int len; 327 328 remaining = buflen - (p - sidlist); 329 330 len = wbcSidToStringBuf(&sids[i], p, remaining); 331 if (len > remaining) { 332 free(sidlist); 333 return WBC_ERR_UNKNOWN_FAILURE; 334 } 335 336 p += len; 337 *p++ = '\n'; 338 } 339 *p++ = '\0'; 340 341 ZERO_STRUCT(request); 342 ZERO_STRUCT(response); 343 344 request.extra_data.data = sidlist; 345 request.extra_len = p - sidlist; 346 347 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSIDS, 348 &request, &response); 349 free(sidlist); 350 if (!WBC_ERROR_IS_OK(wbc_status)) { 351 return wbc_status; 352 } 353 354 extra_len = response.length - sizeof(struct winbindd_response); 355 extra_data = (char *)response.extra_data.data; 356 357 if ((extra_len <= 0) || (extra_data[extra_len-1] != '\0')) { 358 goto wbc_err_invalid; 359 } 360 361 p = extra_data; 362 363 num_domains = strtoul(p, &q, 10); 364 if (*q != '\n') { 365 goto wbc_err_invalid; 366 } 367 p = q+1; 368 369 domains = (struct wbcDomainInfo *)wbcAllocateMemory( 370 num_domains+1, sizeof(struct wbcDomainInfo), 371 wbcDomainInfosDestructor); 372 if (domains == NULL) { 373 wbc_status = WBC_ERR_NO_MEMORY; 374 goto fail; 375 } 376 377 for (i=0; i<num_domains; i++) { 378 379 q = strchr(p, ' '); 380 if (q == NULL) { 381 goto wbc_err_invalid; 382 } 383 *q = '\0'; 384 wbc_status = wbcStringToSid(p, &domains[i].sid); 385 if (!WBC_ERROR_IS_OK(wbc_status)) { 386 goto fail; 387 } 388 p = q+1; 389 390 q = strchr(p, '\n'); 391 if (q == NULL) { 392 goto wbc_err_invalid; 393 } 394 *q = '\0'; 395 domains[i].short_name = wbcStrDup(p); 396 if (domains[i].short_name == NULL) { 397 wbc_status = WBC_ERR_NO_MEMORY; 398 goto fail; 399 } 400 p = q+1; 401 } 402 403 num_names = strtoul(p, &q, 10); 404 if (*q != '\n') { 405 goto wbc_err_invalid; 406 } 407 p = q+1; 408 409 if (num_names != num_sids) { 410 goto wbc_err_invalid; 411 } 412 413 names = (struct wbcTranslatedName *)wbcAllocateMemory( 414 num_names+1, sizeof(struct wbcTranslatedName), 415 wbcTranslatedNamesDestructor); 416 if (names == NULL) { 417 wbc_status = WBC_ERR_NO_MEMORY; 418 goto fail; 419 } 420 421 for (i=0; i<num_names; i++) { 422 423 names[i].domain_index = strtoul(p, &q, 10); 424 if (*q != ' ') { 425 goto wbc_err_invalid; 426 } 427 p = q+1; 428 429 names[i].type = strtoul(p, &q, 10); 430 if (*q != ' ') { 431 goto wbc_err_invalid; 432 } 433 p = q+1; 434 435 q = strchr(p, '\n'); 436 if (q == NULL) { 437 goto wbc_err_invalid; 438 } 439 *q = '\0'; 440 names[i].name = wbcStrDup(p); 441 if (names[i].name == NULL) { 442 wbc_status = WBC_ERR_NO_MEMORY; 443 goto fail; 444 } 445 p = q+1; 446 } 447 if (*p != '\0') { 448 goto wbc_err_invalid; 449 } 450 451 *pdomains = domains; 452 *pnames = names; 453 winbindd_free_response(&response); 454 return WBC_ERR_SUCCESS; 455 456 wbc_err_invalid: 457 wbc_status = WBC_ERR_INVALID_RESPONSE; 458 fail: 459 winbindd_free_response(&response); 460 wbcFreeMemory(domains); 461 wbcFreeMemory(names); 281 462 return wbc_status; 282 463 } … … 296 477 struct winbindd_request request; 297 478 struct winbindd_response response; 298 char *sid_string = NULL;299 479 char *domain_name = NULL; 300 480 const char **names = NULL; … … 312 492 } 313 493 314 wbc_status = wbcSidToString(dom_sid, &sid_string); 315 BAIL_ON_WBC_ERROR(wbc_status); 316 317 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 318 wbcFreeMemory(sid_string); 494 wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid)); 319 495 320 496 /* Even if all the Rids were of maximum 32bit values, … … 325 501 ridbuf_size = (sizeof(char)*11) * num_rids + 1; 326 502 327 ridlist = talloc_zero_array(NULL, char,ridbuf_size);503 ridlist = (char *)malloc(ridbuf_size); 328 504 BAIL_ON_PTR_ERROR(ridlist, wbc_status); 329 505 330 506 len = 0; 331 for (i=0; i<num_rids && (len-1)>0; i++) { 332 char ridstr[12]; 333 334 len = strlen(ridlist); 335 p = ridlist + len; 336 337 snprintf( ridstr, sizeof(ridstr)-1, "%u\n", rids[i]); 338 strncat(p, ridstr, ridbuf_size-len-1); 339 } 507 for (i=0; i<num_rids; i++) { 508 len += snprintf(ridlist + len, ridbuf_size - len, "%u\n", 509 rids[i]); 510 } 511 ridlist[len] = '\0'; 512 len += 1; 340 513 341 514 request.extra_data.data = ridlist; 342 request.extra_len = strlen(ridlist)+1;515 request.extra_len = len; 343 516 344 517 wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS, 345 518 &request, 346 519 &response); 347 talloc_free(ridlist);520 free(ridlist); 348 521 BAIL_ON_WBC_ERROR(wbc_status); 349 522 350 domain_name = talloc_strdup(NULL,response.data.domain_name);523 domain_name = wbcStrDup(response.data.domain_name); 351 524 BAIL_ON_PTR_ERROR(domain_name, wbc_status); 352 525 353 names = talloc_array(NULL, const char*,num_rids);526 names = wbcAllocateStringArray(num_rids); 354 527 BAIL_ON_PTR_ERROR(names, wbc_status); 355 528 356 types = talloc_array(NULL, enum wbcSidType, num_rids); 529 types = (enum wbcSidType *)wbcAllocateMemory( 530 num_rids, sizeof(enum wbcSidType), NULL); 357 531 BAIL_ON_PTR_ERROR(types, wbc_status); 358 532 … … 364 538 if (*p == '\0') { 365 539 wbc_status = WBC_ERR_INVALID_RESPONSE; 366 BAIL_ON_WBC_ERROR(wbc_status);540 goto done; 367 541 } 368 542 … … 371 545 if (*q != ' ') { 372 546 wbc_status = WBC_ERR_INVALID_RESPONSE; 373 BAIL_ON_WBC_ERROR(wbc_status);547 goto done; 374 548 } 375 549 … … 378 552 if ((q = strchr(p, '\n')) == NULL) { 379 553 wbc_status = WBC_ERR_INVALID_RESPONSE; 380 BAIL_ON_WBC_ERROR(wbc_status);554 goto done; 381 555 } 382 556 383 557 *q = '\0'; 384 558 385 names[i] = talloc_strdup(names,p);559 names[i] = strdup(p); 386 560 BAIL_ON_PTR_ERROR(names[i], wbc_status); 387 561 … … 391 565 if (*p != '\0') { 392 566 wbc_status = WBC_ERR_INVALID_RESPONSE; 393 BAIL_ON_WBC_ERROR(wbc_status);567 goto done; 394 568 } 395 569 … … 397 571 398 572 done: 399 if (response.extra_data.data) { 400 free(response.extra_data.data); 401 } 573 winbindd_free_response(&response); 402 574 403 575 if (WBC_ERROR_IS_OK(wbc_status)) { … … 407 579 } 408 580 else { 409 if (domain_name) 410 talloc_free(domain_name); 411 if (names) 412 talloc_free(names); 413 if (types) 414 talloc_free(types); 581 wbcFreeMemory(domain_name); 582 wbcFreeMemory(names); 583 wbcFreeMemory(types); 415 584 } 416 585 … … 428 597 struct winbindd_request request; 429 598 struct winbindd_response response; 430 char *sid_string = NULL;431 599 struct wbcDomainSid *sids = NULL; 432 600 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; … … 443 611 } 444 612 445 wbc_status = wbcSidToString(user_sid, &sid_string); 446 BAIL_ON_WBC_ERROR(wbc_status); 447 448 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 449 wbcFreeMemory(sid_string); 613 wbcSidToStringBuf(user_sid, request.data.sid, sizeof(request.data.sid)); 450 614 451 615 if (domain_groups_only) { … … 466 630 } 467 631 468 sids = talloc_array(NULL, struct wbcDomainSid, 469 response.data.num_entries); 632 sids = (struct wbcDomainSid *)wbcAllocateMemory( 633 response.data.num_entries, sizeof(struct wbcDomainSid), 634 NULL); 470 635 BAIL_ON_PTR_ERROR(sids, wbc_status); 471 636 … … 487 652 488 653 done: 489 if (response.extra_data.data) { 490 free(response.extra_data.data); 491 } 654 winbindd_free_response(&response); 492 655 if (sids) { 493 talloc_free(sids);656 wbcFreeMemory(sids); 494 657 } 495 658 … … 519 682 struct winbindd_request request; 520 683 struct winbindd_response response; 521 char *sid_string = NULL;522 ssize_t sid_len;523 684 ssize_t extra_data_len = 0; 524 685 char * extra_data = NULL; … … 535 696 if (!dom_sid) { 536 697 wbc_status = WBC_ERR_INVALID_PARAM; 537 BAIL_ON_WBC_ERROR(wbc_status); 538 } 539 540 wbc_status = wbcSidToString(dom_sid, &sid_string); 541 BAIL_ON_WBC_ERROR(wbc_status); 542 543 strncpy(request.data.sid, sid_string, sizeof(request.data.sid)-1); 544 wbcFreeMemory(sid_string); 545 sid_string = NULL; 546 547 /* Lets assume each sid is around 54 characters 548 * S-1-5-AAAAAAAAAAA-BBBBBBBBBBB-CCCCCCCCCCC-DDDDDDDDDDD\n */ 549 buflen = 54 * num_sids; 550 extra_data = talloc_array(NULL, char, buflen); 698 goto done; 699 } 700 701 wbcSidToStringBuf(dom_sid, request.data.sid, sizeof(request.data.sid)); 702 703 /* Lets assume each sid is around 57 characters 704 * S-1-5-21-AAAAAAAAAAA-BBBBBBBBBBB-CCCCCCCCCCC-DDDDDDDDDDD\n */ 705 buflen = 57 * num_sids; 706 extra_data = (char *)malloc(buflen); 551 707 if (!extra_data) { 552 708 wbc_status = WBC_ERR_NO_MEMORY; 553 BAIL_ON_WBC_ERROR(wbc_status);709 goto done; 554 710 } 555 711 556 712 /* Build the sid list */ 557 713 for (i=0; i<num_sids; i++) { 558 if (sid_string) { 559 wbcFreeMemory(sid_string); 560 sid_string = NULL; 561 } 562 wbc_status = wbcSidToString(&sids[i], &sid_string); 563 BAIL_ON_WBC_ERROR(wbc_status); 564 565 sid_len = strlen(sid_string); 714 char sid_str[WBC_SID_STRING_BUFLEN]; 715 size_t sid_len; 716 717 sid_len = wbcSidToStringBuf(&sids[i], sid_str, sizeof(sid_str)); 566 718 567 719 if (buflen < extra_data_len + sid_len + 2) { 568 720 buflen *= 2; 569 extra_data = talloc_realloc(NULL, extra_data, 570 char, buflen); 721 extra_data = (char *)realloc(extra_data, buflen); 571 722 if (!extra_data) { 572 723 wbc_status = WBC_ERR_NO_MEMORY; … … 575 726 } 576 727 577 strncpy(&extra_data[extra_data_len], sid_str ing,728 strncpy(&extra_data[extra_data_len], sid_str, 578 729 buflen - extra_data_len); 579 730 extra_data_len += sid_len; … … 581 732 extra_data[extra_data_len] = '\0'; 582 733 } 734 extra_data_len += 1; 583 735 584 736 request.extra_data.data = extra_data; … … 593 745 !response.extra_data.data) { 594 746 wbc_status = WBC_ERR_INVALID_RESPONSE; 595 BAIL_ON_WBC_ERROR(wbc_status);596 } 597 598 rids = talloc_array(NULL, uint32_t,599 response.data.num_entries);747 goto done; 748 } 749 750 rids = (uint32_t *)wbcAllocateMemory(response.data.num_entries, 751 sizeof(uint32_t), NULL); 600 752 BAIL_ON_PTR_ERROR(sids, wbc_status); 601 753 … … 619 771 620 772 done: 621 if (sid_string) { 622 wbcFreeMemory(sid_string); 623 } 624 if (extra_data) { 625 talloc_free(extra_data); 626 } 627 if (response.extra_data.data) { 628 free(response.extra_data.data); 629 } 630 if (rids) { 631 talloc_free(rids); 632 } 633 773 free(extra_data); 774 winbindd_free_response(&response); 775 wbcFreeMemory(rids); 634 776 return wbc_status; 635 777 } … … 663 805 BAIL_ON_WBC_ERROR(wbc_status); 664 806 807 users = wbcAllocateStringArray(response.data.num_entries); 808 if (users == NULL) { 809 return WBC_ERR_NO_MEMORY; 810 } 811 665 812 /* Look through extra data */ 666 813 667 814 next = (const char *)response.extra_data.data; 668 815 while (next) { 669 const char **tmp; 670 const char *current = next; 671 char *k = strchr(next, ','); 816 const char *current; 817 char *k; 818 819 if (num_users >= response.data.num_entries) { 820 wbc_status = WBC_ERR_INVALID_RESPONSE; 821 goto done; 822 } 823 824 current = next; 825 k = strchr(next, ','); 826 672 827 if (k) { 673 828 k[0] = '\0'; … … 677 832 } 678 833 679 tmp = talloc_realloc(NULL, users, 680 const char *, 681 num_users+1); 682 BAIL_ON_PTR_ERROR(tmp, wbc_status); 683 users = tmp; 684 685 users[num_users] = talloc_strdup(users, current); 834 users[num_users] = strdup(current); 686 835 BAIL_ON_PTR_ERROR(users[num_users], wbc_status); 687 688 num_users++; 689 } 690 691 *_num_users = num_users; 836 num_users += 1; 837 } 838 if (num_users != response.data.num_entries) { 839 wbc_status = WBC_ERR_INVALID_RESPONSE; 840 goto done; 841 } 842 843 *_num_users = response.data.num_entries; 692 844 *_users = users; 693 845 users = NULL; … … 695 847 696 848 done: 697 if (response.extra_data.data) { 698 free(response.extra_data.data); 699 } 700 if (users) { 701 talloc_free(users); 702 } 849 winbindd_free_response(&response); 850 wbcFreeMemory(users); 703 851 return wbc_status; 704 852 } … … 731 879 BAIL_ON_WBC_ERROR(wbc_status); 732 880 881 groups = wbcAllocateStringArray(response.data.num_entries); 882 if (groups == NULL) { 883 return WBC_ERR_NO_MEMORY; 884 } 885 733 886 /* Look through extra data */ 734 887 735 888 next = (const char *)response.extra_data.data; 736 889 while (next) { 737 const char **tmp; 738 const char *current = next; 739 char *k = strchr(next, ','); 890 const char *current; 891 char *k; 892 893 if (num_groups >= response.data.num_entries) { 894 wbc_status = WBC_ERR_INVALID_RESPONSE; 895 goto done; 896 } 897 898 current = next; 899 k = strchr(next, ','); 900 740 901 if (k) { 741 902 k[0] = '\0'; … … 745 906 } 746 907 747 tmp = talloc_realloc(NULL, groups, 748 const char *, 749 num_groups+1); 750 BAIL_ON_PTR_ERROR(tmp, wbc_status); 751 groups = tmp; 752 753 groups[num_groups] = talloc_strdup(groups, current); 908 groups[num_groups] = strdup(current); 754 909 BAIL_ON_PTR_ERROR(groups[num_groups], wbc_status); 755 756 num_groups++; 757 } 758 759 *_num_groups = num_groups; 910 num_groups += 1; 911 } 912 if (num_groups != response.data.num_entries) { 913 wbc_status = WBC_ERR_INVALID_RESPONSE; 914 goto done; 915 } 916 917 *_num_groups = response.data.num_entries; 760 918 *_groups = groups; 761 919 groups = NULL; … … 763 921 764 922 done: 765 if (response.extra_data.data) { 766 free(response.extra_data.data); 767 } 768 if (groups) { 769 talloc_free(groups); 770 } 923 winbindd_free_response(&response); 924 wbcFreeMemory(groups); 771 925 return wbc_status; 772 926 } … … 797 951 wbcFreeMemory(name); 798 952 799 name = talloc_strdup(NULL, pwd->pw_gecos); 953 name = wbcStrDup(pwd->pw_gecos); 954 wbcFreeMemory(pwd); 800 955 BAIL_ON_PTR_ERROR(name, wbc_status); 801 956 } -
vendor/current/nsswitch/libwbclient/wbc_util.c
r414 r740 2 2 Unix SMB/CIFS implementation. 3 3 4 Winbind client API4 Winbind client asynchronous API, utility functions 5 5 6 6 Copyright (C) Gerald (Jerry) Carter 2007-2008 … … 25 25 #include "replace.h" 26 26 #include "libwbclient.h" 27 28 27 #include "../winbind_client.h" 29 28 30 29 /** @brief Ping winbindd to see if the daemon is running … … 32 31 * @return #wbcErr 33 32 **/ 34 35 33 wbcErr wbcPing(void) 36 34 { … … 45 43 return wbcRequestResponse(WINBINDD_PING, &request, &response); 46 44 } 45 46 static void wbcInterfaceDetailsDestructor(void *ptr) 47 { 48 struct wbcInterfaceDetails *i = (struct wbcInterfaceDetails *)ptr; 49 free(i->winbind_version); 50 free(i->netbios_name); 51 free(i->netbios_domain); 52 free(i->dns_domain); 53 } 54 55 /** 56 * @brief Query useful information about the winbind service 57 * 58 * @param *_details pointer to hold the struct wbcInterfaceDetails 59 * 60 * @return #wbcErr 61 */ 47 62 48 63 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details) … … 59 74 ZERO_STRUCT(response); 60 75 61 info = talloc(NULL, struct wbcInterfaceDetails); 76 info = (struct wbcInterfaceDetails *)wbcAllocateMemory( 77 1, sizeof(struct wbcInterfaceDetails), 78 wbcInterfaceDetailsDestructor); 62 79 BAIL_ON_PTR_ERROR(info, wbc_status); 63 80 … … 71 88 BAIL_ON_WBC_ERROR(wbc_status); 72 89 73 info->winbind_version = talloc_strdup(info, 74 response.data.info.samba_version); 90 info->winbind_version = strdup(response.data.info.samba_version); 75 91 BAIL_ON_PTR_ERROR(info->winbind_version, wbc_status); 76 92 info->winbind_separator = response.data.info.winbind_separator; … … 80 96 BAIL_ON_WBC_ERROR(wbc_status); 81 97 82 info->netbios_name = talloc_strdup(info, 83 response.data.netbios_name); 98 info->netbios_name = strdup(response.data.netbios_name); 84 99 BAIL_ON_PTR_ERROR(info->netbios_name, wbc_status); 85 100 … … 88 103 BAIL_ON_WBC_ERROR(wbc_status); 89 104 90 info->netbios_domain = talloc_strdup(info, 91 response.data.domain_name); 105 info->netbios_domain = strdup(response.data.domain_name); 92 106 BAIL_ON_PTR_ERROR(info->netbios_domain, wbc_status); 93 107 … … 102 116 103 117 if (domain) { 104 info->dns_domain = talloc_strdup(info, 105 domain->dns_name); 118 info->dns_domain = strdup(domain->dns_name); 106 119 wbcFreeMemory(domain); 107 120 BAIL_ON_PTR_ERROR(info->dns_domain, wbc_status); … … 116 129 117 130 done: 118 talloc_free(info); 119 return wbc_status; 120 } 121 122 123 /* Lookup the current status of a trusted domain */ 131 wbcFreeMemory(info); 132 return wbc_status; 133 } 134 135 static void wbcDomainInfoDestructor(void *ptr) 136 { 137 struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; 138 free(i->short_name); 139 free(i->dns_name); 140 } 141 142 /** @brief Lookup the current status of a trusted domain, sync wrapper 143 * 144 * @param domain Domain to query 145 * @param *dinfo Pointer to returned struct wbcDomainInfo 146 * 147 * @return #wbcErr 148 */ 149 124 150 wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo) 125 151 { … … 147 173 BAIL_ON_WBC_ERROR(wbc_status); 148 174 149 info = talloc(NULL, struct wbcDomainInfo); 175 info = (struct wbcDomainInfo *)wbcAllocateMemory( 176 1, sizeof(struct wbcDomainInfo), wbcDomainInfoDestructor); 150 177 BAIL_ON_PTR_ERROR(info, wbc_status); 151 178 152 info->short_name = talloc_strdup(info, 153 response.data.domain_info.name); 179 info->short_name = strdup(response.data.domain_info.name); 154 180 BAIL_ON_PTR_ERROR(info->short_name, wbc_status); 155 181 156 info->dns_name = talloc_strdup(info, 157 response.data.domain_info.alt_name); 182 info->dns_name = strdup(response.data.domain_info.alt_name); 158 183 BAIL_ON_PTR_ERROR(info->dns_name, wbc_status); 159 184 … … 170 195 171 196 *dinfo = info; 197 info = NULL; 172 198 173 199 wbc_status = WBC_ERR_SUCCESS; 174 200 175 201 done: 176 if (!WBC_ERROR_IS_OK(wbc_status)) { 177 talloc_free(info); 178 } 179 180 return wbc_status; 181 } 182 202 wbcFreeMemory(info); 203 return wbc_status; 204 } 205 206 /* Get the list of current DCs */ 207 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs, 208 const char ***dc_names, const char ***dc_ips) 209 { 210 struct winbindd_request request; 211 struct winbindd_response response; 212 const char **names = NULL; 213 const char **ips = NULL; 214 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 215 size_t extra_len; 216 int i; 217 char *p; 218 219 /* Initialise request */ 220 221 ZERO_STRUCT(request); 222 ZERO_STRUCT(response); 223 224 if (domain != NULL) { 225 strncpy(request.domain_name, domain, 226 sizeof(request.domain_name) - 1); 227 } 228 229 wbc_status = wbcRequestResponse(WINBINDD_DC_INFO, 230 &request, &response); 231 BAIL_ON_WBC_ERROR(wbc_status); 232 233 names = wbcAllocateStringArray(response.data.num_entries); 234 BAIL_ON_PTR_ERROR(names, wbc_status); 235 236 ips = wbcAllocateStringArray(response.data.num_entries); 237 BAIL_ON_PTR_ERROR(ips, wbc_status); 238 239 wbc_status = WBC_ERR_INVALID_RESPONSE; 240 241 p = (char *)response.extra_data.data; 242 243 if (response.length < (sizeof(struct winbindd_response)+1)) { 244 goto done; 245 } 246 247 extra_len = response.length - sizeof(struct winbindd_response); 248 249 if (p[extra_len-1] != '\0') { 250 goto done; 251 } 252 253 for (i=0; i<response.data.num_entries; i++) { 254 char *q; 255 256 q = strchr(p, '\n'); 257 if (q == NULL) { 258 goto done; 259 } 260 names[i] = strndup(p, q-p); 261 BAIL_ON_PTR_ERROR(names[i], wbc_status); 262 p = q+1; 263 264 q = strchr(p, '\n'); 265 if (q == NULL) { 266 goto done; 267 } 268 ips[i] = strndup(p, q-p); 269 BAIL_ON_PTR_ERROR(ips[i], wbc_status); 270 p = q+1; 271 } 272 if (p[0] != '\0') { 273 goto done; 274 } 275 276 wbc_status = WBC_ERR_SUCCESS; 277 done: 278 if (response.extra_data.data) 279 free(response.extra_data.data); 280 281 if (WBC_ERROR_IS_OK(wbc_status)) { 282 *num_dcs = response.data.num_entries; 283 *dc_names = names; 284 names = NULL; 285 *dc_ips = ips; 286 ips = NULL; 287 } 288 wbcFreeMemory(names); 289 wbcFreeMemory(ips); 290 return wbc_status; 291 } 183 292 184 293 /* Resolve a NetbiosName via WINS */ … … 205 314 /* Display response */ 206 315 207 ipaddr = talloc_strdup(NULL,response.data.winsresp);316 ipaddr = wbcStrDup(response.data.winsresp); 208 317 BAIL_ON_PTR_ERROR(ipaddr, wbc_status); 209 318 … … 238 347 /* Display response */ 239 348 240 name_str = talloc_strdup(NULL,response.data.winsresp);349 name_str = wbcStrDup(response.data.winsresp); 241 350 BAIL_ON_PTR_ERROR(name_str, wbc_status); 242 351 … … 251 360 */ 252 361 253 static wbcErr process_domain_info_string(TALLOC_CTX *ctx, 254 struct wbcDomainInfo *info, 362 static wbcErr process_domain_info_string(struct wbcDomainInfo *info, 255 363 char *info_string) 256 364 { … … 258 366 char *r = NULL; 259 367 char *s = NULL; 260 261 if (!info || !info_string) {262 wbc_status = WBC_ERR_INVALID_PARAM;263 BAIL_ON_WBC_ERROR(wbc_status);264 }265 266 ZERO_STRUCTP(info);267 368 268 369 r = info_string; … … 276 377 s++; 277 378 278 info->short_name = talloc_strdup(ctx,r);379 info->short_name = strdup(r); 279 380 BAIL_ON_PTR_ERROR(info->short_name, wbc_status); 280 381 … … 289 390 s++; 290 391 291 info->dns_name = talloc_strdup(ctx,r);392 info->dns_name = strdup(r); 292 393 BAIL_ON_PTR_ERROR(info->dns_name, wbc_status); 293 394 … … 382 483 } 383 484 485 static void wbcDomainInfoListDestructor(void *ptr) 486 { 487 struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; 488 489 while (i->short_name != NULL) { 490 free(i->short_name); 491 free(i->dns_name); 492 i += 1; 493 } 494 } 495 384 496 /* Enumerate the domain trusts known by Winbind */ 385 497 wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains) … … 388 500 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 389 501 char *p = NULL; 390 char *q = NULL;391 502 char *extra_data = NULL; 392 int count = 0;393 503 struct wbcDomainInfo *d_list = NULL; 394 504 int i = 0; … … 418 528 } 419 529 420 /* Count number of domains */ 421 422 count = 0; 423 while (p) { 424 count++; 425 426 if ((q = strchr(p, '\n')) != NULL) 427 q++; 428 p = q; 429 } 430 431 d_list = talloc_array(NULL, struct wbcDomainInfo, count); 530 d_list = (struct wbcDomainInfo *)wbcAllocateMemory( 531 response.data.num_entries + 1,sizeof(struct wbcDomainInfo), 532 wbcDomainInfoListDestructor); 432 533 BAIL_ON_PTR_ERROR(d_list, wbc_status); 433 534 … … 439 540 /* Outer loop processes the list of domain information */ 440 541 441 for (i=0; i< count&& p; i++) {542 for (i=0; i<response.data.num_entries && p; i++) { 442 543 char *next = strchr(p, '\n'); 443 544 … … 447 548 } 448 549 449 wbc_status = process_domain_info_string( d_list,&d_list[i], p);550 wbc_status = process_domain_info_string(&d_list[i], p); 450 551 BAIL_ON_WBC_ERROR(wbc_status); 451 552 … … 454 555 455 556 *domains = d_list; 557 d_list = NULL; 456 558 *num_domains = i; 457 559 458 560 done: 459 if (!WBC_ERROR_IS_OK(wbc_status)) { 460 if (d_list) 461 talloc_free(d_list); 462 if (extra_data) 463 free(extra_data); 464 } 465 466 return wbc_status; 561 winbindd_free_response(&response); 562 wbcFreeMemory(d_list); 563 free(extra_data); 564 return wbc_status; 565 } 566 567 static void wbcDomainControllerInfoDestructor(void *ptr) 568 { 569 struct wbcDomainControllerInfo *i = 570 (struct wbcDomainControllerInfo *)ptr; 571 free(i->dc_name); 467 572 } 468 573 … … 492 597 request.flags = flags; 493 598 494 dc = talloc(NULL, struct wbcDomainControllerInfo); 599 dc = (struct wbcDomainControllerInfo *)wbcAllocateMemory( 600 1, sizeof(struct wbcDomainControllerInfo), 601 wbcDomainControllerInfoDestructor); 495 602 BAIL_ON_PTR_ERROR(dc, wbc_status); 496 603 … … 502 609 BAIL_ON_WBC_ERROR(wbc_status); 503 610 504 dc->dc_name = talloc_strdup(dc,response.data.dsgetdcname.dc_unc);611 dc->dc_name = strdup(response.data.dsgetdcname.dc_unc); 505 612 BAIL_ON_PTR_ERROR(dc->dc_name, wbc_status); 506 613 507 614 *dc_info = dc; 615 dc = NULL; 508 616 509 617 done: 510 if (!WBC_ERROR_IS_OK(wbc_status)) { 511 talloc_free(dc); 512 } 513 514 return wbc_status; 515 } 516 517 static wbcErr wbc_create_domain_controller_info_ex(TALLOC_CTX *mem_ctx, 518 const struct winbindd_response *resp, 618 wbcFreeMemory(dc); 619 return wbc_status; 620 } 621 622 static void wbcDomainControllerInfoExDestructor(void *ptr) 623 { 624 struct wbcDomainControllerInfoEx *i = 625 (struct wbcDomainControllerInfoEx *)ptr; 626 free((char *)(i->dc_unc)); 627 free((char *)(i->dc_address)); 628 free((char *)(i->domain_guid)); 629 free((char *)(i->domain_name)); 630 free((char *)(i->forest_name)); 631 free((char *)(i->dc_site_name)); 632 free((char *)(i->client_site_name)); 633 } 634 635 static wbcErr wbc_create_domain_controller_info_ex(const struct winbindd_response *resp, 519 636 struct wbcDomainControllerInfoEx **_i) 520 637 { … … 523 640 struct wbcGuid guid; 524 641 525 i = talloc(mem_ctx, struct wbcDomainControllerInfoEx); 642 i = (struct wbcDomainControllerInfoEx *)wbcAllocateMemory( 643 1, sizeof(struct wbcDomainControllerInfoEx), 644 wbcDomainControllerInfoExDestructor); 526 645 BAIL_ON_PTR_ERROR(i, wbc_status); 527 646 528 i->dc_unc = talloc_strdup(i,resp->data.dsgetdcname.dc_unc);647 i->dc_unc = strdup(resp->data.dsgetdcname.dc_unc); 529 648 BAIL_ON_PTR_ERROR(i->dc_unc, wbc_status); 530 649 531 i->dc_address = talloc_strdup(i,resp->data.dsgetdcname.dc_address);650 i->dc_address = strdup(resp->data.dsgetdcname.dc_address); 532 651 BAIL_ON_PTR_ERROR(i->dc_address, wbc_status); 533 652 … … 536 655 wbc_status = wbcStringToGuid(resp->data.dsgetdcname.domain_guid, &guid); 537 656 if (WBC_ERROR_IS_OK(wbc_status)) { 538 i->domain_guid = talloc(i, struct wbcGuid); 657 i->domain_guid = (struct wbcGuid *)malloc( 658 sizeof(struct wbcGuid)); 539 659 BAIL_ON_PTR_ERROR(i->domain_guid, wbc_status); 540 660 541 661 *i->domain_guid = guid; 542 } else { 543 i->domain_guid = NULL; 544 } 545 546 i->domain_name = talloc_strdup(i, resp->data.dsgetdcname.domain_name); 662 } 663 664 i->domain_name = strdup(resp->data.dsgetdcname.domain_name); 547 665 BAIL_ON_PTR_ERROR(i->domain_name, wbc_status); 548 666 549 667 if (resp->data.dsgetdcname.forest_name[0] != '\0') { 550 i->forest_name = talloc_strdup(i, 551 resp->data.dsgetdcname.forest_name); 668 i->forest_name = strdup(resp->data.dsgetdcname.forest_name); 552 669 BAIL_ON_PTR_ERROR(i->forest_name, wbc_status); 553 } else {554 i->forest_name = NULL;555 670 } 556 671 … … 558 673 559 674 if (resp->data.dsgetdcname.dc_site_name[0] != '\0') { 560 i->dc_site_name = talloc_strdup(i, 561 resp->data.dsgetdcname.dc_site_name); 675 i->dc_site_name = strdup(resp->data.dsgetdcname.dc_site_name); 562 676 BAIL_ON_PTR_ERROR(i->dc_site_name, wbc_status); 563 } else {564 i->dc_site_name = NULL;565 677 } 566 678 567 679 if (resp->data.dsgetdcname.client_site_name[0] != '\0') { 568 i->client_site_name = talloc_strdup(i,680 i->client_site_name = strdup( 569 681 resp->data.dsgetdcname.client_site_name); 570 682 BAIL_ON_PTR_ERROR(i->client_site_name, wbc_status); 571 } else {572 i->client_site_name = NULL;573 683 } 574 684 … … 577 687 578 688 done: 579 talloc_free(i); 689 if (i != NULL) { 690 wbcFreeMemory(i); 691 } 580 692 return wbc_status; 581 693 } … … 632 744 633 745 if (dc_info) { 634 wbc_status = wbc_create_domain_controller_info_ex(NULL, 635 &response, 746 wbc_status = wbc_create_domain_controller_info_ex(&response, 636 747 dc_info); 637 748 BAIL_ON_WBC_ERROR(wbc_status); … … 643 754 } 644 755 756 static void wbcNamedBlobDestructor(void *ptr) 757 { 758 struct wbcNamedBlob *b = (struct wbcNamedBlob *)ptr; 759 760 while (b->name != NULL) { 761 free((char *)(b->name)); 762 free(b->blob.data); 763 b += 1; 764 } 765 } 766 645 767 /* Initialize a named blob and add to list of blobs */ 646 768 wbcErr wbcAddNamedBlob(size_t *num_blobs, 647 struct wbcNamedBlob ** blobs,769 struct wbcNamedBlob **pblobs, 648 770 const char *name, 649 771 uint32_t flags, … … 652 774 { 653 775 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 654 struct wbcNamedBlob blob; 655 656 *blobs = talloc_realloc(NULL, *blobs, struct wbcNamedBlob, 657 *(num_blobs)+1); 658 BAIL_ON_PTR_ERROR(*blobs, wbc_status); 659 660 blob.name = talloc_strdup(*blobs, name); 661 BAIL_ON_PTR_ERROR(blob.name, wbc_status); 662 blob.flags = flags; 663 blob.blob.length = length; 664 blob.blob.data = (uint8_t *)talloc_memdup(*blobs, data, length); 665 BAIL_ON_PTR_ERROR(blob.blob.data, wbc_status); 666 667 (*(blobs))[*num_blobs] = blob; 668 *(num_blobs) += 1; 776 struct wbcNamedBlob *blobs, *blob; 777 778 if (name == NULL) { 779 return WBC_ERR_INVALID_PARAM; 780 } 781 782 /* 783 * Overallocate the b->name==NULL terminator for 784 * wbcNamedBlobDestructor 785 */ 786 blobs = (struct wbcNamedBlob *)wbcAllocateMemory( 787 *num_blobs + 2, sizeof(struct wbcNamedBlob), 788 wbcNamedBlobDestructor); 789 790 if (blobs == NULL) { 791 return WBC_ERR_NO_MEMORY; 792 } 793 794 if (*pblobs != NULL) { 795 struct wbcNamedBlob *old = *pblobs; 796 memcpy(blobs, old, sizeof(struct wbcNamedBlob) * (*num_blobs)); 797 if (*num_blobs != 0) { 798 /* end indicator for wbcNamedBlobDestructor */ 799 old[0].name = NULL; 800 } 801 wbcFreeMemory(old); 802 } 803 *pblobs = blobs; 804 805 blob = &blobs[*num_blobs]; 806 807 blob->name = strdup(name); 808 BAIL_ON_PTR_ERROR(blob->name, wbc_status); 809 blob->flags = flags; 810 811 blob->blob.length = length; 812 blob->blob.data = (uint8_t *)malloc(length); 813 BAIL_ON_PTR_ERROR(blob->blob.data, wbc_status); 814 memcpy(blob->blob.data, data, length); 815 816 *num_blobs += 1; 817 *pblobs = blobs; 818 blobs = NULL; 669 819 670 820 wbc_status = WBC_ERR_SUCCESS; 671 821 done: 672 if (!WBC_ERROR_IS_OK(wbc_status) && blobs) { 673 wbcFreeMemory(*blobs); 674 } 675 return wbc_status; 676 } 822 wbcFreeMemory(blobs); 823 return wbc_status; 824 } -
vendor/current/nsswitch/libwbclient/wbclient.c
r478 r740 24 24 25 25 #include "replace.h" 26 #include "talloc.h"27 #include "tevent.h"28 26 #include "libwbclient.h" 29 27 … … 37 35 struct winbindd_response *response); 38 36 39 /** @brief Wrapper around Winbind's send/receive API call 40 * 41 * @param cmd Winbind command operation to perform 42 * @param request Send structure 43 * @param response Receive structure 44 * 45 * @return #wbcErr 46 **/ 47 48 /********************************************************************** 37 /* 49 38 result == NSS_STATUS_UNAVAIL: winbind not around 50 39 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing … … 57 46 58 47 --Volker 59 * *********************************************************************/48 */ 60 49 61 50 static wbcErr wbcRequestResponseInt( … … 92 81 } 93 82 83 /** 84 * @brief Wrapper around Winbind's send/receive API call 85 * 86 * @param cmd Winbind command operation to perform 87 * @param request Send structure 88 * @param response Receive structure 89 * 90 * @return #wbcErr 91 */ 94 92 wbcErr wbcRequestResponse(int cmd, 95 93 struct winbindd_request *request, … … 150 148 } 151 149 150 #define WBC_MAGIC (0x7a2b0e1e) 151 #define WBC_MAGIC_FREE (0x875634fe) 152 153 struct wbcMemPrefix { 154 uint32_t magic; 155 void (*destructor)(void *ptr); 156 }; 157 158 static size_t wbcPrefixLen(void) 159 { 160 size_t result = sizeof(struct wbcMemPrefix); 161 return (result + 15) & ~15; 162 } 163 164 static struct wbcMemPrefix *wbcMemToPrefix(void *ptr) 165 { 166 return (struct wbcMemPrefix *)(((char *)ptr) - wbcPrefixLen()); 167 } 168 169 void *wbcAllocateMemory(size_t nelem, size_t elsize, 170 void (*destructor)(void *ptr)) 171 { 172 struct wbcMemPrefix *result; 173 174 if (nelem >= (2<<24)/elsize) { 175 /* basic protection against integer wrap */ 176 return NULL; 177 } 178 179 result = (struct wbcMemPrefix *)calloc( 180 1, nelem*elsize + wbcPrefixLen()); 181 if (result == NULL) { 182 return NULL; 183 } 184 result->magic = WBC_MAGIC; 185 result->destructor = destructor; 186 return ((char *)result) + wbcPrefixLen(); 187 } 188 152 189 /* Free library allocated memory */ 153 190 void wbcFreeMemory(void *p) 154 191 { 155 if (p) 156 talloc_free(p); 157 192 struct wbcMemPrefix *wbcMem; 193 194 if (p == NULL) { 195 return; 196 } 197 wbcMem = wbcMemToPrefix(p); 198 if (wbcMem->magic != WBC_MAGIC) { 199 return; 200 } 201 202 /* paranoid check to ensure we don't double free */ 203 wbcMem->magic = WBC_MAGIC_FREE; 204 205 if (wbcMem->destructor != NULL) { 206 wbcMem->destructor(p); 207 } 208 free(wbcMem); 158 209 return; 159 210 } 160 211 212 char *wbcStrDup(const char *str) 213 { 214 char *result; 215 size_t len; 216 217 len = strlen(str); 218 result = (char *)wbcAllocateMemory(len+1, sizeof(char), NULL); 219 if (result == NULL) { 220 return NULL; 221 } 222 memcpy(result, str, len+1); 223 return result; 224 } 225 226 static void wbcStringArrayDestructor(void *ptr) 227 { 228 char **p = (char **)ptr; 229 while (*p != NULL) { 230 free(*p); 231 p += 1; 232 } 233 } 234 235 const char **wbcAllocateStringArray(int num_strings) 236 { 237 return (const char **)wbcAllocateMemory( 238 num_strings + 1, sizeof(const char *), 239 wbcStringArrayDestructor); 240 } 241 161 242 wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details) 162 243 { 163 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;164 244 struct wbcLibraryDetails *info; 165 245 166 info = talloc(NULL, struct wbcLibraryDetails); 167 BAIL_ON_PTR_ERROR(info, wbc_status); 246 info = (struct wbcLibraryDetails *)wbcAllocateMemory( 247 1, sizeof(struct wbcLibraryDetails), NULL); 248 249 if (info == NULL) { 250 return WBC_ERR_NO_MEMORY; 251 } 168 252 169 253 info->major_version = WBCLIENT_MAJOR_VERSION; 170 254 info->minor_version = WBCLIENT_MINOR_VERSION; 171 info->vendor_version = talloc_strdup(info, 172 WBCLIENT_VENDOR_VERSION); 173 BAIL_ON_PTR_ERROR(info->vendor_version, wbc_status); 255 info->vendor_version = WBCLIENT_VENDOR_VERSION; 174 256 175 257 *_details = info; 176 info = NULL; 177 178 wbc_status = WBC_ERR_SUCCESS; 179 180 done: 181 talloc_free(info); 182 return wbc_status; 183 } 258 return WBC_ERR_SUCCESS; 259 } -
vendor/current/nsswitch/libwbclient/wbclient.h
r414 r740 66 66 * 0.4: Added wbcSidTypeString() 67 67 * 0.5: Added wbcChangeTrustCredentials() 68 * 0.6: Made struct wbcInterfaceDetails char* members non-const 69 * 0.7: Added wbcSidToStringBuf() 70 * 0.8: Added wbcSidsToUnixIds() and wbcLookupSids() 68 71 **/ 69 72 #define WBCLIENT_MAJOR_VERSION 0 70 #define WBCLIENT_MINOR_VERSION 573 #define WBCLIENT_MINOR_VERSION 8 71 74 #define WBCLIENT_VENDOR_VERSION "Samba libwbclient" 72 75 struct wbcLibraryDetails { … … 82 85 struct wbcInterfaceDetails { 83 86 uint32_t interface_version; 84 c onst char *winbind_version;87 char *winbind_version; 85 88 char winbind_separator; 86 c onst char *netbios_name;87 c onst char *netbios_domain;88 c onst char *dns_domain;89 char *netbios_name; 90 char *netbios_domain; 91 char *dns_domain; 89 92 }; 90 93 … … 191 194 #define WBC_DOMINFO_TRUSTTYPE_IN_FOREST 0x00000002 192 195 #define WBC_DOMINFO_TRUSTTYPE_EXTERNAL 0x00000003 193 194 196 195 197 /** … … 430 432 431 433 enum wbcPasswordChangeRejectReason { 432 WBC_PWD_CHANGE_REJECT_OTHER=0, 433 WBC_PWD_CHANGE_REJECT_TOO_SHORT=1, 434 WBC_PWD_CHANGE_REJECT_IN_HISTORY=2, 435 WBC_PWD_CHANGE_REJECT_COMPLEXITY=5 436 }; 434 WBC_PWD_CHANGE_NO_ERROR=0, 435 WBC_PWD_CHANGE_PASSWORD_TOO_SHORT=1, 436 WBC_PWD_CHANGE_PWD_IN_HISTORY=2, 437 WBC_PWD_CHANGE_USERNAME_IN_PASSWORD=3, 438 WBC_PWD_CHANGE_FULLNAME_IN_PASSWORD=4, 439 WBC_PWD_CHANGE_NOT_COMPLEX=5, 440 WBC_PWD_CHANGE_MACHINE_NOT_DEFAULT=6, 441 WBC_PWD_CHANGE_FAILED_BY_FILTER=7, 442 WBC_PWD_CHANGE_PASSWORD_TOO_LONG=8 443 }; 444 445 /* Note: this defines exist for compatibility reasons with existing code */ 446 #define WBC_PWD_CHANGE_REJECT_OTHER WBC_PWD_CHANGE_NO_ERROR 447 #define WBC_PWD_CHANGE_REJECT_TOO_SHORT WBC_PWD_CHANGE_PASSWORD_TOO_SHORT 448 #define WBC_PWD_CHANGE_REJECT_IN_HISTORY WBC_PWD_CHANGE_PWD_IN_HISTORY 449 #define WBC_PWD_CHANGE_REJECT_COMPLEXITY WBC_PWD_CHANGE_NOT_COMPLEX 437 450 438 451 /** … … 519 532 const char* wbcSidTypeString(enum wbcSidType type); 520 533 534 #define WBC_SID_STRING_BUFLEN (15*11+25) 535 536 /* 537 * @brief Print a sid into a buffer 538 * 539 * @param sid Binary Security Identifier 540 * @param buf Target buffer 541 * @param buflen Target buffer length 542 * 543 * @return Resulting string length. 544 */ 545 int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen); 546 521 547 /** 522 548 * @brief Convert a binary SID to a character string … … 611 637 char **name, 612 638 enum wbcSidType *name_type); 639 640 struct wbcTranslatedName { 641 enum wbcSidType type; 642 char *name; 643 int domain_index; 644 }; 645 646 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids, 647 struct wbcDomainInfo **domains, int *num_domains, 648 struct wbcTranslatedName **names); 613 649 614 650 /** … … 758 794 struct wbcDomainSid *sid); 759 795 796 enum wbcIdType { 797 WBC_ID_TYPE_NOT_SPECIFIED, 798 WBC_ID_TYPE_UID, 799 WBC_ID_TYPE_GID 800 }; 801 802 union wbcUnixIdContainer { 803 uid_t uid; 804 gid_t gid; 805 }; 806 807 struct wbcUnixId { 808 enum wbcIdType type; 809 union wbcUnixIdContainer id; 810 }; 811 812 /** 813 * @brief Convert a list of sids to unix ids 814 * 815 * @param sids Pointer to an array of SIDs to convert 816 * @param num_sids Number of SIDs 817 * @param ids Preallocated output array for translated IDs 818 * 819 * @return #wbcErr 820 * 821 **/ 822 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids, 823 struct wbcUnixId *ids); 824 760 825 /** 761 826 * @brief Obtain a new uid from Winbind … … 783 848 * 784 849 * @return #wbcErr 850 * 851 * @deprecated This method is not impemented any more and should 852 * be removed in the next major version change. 785 853 **/ 786 854 wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid); … … 793 861 * 794 862 * @return #wbcErr 863 * 864 * @deprecated This method is not impemented any more and should 865 * be removed in the next major version change. 795 866 **/ 796 867 wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid); … … 803 874 * 804 875 * @return #wbcErr 876 * 877 * @deprecated This method is not impemented any more and should 878 * be removed in the next major version change. 805 879 **/ 806 880 wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid); … … 813 887 * 814 888 * @return #wbcErr 889 * 890 * @deprecated This method is not impemented any more and should 891 * be removed in the next major version change. 815 892 **/ 816 893 wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid); … … 822 899 * 823 900 * @return #wbcErr 901 * 902 * @deprecated This method is not impemented any more and should 903 * be removed in the next major version change. 824 904 **/ 825 905 wbcErr wbcSetUidHwm(uid_t uid_hwm); … … 831 911 * 832 912 * @return #wbcErr 913 * 914 * @deprecated This method is not impemented any more and should 915 * be removed in the next major version change. 833 916 **/ 834 917 wbcErr wbcSetGidHwm(gid_t gid_hwm); … … 971 1054 * @brief Lookup the current status of a trusted domain 972 1055 * 973 * @param domain Domain to query 974 * @param *info Pointer to returned domain_info struct 1056 * @param domain The domain to query 1057 * 1058 * @param dinfo A pointer to store the returned domain_info struct. 975 1059 * 976 1060 * @return #wbcErr 977 1061 **/ 978 1062 wbcErr wbcDomainInfo(const char *domain, 979 struct wbcDomainInfo **info); 1063 struct wbcDomainInfo **dinfo); 1064 1065 /** 1066 * @brief Lookup the currently contacted DCs 1067 * 1068 * @param domain The domain to query 1069 * 1070 * @param num_dcs Number of DCs currently known 1071 * @param dc_names Names of the currently known DCs 1072 * @param dc_ips IP addresses of the currently known DCs 1073 * 1074 * @return #wbcErr 1075 **/ 1076 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs, 1077 const char ***dc_names, const char ***dc_ips); 980 1078 981 1079 /** -
vendor/current/nsswitch/libwbclient/wbclient_internal.h
r478 r740 33 33 struct winbindd_response *response); 34 34 35 void *wbcAllocateMemory(size_t nelem, size_t elsize, 36 void (*destructor)(void *ptr)); 37 38 char *wbcStrDup(const char *str); 39 const char **wbcAllocateStringArray(int num_strings); 40 35 41 #endif /* _WBCLIENT_INTERNAL_H */ -
vendor/current/nsswitch/nsstest.c
r414 r740 3 3 nss tester for winbindd 4 4 Copyright (C) Andrew Tridgell 2001 5 Copyright (C) Tim Potter 2003 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 18 19 */ 19 20 20 #include "includes.h" 21 21 #include "replace.h" 22 22 #include "nsswitch/nsstest.h" 23 23 … … 30 30 static void *find_fn(const char *name) 31 31 { 32 char s[1024];32 char *s; 33 33 static void *h; 34 34 void *res; 35 35 36 snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); 36 if (asprintf(&s, "_nss_%s_%s", nss_name, name) < 0) { 37 exit(1); 38 } 37 39 38 40 if (!h) { … … 46 48 if (!res) { 47 49 printf("Can't find function %s\n", s); 48 return NULL; 49 } 50 total_errors++; 51 free(s); 52 return NULL; 53 } 54 free(s); 50 55 return res; 51 56 } … … 62 67 { 63 68 NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, 64 size_t , int *) = find_fn("getpwent_r"); 69 size_t , int *) = 70 (NSS_STATUS (*)(struct passwd *, char *, 71 size_t, int *))find_fn("getpwent_r"); 65 72 static struct passwd pwd; 66 73 static char buf[1000]; 67 74 NSS_STATUS status; 68 75 76 if (!_nss_getpwent_r) 77 return NULL; 78 69 79 status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); 70 80 if (status == NSS_STATUS_NOTFOUND) { … … 81 91 { 82 92 NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, 83 size_t , int *) = find_fn("getpwnam_r"); 93 size_t , int *) = 94 (NSS_STATUS (*)(const char *, struct passwd *, char *, 95 size_t, int *))find_fn("getpwnam_r"); 84 96 static struct passwd pwd; 85 97 static char buf[1000]; 86 98 NSS_STATUS status; 87 99 100 if (!_nss_getpwnam_r) 101 return NULL; 102 88 103 status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); 89 104 if (status == NSS_STATUS_NOTFOUND) { … … 100 115 { 101 116 NSS_STATUS (*_nss_getpwuid_r)(uid_t , struct passwd *, char *, 102 size_t , int *) = find_fn("getpwuid_r"); 117 size_t , int *) = 118 (NSS_STATUS (*)(uid_t, struct passwd *, char *, 119 size_t, int *))find_fn("getpwuid_r"); 103 120 static struct passwd pwd; 104 121 static char buf[1000]; 105 122 NSS_STATUS status; 106 123 124 if (!_nss_getpwuid_r) 125 return NULL; 126 107 127 status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno); 108 128 if (status == NSS_STATUS_NOTFOUND) { … … 118 138 static void nss_setpwent(void) 119 139 { 120 NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); 121 NSS_STATUS status; 140 NSS_STATUS (*_nss_setpwent)(void) = 141 (NSS_STATUS(*)(void))find_fn("setpwent"); 142 NSS_STATUS status; 143 144 if (!_nss_setpwent) 145 return; 146 122 147 status = _nss_setpwent(); 123 148 if (status != NSS_STATUS_SUCCESS) { … … 128 153 static void nss_endpwent(void) 129 154 { 130 NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent"); 131 NSS_STATUS status; 155 NSS_STATUS (*_nss_endpwent)(void) = 156 (NSS_STATUS (*)(void))find_fn("endpwent"); 157 NSS_STATUS status; 158 159 if (!_nss_endpwent) 160 return; 161 132 162 status = _nss_endpwent(); 133 163 if (status != NSS_STATUS_SUCCESS) { … … 140 170 { 141 171 NSS_STATUS (*_nss_getgrent_r)(struct group *, char *, 142 size_t , int *) = find_fn("getgrent_r"); 172 size_t , int *) = 173 (NSS_STATUS (*)(struct group *, char *, 174 size_t, int *))find_fn("getgrent_r"); 143 175 static struct group grp; 144 176 static char *buf; … … 146 178 NSS_STATUS status; 147 179 148 if (!buf) buf = malloc_array_p(char, buflen); 180 if (!_nss_getgrent_r) 181 return NULL; 182 183 if (!buf) 184 buf = (char *)malloc(buflen); 149 185 150 186 again: … … 152 188 if (status == NSS_STATUS_TRYAGAIN) { 153 189 buflen *= 2; 154 buf = realloc_p(buf, char, buflen); 190 buf = (char *)realloc(buf, buflen); 191 if (!buf) { 192 return NULL; 193 } 155 194 goto again; 156 195 } 157 196 if (status == NSS_STATUS_NOTFOUND) { 197 free(buf); 158 198 return NULL; 159 199 } 160 200 if (status != NSS_STATUS_SUCCESS) { 161 201 report_nss_error("getgrent", status); 202 free(buf); 162 203 return NULL; 163 204 } … … 168 209 { 169 210 NSS_STATUS (*_nss_getgrnam_r)(const char *, struct group *, char *, 170 size_t , int *) = find_fn("getgrnam_r"); 211 size_t , int *) = 212 (NSS_STATUS (*)(const char *, struct group *, char *, 213 size_t, int *))find_fn("getgrnam_r"); 171 214 static struct group grp; 172 215 static char *buf; … … 174 217 NSS_STATUS status; 175 218 176 if (!buf) buf = malloc_array_p(char, buflen); 219 if (!_nss_getgrnam_r) 220 return NULL; 221 222 if (!buf) 223 buf = (char *)malloc(buflen); 177 224 again: 178 225 status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); 179 226 if (status == NSS_STATUS_TRYAGAIN) { 180 227 buflen *= 2; 181 buf = realloc_p(buf, char, buflen); 228 buf = (char *)realloc(buf, buflen); 229 if (!buf) { 230 return NULL; 231 } 182 232 goto again; 183 233 } 184 234 if (status == NSS_STATUS_NOTFOUND) { 235 free(buf); 185 236 return NULL; 186 237 } 187 238 if (status != NSS_STATUS_SUCCESS) { 188 239 report_nss_error("getgrnam", status); 240 free(buf); 189 241 return NULL; 190 242 } … … 195 247 { 196 248 NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, 197 size_t , int *) = find_fn("getgrgid_r"); 249 size_t , int *) = 250 (NSS_STATUS (*)(gid_t, struct group *, char *, 251 size_t, int *))find_fn("getgrgid_r"); 198 252 static struct group grp; 199 253 static char *buf; … … 201 255 NSS_STATUS status; 202 256 203 if (!buf) buf = malloc_array_p(char, buflen); 257 if (!_nss_getgrgid_r) 258 return NULL; 259 260 if (!buf) 261 buf = (char *)malloc(buflen); 262 204 263 again: 205 264 status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); 206 265 if (status == NSS_STATUS_TRYAGAIN) { 207 266 buflen *= 2; 208 buf = realloc_p(buf, char, buflen); 267 buf = (char *)realloc(buf, buflen); 268 if (!buf) { 269 return NULL; 270 } 209 271 goto again; 210 272 } 211 273 if (status == NSS_STATUS_NOTFOUND) { 274 free(buf); 212 275 return NULL; 213 276 } 214 277 if (status != NSS_STATUS_SUCCESS) { 215 278 report_nss_error("getgrgid", status); 279 free(buf); 216 280 return NULL; 217 281 } … … 221 285 static void nss_setgrent(void) 222 286 { 223 NSS_STATUS (*_nss_setgrent)(void) = find_fn("setgrent"); 224 NSS_STATUS status; 287 NSS_STATUS (*_nss_setgrent)(void) = 288 (NSS_STATUS (*)(void))find_fn("setgrent"); 289 NSS_STATUS status; 290 291 if (!_nss_setgrent) 292 return; 293 225 294 status = _nss_setgrent(); 226 295 if (status != NSS_STATUS_SUCCESS) { … … 231 300 static void nss_endgrent(void) 232 301 { 233 NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); 234 NSS_STATUS status; 302 NSS_STATUS (*_nss_endgrent)(void) = 303 (NSS_STATUS (*)(void))find_fn("endgrent"); 304 NSS_STATUS status; 305 306 if (!_nss_endgrent) 307 return; 308 235 309 status = _nss_endgrent(); 236 310 if (status != NSS_STATUS_SUCCESS) { … … 243 317 NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, 244 318 long int *, gid_t **, long int , int *) = 245 find_fn("initgroups_dyn"); 246 NSS_STATUS status; 247 248 if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; 319 (NSS_STATUS (*)(char *, gid_t, long int *, 320 long int *, gid_t **, 321 long int, int *))find_fn("initgroups_dyn"); 322 NSS_STATUS status; 323 324 if (!_nss_initgroups) 325 return NSS_STATUS_UNAVAIL; 249 326 250 327 status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); … … 257 334 static void print_passwd(struct passwd *pwd) 258 335 { 259 printf("%s:%s:% d:%d:%s:%s:%s\n",336 printf("%s:%s:%lu:%lu:%s:%s:%s\n", 260 337 pwd->pw_name, 261 338 pwd->pw_passwd, 262 pwd->pw_uid,263 pwd->pw_gid,339 (unsigned long)pwd->pw_uid, 340 (unsigned long)pwd->pw_gid, 264 341 pwd->pw_gecos, 265 342 pwd->pw_dir, … … 270 347 { 271 348 int i; 272 printf("%s:%s:% d:",349 printf("%s:%s:%lu:", 273 350 grp->gr_name, 274 351 grp->gr_passwd, 275 grp->gr_gid);352 (unsigned long)grp->gr_gid); 276 353 277 354 if (!grp->gr_mem[0]) { … … 281 358 282 359 for (i=0; grp->gr_mem[i+1]; i++) { 283 printf("%s, 360 printf("%s,", grp->gr_mem[i]); 284 361 } 285 362 printf("%s\n", grp->gr_mem[i]); … … 294 371 NSS_STATUS status; 295 372 296 groups = (gid_t *)malloc _array_p(gid_t,size);373 groups = (gid_t *)malloc(size); 297 374 groups[0] = gid; 298 375 … … 304 381 305 382 for (i=0; i<start-1; i++) { 306 printf("% d, ",groups[i]);307 } 308 printf("% d\n",groups[i]);383 printf("%lu, ", (unsigned long)groups[i]); 384 } 385 printf("%lu\n", (unsigned long)groups[i]); 309 386 } 310 387 -
vendor/current/nsswitch/pam_winbind.c
r414 r740 157 157 { 158 158 if (!initialized) { 159 bindtextdomain(MODULE_NAME, dyn_LOCALEDIR);159 bindtextdomain(MODULE_NAME, LOCALEDIR); 160 160 initialized = 1; 161 161 } … … 1078 1078 int sid_list_buffer_size) 1079 1079 { 1080 const char* sid_string = NULL; 1081 char *sid_str = NULL; 1080 char sid_string[WBC_SID_STRING_BUFLEN]; 1082 1081 1083 1082 /* lookup name? */ 1084 1083 if (IS_SID_STRING(name)) { 1085 s id_string = name;1084 strlcpy(sid_string, name, sizeof(sid_string)); 1086 1085 } else { 1087 1086 wbcErr wbc_status; … … 1099 1098 } 1100 1099 1101 wbc_status = wbcSidToString(&sid, &sid_str); 1102 if (!WBC_ERROR_IS_OK(wbc_status)) { 1103 return false; 1104 } 1105 1106 sid_string = sid_str; 1100 wbcSidToStringBuf(&sid, sid_string, sizeof(sid_string)); 1107 1101 } 1108 1102 1109 1103 if (!safe_append_string(sid_list_buffer, sid_string, 1110 1104 sid_list_buffer_size)) { 1111 wbcFreeMemory(sid_str);1112 1105 return false; 1113 1106 } 1114 1115 wbcFreeMemory(sid_str);1116 1107 return true; 1117 1108 } … … 1145 1136 1146 1137 search_location = name_list; 1147 while ((comma = str str(search_location, ",")) != NULL) {1138 while ((comma = strchr(search_location, ',')) != NULL) { 1148 1139 current_name = strndup(search_location, 1149 1140 comma - search_location); … … 1200 1191 */ 1201 1192 len = strlen(sid_list_buffer); 1202 if (len) { 1203 if (sid_list_buffer[len - 1] == ',') { 1204 sid_list_buffer[len - 1] = '\0'; 1205 } 1193 if ((len != 0) && (sid_list_buffer[len - 1] == ',')) { 1194 sid_list_buffer[len - 1] = '\0'; 1206 1195 } 1207 1196 } … … 1435 1424 const struct wbcAuthErrorInfo *e, 1436 1425 const char *nt_status_string, 1437 int *pam_err or)1426 int *pam_err) 1438 1427 { 1439 1428 const char *ntstatus = NULL; 1440 1429 const char *error_string = NULL; 1441 1430 1442 if (!e || !pam_err or) {1431 if (!e || !pam_err) { 1443 1432 return false; 1444 1433 } … … 1454 1443 if (error_string) { 1455 1444 _make_remark(ctx, PAM_ERROR_MSG, error_string); 1456 *pam_err or= e->pam_error;1445 *pam_err = e->pam_error; 1457 1446 return true; 1458 1447 } 1459 1448 1460 1449 if (e->display_string) { 1461 _make_remark(ctx, PAM_ERROR_MSG, e->display_string);1462 *pam_err or= e->pam_error;1450 _make_remark(ctx, PAM_ERROR_MSG, _(e->display_string)); 1451 *pam_err = e->pam_error; 1463 1452 return true; 1464 1453 } 1465 1454 1466 1455 _make_remark(ctx, PAM_ERROR_MSG, nt_status_string); 1467 *pam_err or= e->pam_error;1456 *pam_err = e->pam_error; 1468 1457 1469 1458 return true; … … 1902 1891 1903 1892 done: 1904 if (logon.blobs) { 1905 wbcFreeMemory(logon.blobs); 1906 } 1893 wbcFreeMemory(logon.blobs); 1907 1894 if (info && info->blobs && !p_info) { 1908 1895 wbcFreeMemory(info->blobs); … … 2001 1988 case -1: 2002 1989 break; 2003 case WBC_PWD_CHANGE_ REJECT_OTHER:1990 case WBC_PWD_CHANGE_NO_ERROR: 2004 1991 if ((min_pwd_age > 0) && 2005 1992 (pwd_last_set + min_pwd_age > time(NULL))) { … … 2008 1995 } 2009 1996 break; 2010 case WBC_PWD_CHANGE_ REJECT_TOO_SHORT:1997 case WBC_PWD_CHANGE_PASSWORD_TOO_SHORT: 2011 1998 PAM_WB_REMARK_DIRECT(ctx, 2012 1999 "NT_STATUS_PWD_TOO_SHORT"); 2013 2000 break; 2014 case WBC_PWD_CHANGE_ REJECT_IN_HISTORY:2001 case WBC_PWD_CHANGE_PWD_IN_HISTORY: 2015 2002 PAM_WB_REMARK_DIRECT(ctx, 2016 2003 "NT_STATUS_PWD_HISTORY_CONFLICT"); 2017 2004 break; 2018 case WBC_PWD_CHANGE_ REJECT_COMPLEXITY:2005 case WBC_PWD_CHANGE_NOT_COMPLEX: 2019 2006 _make_remark(ctx, PAM_ERROR_MSG, 2020 2007 _("Password does not meet " … … 2425 2412 struct wbcDomainSid sid; 2426 2413 enum wbcSidType type; 2427 char *domain ;2414 char *domain = NULL; 2428 2415 char *name; 2429 2416 char *p; -
vendor/current/nsswitch/pam_winbind.h
r414 r740 1 /* 2 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000 3 * Copyright (c) Tim Potter <tpot@samba.org> 2000 4 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002 5 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2008 6 * Copyright (c) Jan Rêkorajski 1999. 7 * Copyright (c) Andrew G. Morgan 1996-8. 8 * Copyright (c) Alex O. Yuriev, 1996. 9 * Copyright (c) Cristian Gafton 1996. 10 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, and the entire permission notice in its entirety, 17 * including the disclaimer of warranties. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. The name of the author may not be used to endorse or promote 22 * products derived from this software without specific prior 23 * written permission. 24 * 25 * ALTERNATIVELY, this product may be distributed under the terms of 26 * the GNU Public License, in which case the provisions of the GPL are 27 * required INSTEAD OF the above restrictions. (This clause is 28 * necessary due to a potential bad interaction between the GPL and 29 * the restrictions contained in a BSD-style copyright.) 30 * 31 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED 32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 33 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 34 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 41 * OF THE POSSIBILITY OF SUCH DAMAGE. 42 */ 43 1 44 /* pam_winbind header file 2 45 (Solaris needs some macros from Linux for common PAM code) … … 4 47 Shirish Kalele 2000 5 48 */ 49 50 #ifndef _NSSWITCH_PAM_WINBIND_H_ 51 #define _NSSWITCH_PAM_WINBIND_H_ 6 52 7 53 #include "../lib/replace/replace.h" … … 10 56 #include <talloc.h> 11 57 #include "libwbclient/wbclient.h" 12 #include "localedir.h"13 58 14 59 #define MODULE_NAME "pam_winbind" … … 177 222 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type) 178 223 #define TALLOC_P(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) 224 225 #endif /* _NSSWITCH_PAM_WINBIND_H_ */ -
vendor/current/nsswitch/tests/test_wbinfo.sh
r414 r740 16 16 failed=0 17 17 samba4bindir="$BUILDDIR/bin" 18 wbinfo="$ samba4bindir/wbinfo$EXEEXT"18 wbinfo="$VALGRIND $samba4bindir/wbinfo$EXEEXT" 19 19 20 20 . `dirname $0`/../../testprogs/blackbox/subunit.sh … … 164 164 echo "Own domain reported as $own_domain instead of $DOMAIN" 165 165 echo "failure: wbinfo --own-domain against $TARGET check output" 166 failed=`expr $failed + 1` 166 167 fi 167 168 … … 174 175 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1` 175 176 176 testit "wbinfo --uid-info against $TARGET" $wbinfo --uid-info $admin_uid 177 178 # this does not work 179 knownfail "wbinfo --group-info against $TARGET" $wbinfo --group-info "S-1-22-2-0" 180 knownfail "wbinfo --gid-info against $TARGET" $wbinfo --gid-info 30001 181 knownfail "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" 177 testit "wbinfo --uid-info against $TARGET" $wbinfo --uid-info $admin_uid || failed=`expr $failed + 1` 178 179 echo "test: wbinfo --group-info against $TARGET" 180 rawgid=`$wbinfo --group-info "Domain admins" | sed 's/.*:\([0-9][0-9]*\):/\1/'` 181 if test x$? = x0; then 182 echo "success: wbinfo --group-info against $TARGET" 183 else 184 echo "failure: wbinfo --group-info against $TARGET" 185 failed=`expr $failed + 1` 186 fi 187 188 gid=`echo $rawgid | sed 's/.*:\([0-9][0-9]*\):/\1/'` 189 testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=`expr $failed + 1` 190 191 testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=`expr $failed + 1` 182 192 183 193 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1` -
vendor/current/nsswitch/wb_common.c
r591 r740 23 23 */ 24 24 25 #include "replace.h" 26 #include "system/select.h" 25 27 #include "winbind_client.h" 26 28 … … 42 44 /* Initialise a request structure */ 43 45 44 void winbindd_init_request(struct winbindd_request *request, int request_type) 46 static void winbindd_init_request(struct winbindd_request *request, 47 int request_type) 45 48 { 46 49 request->length = sizeof(struct winbindd_request); … … 65 68 __attribute__((destructor)) 66 69 #endif 67 void winbind_close_sock(void)70 static void winbind_close_sock(void) 68 71 { 69 72 if (winbindd_fd != -1) { … … 233 236 for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1; 234 237 wait_time += slept) { 235 struct timeval tv; 236 fd_set w_fds; 238 struct pollfd pfd; 237 239 int ret; 238 240 int connect_errno = 0; … … 244 246 switch (errno) { 245 247 case EINPROGRESS: 246 FD_ZERO(&w_fds); 247 if (fd < 0 || fd >= FD_SETSIZE) { 248 errno = EBADF; 249 goto error_out; 250 } 251 FD_SET(fd, &w_fds); 252 tv.tv_sec = CONNECT_TIMEOUT - wait_time; 253 tv.tv_usec = 0; 254 255 ret = select(fd + 1, NULL, &w_fds, NULL, &tv); 248 pfd.fd = fd; 249 pfd.events = POLLOUT; 250 251 ret = poll(&pfd, 1, (CONNECT_TIMEOUT - wait_time) * 1000); 256 252 257 253 if (ret > 0) { … … 371 367 /* Write data to winbindd socket */ 372 368 373 int winbind_write_sock(void *buffer, int count, int recursing, int need_priv) 369 static int winbind_write_sock(void *buffer, int count, int recursing, 370 int need_priv) 374 371 { 375 372 int result, nwritten; … … 389 386 390 387 while(nwritten < count) { 391 struct timeval tv;392 fd_set r_fds;388 struct pollfd pfd; 389 int ret; 393 390 394 391 /* Catch pipe close on other end by checking if a read() 395 call would not block by calling select(). */ 396 397 FD_ZERO(&r_fds); 398 if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { 399 errno = EBADF; 392 call would not block by calling poll(). */ 393 394 pfd.fd = winbindd_fd; 395 pfd.events = POLLIN|POLLHUP; 396 397 ret = poll(&pfd, 1, 0); 398 if (ret == -1) { 399 winbind_close_sock(); 400 return -1; /* poll error */ 401 } 402 403 /* Write should be OK if fd not available for reading */ 404 405 if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) { 406 407 /* Pipe has closed on remote end */ 408 409 winbind_close_sock(); 410 goto restart; 411 } 412 413 /* Do the write */ 414 415 result = write(winbindd_fd, 416 (char *)buffer + nwritten, 417 count - nwritten); 418 419 if ((result == -1) || (result == 0)) { 420 421 /* Write failed */ 422 400 423 winbind_close_sock(); 401 424 return -1; 402 425 } 403 FD_SET(winbindd_fd, &r_fds); 404 ZERO_STRUCT(tv); 405 406 if (select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv) == -1) { 407 winbind_close_sock(); 408 return -1; /* Select error */ 409 } 410 411 /* Write should be OK if fd not available for reading */ 412 413 if (!FD_ISSET(winbindd_fd, &r_fds)) { 414 415 /* Do the write */ 416 417 result = write(winbindd_fd, 418 (char *)buffer + nwritten, 419 count - nwritten); 420 421 if ((result == -1) || (result == 0)) { 422 423 /* Write failed */ 424 425 winbind_close_sock(); 426 return -1; 427 } 428 429 nwritten += result; 430 431 } else { 432 433 /* Pipe has closed on remote end */ 434 435 winbind_close_sock(); 436 goto restart; 437 } 426 427 nwritten += result; 438 428 } 439 429 … … 443 433 /* Read data from winbindd socket */ 444 434 445 int winbind_read_sock(void *buffer, int count)435 static int winbind_read_sock(void *buffer, int count) 446 436 { 447 437 int nread = 0; 448 int total_time = 0 , selret;438 int total_time = 0; 449 439 450 440 if (winbindd_fd == -1) { … … 454 444 /* Read data from socket */ 455 445 while(nread < count) { 456 struct timeval tv;457 fd_set r_fds;446 struct pollfd pfd; 447 int ret; 458 448 459 449 /* Catch pipe close on other end by checking if a read() 460 call would not block by calling select(). */ 461 462 FD_ZERO(&r_fds); 463 if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { 464 errno = EBADF; 450 call would not block by calling poll(). */ 451 452 pfd.fd = winbindd_fd; 453 pfd.events = POLLIN|POLLHUP; 454 455 /* Wait for 5 seconds for a reply. May need to parameterise this... */ 456 457 ret = poll(&pfd, 1, 5000); 458 if (ret == -1) { 465 459 winbind_close_sock(); 466 return -1; 467 } 468 FD_SET(winbindd_fd, &r_fds); 469 ZERO_STRUCT(tv); 470 /* Wait for 5 seconds for a reply. May need to parameterise this... */ 471 tv.tv_sec = 5; 472 473 if ((selret = select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv)) == -1) { 474 winbind_close_sock(); 475 return -1; /* Select error */ 476 } 477 478 if (selret == 0) { 460 return -1; /* poll error */ 461 } 462 463 if (ret == 0) { 479 464 /* Not ready for read yet... */ 480 465 if (total_time >= 30) { … … 487 472 } 488 473 489 if ( FD_ISSET(winbindd_fd, &r_fds)) {474 if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) { 490 475 491 476 /* Do the Read */ … … 514 499 /* Read reply */ 515 500 516 int winbindd_read_reply(struct winbindd_response *response)501 static int winbindd_read_reply(struct winbindd_response *response) 517 502 { 518 503 int result1, result2 = 0; … … 527 512 sizeof(struct winbindd_response)); 528 513 if (result1 == -1) { 514 return -1; 515 } 516 517 if (response->length < sizeof(struct winbindd_response)) { 529 518 return -1; 530 519 } … … 683 672 return status; 684 673 } 685 686 /*************************************************************************687 ************************************************************************/688 689 const char *nss_err_str(NSS_STATUS ret)690 {691 switch (ret) {692 case NSS_STATUS_TRYAGAIN:693 return "NSS_STATUS_TRYAGAIN";694 case NSS_STATUS_SUCCESS:695 return "NSS_STATUS_SUCCESS";696 case NSS_STATUS_NOTFOUND:697 return "NSS_STATUS_NOTFOUND";698 case NSS_STATUS_UNAVAIL:699 return "NSS_STATUS_UNAVAIL";700 #ifdef NSS_STATUS_RETURN701 case NSS_STATUS_RETURN:702 return "NSS_STATUS_RETURN";703 #endif704 default:705 return "UNKNOWN RETURN CODE!!!!!!!";706 }707 } -
vendor/current/nsswitch/wbinfo.c
r414 r740 23 23 24 24 #include "includes.h" 25 #include "popt_common.h" 25 26 #include "winbind_client.h" 26 27 #include "libwbclient/wbclient.h" 27 28 #include "lib/popt/popt.h" 28 29 #include "../libcli/auth/libcli_auth.h" 29 #if !(_SAMBA_VERSION_) <430 #if (_SAMBA_BUILD_) >= 4 30 31 #include "lib/cmdline/popt_common.h" 31 32 #endif … … 48 49 if (!WBC_ERROR_IS_OK(wbc_status)) { 49 50 d_fprintf(stderr, "could not obtain winbind interface " 50 "details !\n");51 "details: %s\n", wbcErrorString(wbc_status)); 51 52 } 52 53 … … 173 174 wbc_status = wbcGetpwnam(user, &pwd); 174 175 if (!WBC_ERROR_IS_OK(wbc_status)) { 176 d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n", 177 wbcErrorString(wbc_status)); 175 178 return false; 176 179 } … … 185 188 pwd->pw_shell); 186 189 190 wbcFreeMemory(pwd); 191 187 192 return true; 188 193 } … … 196 201 wbc_status = wbcGetpwuid(uid, &pwd); 197 202 if (!WBC_ERROR_IS_OK(wbc_status)) { 203 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n", 204 wbcErrorString(wbc_status)); 198 205 return false; 199 206 } … … 208 215 pwd->pw_shell); 209 216 217 wbcFreeMemory(pwd); 218 210 219 return true; 211 220 } … … 220 229 wbc_status = wbcGetpwsid(&sid, &pwd); 221 230 if (!WBC_ERROR_IS_OK(wbc_status)) { 231 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n", 232 wbcErrorString(wbc_status)); 222 233 return false; 223 234 } … … 245 256 wbc_status = wbcGetgrnam(group, &grp); 246 257 if (!WBC_ERROR_IS_OK(wbc_status)) { 258 d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n", 259 wbcErrorString(wbc_status)); 247 260 return false; 248 261 } … … 274 287 wbc_status = wbcGetgrgid(gid, &grp); 275 288 if (!WBC_ERROR_IS_OK(wbc_status)) { 289 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n", 290 wbcErrorString(wbc_status)); 276 291 return false; 277 292 } … … 307 322 wbc_status = wbcGetGroups(user, &num_groups, &groups); 308 323 if (!WBC_ERROR_IS_OK(wbc_status)) { 324 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n", 325 wbcErrorString(wbc_status)); 309 326 return false; 310 327 } … … 332 349 wbc_status = wbcStringToSid(user_sid_str, &user_sid); 333 350 if (!WBC_ERROR_IS_OK(wbc_status)) { 351 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 352 wbcErrorString(wbc_status)); 334 353 return false; 335 354 } … … 337 356 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids); 338 357 if (!WBC_ERROR_IS_OK(wbc_status)) { 358 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n", 359 wbcErrorString(wbc_status)); 339 360 return false; 340 361 } 341 362 342 363 for (i = 0; i < num_sids; i++) { 343 char *str = NULL; 344 wbc_status = wbcSidToString(&sids[i], &str); 345 if (!WBC_ERROR_IS_OK(wbc_status)) { 346 wbcFreeMemory(sids); 347 return false; 348 } 364 char str[WBC_SID_STRING_BUFLEN]; 365 wbcSidToStringBuf(&sids[i], str, sizeof(str)); 349 366 d_printf("%s\n", str); 350 wbcFreeMemory(str);351 367 } 352 368 … … 367 383 wbc_status = wbcStringToSid(user_sid_str, &user_sid); 368 384 if (!WBC_ERROR_IS_OK(wbc_status)) { 385 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 386 wbcErrorString(wbc_status)); 369 387 return false; 370 388 } … … 372 390 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids); 373 391 if (!WBC_ERROR_IS_OK(wbc_status)) { 392 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n", 393 wbcErrorString(wbc_status)); 374 394 return false; 375 395 } 376 396 377 397 for (i = 0; i < num_sids; i++) { 378 char *str = NULL; 379 wbc_status = wbcSidToString(&sids[i], &str); 380 if (!WBC_ERROR_IS_OK(wbc_status)) { 381 wbcFreeMemory(sids); 382 return false; 383 } 398 char str[WBC_SID_STRING_BUFLEN]; 399 wbcSidToStringBuf(&sids[i], str, sizeof(str)); 384 400 d_printf("%s\n", str); 385 wbcFreeMemory(str);386 401 } 387 402 … … 400 415 uint32_t *alias_rids = NULL; 401 416 uint32_t num_alias_rids; 402 char *domain_sid_str = NULL;417 char domain_sid_str[WBC_SID_STRING_BUFLEN]; 403 418 404 419 /* Send request */ … … 412 427 wbc_status = wbcDomainInfo(domain, &dinfo); 413 428 if (!WBC_ERROR_IS_OK(wbc_status)) { 414 d_ printf("wbcDomainInfo(%s) failed: %s\n", domain,415 wbcErrorString(wbc_status));429 d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain, 430 wbcErrorString(wbc_status)); 416 431 goto done; 417 432 } … … 427 442 } 428 443 429 wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str); 430 if (!WBC_ERROR_IS_OK(wbc_status)) { 431 goto done; 432 } 444 wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str)); 433 445 434 446 for (i = 0; i < num_alias_rids; i++) { … … 439 451 440 452 done: 441 if (domain_sid_str) { 442 wbcFreeMemory(domain_sid_str); 443 } 444 if (dinfo) { 445 wbcFreeMemory(dinfo); 446 } 453 wbcFreeMemory(dinfo); 447 454 return (WBC_ERR_SUCCESS == wbc_status); 448 455 } … … 458 465 wbc_status = wbcResolveWinsByName(name, &ip); 459 466 if (!WBC_ERROR_IS_OK(wbc_status)) { 467 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n", 468 wbcErrorString(wbc_status)); 460 469 return false; 461 470 } … … 479 488 wbc_status = wbcResolveWinsByIP(ip, &name); 480 489 if (!WBC_ERROR_IS_OK(wbc_status)) { 490 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n", 491 wbcErrorString(wbc_status)); 481 492 return false; 482 493 } … … 503 514 wbc_status = wbcListTrusts(&domain_list, &num_domains); 504 515 if (!WBC_ERROR_IS_OK(wbc_status)) { 516 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n", 517 wbcErrorString(wbc_status)); 505 518 return false; 506 519 } … … 559 572 } 560 573 574 wbcFreeMemory(domain_list); 575 561 576 return true; 562 577 } … … 589 604 wbc_status = wbcListTrusts(&domain_list, &num_domains); 590 605 if (!WBC_ERROR_IS_OK(wbc_status)) { 606 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n", 607 wbcErrorString(wbc_status)); 591 608 return false; 592 609 } … … 609 626 } 610 627 628 wbcFreeMemory(domain_list); 629 611 630 return true; 612 631 } … … 619 638 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 620 639 struct wbcDomainInfo *dinfo = NULL; 621 char *sid_str = NULL;640 char sid_str[WBC_SID_STRING_BUFLEN]; 622 641 623 642 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){ … … 629 648 wbc_status = wbcDomainInfo(domain, &dinfo); 630 649 if (!WBC_ERROR_IS_OK(wbc_status)) { 631 return false; 632 } 633 634 wbc_status = wbcSidToString(&dinfo->sid, &sid_str); 635 if (!WBC_ERROR_IS_OK(wbc_status)) { 636 wbcFreeMemory(dinfo); 637 return false; 638 } 650 d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n", 651 wbcErrorString(wbc_status)); 652 return false; 653 } 654 655 wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str)); 639 656 640 657 /* Display response */ … … 655 672 "Yes" : "No"); 656 673 657 wbcFreeMemory(sid_str);658 674 wbcFreeMemory(dinfo); 659 675 … … 743 759 } 744 760 if (!WBC_ERROR_IS_OK(wbc_status)) { 745 return false; 746 } 761 d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: " 762 "%s\n", wbcErrorString(wbc_status)); 763 return false; 764 } 765 766 return true; 767 } 768 769 /* Find the currently connected DCs */ 770 771 static bool wbinfo_dc_info(const char *domain_name) 772 { 773 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 774 size_t i, num_dcs; 775 const char **dc_names, **dc_ips; 776 777 wbc_status = wbcDcInfo(domain_name, &num_dcs, 778 &dc_names, &dc_ips); 779 if (!WBC_ERROR_IS_OK(wbc_status)) { 780 printf("Could not find dc info %s\n", 781 domain_name ? domain_name : "our domain"); 782 return false; 783 } 784 785 for (i=0; i<num_dcs; i++) { 786 printf("%s (%s)\n", dc_names[i], dc_ips[i]); 787 } 788 wbcFreeMemory(dc_names); 789 wbcFreeMemory(dc_ips); 747 790 748 791 return true; … … 775 818 } 776 819 if (!WBC_ERROR_IS_OK(wbc_status)) { 820 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: " 821 "%s\n", wbcErrorString(wbc_status)); 777 822 return false; 778 823 } … … 799 844 } 800 845 if (!WBC_ERROR_IS_OK(wbc_status)) { 846 d_fprintf(stderr, "failed to call wbcPingDc: %s\n", 847 wbcErrorString(wbc_status)); 801 848 return false; 802 849 } … … 811 858 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 812 859 struct wbcDomainSid sid; 813 char *sid_str = NULL;860 char sid_str[WBC_SID_STRING_BUFLEN]; 814 861 815 862 /* Send request */ … … 817 864 wbc_status = wbcUidToSid(uid, &sid); 818 865 if (!WBC_ERROR_IS_OK(wbc_status)) { 819 return false; 820 } 821 822 wbc_status = wbcSidToString(&sid, &sid_str); 823 if (!WBC_ERROR_IS_OK(wbc_status)) { 824 return false; 825 } 866 d_fprintf(stderr, "failed to call wbcUidToSid: %s\n", 867 wbcErrorString(wbc_status)); 868 return false; 869 } 870 871 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); 826 872 827 873 /* Display response */ … … 829 875 d_printf("%s\n", sid_str); 830 876 831 wbcFreeMemory(sid_str);832 833 877 return true; 834 878 } … … 840 884 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 841 885 struct wbcDomainSid sid; 842 char *sid_str = NULL;886 char sid_str[WBC_SID_STRING_BUFLEN]; 843 887 844 888 /* Send request */ … … 846 890 wbc_status = wbcGidToSid(gid, &sid); 847 891 if (!WBC_ERROR_IS_OK(wbc_status)) { 848 return false; 849 } 850 851 wbc_status = wbcSidToString(&sid, &sid_str); 852 if (!WBC_ERROR_IS_OK(wbc_status)) { 853 return false; 854 } 892 d_fprintf(stderr, "failed to call wbcGidToSid: %s\n", 893 wbcErrorString(wbc_status)); 894 return false; 895 } 896 897 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); 855 898 856 899 /* Display response */ 857 900 858 901 d_printf("%s\n", sid_str); 859 860 wbcFreeMemory(sid_str);861 902 862 903 return true; … … 875 916 wbc_status = wbcStringToSid(sid_str, &sid); 876 917 if (!WBC_ERROR_IS_OK(wbc_status)) { 918 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 919 wbcErrorString(wbc_status)); 877 920 return false; 878 921 } … … 880 923 wbc_status = wbcSidToUid(&sid, &uid); 881 924 if (!WBC_ERROR_IS_OK(wbc_status)) { 925 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n", 926 wbcErrorString(wbc_status)); 882 927 return false; 883 928 } … … 900 945 wbc_status = wbcStringToSid(sid_str, &sid); 901 946 if (!WBC_ERROR_IS_OK(wbc_status)) { 947 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 948 wbcErrorString(wbc_status)); 902 949 return false; 903 950 } … … 905 952 wbc_status = wbcSidToGid(&sid, &gid); 906 953 if (!WBC_ERROR_IS_OK(wbc_status)) { 954 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n", 955 wbcErrorString(wbc_status)); 907 956 return false; 908 957 } … … 915 964 } 916 965 966 static bool wbinfo_sids_to_unix_ids(const char *arg) 967 { 968 char sidstr[WBC_SID_STRING_BUFLEN]; 969 struct wbcDomainSid *sids; 970 struct wbcUnixId *unix_ids; 971 int i, num_sids; 972 const char *p; 973 wbcErr wbc_status; 974 975 976 num_sids = 0; 977 sids = NULL; 978 p = arg; 979 980 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) { 981 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid, 982 num_sids+1); 983 if (sids == NULL) { 984 d_fprintf(stderr, "talloc failed\n"); 985 return false; 986 } 987 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]); 988 if (!WBC_ERROR_IS_OK(wbc_status)) { 989 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n", 990 sidstr, wbcErrorString(wbc_status)); 991 TALLOC_FREE(sids); 992 return false; 993 } 994 num_sids += 1; 995 } 996 997 unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids); 998 if (unix_ids == NULL) { 999 TALLOC_FREE(sids); 1000 return false; 1001 } 1002 1003 wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids); 1004 if (!WBC_ERROR_IS_OK(wbc_status)) { 1005 d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n", 1006 wbcErrorString(wbc_status)); 1007 TALLOC_FREE(sids); 1008 return false; 1009 } 1010 1011 for (i=0; i<num_sids; i++) { 1012 1013 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr)); 1014 1015 switch(unix_ids[i].type) { 1016 case WBC_ID_TYPE_UID: 1017 d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid); 1018 break; 1019 case WBC_ID_TYPE_GID: 1020 d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid); 1021 break; 1022 default: 1023 d_printf("%s -> unmapped\n", sidstr); 1024 break; 1025 } 1026 } 1027 1028 TALLOC_FREE(sids); 1029 TALLOC_FREE(unix_ids); 1030 1031 return true; 1032 } 1033 917 1034 static bool wbinfo_allocate_uid(void) 918 1035 { … … 924 1041 wbc_status = wbcAllocateUid(&uid); 925 1042 if (!WBC_ERROR_IS_OK(wbc_status)) { 1043 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n", 1044 wbcErrorString(wbc_status)); 926 1045 return false; 927 1046 } … … 943 1062 wbc_status = wbcAllocateGid(&gid); 944 1063 if (!WBC_ERROR_IS_OK(wbc_status)) { 1064 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n", 1065 wbcErrorString(wbc_status)); 945 1066 return false; 946 1067 } … … 962 1083 wbc_status = wbcStringToSid(sid_str, &sid); 963 1084 if (!WBC_ERROR_IS_OK(wbc_status)) { 1085 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1086 wbcErrorString(wbc_status)); 964 1087 return false; 965 1088 } … … 967 1090 wbc_status = wbcSetUidMapping(uid, &sid); 968 1091 if (!WBC_ERROR_IS_OK(wbc_status)) { 1092 d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n", 1093 wbcErrorString(wbc_status)); 969 1094 return false; 970 1095 } … … 987 1112 wbc_status = wbcStringToSid(sid_str, &sid); 988 1113 if (!WBC_ERROR_IS_OK(wbc_status)) { 1114 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1115 wbcErrorString(wbc_status)); 989 1116 return false; 990 1117 } … … 992 1119 wbc_status = wbcSetGidMapping(gid, &sid); 993 1120 if (!WBC_ERROR_IS_OK(wbc_status)) { 1121 d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n", 1122 wbcErrorString(wbc_status)); 994 1123 return false; 995 1124 } … … 1012 1141 wbc_status = wbcStringToSid(sid_str, &sid); 1013 1142 if (!WBC_ERROR_IS_OK(wbc_status)) { 1143 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1144 wbcErrorString(wbc_status)); 1014 1145 return false; 1015 1146 } … … 1017 1148 wbc_status = wbcRemoveUidMapping(uid, &sid); 1018 1149 if (!WBC_ERROR_IS_OK(wbc_status)) { 1150 d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n", 1151 wbcErrorString(wbc_status)); 1019 1152 return false; 1020 1153 } … … 1037 1170 wbc_status = wbcStringToSid(sid_str, &sid); 1038 1171 if (!WBC_ERROR_IS_OK(wbc_status)) { 1172 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1173 wbcErrorString(wbc_status)); 1039 1174 return false; 1040 1175 } … … 1042 1177 wbc_status = wbcRemoveGidMapping(gid, &sid); 1043 1178 if (!WBC_ERROR_IS_OK(wbc_status)) { 1179 d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n", 1180 wbcErrorString(wbc_status)); 1044 1181 return false; 1045 1182 } … … 1067 1204 wbc_status = wbcStringToSid(sid_str, &sid); 1068 1205 if (!WBC_ERROR_IS_OK(wbc_status)) { 1206 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1207 wbcErrorString(wbc_status)); 1069 1208 return false; 1070 1209 } … … 1072 1211 wbc_status = wbcLookupSid(&sid, &domain, &name, &type); 1073 1212 if (!WBC_ERROR_IS_OK(wbc_status)) { 1213 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n", 1214 wbcErrorString(wbc_status)); 1074 1215 return false; 1075 1216 } … … 1097 1238 wbc_status = wbcStringToSid(sid_str, &sid); 1098 1239 if (!WBC_ERROR_IS_OK(wbc_status)) { 1240 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", 1241 wbcErrorString(wbc_status)); 1099 1242 return false; 1100 1243 } … … 1102 1245 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type); 1103 1246 if (!WBC_ERROR_IS_OK(wbc_status)) { 1247 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n", 1248 wbcErrorString(wbc_status)); 1104 1249 return false; 1105 1250 } … … 1185 1330 ret = true; 1186 1331 done: 1187 if (dinfo) { 1188 wbcFreeMemory(dinfo); 1189 } 1190 if (domain_name) { 1191 wbcFreeMemory(domain_name); 1192 } 1193 if (names) { 1194 wbcFreeMemory(names); 1195 } 1196 if (types) { 1197 wbcFreeMemory(types); 1198 } 1332 wbcFreeMemory(dinfo); 1333 wbcFreeMemory(domain_name); 1334 wbcFreeMemory(names); 1335 wbcFreeMemory(types); 1199 1336 TALLOC_FREE(mem_ctx); 1200 1337 return ret; 1201 1338 } 1202 1339 1340 static bool wbinfo_lookup_sids(const char *arg) 1341 { 1342 char sidstr[WBC_SID_STRING_BUFLEN]; 1343 struct wbcDomainSid *sids; 1344 struct wbcDomainInfo *domains; 1345 struct wbcTranslatedName *names; 1346 int num_domains; 1347 int i, num_sids; 1348 const char *p; 1349 wbcErr wbc_status; 1350 1351 1352 num_sids = 0; 1353 sids = NULL; 1354 p = arg; 1355 1356 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) { 1357 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid, 1358 num_sids+1); 1359 if (sids == NULL) { 1360 d_fprintf(stderr, "talloc failed\n"); 1361 return false; 1362 } 1363 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]); 1364 if (!WBC_ERROR_IS_OK(wbc_status)) { 1365 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n", 1366 sidstr, wbcErrorString(wbc_status)); 1367 TALLOC_FREE(sids); 1368 return false; 1369 } 1370 num_sids += 1; 1371 } 1372 1373 wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains, 1374 &names); 1375 if (!WBC_ERROR_IS_OK(wbc_status)) { 1376 d_fprintf(stderr, "wbcLookupSids failed: %s\n", 1377 wbcErrorString(wbc_status)); 1378 TALLOC_FREE(sids); 1379 return false; 1380 } 1381 1382 for (i=0; i<num_sids; i++) { 1383 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr)); 1384 1385 d_printf("%s -> %s\\%s %d\n", sidstr, 1386 domains[names[i].domain_index].short_name, 1387 names[i].name, names[i].type); 1388 } 1389 return true; 1390 } 1391 1203 1392 /* Convert string to sid */ 1204 1393 … … 1207 1396 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 1208 1397 struct wbcDomainSid sid; 1209 char *sid_str;1398 char sid_str[WBC_SID_STRING_BUFLEN]; 1210 1399 enum wbcSidType type; 1211 1400 fstring domain_name; … … 1220 1409 &sid, &type); 1221 1410 if (!WBC_ERROR_IS_OK(wbc_status)) { 1222 return false; 1223 } 1224 1225 wbc_status = wbcSidToString(&sid, &sid_str); 1226 if (!WBC_ERROR_IS_OK(wbc_status)) { 1227 return false; 1228 } 1411 d_fprintf(stderr, "failed to call wbcLookupName: %s\n", 1412 wbcErrorString(wbc_status)); 1413 return false; 1414 } 1415 1416 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); 1229 1417 1230 1418 /* Display response */ 1231 1419 1232 1420 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type); 1233 1234 wbcFreeMemory(sid_str);1235 1421 1236 1422 return true; … … 1312 1498 sizeof(flags)); 1313 1499 if (!WBC_ERROR_IS_OK(wbc_status)) { 1500 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1501 wbcErrorString(wbc_status)); 1314 1502 goto done; 1315 1503 } … … 1322 1510 sizeof(uid)); 1323 1511 if (!WBC_ERROR_IS_OK(wbc_status)) { 1512 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1513 wbcErrorString(wbc_status)); 1324 1514 goto done; 1325 1515 } … … 1332 1522 strlen(cctype)+1); 1333 1523 if (!WBC_ERROR_IS_OK(wbc_status)) { 1524 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n", 1525 wbcErrorString(wbc_status)); 1334 1526 goto done; 1335 1527 } … … 1344 1536 if (error) { 1345 1537 d_fprintf(stderr, 1346 "error code was %s (0x%x)\nerror mess sage was: %s\n",1538 "error code was %s (0x%x)\nerror message was: %s\n", 1347 1539 error->nt_string, 1348 1540 error->nt_status, … … 1415 1607 if (response.data.auth.nt_status) 1416 1608 d_fprintf(stderr, 1417 "error code was %s (0x%x)\nerror mess sage was: %s\n",1609 "error code was %s (0x%x)\nerror message was: %s\n", 1418 1610 response.data.auth.nt_status_string, 1419 1611 response.data.auth.nt_status, … … 1516 1708 if (wbc_status == WBC_ERR_AUTH_ERROR) { 1517 1709 d_fprintf(stderr, 1518 "error code was %s (0x%x)\nerror mess sage was: %s\n",1710 "error code was %s (0x%x)\nerror message was: %s\n", 1519 1711 err->nt_string, 1520 1712 err->nt_status, … … 1529 1721 1530 1722 return WBC_ERROR_IS_OK(wbc_status); 1723 } 1724 1725 /* Authenticate a user with a plaintext password */ 1726 1727 static bool wbinfo_pam_logon(char *username) 1728 { 1729 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; 1730 struct wbcLogonUserParams params; 1731 struct wbcAuthErrorInfo *error; 1732 char *s = NULL; 1733 char *p = NULL; 1734 TALLOC_CTX *frame = talloc_tos(); 1735 uint32_t flags; 1736 uint32_t uid; 1737 1738 ZERO_STRUCT(params); 1739 1740 if ((s = talloc_strdup(frame, username)) == NULL) { 1741 return false; 1742 } 1743 1744 if ((p = strchr(s, '%')) != NULL) { 1745 *p = 0; 1746 p++; 1747 params.password = talloc_strdup(frame, p); 1748 } else { 1749 params.password = wbinfo_prompt_pass(frame, NULL, username); 1750 } 1751 params.username = s; 1752 1753 flags = WBFLAG_PAM_CACHED_LOGIN; 1754 1755 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, 1756 "flags", 0, 1757 (uint8_t *)&flags, sizeof(flags)); 1758 if (!WBC_ERROR_IS_OK(wbc_status)) { 1759 d_printf("wbcAddNamedBlob failed: %s\n", 1760 wbcErrorString(wbc_status)); 1761 return false; 1762 } 1763 1764 uid = getuid(); 1765 1766 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, 1767 "user_uid", 0, 1768 (uint8_t *)&uid, sizeof(uid)); 1769 if (!WBC_ERROR_IS_OK(wbc_status)) { 1770 d_printf("wbcAddNamedBlob failed: %s\n", 1771 wbcErrorString(wbc_status)); 1772 return false; 1773 } 1774 1775 wbc_status = wbcLogonUser(¶ms, NULL, &error, NULL); 1776 1777 wbcFreeMemory(params.blobs); 1778 1779 d_printf("plaintext password authentication %s\n", 1780 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed"); 1781 1782 if (!WBC_ERROR_IS_OK(wbc_status)) { 1783 d_fprintf(stderr, 1784 "error code was %s (0x%x)\nerror message was: %s\n", 1785 error->nt_string, 1786 (int)error->nt_status, 1787 error->display_string); 1788 wbcFreeMemory(error); 1789 return false; 1790 } 1791 return true; 1531 1792 } 1532 1793 … … 1607 1868 if (response.data.auth.nt_status) 1608 1869 d_fprintf(stderr, 1609 "error code was %s (0x%x)\nerror mess sage was: %s\n",1870 "error code was %s (0x%x)\nerror message was: %s\n", 1610 1871 response.data.auth.nt_status_string, 1611 1872 response.data.auth.nt_status, … … 1684 1945 wbc_status = wbcListGroups(domain, &num_groups, &groups); 1685 1946 if (!WBC_ERROR_IS_OK(wbc_status)) { 1947 d_fprintf(stderr, "failed to call wbcListGroups: %s\n", 1948 wbcErrorString(wbc_status)); 1686 1949 return false; 1687 1950 } … … 1754 2017 OPT_GETDCNAME, 1755 2018 OPT_DSGETDCNAME, 2019 OPT_DC_INFO, 1756 2020 OPT_USERDOMGROUPS, 1757 2021 OPT_SIDALIASES, 1758 2022 OPT_USERSIDS, 2023 OPT_LOOKUP_SIDS, 1759 2024 OPT_ALLOCATE_UID, 1760 2025 OPT_ALLOCATE_GID, … … 1763 2028 OPT_REMOVE_UID_MAPPING, 1764 2029 OPT_REMOVE_GID_MAPPING, 2030 OPT_SIDS_TO_XIDS, 1765 2031 OPT_SEPARATOR, 1766 2032 OPT_LIST_ALL_DOMAINS, … … 1773 2039 OPT_ONLINESTATUS, 1774 2040 OPT_CHANGE_USER_PASSWORD, 1775 OPT_PING_DC,1776 2041 OPT_CCACHE_SAVE, 1777 2042 OPT_SID_TO_FULLNAME, 1778 2043 OPT_NTLMV2, 2044 OPT_PAM_LOGON, 2045 OPT_LOGOFF, 2046 OPT_LOGOFF_USER, 2047 OPT_LOGOFF_UID, 1779 2048 OPT_LANMAN 1780 2049 }; … … 1794 2063 bool use_ntlmv2 = false; 1795 2064 bool use_lanman = false; 2065 char *logoff_user = getenv("USER"); 2066 int logoff_uid = geteuid(); 1796 2067 1797 2068 struct poptOption long_options[] = { … … 1810 2081 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" }, 1811 2082 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" }, 2083 { "lookup-sids", 0, POPT_ARG_STRING, &string_arg, 2084 OPT_LOOKUP_SIDS, "Converts SIDs to types and names", 2085 "Sid-List"}, 1812 2086 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" }, 1813 2087 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" }, … … 1822 2096 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" }, 1823 2097 { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" }, 2098 { "sids-to-unix-ids", 0, POPT_ARG_STRING, &string_arg, 2099 OPT_SIDS_TO_XIDS, "Translate SIDs to Unix IDs", "Sid-List" }, 1824 2100 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" }, 1825 2101 { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" }, 1826 { "ping-dc", 0, POPT_ARG_NONE, 0, OPT_PING_DC,2102 { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P', 1827 2103 "Check the NETLOGON connection" }, 1828 2104 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" }, 1829 2105 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" }, 1830 2106 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" }, 1831 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, " Show sequence numbers of all domains" },2107 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Deprecated command, see --online-status" }, 1832 2108 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"}, 1833 2109 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" }, … … 1843 2119 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" }, 1844 2120 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" }, 2121 { "pam-logon", 0, POPT_ARG_STRING, &string_arg, OPT_PAM_LOGON, 2122 "do a pam logon equivalent", "user%password" }, 2123 { "logoff", 0, POPT_ARG_NONE, NULL, OPT_LOGOFF, 2124 "log off user", "uid" }, 2125 { "logoff-user", 0, POPT_ARG_STRING, &logoff_user, 2126 OPT_LOGOFF_USER, "username to log off" }, 2127 { "logoff-uid", 0, POPT_ARG_INT, &logoff_uid, 2128 OPT_LOGOFF_UID, "uid to log off" }, 1845 2129 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" }, 1846 2130 { "ccache-save", 0, POPT_ARG_STRING, &string_arg, … … 1850 2134 "Get a DC name for a foreign domain", "domainname" }, 1851 2135 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" }, 2136 { "dc-info", 0, POPT_ARG_STRING, &string_arg, OPT_DC_INFO, 2137 "Find the currently known DCs", "domainname" }, 1852 2138 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL }, 1853 2139 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" }, … … 1944 2230 } 1945 2231 break; 2232 case OPT_LOOKUP_SIDS: 2233 if (!wbinfo_lookup_sids(string_arg)) { 2234 d_fprintf(stderr, "Could not lookup SIDs %s\n", 2235 string_arg); 2236 goto done; 2237 } 2238 break; 1946 2239 case 'n': 1947 2240 if (!wbinfo_lookupname(string_arg)) { … … 2053 2346 } 2054 2347 break; 2348 case OPT_SIDS_TO_XIDS: 2349 if (!wbinfo_sids_to_unix_ids(string_arg)) { 2350 d_fprintf(stderr, "wbinfo_sids_to_unix_ids " 2351 "failed\n"); 2352 goto done; 2353 } 2354 break; 2055 2355 case 't': 2056 2356 if (!wbinfo_check_secret(opt_domain_name)) { … … 2065 2365 } 2066 2366 break; 2067 case OPT_PING_DC:2367 case 'P': 2068 2368 if (!wbinfo_ping_dc()) { 2069 2369 d_fprintf(stderr, "Could not ping our DC\n"); … … 2192 2492 break; 2193 2493 } 2494 case OPT_PAM_LOGON: 2495 if (!wbinfo_pam_logon(string_arg)) { 2496 d_fprintf(stderr, "pam_logon failed for %s\n", 2497 string_arg); 2498 goto done; 2499 } 2500 break; 2501 case OPT_LOGOFF: 2502 { 2503 wbcErr wbc_status; 2504 2505 wbc_status = wbcLogoffUser(logoff_user, logoff_uid, 2506 ""); 2507 d_printf("Logoff %s (%d): %s\n", logoff_user, 2508 logoff_uid, wbcErrorString(wbc_status)); 2509 break; 2510 } 2194 2511 case 'K': { 2195 2512 uint32_t flags = WBFLAG_PAM_KRB5 | … … 2246 2563 } 2247 2564 break; 2565 case OPT_DC_INFO: 2566 if (!wbinfo_dc_info(string_arg)) { 2567 goto done; 2568 } 2569 break; 2248 2570 case OPT_SEPARATOR: { 2249 2571 const char sep = winbind_separator(); … … 2275 2597 /* generic configuration options */ 2276 2598 case OPT_DOMAIN_NAME: 2277 break;2278 2599 case OPT_VERBOSE: 2279 break;2280 2600 case OPT_NTLMV2: 2281 break;2282 2601 case OPT_LANMAN: 2602 case OPT_LOGOFF_USER: 2603 case OPT_LOGOFF_UID: 2283 2604 break; 2284 2605 default: -
vendor/current/nsswitch/winbind_client.h
r414 r740 1 /* 2 Unix SMB/CIFS implementation. 3 4 winbind client common code 5 6 Copyright (C) Tim Potter 2000 7 Copyright (C) Andrew Tridgell 2000 8 Copyright (C) Andrew Bartlett 2002 9 10 11 This library is free software; you can redistribute it and/or 12 modify it under the terms of the GNU Lesser General Public 13 License as published by the Free Software Foundation; either 14 version 3 of the License, or (at your option) any later version. 15 16 This library is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Library General Public License for more details. 20 21 You should have received a copy of the GNU Lesser General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 #ifndef _NSSWITCH_WINBIND_CLIENT_H_ 26 #define _NSSWITCH_WINBIND_CLIENT_H_ 27 1 28 #include "winbind_nss_config.h" 2 29 #include "winbind_struct_protocol.h" 3 30 4 void winbindd_init_request(struct winbindd_request *req,int rq_type);5 31 void winbindd_free_response(struct winbindd_response *response); 6 32 NSS_STATUS winbindd_send_request(int req_type, int need_priv, … … 13 39 struct winbindd_request *request, 14 40 struct winbindd_response *response); 15 int winbindd_read_reply(struct winbindd_response *response);16 17 41 #define winbind_env_set() \ 18 42 (strcmp(getenv(WINBINDD_DONT_ENV)?getenv(WINBINDD_DONT_ENV):"0","1") == 0) … … 24 48 (setenv(WINBINDD_DONT_ENV, "0", 1) == 0) 25 49 26 int winbind_write_sock(void *buffer, int count, int recursing, int need_priv); 27 int winbind_read_sock(void *buffer, int count); 28 void winbind_close_sock(void); 29 30 const char *nss_err_str(NSS_STATUS ret); 50 #endif /* _NSSWITCH_WINBIND_CLIENT_H_ */ -
vendor/current/nsswitch/winbind_nss_hpux.h
r414 r740 131 131 void *returnval; 132 132 int erange; 133 int h_errno; 133 /* 134 * h_errno is defined as function call macro for multithreaded applications 135 * in HP-UX. *this* h_errno is not used in the HP-UX codepath of our nss 136 * modules, so let's simply rename it: 137 */ 138 int h_errno_unused; 134 139 nss_status_t status; 135 140 } nss_XbyY_args_t; -
vendor/current/nsswitch/winbind_nss_linux.c
r414 r740 72 72 size_t buflen, int *errnop); 73 73 74 /************************************************************************* 75 ************************************************************************/ 76 77 #ifdef DEBUG_NSS 78 static const char *nss_err_str(NSS_STATUS ret) 79 { 80 switch (ret) { 81 case NSS_STATUS_TRYAGAIN: 82 return "NSS_STATUS_TRYAGAIN"; 83 case NSS_STATUS_SUCCESS: 84 return "NSS_STATUS_SUCCESS"; 85 case NSS_STATUS_NOTFOUND: 86 return "NSS_STATUS_NOTFOUND"; 87 case NSS_STATUS_UNAVAIL: 88 return "NSS_STATUS_UNAVAIL"; 89 #ifdef NSS_STATUS_RETURN 90 case NSS_STATUS_RETURN: 91 return "NSS_STATUS_RETURN"; 92 #endif 93 default: 94 return "UNKNOWN RETURN CODE!!!!!!!"; 95 } 96 } 97 #endif 98 74 99 /* Prototypes from wb_common.c */ 75 100 -
vendor/current/nsswitch/winbind_nss_solaris.h
r414 r740 23 23 #define _WINBIND_NSS_SOLARIS_H 24 24 25 /* Solaris has a broken nss_common header file containing C++ reserved names. */26 #ifndef __cplusplus27 #undef class28 #undef private29 #undef public30 #undef protected31 #undef template32 #undef this33 #undef new34 #undef delete35 #undef friend36 #endif37 38 25 #include <nss_common.h> 39 40 #ifndef __cplusplus41 #define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES42 #define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES43 #define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES44 #define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES45 #define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES46 #define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES47 #define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES48 #define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES49 #define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES50 #endif51 52 26 #include <nss_dbdefs.h> 53 27 #include <nsswitch.h> -
vendor/current/nsswitch/winbind_struct_protocol.h
r414 r740 51 51 * 23: added session_key to ccache_ntlm_auth response 52 52 * added WINBINDD_CCACHE_SAVE 53 * 24: Fill in num_entries WINBINDD_LIST_USERS and WINBINDD_LIST_GROUPS 54 * 25: removed WINBINDD_SET_HWM 55 * removed WINBINDD_SET_MAPPING 56 * removed WINBINDD_REMOVE_MAPPING 57 * 26: added WINBINDD_DC_INFO 58 * 27: added WINBINDD_LOOKUPSIDS 53 59 */ 54 #define WINBIND_INTERFACE_VERSION 2 360 #define WINBIND_INTERFACE_VERSION 27 55 61 56 62 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment. 57 63 On a 64bit Linux box, we have to support a constant structure size 58 between /lib/libnss_winbind.so.2 and /li 64/libnss_winbind.so.2.64 between /lib/libnss_winbind.so.2 and /lib64/libnss_winbind.so.2. 59 65 The easiest way to do this is to always use 8byte values for time_t. */ 60 66 … … 104 110 WINBINDD_LOOKUPNAME, 105 111 WINBINDD_LOOKUPRIDS, 112 WINBINDD_LOOKUPSIDS, 106 113 107 114 /* Lookup functions */ … … 115 122 WINBINDD_ALLOCATE_UID, 116 123 WINBINDD_ALLOCATE_GID, 117 WINBINDD_SET_MAPPING,118 WINBINDD_REMOVE_MAPPING,119 WINBINDD_SET_HWM,120 124 121 125 /* Miscellaneous other stuff */ … … 132 136 WINBINDD_GETDCNAME, /* Issue a GetDCName Request */ 133 137 WINBINDD_DSGETDCNAME, /* Issue a DsGetDCName Request */ 138 WINBINDD_DC_INFO, /* Which DC are we connected to? */ 134 139 135 140 WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */ … … 167 172 WINBINDD_DUAL_UID2SID, 168 173 WINBINDD_DUAL_GID2SID, 169 WINBINDD_DUAL_SET_MAPPING,170 WINBINDD_DUAL_REMOVE_MAPPING,171 WINBINDD_DUAL_SET_HWM,172 174 173 175 /* Wrapper around possibly blocking unix nss calls */ -
vendor/current/nsswitch/wins.c
r427 r740 20 20 21 21 #include "includes.h" 22 #include "nsswitch/winbind_nss.h" 23 22 24 #ifdef HAVE_NS_API_H 23 25 … … 38 40 39 41 static int initialised; 40 41 extern bool AllowDebugChange;42 42 43 43 NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, … … 46 46 char *buffer, size_t buflen, int *h_errnop); 47 47 48 /* Use our own create socket code so we don't recurse.... */49 50 static int wins_lookup_open_socket_in(void)51 {52 struct sockaddr_in sock;53 int val=1;54 int res;55 56 memset((char *)&sock,'\0',sizeof(sock));57 58 #ifdef HAVE_SOCK_SIN_LEN59 sock.sin_len = sizeof(sock);60 #endif61 sock.sin_port = 0;62 sock.sin_family = AF_INET;63 sock.sin_addr.s_addr = interpret_addr("0.0.0.0");64 res = socket(AF_INET, SOCK_DGRAM, 0);65 if (res == -1)66 return -1;67 68 if (setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) != 0) {69 close(res);70 return -1;71 }72 #ifdef SO_REUSEPORT73 if (setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) != 0) {74 close(res);75 return -1;76 }77 #endif /* SO_REUSEPORT */78 79 /* now we've got a socket - we need to bind it */80 81 if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) {82 close(res);83 return(-1);84 }85 86 set_socket_options(res,"SO_BROADCAST");87 88 return res;89 }90 91 92 48 static void nss_wins_init(void) 93 49 { 94 50 initialised = 1; 95 DEBUGLEVEL = 0;96 AllowDebugChange = False;51 load_case_tables_library(); 52 lp_set_cmdline("log level", "0"); 97 53 98 54 TimeInit(); 99 55 setup_logging("nss_wins",False); 100 load_case_tables();101 56 lp_load(get_dyn_CONFIGFILE(),True,False,False,True); 102 57 load_interfaces(); … … 105 60 static struct in_addr *lookup_byname_backend(const char *name, int *count) 106 61 { 107 int fd = -1;108 62 struct ip_service *address = NULL; 109 63 struct in_addr *ret = NULL; 110 int j , flags = 0;64 int j; 111 65 112 66 if (!initialised) { … … 127 81 return NULL; 128 82 } 129 *ret = ((struct sockaddr_in *)&address[0].ss)->sin_addr; 83 *ret = ((struct sockaddr_in *)(void *)&address[0].ss) 84 ->sin_addr; 130 85 free( address ); 131 86 return ret; 132 }133 134 fd = wins_lookup_open_socket_in();135 if (fd == -1) {136 return NULL;137 87 } 138 88 … … 142 92 struct sockaddr_storage ss; 143 93 struct sockaddr_storage *pss; 94 NTSTATUS status; 95 144 96 if (!bcast) { 145 97 continue; 146 98 } 147 99 in_addr_to_sockaddr_storage(&ss, *bcast); 148 pss = name_query(fd,name,0x00,True,True,&ss,count, &flags, NULL); 149 if (pss) { 100 status = name_query(name, 0x00, True, True, &ss, 101 NULL, &pss, count, NULL); 102 if (NT_STATUS_IS_OK(status) && (*count > 0)) { 150 103 if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) { 151 104 return NULL; 152 105 } 153 106 *ret = ((struct sockaddr_in *)pss)->sin_addr; 107 TALLOC_FREE(pss); 154 108 break; 155 109 } 156 110 } 157 111 158 close(fd);159 112 return ret; 160 113 } … … 162 115 #ifdef HAVE_NS_API_H 163 116 164 static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count) 165 { 166 int fd; 117 static struct node_status *lookup_byaddr_backend(char *addr, int *count) 118 { 167 119 struct sockaddr_storage ss; 168 120 struct nmb_name nname; 169 NODE_STATUS_STRUCT *status; 121 struct node_status *result; 122 NTSTATUS status; 170 123 171 124 if (!initialised) { 172 125 nss_wins_init(); 173 126 } 174 175 fd = wins_lookup_open_socket_in();176 if (fd == -1)177 return NULL;178 127 179 128 make_nmb_name(&nname, "*", 0); … … 181 130 return NULL; 182 131 } 183 status = node_status_query(fd, &nname, &ss, count, NULL); 184 185 close(fd); 186 return status; 132 status = node_status_query(NULL, &nname, &ss, &result, count, NULL); 133 if (!NT_STATUS_IS_OK(status)) { 134 return NULL; 135 } 136 137 return result; 187 138 } 188 139 … … 202 153 char *addr; 203 154 struct in_addr *ip_list; 204 NODE_STATUS_STRUCT*status;155 struct node_status *status; 205 156 int i, count, len, size; 206 157 char response[1024]; … … 234 185 size = strlen(key) + 1; 235 186 if (size > len) { 236 free(status);187 talloc_free(status); 237 188 return NSD_ERROR; 238 189 } … … 246 197 size = sizeof(status[i].name) + 1; 247 198 if (size > len) { 248 free(status);199 talloc_free(status); 249 200 return NSD_ERROR; 250 201 } … … 256 207 } 257 208 response[strlen(response)-1] = '\n'; 258 free(status);209 talloc_free(status); 259 210 } 260 211 } else if (StrCaseCmp(map,"hosts.byname") == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.