Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

Location:
vendor/current/nsswitch/libwbclient
Files:
7 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/nsswitch/libwbclient/tests/wbclient.c

    r740 r988  
    2323#include "lib/util/data_blob.h"
    2424#include "lib/util/time.h"
     25#include "libcli/resolve/resolve.h"
    2526#include "nsswitch/libwbclient/wbclient.h"
    2627#include "torture/smbtorture.h"
     
    2930#include "lib/util/charset/charset.h"
    3031#include "libcli/auth/libcli_auth.h"
    31 #include "source4/param/param.h"
    32 #include "lib/util/util.h"
     32#include "lib/param/param.h"
     33#include "lib/util/samba_util.h"
    3334#include "lib/crypto/arcfour.h"
     35#include "auth/credentials/credentials.h"
     36#include "lib/cmdline/popt_common.h"
    3437
    3538#define WBC_ERROR_EQUAL(x,y) (x == y)
    3639
    37 #define torture_assert_wbc_equal(torture_ctx, got, expected, cmt) \
     40#define torture_assert_wbc_equal(torture_ctx, got, expected, cmt, cmt_arg)      \
    3841        do { wbcErr __got = got, __expected = expected; \
    3942        if (!WBC_ERROR_EQUAL(__got, __expected)) { \
    40                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", wbcErrorString(__got), wbcErrorString(__expected), cmt); \
     43                torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: " cmt, wbcErrorString(__got), wbcErrorString(__expected), cmt_arg); \
    4144                return false; \
    4245        } \
    4346        } while (0)
    4447
    45 #define torture_assert_wbc_ok(torture_ctx,expr,cmt) \
    46                 torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt)
     48#define torture_assert_wbc_ok(torture_ctx,expr,cmt,cmt_arg)                     \
     49        torture_assert_wbc_equal(torture_ctx,expr,WBC_ERR_SUCCESS,cmt,cmt_arg)
    4750
    4851static bool test_wbc_ping(struct torture_context *tctx)
    4952{
    5053        torture_assert_wbc_ok(tctx, wbcPing(),
    51                 "wbcPing failed");
     54                "%s", "wbcPing failed");
    5255
    5356        return true;
     
    5659static bool test_wbc_pingdc(struct torture_context *tctx)
    5760{
    58         torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_NOT_IMPLEMENTED,
    59                 "wbcPingDc failed");
     61        struct wbcInterfaceDetails *details;
     62
     63        torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_DOMAIN_NOT_FOUND,
     64                                 "%s", "wbcPingDc failed");
    6065        torture_assert_wbc_ok(tctx, wbcPingDc(NULL, NULL),
    61                 "wbcPingDc failed");
     66                "%s", "wbcPingDc failed");
     67
     68        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
     69                "%s", "wbcInterfaceDetails failed");
     70        torture_assert(tctx, details,
     71                       "wbcInterfaceDetails returned NULL pointer");
     72        torture_assert(tctx, details->netbios_domain,
     73                       "wbcInterfaceDetails returned NULL netbios_domain");
     74
     75        torture_assert_wbc_ok(tctx, wbcPingDc(details->netbios_domain, NULL),
     76                "wbcPingDc(%s) failed", details->netbios_domain);
     77
     78        torture_assert_wbc_ok(tctx, wbcPingDc("BUILTIN", NULL),
     79                "%s", "wbcPingDc(BUILTIN) failed");
     80
     81        wbcFreeMemory(details);
     82        return true;
     83}
     84
     85static bool test_wbc_pingdc2(struct torture_context *tctx)
     86{
     87        struct wbcInterfaceDetails *details;
     88        char *name = NULL;
     89
     90        torture_assert_wbc_equal(tctx, wbcPingDc2("random_string", NULL, &name),
     91                                 WBC_ERR_DOMAIN_NOT_FOUND, "%s",
     92                                 "wbcPingDc2 failed");
     93        torture_assert_wbc_ok(tctx, wbcPingDc2(NULL, NULL, &name), "%s",
     94                              "wbcPingDc2 failed");
     95
     96        wbcFreeMemory(name);
     97
     98        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
     99                "%s", "wbcInterfaceDetails failed");
     100        torture_assert(tctx, details,
     101                       "wbcInterfaceDetails returned NULL pointer");
     102        torture_assert(tctx, details->netbios_domain,
     103                       "wbcInterfaceDetails returned NULL netbios_domain");
     104
     105        torture_assert_wbc_ok(tctx, wbcPingDc2(details->netbios_domain, NULL, &name),
     106                "wbcPingDc2(%s) failed", details->netbios_domain);
     107        wbcFreeMemory(name);
     108
     109        torture_assert_wbc_ok(tctx, wbcPingDc2("BUILTIN", NULL, &name),
     110                "%s", "wbcPingDc2(BUILTIN) failed");
     111        wbcFreeMemory(name);
     112
     113        wbcFreeMemory(details);
    62114
    63115        return true;
     
    69121
    70122        torture_assert_wbc_ok(tctx, wbcLibraryDetails(&details),
    71                 "wbcLibraryDetails failed");
     123                "%s", "wbcLibraryDetails failed");
    72124        torture_assert(tctx, details,
    73125                "wbcLibraryDetails returned NULL pointer");
     
    83135
    84136        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    85                 "wbcInterfaceDetails failed");
     137                "%s", "wbcInterfaceDetails failed");
    86138        torture_assert(tctx, details,
    87                 "wbcInterfaceDetails returned NULL pointer");
     139                       "wbcInterfaceDetails returned NULL pointer");
    88140
    89141        wbcFreeMemory(details);
     
    113165                                 "SID_UNKNOWN", "SID_UNKNOWN failed");
    114166        torture_assert_str_equal(tctx, wbcSidTypeString(WBC_SID_NAME_COMPUTER),
    115                                  "SID_COMPUTER", "SID_COMPUTER failed");
     167                                 "SID_COMPUTER",  "SID_COMPUTER failed");
    116168        return true;
    117169}
     
    124176
    125177        torture_assert_wbc_ok(tctx, wbcStringToSid(sid_string, &sid),
    126                 "wbcStringToSid failed");
     178                              "wbcStringToSid of %s failed", sid_string);
    127179        torture_assert_wbc_ok(tctx, wbcSidToString(&sid, &sid_string2),
    128                 "wbcSidToString failed");
     180                              "wbcSidToString of %s failed", sid_string);
    129181        torture_assert_str_equal(tctx, sid_string, sid_string2,
    130182                "sid strings differ");
     
    141193
    142194        torture_assert_wbc_ok(tctx, wbcStringToGuid(guid_string, &guid),
    143                 "wbcStringToGuid failed");
     195                              "wbcStringToGuid of %s failed", guid_string);
    144196        torture_assert_wbc_ok(tctx, wbcGuidToString(&guid, &guid_string2),
    145                 "wbcGuidToString failed");
     197                              "wbcGuidToString of %s failed", guid_string);
    146198        torture_assert_str_equal(tctx, guid_string, guid_string2,
    147                 "guid strings differ");
     199                                 "guid strings differ");
    148200        wbcFreeMemory(guid_string2);
    149201
     
    157209
    158210        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    159                 "wbcInterfaceDetails failed");
     211                "%s", "wbcInterfaceDetails failed");
    160212        torture_assert_wbc_ok(
    161213                tctx, wbcDomainInfo(details->netbios_domain, &info),
    162                 "wbcDomainInfo failed");
     214                "%s", "wbcDomainInfo failed");
    163215        wbcFreeMemory(details);
    164216
     
    179231
    180232        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    181                 "wbcInterfaceDetails failed");
     233                "%s", "wbcInterfaceDetails failed");
    182234
    183235        domain_name = talloc_strdup(tctx, details->netbios_domain);
     
    185237
    186238        torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users),
    187                 "wbcListUsers failed");
     239                "%s", "wbcListUsers failed");
    188240        torture_assert(tctx, !(num_users > 0 && !users),
    189241                "wbcListUsers returned invalid results");
     
    195247                char *domain;
    196248                char *name;
     249                char *sid_string;
    197250                uint32_t num_sids;
    198251
    199252                torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, users[i], &sid, &name_type),
    200                         "wbcLookupName failed");
     253                                      "wbcLookupName of %s failed", users[i]);
    201254                torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
    202                         "wbcLookupName expected WBC_SID_NAME_USER");
     255                                         "wbcLookupName expected WBC_SID_NAME_USER");
     256                wbcSidToString(&sid, &sid_string);
    203257                torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
    204                         "wbcLookupSid failed");
     258                                      "wbcLookupSid of %s failed", sid_string);
    205259                torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER,
    206                         "wbcLookupSid expected WBC_SID_NAME_USER");
     260                                         "wbcLookupSid of expected WBC_SID_NAME_USER");
    207261                torture_assert(tctx, name,
    208262                        "wbcLookupSid returned no name");
     
    210264                wbcFreeMemory(name);
    211265                torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
    212                         "wbcLookupUserSids failed");
     266                        "wbcLookupUserSids of %s failed", sid_string);
    213267                torture_assert_wbc_ok(
    214268                        tctx, wbcGetDisplayName(&sid, &domain, &name,
    215269                                                &name_type),
    216                         "wbcGetDisplayName failed");
     270                        "wbcGetDisplayName of %s failed", sid_string);
    217271                wbcFreeMemory(domain);
    218272                wbcFreeMemory(name);
    219273                wbcFreeMemory(sids);
     274                wbcFreeMemory(sid_string);
    220275        }
    221276        wbcFreeMemory(users);
     
    233288
    234289        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    235                 "wbcInterfaceDetails failed");
     290                              "%s", "wbcInterfaceDetails failed");
    236291
    237292        domain_name = talloc_strdup(tctx, details->netbios_domain);
     
    239294
    240295        torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups),
    241                 "wbcListGroups failed");
     296                              "wbcListGroups in %s failed", domain_name);
    242297        torture_assert(tctx, !(num_groups > 0 && !groups),
    243                 "wbcListGroups returned invalid results");
     298                       "wbcListGroups returned invalid results");
    244299
    245300        for (i=0; i < MIN(num_groups,100); i++) {
     
    249304                char *domain;
    250305                char *name;
     306                char *sid_string;
    251307
    252308                torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type),
    253                         "wbcLookupName failed");
     309                                      "wbcLookupName for %s failed", domain_name);
     310                wbcSidToString(&sid, &sid_string);
    254311                torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type),
    255                         "wbcLookupSid failed");
     312                                      "wbcLookupSid of %s failed", sid_string);
     313                wbcFreeMemory(sid_string);
    256314                torture_assert(tctx, name,
    257315                        "wbcLookupSid returned no name");
     
    269327
    270328        torture_assert_wbc_ok(tctx, wbcListTrusts(&domains, &num_domains),
    271                 "wbcListTrusts failed");
     329                              "%s", "wbcListTrusts failed");
    272330        torture_assert(tctx, !(num_domains > 0 && !domains),
    273331                "wbcListTrusts returned invalid results");
     
    283341                */
    284342                torture_assert_wbc_ok(tctx, wbcCheckTrustCredentials(domains[i].short_name, &error),
    285                         "wbcCheckTrustCredentials failed");
     343                                      "%s", "wbcCheckTrustCredentials failed");
    286344                /*
    287345                torture_assert_wbc_ok(tctx, wbcLookupName(domains[i].short_name, NULL, &sid, &name_type),
     
    309367
    310368        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    311                 "wbcInterfaceDetails failed");
     369                "%s", "wbcInterfaceDetails failed");
    312370
    313371        domain_name = talloc_strdup(tctx, details->netbios_domain);
     
    315373
    316374        torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info),
    317                 "wbcLookupDomainController failed");
     375                              "wbcLookupDomainController for %s failed", domain_name);
    318376        wbcFreeMemory(dc_info);
    319377
     
    328386
    329387        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    330                 "wbcInterfaceDetails failed");
     388                "%s", "wbcInterfaceDetails failed");
    331389
    332390        domain_name = talloc_strdup(tctx, details->netbios_domain);
     
    334392
    335393        torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info),
    336                 "wbcLookupDomainControllerEx failed");
     394                "wbcLookupDomainControllerEx for %s failed", domain_name);
    337395        wbcFreeMemory(dc_info);
    338396
     
    348406        name = torture_setting_string(tctx, "host", NULL);
    349407
     408        torture_comment(tctx, "test-WinsByName: host='%s'\n", name);
     409
    350410        ret = wbcResolveWinsByName(name, &ip);
    351411
    352412        if (is_ipaddress(name)) {
    353                 torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName failed");
     413                torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName of %s failed", name);
    354414        } else {
    355                 torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName failed");
     415                torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName for %s failed", name);
    356416        }
    357417
     
    362422{
    363423        const char *ip;
     424        const char *host;
     425        struct nbt_name nbt_name;
    364426        char *name;
    365427        wbcErr ret;
    366 
    367         ip = torture_setting_string(tctx, "host", NULL);
     428        NTSTATUS status;
     429
     430        host = torture_setting_string(tctx, "host", NULL);
     431
     432        torture_comment(tctx, "test-WinsByIp: host='%s'\n", host);
     433
     434        make_nbt_name_server(&nbt_name, host);
     435
     436        status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx),
     437                                 0, 0, &nbt_name, tctx, &ip, tctx->ev);
     438        torture_assert_ntstatus_ok(tctx, status,
     439                        talloc_asprintf(tctx,"Failed to resolve %s: %s",
     440                                        nbt_name.name, nt_errstr(status)));
     441
     442        torture_comment(tctx, "test-WinsByIp: ip='%s'\n", ip);
    368443
    369444        ret = wbcResolveWinsByIP(ip, &name);
    370445
    371         torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP failed");
     446        torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP for %s failed", ip);
    372447
    373448        wbcFreeMemory(name);
     
    388463        ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names,
    389464                            &types);
    390         torture_assert_wbc_ok(tctx, ret, "wbcLookupRids failed");
     465        torture_assert_wbc_ok(tctx, ret, "%s", "wbcLookupRids for 544 and 545 failed");
    391466
    392467        torture_assert_str_equal(
     
    396471                tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'");
    397472
    398         wbcFreeMemory((char *)domain_name);
     473        wbcFreeMemory(discard_const_p(char ,domain_name));
    399474        wbcFreeMemory(names);
    400475        wbcFreeMemory(types);
     
    414489
    415490        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    416                 "wbcInterfaceDetails failed");
     491                              "%s", "wbcInterfaceDetails failed");
    417492        torture_assert_wbc_ok(
    418493                tctx, wbcDomainInfo(details->netbios_domain, &info),
    419                 "wbcDomainInfo failed");
     494                "wbcDomainInfo of %s failed", details->netbios_domain);
    420495        wbcFreeMemory(details);
    421496
     
    428503        torture_assert_wbc_ok(
    429504                tctx, wbcStringToSid("S-1-5-32", &builtin),
    430                 "wbcStringToSid failed");
     505                "wbcStringToSid of %s failed", "S-1-5-32");
    431506
    432507        ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids);
    433         torture_assert_wbc_ok(tctx, ret, "wbcGetSidAliases failed");
     508        torture_assert_wbc_ok(tctx, ret, "%s", "wbcGetSidAliases failed");
    434509
    435510        wbcFreeMemory(rids);
     
    446521        wbcErr ret;
    447522
    448         ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password);
    449         torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    450                                  "wbcAuthenticateUser failed");
     523        ret = wbcAuthenticateUser(cli_credentials_get_username(cmdline_credentials), correct_password);
     524        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     525                                 "wbcAuthenticateUser of %s failed",
     526                                 cli_credentials_get_username(cmdline_credentials));
    451527
    452528        ZERO_STRUCT(params);
    453         params.account_name             = getenv("USERNAME");
     529        params.account_name             = cli_credentials_get_username(cmdline_credentials);
    454530        params.level                    = WBC_AUTH_USER_LEVEL_PLAIN;
    455531        params.password.plaintext       = correct_password;
     
    457533        ret = wbcAuthenticateUserEx(&params, &info, &error);
    458534        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    459                                  "wbcAuthenticateUserEx failed");
     535                                 "wbcAuthenticateUserEx of %s failed", params.account_name);
    460536        wbcFreeMemory(info);
    461537        info = NULL;
     
    467543        ret = wbcAuthenticateUserEx(&params, &info, &error);
    468544        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
    469                                  "wbcAuthenticateUserEx succeeded where it "
    470                                  "should have failed");
     545                                 "wbcAuthenticateUserEx for %s succeeded where it "
     546                                 "should have failed", params.account_name);
    471547        wbcFreeMemory(info);
    472548        info = NULL;
     
    480556static bool test_wbc_authenticate_user(struct torture_context *tctx)
    481557{
    482         return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
     558        return test_wbc_authenticate_user_int(tctx, cli_credentials_get_password(cmdline_credentials));
    483559}
    484560
     
    486562{
    487563        wbcErr ret;
    488         const char *oldpass = getenv("PASSWORD");
    489         const char *newpass = "Koo8irei";
     564        const char *oldpass = cli_credentials_get_password(cmdline_credentials);
     565        const char *newpass = "Koo8irei%$";
    490566
    491567        struct samr_CryptPassword new_nt_password;
     
    551627
    552628        params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE;
    553         params.account_name = getenv("USERNAME");
    554         params.domain_name = "SAMBA-TEST";
     629        params.account_name = cli_credentials_get_username(cmdline_credentials);
     630        params.domain_name = cli_credentials_get_domain(cmdline_credentials);
    555631
    556632        ret = wbcChangeUserPasswordEx(&params, NULL, NULL, NULL);
    557633        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    558                                  "wbcChangeUserPassword failed");
    559 
    560         if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) {
     634                                 "wbcChangeUserPassword for %s failed", params.account_name);
     635
     636        if (!test_wbc_authenticate_user_int(tctx, newpass)) {
    561637                return false;
    562638        }
    563639
    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"));
     640        ret = wbcChangeUserPassword(cli_credentials_get_username(cmdline_credentials), newpass,
     641                                    cli_credentials_get_password(cmdline_credentials));
     642        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     643                                 "wbcChangeUserPassword for %s failed", params.account_name);
     644
     645        return test_wbc_authenticate_user_int(tctx, cli_credentials_get_password(cmdline_credentials));
    570646}
    571647
     
    586662        ret = wbcLogonUser(&params, &info, &error, &policy);
    587663        torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM,
    588                                  "wbcLogonUser succeeded where it should "
     664                                 "%s", "wbcLogonUser succeeded for NULL where it should "
    589665                                 "have failed");
    590666
    591         params.username = getenv("USERNAME");
    592         params.password = getenv("PASSWORD");
     667        params.username = cli_credentials_get_username(cmdline_credentials);
     668        params.password = cli_credentials_get_password(cmdline_credentials);
    593669
    594670        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
    595671                              "foo", 0, discard_const_p(uint8_t, "bar"), 4);
    596672        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    597                                  "wbcAddNamedBlob failed");
     673                                 "%s", "wbcAddNamedBlob failed");
    598674
    599675        ret = wbcLogonUser(&params, &info, &error, &policy);
    600676        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    601                                  "wbcLogonUser failed");
     677                                 "wbcLogonUser for %s failed", params.username);
    602678        wbcFreeMemory(info); info = NULL;
    603679        wbcFreeMemory(error); error = NULL;
     
    608684        ret = wbcLogonUser(&params, &info, &error, &policy);
    609685        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
    610                                  "wbcLogonUser should have failed with "
    611                                  "WBC_ERR_AUTH_ERROR");
     686                                 "wbcLogonUser for %s should have failed with "
     687                                 "WBC_ERR_AUTH_ERROR", params.username);
    612688        wbcFreeMemory(info); info = NULL;
    613689        wbcFreeMemory(error); error = NULL;
     
    619695                              strlen("S-1-2-3-4")+1);
    620696        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    621                                  "wbcAddNamedBlob failed");
    622         params.password = getenv("PASSWORD");
     697                                 "%s", "wbcAddNamedBlob failed");
     698        params.password = cli_credentials_get_password(cmdline_credentials);
    623699        ret = wbcLogonUser(&params, &info, &error, &policy);
    624700        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
    625                                  "wbcLogonUser should have failed with "
    626                                  "WBC_ERR_AUTH_ERROR");
     701                                 "wbcLogonUser for %s should have failed with "
     702                                 "WBC_ERR_AUTH_ERROR", params.username);
    627703        wbcFreeMemory(info); info = NULL;
    628704        wbcFreeMemory(error); error = NULL;
     
    633709        ret = wbcInterfaceDetails(&iface);
    634710        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    635                                  "wbcInterfaceDetails failed");
    636 
    637         ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid,
     711                                 "%s", "wbcInterfaceDetails failed");
     712
     713        ret = wbcLookupName(iface->netbios_domain, cli_credentials_get_username(cmdline_credentials), &sid,
    638714                            &sidtype);
    639715        wbcFreeMemory(iface);
    640716        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    641                                  "wbcLookupName failed");
     717                                 "wbcLookupName for %s failed", cli_credentials_get_username(cmdline_credentials));
    642718
    643719        ret = wbcSidToString(&sid, &sidstr);
    644720        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    645                                  "wbcSidToString failed");
     721                                 "%s", "wbcSidToString failed");
    646722
    647723        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     
    649725                              (uint8_t *)sidstr, strlen(sidstr)+1);
    650726        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    651                                  "wbcAddNamedBlob failed");
     727                                 "%s", "wbcAddNamedBlob failed");
    652728        wbcFreeMemory(sidstr);
    653         params.password = getenv("PASSWORD");
     729        params.password = cli_credentials_get_password(cmdline_credentials);
    654730        ret = wbcLogonUser(&params, &info, &error, &policy);
    655731        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    656                                  "wbcLogonUser failed");
     732                                 "wbcLogonUser for %s failed", params.username);
    657733        wbcFreeMemory(info); info = NULL;
    658734        wbcFreeMemory(error); error = NULL;
     
    670746        gid_t *groups;
    671747
    672         ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups);
    673         torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
    674                                  "wbcGetGroups failed");
     748        ret = wbcGetGroups(cli_credentials_get_username(cmdline_credentials), &num_groups, &groups);
     749        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     750                                 "wbcGetGroups for %s failed", cli_credentials_get_username(cmdline_credentials));
    675751        wbcFreeMemory(groups);
    676752        return true;
     
    683759        torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
    684760        torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
     761        torture_suite_add_simple_test(suite, "wbcPingDc2", test_wbc_pingdc2);
    685762        torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
    686763        torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
  • vendor/current/nsswitch/libwbclient/wbc_err_internal.h

    r414 r988  
    3030                        goto done;              \
    3131                }                               \
    32         } while(0);
     32        } while(0)
    3333
    3434#define BAIL_ON_PTR_ERROR(x, status)                    \
     
    4040                        status = WBC_ERR_SUCCESS;       \
    4141                }                                       \
    42         } while (0);
     42        } while (0)
    4343
    4444
  • vendor/current/nsswitch/libwbclient/wbc_idmap.c

    r740 r988  
    2727
    2828/* Convert a Windows SID to a Unix uid, allocating an uid if needed */
    29 wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
     29wbcErr wbcCtxSidToUid(struct wbcContext *ctx, const struct wbcDomainSid *sid,
     30                      uid_t *puid)
    3031{
    3132        struct winbindd_request request;
     
    4748        /* Make request */
    4849
    49         wbc_status = wbcRequestResponse(WINBINDD_SID_TO_UID,
     50        wbc_status = wbcRequestResponse(ctx, WINBINDD_SID_TO_UID,
    5051                                        &request,
    5152                                        &response);
     
    5859 done:
    5960        return wbc_status;
     61}
     62
     63wbcErr wbcSidToUid(const struct wbcDomainSid *sid, uid_t *puid)
     64{
     65        return wbcCtxSidToUid(NULL, sid, puid);
    6066}
    6167
     
    6874
    6975/* Convert a Unix uid to a Windows SID, allocating a SID if needed */
    70 wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
     76wbcErr wbcCtxUidToSid(struct wbcContext *ctx, uid_t uid,
     77                      struct wbcDomainSid *sid)
    7178{
    7279        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    8895        /* Make request */
    8996
    90         wbc_status = wbcRequestResponse(WINBINDD_UID_TO_SID,
     97        wbc_status = wbcRequestResponse(ctx, WINBINDD_UID_TO_SID,
    9198                                        &request,
    9299                                        &response);
     
    98105done:
    99106        return wbc_status;
     107}
     108
     109wbcErr wbcUidToSid(uid_t uid, struct wbcDomainSid *sid)
     110{
     111        return wbcCtxUidToSid(NULL, uid, sid);
    100112}
    101113
     
    116128 **/
    117129
    118 wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
     130wbcErr wbcCtxSidToGid(struct wbcContext *ctx, const struct wbcDomainSid *sid,
     131                      gid_t *pgid)
    119132{
    120133        struct winbindd_request request;
     
    136149        /* Make request */
    137150
    138         wbc_status = wbcRequestResponse(WINBINDD_SID_TO_GID,
     151        wbc_status = wbcRequestResponse(ctx, WINBINDD_SID_TO_GID,
    139152                                        &request,
    140153                                        &response);
     
    149162}
    150163
     164wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid)
     165{
     166        return wbcCtxSidToGid(NULL, sid, pgid);
     167}
    151168
    152169/* Convert a Windows SID to a Unix gid if there already is a mapping */
     
    160177
    161178/* Convert a Unix gid to a Windows SID, allocating a SID if needed */
    162 wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
     179wbcErr wbcCtxGidToSid(struct wbcContext *ctx, gid_t gid,
     180                      struct wbcDomainSid *sid)
    163181{
    164182        struct winbindd_request request;
     
    180198        /* Make request */
    181199
    182         wbc_status = wbcRequestResponse(WINBINDD_GID_TO_SID,
     200        wbc_status = wbcRequestResponse(ctx, WINBINDD_GID_TO_SID,
    183201                                        &request,
    184202                                        &response);
     
    190208done:
    191209        return wbc_status;
     210}
     211
     212wbcErr wbcGidToSid(gid_t gid, struct wbcDomainSid *sid)
     213{
     214        return wbcCtxGidToSid(NULL, gid, sid);
    192215}
    193216
     
    200223
    201224/* Obtain a new uid from Winbind */
    202 wbcErr wbcAllocateUid(uid_t *puid)
     225wbcErr wbcCtxAllocateUid(struct wbcContext *ctx, uid_t *puid)
    203226{
    204227        struct winbindd_request request;
     
    216239        /* Make request */
    217240
    218         wbc_status = wbcRequestResponsePriv(WINBINDD_ALLOCATE_UID,
     241        wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_ALLOCATE_UID,
    219242                                            &request, &response);
    220243        BAIL_ON_WBC_ERROR(wbc_status);
     
    229252}
    230253
     254wbcErr wbcAllocateUid(uid_t *puid)
     255{
     256        return wbcCtxAllocateUid(NULL, puid);
     257}
     258
    231259/* Obtain a new gid from Winbind */
    232 wbcErr wbcAllocateGid(gid_t *pgid)
     260wbcErr wbcCtxAllocateGid(struct wbcContext *ctx, gid_t *pgid)
    233261{
    234262        struct winbindd_request request;
     
    246274        /* Make request */
    247275
    248         wbc_status = wbcRequestResponsePriv(WINBINDD_ALLOCATE_GID,
     276        wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_ALLOCATE_GID,
    249277                                            &request, &response);
    250278        BAIL_ON_WBC_ERROR(wbc_status);
     
    257285 done:
    258286        return wbc_status;
     287}
     288
     289wbcErr wbcAllocateGid(gid_t *pgid)
     290{
     291        return wbcCtxAllocateGid(NULL, pgid);
    259292}
    260293
     
    300333
    301334/* Convert a list of SIDs */
    302 wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
    303                         struct wbcUnixId *ids)
     335wbcErr wbcCtxSidsToUnixIds(struct wbcContext *ctx,
     336                           const struct wbcDomainSid *sids,
     337                           uint32_t num_sids, struct wbcUnixId *ids)
    304338{
    305339        struct winbindd_request request;
     
    342376        request.extra_len = p - sidlist;
    343377
    344         wbc_status = wbcRequestResponse(WINBINDD_SIDS_TO_XIDS,
     378        wbc_status = wbcRequestResponse(ctx, WINBINDD_SIDS_TO_XIDS,
    345379                                        &request, &response);
    346380        free(sidlist);
     
    371405                        id->id.gid = strtoul(p+1, &q, 10);
    372406                        break;
     407                case 'B':
     408                        id->type = WBC_ID_TYPE_BOTH;
     409                        id->id.uid = strtoul(p+1, &q, 10);
     410                        break;
    373411                default:
    374412                        id->type = WBC_ID_TYPE_NOT_SPECIFIED;
    375                         q = p;
     413                        q = strchr(p, '\n');
    376414                        break;
    377415                };
    378                 if (q[0] != '\n') {
     416                if (q == NULL || q[0] != '\n') {
    379417                        goto wbc_err_invalid;
    380418                }
     
    390428        return wbc_status;
    391429}
     430
     431wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
     432                        struct wbcUnixId *ids)
     433{
     434        return wbcCtxSidsToUnixIds(NULL, sids, num_sids, ids);
     435}
  • vendor/current/nsswitch/libwbclient/wbc_pam.c

    r740 r988  
    2929
    3030/* Authenticate a username/password pair */
    31 wbcErr wbcAuthenticateUser(const char *username,
    32                            const char *password)
     31wbcErr wbcCtxAuthenticateUser(struct wbcContext *ctx,
     32                              const char *username, const char *password)
    3333{
    3434        wbcErr wbc_status = WBC_ERR_SUCCESS;
     
    4141        params.password.plaintext       = password;
    4242
    43         wbc_status = wbcAuthenticateUserEx(&params, NULL, NULL);
     43        wbc_status = wbcCtxAuthenticateUserEx(ctx, &params, NULL, NULL);
    4444        BAIL_ON_WBC_ERROR(wbc_status);
    4545
    4646done:
    4747        return wbc_status;
     48}
     49
     50wbcErr wbcAuthenticateUser(const char *username, const char *password)
     51{
     52        return wbcCtxAuthenticateUser(NULL, username, password);
    4853}
    4954
     
    343348
    344349/* Authenticate with more detailed information */
    345 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
    346                              struct wbcAuthUserInfo **info,
    347                              struct wbcAuthErrorInfo **error)
     350wbcErr wbcCtxAuthenticateUserEx(struct wbcContext *ctx,
     351                                const struct wbcAuthUserParams *params,
     352                                struct wbcAuthUserInfo **info,
     353                                struct wbcAuthErrorInfo **error)
    348354{
    349355        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    364370        }
    365371
    366         if (!params->account_name) {
     372        if (params->level != WBC_AUTH_USER_LEVEL_PAC && !params->account_name) {
    367373                wbc_status = WBC_ERR_INVALID_PARAM;
    368374                BAIL_ON_WBC_ERROR(wbc_status);
     
    389395                        ZERO_STRUCT(sep_response);
    390396
    391                         wbc_status = wbcRequestResponse(WINBINDD_INFO,
     397                        wbc_status = wbcRequestResponse(ctx, WINBINDD_INFO,
    392398                                                        NULL, &sep_response);
    393399                        BAIL_ON_WBC_ERROR(wbc_status);
     
    491497                }
    492498                break;
     499
     500        case WBC_AUTH_USER_LEVEL_PAC:
     501                cmd = WINBINDD_PAM_AUTH_CRAP;
     502                request.flags = WBFLAG_PAM_AUTH_PAC | WBFLAG_PAM_INFO3_TEXT;
     503                request.extra_data.data = malloc(params->password.pac.length);
     504                if (request.extra_data.data == NULL) {
     505                        wbc_status = WBC_ERR_NO_MEMORY;
     506                        BAIL_ON_WBC_ERROR(wbc_status);
     507                }
     508                memcpy(request.extra_data.data, params->password.pac.data,
     509                       params->password.pac.length);
     510                request.extra_len = params->password.pac.length;
     511                break;
     512
    493513        default:
    494514                break;
     
    505525
    506526        if (cmd == WINBINDD_PAM_AUTH_CRAP) {
    507                 wbc_status = wbcRequestResponsePriv(cmd, &request, &response);
     527                wbc_status = wbcRequestResponsePriv(ctx, cmd,
     528                                                    &request, &response);
    508529        } else {
    509                 wbc_status = wbcRequestResponse(cmd, &request, &response);
     530                wbc_status = wbcRequestResponse(ctx, cmd,
     531                                                &request, &response);
    510532        }
    511533        if (response.data.auth.nt_status != 0) {
     
    534556}
    535557
     558wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
     559                             struct wbcAuthUserInfo **info,
     560                             struct wbcAuthErrorInfo **error)
     561{
     562        return wbcCtxAuthenticateUserEx(NULL, params, info, error);
     563}
     564
    536565/* Trigger a verification of the trust credentials of a specific domain */
    537 wbcErr wbcCheckTrustCredentials(const char *domain,
    538                                 struct wbcAuthErrorInfo **error)
     566wbcErr wbcCtxCheckTrustCredentials(struct wbcContext *ctx, const char *domain,
     567                                   struct wbcAuthErrorInfo **error)
    539568{
    540569        struct winbindd_request request;
     
    552581        /* Send request */
    553582
    554         wbc_status = wbcRequestResponsePriv(WINBINDD_CHECK_MACHACC,
     583        wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_CHECK_MACHACC,
    555584                                            &request, &response);
    556585        if (response.data.auth.nt_status != 0) {
     
    570599}
    571600
     601wbcErr wbcCheckTrustCredentials(const char *domain,
     602                                struct wbcAuthErrorInfo **error)
     603{
     604        return wbcCtxCheckTrustCredentials(NULL, domain, error);
     605}
     606
    572607/* Trigger a change of the trust credentials for a specific domain */
    573 wbcErr wbcChangeTrustCredentials(const char *domain,
    574                                  struct wbcAuthErrorInfo **error)
     608wbcErr wbcCtxChangeTrustCredentials(struct wbcContext *ctx, const char *domain,
     609                                    struct wbcAuthErrorInfo **error)
    575610{
    576611        struct winbindd_request request;
     
    588623        /* Send request */
    589624
    590         wbc_status = wbcRequestResponsePriv(WINBINDD_CHANGE_MACHACC,
    591                                         &request, &response);
     625        wbc_status = wbcRequestResponsePriv(ctx, WINBINDD_CHANGE_MACHACC,
     626                                            &request, &response);
    592627        if (response.data.auth.nt_status != 0) {
    593628                if (error) {
     
    606641}
    607642
     643wbcErr wbcChangeTrustCredentials(const char *domain,
     644                                 struct wbcAuthErrorInfo **error)
     645{
     646        return wbcCtxChangeTrustCredentials(NULL, domain, error);
     647}
     648
    608649/*
    609650 * Trigger a no-op NETLOGON call. Lightweight version of
    610651 * wbcCheckTrustCredentials
    611652 */
     653wbcErr wbcCtxPingDc(struct wbcContext *ctx, const char *domain,
     654                    struct wbcAuthErrorInfo **error)
     655{
     656        return wbcCtxPingDc2(ctx, domain, error, NULL);
     657}
     658
    612659wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
     660{
     661        return wbcPingDc2(domain, error, NULL);
     662}
     663
     664/*
     665 * Trigger a no-op NETLOGON call. Lightweight version of
     666 * wbcCheckTrustCredentials, optionally return attempted DC
     667 */
     668wbcErr wbcCtxPingDc2(struct wbcContext *ctx, const char *domain,
     669                     struct wbcAuthErrorInfo **error, char **dcname)
    613670{
    614671        struct winbindd_request request;
     
    616673        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    617674
    618         if (domain) {
    619                 /*
    620                  * the current protocol doesn't support
    621                  * specifying a domain
    622                  */
    623                 wbc_status = WBC_ERR_NOT_IMPLEMENTED;
    624                 BAIL_ON_WBC_ERROR(wbc_status);
    625         }
    626 
    627675        ZERO_STRUCT(request);
    628676        ZERO_STRUCT(response);
    629677
     678        if (domain) {
     679                strncpy(request.domain_name, domain,
     680                        sizeof(request.domain_name)-1);
     681        }
     682
    630683        /* Send request */
    631684
    632         wbc_status = wbcRequestResponse(WINBINDD_PING_DC,
     685        wbc_status = wbcRequestResponse(ctx, WINBINDD_PING_DC,
    633686                                        &request,
    634687                                        &response);
     688
     689        if (dcname && response.extra_data.data) {
     690                size_t len;
     691
     692                len = response.length - sizeof(struct winbindd_response);
     693                *dcname = wbcAllocateMemory(1, len, NULL);
     694                BAIL_ON_PTR_ERROR(*dcname, wbc_status);
     695
     696                strlcpy(*dcname, response.extra_data.data, len);
     697        }
     698
    635699        if (response.data.auth.nt_status != 0) {
    636700                if (error) {
     
    649713}
    650714
     715wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
     716                  char **dcname)
     717{
     718        return wbcCtxPingDc2(NULL, domain, error, dcname);
     719}
     720
    651721/* Trigger an extended logoff notification to Winbind for a specific user */
    652 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
    653                        struct wbcAuthErrorInfo **error)
     722wbcErr wbcCtxLogoffUserEx(struct wbcContext *ctx,
     723                          const struct wbcLogoffUserParams *params,
     724                          struct wbcAuthErrorInfo **error)
    654725{
    655726        struct winbindd_request request;
     
    714785        /* Send request */
    715786
    716         wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
     787        wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_LOGOFF,
    717788                                        &request,
    718789                                        &response);
     
    735806}
    736807
     808wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
     809                       struct wbcAuthErrorInfo **error)
     810{
     811        return wbcCtxLogoffUserEx(NULL, params, error);
     812}
     813
    737814/* Trigger a logoff notification to Winbind for a specific user */
     815wbcErr wbcCtxLogoffUser(struct wbcContext *ctx,
     816                        const char *username, uid_t uid,
     817                        const char *ccfilename)
     818{
     819        struct winbindd_request request;
     820        struct winbindd_response response;
     821        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     822
     823        /* validate input */
     824
     825        if (!username) {
     826                wbc_status = WBC_ERR_INVALID_PARAM;
     827                BAIL_ON_WBC_ERROR(wbc_status);
     828        }
     829
     830        ZERO_STRUCT(request);
     831        ZERO_STRUCT(response);
     832
     833        strncpy(request.data.logoff.user, username,
     834                sizeof(request.data.logoff.user)-1);
     835        request.data.logoff.uid = uid;
     836
     837        if (ccfilename) {
     838                strncpy(request.data.logoff.krb5ccname, ccfilename,
     839                        sizeof(request.data.logoff.krb5ccname)-1);
     840        }
     841
     842        /* Send request */
     843
     844        wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_LOGOFF,
     845                                        &request,
     846                                        &response);
     847
     848        /* Take the response above and return it to the caller */
     849
     850 done:
     851        return wbc_status;
     852}
     853
    738854wbcErr wbcLogoffUser(const char *username,
    739855                     uid_t uid,
    740856                     const char *ccfilename)
    741857{
    742         struct winbindd_request request;
    743         struct winbindd_response response;
    744         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    745 
    746         /* validate input */
    747 
    748         if (!username) {
    749                 wbc_status = WBC_ERR_INVALID_PARAM;
    750                 BAIL_ON_WBC_ERROR(wbc_status);
    751         }
    752 
    753         ZERO_STRUCT(request);
    754         ZERO_STRUCT(response);
    755 
    756         strncpy(request.data.logoff.user, username,
    757                 sizeof(request.data.logoff.user)-1);
    758         request.data.logoff.uid = uid;
    759 
    760         if (ccfilename) {
    761                 strncpy(request.data.logoff.krb5ccname, ccfilename,
    762                         sizeof(request.data.logoff.krb5ccname)-1);
    763         }
    764 
    765         /* Send request */
    766 
    767         wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
    768                                         &request,
    769                                         &response);
    770 
    771         /* Take the response above and return it to the caller */
    772 
    773  done:
    774         return wbc_status;
     858        return wbcCtxLogoffUser(NULL, username, uid, ccfilename);
    775859}
    776860
    777861/* Change a password for a user with more detailed information upon failure */
    778 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
    779                                struct wbcAuthErrorInfo **error,
    780                                enum wbcPasswordChangeRejectReason *reject_reason,
    781                                struct wbcUserPasswordPolicyInfo **policy)
     862wbcErr wbcCtxChangeUserPasswordEx(struct wbcContext *ctx,
     863                        const struct wbcChangePasswordParams *params,
     864                        struct wbcAuthErrorInfo **error,
     865                        enum wbcPasswordChangeRejectReason *reject_reason,
     866                        struct wbcUserPasswordPolicyInfo **policy)
    782867{
    783868        struct winbindd_request request;
     
    9381023        /* Send request */
    9391024
    940         wbc_status = wbcRequestResponse(cmd,
     1025        wbc_status = wbcRequestResponse(ctx, cmd,
    9411026                                        &request,
    9421027                                        &response);
     
    9731058}
    9741059
     1060wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
     1061                              struct wbcAuthErrorInfo **error,
     1062                              enum wbcPasswordChangeRejectReason *reject_reason,
     1063                              struct wbcUserPasswordPolicyInfo **policy)
     1064{
     1065        return wbcCtxChangeUserPasswordEx(NULL, params, error,
     1066                                          reject_reason, policy);
     1067}
     1068
    9751069/* Change a password for a user */
    976 wbcErr wbcChangeUserPassword(const char *username,
    977                              const char *old_password,
    978                              const char *new_password)
     1070wbcErr wbcCtxChangeUserPassword(struct wbcContext *ctx,
     1071                                const char *username,
     1072                                const char *old_password,
     1073                                const char *new_password)
    9791074{
    9801075        wbcErr wbc_status = WBC_ERR_SUCCESS;
     
    9881083        params.new_password.plaintext   = new_password;
    9891084
    990         wbc_status = wbcChangeUserPasswordEx(&params,
    991                                              NULL,
    992                                              NULL,
    993                                              NULL);
     1085        wbc_status = wbcCtxChangeUserPasswordEx(ctx, &params,
     1086                                                NULL,
     1087                                                NULL,
     1088                                                NULL);
    9941089        BAIL_ON_WBC_ERROR(wbc_status);
    9951090
     
    9981093}
    9991094
     1095wbcErr wbcChangeUserPassword(const char *username,
     1096                             const char *old_password,
     1097                             const char *new_password)
     1098{
     1099        return wbcCtxChangeUserPassword(NULL, username,
     1100                                        old_password, new_password);
     1101}
     1102
    10001103/* Logon a User */
    1001 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
    1002                     struct wbcLogonUserInfo **info,
    1003                     struct wbcAuthErrorInfo **error,
    1004                     struct wbcUserPasswordPolicyInfo **policy)
     1104wbcErr wbcCtxLogonUser(struct wbcContext *ctx,
     1105                       const struct wbcLogonUserParams *params,
     1106                       struct wbcLogonUserInfo **info,
     1107                       struct wbcAuthErrorInfo **error,
     1108                       struct wbcUserPasswordPolicyInfo **policy)
    10051109{
    10061110        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    11041208        }
    11051209
    1106         wbc_status = wbcRequestResponse(WINBINDD_PAM_AUTH,
     1210        wbc_status = wbcRequestResponse(ctx, WINBINDD_PAM_AUTH,
    11071211                                        &request,
    11081212                                        &response);
     
    11381242}
    11391243
     1244wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
     1245                    struct wbcLogonUserInfo **info,
     1246                    struct wbcAuthErrorInfo **error,
     1247                    struct wbcUserPasswordPolicyInfo **policy)
     1248{
     1249        return wbcCtxLogonUser(NULL, params, info, error, policy);
     1250}
     1251
    11401252static void wbcCredentialCacheInfoDestructor(void *ptr)
    11411253{
     
    11461258
    11471259/* Authenticate a user with cached credentials */
    1148 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
    1149                           struct wbcCredentialCacheInfo **info,
    1150                           struct wbcAuthErrorInfo **error)
     1260wbcErr wbcCtxCredentialCache(struct wbcContext *ctx,
     1261                             struct wbcCredentialCacheParams *params,
     1262                             struct wbcCredentialCacheInfo **info,
     1263                             struct wbcAuthErrorInfo **error)
    11511264{
    11521265        wbcErr status = WBC_ERR_UNKNOWN_FAILURE;
     
    11611274        ZERO_STRUCT(response);
    11621275
    1163         if (info != NULL) {
    1164                 *info = NULL;
    1165         }
     1276        *info = NULL;
     1277
    11661278        if (error != NULL) {
    11671279                *error = NULL;
     
    11741286        }
    11751287
     1288        for (i=0; i<params->num_blobs; i++) {
     1289                /*
     1290                 * Older callers may used to provide the NEGOTIATE request
     1291                 * as "initial_blob", but it was completely ignored by winbindd.
     1292                 *
     1293                 * So we keep ignoring it.
     1294                 *
     1295                 * A new callers that is capable to support "new_spnego",
     1296                 * will provide the NEGOTIATE request as "negotiate_blob"
     1297                 * instead.
     1298                 */
     1299                if (strcasecmp(params->blobs[i].name, "negotiate_blob") == 0) {
     1300                        if (initial_blob != NULL) {
     1301                                status = WBC_ERR_INVALID_PARAM;
     1302                                goto fail;
     1303                        }
     1304                        initial_blob = &params->blobs[i];
     1305                        continue;
     1306                }
     1307                if (strcasecmp(params->blobs[i].name, "challenge_blob") == 0) {
     1308                        if (challenge_blob != NULL) {
     1309                                status = WBC_ERR_INVALID_PARAM;
     1310                                goto fail;
     1311                        }
     1312                        challenge_blob = &params->blobs[i];
     1313                        continue;
     1314                }
     1315        }
     1316
    11761317        if (params->domain_name != NULL) {
    1177                 status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
     1318                status = wbcRequestResponse(ctx, WINBINDD_INFO,
     1319                                            NULL, &response);
    11781320                if (!WBC_ERROR_IS_OK(status)) {
    11791321                        goto fail;
     
    11911333        request.data.ccache_ntlm_auth.uid = getuid();
    11921334
    1193         for (i=0; i<params->num_blobs; i++) {
    1194                 if (strcasecmp(params->blobs[i].name, "initial_blob") == 0) {
    1195                         initial_blob = &params->blobs[i];
    1196                         break;
    1197                 }
    1198                 if (strcasecmp(params->blobs[i].name, "challenge_blob") == 0) {
    1199                         challenge_blob = &params->blobs[i];
    1200                         break;
    1201                 }
    1202         }
    1203 
    12041335        request.data.ccache_ntlm_auth.initial_blob_len = 0;
    12051336        request.data.ccache_ntlm_auth.challenge_blob_len = 0;
     
    12351366        }
    12361367
    1237         status = wbcRequestResponse(WINBINDD_CCACHE_NTLMAUTH, &request,
    1238                                     &response);
     1368        status = wbcRequestResponse(ctx, WINBINDD_CCACHE_NTLMAUTH,
     1369                                    &request, &response);
    12391370        if (!WBC_ERROR_IS_OK(status)) {
    12401371                goto fail;
     
    12641395                goto fail;
    12651396        }
     1397        if (response.data.ccache_ntlm_auth.new_spnego) {
     1398                status = wbcAddNamedBlob(
     1399                        &result->num_blobs, &result->blobs, "new_spnego", 0,
     1400                        &response.data.ccache_ntlm_auth.new_spnego,
     1401                        sizeof(response.data.ccache_ntlm_auth.new_spnego));
     1402                if (!WBC_ERROR_IS_OK(status)) {
     1403                        goto fail;
     1404                }
     1405        }
    12661406
    12671407        *info = result;
     
    12751415}
    12761416
     1417wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
     1418                          struct wbcCredentialCacheInfo **info,
     1419                          struct wbcAuthErrorInfo **error)
     1420{
     1421        return wbcCtxCredentialCache(NULL, params, info, error);
     1422}
     1423
    12771424/* Authenticate a user with cached credentials */
    1278 wbcErr wbcCredentialSave(const char *user, const char *password)
     1425wbcErr wbcCtxCredentialSave(struct wbcContext *ctx,
     1426                            const char *user, const char *password)
    12791427{
    12801428        struct winbindd_request request;
     
    12901438        request.data.ccache_save.uid = getuid();
    12911439
    1292         return wbcRequestResponse(WINBINDD_CCACHE_SAVE, &request, &response);
    1293 }
     1440        return wbcRequestResponse(ctx, WINBINDD_CCACHE_SAVE, &request, &response);
     1441}
     1442
     1443wbcErr wbcCredentialSave(const char *user, const char *password)
     1444{
     1445        return wbcCtxCredentialSave(NULL, user, password);
     1446}
  • vendor/current/nsswitch/libwbclient/wbc_pwd.c

    r740 r988  
    55
    66   Copyright (C) Gerald (Jerry) Carter 2007
     7   Copyright (C) Matthew Newton 2015
    78
    89
     
    168169
    169170/* Fill in a struct passwd* for a domain user based on username */
    170 wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
     171wbcErr wbcCtxGetpwnam(struct wbcContext *ctx,
     172                      const char *name, struct passwd **pwd)
    171173{
    172174        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    188190        strncpy(request.data.username, name, sizeof(request.data.username)-1);
    189191
    190         wbc_status = wbcRequestResponse(WINBINDD_GETPWNAM,
     192        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWNAM,
    191193                                        &request,
    192194                                        &response);
     
    200202}
    201203
     204wbcErr wbcGetpwnam(const char *name, struct passwd **pwd)
     205{
     206        return wbcCtxGetpwnam(NULL, name, pwd);
     207}
     208
    202209/* Fill in a struct passwd* for a domain user based on uid */
    203 wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
     210wbcErr wbcCtxGetpwuid(struct wbcContext *ctx, uid_t uid, struct passwd **pwd)
    204211{
    205212        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    219226        request.data.uid = uid;
    220227
    221         wbc_status = wbcRequestResponse(WINBINDD_GETPWUID,
     228        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWUID,
    222229                                        &request,
    223230                                        &response);
     
    231238}
    232239
     240wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd)
     241{
     242        return wbcCtxGetpwuid(NULL, uid, pwd);
     243}
     244
    233245/* Fill in a struct passwd* for a domain user based on sid */
    234 wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
     246wbcErr wbcCtxGetpwsid(struct wbcContext *ctx,
     247                      struct wbcDomainSid *sid, struct passwd **pwd)
    235248{
    236249        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    250263        wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid));
    251264
    252         wbc_status = wbcRequestResponse(WINBINDD_GETPWSID,
     265        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWSID,
    253266                                        &request,
    254267                                        &response);
     
    262275}
    263276
     277wbcErr wbcGetpwsid(struct wbcDomainSid *sid, struct passwd **pwd)
     278{
     279        return wbcCtxGetpwsid(NULL, sid, pwd);
     280}
     281
    264282/* Fill in a struct passwd* for a domain user based on username */
    265 wbcErr wbcGetgrnam(const char *name, struct group **grp)
     283wbcErr wbcCtxGetgrnam(struct wbcContext *ctx,
     284                      const char *name, struct group **grp)
    266285{
    267286        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    283302        strncpy(request.data.groupname, name, sizeof(request.data.groupname)-1);
    284303
    285         wbc_status = wbcRequestResponse(WINBINDD_GETGRNAM,
     304        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRNAM,
    286305                                        &request,
    287306                                        &response);
     
    298317}
    299318
     319wbcErr wbcGetgrnam(const char *name, struct group **grp)
     320{
     321        return wbcCtxGetgrnam(NULL, name, grp);
     322}
     323
    300324/* Fill in a struct passwd* for a domain user based on uid */
    301 wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
     325wbcErr wbcCtxGetgrgid(struct wbcContext *ctx, gid_t gid, struct group **grp)
    302326{
    303327        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    317341        request.data.gid = gid;
    318342
    319         wbc_status = wbcRequestResponse(WINBINDD_GETGRGID,
     343        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRGID,
    320344                                        &request,
    321345                                        &response);
     
    332356}
    333357
    334 /** @brief Number of cached passwd structs
    335  *
    336  */
    337 static uint32_t pw_cache_size;
    338 
    339 /** @brief Position of the pwent context
    340  *
    341  */
    342 static uint32_t pw_cache_idx;
     358wbcErr wbcGetgrgid(gid_t gid, struct group **grp)
     359{
     360        return wbcCtxGetgrgid(NULL, gid, grp);
     361}
    343362
    344363/** @brief Winbindd response containing the passwd structs
     
    348367
    349368/* Reset the passwd iterator */
     369wbcErr wbcCtxSetpwent(struct wbcContext *ctx)
     370{
     371        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     372
     373        if (!ctx) {
     374                ctx = wbcGetGlobalCtx();
     375        }
     376
     377        if (ctx->pw_cache_size > 0) {
     378                ctx->pw_cache_idx = ctx->pw_cache_size = 0;
     379                winbindd_free_response(&pw_response);
     380        }
     381
     382        ZERO_STRUCT(pw_response);
     383
     384        wbc_status = wbcRequestResponse(ctx, WINBINDD_SETPWENT,
     385                                        NULL, NULL);
     386        BAIL_ON_WBC_ERROR(wbc_status);
     387
     388 done:
     389        return wbc_status;
     390}
     391
    350392wbcErr wbcSetpwent(void)
    351393{
    352         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    353 
    354         if (pw_cache_size > 0) {
    355                 pw_cache_idx = pw_cache_size = 0;
     394        return wbcCtxSetpwent(NULL);
     395}
     396
     397/* Close the passwd iterator */
     398wbcErr wbcCtxEndpwent(struct wbcContext *ctx)
     399{
     400        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     401
     402        if (!ctx) {
     403                ctx = wbcGetGlobalCtx();
     404        }
     405
     406        if (ctx->pw_cache_size > 0) {
     407                ctx->pw_cache_idx = ctx->pw_cache_size = 0;
    356408                winbindd_free_response(&pw_response);
    357409        }
    358410
    359         ZERO_STRUCT(pw_response);
    360 
    361         wbc_status = wbcRequestResponse(WINBINDD_SETPWENT,
     411        wbc_status = wbcRequestResponse(ctx, WINBINDD_ENDPWENT,
    362412                                        NULL, NULL);
    363413        BAIL_ON_WBC_ERROR(wbc_status);
     
    367417}
    368418
    369 /* Close the passwd iterator */
    370419wbcErr wbcEndpwent(void)
    371420{
    372         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    373 
    374         if (pw_cache_size > 0) {
    375                 pw_cache_idx = pw_cache_size = 0;
    376                 winbindd_free_response(&pw_response);
    377         }
    378 
    379         wbc_status = wbcRequestResponse(WINBINDD_ENDPWENT,
    380                                         NULL, NULL);
    381         BAIL_ON_WBC_ERROR(wbc_status);
    382 
    383  done:
    384         return wbc_status;
     421        return wbcCtxEndpwent(NULL);
    385422}
    386423
    387424/* Return the next struct passwd* entry from the pwent iterator */
     425wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd)
     426{
     427        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     428        struct winbindd_request request;
     429        struct winbindd_pw *wb_pw;
     430
     431        if (!ctx) {
     432                ctx = wbcGetGlobalCtx();
     433        }
     434
     435        /* If there's a cached result, return that. */
     436        if (ctx->pw_cache_idx < ctx->pw_cache_size) {
     437                goto return_result;
     438        }
     439
     440        /* Otherwise, query winbindd for some entries. */
     441
     442        ctx->pw_cache_idx = 0;
     443
     444        winbindd_free_response(&pw_response);
     445
     446        ZERO_STRUCT(request);
     447        request.data.num_entries = MAX_GETPWENT_USERS;
     448
     449        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETPWENT, &request,
     450                                        &pw_response);
     451
     452        BAIL_ON_WBC_ERROR(wbc_status);
     453
     454        ctx->pw_cache_size = pw_response.data.num_entries;
     455
     456return_result:
     457
     458        wb_pw = (struct winbindd_pw *) pw_response.extra_data.data;
     459
     460        *pwd = copy_passwd_entry(&wb_pw[ctx->pw_cache_idx]);
     461
     462        BAIL_ON_PTR_ERROR(*pwd, wbc_status);
     463
     464        ctx->pw_cache_idx++;
     465
     466done:
     467        return wbc_status;
     468}
     469
    388470wbcErr wbcGetpwent(struct passwd **pwd)
    389471{
    390         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    391         struct winbindd_request request;
    392         struct winbindd_pw *wb_pw;
    393 
    394         /* If there's a cached result, return that. */
    395         if (pw_cache_idx < pw_cache_size) {
    396                 goto return_result;
    397         }
    398 
    399         /* Otherwise, query winbindd for some entries. */
    400 
    401         pw_cache_idx = 0;
    402 
    403         winbindd_free_response(&pw_response);
    404 
    405         ZERO_STRUCT(request);
    406         request.data.num_entries = MAX_GETPWENT_USERS;
    407 
    408         wbc_status = wbcRequestResponse(WINBINDD_GETPWENT, &request,
    409                                         &pw_response);
    410 
    411         BAIL_ON_WBC_ERROR(wbc_status);
    412 
    413         pw_cache_size = pw_response.data.num_entries;
    414 
    415 return_result:
    416 
    417         wb_pw = (struct winbindd_pw *) pw_response.extra_data.data;
    418 
    419         *pwd = copy_passwd_entry(&wb_pw[pw_cache_idx]);
    420 
    421         BAIL_ON_PTR_ERROR(*pwd, wbc_status);
    422 
    423         pw_cache_idx++;
    424 
    425 done:
    426         return wbc_status;
    427 }
    428 
    429 /** @brief Number of cached group structs
    430  *
    431  */
    432 static uint32_t gr_cache_size;
    433 
    434 /** @brief Position of the grent context
    435  *
    436  */
    437 static uint32_t gr_cache_idx;
     472        return wbcCtxGetpwent(NULL, pwd);
     473}
    438474
    439475/** @brief Winbindd response containing the group structs
     
    443479
    444480/* Reset the group iterator */
     481wbcErr wbcCtxSetgrent(struct wbcContext *ctx)
     482{
     483        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     484
     485        if (!ctx) {
     486                ctx = wbcGetGlobalCtx();
     487        }
     488
     489        if (ctx->gr_cache_size > 0) {
     490                ctx->gr_cache_idx = ctx->gr_cache_size = 0;
     491                winbindd_free_response(&gr_response);
     492        }
     493
     494        ZERO_STRUCT(gr_response);
     495
     496        wbc_status = wbcRequestResponse(ctx, WINBINDD_SETGRENT,
     497                                        NULL, NULL);
     498        BAIL_ON_WBC_ERROR(wbc_status);
     499
     500 done:
     501        return wbc_status;
     502}
     503
    445504wbcErr wbcSetgrent(void)
    446505{
    447         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    448 
    449         if (gr_cache_size > 0) {
    450                 gr_cache_idx = gr_cache_size = 0;
     506        return wbcCtxSetgrent(NULL);
     507}
     508
     509/* Close the group iterator */
     510wbcErr wbcCtxEndgrent(struct wbcContext *ctx)
     511{
     512        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     513
     514        if (!ctx) {
     515                ctx = wbcGetGlobalCtx();
     516        }
     517
     518        if (ctx->gr_cache_size > 0) {
     519                ctx->gr_cache_idx = ctx->gr_cache_size = 0;
    451520                winbindd_free_response(&gr_response);
    452521        }
    453522
    454         ZERO_STRUCT(gr_response);
    455 
    456         wbc_status = wbcRequestResponse(WINBINDD_SETGRENT,
     523        wbc_status = wbcRequestResponse(ctx, WINBINDD_ENDGRENT,
    457524                                        NULL, NULL);
    458525        BAIL_ON_WBC_ERROR(wbc_status);
     
    462529}
    463530
    464 /* Close the group iterator */
    465531wbcErr wbcEndgrent(void)
    466532{
    467         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    468 
    469         if (gr_cache_size > 0) {
    470                 gr_cache_idx = gr_cache_size = 0;
    471                 winbindd_free_response(&gr_response);
    472         }
    473 
    474         wbc_status = wbcRequestResponse(WINBINDD_ENDGRENT,
    475                                         NULL, NULL);
    476         BAIL_ON_WBC_ERROR(wbc_status);
    477 
    478  done:
    479         return wbc_status;
     533        return wbcCtxEndgrent(NULL);
    480534}
    481535
    482536/* Return the next struct group* entry from the pwent iterator */
    483 wbcErr wbcGetgrent(struct group **grp)
     537wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp)
    484538{
    485539        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    488542        uint32_t mem_ofs;
    489543
     544        if (!ctx) {
     545                ctx = wbcGetGlobalCtx();
     546        }
     547
    490548        /* If there's a cached result, return that. */
    491         if (gr_cache_idx < gr_cache_size) {
     549        if (ctx->gr_cache_idx < ctx->gr_cache_size) {
    492550                goto return_result;
    493551        }
     
    495553        /* Otherwise, query winbindd for some entries. */
    496554
    497         gr_cache_idx = 0;
     555        ctx->gr_cache_idx = 0;
    498556
    499557        winbindd_free_response(&gr_response);
     
    502560        request.data.num_entries = MAX_GETGRENT_GROUPS;
    503561
    504         wbc_status = wbcRequestResponse(WINBINDD_GETGRENT, &request,
    505                                         &gr_response);
    506 
    507         BAIL_ON_WBC_ERROR(wbc_status);
    508 
    509         gr_cache_size = gr_response.data.num_entries;
     562        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRENT,
     563                                        &request, &gr_response);
     564
     565        BAIL_ON_WBC_ERROR(wbc_status);
     566
     567        ctx->gr_cache_size = gr_response.data.num_entries;
    510568
    511569return_result:
     
    513571        wb_gr = (struct winbindd_gr *) gr_response.extra_data.data;
    514572
    515         mem_ofs = wb_gr[gr_cache_idx].gr_mem_ofs +
    516                   gr_cache_size * sizeof(struct winbindd_gr);
    517 
    518         *grp = copy_group_entry(&wb_gr[gr_cache_idx],
     573        mem_ofs = wb_gr[ctx->gr_cache_idx].gr_mem_ofs +
     574                  ctx->gr_cache_size * sizeof(struct winbindd_gr);
     575
     576        *grp = copy_group_entry(&wb_gr[ctx->gr_cache_idx],
    519577                                ((char *)gr_response.extra_data.data)+mem_ofs);
    520578
    521579        BAIL_ON_PTR_ERROR(*grp, wbc_status);
    522580
    523         gr_cache_idx++;
     581        ctx->gr_cache_idx++;
    524582
    525583done:
     
    527585}
    528586
     587wbcErr wbcGetgrent(struct group **grp)
     588{
     589        return wbcCtxGetgrent(NULL, grp);
     590}
     591
    529592/* Return the next struct group* entry from the pwent iterator */
    530 wbcErr wbcGetgrlist(struct group **grp)
     593wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp)
    531594{
    532595        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    534597        struct winbindd_gr *wb_gr;
    535598
     599        if (!ctx) {
     600                ctx = wbcGetGlobalCtx();
     601        }
     602
    536603        /* If there's a cached result, return that. */
    537         if (gr_cache_idx < gr_cache_size) {
     604        if (ctx->gr_cache_idx < ctx->gr_cache_size) {
    538605                goto return_result;
    539606        }
     
    541608        /* Otherwise, query winbindd for some entries. */
    542609
    543         gr_cache_idx = 0;
     610        ctx->gr_cache_idx = 0;
    544611
    545612        winbindd_free_response(&gr_response);
     
    549616        request.data.num_entries = MAX_GETGRENT_GROUPS;
    550617
    551         wbc_status = wbcRequestResponse(WINBINDD_GETGRLST, &request,
    552                                         &gr_response);
    553 
    554         BAIL_ON_WBC_ERROR(wbc_status);
    555 
    556         gr_cache_size = gr_response.data.num_entries;
     618        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGRLST,
     619                                        &request, &gr_response);
     620
     621        BAIL_ON_WBC_ERROR(wbc_status);
     622
     623        ctx->gr_cache_size = gr_response.data.num_entries;
    557624
    558625return_result:
     
    560627        wb_gr = (struct winbindd_gr *) gr_response.extra_data.data;
    561628
    562         *grp = copy_group_entry(&wb_gr[gr_cache_idx], NULL);
     629        *grp = copy_group_entry(&wb_gr[ctx->gr_cache_idx], NULL);
    563630
    564631        BAIL_ON_PTR_ERROR(*grp, wbc_status);
    565632
    566         gr_cache_idx++;
     633        ctx->gr_cache_idx++;
    567634
    568635done:
     
    570637}
    571638
     639wbcErr wbcGetgrlist(struct group **grp)
     640{
     641        return wbcCtxGetgrlist(NULL, grp);
     642}
     643
    572644/* Return the unix group array belonging to the given user */
    573 wbcErr wbcGetGroups(const char *account,
    574                     uint32_t *num_groups,
    575                     gid_t **_groups)
     645wbcErr wbcCtxGetGroups(struct wbcContext *ctx, const char *account,
     646                       uint32_t *num_groups, gid_t **_groups)
    576647{
    577648        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    595666        strncpy(request.data.username, account, sizeof(request.data.username)-1);
    596667
    597         wbc_status = wbcRequestResponse(WINBINDD_GETGROUPS,
     668        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETGROUPS,
    598669                                        &request,
    599670                                        &response);
     
    619690        return wbc_status;
    620691}
     692
     693wbcErr wbcGetGroups(const char *account, uint32_t *num_groups, gid_t **_groups)
     694{
     695        return wbcCtxGetGroups(NULL, account, num_groups, _groups);
     696}
  • vendor/current/nsswitch/libwbclient/wbc_sid.c

    r860 r988  
    3333int wbcSidToStringBuf(const struct wbcDomainSid *sid, char *buf, int buflen)
    3434{
    35         uint32_t id_auth;
     35        uint64_t id_auth;
    3636        int i, ofs;
    3737
     
    4141        }
    4242
    43         /*
    44          * BIG NOTE: this function only does SIDS where the identauth is not
    45          * >= ^32 in a range of 2^48.
    46          */
    47 
    48         id_auth = sid->id_auth[5] +
    49                 (sid->id_auth[4] << 8) +
    50                 (sid->id_auth[3] << 16) +
    51                 (sid->id_auth[2] << 24);
    52 
    53         ofs = snprintf(buf, buflen, "S-%u-%lu",
    54                        (unsigned int)sid->sid_rev_num, (unsigned long)id_auth);
     43        id_auth = (uint64_t)sid->id_auth[5] +
     44                ((uint64_t)sid->id_auth[4] << 8) +
     45                ((uint64_t)sid->id_auth[3] << 16) +
     46                ((uint64_t)sid->id_auth[2] << 24) +
     47                ((uint64_t)sid->id_auth[1] << 32) +
     48                ((uint64_t)sid->id_auth[0] << 40);
     49
     50        ofs = snprintf(buf, buflen, "S-%hhu-", (unsigned char)sid->sid_rev_num);
     51        if (id_auth >= UINT32_MAX) {
     52                ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "0x%llx",
     53                                (unsigned long long)id_auth);
     54        } else {
     55                ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "%llu",
     56                                (unsigned long long)id_auth);
     57        }
    5558
    5659        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]);
     60                ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%u",
     61                                (unsigned int)sid->sub_auths[i]);
    5962        }
    6063        return ofs;
     
    8992}
    9093
     94#define AUTHORITY_MASK  (~(0xffffffffffffULL))
     95
    9196/* Convert a character string to a binary SID */
    9297wbcErr wbcStringToSid(const char *str,
     
    95100        const char *p;
    96101        char *q;
    97         uint32_t x;
     102        uint64_t x;
    98103        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    99104
     
    116121
    117122        p = str+2;
    118         x = (uint32_t)strtol(p, &q, 10);
    119         if (x==0 || !q || *q!='-') {
     123        x = (uint64_t)strtoul(p, &q, 10);
     124        if (x==0 || x > UINT8_MAX || !q || *q!='-') {
    120125                wbc_status = WBC_ERR_INVALID_SID;
    121126                BAIL_ON_WBC_ERROR(wbc_status);
     
    123128        sid->sid_rev_num = (uint8_t)x;
    124129
    125         /* Next the Identifier Authority.  This is stored in big-endian
    126            in a 6 byte array. */
    127 
     130        /*
     131         * Next the Identifier Authority.  This is stored big-endian in a
     132         * 6 byte array. If the authority value is >= UINT_MAX, then it should
     133         * be expressed as a hex value, according to MS-DTYP.
     134         */
    128135        p = q+1;
    129         x = (uint32_t)strtol(p, &q, 10);
    130         if (!q || *q!='-') {
     136        x = strtoull(p, &q, 0);
     137        if (!q || *q!='-' || (x & AUTHORITY_MASK)) {
    131138                wbc_status = WBC_ERR_INVALID_SID;
    132139                BAIL_ON_WBC_ERROR(wbc_status);
    133140        }
    134         sid->id_auth[5] = (x & 0x000000ff);
    135         sid->id_auth[4] = (x & 0x0000ff00) >> 8;
    136         sid->id_auth[3] = (x & 0x00ff0000) >> 16;
    137         sid->id_auth[2] = (x & 0xff000000) >> 24;
    138         sid->id_auth[1] = 0;
    139         sid->id_auth[0] = 0;
     141        sid->id_auth[5] = (x & 0x0000000000ffULL);
     142        sid->id_auth[4] = (x & 0x00000000ff00ULL) >> 8;
     143        sid->id_auth[3] = (x & 0x000000ff0000ULL) >> 16;
     144        sid->id_auth[2] = (x & 0x0000ff000000ULL) >> 24;
     145        sid->id_auth[1] = (x & 0x00ff00000000ULL) >> 32;
     146        sid->id_auth[0] = (x & 0xff0000000000ULL) >> 40;
    140147
    141148        /* now read the the subauthorities */
    142 
    143149        p = q +1;
    144150        sid->num_auths = 0;
    145151        while (sid->num_auths < WBC_MAXSUBAUTHS) {
    146                 x=(uint32_t)strtoul(p, &q, 10);
     152                x = strtoull(p, &q, 10);
    147153                if (p == q)
    148154                        break;
    149                 if (q == NULL) {
     155                if (x > UINT32_MAX) {
    150156                        wbc_status = WBC_ERR_INVALID_SID;
    151157                        BAIL_ON_WBC_ERROR(wbc_status);
     
    175181
    176182/* Convert a domain and name to SID */
     183wbcErr wbcCtxLookupName(struct wbcContext *ctx,
     184                        const char *domain,
     185                        const char *name,
     186                        struct wbcDomainSid *sid,
     187                        enum wbcSidType *name_type)
     188{
     189        struct winbindd_request request;
     190        struct winbindd_response response;
     191        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     192
     193        if (!sid || !name_type) {
     194                wbc_status = WBC_ERR_INVALID_PARAM;
     195                BAIL_ON_WBC_ERROR(wbc_status);
     196        }
     197
     198        /* Initialize request */
     199
     200        ZERO_STRUCT(request);
     201        ZERO_STRUCT(response);
     202
     203        /* dst is already null terminated from the memset above */
     204
     205        strncpy(request.data.name.dom_name, domain,
     206                sizeof(request.data.name.dom_name)-1);
     207        strncpy(request.data.name.name, name,
     208                sizeof(request.data.name.name)-1);
     209
     210        wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPNAME,
     211                                        &request,
     212                                        &response);
     213        BAIL_ON_WBC_ERROR(wbc_status);
     214
     215        wbc_status = wbcStringToSid(response.data.sid.sid, sid);
     216        BAIL_ON_WBC_ERROR(wbc_status);
     217
     218        *name_type = (enum wbcSidType)response.data.sid.type;
     219
     220        wbc_status = WBC_ERR_SUCCESS;
     221
     222 done:
     223        return wbc_status;
     224}
     225
    177226wbcErr wbcLookupName(const char *domain,
    178227                     const char *name,
     
    180229                     enum wbcSidType *name_type)
    181230{
    182         struct winbindd_request request;
    183         struct winbindd_response response;
    184         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    185 
    186         if (!sid || !name_type) {
    187                 wbc_status = WBC_ERR_INVALID_PARAM;
    188                 BAIL_ON_WBC_ERROR(wbc_status);
    189         }
    190 
    191         /* Initialize request */
    192 
    193         ZERO_STRUCT(request);
    194         ZERO_STRUCT(response);
    195 
    196         /* dst is already null terminated from the memset above */
    197 
    198         strncpy(request.data.name.dom_name, domain,
    199                 sizeof(request.data.name.dom_name)-1);
    200         strncpy(request.data.name.name, name,
    201                 sizeof(request.data.name.name)-1);
    202 
    203         wbc_status = wbcRequestResponse(WINBINDD_LOOKUPNAME,
    204                                         &request,
    205                                         &response);
    206         BAIL_ON_WBC_ERROR(wbc_status);
    207 
    208         wbc_status = wbcStringToSid(response.data.sid.sid, sid);
    209         BAIL_ON_WBC_ERROR(wbc_status);
    210 
    211         *name_type = (enum wbcSidType)response.data.sid.type;
    212 
    213         wbc_status = WBC_ERR_SUCCESS;
    214 
    215  done:
    216         return wbc_status;
     231        return wbcCtxLookupName(NULL, domain, name, sid, name_type);
    217232}
    218233
    219234
    220235/* Convert a SID to a domain and name */
    221 wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
    222                     char **pdomain,
    223                     char **pname,
    224                     enum wbcSidType *pname_type)
     236wbcErr wbcCtxLookupSid(struct wbcContext *ctx,
     237                       const struct wbcDomainSid *sid,
     238                       char **pdomain,
     239                       char **pname,
     240                       enum wbcSidType *pname_type)
    225241{
    226242        struct winbindd_request request;
     
    242258        /* Make request */
    243259
    244         wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, &request,
     260        wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPSID,
     261                                        &request,
    245262                                        &response);
    246263        if (!WBC_ERROR_IS_OK(wbc_status)) {
     
    280297}
    281298
     299wbcErr wbcLookupSid(const struct wbcDomainSid *sid,
     300                    char **pdomain,
     301                    char **pname,
     302                    enum wbcSidType *pname_type)
     303{
     304        return wbcCtxLookupSid(NULL, sid, pdomain, pname, pname_type);
     305}
     306
    282307static void wbcDomainInfosDestructor(void *ptr)
    283308{
     
    296321
    297322        while (n->name != NULL) {
    298                 free(n->name);
     323                wbcFreeMemory(n->name);
    299324                n += 1;
    300325        }
    301326}
    302327
    303 wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
    304                      struct wbcDomainInfo **pdomains, int *pnum_domains,
    305                      struct wbcTranslatedName **pnames)
     328wbcErr wbcCtxLookupSids(struct wbcContext *ctx,
     329                        const struct wbcDomainSid *sids, int num_sids,
     330                        struct wbcDomainInfo **pdomains, int *pnum_domains,
     331                        struct wbcTranslatedName **pnames)
    306332{
    307333        struct winbindd_request request;
     
    345371        request.extra_len = p - sidlist;
    346372
    347         wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSIDS,
     373        wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPSIDS,
    348374                                        &request, &response);
    349375        free(sidlist);
     
    470496}
    471497
     498wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
     499                     struct wbcDomainInfo **pdomains, int *pnum_domains,
     500                     struct wbcTranslatedName **pnames)
     501{
     502        return wbcCtxLookupSids(NULL, sids, num_sids, pdomains,
     503                                pnum_domains, pnames);
     504}
     505
    472506/* Translate a collection of RIDs within a domain to names */
    473507
    474 wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
     508wbcErr wbcCtxLookupRids(struct wbcContext *ctx, struct wbcDomainSid *dom_sid,
    475509                     int num_rids,
    476510                     uint32_t *rids,
     
    522556        request.extra_len = len;
    523557
    524         wbc_status = wbcRequestResponse(WINBINDD_LOOKUPRIDS,
     558        wbc_status = wbcRequestResponse(ctx, WINBINDD_LOOKUPRIDS,
    525559                                        &request,
    526560                                        &response);
     
    594628}
    595629
     630wbcErr wbcLookupRids(struct wbcDomainSid *dom_sid,
     631                     int num_rids,
     632                     uint32_t *rids,
     633                     const char **pp_domain_name,
     634                     const char ***pnames,
     635                     enum wbcSidType **ptypes)
     636{
     637        return wbcCtxLookupRids(NULL, dom_sid, num_rids, rids,
     638                                pp_domain_name, pnames, ptypes);
     639}
     640
    596641/* Get the groups a user belongs to */
    597 wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
    598                          bool domain_groups_only,
    599                          uint32_t *num_sids,
    600                          struct wbcDomainSid **_sids)
     642wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
     643                            const struct wbcDomainSid *user_sid,
     644                            bool domain_groups_only,
     645                            uint32_t *num_sids,
     646                            struct wbcDomainSid **_sids)
    601647{
    602648        uint32_t i;
     
    626672        }
    627673
    628         wbc_status = wbcRequestResponse(cmd,
     674        wbc_status = wbcRequestResponse(ctx, cmd,
    629675                                        &request,
    630676                                        &response);
     
    667713}
    668714
     715wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
     716                         bool domain_groups_only,
     717                         uint32_t *num_sids,
     718                         struct wbcDomainSid **_sids)
     719{
     720        return wbcCtxLookupUserSids(NULL, user_sid, domain_groups_only,
     721                                    num_sids, _sids);
     722}
     723
    669724static inline
    670725wbcErr _sid_to_rid(struct wbcDomainSid *sid, uint32_t *rid)
     
    679734
    680735/* Get alias membership for sids */
    681 wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
    682                         struct wbcDomainSid *sids,
    683                         uint32_t num_sids,
    684                         uint32_t **alias_rids,
    685                         uint32_t *num_alias_rids)
     736wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
     737                           const struct wbcDomainSid *dom_sid,
     738                           struct wbcDomainSid *sids,
     739                           uint32_t num_sids,
     740                           uint32_t **alias_rids,
     741                           uint32_t *num_alias_rids)
    686742{
    687743        uint32_t i;
     
    744800        request.extra_len = extra_data_len;
    745801
    746         wbc_status = wbcRequestResponse(WINBINDD_GETSIDALIASES,
     802        wbc_status = wbcRequestResponse(ctx, WINBINDD_GETSIDALIASES,
    747803                                        &request,
    748804                                        &response);
     
    784840}
    785841
     842wbcErr wbcGetSidAliases(const struct wbcDomainSid *dom_sid,
     843                        struct wbcDomainSid *sids,
     844                        uint32_t num_sids,
     845                        uint32_t **alias_rids,
     846                        uint32_t *num_alias_rids)
     847{
     848        return wbcCtxGetSidAliases(NULL, dom_sid, sids, num_sids,
     849                                   alias_rids, num_alias_rids);
     850}
     851
    786852
    787853/* Lists Users */
    788 wbcErr wbcListUsers(const char *domain_name,
    789                     uint32_t *_num_users,
    790                     const char ***_users)
     854wbcErr wbcCtxListUsers(struct wbcContext *ctx,
     855                       const char *domain_name,
     856                       uint32_t *_num_users,
     857                       const char ***_users)
    791858{
    792859        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    807874        }
    808875
    809         wbc_status = wbcRequestResponse(WINBINDD_LIST_USERS,
     876        wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_USERS,
    810877                                        &request,
    811878                                        &response);
     
    859926}
    860927
     928wbcErr wbcListUsers(const char *domain_name,
     929                    uint32_t *_num_users,
     930                    const char ***_users)
     931{
     932        return wbcCtxListUsers(NULL, domain_name, _num_users, _users);
     933}
     934
    861935/* Lists Groups */
    862 wbcErr wbcListGroups(const char *domain_name,
    863                      uint32_t *_num_groups,
    864                      const char ***_groups)
     936wbcErr wbcCtxListGroups(struct wbcContext *ctx,
     937                        const char *domain_name,
     938                        uint32_t *_num_groups,
     939                        const char ***_groups)
    865940{
    866941        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    881956        }
    882957
    883         wbc_status = wbcRequestResponse(WINBINDD_LIST_GROUPS,
     958        wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_GROUPS,
    884959                                        &request,
    885960                                        &response);
     
    9331008}
    9341009
    935 wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
    936                          char **pdomain,
    937                          char **pfullname,
    938                          enum wbcSidType *pname_type)
     1010wbcErr wbcListGroups(const char *domain_name,
     1011                     uint32_t *_num_groups,
     1012                     const char ***_groups)
     1013{
     1014        return wbcCtxListGroups(NULL, domain_name, _num_groups, _groups);
     1015}
     1016
     1017wbcErr wbcCtxGetDisplayName(struct wbcContext *ctx,
     1018                            const struct wbcDomainSid *sid,
     1019                            char **pdomain,
     1020                            char **pfullname,
     1021                            enum wbcSidType *pname_type)
    9391022{
    9401023        wbcErr wbc_status;
     
    9431026        enum wbcSidType name_type;
    9441027
    945         wbc_status = wbcLookupSid(sid, &domain, &name, &name_type);
     1028        wbc_status = wbcCtxLookupSid(ctx, sid, &domain, &name, &name_type);
    9461029        BAIL_ON_WBC_ERROR(wbc_status);
    9471030
     
    9501033                struct passwd *pwd;
    9511034
    952                 wbc_status = wbcSidToUid(sid, &uid);
    953                 BAIL_ON_WBC_ERROR(wbc_status);
    954 
    955                 wbc_status = wbcGetpwuid(uid, &pwd);
     1035                wbc_status = wbcCtxSidToUid(ctx, sid, &uid);
     1036                BAIL_ON_WBC_ERROR(wbc_status);
     1037
     1038                wbc_status = wbcCtxGetpwuid(ctx, uid, &pwd);
    9561039                BAIL_ON_WBC_ERROR(wbc_status);
    9571040
     
    9761059
    9771060        return wbc_status;
     1061}
     1062
     1063wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
     1064                         char **pdomain,
     1065                         char **pfullname,
     1066                         enum wbcSidType *pname_type)
     1067{
     1068        return wbcCtxGetDisplayName(NULL, sid, pdomain, pfullname, pname_type);
    9781069}
    9791070
  • vendor/current/nsswitch/libwbclient/wbc_util.c

    r740 r988  
    2929/** @brief Ping winbindd to see if the daemon is running
    3030 *
     31 * @param *ctx       wbclient Context
     32 *
    3133 * @return #wbcErr
    3234 **/
    33 wbcErr wbcPing(void)
     35wbcErr wbcCtxPing(struct wbcContext *ctx)
    3436{
    3537        struct winbindd_request request;
     
    4143        ZERO_STRUCT(response);
    4244
    43         return wbcRequestResponse(WINBINDD_PING, &request, &response);
     45        return wbcRequestResponse(ctx, WINBINDD_PING, &request, &response);
     46}
     47
     48wbcErr wbcPing(void)
     49{
     50        return wbcCtxPing(NULL);
    4451}
    4552
     
    6168 */
    6269
    63 wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
     70wbcErr wbcCtxInterfaceDetails(struct wbcContext *ctx,
     71                              struct wbcInterfaceDetails **_details)
    6472{
    6573        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    8088
    8189        /* first the interface version */
    82         wbc_status = wbcRequestResponse(WINBINDD_INTERFACE_VERSION, NULL, &response);
     90        wbc_status = wbcRequestResponse(ctx, WINBINDD_INTERFACE_VERSION,
     91                                        NULL, &response);
    8392        BAIL_ON_WBC_ERROR(wbc_status);
    8493        info->interface_version = response.data.interface_version;
    8594
    8695        /* then the samba version and the winbind separator */
    87         wbc_status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
     96        wbc_status = wbcRequestResponse(ctx, WINBINDD_INFO, NULL, &response);
    8897        BAIL_ON_WBC_ERROR(wbc_status);
    8998
     
    93102
    94103        /* then the local netbios name */
    95         wbc_status = wbcRequestResponse(WINBINDD_NETBIOS_NAME, NULL, &response);
     104        wbc_status = wbcRequestResponse(ctx, WINBINDD_NETBIOS_NAME,
     105                                        NULL, &response);
    96106        BAIL_ON_WBC_ERROR(wbc_status);
    97107
     
    100110
    101111        /* then the local workgroup name */
    102         wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_NAME, NULL, &response);
     112        wbc_status = wbcRequestResponse(ctx, WINBINDD_DOMAIN_NAME,
     113                                        NULL, &response);
    103114        BAIL_ON_WBC_ERROR(wbc_status);
    104115
     
    106117        BAIL_ON_PTR_ERROR(info->netbios_domain, wbc_status);
    107118
    108         wbc_status = wbcDomainInfo(info->netbios_domain, &domain);
     119        wbc_status = wbcCtxDomainInfo(ctx, info->netbios_domain, &domain);
    109120        if (wbc_status == WBC_ERR_DOMAIN_NOT_FOUND) {
    110121                /* maybe it's a standalone server */
     
    131142        wbcFreeMemory(info);
    132143        return wbc_status;
     144}
     145
     146wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **_details)
     147{
     148        return wbcCtxInterfaceDetails(NULL, _details);
    133149}
    134150
     
    148164 */
    149165
    150 wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
     166wbcErr wbcCtxDomainInfo(struct wbcContext *ctx,
     167                        const char *domain,
     168                        struct wbcDomainInfo **dinfo)
    151169{
    152170        struct winbindd_request request;
     
    168186                sizeof(request.domain_name)-1);
    169187
    170         wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_INFO,
     188        wbc_status = wbcRequestResponse(ctx, WINBINDD_DOMAIN_INFO,
    171189                                        &request,
    172190                                        &response);
     
    204222}
    205223
     224wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo)
     225{
     226        return wbcCtxDomainInfo(NULL, domain, dinfo);
     227}
     228
    206229/* Get the list of current DCs */
    207 wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
    208                  const char ***dc_names, const char ***dc_ips)
     230wbcErr wbcCtxDcInfo(struct wbcContext *ctx,
     231                    const char *domain, size_t *num_dcs,
     232                    const char ***dc_names, const char ***dc_ips)
    209233{
    210234        struct winbindd_request request;
     
    227251        }
    228252
    229         wbc_status = wbcRequestResponse(WINBINDD_DC_INFO,
     253        wbc_status = wbcRequestResponse(ctx, WINBINDD_DC_INFO,
    230254                                        &request, &response);
    231255        BAIL_ON_WBC_ERROR(wbc_status);
     
    291315}
    292316
     317wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
     318                 const char ***dc_names, const char ***dc_ips)
     319{
     320        return wbcCtxDcInfo(NULL, domain, num_dcs, dc_names, dc_ips);
     321}
     322
    293323/* Resolve a NetbiosName via WINS */
    294 wbcErr wbcResolveWinsByName(const char *name, char **ip)
     324wbcErr wbcCtxResolveWinsByName(struct wbcContext *ctx,
     325                               const char *name, char **ip)
    295326{
    296327        struct winbindd_request request;
     
    307338                sizeof(request.data.winsreq)-1);
    308339
    309         wbc_status = wbcRequestResponse(WINBINDD_WINS_BYNAME,
     340        wbc_status = wbcRequestResponse(ctx, WINBINDD_WINS_BYNAME,
    310341                                        &request,
    311342                                        &response);
     
    324355}
    325356
     357wbcErr wbcResolveWinsByName(const char *name, char **ip)
     358{
     359        return wbcCtxResolveWinsByName(NULL, name, ip);
     360}
     361
    326362/* Resolve an IP address via WINS into a NetbiosName */
    327 wbcErr wbcResolveWinsByIP(const char *ip, char **name)
     363wbcErr wbcCtxResolveWinsByIP(struct wbcContext *ctx,
     364                             const char *ip, char **name)
    328365{
    329366        struct winbindd_request request;
     
    340377                sizeof(request.data.winsreq)-1);
    341378
    342         wbc_status = wbcRequestResponse(WINBINDD_WINS_BYIP,
     379        wbc_status = wbcRequestResponse(ctx, WINBINDD_WINS_BYIP,
    343380                                        &request,
    344381                                        &response);
     
    355392 done:
    356393        return wbc_status;
     394}
     395
     396wbcErr wbcResolveWinsByIP(const char *ip, char **name)
     397{
     398        return wbcCtxResolveWinsByIP(NULL, ip, name);
    357399}
    358400
     
    467509
    468510        /* Online/Offline status */
    469 
    470511        r = s;
    471         if (r == NULL) {
    472                 wbc_status = WBC_ERR_INVALID_RESPONSE;
    473                 BAIL_ON_WBC_ERROR(wbc_status);
    474         }
    475512        if ( strcmp(r, "Offline") == 0) {
    476513                info->domain_flags |= WBC_DOMINFO_DOMAIN_OFFLINE;
     
    495532
    496533/* Enumerate the domain trusts known by Winbind */
    497 wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
     534wbcErr wbcCtxListTrusts(struct wbcContext *ctx,
     535                        struct wbcDomainInfo **domains, size_t *num_domains)
    498536{
    499537        struct winbindd_response response;
     
    511549        /* Send request */
    512550
    513         wbc_status = wbcRequestResponse(WINBINDD_LIST_TRUSTDOM,
     551        wbc_status = wbcRequestResponse(ctx, WINBINDD_LIST_TRUSTDOM,
    514552                                        NULL,
    515553                                        &response);
     
    565603}
    566604
     605wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains)
     606{
     607        return wbcCtxListTrusts(NULL, domains, num_domains);
     608}
     609
    567610static void wbcDomainControllerInfoDestructor(void *ptr)
    568611{
     
    573616
    574617/* Enumerate the domain trusts known by Winbind */
    575 wbcErr wbcLookupDomainController(const char *domain,
    576                                  uint32_t flags,
    577                                 struct wbcDomainControllerInfo **dc_info)
     618wbcErr wbcCtxLookupDomainController(struct wbcContext *ctx,
     619                                    const char *domain, uint32_t flags,
     620                                    struct wbcDomainControllerInfo **dc_info)
    578621{
    579622        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     
    604647        /* Send request */
    605648
    606         wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME,
     649        wbc_status = wbcRequestResponse(ctx, WINBINDD_DSGETDCNAME,
    607650                                        &request,
    608651                                        &response);
     
    620663}
    621664
     665wbcErr wbcLookupDomainController(const char *domain, uint32_t flags,
     666                                 struct wbcDomainControllerInfo **dc_info)
     667{
     668        return wbcCtxLookupDomainController(NULL, domain, flags, dc_info);
     669}
     670
    622671static void wbcDomainControllerInfoExDestructor(void *ptr)
    623672{
    624673        struct wbcDomainControllerInfoEx *i =
    625674                (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));
     675        free(discard_const_p(char, i->dc_unc));
     676        free(discard_const_p(char, i->dc_address));
     677        free(discard_const_p(char, i->domain_guid));
     678        free(discard_const_p(char, i->domain_name));
     679        free(discard_const_p(char, i->forest_name));
     680        free(discard_const_p(char, i->dc_site_name));
     681        free(discard_const_p(char, i->client_site_name));
    633682}
    634683
     
    694743
    695744/* Get extended domain controller information */
     745wbcErr wbcCtxLookupDomainControllerEx(struct wbcContext *ctx,
     746                                      const char *domain,
     747                                      struct wbcGuid *guid,
     748                                      const char *site,
     749                                      uint32_t flags,
     750                                      struct wbcDomainControllerInfoEx **dc_info)
     751{
     752        wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
     753        struct winbindd_request request;
     754        struct winbindd_response response;
     755
     756        /* validate input params */
     757
     758        if (!domain || !dc_info) {
     759                wbc_status = WBC_ERR_INVALID_PARAM;
     760                BAIL_ON_WBC_ERROR(wbc_status);
     761        }
     762
     763        ZERO_STRUCT(request);
     764        ZERO_STRUCT(response);
     765
     766        request.data.dsgetdcname.flags = flags;
     767
     768        strncpy(request.data.dsgetdcname.domain_name, domain,
     769                sizeof(request.data.dsgetdcname.domain_name)-1);
     770
     771        if (site) {
     772                strncpy(request.data.dsgetdcname.site_name, site,
     773                        sizeof(request.data.dsgetdcname.site_name)-1);
     774        }
     775
     776        if (guid) {
     777                char *str = NULL;
     778
     779                wbc_status = wbcGuidToString(guid, &str);
     780                BAIL_ON_WBC_ERROR(wbc_status);
     781
     782                strncpy(request.data.dsgetdcname.domain_guid, str,
     783                        sizeof(request.data.dsgetdcname.domain_guid)-1);
     784
     785                wbcFreeMemory(str);
     786        }
     787
     788        /* Send request */
     789
     790        wbc_status = wbcRequestResponse(ctx, WINBINDD_DSGETDCNAME,
     791                                        &request,
     792                                        &response);
     793        BAIL_ON_WBC_ERROR(wbc_status);
     794
     795        if (dc_info) {
     796                wbc_status = wbc_create_domain_controller_info_ex(&response,
     797                                                                  dc_info);
     798                BAIL_ON_WBC_ERROR(wbc_status);
     799        }
     800
     801        wbc_status = WBC_ERR_SUCCESS;
     802done:
     803        return wbc_status;
     804}
     805
    696806wbcErr wbcLookupDomainControllerEx(const char *domain,
    697807                                   struct wbcGuid *guid,
     
    700810                                   struct wbcDomainControllerInfoEx **dc_info)
    701811{
    702         wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
    703         struct winbindd_request request;
    704         struct winbindd_response response;
    705 
    706         /* validate input params */
    707 
    708         if (!domain || !dc_info) {
    709                 wbc_status = WBC_ERR_INVALID_PARAM;
    710                 BAIL_ON_WBC_ERROR(wbc_status);
    711         }
    712 
    713         ZERO_STRUCT(request);
    714         ZERO_STRUCT(response);
    715 
    716         request.data.dsgetdcname.flags = flags;
    717 
    718         strncpy(request.data.dsgetdcname.domain_name, domain,
    719                 sizeof(request.data.dsgetdcname.domain_name)-1);
    720 
    721         if (site) {
    722                 strncpy(request.data.dsgetdcname.site_name, site,
    723                         sizeof(request.data.dsgetdcname.site_name)-1);
    724         }
    725 
    726         if (guid) {
    727                 char *str = NULL;
    728 
    729                 wbc_status = wbcGuidToString(guid, &str);
    730                 BAIL_ON_WBC_ERROR(wbc_status);
    731 
    732                 strncpy(request.data.dsgetdcname.domain_guid, str,
    733                         sizeof(request.data.dsgetdcname.domain_guid)-1);
    734 
    735                 wbcFreeMemory(str);
    736         }
    737 
    738         /* Send request */
    739 
    740         wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME,
    741                                         &request,
    742                                         &response);
    743         BAIL_ON_WBC_ERROR(wbc_status);
    744 
    745         if (dc_info) {
    746                 wbc_status = wbc_create_domain_controller_info_ex(&response,
    747                                                                   dc_info);
    748                 BAIL_ON_WBC_ERROR(wbc_status);
    749         }
    750 
    751         wbc_status = WBC_ERR_SUCCESS;
    752 done:
    753         return wbc_status;
     812        return wbcCtxLookupDomainControllerEx(NULL, domain, guid, site,
     813                                              flags, dc_info);
    754814}
    755815
     
    759819
    760820        while (b->name != NULL) {
    761                 free((char *)(b->name));
     821                free(discard_const_p(char, b->name));
    762822                free(b->blob.data);
    763823                b += 1;
  • vendor/current/nsswitch/libwbclient/wbclient.c

    r740 r988  
    55
    66   Copyright (C) Gerald (Jerry) Carter 2007
     7   Copyright (C) Matthew Newton 2015
    78
    89
     
    2829/* From wb_common.c */
    2930
    30 NSS_STATUS winbindd_request_response(int req_type,
     31struct winbindd_context;
     32
     33NSS_STATUS winbindd_request_response(struct winbindd_context *wbctx,
     34                                     int req_type,
    3135                                     struct winbindd_request *request,
    3236                                     struct winbindd_response *response);
    33 NSS_STATUS winbindd_priv_request_response(int req_type,
     37NSS_STATUS winbindd_priv_request_response(struct winbindd_context *wbctx,
     38                                          int req_type,
    3439                                          struct winbindd_request *request,
    3540                                          struct winbindd_response *response);
     41struct winbindd_context *winbindd_ctx_create(void);
     42void winbindd_ctx_free(struct winbindd_context *ctx);
     43
     44/* Global context used for non-Ctx functions */
     45
     46static struct wbcContext wbcGlobalCtx = {
     47        .winbindd_ctx = NULL,
     48        .pw_cache_size = 0,
     49        .pw_cache_idx = 0,
     50        .gr_cache_size = 0,
     51        .gr_cache_idx = 0
     52};
    3653
    3754/*
     
    4966
    5067static wbcErr wbcRequestResponseInt(
     68        struct winbindd_context *wbctx,
    5169        int cmd,
    5270        struct winbindd_request *request,
    5371        struct winbindd_response *response,
    54         NSS_STATUS (*fn)(int req_type,
     72        NSS_STATUS (*fn)(struct winbindd_context *wbctx, int req_type,
    5573                         struct winbindd_request *request,
    5674                         struct winbindd_response *response))
     
    6179        /* for some calls the request and/or response can be NULL */
    6280
    63         nss_status = fn(cmd, request, response);
     81        nss_status = fn(wbctx, cmd, request, response);
    6482
    6583        switch (nss_status) {
     
    84102 * @brief Wrapper around Winbind's send/receive API call
    85103 *
     104 * @param ctx       Context
    86105 * @param cmd       Winbind command operation to perform
    87106 * @param request   Send structure
     
    90109 * @return #wbcErr
    91110 */
    92 wbcErr wbcRequestResponse(int cmd,
     111wbcErr wbcRequestResponse(struct wbcContext *ctx, int cmd,
    93112                          struct winbindd_request *request,
    94113                          struct winbindd_response *response)
    95114{
    96         return wbcRequestResponseInt(cmd, request, response,
     115        struct winbindd_context *wbctx = NULL;
     116
     117        if (ctx) {
     118                wbctx = ctx->winbindd_ctx;
     119        }
     120
     121        return wbcRequestResponseInt(wbctx, cmd, request, response,
    97122                                     winbindd_request_response);
    98123}
    99124
    100 wbcErr wbcRequestResponsePriv(int cmd,
     125wbcErr wbcRequestResponsePriv(struct wbcContext *ctx, int cmd,
    101126                              struct winbindd_request *request,
    102127                              struct winbindd_response *response)
    103128{
    104         return wbcRequestResponseInt(cmd, request, response,
     129        struct winbindd_context *wbctx = NULL;
     130
     131        if (ctx) {
     132                wbctx = ctx->winbindd_ctx;
     133        }
     134
     135        return wbcRequestResponseInt(wbctx, cmd, request, response,
    105136                                     winbindd_priv_request_response);
    106137}
     
    258289        return WBC_ERR_SUCCESS;
    259290}
     291
     292/* Context handling functions */
     293
     294static void wbcContextDestructor(void *ptr)
     295{
     296        struct wbcContext *ctx = (struct wbcContext *)ptr;
     297
     298        winbindd_ctx_free(ctx->winbindd_ctx);
     299}
     300
     301struct wbcContext *wbcCtxCreate(void)
     302{
     303        struct wbcContext *ctx;
     304        struct winbindd_context *wbctx;
     305
     306        ctx = (struct wbcContext *)wbcAllocateMemory(
     307                1, sizeof(struct wbcContext), wbcContextDestructor);
     308
     309        if (!ctx) {
     310                return NULL;
     311        }
     312
     313        wbctx = winbindd_ctx_create();
     314
     315        if (!wbctx) {
     316                wbcFreeMemory(ctx);
     317                return NULL;
     318        }
     319
     320        ctx->winbindd_ctx = wbctx;
     321
     322        return ctx;
     323}
     324
     325void wbcCtxFree(struct wbcContext *ctx)
     326{
     327        wbcFreeMemory(ctx);
     328}
     329
     330struct wbcContext *wbcGetGlobalCtx(void)
     331{
     332        return &wbcGlobalCtx;
     333}
  • vendor/current/nsswitch/libwbclient/wbclient.h

    r740 r988  
    66   Copyright (C) Gerald (Jerry) Carter 2007
    77   Copyright (C) Volker Lendecke 2009
     8   Copyright (C) Matthew Newton 2015
    89
    910   This library is free software; you can redistribute it and/or
     
    6970 *  0.7: Added wbcSidToStringBuf()
    7071 *  0.8: Added wbcSidsToUnixIds() and wbcLookupSids()
     72 *  0.9: Added support for WBC_ID_TYPE_BOTH
     73 *  0.10: Added wbcPingDc2()
     74 *  0.11: Extended wbcAuthenticateUserEx to provide PAC parsing
     75 *  0.12: Added wbcCtxCreate and friends
    7176 **/
    7277#define WBCLIENT_MAJOR_VERSION 0
    73 #define WBCLIENT_MINOR_VERSION 8
     78#define WBCLIENT_MINOR_VERSION 12
    7479#define WBCLIENT_VENDOR_VERSION "Samba libwbclient"
    7580struct wbcLibraryDetails {
     
    9196        char *dns_domain;
    9297};
     98
     99/**
     100 *  @brief Library context data
     101 *
     102 **/
     103
     104struct wbcContext;
    93105
    94106/*
     
    196208
    197209/**
     210 * @brief Generic Blob
     211 **/
     212
     213struct wbcBlob {
     214        uint8_t *data;
     215        size_t length;
     216};
     217
     218/**
     219 * @brief Named Blob
     220 **/
     221
     222struct wbcNamedBlob {
     223        const char *name;
     224        uint32_t flags;
     225        struct wbcBlob blob;
     226};
     227
     228/**
    198229 * @brief Auth User Parameters
    199230 **/
     
    211242                WBC_AUTH_USER_LEVEL_PLAIN = 1,
    212243                WBC_AUTH_USER_LEVEL_HASH = 2,
    213                 WBC_AUTH_USER_LEVEL_RESPONSE = 3
     244                WBC_AUTH_USER_LEVEL_RESPONSE = 3,
     245                WBC_AUTH_USER_LEVEL_PAC = 4
    214246        } level;
    215247        union {
     
    226258                        uint8_t *lm_data;
    227259                } response;
     260                struct wbcBlob pac;
    228261        } password;
    229 };
    230 
    231 /**
    232  * @brief Generic Blob
    233  **/
    234 
    235 struct wbcBlob {
    236         uint8_t *data;
    237         size_t length;
    238 };
    239 
    240 /**
    241  * @brief Named Blob
    242  **/
    243 
    244 struct wbcNamedBlob {
    245         const char *name;
    246         uint32_t flags;
    247         struct wbcBlob blob;
    248262};
    249263
     
    519533
    520534
     535/**********************************************************
     536 * Context Management
     537 **********************************************************/
     538
     539/**
     540 * @brief Create a new wbcContext context
     541 *
     542 * @return wbcContext
     543 **/
     544struct wbcContext *wbcCtxCreate(void);
     545
     546/**
     547 * @brief Free a library context
     548 *
     549 * @param ctx           wbcContext to free
     550 *
     551 * @return void
     552 **/
     553void wbcCtxFree(struct wbcContext *ctx);
     554
     555
     556
    521557/*
    522558 * Utility functions for dealing with SIDs
     
    596632 * @brief Ping winbindd to see if the daemon is running
    597633 *
     634 * @param *ctx        wbclient Context
     635 *
     636 * @return #wbcErr
     637 **/
     638wbcErr wbcCtxPing(struct wbcContext *ctx);
     639
     640/**
     641 * @brief Ping winbindd to see if the daemon is running
     642 *
    598643 * @return #wbcErr
    599644 **/
     
    602647wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details);
    603648
     649wbcErr wbcCtxInterfaceDetails(struct wbcContext *ctx,
     650                              struct wbcInterfaceDetails **details);
    604651wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details);
    605652
     
    611658 * @brief Convert a domain and name to SID
    612659 *
     660 * @param *ctx        wbclient Context
    613661 * @param dom_name    Domain name (possibly "")
    614662 * @param name        User or group name
     
    618666 * @return #wbcErr
    619667 **/
     668wbcErr wbcCtxLookupName(struct wbcContext *ctx,
     669                        const char *dom_name,
     670                        const char *name,
     671                        struct wbcDomainSid *sid,
     672                        enum wbcSidType *name_type);
     673
     674/**
     675 * @brief Convert a domain and name to SID
     676 *
     677 * @param dom_name    Domain name (possibly "")
     678 * @param name        User or group name
     679 * @param *sid        Pointer to the resolved domain SID
     680 * @param *name_type  Pointer to the SID type
     681 *
     682 * @return #wbcErr
     683 **/
    620684wbcErr wbcLookupName(const char *dom_name,
    621685                     const char *name,
     
    626690 * @brief Convert a SID to a domain and name
    627691 *
    628  * @param *sid        Pointer to the domain SID to be resolved
     692 * @param *ctx       wbclient Context
     693 * @param *sid       Pointer to the domain SID to be resolved
     694 * @param domain     Resolved Domain name (possibly "")
     695 * @param name       Resolved User or group name
     696 * @param *name_type Pointer to the resolved SID type
     697 *
     698 * @return #wbcErr
     699 **/
     700wbcErr wbcCtxLookupSid(struct wbcContext *ctx,
     701                       const struct wbcDomainSid *sid,
     702                       char **domain,
     703                       char **name,
     704                       enum wbcSidType *name_type);
     705
     706/**
     707 * @brief Convert a SID to a domain and name
     708 *
     709 * @param *sid       Pointer to the domain SID to be resolved
    629710 * @param domain     Resolved Domain name (possibly "")
    630711 * @param name       Resolved User or group name
     
    644725};
    645726
     727wbcErr wbcCtxLookupSids(struct wbcContext *ctx,
     728                        const struct wbcDomainSid *sids, int num_sids,
     729                        struct wbcDomainInfo **domains, int *num_domains,
     730                        struct wbcTranslatedName **names);
     731
    646732wbcErr wbcLookupSids(const struct wbcDomainSid *sids, int num_sids,
    647733                     struct wbcDomainInfo **domains, int *num_domains,
    648734                     struct wbcTranslatedName **names);
     735
     736/**
     737 * @brief Translate a collection of RIDs within a domain to names
     738 */
     739wbcErr wbcCtxLookupRids(struct wbcContext *ctx,
     740                        struct wbcDomainSid *dom_sid,
     741                        int num_rids,
     742                        uint32_t *rids,
     743                        const char **domain_name,
     744                        const char ***names,
     745                        enum wbcSidType **types);
    649746
    650747/**
     
    661758 * @brief Get the groups a user belongs to
    662759 **/
     760wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
     761                            const struct wbcDomainSid *user_sid,
     762                            bool domain_groups_only,
     763                            uint32_t *num_sids,
     764                            struct wbcDomainSid **sids);
     765
     766/*
     767 * @brief Get the groups a user belongs to
     768 **/
    663769wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
    664770                         bool domain_groups_only,
    665771                         uint32_t *num_sids,
    666772                         struct wbcDomainSid **sids);
     773
     774/*
     775 * @brief Get alias membership for sids
     776 **/
     777wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
     778                           const struct wbcDomainSid *dom_sid,
     779                           struct wbcDomainSid *sids,
     780                           uint32_t num_sids,
     781                           uint32_t **alias_rids,
     782                           uint32_t *num_alias_rids);
    667783
    668784/*
     
    678794 * @brief Lists Users
    679795 **/
     796wbcErr wbcCtxListUsers(struct wbcContext *ctx,
     797                       const char *domain_name,
     798                       uint32_t *num_users,
     799                       const char ***users);
     800
     801/**
     802 * @brief Lists Users
     803 **/
    680804wbcErr wbcListUsers(const char *domain_name,
    681805                    uint32_t *num_users,
     
    685809 * @brief Lists Groups
    686810 **/
     811wbcErr wbcCtxListGroups(struct wbcContext *ctx,
     812                        const char *domain_name,
     813                        uint32_t *num_groups,
     814                        const char ***groups);
     815
     816/**
     817 * @brief Lists Groups
     818 **/
    687819wbcErr wbcListGroups(const char *domain_name,
    688820                     uint32_t *num_groups,
    689821                     const char ***groups);
     822
     823wbcErr wbcCtxGetDisplayName(struct wbcContext *ctx,
     824                            const struct wbcDomainSid *sid,
     825                            char **pdomain,
     826                            char **pfullname,
     827                            enum wbcSidType *pname_type);
    690828
    691829wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid,
     
    701839 * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
    702840 *
     841 * @param *ctx        wbclient Context
    703842 * @param *sid        Pointer to the domain SID to be resolved
    704843 * @param *puid       Pointer to the resolved uid_t value
     
    707846 *
    708847 **/
     848wbcErr wbcCtxSidToUid(struct wbcContext *ctx,
     849                      const struct wbcDomainSid *sid,
     850                      uid_t *puid);
     851
     852/**
     853 * @brief Convert a Windows SID to a Unix uid, allocating an uid if needed
     854 *
     855 * @param *sid        Pointer to the domain SID to be resolved
     856 * @param *puid       Pointer to the resolved uid_t value
     857 *
     858 * @return #wbcErr
     859 *
     860 **/
    709861wbcErr wbcSidToUid(const struct wbcDomainSid *sid,
    710862                   uid_t *puid);
     
    725877 * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
    726878 *
     879 * @param *ctx        wbclient Context
    727880 * @param uid         Unix uid to be resolved
    728881 * @param *sid        Pointer to the resolved domain SID
     
    731884 *
    732885 **/
     886wbcErr wbcCtxUidToSid(struct wbcContext *ctx, uid_t uid,
     887                      struct wbcDomainSid *sid);
     888
     889/**
     890 * @brief Convert a Unix uid to a Windows SID, allocating a SID if needed
     891 *
     892 * @param uid         Unix uid to be resolved
     893 * @param *sid        Pointer to the resolved domain SID
     894 *
     895 * @return #wbcErr
     896 *
     897 **/
    733898wbcErr wbcUidToSid(uid_t uid,
    734899                   struct wbcDomainSid *sid);
     
    749914 * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
    750915 *
     916 * @param *ctx        wbclient Context
    751917 * @param *sid        Pointer to the domain SID to be resolved
    752918 * @param *pgid       Pointer to the resolved gid_t value
     
    755921 *
    756922 **/
     923wbcErr wbcCtxSidToGid(struct wbcContext *ctx,
     924                      const struct wbcDomainSid *sid,
     925                      gid_t *pgid);
     926
     927/**
     928 * @brief Convert a Windows SID to a Unix gid, allocating a gid if needed
     929 *
     930 * @param *sid        Pointer to the domain SID to be resolved
     931 * @param *pgid       Pointer to the resolved gid_t value
     932 *
     933 * @return #wbcErr
     934 *
     935 **/
    757936wbcErr wbcSidToGid(const struct wbcDomainSid *sid,
    758937                   gid_t *pgid);
     
    769948wbcErr wbcQuerySidToGid(const struct wbcDomainSid *sid,
    770949                        gid_t *pgid);
     950
     951/**
     952 * @brief Convert a Unix gid to a Windows SID, allocating a SID if needed
     953 *
     954 * @param *ctx        wbclient Context
     955 * @param gid         Unix gid to be resolved
     956 * @param *sid        Pointer to the resolved domain SID
     957 *
     958 * @return #wbcErr
     959 *
     960 **/
     961wbcErr wbcCtxGidToSid(struct wbcContext *ctx, gid_t gid,
     962                   struct wbcDomainSid *sid);
    771963
    772964/**
     
    797989        WBC_ID_TYPE_NOT_SPECIFIED,
    798990        WBC_ID_TYPE_UID,
    799         WBC_ID_TYPE_GID
     991        WBC_ID_TYPE_GID,
     992        WBC_ID_TYPE_BOTH
    800993};
    801994
     
    8131006 * @brief Convert a list of sids to unix ids
    8141007 *
     1008 * @param *ctx        wbclient Context
    8151009 * @param sids        Pointer to an array of SIDs to convert
    8161010 * @param num_sids    Number of SIDs
     
    8201014 *
    8211015 **/
     1016wbcErr wbcCtxSidsToUnixIds(struct wbcContext *ctx,
     1017                           const struct wbcDomainSid *sids, uint32_t num_sids,
     1018                           struct wbcUnixId *ids);
     1019
     1020/**
     1021 * @brief Convert a list of sids to unix ids
     1022 *
     1023 * @param sids        Pointer to an array of SIDs to convert
     1024 * @param num_sids    Number of SIDs
     1025 * @param ids         Preallocated output array for translated IDs
     1026 *
     1027 * @return #wbcErr
     1028 *
     1029 **/
    8221030wbcErr wbcSidsToUnixIds(const struct wbcDomainSid *sids, uint32_t num_sids,
    8231031                        struct wbcUnixId *ids);
     
    8261034 * @brief Obtain a new uid from Winbind
    8271035 *
    828  * @param *puid      *pointer to the allocated uid
     1036 * @param *ctx        wbclient Context
     1037 * @param *puid       Pointer to the allocated uid
     1038 *
     1039 * @return #wbcErr
     1040 **/
     1041wbcErr wbcCtxAllocateUid(struct wbcContext *ctx, uid_t *puid);
     1042
     1043/**
     1044 * @brief Obtain a new uid from Winbind
     1045 *
     1046 * @param *puid       Pointer to the allocated uid
    8291047 *
    8301048 * @return #wbcErr
     
    8351053 * @brief Obtain a new gid from Winbind
    8361054 *
    837  * @param *pgid      Pointer to the allocated gid
     1055 * @param *ctx        wbclient Context
     1056 * @param *pgid       Pointer to the allocated gid
     1057 *
     1058 * @return #wbcErr
     1059 **/
     1060wbcErr wbcCtxAllocateGid(struct wbcContext *ctx, gid_t *pgid);
     1061
     1062/**
     1063 * @brief Obtain a new gid from Winbind
     1064 *
     1065 * @param *pgid       Pointer to the allocated gid
    8381066 *
    8391067 * @return #wbcErr
     
    8451073 *
    8461074 * @param uid       Uid of the desired mapping.
    847  * @param *sid      Pointer to the sid of the diresired mapping.
     1075 * @param *sid      Pointer to the sid of the desired mapping.
    8481076 *
    8491077 * @return #wbcErr
     
    8581086 *
    8591087 * @param gid       Gid of the desired mapping.
    860  * @param *sid      Pointer to the sid of the diresired mapping.
     1088 * @param *sid      Pointer to the sid of the desired mapping.
    8611089 *
    8621090 * @return #wbcErr
     
    9251153 *   on username
    9261154 *
     1155 * @param *ctx      wbclient Context
    9271156 * @param *name     Username to lookup
    9281157 * @param **pwd     Pointer to resulting struct passwd* from the query.
     
    9301159 * @return #wbcErr
    9311160 **/
     1161wbcErr wbcCtxGetpwnam(struct wbcContext *ctx,
     1162                      const char *name, struct passwd **pwd);
     1163
     1164/**
     1165 * @brief Fill in a struct passwd* for a domain user based
     1166 *   on username
     1167 *
     1168 * @param *name     Username to lookup
     1169 * @param **pwd     Pointer to resulting struct passwd* from the query.
     1170 *
     1171 * @return #wbcErr
     1172 **/
    9321173wbcErr wbcGetpwnam(const char *name, struct passwd **pwd);
    9331174
     
    9361177 *   on uid
    9371178 *
     1179 * @param *ctx      wbclient Context
    9381180 * @param uid       Uid to lookup
    9391181 * @param **pwd     Pointer to resulting struct passwd* from the query.
     
    9411183 * @return #wbcErr
    9421184 **/
     1185wbcErr wbcCtxGetpwuid(struct wbcContext *ctx,
     1186                      uid_t uid, struct passwd **pwd);
     1187
     1188/**
     1189 * @brief Fill in a struct passwd* for a domain user based
     1190 *   on uid
     1191 *
     1192 * @param uid       Uid to lookup
     1193 * @param **pwd     Pointer to resulting struct passwd* from the query.
     1194 *
     1195 * @return #wbcErr
     1196 **/
    9431197wbcErr wbcGetpwuid(uid_t uid, struct passwd **pwd);
    9441198
     
    9471201 *   on sid
    9481202 *
     1203 * @param *ctx         wbclient Context
    9491204 * @param sid       Sid to lookup
    9501205 * @param **pwd     Pointer to resulting struct passwd* from the query.
     
    9521207 * @return #wbcErr
    9531208 **/
     1209wbcErr wbcCtxGetpwsid(struct wbcContext *ctx,
     1210                      struct wbcDomainSid * sid, struct passwd **pwd);
     1211
     1212/**
     1213 * @brief Fill in a struct passwd* for a domain user based
     1214 *   on sid
     1215 *
     1216 * @param sid       Sid to lookup
     1217 * @param **pwd     Pointer to resulting struct passwd* from the query.
     1218 *
     1219 * @return #wbcErr
     1220 **/
    9541221wbcErr wbcGetpwsid(struct wbcDomainSid * sid, struct passwd **pwd);
    9551222
     
    9581225 *   on username
    9591226 *
     1227 * @param *ctx      wbclient Context
    9601228 * @param *name     Username to lookup
    9611229 * @param **grp     Pointer to resulting struct group* from the query.
     
    9631231 * @return #wbcErr
    9641232 **/
     1233wbcErr wbcCtxGetgrnam(struct wbcContext *ctx,
     1234                      const char *name, struct group **grp);
     1235
     1236/**
     1237 * @brief Fill in a struct passwd* for a domain user based
     1238 *   on username
     1239 *
     1240 * @param *name     Username to lookup
     1241 * @param **grp     Pointer to resulting struct group* from the query.
     1242 *
     1243 * @return #wbcErr
     1244 **/
    9651245wbcErr wbcGetgrnam(const char *name, struct group **grp);
    9661246
     
    9691249 *   on uid
    9701250 *
     1251 * @param *ctx      wbclient Context
    9711252 * @param gid       Uid to lookup
    9721253 * @param **grp     Pointer to resulting struct group* from the query.
     
    9741255 * @return #wbcErr
    9751256 **/
     1257wbcErr wbcCtxGetgrgid(struct wbcContext *ctx,
     1258                      gid_t gid, struct group **grp);
     1259
     1260/**
     1261 * @brief Fill in a struct passwd* for a domain user based
     1262 *   on uid
     1263 *
     1264 * @param gid       Uid to lookup
     1265 * @param **grp     Pointer to resulting struct group* from the query.
     1266 *
     1267 * @return #wbcErr
     1268 **/
    9761269wbcErr wbcGetgrgid(gid_t gid, struct group **grp);
    9771270
     
    9791272 * @brief Reset the passwd iterator
    9801273 *
     1274 * @param *ctx      wbclient Context
     1275 *
     1276 * @return #wbcErr
     1277 **/
     1278wbcErr wbcCtxSetpwent(struct wbcContext *ctx);
     1279
     1280/**
     1281 * @brief Reset the passwd iterator
     1282 *
    9811283 * @return #wbcErr
    9821284 **/
     
    9861288 * @brief Close the passwd iterator
    9871289 *
     1290 * @param *ctx      wbclient Context
     1291 *
     1292 * @return #wbcErr
     1293 **/
     1294wbcErr wbcCtxEndpwent(struct wbcContext *ctx);
     1295
     1296/**
     1297 * @brief Close the passwd iterator
     1298 *
    9881299 * @return #wbcErr
    9891300 **/
     
    9931304 * @brief Return the next struct passwd* entry from the pwent iterator
    9941305 *
    995  * @param **pwd       Pointer to resulting struct passwd* from the query.
     1306 * @param *ctx      wbclient Context
     1307 * @param **pwd     Pointer to resulting struct passwd* from the query.
     1308 *
     1309 * @return #wbcErr
     1310 **/
     1311wbcErr wbcCtxGetpwent(struct wbcContext *ctx, struct passwd **pwd);
     1312
     1313/**
     1314 * @brief Return the next struct passwd* entry from the pwent iterator
     1315 *
     1316 * @param **pwd     Pointer to resulting struct passwd* from the query.
    9961317 *
    9971318 * @return #wbcErr
     
    10021323 * @brief Reset the group iterator
    10031324 *
     1325 * @param *ctx      wbclient Context
     1326 *
     1327 * @return #wbcErr
     1328 **/
     1329wbcErr wbcCtxSetgrent(struct wbcContext *ctx);
     1330
     1331/**
     1332 * @brief Reset the group iterator
     1333 *
    10041334 * @return #wbcErr
    10051335 **/
     
    10091339 * @brief Close the group iterator
    10101340 *
     1341 * @param *ctx      wbclient Context
     1342 *
     1343 * @return #wbcErr
     1344 **/
     1345wbcErr wbcCtxEndgrent(struct wbcContext *ctx);
     1346
     1347/**
     1348 * @brief Close the group iterator
     1349 *
    10111350 * @return #wbcErr
    10121351 **/
     
    10161355 * @brief Return the next struct group* entry from the pwent iterator
    10171356 *
    1018  * @param **grp       Pointer to resulting struct group* from the query.
     1357 * @param *ctx      wbclient Context
     1358 * @param **grp     Pointer to resulting struct group* from the query.
     1359 *
     1360 * @return #wbcErr
     1361 **/
     1362wbcErr wbcCtxGetgrent(struct wbcContext *ctx, struct group **grp);
     1363
     1364/**
     1365 * @brief Return the next struct group* entry from the pwent iterator
     1366 *
     1367 * @param **grp     Pointer to resulting struct group* from the query.
    10191368 *
    10201369 * @return #wbcErr
     
    10271376 * This is similar to #wbcGetgrent, just that the member list is empty
    10281377 *
    1029  * @param **grp       Pointer to resulting struct group* from the query.
     1378 * @param *ctx      wbclient Context
     1379 * @param **grp     Pointer to resulting struct group* from the query.
     1380 *
     1381 * @return #wbcErr
     1382 **/
     1383wbcErr wbcCtxGetgrlist(struct wbcContext *ctx, struct group **grp);
     1384
     1385/**
     1386 * @brief Return the next struct group* entry from the pwent iterator
     1387 *
     1388 * This is similar to #wbcGetgrent, just that the member list is empty
     1389 *
     1390 * @param **grp     Pointer to resulting struct group* from the query.
    10301391 *
    10311392 * @return #wbcErr
     
    10361397 * @brief Return the unix group array belonging to the given user
    10371398 *
     1399 * @param *ctx           wbclient Context
    10381400 * @param *account       The given user name
    10391401 * @param *num_groups    Number of elements returned in the groups array
     
    10421404 * @return #wbcErr
    10431405 **/
     1406wbcErr wbcCtxGetGroups(struct wbcContext *ctx,
     1407                       const char *account,
     1408                       uint32_t *num_groups,
     1409                       gid_t **_groups);
     1410
     1411/**
     1412 * @brief Return the unix group array belonging to the given user
     1413 *
     1414 * @param *account       The given user name
     1415 * @param *num_groups    Number of elements returned in the groups array
     1416 * @param **_groups      Pointer to resulting gid_t array.
     1417 *
     1418 * @return #wbcErr
     1419 **/
    10441420wbcErr wbcGetGroups(const char *account,
    10451421                    uint32_t *num_groups,
     
    10541430 * @brief Lookup the current status of a trusted domain
    10551431 *
    1056  * @param domain        The domain to query
     1432 * @param *ctx           wbclient Context
     1433 * @param domain         The domain to query
     1434 *
     1435 * @param dinfo          A pointer to store the returned domain_info struct.
     1436 *
     1437 * @return #wbcErr
     1438 **/
     1439wbcErr wbcCtxDomainInfo(struct wbcContext *ctx,
     1440                        const char *domain,
     1441                        struct wbcDomainInfo **dinfo);
     1442
     1443/**
     1444 * @brief Lookup the current status of a trusted domain
     1445 *
     1446 * @param domain         The domain to query
    10571447 *
    10581448 * @param dinfo          A pointer to store the returned domain_info struct.
     
    10661456 * @brief Lookup the currently contacted DCs
    10671457 *
     1458 * @param *ctx          wbclient Context
    10681459 * @param domain        The domain to query
    10691460 *
     
    10741465 * @return #wbcErr
    10751466 **/
     1467wbcErr wbcCtxDcInfo(struct wbcContext *ctx,
     1468                    const char *domain, size_t *num_dcs,
     1469                    const char ***dc_names, const char ***dc_ips);
     1470
     1471/**
     1472 * @brief Lookup the currently contacted DCs
     1473 *
     1474 * @param domain        The domain to query
     1475 *
     1476 * @param num_dcs       Number of DCs currently known
     1477 * @param dc_names      Names of the currently known DCs
     1478 * @param dc_ips        IP addresses of the currently known DCs
     1479 *
     1480 * @return #wbcErr
     1481 **/
    10761482wbcErr wbcDcInfo(const char *domain, size_t *num_dcs,
    10771483                 const char ***dc_names, const char ***dc_ips);
     1484
     1485/**
     1486 * @brief Enumerate the domain trusts known by Winbind
     1487 *
     1488 * @param *ctx          wbclient Context
     1489 * @param **domains     Pointer to the allocated domain list array
     1490 * @param *num_domains  Pointer to number of domains returned
     1491 *
     1492 * @return #wbcErr
     1493 **/
     1494wbcErr wbcCtxListTrusts(struct wbcContext *ctx,
     1495                        struct wbcDomainInfo **domains,
     1496                        size_t *num_domains);
    10781497
    10791498/**
     
    11131532 * @brief Enumerate the domain trusts known by Winbind
    11141533 *
     1534 * @param *ctx          wbclient Context
    11151535 * @param domain        Name of the domain to query for a DC
    11161536 * @param flags         Bit flags used to control the domain location query
     
    11191539 * @return #wbcErr
    11201540 **/
     1541wbcErr wbcCtxLookupDomainController(struct wbcContext *ctx,
     1542                                    const char *domain,
     1543                                    uint32_t flags,
     1544                                    struct wbcDomainControllerInfo **dc_info);
     1545
     1546/**
     1547 * @brief Enumerate the domain trusts known by Winbind
     1548 *
     1549 * @param domain        Name of the domain to query for a DC
     1550 * @param flags         Bit flags used to control the domain location query
     1551 * @param *dc_info      Pointer to the returned domain controller information
     1552 *
     1553 * @return #wbcErr
     1554 **/
    11211555wbcErr wbcLookupDomainController(const char *domain,
    11221556                                 uint32_t flags,
     
    11261560 * @brief Get extended domain controller information
    11271561 *
     1562 * @param *ctx          wbclient Context
    11281563 * @param domain        Name of the domain to query for a DC
    11291564 * @param guid          Guid of the domain to query for a DC
     
    11341569 * @return #wbcErr
    11351570 **/
     1571wbcErr wbcCtxLookupDomainControllerEx(struct wbcContext *ctx,
     1572                                      const char *domain,
     1573                                      struct wbcGuid *guid,
     1574                                      const char *site,
     1575                                      uint32_t flags,
     1576                                      struct wbcDomainControllerInfoEx **dc_info);
     1577
     1578/**
     1579 * @brief Get extended domain controller information
     1580 *
     1581 * @param domain        Name of the domain to query for a DC
     1582 * @param guid          Guid of the domain to query for a DC
     1583 * @param site          Site of the domain to query for a DC
     1584 * @param flags         Bit flags used to control the domain location query
     1585 * @param *dc_info      Pointer to the returned extended domain controller information
     1586 *
     1587 * @return #wbcErr
     1588 **/
    11361589wbcErr wbcLookupDomainControllerEx(const char *domain,
    11371590                                   struct wbcGuid *guid,
     
    11471600 * @brief Authenticate a username/password pair
    11481601 *
     1602 * @param *ctx         wbclient Context
    11491603 * @param username     Name of user to authenticate
    11501604 * @param password     Clear text password os user
     
    11521606 * @return #wbcErr
    11531607 **/
     1608wbcErr wbcCtxAuthenticateUser(struct wbcContext *ctx,
     1609                              const char *username,
     1610                              const char *password);
     1611
     1612/**
     1613 * @brief Authenticate a username/password pair
     1614 *
     1615 * @param username     Name of user to authenticate
     1616 * @param password     Clear text password os user
     1617 *
     1618 * @return #wbcErr
     1619 **/
    11541620wbcErr wbcAuthenticateUser(const char *username,
    11551621                           const char *password);
     
    11581624 * @brief Authenticate with more detailed information
    11591625 *
     1626 * @param *ctx         wbclient Context
    11601627 * @param params       Input parameters, WBC_AUTH_USER_LEVEL_HASH
    11611628 *                     is not supported yet
     
    11651632 * @return #wbcErr
    11661633 **/
     1634wbcErr wbcCtxAuthenticateUserEx(struct wbcContext *ctx,
     1635                                const struct wbcAuthUserParams *params,
     1636                                struct wbcAuthUserInfo **info,
     1637                                struct wbcAuthErrorInfo **error);
     1638
     1639/**
     1640 * @brief Authenticate with more detailed information
     1641 *
     1642 * @param params       Input parameters, WBC_AUTH_USER_LEVEL_HASH
     1643 *                     is not supported yet
     1644 * @param info         Output details on WBC_ERR_SUCCESS
     1645 * @param error        Output details on WBC_ERR_AUTH_ERROR
     1646 *
     1647 * @return #wbcErr
     1648 **/
    11671649wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
    11681650                             struct wbcAuthUserInfo **info,
     
    11721654 * @brief Logon a User
    11731655 *
     1656 * @param[in]  *ctx        wbclient Context
    11741657 * @param[in]  params      Pointer to a wbcLogonUserParams structure
    11751658 * @param[out] info        Pointer to a pointer to a wbcLogonUserInfo structure
     
    11791662 * @return #wbcErr
    11801663 **/
     1664wbcErr wbcCtxLogonUser(struct wbcContext *ctx,
     1665                       const struct wbcLogonUserParams *params,
     1666                       struct wbcLogonUserInfo **info,
     1667                       struct wbcAuthErrorInfo **error,
     1668                       struct wbcUserPasswordPolicyInfo **policy);
     1669
     1670/**
     1671 * @brief Logon a User
     1672 *
     1673 * @param[in]  params      Pointer to a wbcLogonUserParams structure
     1674 * @param[out] info        Pointer to a pointer to a wbcLogonUserInfo structure
     1675 * @param[out] error       Pointer to a pointer to a wbcAuthErrorInfo structure
     1676 * @param[out] policy      Pointer to a pointer to a wbcUserPasswordPolicyInfo structure
     1677 *
     1678 * @return #wbcErr
     1679 **/
    11811680wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
    11821681                    struct wbcLogonUserInfo **info,
     
    11871686 * @brief Trigger a logoff notification to Winbind for a specific user
    11881687 *
     1688 * @param *ctx        wbclient Context
    11891689 * @param username    Name of user to remove from Winbind's list of
    11901690 *                    logged on users.
     
    11951695 * @return #wbcErr
    11961696 **/
     1697wbcErr wbcCtxLogoffUser(struct wbcContext *ctx,
     1698                        const char *username, uid_t uid,
     1699                        const char *ccfilename);
     1700
     1701/**
     1702 * @brief Trigger a logoff notification to Winbind for a specific user
     1703 *
     1704 * @param username    Name of user to remove from Winbind's list of
     1705 *                    logged on users.
     1706 * @param uid         Uid assigned to the username
     1707 * @param ccfilename  Absolute path to the Krb5 credentials cache to
     1708 *                    be removed
     1709 *
     1710 * @return #wbcErr
     1711 **/
    11971712wbcErr wbcLogoffUser(const char *username,
    11981713                     uid_t uid,
     
    12021717 * @brief Trigger an extended logoff notification to Winbind for a specific user
    12031718 *
     1719 * @param *ctx        wbclient Context
    12041720 * @param params      A wbcLogoffUserParams structure
    12051721 * @param error       User output details on error
     
    12071723 * @return #wbcErr
    12081724 **/
     1725wbcErr wbcCtxLogoffUserEx(struct wbcContext *ctx,
     1726                          const struct wbcLogoffUserParams *params,
     1727                          struct wbcAuthErrorInfo **error);
     1728
     1729/**
     1730 * @brief Trigger an extended logoff notification to Winbind for a specific user
     1731 *
     1732 * @param params      A wbcLogoffUserParams structure
     1733 * @param error       User output details on error
     1734 *
     1735 * @return #wbcErr
     1736 **/
    12091737wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
    12101738                       struct wbcAuthErrorInfo **error);
     
    12131741 * @brief Change a password for a user
    12141742 *
     1743 * @param *ctx          wbclient Context
    12151744 * @param username      Name of user to authenticate
    12161745 * @param old_password  Old clear text password of user
     
    12191748 * @return #wbcErr
    12201749 **/
     1750wbcErr wbcCtxChangeUserPassword(struct wbcContext *ctx,
     1751                                const char *username,
     1752                                const char *old_password,
     1753                                const char *new_password);
     1754
     1755/**
     1756 * @brief Change a password for a user
     1757 *
     1758 * @param username      Name of user to authenticate
     1759 * @param old_password  Old clear text password of user
     1760 * @param new_password  New clear text password of user
     1761 *
     1762 * @return #wbcErr
     1763 **/
    12211764wbcErr wbcChangeUserPassword(const char *username,
    12221765                             const char *old_password,
     
    12271770 *   failure
    12281771 *
     1772 * @param *ctx                  wbclient Context
    12291773 * @param params                Input parameters
    12301774 * @param error                 User output details on WBC_ERR_PWD_CHANGE_FAILED
     
    12341778 * @return #wbcErr
    12351779 **/
     1780wbcErr wbcCtxChangeUserPasswordEx(struct wbcContext *ctx,
     1781                                  const struct wbcChangePasswordParams *params,
     1782                                  struct wbcAuthErrorInfo **error,
     1783                                  enum wbcPasswordChangeRejectReason *reject_reason,
     1784                                  struct wbcUserPasswordPolicyInfo **policy);
     1785
     1786/**
     1787 * @brief Change a password for a user with more detailed information upon
     1788 *   failure
     1789 *
     1790 * @param params                Input parameters
     1791 * @param error                 User output details on WBC_ERR_PWD_CHANGE_FAILED
     1792 * @param reject_reason         New password reject reason on WBC_ERR_PWD_CHANGE_FAILED
     1793 * @param policy                Password policy output details on WBC_ERR_PWD_CHANGE_FAILED
     1794 *
     1795 * @return #wbcErr
     1796 **/
    12361797wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
    12371798                               struct wbcAuthErrorInfo **error,
     
    12421803 * @brief Authenticate a user with cached credentials
    12431804 *
     1805 * @param *ctx       wbclient Context
    12441806 * @param *params    Pointer to a wbcCredentialCacheParams structure
    12451807 * @param **info     Pointer to a pointer to a wbcCredentialCacheInfo structure
     
    12481810 * @return #wbcErr
    12491811 **/
     1812wbcErr wbcCtxCredentialCache(struct wbcContext *ctx,
     1813                             struct wbcCredentialCacheParams *params,
     1814                             struct wbcCredentialCacheInfo **info,
     1815                             struct wbcAuthErrorInfo **error);
     1816
     1817/**
     1818 * @brief Authenticate a user with cached credentials
     1819 *
     1820 * @param *params    Pointer to a wbcCredentialCacheParams structure
     1821 * @param **info     Pointer to a pointer to a wbcCredentialCacheInfo structure
     1822 * @param **error    Pointer to a pointer to a wbcAuthErrorInfo structure
     1823 *
     1824 * @return #wbcErr
     1825 **/
    12501826wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
    12511827                          struct wbcCredentialCacheInfo **info,
     
    12551831 * @brief Save a password with winbind for doing wbcCredentialCache() later
    12561832 *
     1833 * @param *ctx       wbclient Context
     1834 * @param *user      Username
     1835 * @param *password  Password
     1836 *
     1837 * @return #wbcErr
     1838 **/
     1839wbcErr wbcCtxCredentialSave(struct wbcContext *ctx,
     1840                            const char *user, const char *password);
     1841
     1842/**
     1843 * @brief Save a password with winbind for doing wbcCredentialCache() later
     1844 *
    12571845 * @param *user      Username
    12581846 * @param *password  Password
     
    12691857 * @brief Resolve a NetbiosName via WINS
    12701858 *
     1859 * @param *ctx         wbclient Context
    12711860 * @param name         Name to resolve
    12721861 * @param *ip          Pointer to the ip address string
     
    12741863 * @return #wbcErr
    12751864 **/
     1865wbcErr wbcCtxResolveWinsByName(struct wbcContext *ctx,
     1866                               const char *name, char **ip);
     1867
     1868/**
     1869 * @brief Resolve a NetbiosName via WINS
     1870 *
     1871 * @param name         Name to resolve
     1872 * @param *ip          Pointer to the ip address string
     1873 *
     1874 * @return #wbcErr
     1875 **/
    12761876wbcErr wbcResolveWinsByName(const char *name, char **ip);
    12771877
     
    12791879 * @brief Resolve an IP address via WINS into a NetbiosName
    12801880 *
    1281  * @param ip          The ip address string
    1282  * @param *name       Pointer to the name
     1881 * @param *ctx         wbclient Context
     1882 * @param ip           The ip address string
     1883 * @param *name        Pointer to the name
     1884 *
     1885 * @return #wbcErr
     1886 *
     1887 **/
     1888wbcErr wbcCtxResolveWinsByIP(struct wbcContext *ctx,
     1889                             const char *ip, char **name);
     1890
     1891/**
     1892 * @brief Resolve an IP address via WINS into a NetbiosName
     1893 *
     1894 * @param ip           The ip address string
     1895 * @param *name        Pointer to the name
    12831896 *
    12841897 * @return #wbcErr
     
    12941907 * @brief Trigger a verification of the trust credentials of a specific domain
    12951908 *
     1909 * @param *ctx         wbclient Context
    12961910 * @param *domain      The name of the domain.
    12971911 * @param error        Output details on WBC_ERR_AUTH_ERROR
     
    12991913 * @return #wbcErr
    13001914 **/
     1915wbcErr wbcCtxCheckTrustCredentials(struct wbcContext *ctx, const char *domain,
     1916                                   struct wbcAuthErrorInfo **error);
     1917
     1918/**
     1919 * @brief Trigger a verification of the trust credentials of a specific domain
     1920 *
     1921 * @param *domain      The name of the domain.
     1922 * @param error        Output details on WBC_ERR_AUTH_ERROR
     1923 *
     1924 * @return #wbcErr
     1925 **/
    13011926wbcErr wbcCheckTrustCredentials(const char *domain,
    13021927                                struct wbcAuthErrorInfo **error);
     
    13051930 * @brief Trigger a change of the trust credentials for a specific domain
    13061931 *
     1932 * @param *ctx         wbclient Context
    13071933 * @param *domain      The name of the domain.
    13081934 * @param error        Output details on WBC_ERR_AUTH_ERROR
     
    13101936 * @return #wbcErr
    13111937 **/
     1938wbcErr wbcCtxChangeTrustCredentials(struct wbcContext *ctx, const char *domain,
     1939                                    struct wbcAuthErrorInfo **error);
     1940
     1941/**
     1942 * @brief Trigger a change of the trust credentials for a specific domain
     1943 *
     1944 * @param *domain      The name of the domain.
     1945 * @param error        Output details on WBC_ERR_AUTH_ERROR
     1946 *
     1947 * @return #wbcErr
     1948 **/
    13121949wbcErr wbcChangeTrustCredentials(const char *domain,
    13131950                                 struct wbcAuthErrorInfo **error);
     
    13171954 *        version of wbcCheckTrustCredentials
    13181955 *
     1956 * @param *ctx         wbclient Context
    13191957 * @param *domain      The name of the domain, only NULL for the default domain is
    13201958 *                     supported yet. Other values than NULL will result in
     
    13241962 * @return #wbcErr
    13251963 **/
     1964wbcErr wbcCtxPingDc(struct wbcContext *ctx, const char *domain,
     1965                    struct wbcAuthErrorInfo **error);
     1966
     1967/**
     1968 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
     1969 *        version of wbcCheckTrustCredentials
     1970 *
     1971 * @param *domain      The name of the domain, only NULL for the default domain is
     1972 *                     supported yet. Other values than NULL will result in
     1973 *                     WBC_ERR_NOT_IMPLEMENTED.
     1974 * @param error        Output details on WBC_ERR_AUTH_ERROR
     1975 *
     1976 * @return #wbcErr
     1977 **/
    13261978wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error);
     1979
     1980/**
     1981 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
     1982 *        version of wbcCheckTrustCredentials
     1983 *
     1984 * @param *ctx         wbclient Context
     1985 * @param *domain      The name of the domain, only NULL for the default domain is
     1986 *                     supported yet. Other values than NULL will result in
     1987 *                     WBC_ERR_NOT_IMPLEMENTED.
     1988 * @param error        Output details on WBC_ERR_AUTH_ERROR
     1989 * @param dcname       DC that was attempted to ping
     1990 *
     1991 * @return #wbcErr
     1992 **/
     1993wbcErr wbcCtxPingDc2(struct wbcContext *ctx, const char *domain,
     1994                     struct wbcAuthErrorInfo **error,
     1995                     char **dcname);
     1996
     1997/**
     1998 * @brief Trigger a no-op call through the NETLOGON pipe. Low-cost
     1999 *        version of wbcCheckTrustCredentials
     2000 *
     2001 * @param *domain      The name of the domain, only NULL for the default domain is
     2002 *                     supported yet. Other values than NULL will result in
     2003 *                     WBC_ERR_NOT_IMPLEMENTED.
     2004 * @param error        Output details on WBC_ERR_AUTH_ERROR
     2005 * @param dcname       DC that was attempted to ping
     2006 *
     2007 * @return #wbcErr
     2008 **/
     2009wbcErr wbcPingDc2(const char *domain, struct wbcAuthErrorInfo **error,
     2010                  char **dcname);
    13272011
    13282012/**********************************************************
  • vendor/current/nsswitch/libwbclient/wbclient_internal.h

    r740 r988  
    2323#define _WBCLIENT_INTERNAL_H
    2424
     25struct wbcContext {
     26        struct winbindd_context *winbindd_ctx;
     27        uint32_t pw_cache_size; /* Number of cached passwd structs */
     28        uint32_t pw_cache_idx;  /* Position of the pwent context */
     29        uint32_t gr_cache_size; /* Number of cached group structs */
     30        uint32_t gr_cache_idx;  /* Position of the grent context */
     31};
     32
    2533/* Private functions */
    2634
    27 wbcErr wbcRequestResponse(int cmd,
     35wbcErr wbcRequestResponse(struct wbcContext *ctx, int cmd,
    2836                          struct winbindd_request *request,
    2937                          struct winbindd_response *response);
    3038
    31 wbcErr wbcRequestResponsePriv(int cmd,
     39wbcErr wbcRequestResponsePriv(struct wbcContext *ctx, int cmd,
    3240                              struct winbindd_request *request,
    3341                              struct winbindd_response *response);
     
    3846char *wbcStrDup(const char *str);
    3947const char **wbcAllocateStringArray(int num_strings);
     48struct wbcContext *wbcGetGlobalCtx(void);
    4049
    4150#endif      /* _WBCLIENT_INTERNAL_H */
Note: See TracChangeset for help on using the changeset viewer.