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

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

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

    r414 r740  
    22   Unix SMB/CIFS implementation.
    33   SMB torture tester
    4    Copyright (C) Guenther Deschner 2009
     4   Copyright (C) Guenther Deschner 2009-2010
    55
    66   This program is free software; you can redistribute it and/or modify
     
    1818*/
    1919
    20 #include "includes.h"
     20#include "lib/replace/replace.h"
     21#include "libcli/util/ntstatus.h"
     22#include "libcli/util/werror.h"
     23#include "lib/util/data_blob.h"
     24#include "lib/util/time.h"
    2125#include "nsswitch/libwbclient/wbclient.h"
    2226#include "torture/smbtorture.h"
    2327#include "torture/winbind/proto.h"
     28#include "lib/util/util_net.h"
     29#include "lib/util/charset/charset.h"
     30#include "libcli/auth/libcli_auth.h"
     31#include "source4/param/param.h"
     32#include "lib/util/util.h"
     33#include "lib/crypto/arcfour.h"
    2434
    2535#define WBC_ERROR_EQUAL(x,y) (x == y)
     
    4050        torture_assert_wbc_ok(tctx, wbcPing(),
    4151                "wbcPing failed");
     52
     53        return true;
     54}
     55
     56static bool test_wbc_pingdc(struct torture_context *tctx)
     57{
     58        torture_assert_wbc_equal(tctx, wbcPingDc("random_string", NULL), WBC_ERR_NOT_IMPLEMENTED,
     59                "wbcPingDc failed");
     60        torture_assert_wbc_ok(tctx, wbcPingDc(NULL, NULL),
     61                "wbcPingDc failed");
    4262
    4363        return true;
     
    109129        torture_assert_str_equal(tctx, sid_string, sid_string2,
    110130                "sid strings differ");
     131        wbcFreeMemory(sid_string2);
    111132
    112133        return true;
     
    125146        torture_assert_str_equal(tctx, guid_string, guid_string2,
    126147                "guid strings differ");
     148        wbcFreeMemory(guid_string2);
    127149
    128150        return true;
     
    131153static bool test_wbc_domain_info(struct torture_context *tctx)
    132154{
    133         const char *domain_name = NULL;
    134155        struct wbcDomainInfo *info;
    135156        struct wbcInterfaceDetails *details;
     
    137158        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
    138159                "wbcInterfaceDetails failed");
    139 
    140         domain_name = talloc_strdup(tctx, details->netbios_domain);
     160        torture_assert_wbc_ok(
     161                tctx, wbcDomainInfo(details->netbios_domain, &info),
     162                "wbcDomainInfo failed");
    141163        wbcFreeMemory(details);
    142164
    143         torture_assert_wbc_ok(tctx, wbcDomainInfo(domain_name, &info),
    144                 "wbcDomainInfo failed");
    145165        torture_assert(tctx, info,
    146166                "wbcDomainInfo returned NULL pointer");
     167        wbcFreeMemory(info);
    147168
    148169        return true;
     
    186207                torture_assert(tctx, name,
    187208                        "wbcLookupSid returned no name");
     209                wbcFreeMemory(domain);
     210                wbcFreeMemory(name);
    188211                torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids),
    189212                        "wbcLookupUserSids failed");
     213                torture_assert_wbc_ok(
     214                        tctx, wbcGetDisplayName(&sid, &domain, &name,
     215                                                &name_type),
     216                        "wbcGetDisplayName failed");
     217                wbcFreeMemory(domain);
     218                wbcFreeMemory(name);
     219                wbcFreeMemory(sids);
    190220        }
     221        wbcFreeMemory(users);
    191222
    192223        return true;
     
    226257                        "wbcLookupSid returned no name");
    227258        }
     259        wbcFreeMemory(groups);
    228260
    229261        return true;
     
    265297                */
    266298        }
     299        wbcFreeMemory(domains);
    267300
    268301        return true;
     
    283316        torture_assert_wbc_ok(tctx, wbcLookupDomainController(domain_name, 0, &dc_info),
    284317                "wbcLookupDomainController failed");
     318        wbcFreeMemory(dc_info);
    285319
    286320        return true;
     
    301335        torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info),
    302336                "wbcLookupDomainControllerEx failed");
    303 
    304         return true;
    305 }
    306 
     337        wbcFreeMemory(dc_info);
     338
     339        return true;
     340}
     341
     342static bool test_wbc_resolve_winsbyname(struct torture_context *tctx)
     343{
     344        const char *name;
     345        char *ip;
     346        wbcErr ret;
     347
     348        name = torture_setting_string(tctx, "host", NULL);
     349
     350        ret = wbcResolveWinsByName(name, &ip);
     351
     352        if (is_ipaddress(name)) {
     353                torture_assert_wbc_equal(tctx, ret, WBC_ERR_DOMAIN_NOT_FOUND, "wbcResolveWinsByName failed");
     354        } else {
     355                torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByName failed");
     356        }
     357
     358        return true;
     359}
     360
     361static bool test_wbc_resolve_winsbyip(struct torture_context *tctx)
     362{
     363        const char *ip;
     364        char *name;
     365        wbcErr ret;
     366
     367        ip = torture_setting_string(tctx, "host", NULL);
     368
     369        ret = wbcResolveWinsByIP(ip, &name);
     370
     371        torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP failed");
     372
     373        wbcFreeMemory(name);
     374
     375        return true;
     376}
     377
     378static bool test_wbc_lookup_rids(struct torture_context *tctx)
     379{
     380        struct wbcDomainSid builtin;
     381        uint32_t rids[2] = { 544, 545 };
     382        const char *domain_name, **names;
     383        enum wbcSidType *types;
     384        wbcErr ret;
     385
     386        wbcStringToSid("S-1-5-32", &builtin);
     387
     388        ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names,
     389                            &types);
     390        torture_assert_wbc_ok(tctx, ret, "wbcLookupRids failed");
     391
     392        torture_assert_str_equal(
     393                tctx, names[0], "Administrators",
     394                "S-1-5-32-544 not mapped to 'Administrators'");
     395        torture_assert_str_equal(
     396                tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'");
     397
     398        wbcFreeMemory((char *)domain_name);
     399        wbcFreeMemory(names);
     400        wbcFreeMemory(types);
     401
     402        return true;
     403}
     404
     405static bool test_wbc_get_sidaliases(struct torture_context *tctx)
     406{
     407        struct wbcDomainSid builtin;
     408        struct wbcDomainInfo *info;
     409        struct wbcInterfaceDetails *details;
     410        struct wbcDomainSid sids[2];
     411        uint32_t *rids;
     412        uint32_t num_rids;
     413        wbcErr ret;
     414
     415        torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details),
     416                "wbcInterfaceDetails failed");
     417        torture_assert_wbc_ok(
     418                tctx, wbcDomainInfo(details->netbios_domain, &info),
     419                "wbcDomainInfo failed");
     420        wbcFreeMemory(details);
     421
     422        sids[0] = info->sid;
     423        sids[0].sub_auths[sids[0].num_auths++] = 500;
     424        sids[1] = info->sid;
     425        sids[1].sub_auths[sids[1].num_auths++] = 512;
     426        wbcFreeMemory(info);
     427
     428        torture_assert_wbc_ok(
     429                tctx, wbcStringToSid("S-1-5-32", &builtin),
     430                "wbcStringToSid failed");
     431
     432        ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids);
     433        torture_assert_wbc_ok(tctx, ret, "wbcGetSidAliases failed");
     434
     435        wbcFreeMemory(rids);
     436
     437        return true;
     438}
     439
     440static bool test_wbc_authenticate_user_int(struct torture_context *tctx,
     441                                           const char *correct_password)
     442{
     443        struct wbcAuthUserParams params;
     444        struct wbcAuthUserInfo *info = NULL;
     445        struct wbcAuthErrorInfo *error = NULL;
     446        wbcErr ret;
     447
     448        ret = wbcAuthenticateUser(getenv("USERNAME"), correct_password);
     449        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     450                                 "wbcAuthenticateUser failed");
     451
     452        ZERO_STRUCT(params);
     453        params.account_name             = getenv("USERNAME");
     454        params.level                    = WBC_AUTH_USER_LEVEL_PLAIN;
     455        params.password.plaintext       = correct_password;
     456
     457        ret = wbcAuthenticateUserEx(&params, &info, &error);
     458        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     459                                 "wbcAuthenticateUserEx failed");
     460        wbcFreeMemory(info);
     461        info = NULL;
     462
     463        wbcFreeMemory(error);
     464        error = NULL;
     465
     466        params.password.plaintext       = "wrong";
     467        ret = wbcAuthenticateUserEx(&params, &info, &error);
     468        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
     469                                 "wbcAuthenticateUserEx succeeded where it "
     470                                 "should have failed");
     471        wbcFreeMemory(info);
     472        info = NULL;
     473
     474        wbcFreeMemory(error);
     475        error = NULL;
     476
     477        return true;
     478}
     479
     480static bool test_wbc_authenticate_user(struct torture_context *tctx)
     481{
     482        return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
     483}
     484
     485static bool test_wbc_change_password(struct torture_context *tctx)
     486{
     487        wbcErr ret;
     488        const char *oldpass = getenv("PASSWORD");
     489        const char *newpass = "Koo8irei";
     490
     491        struct samr_CryptPassword new_nt_password;
     492        struct samr_CryptPassword new_lm_password;
     493        struct samr_Password old_nt_hash_enc;
     494        struct samr_Password old_lanman_hash_enc;
     495
     496        uint8_t old_nt_hash[16];
     497        uint8_t old_lanman_hash[16];
     498        uint8_t new_nt_hash[16];
     499        uint8_t new_lanman_hash[16];
     500
     501        struct wbcChangePasswordParams params;
     502
     503        if (oldpass == NULL) {
     504                torture_skip(tctx,
     505                        "skipping wbcChangeUserPassword test as old password cannot be retrieved\n");
     506        }
     507
     508        ZERO_STRUCT(params);
     509
     510        E_md4hash(oldpass, old_nt_hash);
     511        E_md4hash(newpass, new_nt_hash);
     512
     513        if (lpcfg_client_lanman_auth(tctx->lp_ctx) &&
     514            E_deshash(newpass, new_lanman_hash) &&
     515            E_deshash(oldpass, old_lanman_hash)) {
     516
     517                /* E_deshash returns false for 'long' passwords (> 14
     518                   DOS chars).  This allows us to match Win2k, which
     519                   does not store a LM hash for these passwords (which
     520                   would reduce the effective password length to 14) */
     521
     522                encode_pw_buffer(new_lm_password.data, newpass, STR_UNICODE);
     523                arcfour_crypt(new_lm_password.data, old_nt_hash, 516);
     524                E_old_pw_hash(new_nt_hash, old_lanman_hash,
     525                              old_lanman_hash_enc.hash);
     526
     527                params.old_password.response.old_lm_hash_enc_length =
     528                        sizeof(old_lanman_hash_enc.hash);
     529                params.old_password.response.old_lm_hash_enc_data =
     530                        old_lanman_hash_enc.hash;
     531                params.new_password.response.lm_length =
     532                        sizeof(new_lm_password.data);
     533                params.new_password.response.lm_data =
     534                        new_lm_password.data;
     535        } else {
     536                ZERO_STRUCT(new_lm_password);
     537                ZERO_STRUCT(old_lanman_hash_enc);
     538        }
     539
     540        encode_pw_buffer(new_nt_password.data, newpass, STR_UNICODE);
     541
     542        arcfour_crypt(new_nt_password.data, old_nt_hash, 516);
     543        E_old_pw_hash(new_nt_hash, old_nt_hash, old_nt_hash_enc.hash);
     544
     545        params.old_password.response.old_nt_hash_enc_length =
     546                sizeof(old_nt_hash_enc.hash);
     547        params.old_password.response.old_nt_hash_enc_data =
     548                old_nt_hash_enc.hash;
     549        params.new_password.response.nt_length = sizeof(new_nt_password.data);
     550        params.new_password.response.nt_data = new_nt_password.data;
     551
     552        params.level = WBC_CHANGE_PASSWORD_LEVEL_RESPONSE;
     553        params.account_name = getenv("USERNAME");
     554        params.domain_name = "SAMBA-TEST";
     555
     556        ret = wbcChangeUserPasswordEx(&params, NULL, NULL, NULL);
     557        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     558                                 "wbcChangeUserPassword failed");
     559
     560        if (!test_wbc_authenticate_user_int(tctx, "Koo8irei")) {
     561                return false;
     562        }
     563
     564        ret = wbcChangeUserPassword(getenv("USERNAME"), "Koo8irei",
     565                                    getenv("PASSWORD"));
     566        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     567                                 "wbcChangeUserPassword failed");
     568
     569        return test_wbc_authenticate_user_int(tctx, getenv("PASSWORD"));
     570}
     571
     572static bool test_wbc_logon_user(struct torture_context *tctx)
     573{
     574        struct wbcLogonUserParams params;
     575        struct wbcLogonUserInfo *info = NULL;
     576        struct wbcAuthErrorInfo *error = NULL;
     577        struct wbcUserPasswordPolicyInfo *policy = NULL;
     578        struct wbcInterfaceDetails *iface;
     579        struct wbcDomainSid sid;
     580        enum wbcSidType sidtype;
     581        char *sidstr;
     582        wbcErr ret;
     583
     584        ZERO_STRUCT(params);
     585
     586        ret = wbcLogonUser(&params, &info, &error, &policy);
     587        torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM,
     588                                 "wbcLogonUser succeeded where it should "
     589                                 "have failed");
     590
     591        params.username = getenv("USERNAME");
     592        params.password = getenv("PASSWORD");
     593
     594        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     595                              "foo", 0, discard_const_p(uint8_t, "bar"), 4);
     596        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     597                                 "wbcAddNamedBlob failed");
     598
     599        ret = wbcLogonUser(&params, &info, &error, &policy);
     600        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     601                                 "wbcLogonUser failed");
     602        wbcFreeMemory(info); info = NULL;
     603        wbcFreeMemory(error); error = NULL;
     604        wbcFreeMemory(policy); policy = NULL;
     605
     606        params.password = "wrong";
     607
     608        ret = wbcLogonUser(&params, &info, &error, &policy);
     609        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
     610                                 "wbcLogonUser should have failed with "
     611                                 "WBC_ERR_AUTH_ERROR");
     612        wbcFreeMemory(info); info = NULL;
     613        wbcFreeMemory(error); error = NULL;
     614        wbcFreeMemory(policy); policy = NULL;
     615
     616        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     617                              "membership_of", 0,
     618                              discard_const_p(uint8_t, "S-1-2-3-4"),
     619                              strlen("S-1-2-3-4")+1);
     620        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     621                                 "wbcAddNamedBlob failed");
     622        params.password = getenv("PASSWORD");
     623        ret = wbcLogonUser(&params, &info, &error, &policy);
     624        torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR,
     625                                 "wbcLogonUser should have failed with "
     626                                 "WBC_ERR_AUTH_ERROR");
     627        wbcFreeMemory(info); info = NULL;
     628        wbcFreeMemory(error); error = NULL;
     629        wbcFreeMemory(policy); policy = NULL;
     630        wbcFreeMemory(params.blobs);
     631        params.blobs = NULL; params.num_blobs = 0;
     632
     633        ret = wbcInterfaceDetails(&iface);
     634        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     635                                 "wbcInterfaceDetails failed");
     636
     637        ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid,
     638                            &sidtype);
     639        wbcFreeMemory(iface);
     640        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     641                                 "wbcLookupName failed");
     642
     643        ret = wbcSidToString(&sid, &sidstr);
     644        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     645                                 "wbcSidToString failed");
     646
     647        ret = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
     648                              "membership_of", 0,
     649                              (uint8_t *)sidstr, strlen(sidstr)+1);
     650        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     651                                 "wbcAddNamedBlob failed");
     652        wbcFreeMemory(sidstr);
     653        params.password = getenv("PASSWORD");
     654        ret = wbcLogonUser(&params, &info, &error, &policy);
     655        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     656                                 "wbcLogonUser failed");
     657        wbcFreeMemory(info); info = NULL;
     658        wbcFreeMemory(error); error = NULL;
     659        wbcFreeMemory(policy); policy = NULL;
     660        wbcFreeMemory(params.blobs);
     661        params.blobs = NULL; params.num_blobs = 0;
     662
     663        return true;
     664}
     665
     666static bool test_wbc_getgroups(struct torture_context *tctx)
     667{
     668        wbcErr ret;
     669        uint32_t num_groups;
     670        gid_t *groups;
     671
     672        ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups);
     673        torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS,
     674                                 "wbcGetGroups failed");
     675        wbcFreeMemory(groups);
     676        return true;
     677}
    307678
    308679struct torture_suite *torture_wbclient(void)
    309680{
    310         struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "WBCLIENT");
     681        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient");
    311682
    312683        torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping);
     684        torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc);
    313685        torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details);
    314686        torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details);
     
    322694        torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc);
    323695        torture_suite_add_simple_test(suite, "wbcLookupDomainControllerEx", test_wbc_lookupdcex);
     696        torture_suite_add_simple_test(suite, "wbcResolveWinsByName", test_wbc_resolve_winsbyname);
     697        torture_suite_add_simple_test(suite, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip);
     698        torture_suite_add_simple_test(suite, "wbcLookupRids",
     699                                      test_wbc_lookup_rids);
     700        torture_suite_add_simple_test(suite, "wbcGetSidAliases",
     701                                      test_wbc_get_sidaliases);
     702        torture_suite_add_simple_test(suite, "wbcAuthenticateUser",
     703                                      test_wbc_authenticate_user);
     704        torture_suite_add_simple_test(suite, "wbcLogonUser",
     705                                      test_wbc_logon_user);
     706        torture_suite_add_simple_test(suite, "wbcChangeUserPassword",
     707                                      test_wbc_change_password);
     708        torture_suite_add_simple_test(suite, "wbcGetGroups",
     709                                      test_wbc_getgroups);
    324710
    325711        return suite;
Note: See TracChangeset for help on using the changeset viewer.