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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/librpc/tests/binding_string.c

    r740 r988  
    2525#include "librpc/rpc/dcerpc_proto.h"
    2626#include "torture/torture.h"
     27#include "torture/local/proto.h"
    2728#include "lib/util/util_net.h"
    2829
     
    3233        const char *binding = test_data;
    3334        struct dcerpc_binding *b, *b2;
    34         const char *s, *s2;
     35        char *s, *s2, *p;
    3536        struct epm_tower tower;
    3637        TALLOC_CTX *mem_ctx = tctx;
     38        const char *host;
     39        struct GUID object;
    3740
    3841        /* Parse */
     
    4043                "Error parsing binding string");
    4144
     45        object = dcerpc_binding_get_object(b);
     46
    4247        s = dcerpc_binding_string(mem_ctx, b);
    4348        torture_assert(tctx, s != NULL, "Error converting binding back to string");
     
    5560                            "Error generating binding from tower for original binding");
    5661
    57         /* Compare to a stripped down version of the binding string because
    58          * the protocol tower doesn't contain the extra option data */
    59         b->options = NULL;
    60 
    61         b->flags = 0;
    62        
     62        /* The tower doesn't contain the object */
     63        torture_assert_ntstatus_ok(tctx, dcerpc_binding_set_object(b2, object),
     64                            "set object on tower binding");
     65
    6366        s = dcerpc_binding_string(mem_ctx, b);
    6467        torture_assert(tctx, s != NULL, "Error converting binding back to string for (stripped down)");
    6568
     69        /*
     70         * Compare to a stripped down version of the binding string because
     71         * the protocol tower doesn't contain the extra option data
     72         *
     73         * We remove all options except of the endpoint.
     74         */
     75        p = strchr(s, '[');
     76        if (p != NULL) {
     77                char *p2;
     78
     79                p2 = strchr(p + 1, ',');
     80                if (p2 != NULL) {
     81                        /*
     82                         * We only look at the first option,
     83                         * which might be the endpoint.
     84                         */
     85                        p2[0] = ']';
     86                        p2[1] = '\0';
     87                }
     88
     89                p2 = strchr(p + 1, '=');
     90                if (p2 != NULL) {
     91                        /*
     92                         * It's not the endpoint, so remove the
     93                         * whole option section.
     94                         */
     95                        *p = '\0';
     96                }
     97        }
     98
    6699        s2 = dcerpc_binding_string(mem_ctx, b2);
    67100        torture_assert(tctx, s != NULL, "Error converting binding back to string");
    68101
    69         if (is_ipaddress(b->host))
     102        host = dcerpc_binding_get_string_option(b, "host");
     103        if (host && is_ipaddress_v4(host)) {
    70104                torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
     105        }
    71106
    72107        return true;
     
    82117        "ncacn_ip_tcp:127.0.0.1[20]",
    83118        "ncacn_ip_tcp:127.0.0.1[20,sign]",
    84         "ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
     119        "ncacn_ip_tcp:127.0.0.1[20,sign,Security=Foobar]",
    85120        "ncacn_http:127.0.0.1",
    86121        "ncacn_http:127.0.0.1[78]",
     
    96131        "ncalrpc:[IDENTIFIER]",
    97132        "ncacn_unix_stream:[/tmp/epmapper,sign]",
     133        "ncacn_ip_tcp:127.0.0.1[75,target_hostname=port75.example.com,target_principal=host/port75.example.com]",
     134        "ncacn_ip_tcp:127.0.0.1[75,connect,target_hostname=port75.example.com,target_principal=host/port75.example.com,assoc_group_id=0x01234567]",
     135        "ncacn_ip_tcp:::",
     136        "ncacn_ip_tcp:::[75]",
     137        "ncacn_ip_tcp:FD00::5357:5F00",
     138        "ncacn_ip_tcp:FD00::5357:5F00[75]",
     139        "ncacn_ip_tcp:FD00::5357:5F00[,target_hostname=port75.example.com]",
     140        "ncacn_ip_tcp:FD00::5357:5F00[75,target_hostname=port75.example.com]",
     141        "ncacn_ip_tcp:fe80::5357:5F00%75",
     142        "ncacn_ip_tcp:fe80::5357:5F00%75[75]",
     143        "ncacn_ip_tcp:fe80::5357:5F00%75[,target_hostname=port75.example.com]",
     144        "ncacn_ip_tcp:fe80::5357:5F00%75[75,target_hostname=port75.example.com]",
    98145};
    99146
     
    102149        struct dcerpc_binding *b;
    103150        struct GUID uuid;
     151        struct GUID object;
     152        struct ndr_syntax_id abstract;
     153        enum dcerpc_transport_t transport;
     154        const char *endpoint;
     155        uint32_t flags;
    104156
    105157        torture_assert_ntstatus_ok(tctx,
     
    108160
    109161        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER", &b), "parse");
    110         torture_assert(tctx, b->transport == NCACN_NP, "ncacn_np expected");
     162        transport = dcerpc_binding_get_transport(b);
     163        torture_assert(tctx, transport == NCACN_NP, "ncacn_np expected");
    111164        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER", &b), "parse");
    112         torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
     165        transport = dcerpc_binding_get_transport(b);
     166        torture_assert(tctx, transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
    113167        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[rpcecho]", &b), "parse");
    114         torture_assert_str_equal(tctx, b->endpoint, "rpcecho", "endpoint");
     168        endpoint = dcerpc_binding_get_string_option(b, "endpoint");
     169        torture_assert_str_equal(tctx, endpoint, "rpcecho", "endpoint");
    115170        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[/pipe/rpcecho]", &b), "parse");
    116171        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[/pipe/rpcecho,sign,seal]", &b), "parse");
    117         torture_assert(tctx, b->flags == DCERPC_SIGN+DCERPC_SEAL, "sign+seal flags");
    118         torture_assert_str_equal(tctx, b->endpoint, "/pipe/rpcecho", "endpoint");
     172        flags = dcerpc_binding_get_flags(b);
     173        torture_assert(tctx, flags == DCERPC_SIGN+DCERPC_SEAL, "sign+seal flags");
     174        endpoint = dcerpc_binding_get_string_option(b, "endpoint");
     175        torture_assert_str_equal(tctx, endpoint, "/pipe/rpcecho", "endpoint");
    119176        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[,sign]", &b), "parse");
    120177        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign]", &b), "parse");
    121         torture_assert(tctx, b->endpoint == NULL, "endpoint");
    122         torture_assert(tctx, b->flags == DCERPC_SIGN, "sign flag");
     178        endpoint = dcerpc_binding_get_string_option(b, "endpoint");
     179        torture_assert(tctx, endpoint == NULL, "endpoint");
     180        flags = dcerpc_binding_get_flags(b);
     181        torture_assert(tctx, flags == DCERPC_SIGN, "sign flag");
    123182        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncalrpc:", &b), "parse");
    124         torture_assert(tctx, b->transport == NCALRPC, "ncalrpc expected");
     183        transport = dcerpc_binding_get_transport(b);
     184        torture_assert(tctx, transport == NCALRPC, "ncalrpc expected");
    125185        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
    126186                "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:$SERVER", &b), "parse");
    127         torture_assert(tctx, GUID_equal(&b->object.uuid, &uuid), "object uuid");
    128         torture_assert_int_equal(tctx, b->object.if_version, 0, "object version");
     187        object = dcerpc_binding_get_object(b);
     188        abstract = dcerpc_binding_get_abstract_syntax(b);
     189        torture_assert(tctx, GUID_equal(&object, &uuid), "object uuid");
     190        torture_assert(tctx, ndr_syntax_id_equal(&abstract, &ndr_syntax_id_null),
     191                       "null abstract syntax");
    129192        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
    130193                "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:$SERVER", &b), "parse");
    131194        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]", &b), "parse");
    132         torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
    133         torture_assert(tctx, b->flags == (DCERPC_SIGN | DCERPC_LOCALADDRESS), "sign flag");
    134         torture_assert_str_equal(tctx, b->localaddress, "192.168.1.1", "localaddress");
     195        transport = dcerpc_binding_get_transport(b);
     196        torture_assert(tctx, transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
     197        flags = dcerpc_binding_get_flags(b);
     198        torture_assert(tctx, flags == DCERPC_SIGN, "sign flag");
     199        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "localaddress"),
     200                                 "192.168.1.1", "localaddress");
    135201        torture_assert_str_equal(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]",
    136202                                 dcerpc_binding_string(tctx, b), "back to string");
     203        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "host"),
     204                                 "$SERVER", "host");
     205        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "target_hostname"),
     206                                 "$SERVER", "target_hostname");
     207
     208        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
     209                "ncacn_ip_tcp:$HOST[,target_hostname=$HOSTNAME,target_principal=$PRINCIPAL]",
     210                &b), "parse");
     211        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "host"),
     212                                 "$HOST", "host");
     213        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "target_hostname"),
     214                                 "$HOSTNAME", "target_hostname");
     215        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "target_principal"),
     216                                 "$PRINCIPAL", "target_principal");
     217        torture_assert_str_equal(tctx,
     218                                 dcerpc_binding_string(tctx, b),
     219                "ncacn_ip_tcp:$HOST[,target_hostname=$HOSTNAME,target_principal=$PRINCIPAL]",
     220                                 "back to string");
     221
     222        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
     223                "ncacn_ip_tcp:$HOST[,connect,target_hostname=$HOSTNAME,target_principal=$PRINCIPAL,assoc_group_id=0x01234567]",
     224                &b), "parse");
     225        flags = dcerpc_binding_get_flags(b);
     226        torture_assert(tctx, flags == DCERPC_CONNECT, "connect flag");
     227        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "host"),
     228                                 "$HOST", "host");
     229        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "target_hostname"),
     230                                 "$HOSTNAME", "target_hostname");
     231        torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "target_principal"),
     232                                 "$PRINCIPAL", "target_principal");
     233        torture_assert_int_equal(tctx, dcerpc_binding_get_assoc_group_id(b), 0x01234567,
     234                                 "assoc_group_id");
     235        torture_assert_str_equal(tctx,
     236                                 dcerpc_binding_string(tctx, b),
     237                "ncacn_ip_tcp:$HOST[,connect,target_hostname=$HOSTNAME,target_principal=$PRINCIPAL,assoc_group_id=0x01234567]",
     238                                 "back to string");
    137239
    138240        return true;
    139241}
    140242
    141 static bool test_no_transport(struct torture_context *tctx)
     243static bool test_no_transport(struct torture_context *tctx, const void *test_data)
    142244{
    143         const char *binding = "somehost";
     245        const char *binding = test_data;
    144246        struct dcerpc_binding *b;
     247        enum dcerpc_transport_t transport;
    145248        const char *s;
    146249
     
    149252                "Error parsing binding string");
    150253
    151         torture_assert(tctx, b->transport == NCA_UNKNOWN, "invalid transport");
     254        transport = dcerpc_binding_get_transport(b);
     255        torture_assert(tctx, transport == NCA_UNKNOWN, "invalid transport");
    152256
    153257        s = dcerpc_binding_string(tctx, b);
     
    159263        return true;
    160264}
     265
     266static const char *test_no_strings[] = {
     267        "port75.example.com",
     268        "port75.example.com[75]",
     269        "127.0.0.1",
     270        "127.0.0.1[75]",
     271        "127.0.0.1[,target_hostname=port75.example.com]",
     272        "127.0.0.1[75,target_hostname=port75.example.com]",
     273        "::",
     274        "::[75]",
     275        "::[,target_hostname=port75.example.com]",
     276        "::[75,target_hostname=port75.example.com]",
     277        "FD00::5357:5F00",
     278        "FD00::5357:5F00[75]",
     279        "FD00::5357:5F00[,target_hostname=port75.example.com]",
     280        "FD00::5357:5F00[75,target_hostname=port75.example.com]",
     281        "fe80::5357:5F00%75",
     282        "fe80::5357:5F00%75[75]",
     283        "fe80::5357:5F00%75[,target_hostname=port75.example.com]",
     284        "fe80::5357:5F00%75[75,target_hostname=port75.example.com]",
     285};
    161286
    162287struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
     
    171296        }
    172297
    173         torture_suite_add_simple_test(suite, "no transport",test_no_transport);
     298        for (i = 0; i < ARRAY_SIZE(test_no_strings); i++) {
     299                torture_suite_add_simple_tcase_const(suite, test_no_strings[i],
     300                                                     test_no_transport,
     301                                                     test_no_strings[i]);
     302        }
    174303
    175304        torture_suite_add_simple_test(suite, "parsing results",
Note: See TracChangeset for help on using the changeset viewer.