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:
3 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/librpc/rpc/binding.c

    r414 r745  
    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                }
  • trunk/server/librpc/rpc/dcerpc_error.c

    r596 r745  
    2222#include "includes.h"
    2323#include "librpc/rpc/dcerpc.h"
     24#include "rpc_common.h"
    2425
    2526struct dcerpc_fault_table {
     
    3031static const struct dcerpc_fault_table dcerpc_faults[] =
    3132{
    32         { "DCERPC_FAULT_OP_RNG_ERROR",          DCERPC_FAULT_OP_RNG_ERROR },
    33         { "DCERPC_FAULT_UNK_IF",                DCERPC_FAULT_UNK_IF },
    34         { "DCERPC_FAULT_NDR",                   DCERPC_FAULT_NDR },
    35         { "DCERPC_FAULT_INVALID_TAG",           DCERPC_FAULT_INVALID_TAG },
    36         { "DCERPC_FAULT_CONTEXT_MISMATCH",      DCERPC_FAULT_CONTEXT_MISMATCH },
    37         { "DCERPC_FAULT_OTHER",                 DCERPC_FAULT_OTHER },
    38         { "DCERPC_FAULT_ACCESS_DENIED",         DCERPC_FAULT_ACCESS_DENIED },
    39         { "DCERPC_FAULT_SEC_PKG_ERROR",         DCERPC_FAULT_SEC_PKG_ERROR },
    40 
    41         { NULL,                                 0}
     33#define _FAULT_STR(x) { #x , x }
     34        _FAULT_STR(DCERPC_NCA_S_COMM_FAILURE),
     35        _FAULT_STR(DCERPC_NCA_S_OP_RNG_ERROR),
     36        _FAULT_STR(DCERPC_NCA_S_UNKNOWN_IF),
     37        _FAULT_STR(DCERPC_NCA_S_WRONG_BOOT_TIME),
     38        _FAULT_STR(DCERPC_NCA_S_YOU_CRASHED),
     39        _FAULT_STR(DCERPC_NCA_S_PROTO_ERROR),
     40        _FAULT_STR(DCERPC_NCA_S_OUT_ARGS_TOO_BIG),
     41        _FAULT_STR(DCERPC_NCA_S_SERVER_TOO_BUSY),
     42        _FAULT_STR(DCERPC_NCA_S_FAULT_STRING_TOO_LARGE),
     43        _FAULT_STR(DCERPC_NCA_S_UNSUPPORTED_TYPE),
     44        _FAULT_STR(DCERPC_NCA_S_FAULT_INT_DIV_BY_ZERO),
     45        _FAULT_STR(DCERPC_NCA_S_FAULT_ADDR_ERROR),
     46        _FAULT_STR(DCERPC_NCA_S_FAULT_FP_DIV_BY_ZERO),
     47        _FAULT_STR(DCERPC_NCA_S_FAULT_FP_UNDERFLOW),
     48        _FAULT_STR(DCERPC_NCA_S_FAULT_FP_OVERRFLOW),
     49        _FAULT_STR(DCERPC_NCA_S_FAULT_INVALID_TAG),
     50        _FAULT_STR(DCERPC_NCA_S_FAULT_INVALID_BOUND),
     51        _FAULT_STR(DCERPC_NCA_S_FAULT_RPC_VERSION_MISMATCH),
     52        _FAULT_STR(DCERPC_NCA_S_FAULT_UNSPEC_REJECT),
     53        _FAULT_STR(DCERPC_NCA_S_FAULT_BAD_ACTID),
     54        _FAULT_STR(DCERPC_NCA_S_FAULT_WHO_ARE_YOU_FAILED),
     55        _FAULT_STR(DCERPC_NCA_S_FAULT_MANAGER_NOT_ENTERED),
     56        _FAULT_STR(DCERPC_NCA_S_FAULT_CANCEL),
     57        _FAULT_STR(DCERPC_NCA_S_FAULT_ILL_INST),
     58        _FAULT_STR(DCERPC_NCA_S_FAULT_FP_ERROR),
     59        _FAULT_STR(DCERPC_NCA_S_FAULT_INT_OVERFLOW),
     60        _FAULT_STR(DCERPC_NCA_S_UNUSED_1C000011),
     61        _FAULT_STR(DCERPC_NCA_S_FAULT_UNSPEC),
     62        _FAULT_STR(DCERPC_NCA_S_FAULT_REMOTE_COMM_FAILURE),
     63        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_EMPTY),
     64        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_CLOSED),
     65        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_ORDER),
     66        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_DISCIPLINE),
     67        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_COMM_ERROR),
     68        _FAULT_STR(DCERPC_NCA_S_FAULT_PIPE_MEMORY),
     69        _FAULT_STR(DCERPC_NCA_S_FAULT_CONTEXT_MISMATCH),
     70        _FAULT_STR(DCERPC_NCA_S_FAULT_REMOTE_NO_MEMORY),
     71        _FAULT_STR(DCERPC_NCA_S_INVALID_PRES_CONTEXT_ID),
     72        _FAULT_STR(DCERPC_NCA_S_UNSUPPORTED_AUTHN_LEVEL),
     73        _FAULT_STR(DCERPC_NCA_S_UNUSED_1C00001E),
     74        _FAULT_STR(DCERPC_NCA_S_INVALID_CHECKSUM),
     75        _FAULT_STR(DCERPC_NCA_S_INVALID_CRC),
     76        _FAULT_STR(DCERPC_NCA_S_FAULT_USER_DEFINED),
     77        _FAULT_STR(DCERPC_NCA_S_FAULT_TX_OPEN_FAILED),
     78        _FAULT_STR(DCERPC_NCA_S_FAULT_CODESET_CONV_ERROR),
     79        _FAULT_STR(DCERPC_NCA_S_FAULT_OBJECT_NOT_FOUND),
     80        _FAULT_STR(DCERPC_NCA_S_FAULT_NO_CLIENT_STUB),
     81        { NULL, 0 }
     82#undef _FAULT_STR
    4283};
    4384
     
    4586{
    4687        int idx = 0;
     88        WERROR werr = W_ERROR(fault_code);
    4789
    4890        while (dcerpc_faults[idx].errstr != NULL) {
     
    5395        }
    5496
    55         return talloc_asprintf(mem_ctx, "DCERPC fault 0x%08x", fault_code);
     97        return win_errstr(werr);
    5698}
     99
     100_PUBLIC_ NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code)
     101{
     102        /* TODO: add more mappings */
     103        switch (fault_code) {
     104        case DCERPC_FAULT_OP_RNG_ERROR:
     105                return NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE;
     106        case DCERPC_FAULT_UNK_IF:
     107                return NT_STATUS_RPC_UNKNOWN_IF;
     108        case DCERPC_FAULT_NDR:
     109                return NT_STATUS_RPC_BAD_STUB_DATA;
     110        case DCERPC_FAULT_INVALID_TAG:
     111                return NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE;
     112        case DCERPC_FAULT_CONTEXT_MISMATCH:
     113                return NT_STATUS_RPC_SS_CONTEXT_MISMATCH;
     114        case DCERPC_FAULT_OTHER:
     115                return NT_STATUS_RPC_CALL_FAILED;
     116        case DCERPC_FAULT_ACCESS_DENIED:
     117                return NT_STATUS_ACCESS_DENIED;
     118        case DCERPC_FAULT_SEC_PKG_ERROR:
     119                return NT_STATUS_RPC_SEC_PKG_ERROR;
     120        }
     121
     122        return NT_STATUS_RPC_PROTOCOL_ERROR;
     123}
     124
Note: See TracChangeset for help on using the changeset viewer.