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/librpc/rpc/binding.c

    r414 r740  
    2424
    2525#include "includes.h"
     26#include "../../lib/util/util_net.h"
    2627#include "librpc/gen_ndr/ndr_epmapper.h"
    2728#include "librpc/gen_ndr/ndr_misc.h"
    2829#include "librpc/rpc/dcerpc.h"
     30#include "rpc_common.h"
     31
    2932#undef strcasecmp
     33#undef strncasecmp
    3034
    3135#define MAX_PROTSEQ             10
     
    8690        {"smb2", DCERPC_SMB2},
    8791        {"hdrsign", DCERPC_HEADER_SIGNING},
    88         {"ndr64", DCERPC_NDR64}
     92        {"ndr64", DCERPC_NDR64},
     93        {"localaddress", DCERPC_LOCALADDRESS}
    8994};
    9095
     
    114119                        } else { /* IPX */
    115120                                return talloc_asprintf(mem_ctx, "IPX:%s",
    116                                                 data_blob_hex_string(mem_ctx, &epm_floor->rhs.uuid.unknown));
     121                                                data_blob_hex_string_upper(mem_ctx, &epm_floor->rhs.uuid.unknown));
    117122                        }
    118123
     
    220225        for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
    221226                if (b->flags & ncacn_options[i].flag) {
    222                         s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
     227                        if (ncacn_options[i].flag == DCERPC_LOCALADDRESS && b->localaddress) {
     228                                s = talloc_asprintf_append_buffer(s, ",%s=%s", ncacn_options[i].name,
     229                                                                  b->localaddress);
     230                        } else {
     231                                s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
     232                        }
    223233                        if (!s) return NULL;
    224234                }
     
    240250        int i, j, comma_count;
    241251
    242         b = talloc(mem_ctx, struct dcerpc_binding);
     252        b = talloc_zero(mem_ctx, struct dcerpc_binding);
    243253        if (!b) {
    244254                return NT_STATUS_NO_MEMORY;
     
    313323        b->assoc_group_id = 0;
    314324        b->endpoint = NULL;
     325        b->localaddress = NULL;
    315326
    316327        if (!options) {
     
    339350        for (i=0;b->options[i];i++) {
    340351                for (j=0;j<ARRAY_SIZE(ncacn_options);j++) {
    341                         if (strcasecmp(ncacn_options[j].name, b->options[i]) == 0) {
     352                        size_t opt_len = strlen(ncacn_options[j].name);
     353                        if (strncasecmp(ncacn_options[j].name, b->options[i], opt_len) == 0) {
    342354                                int k;
     355                                char c = b->options[i][opt_len];
     356
     357                                if (ncacn_options[j].flag == DCERPC_LOCALADDRESS && c == '=') {
     358                                        b->localaddress = talloc_strdup(b, &b->options[i][opt_len+1]);
     359                                } else if (c != 0) {
     360                                        continue;
     361                                }
     362
    343363                                b->flags |= ncacn_options[j].flag;
    344364                                for (k=i;b->options[k];k++) {
     
    376396        uint16_t if_version=0;
    377397
    378         ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx, NULL);
     398        ndr = ndr_pull_init_blob(&epm_floor->lhs.lhs_data, mem_ctx);
    379399        if (ndr == NULL) {
    380400                talloc_free(mem_ctx);
     
    404424static DATA_BLOB dcerpc_floor_pack_lhs_data(TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax)
    405425{
    406         struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx, NULL);
     426        DATA_BLOB blob;
     427        struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx);
    407428
    408429        ndr->flags |= LIBNDR_FLAG_NOALIGN;
     
    411432        ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version);
    412433
    413         return ndr_push_blob(ndr);
     434        blob = ndr_push_blob(ndr);
     435        talloc_steal(mem_ctx, blob.data);
     436        talloc_free(ndr);
     437        return blob;
     438}
     439
     440static bool dcerpc_floor_pack_rhs_if_version_data(
     441        TALLOC_CTX *mem_ctx, const struct ndr_syntax_id *syntax,
     442        DATA_BLOB *pblob)
     443{
     444        DATA_BLOB blob;
     445        struct ndr_push *ndr = ndr_push_init_ctx(mem_ctx);
     446        enum ndr_err_code ndr_err;
     447
     448        if (ndr == NULL) {
     449                return false;
     450        }
     451
     452        ndr->flags |= LIBNDR_FLAG_NOALIGN;
     453
     454        ndr_err = ndr_push_uint16(ndr, NDR_SCALARS, syntax->if_version >> 16);
     455        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     456                return false;
     457        }
     458
     459        blob = ndr_push_blob(ndr);
     460        talloc_steal(mem_ctx, blob.data);
     461        talloc_free(ndr);
     462        *pblob = blob;
     463        return true;
    414464}
    415465
     
    608658}
    609659
    610 _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 
    611                                    struct epm_tower *tower,
    612                                    struct dcerpc_binding **b_out)
     660_PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
     661                                            struct epm_tower *tower,
     662                                            struct dcerpc_binding **b_out)
    613663{
    614664        NTSTATUS status;
    615665        struct dcerpc_binding *binding;
    616666
    617         binding = talloc(mem_ctx, struct dcerpc_binding);
     667        /*
     668         * A tower needs to have at least 4 floors to carry useful
     669         * information. Floor 3 is the transport identifier which defines
     670         * how many floors are required at least.
     671         */
     672        if (tower->num_floors < 4) {
     673                return NT_STATUS_INVALID_PARAMETER;
     674        }
     675
     676        binding = talloc_zero(mem_ctx, struct dcerpc_binding);
    618677        NT_STATUS_HAVE_NO_MEMORY(binding);
    619678
     
    631690        }
    632691
    633         if (tower->num_floors < 1) {
    634                 return NT_STATUS_OK;
    635         }
    636 
    637692        /* Set object uuid */
    638693        status = dcerpc_floor_get_lhs_data(&tower->floors[0], &binding->object);
    639694
    640695        if (!NT_STATUS_IS_OK(status)) {
    641                 DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status)));     
     696                DEBUG(1, ("Error pulling object uuid and version: %s", nt_errstr(status)));
    642697                return status;
    643698        }
     
    649704        /* Set endpoint */
    650705        if (tower->num_floors >= 4) {
    651                 binding->endpoint = dcerpc_floor_get_rhs_data(mem_ctx, &tower->floors[3]);
     706                binding->endpoint = dcerpc_floor_get_rhs_data(binding, &tower->floors[3]);
    652707        } else {
    653708                binding->endpoint = NULL;
     
    656711        /* Set network address */
    657712        if (tower->num_floors >= 5) {
    658                 binding->host = dcerpc_floor_get_rhs_data(mem_ctx, &tower->floors[4]);
     713                binding->host = dcerpc_floor_get_rhs_data(binding, &tower->floors[4]);
    659714                NT_STATUS_HAVE_NO_MEMORY(binding->host);
    660715                binding->target_hostname = binding->host;
     
    662717        *b_out = binding;
    663718        return NT_STATUS_OK;
     719}
     720
     721_PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
     722                                                   const struct dcerpc_binding *b)
     723{
     724        struct dcerpc_binding *n;
     725        uint32_t count;
     726
     727        n = talloc_zero(mem_ctx, struct dcerpc_binding);
     728        if (n == NULL) {
     729                return NULL;
     730        }
     731
     732        n->transport = b->transport;
     733        n->object = b->object;
     734        n->flags = b->flags;
     735        n->assoc_group_id = b->assoc_group_id;
     736
     737        if (b->host != NULL) {
     738                n->host = talloc_strdup(n, b->host);
     739                if (n->host == NULL) {
     740                        talloc_free(n);
     741                        return NULL;
     742                }
     743        }
     744
     745        if (b->target_hostname != NULL) {
     746                n->target_hostname = talloc_strdup(n, b->target_hostname);
     747                if (n->target_hostname == NULL) {
     748                        talloc_free(n);
     749                        return NULL;
     750                }
     751        }
     752
     753        if (b->target_principal != NULL) {
     754                n->target_principal = talloc_strdup(n, b->target_principal);
     755                if (n->target_principal == NULL) {
     756                        talloc_free(n);
     757                        return NULL;
     758                }
     759        }
     760
     761        if (b->localaddress != NULL) {
     762                n->localaddress = talloc_strdup(n, b->localaddress);
     763                if (n->localaddress == NULL) {
     764                        talloc_free(n);
     765                        return NULL;
     766                }
     767        }
     768
     769        if (b->endpoint != NULL) {
     770                n->endpoint = talloc_strdup(n, b->endpoint);
     771                if (n->endpoint == NULL) {
     772                        talloc_free(n);
     773                        return NULL;
     774                }
     775        }
     776
     777        for (count = 0; b->options && b->options[count]; count++);
     778
     779        if (count > 0) {
     780                uint32_t i;
     781
     782                n->options = talloc_array(n, const char *, count + 1);
     783                if (n->options == NULL) {
     784                        talloc_free(n);
     785                        return NULL;
     786                }
     787
     788                for (i = 0; i < count; i++) {
     789                        n->options[i] = talloc_strdup(n->options, b->options[i]);
     790                        if (n->options[i] == NULL) {
     791                                talloc_free(n);
     792                                return NULL;
     793                        }
     794                }
     795                n->options[count] = NULL;
     796        }
     797
     798        return n;
    664799}
    665800
     
    692827        tower->floors[0].lhs.protocol = EPM_PROTOCOL_UUID;
    693828
    694         tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(mem_ctx, &binding->object);
    695 
    696         tower->floors[0].rhs.uuid.unknown = data_blob_talloc_zero(mem_ctx, 2);
     829        tower->floors[0].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors, &binding->object);
     830
     831        if (!dcerpc_floor_pack_rhs_if_version_data(
     832                    tower->floors, &binding->object,
     833                    &tower->floors[0].rhs.uuid.unknown)) {
     834                return NT_STATUS_NO_MEMORY;
     835        }
    697836
    698837        /* Floor 1 */
    699838        tower->floors[1].lhs.protocol = EPM_PROTOCOL_UUID;
    700839
    701         tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(mem_ctx,
     840        tower->floors[1].lhs.lhs_data = dcerpc_floor_pack_lhs_data(tower->floors,
    702841                                                                &ndr_transfer_syntax);
    703842
    704         tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(mem_ctx, 2);
     843        tower->floors[1].rhs.uuid.unknown = data_blob_talloc_zero(tower->floors, 2);
    705844
    706845        /* Floor 2 to num_protocols */
    707846        for (i = 0; i < num_protocols; i++) {
    708847                tower->floors[2 + i].lhs.protocol = protseq[i];
    709                 tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(mem_ctx, NULL, 0);
     848                tower->floors[2 + i].lhs.lhs_data = data_blob_talloc(tower->floors, NULL, 0);
    710849                ZERO_STRUCT(tower->floors[2 + i].rhs);
    711                 dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[2 + i], "");
     850                dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[2 + i], "");
    712851        }
    713852
    714853        /* The 4th floor contains the endpoint */
    715854        if (num_protocols >= 2 && binding->endpoint) {
    716                 status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[3], binding->endpoint);
     855                status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[3], binding->endpoint);
    717856                if (NT_STATUS_IS_ERR(status)) {
    718857                        return status;
     
    722861        /* The 5th contains the network address */
    723862        if (num_protocols >= 3 && binding->host) {
    724                 if (is_ipaddress(binding->host)) {
    725                         status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[4],
     863                if (is_ipaddress(binding->host) ||
     864                    (binding->host[0] == '\\' && binding->host[1] == '\\')) {
     865                        status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4],
    726866                                                           binding->host);
    727867                } else {
     
    731871                           a wildcard all-zeros IP for the server to
    732872                           fill in */
    733                         status = dcerpc_floor_set_rhs_data(mem_ctx, &tower->floors[4],
     873                        status = dcerpc_floor_set_rhs_data(tower->floors, &tower->floors[4],
    734874                                                           "0.0.0.0");
    735875                }
Note: See TracChangeset for help on using the changeset viewer.