Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

Location:
vendor/current/nsswitch
Files:
5 added
7 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/nsswitch/libwbclient/libwbclient.h

    r414 r740  
    3232#include "nsswitch/winbind_struct_protocol.h"
    3333
    34 #include <talloc.h>
    35 
    3634/* Public headers */
    3735
    3836#include "wbclient.h"
    39 #include "wbc_async.h"
    4037
    4138/* Private headers */
  • vendor/current/nsswitch/libwbclient/tests/wbclient.c

    r414 r740  
    22   Unix SMB/CIFS implementation.
    33   SMB torture tester
    4    Copyright (C) Guenther Deschner 2009
     4   Copyright (C) Guenther Deschner 2009-2010
    55
    66   This program is free software; you can redistribute it and/or modify
     
    1818*/
    1919
    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"
    2125#include "nsswitch/libwbclient/wbclient.h"
    2226#include "torture/smbtorture.h"
    2327#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"
    2434
    2535#define WBC_ERROR_EQUAL(x,y) (x == y)
     
    4050        torture_assert_wbc_ok(tctx, wbcPing(),
    4151                "wbcPing failed");
     52
     53        return true;
     54}
     55
     56static 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");
    4262
    4363        return true;
     
    109129        torture_assert_str_equal(tctx, sid_string, sid_string2,
    110130                "sid strings differ");
     131        wbcFreeMemory(sid_string2);
    111132
    112133        return true;
     
    125146        torture_assert_str_equal(tctx, guid_string, guid_string2,
    126147                "guid strings differ");
     148        wbcFreeMemory(guid_string2);
    127149
    128150        return true;
     
    131153static bool test_wbc_domain_info(struct torture_context *tctx)
    132154{
    133         const char *domain_name = NULL;
    134155        struct wbcDomainInfo *info;
    135156        struct wbcInterfaceDetails *details;
     
    137158        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    138159                "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");
    141163        wbcFreeMemory(details);
    142164
    143         torture_assert_wbc_ok(tctx, wbcDomainInfo(domain_name, &info),
    144                 "wbcDomainInfo failed");
    145165        torture_assert(tctx, info,
    146166                "wbcDomainInfo returned NULL pointer");
     167        wbcFreeMemory(info);
    147168
    148169        return true;
     
    186207                torture_assert(tctx, name,
    187208                        "wbcLookupSid returned no name");
     209                wbcFreeMemory(domain);
     210                wbcFreeMemory(name);
    188211                torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
    189212                        "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);
    190220        }
     221        wbcFreeMemory(users);
    191222
    192223        return true;
     
    226257                        "wbcLookupSid returned no name");
    227258        }
     259        wbcFreeMemory(groups);
    228260
    229261        return true;
     
    265297                */
    266298        }
     299        wbcFreeMemory(domains);
    267300
    268301        return true;
     
    283316        torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info),
    284317                "wbcLookupDomainController failed");
     318        wbcFreeMemory(dc_info);
    285319
    286320        return true;
     
    301335        torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info),
    302336                "wbcLookupDomainControllerEx failed");
    303 
    304         return true;
    305 }
    306 
     337        wbcFreeMemory(dc_info);
     338
     339        return true;
     340}
     341
     342static 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
     361static 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
     378static 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
     405static 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
     440static 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(&params, &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(&params, &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
     480static bool test_wbc_authenticate_user(struct torture_context *tctx)
     481{
     482        return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
     483}
     484
     485static 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(&params, 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
     572static 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(&params, &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(&params.num_blobs, &params.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(&params, &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(&params, &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(&params.num_blobs, &params.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(&params, &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(&params.num_blobs, &params.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(&params, &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
     666static 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}
    307678
    308679struct torture_suite *torture_wbclient(void)
    309680{
    310         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "WBCLIENT");
     681        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient");
    311682
    312683        torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
     684        torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
    313685        torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
    314686        torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
     
    322694        torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc);
    323695        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);
    324710
    325711        return suite;
  • vendor/current/nsswitch/libwbclient/wbc_guid.c

    r414 r740  
    3030                       char **guid_string)
    3131{
    32         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     32        char *result;
    3333
    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;
    3737        }
     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;
    3848
    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;
    5450}
    5551
  • vendor/current/nsswitch/libwbclient/wbc_idmap.c

    r478 r740  
    55
    66   Copyright (C) Gerald (Jerry) Carter 2007
    7 
    87
    98   This library is free software; you can redistribute it and/or
     
    2524#include "replace.h"
    2625#include "libwbclient.h"
     26#include "../winbind_client.h"
    2727
    2828/* Convert a Windows SID to a Unix uid, allocating an uid if needed */
     
    3131        struct winbindd_request request;
    3232        struct winbindd_response response;
    33         char *sid_string = NULL;
    3433        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    3534
     
    4443        ZERO_STRUCT(response);
    4544
    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));
    5146
    5247        /* Make request */
     
    126121        struct winbindd_response response;
    127122        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    128         char *sid_string = NULL;
    129123
    130124        if (!sid || !pgid) {
     
    138132        ZERO_STRUCT(response);
    139133
    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));
    145135
    146136        /* Make request */
     
    159149}
    160150
     151
    161152/* Convert a Windows SID to a Unix gid if there already is a mapping */
    162153
     
    166157        return WBC_ERR_NOT_IMPLEMENTED;
    167158}
     159
    168160
    169161/* Convert a Unix gid to a Windows SID, allocating a SID if needed */
     
    271263#define _ID_TYPE_GID 2
    272264
    273 /* Set an user id mapping */
     265/* Set an user id mapping - not implemented any more */
    274266wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid)
    275267{
    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 */
    311272wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid)
    312273{
    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 */
    348278wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid)
    349279{
    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 */
    385284wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid)
    386285{
    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 */
    422290wbcErr wbcSetUidHwm(uid_t uid_hwm)
    423291{
    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 */
    447296wbcErr wbcSetGidHwm(gid_t gid_hwm)
    448297{
    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 */
     302wbcErr 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
     386wbc_err_invalid:
     387        wbc_status = WBC_ERR_INVALID_RESPONSE;
     388done:
     389        winbindd_free_response(&response);
     390        return wbc_status;
     391}
  • vendor/current/nsswitch/libwbclient/wbc_pam.c

    r597 r740  
    2626#include "replace.h"
    2727#include "libwbclient.h"
     28#include "../winbind_client.h"
    2829
    2930/* Authenticate a username/password pair */
     
    4748}
    4849
    49 static wbcErr wbc_create_auth_info(TALLOC_CTX *mem_ctx,
    50                                    const struct winbindd_response *resp,
     50static 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
     63static 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
     79static wbcErr wbc_create_auth_info(const struct winbindd_response *resp,
    5180                                   struct wbcAuthUserInfo **_i)
    5281{
     
    5887        uint32_t j;
    5988
    60         i = talloc(mem_ctx, struct wbcAuthUserInfo);
     89        i = (struct wbcAuthUserInfo *)wbcAllocateMemory(
     90                1, sizeof(struct wbcAuthUserInfo),
     91                wbcAuthUserInfoDestructor);
    6192        BAIL_ON_PTR_ERROR(i, wbc_status);
    6293
    6394        i->user_flags   = resp->data.auth.info3.user_flgs;
    6495
    65         i->account_name = talloc_strdup(i, resp->data.auth.info3.user_name);
     96        i->account_name = strdup(resp->data.auth.info3.user_name);
    6697        BAIL_ON_PTR_ERROR(i->account_name, wbc_status);
    6798        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);
    69100        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);
    71102        BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
    72103        i->dns_domain_name= NULL;
     
    90121        i->pass_must_change_time= resp->data.auth.info3.pass_must_change_time;
    91122
    92         i->logon_server = talloc_strdup(i, resp->data.auth.info3.logon_srv);
     123        i->logon_server = strdup(resp->data.auth.info3.logon_srv);
    93124        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);
    95126        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);
    97128        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);
    99130        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);
    101132        BAIL_ON_PTR_ERROR(i->home_drive, wbc_status);
    102133
     
    105136        i->num_sids     += resp->data.auth.info3.num_other_sids;
    106137
    107         i->sids = talloc_array(i, struct wbcSidWithAttr, i->num_sids);
     138        i->sids = (struct wbcSidWithAttr *)calloc(
     139                sizeof(struct wbcSidWithAttr), i->num_sids);
    108140        BAIL_ON_PTR_ERROR(i->sids, wbc_status);
    109141
     
    112144        BAIL_ON_WBC_ERROR(wbc_status);
    113145
    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 
    125146        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        }
    129152        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        }
    133158        sn++;
    134159
     
    158183                }
    159184
    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                }
    162190                sn++;
    163191        }
     
    203231        i = NULL;
    204232done:
    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
     237static void wbcAuthErrorInfoDestructor(void *ptr)
     238{
     239        struct wbcAuthErrorInfo *e = (struct wbcAuthErrorInfo *)ptr;
     240        free(e->nt_string);
     241        free(e->display_string);
     242}
     243
     244static wbcErr wbc_create_error_info(const struct winbindd_response *resp,
     245                                    struct wbcAuthErrorInfo **_e)
    212246{
    213247        wbcErr wbc_status = WBC_ERR_SUCCESS;
    214248        struct wbcAuthErrorInfo *e;
    215249
    216         e = talloc(mem_ctx, struct wbcAuthErrorInfo);
     250        e = (struct wbcAuthErrorInfo *)wbcAllocateMemory(
     251                1, sizeof(struct wbcAuthErrorInfo),
     252                wbcAuthErrorInfoDestructor);
    217253        BAIL_ON_PTR_ERROR(e, wbc_status);
    218254
    219255        e->nt_status = resp->data.auth.nt_status;
    220256        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);
    222258        BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);
    223259
    224         e->display_string = talloc_strdup(e, resp->data.auth.error_string);
     260        e->display_string = strdup(resp->data.auth.error_string);
    225261        BAIL_ON_PTR_ERROR(e->display_string, wbc_status);
    226262
     
    229265
    230266done:
    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
     271static wbcErr wbc_create_password_policy_info(const struct winbindd_response *resp,
    237272                                              struct wbcUserPasswordPolicyInfo **_i)
    238273{
     
    240275        struct wbcUserPasswordPolicyInfo *i;
    241276
    242         i = talloc(mem_ctx, struct wbcUserPasswordPolicyInfo);
     277        i = (struct wbcUserPasswordPolicyInfo *)wbcAllocateMemory(
     278                1, sizeof(struct wbcUserPasswordPolicyInfo), NULL);
    243279        BAIL_ON_PTR_ERROR(i, wbc_status);
    244280
     
    253289
    254290done:
    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
     295static void wbcLogonUserInfoDestructor(void *ptr)
     296{
     297        struct wbcLogonUserInfo *i = (struct wbcLogonUserInfo *)ptr;
     298        wbcFreeMemory(i->info);
     299        wbcFreeMemory(i->blobs);
     300}
     301
     302static wbcErr wbc_create_logon_info(struct winbindd_response *resp,
    261303                                    struct wbcLogonUserInfo **_i)
    262304{
     
    264306        struct wbcLogonUserInfo *i;
    265307
    266         i = talloc_zero(mem_ctx, struct wbcLogonUserInfo);
     308        i = (struct wbcLogonUserInfo *)wbcAllocateMemory(
     309                1, sizeof(struct wbcLogonUserInfo),
     310                wbcLogonUserInfoDestructor);
    267311        BAIL_ON_PTR_ERROR(i, wbc_status);
    268312
    269         wbc_status = wbc_create_auth_info(i, resp, &i->info);
     313        wbc_status = wbc_create_auth_info(resp, &i->info);
    270314        BAIL_ON_WBC_ERROR(wbc_status);
    271315
    272         if (resp->data.auth.krb5ccname &&
    273             strlen(resp->data.auth.krb5ccname)) {
     316        if (resp->data.auth.krb5ccname[0] != '\0') {
    274317                wbc_status = wbcAddNamedBlob(&i->num_blobs,
    275318                                             &i->blobs,
     
    281324        }
    282325
    283         if (resp->data.auth.unix_username &&
    284             strlen(resp->data.auth.unix_username)) {
     326        if (resp->data.auth.unix_username[0] != '\0') {
    285327                wbc_status = wbcAddNamedBlob(&i->num_blobs,
    286328                                             &i->blobs,
     
    295337        i = NULL;
    296338done:
    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
    304343
    305344/* Authenticate with more detailed information */
     
    437476                        request.flags |= WBFLAG_BIG_NTLMV2_BLOB;
    438477                        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);
    440480                        if (request.extra_data.data == NULL) {
    441481                                wbc_status = WBC_ERR_NO_MEMORY;
     
    471511        if (response.data.auth.nt_status != 0) {
    472512                if (error) {
    473                         wbc_status = wbc_create_error_info(NULL,
    474                                                            &response,
     513                        wbc_status = wbc_create_error_info(&response,
    475514                                                           error);
    476515                        BAIL_ON_WBC_ERROR(wbc_status);
     
    483522
    484523        if (info) {
    485                 wbc_status = wbc_create_auth_info(NULL,
    486                                                   &response,
    487                                                   info);
     524                wbc_status = wbc_create_auth_info(&response, info);
    488525                BAIL_ON_WBC_ERROR(wbc_status);
    489526        }
    490527
    491528done:
    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);
    496532
    497533        return wbc_status;
     
    520556        if (response.data.auth.nt_status != 0) {
    521557                if (error) {
    522                         wbc_status = wbc_create_error_info(NULL,
    523                                                            &response,
     558                        wbc_status = wbc_create_error_info(&response,
    524559                                                           error);
    525560                        BAIL_ON_WBC_ERROR(wbc_status);
     
    557592        if (response.data.auth.nt_status != 0) {
    558593                if (error) {
    559                         wbc_status = wbc_create_error_info(NULL,
    560                                                            &response,
     594                        wbc_status = wbc_create_error_info(&response,
    561595                                                           error);
    562596                        BAIL_ON_WBC_ERROR(wbc_status);
     
    601635        if (response.data.auth.nt_status != 0) {
    602636                if (error) {
    603                         wbc_status = wbc_create_error_info(NULL,
    604                                                            &response,
     637                        wbc_status = wbc_create_error_info(&response,
    605638                                                           error);
    606639                        BAIL_ON_WBC_ERROR(wbc_status);
     
    688721        if (response.data.auth.nt_status != 0) {
    689722                if (error) {
    690                         wbc_status = wbc_create_error_info(NULL,
    691                                                            &response,
     723                        wbc_status = wbc_create_error_info(&response,
    692724                                                           error);
    693725                        BAIL_ON_WBC_ERROR(wbc_status);
     
    758790        if (!params->account_name) {
    759791                wbc_status = WBC_ERR_INVALID_PARAM;
    760                 BAIL_ON_WBC_ERROR(wbc_status);
     792                goto done;
    761793        }
    762794
     
    782814                if (!params->account_name) {
    783815                        wbc_status = WBC_ERR_INVALID_PARAM;
    784                         BAIL_ON_WBC_ERROR(wbc_status);
     816                        goto done;
    785817                }
    786818
     
    806838                if (!params->account_name || !params->domain_name) {
    807839                        wbc_status = WBC_ERR_INVALID_PARAM;
    808                         BAIL_ON_WBC_ERROR(wbc_status);
     840                        goto done;
    809841                }
    810842
     
    812844                    !params->old_password.response.old_lm_hash_enc_data) {
    813845                        wbc_status = WBC_ERR_INVALID_PARAM;
    814                         BAIL_ON_WBC_ERROR(wbc_status);
     846                        goto done;
    815847                }
    816848
     
    818850                    params->old_password.response.old_lm_hash_enc_data) {
    819851                        wbc_status = WBC_ERR_INVALID_PARAM;
    820                         BAIL_ON_WBC_ERROR(wbc_status);
     852                        goto done;
    821853                }
    822854
     
    824856                    !params->old_password.response.old_nt_hash_enc_data) {
    825857                        wbc_status = WBC_ERR_INVALID_PARAM;
    826                         BAIL_ON_WBC_ERROR(wbc_status);
     858                        goto done;
    827859                }
    828860
     
    830862                    params->old_password.response.old_nt_hash_enc_data) {
    831863                        wbc_status = WBC_ERR_INVALID_PARAM;
    832                         BAIL_ON_WBC_ERROR(wbc_status);
     864                        goto done;
    833865                }
    834866
     
    836868                    !params->new_password.response.lm_data) {
    837869                        wbc_status = WBC_ERR_INVALID_PARAM;
    838                         BAIL_ON_WBC_ERROR(wbc_status);
     870                        goto done;
    839871                }
    840872
     
    842874                    params->new_password.response.lm_data) {
    843875                        wbc_status = WBC_ERR_INVALID_PARAM;
    844                         BAIL_ON_WBC_ERROR(wbc_status);
     876                        goto done;
    845877                }
    846878
     
    848880                    !params->new_password.response.nt_data) {
    849881                        wbc_status = WBC_ERR_INVALID_PARAM;
    850                         BAIL_ON_WBC_ERROR(wbc_status);
     882                        goto done;
    851883                }
    852884
     
    854886                    params->new_password.response.nt_data) {
    855887                        wbc_status = WBC_ERR_INVALID_PARAM;
    856                         BAIL_ON_WBC_ERROR(wbc_status);
     888                        goto done;
    857889                }
    858890
     
    900932        default:
    901933                wbc_status = WBC_ERR_INVALID_PARAM;
    902                 BAIL_ON_WBC_ERROR(wbc_status);
     934                goto done;
    903935                break;
    904936        }
     
    917949        if (response.data.auth.nt_status != 0) {
    918950                if (error) {
    919                         wbc_status = wbc_create_error_info(NULL,
    920                                                            &response,
     951                        wbc_status = wbc_create_error_info(&response,
    921952                                                           error);
    922953                        BAIL_ON_WBC_ERROR(wbc_status);
     
    926957
    927958        if (policy) {
    928                 wbc_status = wbc_create_password_policy_info(NULL,
    929                                                              &response,
     959                wbc_status = wbc_create_password_policy_info(&response,
    930960                                                             policy);
    931961                BAIL_ON_WBC_ERROR(wbc_status);
     
    9751005{
    9761006        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    977         int cmd = 0;
    9781007        struct winbindd_request request;
    9791008        struct winbindd_response response;
     
    10141043        /* Initialize request */
    10151044
    1016         cmd = WINBINDD_PAM_AUTH;
    10171045        request.flags = WBFLAG_PAM_INFO3_TEXT |
    10181046                        WBFLAG_PAM_USER_SESSION_KEY |
     
    10761104        }
    10771105
    1078         wbc_status = wbcRequestResponse(cmd,
     1106        wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH,
    10791107                                        &request,
    10801108                                        &response);
     
    10821110        if (response.data.auth.nt_status != 0) {
    10831111                if (error) {
    1084                         wbc_status = wbc_create_error_info(NULL,
    1085                                                            &response,
     1112                        wbc_status = wbc_create_error_info(&response,
    10861113                                                           error);
    10871114                        BAIL_ON_WBC_ERROR(wbc_status);
     
    10941121
    10951122        if (info) {
    1096                 wbc_status = wbc_create_logon_info(NULL,
    1097                                                    &response,
     1123                wbc_status = wbc_create_logon_info(&response,
    10981124                                                   info);
    10991125                BAIL_ON_WBC_ERROR(wbc_status);
     
    11011127
    11021128        if (policy) {
    1103                 wbc_status = wbc_create_password_policy_info(NULL,
    1104                                                              &response,
     1129                wbc_status = wbc_create_password_policy_info(&response,
    11051130                                                             policy);
    11061131                BAIL_ON_WBC_ERROR(wbc_status);
     
    11081133
    11091134done:
    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
     1140static void wbcCredentialCacheInfoDestructor(void *ptr)
     1141{
     1142        struct wbcCredentialCacheInfo *i =
     1143                (struct wbcCredentialCacheInfo *)ptr;
     1144        wbcFreeMemory(i->blobs);
    11141145}
    11151146
     
    11871218
    11881219        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);
    11911221                if (request.extra_data.data == NULL) {
    11921222                        status = WBC_ERR_NO_MEMORY;
     
    12111241        }
    12121242
    1213         result = talloc(NULL, struct wbcCredentialCacheInfo);
     1243        result = (struct wbcCredentialCacheInfo *)wbcAllocateMemory(
     1244                1, sizeof(struct wbcCredentialCacheInfo),
     1245                wbcCredentialCacheInfoDestructor);
    12141246        if (result == NULL) {
    12151247                status = WBC_ERR_NO_MEMORY;
     
    12171249        }
    12181250        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;
    12241252        status = wbcAddNamedBlob(&result->num_blobs, &result->blobs,
    12251253                                 "auth_blob", 0,
     
    12371265        }
    12381266
    1239         if (response.extra_data.data)
    1240                 free(response.extra_data.data);
    12411267        *info = result;
    1242         return WBC_ERR_SUCCESS;
    1243 
     1268        result = NULL;
     1269        status = WBC_ERR_SUCCESS;
    12441270fail:
    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);
    12491274        return status;
    12501275}
  • vendor/current/nsswitch/libwbclient/wbc_pwd.c

    r414 r740  
    2525#include "replace.h"
    2626#include "libwbclient.h"
     27#include "../winbind_client.h"
    2728
    2829/** @brief The maximum number of pwent structs to get from winbindd
     
    4041 **/
    4142
     43static 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
    4253static struct passwd *copy_passwd_entry(struct winbindd_pw *p)
    4354{
    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
     86fail:
     87        wbcFreeMemory(pw);
     88        return NULL;
    7589}
    7690
     
    7892 *
    7993 **/
     94
     95static 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}
    80113
    81114static struct group *copy_group_entry(struct winbindd_gr *g,
    82115                                      char *mem_buf)
    83116{
    84         struct group *grp = NULL;
    85         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     117        struct group *gr = NULL;
    86118        int i;
    87119        char *mem_p, *mem_q;
    88120
    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        }
    101141
    102142        mem_p = mem_q = mem_buf;
    103143        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) {
    105146                        *mem_q = '\0';
    106147                }
    107148
    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                }
    110153
    111154                if (mem_q == NULL) {
     
    115158                mem_p = mem_q + 1;
    116159        }
    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
     164fail:
     165        wbcFreeMemory(gr);
     166        return NULL;
    128167}
    129168
     
    198237        struct winbindd_request request;
    199238        struct winbindd_response response;
    200         char * sid_string = NULL;
    201239
    202240        if (!pwd) {
     
    205243        }
    206244
    207         wbc_status = wbcSidToString(sid, &sid_string);
    208         BAIL_ON_WBC_ERROR(wbc_status);
    209 
    210245        /* Initialize request */
    211246
     
    213248        ZERO_STRUCT(response);
    214249
    215         strncpy(request.data.sid, sid_string, sizeof(request.data.sid));
     250        wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
    216251
    217252        wbc_status = wbcRequestResponse(WINBINDD_GETPWSID,
     
    224259
    225260 done:
    226         if (sid_string) {
    227                 wbcFreeMemory(sid_string);
    228         }
    229 
    230261        return wbc_status;
    231262}
     
    262293
    263294 done:
    264         if (response.extra_data.data)
    265                 free(response.extra_data.data);
     295        winbindd_free_response(&response);
    266296
    267297        return wbc_status;
     
    297327
    298328 done:
    299         if (response.extra_data.data)
    300                 free(response.extra_data.data);
     329        winbindd_free_response(&response);
    301330
    302331        return wbc_status;
     
    325354        if (pw_cache_size > 0) {
    326355                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);
    330357        }
    331358
     
    347374        if (pw_cache_size > 0) {
    348375                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);
    352377        }
    353378
     
    376401        pw_cache_idx = 0;
    377402
    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);
    382404
    383405        ZERO_STRUCT(request);
     
    427449        if (gr_cache_size > 0) {
    428450                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);
    432452        }
    433453
     
    449469        if (gr_cache_size > 0) {
    450470                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);
    454472        }
    455473
     
    479497        gr_cache_idx = 0;
    480498
    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);
    485500
    486501        ZERO_STRUCT(request);
     
    528543        gr_cache_idx = 0;
    529544
    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);
    534547
    535548        ZERO_STRUCT(request);
     
    587600        BAIL_ON_WBC_ERROR(wbc_status);
    588601
    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);
    590604        BAIL_ON_PTR_ERROR(groups, wbc_status);
    591605
     
    601615
    602616 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  
    55
    66   Copyright (C) Gerald (Jerry) Carter 2007
     7   Copyright (C) Volker Lendecke 2010
    78
    89
     
    2526#include "replace.h"
    2627#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. */
     33int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen)
     34{
    3435        uint32_t id_auth;
    35         int i;
    36         char *tmp = NULL;
     36        int i, ofs;
    3737
    3838        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         */
    4247
    4348        id_auth = sid->id_auth[5] +
     
    4651                (sid->id_auth[2] << 24);
    4752
    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 */
     64wbcErr 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;
    6889}
    6990
     
    132153                sid->sub_auths[sid->num_auths++] = x;
    133154
    134                 if ((*q!='-') || (*q=='\0'))
     155                if (*q != '-') {
    135156                        break;
     157                }
    136158                p = q + 1;
    137159        }
     
    150172
    151173}
     174
    152175
    153176/* Convert a domain and name to SID */
     
    194217}
    195218
     219
    196220/* Convert a SID to a domain and name */
    197221wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
     
    203227        struct winbindd_response response;
    204228        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;
    209230
    210231        if (!sid) {
    211                 wbc_status = WBC_ERR_INVALID_PARAM;
    212                 BAIL_ON_WBC_ERROR(wbc_status);
     232                return WBC_ERR_INVALID_PARAM;
    213233        }
    214234
     
    218238        ZERO_STRUCT(response);
    219239
    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));
    227241
    228242        /* Make request */
    229243
    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        }
    234249
    235250        /* Copy out result */
    236251
    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        }
    245275        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 
     276done:
     277        wbcFreeMemory(name);
     278        wbcFreeMemory(domain);
     279        return wbc_status;
     280}
     281
     282static 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
     293static 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
     303wbcErr 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
     456wbc_err_invalid:
     457        wbc_status = WBC_ERR_INVALID_RESPONSE;
     458fail:
     459        winbindd_free_response(&response);
     460        wbcFreeMemory(domains);
     461        wbcFreeMemory(names);
    281462        return wbc_status;
    282463}
     
    296477        struct winbindd_request request;
    297478        struct winbindd_response response;
    298         char *sid_string = NULL;
    299479        char *domain_name = NULL;
    300480        const char **names = NULL;
     
    312492        }
    313493
    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));
    319495
    320496        /* Even if all the Rids were of maximum 32bit values,
     
    325501        ridbuf_size = (sizeof(char)*11) * num_rids + 1;
    326502
    327         ridlist = talloc_zero_array(NULL, char, ridbuf_size);
     503        ridlist = (char *)malloc(ridbuf_size);
    328504        BAIL_ON_PTR_ERROR(ridlist, wbc_status);
    329505
    330506        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;
    340513
    341514        request.extra_data.data = ridlist;
    342         request.extra_len = strlen(ridlist)+1;
     515        request.extra_len = len;
    343516
    344517        wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS,
    345518                                        &request,
    346519                                        &response);
    347         talloc_free(ridlist);
     520        free(ridlist);
    348521        BAIL_ON_WBC_ERROR(wbc_status);
    349522
    350         domain_name = talloc_strdup(NULL, response.data.domain_name);
     523        domain_name = wbcStrDup(response.data.domain_name);
    351524        BAIL_ON_PTR_ERROR(domain_name, wbc_status);
    352525
    353         names = talloc_array(NULL, const char*, num_rids);
     526        names = wbcAllocateStringArray(num_rids);
    354527        BAIL_ON_PTR_ERROR(names, wbc_status);
    355528
    356         types = talloc_array(NULL, enum wbcSidType, num_rids);
     529        types = (enum wbcSidType *)wbcAllocateMemory(
     530                num_rids, sizeof(enum wbcSidType), NULL);
    357531        BAIL_ON_PTR_ERROR(types, wbc_status);
    358532
     
    364538                if (*p == '\0') {
    365539                        wbc_status = WBC_ERR_INVALID_RESPONSE;
    366                         BAIL_ON_WBC_ERROR(wbc_status);
     540                        goto done;
    367541                }
    368542
     
    371545                if (*q != ' ') {
    372546                        wbc_status = WBC_ERR_INVALID_RESPONSE;
    373                         BAIL_ON_WBC_ERROR(wbc_status);
     547                        goto done;
    374548                }
    375549
     
    378552                if ((q = strchr(p, '\n')) == NULL) {
    379553                        wbc_status = WBC_ERR_INVALID_RESPONSE;
    380                         BAIL_ON_WBC_ERROR(wbc_status);
     554                        goto done;
    381555                }
    382556
    383557                *q = '\0';
    384558
    385                 names[i] = talloc_strdup(names, p);
     559                names[i] = strdup(p);
    386560                BAIL_ON_PTR_ERROR(names[i], wbc_status);
    387561
     
    391565        if (*p != '\0') {
    392566                wbc_status = WBC_ERR_INVALID_RESPONSE;
    393                 BAIL_ON_WBC_ERROR(wbc_status);
     567                goto done;
    394568        }
    395569
     
    397571
    398572 done:
    399         if (response.extra_data.data) {
    400                 free(response.extra_data.data);
    401         }
     573        winbindd_free_response(&response);
    402574
    403575        if (WBC_ERROR_IS_OK(wbc_status)) {
     
    407579        }
    408580        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);
    415584        }
    416585
     
    428597        struct winbindd_request request;
    429598        struct winbindd_response response;
    430         char *sid_string = NULL;
    431599        struct wbcDomainSid *sids = NULL;
    432600        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    443611        }
    444612
    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));
    450614
    451615        if (domain_groups_only) {
     
    466630        }
    467631
    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);
    470635        BAIL_ON_PTR_ERROR(sids, wbc_status);
    471636
     
    487652
    488653 done:
    489         if (response.extra_data.data) {
    490                 free(response.extra_data.data);
    491         }
     654        winbindd_free_response(&response);
    492655        if (sids) {
    493                 talloc_free(sids);
     656                wbcFreeMemory(sids);
    494657        }
    495658
     
    519682        struct winbindd_request request;
    520683        struct winbindd_response response;
    521         char *sid_string = NULL;
    522         ssize_t sid_len;
    523684        ssize_t extra_data_len = 0;
    524685        char * extra_data = NULL;
     
    535696        if (!dom_sid) {
    536697                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);
    551707        if (!extra_data) {
    552708                wbc_status = WBC_ERR_NO_MEMORY;
    553                 BAIL_ON_WBC_ERROR(wbc_status);
     709                goto done;
    554710        }
    555711
    556712        /* Build the sid list */
    557713        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));
    566718
    567719                if (buflen < extra_data_len + sid_len + 2) {
    568720                        buflen *= 2;
    569                         extra_data = talloc_realloc(NULL, extra_data,
    570                             char, buflen);
     721                        extra_data = (char *)realloc(extra_data, buflen);
    571722                        if (!extra_data) {
    572723                                wbc_status = WBC_ERR_NO_MEMORY;
     
    575726                }
    576727
    577                 strncpy(&extra_data[extra_data_len], sid_string,
     728                strncpy(&extra_data[extra_data_len], sid_str,
    578729                        buflen - extra_data_len);
    579730                extra_data_len += sid_len;
     
    581732                extra_data[extra_data_len] = '\0';
    582733        }
     734        extra_data_len += 1;
    583735
    584736        request.extra_data.data = extra_data;
     
    593745            !response.extra_data.data) {
    594746                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);
    600752        BAIL_ON_PTR_ERROR(sids, wbc_status);
    601753
     
    619771
    620772 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);
    634776        return wbc_status;
    635777}
     
    663805        BAIL_ON_WBC_ERROR(wbc_status);
    664806
     807        users = wbcAllocateStringArray(response.data.num_entries);
     808        if (users == NULL) {
     809                return WBC_ERR_NO_MEMORY;
     810        }
     811
    665812        /* Look through extra data */
    666813
    667814        next = (const char *)response.extra_data.data;
    668815        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
    672827                if (k) {
    673828                        k[0] = '\0';
     
    677832                }
    678833
    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);
    686835                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;
    692844        *_users = users;
    693845        users = NULL;
     
    695847
    696848 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);
    703851        return wbc_status;
    704852}
     
    731879        BAIL_ON_WBC_ERROR(wbc_status);
    732880
     881        groups = wbcAllocateStringArray(response.data.num_entries);
     882        if (groups == NULL) {
     883                return WBC_ERR_NO_MEMORY;
     884        }
     885
    733886        /* Look through extra data */
    734887
    735888        next = (const char *)response.extra_data.data;
    736889        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
    740901                if (k) {
    741902                        k[0] = '\0';
     
    745906                }
    746907
    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);
    754909                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;
    760918        *_groups = groups;
    761919        groups = NULL;
     
    763921
    764922 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);
    771925        return wbc_status;
    772926}
     
    797951                wbcFreeMemory(name);
    798952
    799                 name = talloc_strdup(NULL, pwd->pw_gecos);
     953                name = wbcStrDup(pwd->pw_gecos);
     954                wbcFreeMemory(pwd);
    800955                BAIL_ON_PTR_ERROR(name, wbc_status);
    801956        }
  • vendor/current/nsswitch/libwbclient/wbc_util.c

    r414 r740  
    22   Unix SMB/CIFS implementation.
    33
    4    Winbind client API
     4   Winbind client asynchronous API, utility functions
    55
    66   Copyright (C) Gerald (Jerry) Carter 2007-2008
     
    2525#include "replace.h"
    2626#include "libwbclient.h"
    27 
    28 
     27#include "../winbind_client.h"
    2928
    3029/** @brief Ping winbindd to see if the daemon is running
     
    3231 * @return #wbcErr
    3332 **/
    34 
    3533wbcErr wbcPing(void)
    3634{
     
    4543        return wbcRequestResponse(WINBINDD_PING, &request, &response);
    4644}
     45
     46static 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 */
    4762
    4863wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
     
    5974        ZERO_STRUCT(response);
    6075
    61         info = talloc(NULL, struct wbcInterfaceDetails);
     76        info = (struct wbcInterfaceDetails *)wbcAllocateMemory(
     77                1, sizeof(struct wbcInterfaceDetails),
     78                wbcInterfaceDetailsDestructor);
    6279        BAIL_ON_PTR_ERROR(info, wbc_status);
    6380
     
    7188        BAIL_ON_WBC_ERROR(wbc_status);
    7289
    73         info->winbind_version = talloc_strdup(info,
    74                                               response.data.info.samba_version);
     90        info->winbind_version = strdup(response.data.info.samba_version);
    7591        BAIL_ON_PTR_ERROR(info->winbind_version, wbc_status);
    7692        info->winbind_separator = response.data.info.winbind_separator;
     
    8096        BAIL_ON_WBC_ERROR(wbc_status);
    8197
    82         info->netbios_name = talloc_strdup(info,
    83                                            response.data.netbios_name);
     98        info->netbios_name = strdup(response.data.netbios_name);
    8499        BAIL_ON_PTR_ERROR(info->netbios_name, wbc_status);
    85100
     
    88103        BAIL_ON_WBC_ERROR(wbc_status);
    89104
    90         info->netbios_domain = talloc_strdup(info,
    91                                         response.data.domain_name);
     105        info->netbios_domain = strdup(response.data.domain_name);
    92106        BAIL_ON_PTR_ERROR(info->netbios_domain, wbc_status);
    93107
     
    102116
    103117        if (domain) {
    104                 info->dns_domain = talloc_strdup(info,
    105                                                  domain->dns_name);
     118                info->dns_domain = strdup(domain->dns_name);
    106119                wbcFreeMemory(domain);
    107120                BAIL_ON_PTR_ERROR(info->dns_domain, wbc_status);
     
    116129
    117130done:
    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
     135static 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
    124150wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
    125151{
     
    147173        BAIL_ON_WBC_ERROR(wbc_status);
    148174
    149         info = talloc(NULL, struct wbcDomainInfo);
     175        info = (struct wbcDomainInfo *)wbcAllocateMemory(
     176                1, sizeof(struct wbcDomainInfo), wbcDomainInfoDestructor);
    150177        BAIL_ON_PTR_ERROR(info, wbc_status);
    151178
    152         info->short_name = talloc_strdup(info,
    153                                          response.data.domain_info.name);
     179        info->short_name = strdup(response.data.domain_info.name);
    154180        BAIL_ON_PTR_ERROR(info->short_name, wbc_status);
    155181
    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);
    158183        BAIL_ON_PTR_ERROR(info->dns_name, wbc_status);
    159184
     
    170195
    171196        *dinfo = info;
     197        info = NULL;
    172198
    173199        wbc_status = WBC_ERR_SUCCESS;
    174200
    175201 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 */
     207wbcErr 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;
     277done:
     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}
    183292
    184293/* Resolve a NetbiosName via WINS */
     
    205314        /* Display response */
    206315
    207         ipaddr = talloc_strdup(NULL, response.data.winsresp);
     316        ipaddr = wbcStrDup(response.data.winsresp);
    208317        BAIL_ON_PTR_ERROR(ipaddr, wbc_status);
    209318
     
    238347        /* Display response */
    239348
    240         name_str = talloc_strdup(NULL, response.data.winsresp);
     349        name_str = wbcStrDup(response.data.winsresp);
    241350        BAIL_ON_PTR_ERROR(name_str, wbc_status);
    242351
     
    251360 */
    252361
    253 static wbcErr process_domain_info_string(TALLOC_CTX *ctx,
    254                                          struct wbcDomainInfo *info,
     362static wbcErr process_domain_info_string(struct wbcDomainInfo *info,
    255363                                         char *info_string)
    256364{
     
    258366        char *r = NULL;
    259367        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);
    267368
    268369        r = info_string;
     
    276377        s++;
    277378
    278         info->short_name = talloc_strdup(ctx, r);
     379        info->short_name = strdup(r);
    279380        BAIL_ON_PTR_ERROR(info->short_name, wbc_status);
    280381
     
    289390        s++;
    290391
    291         info->dns_name = talloc_strdup(ctx, r);
     392        info->dns_name = strdup(r);
    292393        BAIL_ON_PTR_ERROR(info->dns_name, wbc_status);
    293394
     
    382483}
    383484
     485static 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
    384496/* Enumerate the domain trusts known by Winbind */
    385497wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
     
    388500        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    389501        char *p = NULL;
    390         char *q = NULL;
    391502        char *extra_data = NULL;
    392         int count = 0;
    393503        struct wbcDomainInfo *d_list = NULL;
    394504        int i = 0;
     
    418528        }
    419529
    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);
    432533        BAIL_ON_PTR_ERROR(d_list, wbc_status);
    433534
     
    439540        /* Outer loop processes the list of domain information */
    440541
    441         for (i=0; i<count && p; i++) {
     542        for (i=0; i<response.data.num_entries && p; i++) {
    442543                char *next = strchr(p, '\n');
    443544
     
    447548                }
    448549
    449                 wbc_status = process_domain_info_string(d_list, &d_list[i], p);
     550                wbc_status = process_domain_info_string(&d_list[i], p);
    450551                BAIL_ON_WBC_ERROR(wbc_status);
    451552
     
    454555
    455556        *domains = d_list;
     557        d_list = NULL;
    456558        *num_domains = i;
    457559
    458560 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
     567static void wbcDomainControllerInfoDestructor(void *ptr)
     568{
     569        struct wbcDomainControllerInfo *i =
     570                (struct wbcDomainControllerInfo *)ptr;
     571        free(i->dc_name);
    467572}
    468573
     
    492597        request.flags = flags;
    493598
    494         dc = talloc(NULL, struct wbcDomainControllerInfo);
     599        dc = (struct wbcDomainControllerInfo *)wbcAllocateMemory(
     600                 1, sizeof(struct wbcDomainControllerInfo),
     601                wbcDomainControllerInfoDestructor);
    495602        BAIL_ON_PTR_ERROR(dc, wbc_status);
    496603
     
    502609        BAIL_ON_WBC_ERROR(wbc_status);
    503610
    504         dc->dc_name = talloc_strdup(dc, response.data.dsgetdcname.dc_unc);
     611        dc->dc_name = strdup(response.data.dsgetdcname.dc_unc);
    505612        BAIL_ON_PTR_ERROR(dc->dc_name, wbc_status);
    506613
    507614        *dc_info = dc;
     615        dc = NULL;
    508616
    509617done:
    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
     622static 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
     635static wbcErr wbc_create_domain_controller_info_ex(const struct winbindd_response *resp,
    519636                                                   struct wbcDomainControllerInfoEx **_i)
    520637{
     
    523640        struct wbcGuid guid;
    524641
    525         i = talloc(mem_ctx, struct wbcDomainControllerInfoEx);
     642        i = (struct wbcDomainControllerInfoEx *)wbcAllocateMemory(
     643                1, sizeof(struct wbcDomainControllerInfoEx),
     644                wbcDomainControllerInfoExDestructor);
    526645        BAIL_ON_PTR_ERROR(i, wbc_status);
    527646
    528         i->dc_unc = talloc_strdup(i, resp->data.dsgetdcname.dc_unc);
     647        i->dc_unc = strdup(resp->data.dsgetdcname.dc_unc);
    529648        BAIL_ON_PTR_ERROR(i->dc_unc, wbc_status);
    530649
    531         i->dc_address = talloc_strdup(i, resp->data.dsgetdcname.dc_address);
     650        i->dc_address = strdup(resp->data.dsgetdcname.dc_address);
    532651        BAIL_ON_PTR_ERROR(i->dc_address, wbc_status);
    533652
     
    536655        wbc_status = wbcStringToGuid(resp->data.dsgetdcname.domain_guid, &guid);
    537656        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));
    539659                BAIL_ON_PTR_ERROR(i->domain_guid, wbc_status);
    540660
    541661                *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);
    547665        BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
    548666
    549667        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);
    552669                BAIL_ON_PTR_ERROR(i->forest_name, wbc_status);
    553         } else {
    554                 i->forest_name = NULL;
    555670        }
    556671
     
    558673
    559674        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);
    562676                BAIL_ON_PTR_ERROR(i->dc_site_name, wbc_status);
    563         } else {
    564                 i->dc_site_name = NULL;
    565677        }
    566678
    567679        if (resp->data.dsgetdcname.client_site_name[0] != '\0') {
    568                 i->client_site_name = talloc_strdup(i,
     680                i->client_site_name = strdup(
    569681                        resp->data.dsgetdcname.client_site_name);
    570682                BAIL_ON_PTR_ERROR(i->client_site_name, wbc_status);
    571         } else {
    572                 i->client_site_name = NULL;
    573683        }
    574684
     
    577687
    578688done:
    579         talloc_free(i);
     689        if (i != NULL) {
     690                wbcFreeMemory(i);
     691        }
    580692        return wbc_status;
    581693}
     
    632744
    633745        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,
    636747                                                                  dc_info);
    637748                BAIL_ON_WBC_ERROR(wbc_status);
     
    643754}
    644755
     756static 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
    645767/* Initialize a named blob and add to list of blobs */
    646768wbcErr wbcAddNamedBlob(size_t *num_blobs,
    647                        struct wbcNamedBlob **blobs,
     769                       struct wbcNamedBlob **pblobs,
    648770                       const char *name,
    649771                       uint32_t flags,
     
    652774{
    653775        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;
    669819
    670820        wbc_status = WBC_ERR_SUCCESS;
    671821done:
    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  
    2424
    2525#include "replace.h"
    26 #include "talloc.h"
    27 #include "tevent.h"
    2826#include "libwbclient.h"
    2927
     
    3735                                          struct winbindd_response *response);
    3836
    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/*
    4938 result == NSS_STATUS_UNAVAIL: winbind not around
    5039 result == NSS_STATUS_NOTFOUND: winbind around, but domain missing
     
    5746
    5847 --Volker
    59 **********************************************************************/
     48*/
    6049
    6150static wbcErr wbcRequestResponseInt(
     
    9281}
    9382
     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 */
    9492wbcErr wbcRequestResponse(int cmd,
    9593                          struct winbindd_request *request,
     
    150148}
    151149
     150#define WBC_MAGIC (0x7a2b0e1e)
     151#define WBC_MAGIC_FREE (0x875634fe)
     152
     153struct wbcMemPrefix {
     154        uint32_t magic;
     155        void (*destructor)(void *ptr);
     156};
     157
     158static size_t wbcPrefixLen(void)
     159{
     160        size_t result = sizeof(struct wbcMemPrefix);
     161        return (result + 15) & ~15;
     162}
     163
     164static struct wbcMemPrefix *wbcMemToPrefix(void *ptr)
     165{
     166        return (struct wbcMemPrefix *)(((char *)ptr) - wbcPrefixLen());
     167}
     168
     169void *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
    152189/* Free library allocated memory */
    153190void wbcFreeMemory(void *p)
    154191{
    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);
    158209        return;
    159210}
    160211
     212char *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
     226static void wbcStringArrayDestructor(void *ptr)
     227{
     228        char **p = (char **)ptr;
     229        while (*p != NULL) {
     230                free(*p);
     231                p += 1;
     232        }
     233}
     234
     235const char **wbcAllocateStringArray(int num_strings)
     236{
     237        return (const char **)wbcAllocateMemory(
     238                num_strings + 1, sizeof(const char *),
     239                wbcStringArrayDestructor);
     240}
     241
    161242wbcErr wbcLibraryDetails(struct wbcLibraryDetails **_details)
    162243{
    163         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    164244        struct wbcLibraryDetails *info;
    165245
    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        }
    168252
    169253        info->major_version = WBCLIENT_MAJOR_VERSION;
    170254        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;
    174256
    175257        *_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  
    6666 *  0.4: Added wbcSidTypeString()
    6767 *  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()
    6871 **/
    6972#define WBCLIENT_MAJOR_VERSION 0
    70 #define WBCLIENT_MINOR_VERSION 5
     73#define WBCLIENT_MINOR_VERSION 8
    7174#define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
    7275struct wbcLibraryDetails {
     
    8285struct wbcInterfaceDetails {
    8386        uint32_t interface_version;
    84         const char *winbind_version;
     87        char *winbind_version;
    8588        char winbind_separator;
    86         const char *netbios_name;
    87         const char *netbios_domain;
    88         const char *dns_domain;
     89        char *netbios_name;
     90        char *netbios_domain;
     91        char *dns_domain;
    8992};
    9093
     
    191194#define WBC_DOMINFO_TRUSTTYPE_IN_FOREST  0x00000002
    192195#define WBC_DOMINFO_TRUSTTYPE_EXTERNAL   0x00000003
    193 
    194196
    195197/**
     
    430432
    431433enum 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
    437450
    438451/**
     
    519532const char* wbcSidTypeString(enum wbcSidType type);
    520533
     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 */
     545int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen);
     546
    521547/**
    522548 * @brief Convert a binary SID to a character string
     
    611637                    char **name,
    612638                    enum wbcSidType *name_type);
     639
     640struct wbcTranslatedName {
     641        enum wbcSidType type;
     642        char *name;
     643        int domain_index;
     644};
     645
     646wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
     647                     struct wbcDomainInfo **domains, int *num_domains,
     648                     struct wbcTranslatedName **names);
    613649
    614650/**
     
    758794                        struct wbcDomainSid *sid);
    759795
     796enum wbcIdType {
     797        WBC_ID_TYPE_NOT_SPECIFIED,
     798        WBC_ID_TYPE_UID,
     799        WBC_ID_TYPE_GID
     800};
     801
     802union wbcUnixIdContainer {
     803        uid_t uid;
     804        gid_t gid;
     805};
     806
     807struct 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 **/
     822wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
     823                        struct wbcUnixId *ids);
     824
    760825/**
    761826 * @brief Obtain a new uid from Winbind
     
    783848 *
    784849 * @return #wbcErr
     850 *
     851 * @deprecated      This method is not impemented any more and should
     852 *                  be removed in the next major version change.
    785853 **/
    786854wbcErr wbcSetUidMapping(uid_t uid, const struct wbcDomainSid *sid);
     
    793861 *
    794862 * @return #wbcErr
     863 *
     864 * @deprecated      This method is not impemented any more and should
     865 *                  be removed in the next major version change.
    795866 **/
    796867wbcErr wbcSetGidMapping(gid_t gid, const struct wbcDomainSid *sid);
     
    803874 *
    804875 * @return #wbcErr
     876 *
     877 * @deprecated      This method is not impemented any more and should
     878 *                  be removed in the next major version change.
    805879 **/
    806880wbcErr wbcRemoveUidMapping(uid_t uid, const struct wbcDomainSid *sid);
     
    813887 *
    814888 * @return #wbcErr
     889 *
     890 * @deprecated      This method is not impemented any more and should
     891 *                  be removed in the next major version change.
    815892 **/
    816893wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid);
     
    822899 *
    823900 * @return #wbcErr
     901 *
     902 * @deprecated      This method is not impemented any more and should
     903 *                  be removed in the next major version change.
    824904 **/
    825905wbcErr wbcSetUidHwm(uid_t uid_hwm);
     
    831911 *
    832912 * @return #wbcErr
     913 *
     914 * @deprecated      This method is not impemented any more and should
     915 *                  be removed in the next major version change.
    833916 **/
    834917wbcErr wbcSetGidHwm(gid_t gid_hwm);
     
    9711054 * @brief Lookup the current status of a trusted domain
    9721055 *
    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.
    9751059 *
    9761060 * @return #wbcErr
    9771061 **/
    9781062wbcErr 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 **/
     1076wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
     1077                 const char ***dc_names, const char ***dc_ips);
    9801078
    9811079/**
  • vendor/current/nsswitch/libwbclient/wbclient_internal.h

    r478 r740  
    3333                              struct winbindd_response *response);
    3434
     35void *wbcAllocateMemory(size_t nelem, size_t elsize,
     36                        void (*destructor)(void *ptr));
     37
     38char *wbcStrDup(const char *str);
     39const char **wbcAllocateStringArray(int num_strings);
     40
    3541#endif      /* _WBCLIENT_INTERNAL_H */
  • vendor/current/nsswitch/nsstest.c

    r414 r740  
    33   nss tester for winbindd
    44   Copyright (C) Andrew Tridgell 2001
     5   Copyright (C) Tim Potter 2003
    56
    67   This program is free software; you can redistribute it and/or modify
     
    1819*/
    1920
    20 #include "includes.h"
    21 
     21#include "replace.h"
    2222#include "nsswitch/nsstest.h"
    2323
     
    3030static void *find_fn(const char *name)
    3131{
    32         char s[1024];
     32        char *s;
    3333        static void *h;
    3434        void *res;
    3535
    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        }
    3739
    3840        if (!h) {
     
    4648        if (!res) {
    4749                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);
    5055        return res;
    5156}
     
    6267{
    6368        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");
    6572        static struct passwd pwd;
    6673        static char buf[1000];
    6774        NSS_STATUS status;
    6875
     76        if (!_nss_getpwent_r)
     77                return NULL;
     78
    6979        status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno);
    7080        if (status == NSS_STATUS_NOTFOUND) {
     
    8191{
    8292        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");
    8496        static struct passwd pwd;
    8597        static char buf[1000];
    8698        NSS_STATUS status;
    8799
     100        if (!_nss_getpwnam_r)
     101                return NULL;
     102
    88103        status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno);
    89104        if (status == NSS_STATUS_NOTFOUND) {
     
    100115{
    101116        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");
    103120        static struct passwd pwd;
    104121        static char buf[1000];
    105122        NSS_STATUS status;
    106123
     124        if (!_nss_getpwuid_r)
     125                return NULL;
     126
    107127        status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno);
    108128        if (status == NSS_STATUS_NOTFOUND) {
     
    118138static void nss_setpwent(void)
    119139{
    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
    122147        status = _nss_setpwent();
    123148        if (status != NSS_STATUS_SUCCESS) {
     
    128153static void nss_endpwent(void)
    129154{
    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
    132162        status = _nss_endpwent();
    133163        if (status != NSS_STATUS_SUCCESS) {
     
    140170{
    141171        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");
    143175        static struct group grp;
    144176        static char *buf;
     
    146178        NSS_STATUS status;
    147179
    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);
    149185
    150186again:
     
    152188        if (status == NSS_STATUS_TRYAGAIN) {
    153189                buflen *= 2;
    154                 buf = realloc_p(buf, char, buflen);
     190                buf = (char *)realloc(buf, buflen);
     191                if (!buf) {
     192                        return NULL;
     193                }
    155194                goto again;
    156195        }
    157196        if (status == NSS_STATUS_NOTFOUND) {
     197                free(buf);
    158198                return NULL;
    159199        }
    160200        if (status != NSS_STATUS_SUCCESS) {
    161201                report_nss_error("getgrent", status);
     202                free(buf);
    162203                return NULL;
    163204        }
     
    168209{
    169210        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");
    171214        static struct group grp;
    172215        static char *buf;
     
    174217        NSS_STATUS status;
    175218
    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);
    177224again:
    178225        status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno);
    179226        if (status == NSS_STATUS_TRYAGAIN) {
    180227                buflen *= 2;
    181                 buf = realloc_p(buf, char, buflen);
     228                buf = (char *)realloc(buf, buflen);
     229                if (!buf) {
     230                        return NULL;
     231                }
    182232                goto again;
    183233        }
    184234        if (status == NSS_STATUS_NOTFOUND) {
     235                free(buf);
    185236                return NULL;
    186237        }
    187238        if (status != NSS_STATUS_SUCCESS) {
    188239                report_nss_error("getgrnam", status);
     240                free(buf);
    189241                return NULL;
    190242        }
     
    195247{
    196248        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");
    198252        static struct group grp;
    199253        static char *buf;
     
    201255        NSS_STATUS status;
    202256
    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
    204263again:
    205264        status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno);
    206265        if (status == NSS_STATUS_TRYAGAIN) {
    207266                buflen *= 2;
    208                 buf = realloc_p(buf, char, buflen);
     267                buf = (char *)realloc(buf, buflen);
     268                if (!buf) {
     269                        return NULL;
     270                }
    209271                goto again;
    210272        }
    211273        if (status == NSS_STATUS_NOTFOUND) {
     274                free(buf);
    212275                return NULL;
    213276        }
    214277        if (status != NSS_STATUS_SUCCESS) {
    215278                report_nss_error("getgrgid", status);
     279                free(buf);
    216280                return NULL;
    217281        }
     
    221285static void nss_setgrent(void)
    222286{
    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
    225294        status = _nss_setgrent();
    226295        if (status != NSS_STATUS_SUCCESS) {
     
    231300static void nss_endgrent(void)
    232301{
    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
    235309        status = _nss_endgrent();
    236310        if (status != NSS_STATUS_SUCCESS) {
     
    243317        NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *,
    244318                                      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;
    249326
    250327        status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno);
     
    257334static void print_passwd(struct passwd *pwd)
    258335{
    259         printf("%s:%s:%d:%d:%s:%s:%s\n",
     336        printf("%s:%s:%lu:%lu:%s:%s:%s\n",
    260337               pwd->pw_name,
    261338               pwd->pw_passwd,
    262                pwd->pw_uid,
    263                pwd->pw_gid,
     339               (unsigned long)pwd->pw_uid,
     340               (unsigned long)pwd->pw_gid,
    264341               pwd->pw_gecos,
    265342               pwd->pw_dir,
     
    270347{
    271348        int i;
    272         printf("%s:%s:%d: ",
     349        printf("%s:%s:%lu:",
    273350               grp->gr_name,
    274351               grp->gr_passwd,
    275                grp->gr_gid);
     352               (unsigned long)grp->gr_gid);
    276353
    277354        if (!grp->gr_mem[0]) {
     
    281358
    282359        for (i=0; grp->gr_mem[i+1]; i++) {
    283                 printf("%s, ", grp->gr_mem[i]);
     360                printf("%s,", grp->gr_mem[i]);
    284361        }
    285362        printf("%s\n", grp->gr_mem[i]);
     
    294371        NSS_STATUS status;
    295372
    296         groups = (gid_t *)malloc_array_p(gid_t, size);
     373        groups = (gid_t *)malloc(size);
    297374        groups[0] = gid;
    298375
     
    304381
    305382        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]);
    309386}
    310387
  • vendor/current/nsswitch/pam_winbind.c

    r414 r740  
    157157{
    158158        if (!initialized) {
    159                 bindtextdomain(MODULE_NAME, dyn_LOCALEDIR);
     159                bindtextdomain(MODULE_NAME, LOCALEDIR);
    160160                initialized = 1;
    161161        }
     
    10781078                                       int sid_list_buffer_size)
    10791079{
    1080         const char* sid_string = NULL;
    1081         char *sid_str = NULL;
     1080        char sid_string[WBC_SID_STRING_BUFLEN];
    10821081
    10831082        /* lookup name? */
    10841083        if (IS_SID_STRING(name)) {
    1085                 sid_string = name;
     1084                strlcpy(sid_string, name, sizeof(sid_string));
    10861085        } else {
    10871086                wbcErr wbc_status;
     
    10991098                }
    11001099
    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));
    11071101        }
    11081102
    11091103        if (!safe_append_string(sid_list_buffer, sid_string,
    11101104                                sid_list_buffer_size)) {
    1111                 wbcFreeMemory(sid_str);
    11121105                return false;
    11131106        }
    1114 
    1115         wbcFreeMemory(sid_str);
    11161107        return true;
    11171108}
     
    11451136
    11461137        search_location = name_list;
    1147         while ((comma = strstr(search_location, ",")) != NULL) {
     1138        while ((comma = strchr(search_location, ',')) != NULL) {
    11481139                current_name = strndup(search_location,
    11491140                                       comma - search_location);
     
    12001191                 */
    12011192                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';
    12061195                }
    12071196        }
     
    14351424                                       const struct wbcAuthErrorInfo *e,
    14361425                                       const char *nt_status_string,
    1437                                        int *pam_error)
     1426                                       int *pam_err)
    14381427{
    14391428        const char *ntstatus = NULL;
    14401429        const char *error_string = NULL;
    14411430
    1442         if (!e || !pam_error) {
     1431        if (!e || !pam_err) {
    14431432                return false;
    14441433        }
     
    14541443                if (error_string) {
    14551444                        _make_remark(ctx, PAM_ERROR_MSG, error_string);
    1456                         *pam_error = e->pam_error;
     1445                        *pam_err = e->pam_error;
    14571446                        return true;
    14581447                }
    14591448
    14601449                if (e->display_string) {
    1461                         _make_remark(ctx, PAM_ERROR_MSG, e->display_string);
    1462                         *pam_error = e->pam_error;
     1450                        _make_remark(ctx, PAM_ERROR_MSG, _(e->display_string));
     1451                        *pam_err = e->pam_error;
    14631452                        return true;
    14641453                }
    14651454
    14661455                _make_remark(ctx, PAM_ERROR_MSG, nt_status_string);
    1467                 *pam_error = e->pam_error;
     1456                *pam_err = e->pam_error;
    14681457
    14691458                return true;
     
    19021891
    19031892 done:
    1904         if (logon.blobs) {
    1905                 wbcFreeMemory(logon.blobs);
    1906         }
     1893        wbcFreeMemory(logon.blobs);
    19071894        if (info && info->blobs && !p_info) {
    19081895                wbcFreeMemory(info->blobs);
     
    20011988                        case -1:
    20021989                                break;
    2003                         case WBC_PWD_CHANGE_REJECT_OTHER:
     1990                        case WBC_PWD_CHANGE_NO_ERROR:
    20041991                                if ((min_pwd_age > 0) &&
    20051992                                    (pwd_last_set + min_pwd_age > time(NULL))) {
     
    20081995                                }
    20091996                                break;
    2010                         case WBC_PWD_CHANGE_REJECT_TOO_SHORT:
     1997                        case WBC_PWD_CHANGE_PASSWORD_TOO_SHORT:
    20111998                                PAM_WB_REMARK_DIRECT(ctx,
    20121999                                        "NT_STATUS_PWD_TOO_SHORT");
    20132000                                break;
    2014                         case WBC_PWD_CHANGE_REJECT_IN_HISTORY:
     2001                        case WBC_PWD_CHANGE_PWD_IN_HISTORY:
    20152002                                PAM_WB_REMARK_DIRECT(ctx,
    20162003                                        "NT_STATUS_PWD_HISTORY_CONFLICT");
    20172004                                break;
    2018                         case WBC_PWD_CHANGE_REJECT_COMPLEXITY:
     2005                        case WBC_PWD_CHANGE_NOT_COMPLEX:
    20192006                                _make_remark(ctx, PAM_ERROR_MSG,
    20202007                                             _("Password does not meet "
     
    24252412        struct wbcDomainSid sid;
    24262413        enum wbcSidType type;
    2427         char *domain;
     2414        char *domain = NULL;
    24282415        char *name;
    24292416        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
    144/* pam_winbind header file
    245   (Solaris needs some macros from Linux for common PAM code)
     
    447   Shirish Kalele 2000
    548*/
     49
     50#ifndef _NSSWITCH_PAM_WINBIND_H_
     51#define _NSSWITCH_PAM_WINBIND_H_
    652
    753#include "../lib/replace/replace.h"
     
    1056#include <talloc.h>
    1157#include "libwbclient/wbclient.h"
    12 #include "localedir.h"
    1358
    1459#define MODULE_NAME "pam_winbind"
     
    177222#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
    178223#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  
    1616failed=0
    1717samba4bindir="$BUILDDIR/bin"
    18 wbinfo="$samba4bindir/wbinfo$EXEEXT"
     18wbinfo="$VALGRIND $samba4bindir/wbinfo$EXEEXT"
    1919
    2020. `dirname $0`/../../testprogs/blackbox/subunit.sh
     
    164164        echo "Own domain reported as $own_domain instead of $DOMAIN"
    165165        echo "failure: wbinfo --own-domain against $TARGET check output"
     166        failed=`expr $failed + 1`
    166167fi
    167168
     
    174175testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
    175176
    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"
     177testit "wbinfo --uid-info against $TARGET" $wbinfo --uid-info $admin_uid || failed=`expr $failed + 1`
     178
     179echo "test: wbinfo --group-info against $TARGET"
     180rawgid=`$wbinfo --group-info "Domain admins" | sed 's/.*:\([0-9][0-9]*\):/\1/'`
     181if test x$? = x0; then
     182        echo "success: wbinfo --group-info against $TARGET"
     183else
     184        echo "failure: wbinfo --group-info against $TARGET"
     185        failed=`expr $failed + 1`
     186fi
     187
     188gid=`echo $rawgid | sed 's/.*:\([0-9][0-9]*\):/\1/'`
     189testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=`expr $failed + 1`
     190
     191testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
    182192
    183193testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1`
  • vendor/current/nsswitch/wb_common.c

    r591 r740  
    2323*/
    2424
     25#include "replace.h"
     26#include "system/select.h"
    2527#include "winbind_client.h"
    2628
     
    4244/* Initialise a request structure */
    4345
    44 void winbindd_init_request(struct winbindd_request *request, int request_type)
     46static void winbindd_init_request(struct winbindd_request *request,
     47                                  int request_type)
    4548{
    4649        request->length = sizeof(struct winbindd_request);
     
    6568__attribute__((destructor))
    6669#endif
    67 void winbind_close_sock(void)
     70static void winbind_close_sock(void)
    6871{
    6972        if (winbindd_fd != -1) {
     
    233236        for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1;
    234237                        wait_time += slept) {
    235                 struct timeval tv;
    236                 fd_set w_fds;
     238                struct pollfd pfd;
    237239                int ret;
    238240                int connect_errno = 0;
     
    244246                switch (errno) {
    245247                        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);
    256252
    257253                                if (ret > 0) {
     
    371367/* Write data to winbindd socket */
    372368
    373 int winbind_write_sock(void *buffer, int count, int recursing, int need_priv)
     369static int winbind_write_sock(void *buffer, int count, int recursing,
     370                              int need_priv)
    374371{
    375372        int result, nwritten;
     
    389386
    390387        while(nwritten < count) {
    391                 struct timeval tv;
    392                 fd_set r_fds;
     388                struct pollfd pfd;
     389                int ret;
    393390
    394391                /* 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
    400423                        winbind_close_sock();
    401424                        return -1;
    402425                }
    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;
    438428        }
    439429
     
    443433/* Read data from winbindd socket */
    444434
    445 int winbind_read_sock(void *buffer, int count)
     435static int winbind_read_sock(void *buffer, int count)
    446436{
    447437        int nread = 0;
    448         int total_time = 0, selret;
     438        int total_time = 0;
    449439
    450440        if (winbindd_fd == -1) {
     
    454444        /* Read data from socket */
    455445        while(nread < count) {
    456                 struct timeval tv;
    457                 fd_set r_fds;
     446                struct pollfd pfd;
     447                int ret;
    458448
    459449                /* 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) {
    465459                        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) {
    479464                        /* Not ready for read yet... */
    480465                        if (total_time >= 30) {
     
    487472                }
    488473
    489                 if (FD_ISSET(winbindd_fd, &r_fds)) {
     474                if ((ret == 1) && (pfd.revents & (POLLIN|POLLHUP|POLLERR))) {
    490475
    491476                        /* Do the Read */
     
    514499/* Read reply */
    515500
    516 int winbindd_read_reply(struct winbindd_response *response)
     501static int winbindd_read_reply(struct winbindd_response *response)
    517502{
    518503        int result1, result2 = 0;
     
    527512                                    sizeof(struct winbindd_response));
    528513        if (result1 == -1) {
     514                return -1;
     515        }
     516
     517        if (response->length < sizeof(struct winbindd_response)) {
    529518                return -1;
    530519        }
     
    683672        return status;
    684673}
    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_RETURN
    701                 case NSS_STATUS_RETURN:
    702                         return "NSS_STATUS_RETURN";
    703 #endif
    704                 default:
    705                         return "UNKNOWN RETURN CODE!!!!!!!";
    706         }
    707 }
  • vendor/current/nsswitch/wbinfo.c

    r414 r740  
    2323
    2424#include "includes.h"
     25#include "popt_common.h"
    2526#include "winbind_client.h"
    2627#include "libwbclient/wbclient.h"
    2728#include "lib/popt/popt.h"
    2829#include "../libcli/auth/libcli_auth.h"
    29 #if !(_SAMBA_VERSION_) < 4
     30#if (_SAMBA_BUILD_) >= 4
    3031#include "lib/cmdline/popt_common.h"
    3132#endif
     
    4849        if (!WBC_ERROR_IS_OK(wbc_status)) {
    4950                d_fprintf(stderr, "could not obtain winbind interface "
    50                                   "details!\n");
     51                                  "details: %s\n", wbcErrorString(wbc_status));
    5152        }
    5253
     
    173174        wbc_status = wbcGetpwnam(user, &pwd);
    174175        if (!WBC_ERROR_IS_OK(wbc_status)) {
     176                d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n",
     177                          wbcErrorString(wbc_status));
    175178                return false;
    176179        }
     
    185188                 pwd->pw_shell);
    186189
     190        wbcFreeMemory(pwd);
     191
    187192        return true;
    188193}
     
    196201        wbc_status = wbcGetpwuid(uid, &pwd);
    197202        if (!WBC_ERROR_IS_OK(wbc_status)) {
     203                d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
     204                          wbcErrorString(wbc_status));
    198205                return false;
    199206        }
     
    208215                 pwd->pw_shell);
    209216
     217        wbcFreeMemory(pwd);
     218
    210219        return true;
    211220}
     
    220229        wbc_status = wbcGetpwsid(&sid, &pwd);
    221230        if (!WBC_ERROR_IS_OK(wbc_status)) {
     231                d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
     232                          wbcErrorString(wbc_status));
    222233                return false;
    223234        }
     
    245256        wbc_status = wbcGetgrnam(group, &grp);
    246257        if (!WBC_ERROR_IS_OK(wbc_status)) {
     258                d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n",
     259                          wbcErrorString(wbc_status));
    247260                return false;
    248261        }
     
    274287        wbc_status = wbcGetgrgid(gid, &grp);
    275288        if (!WBC_ERROR_IS_OK(wbc_status)) {
     289                d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
     290                          wbcErrorString(wbc_status));
    276291                return false;
    277292        }
     
    307322        wbc_status = wbcGetGroups(user, &num_groups, &groups);
    308323        if (!WBC_ERROR_IS_OK(wbc_status)) {
     324                d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
     325                          wbcErrorString(wbc_status));
    309326                return false;
    310327        }
     
    332349        wbc_status = wbcStringToSid(user_sid_str, &user_sid);
    333350        if (!WBC_ERROR_IS_OK(wbc_status)) {
     351                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     352                          wbcErrorString(wbc_status));
    334353                return false;
    335354        }
     
    337356        wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
    338357        if (!WBC_ERROR_IS_OK(wbc_status)) {
     358                d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
     359                          wbcErrorString(wbc_status));
    339360                return false;
    340361        }
    341362
    342363        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));
    349366                d_printf("%s\n", str);
    350                 wbcFreeMemory(str);
    351367        }
    352368
     
    367383        wbc_status = wbcStringToSid(user_sid_str, &user_sid);
    368384        if (!WBC_ERROR_IS_OK(wbc_status)) {
     385                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     386                          wbcErrorString(wbc_status));
    369387                return false;
    370388        }
     
    372390        wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
    373391        if (!WBC_ERROR_IS_OK(wbc_status)) {
     392                d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
     393                          wbcErrorString(wbc_status));
    374394                return false;
    375395        }
    376396
    377397        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));
    384400                d_printf("%s\n", str);
    385                 wbcFreeMemory(str);
    386401        }
    387402
     
    400415        uint32_t *alias_rids = NULL;
    401416        uint32_t num_alias_rids;
    402         char *domain_sid_str = NULL;
     417        char domain_sid_str[WBC_SID_STRING_BUFLEN];
    403418
    404419        /* Send request */
     
    412427        wbc_status = wbcDomainInfo(domain, &dinfo);
    413428        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));
    416431                goto done;
    417432        }
     
    427442        }
    428443
    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));
    433445
    434446        for (i = 0; i < num_alias_rids; i++) {
     
    439451
    440452done:
    441         if (domain_sid_str) {
    442                 wbcFreeMemory(domain_sid_str);
    443         }
    444         if (dinfo) {
    445                 wbcFreeMemory(dinfo);
    446         }
     453        wbcFreeMemory(dinfo);
    447454        return (WBC_ERR_SUCCESS == wbc_status);
    448455}
     
    458465        wbc_status = wbcResolveWinsByName(name, &ip);
    459466        if (!WBC_ERROR_IS_OK(wbc_status)) {
     467                d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
     468                          wbcErrorString(wbc_status));
    460469                return false;
    461470        }
     
    479488        wbc_status = wbcResolveWinsByIP(ip, &name);
    480489        if (!WBC_ERROR_IS_OK(wbc_status)) {
     490                d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
     491                          wbcErrorString(wbc_status));
    481492                return false;
    482493        }
     
    503514        wbc_status = wbcListTrusts(&domain_list, &num_domains);
    504515        if (!WBC_ERROR_IS_OK(wbc_status)) {
     516                d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
     517                          wbcErrorString(wbc_status));
    505518                return false;
    506519        }
     
    559572        }
    560573
     574        wbcFreeMemory(domain_list);
     575
    561576        return true;
    562577}
     
    589604        wbc_status = wbcListTrusts(&domain_list, &num_domains);
    590605        if (!WBC_ERROR_IS_OK(wbc_status)) {
     606                d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
     607                          wbcErrorString(wbc_status));
    591608                return false;
    592609        }
     
    609626        }
    610627
     628        wbcFreeMemory(domain_list);
     629
    611630        return true;
    612631}
     
    619638        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    620639        struct wbcDomainInfo *dinfo = NULL;
    621         char *sid_str = NULL;
     640        char sid_str[WBC_SID_STRING_BUFLEN];
    622641
    623642        if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
     
    629648        wbc_status = wbcDomainInfo(domain, &dinfo);
    630649        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));
    639656
    640657        /* Display response */
     
    655672                 "Yes" : "No");
    656673
    657         wbcFreeMemory(sid_str);
    658674        wbcFreeMemory(dinfo);
    659675
     
    743759        }
    744760        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
     771static 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);
    747790
    748791        return true;
     
    775818        }
    776819        if (!WBC_ERROR_IS_OK(wbc_status)) {
     820                d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
     821                          "%s\n", wbcErrorString(wbc_status));
    777822                return false;
    778823        }
     
    799844        }
    800845        if (!WBC_ERROR_IS_OK(wbc_status)) {
     846                d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
     847                          wbcErrorString(wbc_status));
    801848                return false;
    802849        }
     
    811858        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    812859        struct wbcDomainSid sid;
    813         char *sid_str = NULL;
     860        char sid_str[WBC_SID_STRING_BUFLEN];
    814861
    815862        /* Send request */
     
    817864        wbc_status = wbcUidToSid(uid, &sid);
    818865        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));
    826872
    827873        /* Display response */
     
    829875        d_printf("%s\n", sid_str);
    830876
    831         wbcFreeMemory(sid_str);
    832 
    833877        return true;
    834878}
     
    840884        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    841885        struct wbcDomainSid sid;
    842         char *sid_str = NULL;
     886        char sid_str[WBC_SID_STRING_BUFLEN];
    843887
    844888        /* Send request */
     
    846890        wbc_status = wbcGidToSid(gid, &sid);
    847891        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));
    855898
    856899        /* Display response */
    857900
    858901        d_printf("%s\n", sid_str);
    859 
    860         wbcFreeMemory(sid_str);
    861902
    862903        return true;
     
    875916        wbc_status = wbcStringToSid(sid_str, &sid);
    876917        if (!WBC_ERROR_IS_OK(wbc_status)) {
     918                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     919                          wbcErrorString(wbc_status));
    877920                return false;
    878921        }
     
    880923        wbc_status = wbcSidToUid(&sid, &uid);
    881924        if (!WBC_ERROR_IS_OK(wbc_status)) {
     925                d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
     926                          wbcErrorString(wbc_status));
    882927                return false;
    883928        }
     
    900945        wbc_status = wbcStringToSid(sid_str, &sid);
    901946        if (!WBC_ERROR_IS_OK(wbc_status)) {
     947                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     948                          wbcErrorString(wbc_status));
    902949                return false;
    903950        }
     
    905952        wbc_status = wbcSidToGid(&sid, &gid);
    906953        if (!WBC_ERROR_IS_OK(wbc_status)) {
     954                d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
     955                          wbcErrorString(wbc_status));
    907956                return false;
    908957        }
     
    915964}
    916965
     966static 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
    9171034static bool wbinfo_allocate_uid(void)
    9181035{
     
    9241041        wbc_status = wbcAllocateUid(&uid);
    9251042        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1043                d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
     1044                          wbcErrorString(wbc_status));
    9261045                return false;
    9271046        }
     
    9431062        wbc_status = wbcAllocateGid(&gid);
    9441063        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1064                d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
     1065                          wbcErrorString(wbc_status));
    9451066                return false;
    9461067        }
     
    9621083        wbc_status = wbcStringToSid(sid_str, &sid);
    9631084        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1085                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1086                          wbcErrorString(wbc_status));
    9641087                return false;
    9651088        }
     
    9671090        wbc_status = wbcSetUidMapping(uid, &sid);
    9681091        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1092                d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n",
     1093                          wbcErrorString(wbc_status));
    9691094                return false;
    9701095        }
     
    9871112        wbc_status = wbcStringToSid(sid_str, &sid);
    9881113        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1114                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1115                          wbcErrorString(wbc_status));
    9891116                return false;
    9901117        }
     
    9921119        wbc_status = wbcSetGidMapping(gid, &sid);
    9931120        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1121                d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n",
     1122                          wbcErrorString(wbc_status));
    9941123                return false;
    9951124        }
     
    10121141        wbc_status = wbcStringToSid(sid_str, &sid);
    10131142        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1143                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1144                          wbcErrorString(wbc_status));
    10141145                return false;
    10151146        }
     
    10171148        wbc_status = wbcRemoveUidMapping(uid, &sid);
    10181149        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1150                d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
     1151                          wbcErrorString(wbc_status));
    10191152                return false;
    10201153        }
     
    10371170        wbc_status = wbcStringToSid(sid_str, &sid);
    10381171        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1172                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1173                          wbcErrorString(wbc_status));
    10391174                return false;
    10401175        }
     
    10421177        wbc_status = wbcRemoveGidMapping(gid, &sid);
    10431178        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1179                d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
     1180                          wbcErrorString(wbc_status));
    10441181                return false;
    10451182        }
     
    10671204        wbc_status = wbcStringToSid(sid_str, &sid);
    10681205        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1206                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1207                          wbcErrorString(wbc_status));
    10691208                return false;
    10701209        }
     
    10721211        wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
    10731212        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1213                d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
     1214                          wbcErrorString(wbc_status));
    10741215                return false;
    10751216        }
     
    10971238        wbc_status = wbcStringToSid(sid_str, &sid);
    10981239        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1240                d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
     1241                          wbcErrorString(wbc_status));
    10991242                return false;
    11001243        }
     
    11021245        wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
    11031246        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1247                d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
     1248                          wbcErrorString(wbc_status));
    11041249                return false;
    11051250        }
     
    11851330        ret = true;
    11861331done:
    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);
    11991336        TALLOC_FREE(mem_ctx);
    12001337        return ret;
    12011338}
    12021339
     1340static 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
    12031392/* Convert string to sid */
    12041393
     
    12071396        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    12081397        struct wbcDomainSid sid;
    1209         char *sid_str;
     1398        char sid_str[WBC_SID_STRING_BUFLEN];
    12101399        enum wbcSidType type;
    12111400        fstring domain_name;
     
    12201409                                   &sid, &type);
    12211410        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));
    12291417
    12301418        /* Display response */
    12311419
    12321420        d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
    1233 
    1234         wbcFreeMemory(sid_str);
    12351421
    12361422        return true;
     
    13121498                                     sizeof(flags));
    13131499        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1500                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1501                          wbcErrorString(wbc_status));
    13141502                goto done;
    13151503        }
     
    13221510                                     sizeof(uid));
    13231511        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1512                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1513                          wbcErrorString(wbc_status));
    13241514                goto done;
    13251515        }
     
    13321522                                     strlen(cctype)+1);
    13331523        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1524                d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
     1525                          wbcErrorString(wbc_status));
    13341526                goto done;
    13351527        }
     
    13441536        if (error) {
    13451537                d_fprintf(stderr,
    1346                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1538                         "error code was %s (0x%x)\nerror message was: %s\n",
    13471539                         error->nt_string,
    13481540                         error->nt_status,
     
    14151607        if (response.data.auth.nt_status)
    14161608                d_fprintf(stderr,
    1417                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1609                         "error code was %s (0x%x)\nerror message was: %s\n",
    14181610                         response.data.auth.nt_status_string,
    14191611                         response.data.auth.nt_status,
     
    15161708        if (wbc_status == WBC_ERR_AUTH_ERROR) {
    15171709                d_fprintf(stderr,
    1518                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1710                         "error code was %s (0x%x)\nerror message was: %s\n",
    15191711                         err->nt_string,
    15201712                         err->nt_status,
     
    15291721
    15301722        return WBC_ERROR_IS_OK(wbc_status);
     1723}
     1724
     1725/* Authenticate a user with a plaintext password */
     1726
     1727static 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(&params.num_blobs, &params.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(&params.num_blobs, &params.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(&params, 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;
    15311792}
    15321793
     
    16071868        if (response.data.auth.nt_status)
    16081869                d_fprintf(stderr,
    1609                          "error code was %s (0x%x)\nerror messsage was: %s\n",
     1870                         "error code was %s (0x%x)\nerror message was: %s\n",
    16101871                         response.data.auth.nt_status_string,
    16111872                         response.data.auth.nt_status,
     
    16841945        wbc_status = wbcListGroups(domain, &num_groups, &groups);
    16851946        if (!WBC_ERROR_IS_OK(wbc_status)) {
     1947                d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
     1948                          wbcErrorString(wbc_status));
    16861949                return false;
    16871950        }
     
    17542017        OPT_GETDCNAME,
    17552018        OPT_DSGETDCNAME,
     2019        OPT_DC_INFO,
    17562020        OPT_USERDOMGROUPS,
    17572021        OPT_SIDALIASES,
    17582022        OPT_USERSIDS,
     2023        OPT_LOOKUP_SIDS,
    17592024        OPT_ALLOCATE_UID,
    17602025        OPT_ALLOCATE_GID,
     
    17632028        OPT_REMOVE_UID_MAPPING,
    17642029        OPT_REMOVE_GID_MAPPING,
     2030        OPT_SIDS_TO_XIDS,
    17652031        OPT_SEPARATOR,
    17662032        OPT_LIST_ALL_DOMAINS,
     
    17732039        OPT_ONLINESTATUS,
    17742040        OPT_CHANGE_USER_PASSWORD,
    1775         OPT_PING_DC,
    17762041        OPT_CCACHE_SAVE,
    17772042        OPT_SID_TO_FULLNAME,
    17782043        OPT_NTLMV2,
     2044        OPT_PAM_LOGON,
     2045        OPT_LOGOFF,
     2046        OPT_LOGOFF_USER,
     2047        OPT_LOGOFF_UID,
    17792048        OPT_LANMAN
    17802049};
     
    17942063        bool use_ntlmv2 = false;
    17952064        bool use_lanman = false;
     2065        char *logoff_user = getenv("USER");
     2066        int logoff_uid = geteuid();
    17962067
    17972068        struct poptOption long_options[] = {
     
    18102081                  OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
    18112082                { "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"},
    18122086                { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
    18132087                { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
     
    18222096                { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
    18232097                { "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" },
    18242100                { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
    18252101                { "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',
    18272103                  "Check the NETLOGON connection" },
    18282104                { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
    18292105                { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
    18302106                { "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" },
    18322108                { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
    18332109                { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
     
    18432119                { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
    18442120                { "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" },
    18452129                { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
    18462130                { "ccache-save", 0, POPT_ARG_STRING, &string_arg,
     
    18502134                  "Get a DC name for a foreign domain", "domainname" },
    18512135                { "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" },
    18522138                { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
    18532139                { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
     
    19442230                        }
    19452231                        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;
    19462239                case 'n':
    19472240                        if (!wbinfo_lookupname(string_arg)) {
     
    20532346                        }
    20542347                        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;
    20552355                case 't':
    20562356                        if (!wbinfo_check_secret(opt_domain_name)) {
     
    20652365                        }
    20662366                        break;
    2067                 case OPT_PING_DC:
     2367                case 'P':
    20682368                        if (!wbinfo_ping_dc()) {
    20692369                                d_fprintf(stderr, "Could not ping our DC\n");
     
    21922492                                break;
    21932493                        }
     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                }
    21942511                case 'K': {
    21952512                                uint32_t flags = WBFLAG_PAM_KRB5 |
     
    22462563                        }
    22472564                        break;
     2565                case OPT_DC_INFO:
     2566                        if (!wbinfo_dc_info(string_arg)) {
     2567                                goto done;
     2568                        }
     2569                        break;
    22482570                case OPT_SEPARATOR: {
    22492571                        const char sep = winbind_separator();
     
    22752597                /* generic configuration options */
    22762598                case OPT_DOMAIN_NAME:
    2277                         break;
    22782599                case OPT_VERBOSE:
    2279                         break;
    22802600                case OPT_NTLMV2:
    2281                         break;
    22822601                case OPT_LANMAN:
     2602                case OPT_LOGOFF_USER:
     2603                case OPT_LOGOFF_UID:
    22832604                        break;
    22842605                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
    128#include "winbind_nss_config.h"
    229#include "winbind_struct_protocol.h"
    330
    4 void winbindd_init_request(struct winbindd_request *req,int rq_type);
    531void winbindd_free_response(struct winbindd_response *response);
    632NSS_STATUS winbindd_send_request(int req_type, int need_priv,
     
    1339                                          struct winbindd_request *request,
    1440                                          struct winbindd_response *response);
    15 int winbindd_read_reply(struct winbindd_response *response);
    16 
    1741#define winbind_env_set() \
    1842        (strcmp(getenv(WINBINDD_DONT_ENV)?getenv(WINBINDD_DONT_ENV):"0","1") == 0)
     
    2448        (setenv(WINBINDD_DONT_ENV, "0", 1) == 0)
    2549
    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  
    131131        void *returnval;
    132132        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;
    134139        nss_status_t status;
    135140} nss_XbyY_args_t;
  • vendor/current/nsswitch/winbind_nss_linux.c

    r414 r740  
    7272                                 size_t buflen, int *errnop);
    7373
     74/*************************************************************************
     75 ************************************************************************/
     76
     77#ifdef DEBUG_NSS
     78static 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
    7499/* Prototypes from wb_common.c */
    75100
  • vendor/current/nsswitch/winbind_nss_solaris.h

    r414 r740  
    2323#define _WINBIND_NSS_SOLARIS_H
    2424
    25 /* Solaris has a broken nss_common header file containing C++ reserved names. */
    26 #ifndef __cplusplus
    27 #undef class
    28 #undef private
    29 #undef public
    30 #undef protected
    31 #undef template
    32 #undef this
    33 #undef new
    34 #undef delete
    35 #undef friend
    36 #endif
    37 
    3825#include <nss_common.h>
    39 
    40 #ifndef __cplusplus
    41 #define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    42 #define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    43 #define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    44 #define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    45 #define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    46 #define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    47 #define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    48 #define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    49 #define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
    50 #endif
    51 
    5226#include <nss_dbdefs.h>
    5327#include <nsswitch.h>
  • vendor/current/nsswitch/winbind_struct_protocol.h

    r414 r740  
    5151 * 23: added session_key to ccache_ntlm_auth response
    5252 *     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
    5359 */
    54 #define WINBIND_INTERFACE_VERSION 23
     60#define WINBIND_INTERFACE_VERSION 27
    5561
    5662/* Have to deal with time_t being 4 or 8 bytes due to structure alignment.
    5763   On a 64bit Linux box, we have to support a constant structure size
    58    between /lib/libnss_winbind.so.2 and /li64/libnss_winbind.so.2.
     64   between /lib/libnss_winbind.so.2 and /lib64/libnss_winbind.so.2.
    5965   The easiest way to do this is to always use 8byte values for time_t. */
    6066
     
    104110        WINBINDD_LOOKUPNAME,
    105111        WINBINDD_LOOKUPRIDS,
     112        WINBINDD_LOOKUPSIDS,
    106113
    107114        /* Lookup functions */
     
    115122        WINBINDD_ALLOCATE_UID,
    116123        WINBINDD_ALLOCATE_GID,
    117         WINBINDD_SET_MAPPING,
    118         WINBINDD_REMOVE_MAPPING,
    119         WINBINDD_SET_HWM,
    120124
    121125        /* Miscellaneous other stuff */
     
    132136        WINBINDD_GETDCNAME,     /* Issue a GetDCName Request */
    133137        WINBINDD_DSGETDCNAME,   /* Issue a DsGetDCName Request */
     138        WINBINDD_DC_INFO,       /* Which DC are we connected to? */
    134139
    135140        WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */
     
    167172        WINBINDD_DUAL_UID2SID,
    168173        WINBINDD_DUAL_GID2SID,
    169         WINBINDD_DUAL_SET_MAPPING,
    170         WINBINDD_DUAL_REMOVE_MAPPING,
    171         WINBINDD_DUAL_SET_HWM,
    172174
    173175        /* Wrapper around possibly blocking unix nss calls */
  • vendor/current/nsswitch/wins.c

    r427 r740  
    2020
    2121#include "includes.h"
     22#include "nsswitch/winbind_nss.h"
     23
    2224#ifdef HAVE_NS_API_H
    2325
     
    3840
    3941static int initialised;
    40 
    41 extern bool AllowDebugChange;
    4242
    4343NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he,
     
    4646                           char *buffer, size_t buflen, int *h_errnop);
    4747
    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_LEN
    59         sock.sin_len = sizeof(sock);
    60 #endif
    61         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_REUSEPORT
    73         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 
    9248static void nss_wins_init(void)
    9349{
    9450        initialised = 1;
    95         DEBUGLEVEL = 0;
    96         AllowDebugChange = False;
     51        load_case_tables_library();
     52        lp_set_cmdline("log level", "0");
    9753
    9854        TimeInit();
    9955        setup_logging("nss_wins",False);
    100         load_case_tables();
    10156        lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
    10257        load_interfaces();
     
    10560static struct in_addr *lookup_byname_backend(const char *name, int *count)
    10661{
    107         int fd = -1;
    10862        struct ip_service *address = NULL;
    10963        struct in_addr *ret = NULL;
    110         int j, flags = 0;
     64        int j;
    11165
    11266        if (!initialised) {
     
    12781                        return NULL;
    12882                }
    129                 *ret = ((struct sockaddr_in *)&address[0].ss)->sin_addr;
     83                *ret = ((struct sockaddr_in *)(void *)&address[0].ss)
     84                        ->sin_addr;
    13085                free( address );
    13186                return ret;
    132         }
    133 
    134         fd = wins_lookup_open_socket_in();
    135         if (fd == -1) {
    136                 return NULL;
    13787        }
    13888
     
    14292                struct sockaddr_storage ss;
    14393                struct sockaddr_storage *pss;
     94                NTSTATUS status;
     95
    14496                if (!bcast) {
    14597                        continue;
    14698                }
    14799                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)) {
    150103                        if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) {
    151104                                return NULL;
    152105                        }
    153106                        *ret = ((struct sockaddr_in *)pss)->sin_addr;
     107                        TALLOC_FREE(pss);
    154108                        break;
    155109                }
    156110        }
    157111
    158         close(fd);
    159112        return ret;
    160113}
     
    162115#ifdef HAVE_NS_API_H
    163116
    164 static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count)
    165 {
    166         int fd;
     117static struct node_status *lookup_byaddr_backend(char *addr, int *count)
     118{
    167119        struct sockaddr_storage ss;
    168120        struct nmb_name nname;
    169         NODE_STATUS_STRUCT *status;
     121        struct node_status *result;
     122        NTSTATUS status;
    170123
    171124        if (!initialised) {
    172125                nss_wins_init();
    173126        }
    174 
    175         fd = wins_lookup_open_socket_in();
    176         if (fd == -1)
    177                 return NULL;
    178127
    179128        make_nmb_name(&nname, "*", 0);
     
    181130                return NULL;
    182131        }
    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;
    187138}
    188139
     
    202153        char *addr;
    203154        struct in_addr *ip_list;
    204         NODE_STATUS_STRUCT *status;
     155        struct node_status *status;
    205156        int i, count, len, size;
    206157        char response[1024];
     
    234185                    size = strlen(key) + 1;
    235186                    if (size > len) {
    236                         free(status);
     187                        talloc_free(status);
    237188                        return NSD_ERROR;
    238189                    }
     
    246197                                size = sizeof(status[i].name) + 1;
    247198                                if (size > len) {
    248                                     free(status);
     199                                    talloc_free(status);
    249200                                    return NSD_ERROR;
    250201                                }
     
    256207                    }
    257208                    response[strlen(response)-1] = '\n';
    258                     free(status);
     209                    talloc_free(status);
    259210                }
    260211        } else if (StrCaseCmp(map,"hosts.byname") == 0) {
Note: See TracChangeset for help on using the changeset viewer.