Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libsmb/clidfs.c

    r599 r745  
    2121
    2222#include "includes.h"
     23#include "libsmb/libsmb.h"
     24#include "libsmb/clirap.h"
     25#include "msdfs.h"
     26#include "trans2.h"
     27#include "libsmb/nmblib.h"
    2328
    2429/********************************************************************
     
    128133
    129134        /* have to open a new connection */
    130         if (!(c=cli_initialise_ex(get_cmdline_auth_info_signing_state(auth_info)))) {
     135        c = cli_initialise_ex(get_cmdline_auth_info_signing_state(auth_info));
     136        if (c == NULL) {
    131137                d_printf("Connection to %s failed\n", server_n);
    132                 if (c) {
    133                         cli_shutdown(c);
    134                 }
    135138                return NULL;
    136139        }
     
    321324        }
    322325
    323         if (referring_cli && referring_cli->posix_capabilities) {
     326        if (referring_cli && referring_cli->requested_posix_capabilities) {
    324327                uint16 major, minor;
    325328                uint32 caplow, caphigh;
     
    352355
    353356        /* Search to the start of the list. */
    354         for (p = cli; p; p = p->prev) {
     357        for (p = cli; p; p = DLIST_PREV(p)) {
    355358                if (strequal(server, p->desthost) &&
    356359                                strequal(share,p->share)) {
     
    453456**********************************************************************/
    454457
    455 static void split_dfs_path(TALLOC_CTX *ctx,
     458static bool split_dfs_path(TALLOC_CTX *ctx,
    456459                                const char *nodepath,
    457460                                char **pp_server,
     
    468471        path = talloc_strdup(ctx, nodepath);
    469472        if (!path) {
    470                 return;
     473                goto fail;
    471474        }
    472475
    473476        if ( path[0] != '\\' ) {
    474                 return;
     477                goto fail;
    475478        }
    476479
    477480        p = strchr_m( path + 1, '\\' );
    478481        if ( !p ) {
    479                 return;
     482                goto fail;
    480483        }
    481484
     
    492495                *pp_extrapath = talloc_strdup(ctx, "");
    493496        }
     497        if (*pp_extrapath == NULL) {
     498                goto fail;
     499        }
    494500
    495501        *pp_share = talloc_strdup(ctx, p);
     502        if (*pp_share == NULL) {
     503                goto fail;
     504        }
     505
    496506        *pp_server = talloc_strdup(ctx, &path[1]);
     507        if (*pp_server == NULL) {
     508                goto fail;
     509        }
     510
     511        TALLOC_FREE(path);
     512        return true;
     513
     514fail:
     515        TALLOC_FREE(*pp_share);
     516        TALLOC_FREE(*pp_extrapath);
     517        TALLOC_FREE(path);
     518        return false;
    497519}
    498520
     
    565587        }
    566588
    567         if (cli->posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
     589        if (cli->requested_posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
    568590                path_sep = '/';
    569591        }
     
    581603********************************************************************/
    582604
    583 static bool cli_dfs_check_error( struct cli_state *cli, NTSTATUS status )
    584 {
    585         uint32 flgs2 = SVAL(cli->inbuf,smb_flg2);
    586 
     605static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected,
     606                                NTSTATUS status)
     607{
    587608        /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
    588609
    589         if (!((flgs2&FLAGS2_32_BIT_ERROR_CODES) &&
    590                                 (flgs2&FLAGS2_UNICODE_STRINGS)))
    591                 return false;
    592 
    593         if (NT_STATUS_EQUAL(status, NT_STATUS(IVAL(cli->inbuf,smb_rcls))))
     610        if (!(cli->capabilities & CAP_UNICODE)) {
     611                return false;
     612        }
     613        if (!(cli->capabilities & CAP_STATUS32)) {
     614                return false;
     615        }
     616        if (NT_STATUS_EQUAL(status, expected)) {
    594617                return true;
    595 
     618        }
    596619        return false;
    597620}
     
    601624********************************************************************/
    602625
    603 bool cli_dfs_get_referral(TALLOC_CTX *ctx,
     626NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
    604627                        struct cli_state *cli,
    605628                        const char *path,
    606                         CLIENT_DFS_REFERRAL**refs,
     629                        struct client_dfs_referral **refs,
    607630                        size_t *num_refs,
    608631                        size_t *consumed)
     
    610633        unsigned int data_len = 0;
    611634        unsigned int param_len = 0;
    612         uint16 setup = TRANSACT2_GET_DFS_REFERRAL;
    613         char *param = NULL;
    614         char *rparam=NULL, *rdata=NULL;
     635        uint16 setup[1];
     636        uint8_t *param = NULL;
     637        uint8_t *rdata = NULL;
    615638        char *p;
    616639        char *endp;
     
    620643        uint16_t consumed_ucs;
    621644        uint16 num_referrals;
    622         CLIENT_DFS_REFERRAL *referrals = NULL;
    623         bool ret = false;
     645        struct client_dfs_referral *referrals = NULL;
     646        NTSTATUS status;
    624647
    625648        *num_refs = 0;
    626649        *refs = NULL;
    627650
    628         param = SMB_MALLOC_ARRAY(char, 2+pathlen+2);
     651        SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL);
     652
     653        param = SMB_MALLOC_ARRAY(uint8_t, 2+pathlen+2);
    629654        if (!param) {
     655                status = NT_STATUS_NO_MEMORY;
    630656                goto out;
    631657        }
    632658        SSVAL(param, 0, 0x03);  /* max referral level */
    633         p = &param[2];
     659        p = (char *)(&param[2]);
    634660
    635661        path_ucs = (smb_ucs2_t *)p;
     
    637663        param_len = PTR_DIFF(p, param);
    638664
    639         if (!cli_send_trans(cli, SMBtrans2,
    640                         NULL,                        /* name */
    641                         -1, 0,                          /* fid, flags */
    642                         &setup, 1, 0,                   /* setup, length, max */
    643                         param, param_len, 2,            /* param, length, max */
    644                         NULL, 0, cli->max_xmit /* data, length, max */
    645                         )) {
     665        status = cli_trans(talloc_tos(), cli, SMBtrans2,
     666                           NULL, 0xffff, 0, 0,
     667                           setup, 1, 0,
     668                           param, param_len, 2,
     669                           NULL, 0, cli->max_xmit,
     670                           NULL,
     671                           NULL, 0, NULL, /* rsetup */
     672                           NULL, 0, NULL,
     673                           &rdata, 4, &data_len);
     674        if (!NT_STATUS_IS_OK(status)) {
    646675                goto out;
    647676        }
    648 
    649         if (!cli_receive_trans(cli, SMBtrans2,
    650                 &rparam, &param_len,
    651                 &rdata, &data_len)) {
    652                 goto out;
    653         }
    654 
    655677        if (data_len < 4) {
    656678                goto out;
    657679        }
    658680
    659         endp = rdata + data_len;
     681        endp = (char *)rdata + data_len;
    660682
    661683        consumed_ucs  = SVAL(rdata, 0);
     
    689711                uint16 node_offset;
    690712
    691                 referrals = TALLOC_ARRAY(ctx, CLIENT_DFS_REFERRAL,
    692                                 num_referrals);
     713                referrals = talloc_array(ctx, struct client_dfs_referral,
     714                                         num_referrals);
    693715
    694716                if (!referrals) {
     
    697719                /* start at the referrals array */
    698720
    699                 p = rdata+8;
     721                p = (char *)rdata+8;
    700722                for (i=0; i<num_referrals && p < endp; i++) {
    701723                        if (p + 18 > endp) {
     
    718740                        }
    719741                        clistr_pull_talloc(ctx, cli->inbuf,
     742                                           SVAL(cli->inbuf, smb_flg2),
    720743                                           &referrals[i].dfspath,
    721744                                           p+node_offset, -1,
     
    732755        }
    733756
    734         ret = true;
    735 
    736757        *num_refs = num_referrals;
    737758        *refs = referrals;
     
    741762        TALLOC_FREE(consumed_path);
    742763        SAFE_FREE(param);
    743         SAFE_FREE(rdata);
    744         SAFE_FREE(rparam);
    745         return ret;
     764        TALLOC_FREE(rdata);
     765        return status;
    746766}
    747767
     
    757777                        char **pp_targetpath)
    758778{
    759         CLIENT_DFS_REFERRAL *refs = NULL;
     779        struct client_dfs_referral *refs = NULL;
    760780        size_t num_refs = 0;
    761781        size_t consumed = 0;
     
    773793        SMB_STRUCT_STAT sbuf;
    774794        uint32 attributes;
     795        NTSTATUS status;
    775796
    776797        if ( !rootcli || !path || !targetcli ) {
     
    803824        }
    804825
    805         if (cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes)) {
     826        status = cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes);
     827        if (NT_STATUS_IS_OK(status)) {
    806828                /* This is an ordinary path, just return it. */
    807829                *targetcli = rootcli;
     
    815837        /* Special case where client asked for a path that does not exist */
    816838
    817         if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
     839        if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND,
     840                                status)) {
    818841                *targetcli = rootcli;
    819842                *pp_targetpath = talloc_strdup(ctx, path);
     
    826849        /* We got an error, check for DFS referral. */
    827850
    828         if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED)) {
     851        if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED,
     852                                 status)) {
    829853                return false;
    830854        }
     
    845869        }
    846870
    847         if (!cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
    848                         &num_refs, &consumed) || !num_refs) {
     871        status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
     872                                      &num_refs, &consumed);
     873        if (!NT_STATUS_IS_OK(status) || !num_refs) {
    849874                return false;
    850875        }
     
    855880                return false;
    856881        }
    857         split_dfs_path(ctx, refs[0].dfspath, &server, &share, &extrapath );
    858 
    859         if (!server || !share) {
     882        if (!split_dfs_path(ctx, refs[0].dfspath, &server, &share,
     883                            &extrapath)) {
    860884                return false;
    861885        }
     
    9971021                                const char *domain)
    9981022{
    999         CLIENT_DFS_REFERRAL *refs = NULL;
     1023        struct client_dfs_referral *refs = NULL;
    10001024        size_t num_refs = 0;
    10011025        size_t consumed = 0;
     
    10041028        uint16 cnum;
    10051029        char *newextrapath = NULL;
     1030        NTSTATUS status;
    10061031
    10071032        if (!cli || !sharename) {
     
    10311056
    10321057        if (force_encrypt) {
    1033                 NTSTATUS status = cli_cm_force_encryption(cli,
     1058                status = cli_cm_force_encryption(cli,
    10341059                                        username,
    10351060                                        password,
     
    10411066        }
    10421067
    1043         res = cli_dfs_get_referral(ctx, cli, fullpath, &refs, &num_refs, &consumed);
    1044 
    1045         if (!cli_tdis(cli)) {
     1068        status = cli_dfs_get_referral(ctx, cli, fullpath, &refs,
     1069                                      &num_refs, &consumed);
     1070        res = NT_STATUS_IS_OK(status);
     1071
     1072        status = cli_tdis(cli);
     1073        if (!NT_STATUS_IS_OK(status)) {
    10461074                return false;
    10471075        }
     
    10571085        }
    10581086
    1059         split_dfs_path(ctx, refs[0].dfspath, pp_newserver,
    1060                         pp_newshare, &newextrapath );
    1061 
    1062         if ((*pp_newserver == NULL) || (*pp_newshare == NULL)) {
     1087        if (!split_dfs_path(ctx, refs[0].dfspath, pp_newserver,
     1088                            pp_newshare, &newextrapath)) {
    10631089                return false;
    10641090        }
Note: See TracChangeset for help on using the changeset viewer.