LCOV - code coverage report
Current view: top level - source4/torture/rpc - epmapper.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 266 285 93.3 %
Date: 2021-09-23 10:06:22 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for epmapper rpc operations
       4             : 
       5             :    Copyright (C) Andrew Tridgell 2003
       6             :    
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             :    
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "librpc/gen_ndr/ndr_epmapper_c.h"
      23             : #include "librpc/ndr/ndr_table.h"
      24             : #include "librpc/rpc/dcerpc_proto.h"
      25             : #include "torture/rpc/torture_rpc.h"
      26             : #include "lib/util/util_net.h"
      27             : #include "librpc/rpc/rpc_common.h"
      28             : 
      29             : /*
      30             :   display any protocol tower
      31             :  */
      32        7529 : static void display_tower(struct torture_context *tctx, struct epm_tower *twr)
      33             : {
      34             :         int i;
      35             : 
      36       45082 :         for (i = 0; i < twr->num_floors; i++) {
      37       37553 :                 torture_comment(tctx,
      38             :                                 " %s",
      39       37553 :                                 epm_floor_string(tctx, &twr->floors[i]));
      40             :         }
      41        7529 :         torture_comment(tctx, "\n");
      42        7529 : }
      43             : 
      44           5 : static bool test_Insert(struct torture_context *tctx,
      45             :                         struct dcerpc_binding_handle *h,
      46             :                         struct ndr_syntax_id object,
      47             :                         const char *annotation,
      48             :                         const struct dcerpc_binding *b)
      49             : {
      50             :         struct epm_Insert r;
      51             :         NTSTATUS status;
      52             : 
      53           5 :         r.in.num_ents = 1;
      54           5 :         r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
      55             : 
      56           5 :         if (torture_setting_bool(tctx, "samba4", false)) {
      57           3 :                 torture_skip(tctx, "Skip Insert test against Samba4");
      58             :         }
      59             : 
      60             :         /* FIXME zero */
      61           2 :         ZERO_STRUCT(r.in.entries[0].object);
      62           2 :         r.in.entries[0].annotation = annotation;
      63             : 
      64           2 :         r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
      65             : 
      66           2 :         status = dcerpc_binding_build_tower(tctx,
      67             :                                             b,
      68           2 :                                             &r.in.entries[0].tower->tower);
      69             : 
      70           2 :         torture_assert_ntstatus_ok(tctx,
      71             :                                    status,
      72             :                                    "Unable to build tower from binding struct");
      73           2 :         r.in.replace = 0;
      74             : 
      75             :         /* shoot! */
      76           2 :         status = dcerpc_epm_Insert_r(h, tctx, &r);
      77             : 
      78           2 :         if (NT_STATUS_IS_ERR(status)) {
      79           0 :                 torture_comment(tctx,
      80             :                                 "epm_Insert failed - %s\n",
      81             :                                 nt_errstr(status));
      82           0 :                 return false;
      83             :         }
      84             : 
      85           2 :         if (r.out.result != EPMAPPER_STATUS_OK) {
      86           0 :                 torture_comment(tctx,
      87             :                                 "epm_Insert failed - internal error: 0x%.4x\n",
      88             :                                 r.out.result);
      89           0 :                 return false;
      90             :         }
      91             : 
      92           2 :         return true;
      93             : }
      94             : 
      95           4 : static bool test_Delete(struct torture_context *tctx,
      96             :                         struct dcerpc_binding_handle *h,
      97             :                         const char *annotation,
      98             :                         const struct dcerpc_binding *b)
      99             : {
     100             :         NTSTATUS status;
     101             :         struct epm_Delete r;
     102             : 
     103           4 :         r.in.num_ents = 1;
     104           4 :         r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
     105             : 
     106           4 :         ZERO_STRUCT(r.in.entries[0].object);
     107           4 :         r.in.entries[0].annotation = annotation;
     108             : 
     109           4 :         r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
     110             : 
     111           4 :         status = dcerpc_binding_build_tower(tctx,
     112             :                                             b,
     113           4 :                                             &r.in.entries[0].tower->tower);
     114             : 
     115           4 :         torture_assert_ntstatus_ok(tctx,
     116             :                                    status,
     117             :                                    "Unable to build tower from binding struct");
     118           4 :         r.in.num_ents = 1;
     119             : 
     120           4 :         status = dcerpc_epm_Delete_r(h, tctx, &r);
     121           4 :         if (NT_STATUS_IS_ERR(status)) {
     122           0 :                 torture_comment(tctx,
     123             :                                 "epm_Delete failed - %s\n",
     124             :                                 nt_errstr(status));
     125           0 :                 return false;
     126             :         }
     127             : 
     128           4 :         if (r.out.result != EPMAPPER_STATUS_OK) {
     129           0 :                 torture_comment(tctx,
     130             :                                 "epm_Delete failed - internal error: 0x%.4x\n",
     131             :                                 r.out.result);
     132           0 :                 return false;
     133             :         }
     134             : 
     135           4 :         return true;
     136             : }
     137             : 
     138           5 : static bool test_Map_tcpip(struct torture_context *tctx,
     139             :                            struct dcerpc_binding_handle *h,
     140             :                            struct ndr_syntax_id map_syntax)
     141             : {
     142             :         struct epm_Map r;
     143             :         struct GUID uuid;
     144             :         struct policy_handle entry_handle;
     145             :         struct ndr_syntax_id syntax;
     146             :         struct dcerpc_binding *map_binding;
     147             :         struct epm_twr_t map_tower;
     148             :         struct epm_twr_p_t towers[20];
     149             :         struct epm_tower t;
     150             :         uint32_t num_towers;
     151             :         uint32_t port;
     152             :         uint32_t i;
     153             :         long int p;
     154             :         const char *tmp;
     155             :         const char *ip;
     156             :         char *ptr;
     157             :         NTSTATUS status;
     158             : 
     159           5 :         torture_comment(tctx, "Testing epm_Map\n");
     160             : 
     161           5 :         ZERO_STRUCT(uuid);
     162           5 :         ZERO_STRUCT(entry_handle);
     163             : 
     164           5 :         r.in.object = &uuid;
     165           5 :         r.in.map_tower = &map_tower;
     166           5 :         r.in.entry_handle = &entry_handle;
     167           5 :         r.out.entry_handle = &entry_handle;
     168           5 :         r.in.max_towers = 10;
     169           5 :         r.out.towers = towers;
     170           5 :         r.out.num_towers = &num_towers;
     171             : 
     172             :         /* Create map tower */
     173           5 :         status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:[135]", &map_binding);
     174           5 :         torture_assert_ntstatus_ok(tctx, status,
     175             :                                    "epm_Map_tcpip failed: can't create map_binding");
     176             : 
     177           5 :         status = dcerpc_binding_set_abstract_syntax(map_binding, &map_syntax);
     178           5 :         torture_assert_ntstatus_ok(tctx, status,
     179             :                                    "epm_Map_tcpip failed: set map_syntax");
     180             : 
     181           5 :         status = dcerpc_binding_build_tower(tctx, map_binding,
     182             :                                             &map_tower.tower);
     183           5 :         torture_assert_ntstatus_ok(tctx, status,
     184             :                                    "epm_Map_tcpip failed: can't create map_tower");
     185             : 
     186           5 :         torture_comment(tctx,
     187             :                         "epm_Map request for '%s':\n",
     188             :                         ndr_interface_name(&map_syntax.uuid, map_syntax.if_version));
     189           5 :         display_tower(tctx, &r.in.map_tower->tower);
     190             : 
     191           5 :         status = dcerpc_epm_Map_r(h, tctx, &r);
     192             : 
     193           5 :         torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
     194           5 :         torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK,
     195             :                        "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
     196             : 
     197             :         /* Check the result */
     198           2 :         t = r.out.towers[0].twr->tower;
     199             : 
     200             :         /* Check if we got the correct RPC interface identifier */
     201           2 :         dcerpc_floor_get_lhs_data(&t.floors[0], &syntax);
     202           2 :         torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax),
     203             :                        "epm_Map_tcpip failed: Interface identifier mismatch");
     204             : 
     205           2 :         torture_comment(tctx,
     206             :                         "epm_Map_tcpip response for '%s':\n",
     207             :                         ndr_interface_name(&syntax.uuid, syntax.if_version));
     208             : 
     209           2 :         dcerpc_floor_get_lhs_data(&t.floors[1], &syntax);
     210           2 :         torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax_ndr),
     211             :                        "epm_Map_tcpip failed: floor 2 is not NDR encoded");
     212             : 
     213           2 :         torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN,
     214             :                        "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
     215             : 
     216           2 :         tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]);
     217           2 :         p = strtol(tmp, &ptr, 10);
     218           2 :         port = p & 0xffff;
     219           2 :         torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed");
     220             : 
     221           2 :         ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]);
     222           2 :         torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed");
     223             : 
     224           4 :         for (i = 0; i < *r.out.num_towers; i++) {
     225           2 :                 if (r.out.towers[i].twr) {
     226           2 :                         display_tower(tctx, &t);
     227             :                 }
     228             :         }
     229             : 
     230           2 :         return true;
     231             : }
     232             : 
     233           5 : static bool test_Map_full(struct torture_context *tctx,
     234             :                            struct dcerpc_pipe *p)
     235             : {
     236           5 :         const struct ndr_syntax_id obj = {
     237             :                 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
     238             :                 2
     239             :         };
     240           5 :         struct dcerpc_binding_handle *h = p->binding_handle;
     241           5 :         const char *annotation = "SMBTORTURE";
     242             :         struct dcerpc_binding *b;
     243             :         NTSTATUS status;
     244             :         bool ok;
     245             : 
     246           5 :         status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b);
     247           5 :         torture_assert_ntstatus_ok(tctx,
     248             :                                    status,
     249             :                                    "Unable to generate dcerpc_binding struct");
     250           5 :         status = dcerpc_binding_set_abstract_syntax(b, &obj);
     251           5 :         torture_assert_ntstatus_ok(tctx, status, "dcerpc_binding_set_abstract_syntax");
     252             : 
     253           5 :         ok = test_Insert(tctx, h, obj, annotation, b);
     254           5 :         torture_assert(tctx, ok, "test_Insert failed");
     255             : 
     256           5 :         ok = test_Map_tcpip(tctx, h, obj);
     257           5 :         torture_assert(tctx, ok, "test_Map_tcpip failed");
     258             : 
     259           2 :         ok = test_Delete(tctx, h, annotation, b);
     260           2 :         torture_assert(tctx, ok, "test_Delete failed");
     261             : 
     262           2 :         return true;
     263             : }
     264             : 
     265         482 : static bool test_Map_display(struct dcerpc_binding_handle *b,
     266             :                              struct torture_context *tctx,
     267             :                              struct epm_entry_t *entry)
     268             : 
     269             : {
     270             :         NTSTATUS status;
     271         482 :         struct epm_twr_t *twr = entry->tower;
     272             :         struct epm_Map r;
     273         482 :         struct GUID uuid = entry->object;
     274             :         struct policy_handle handle;
     275             :         struct ndr_syntax_id syntax;
     276             :         uint32_t num_towers;
     277             :         uint32_t i;
     278             : 
     279         482 :         ZERO_STRUCT(handle);
     280             : 
     281         482 :         r.in.object = &uuid;
     282         482 :         r.in.map_tower = twr;
     283         482 :         r.in.entry_handle = &handle;
     284         482 :         r.out.entry_handle = &handle;
     285         482 :         r.in.max_towers = 10;
     286         482 :         r.out.num_towers = &num_towers;
     287             : 
     288         482 :         dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
     289             : 
     290         482 :         torture_comment(tctx,
     291             :                         "epm_Map results for '%s':\n",
     292             :                         ndr_interface_name(&syntax.uuid, syntax.if_version));
     293             : 
     294         482 :         status = dcerpc_epm_Map_r(b, tctx, &r);
     295         482 :         if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
     296        3812 :                 for (i=0;i<*r.out.num_towers;i++) {
     297        3330 :                         if (r.out.towers[i].twr) {
     298        3330 :                                 display_tower(tctx, &r.out.towers[i].twr->tower);
     299             :                         }
     300             :                 }
     301             :         }
     302             : 
     303             :         /* RPC protocol identifier */
     304         482 :         twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
     305         482 :         twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
     306         482 :         twr->tower.floors[2].rhs.ncacn.minor_version = 0;
     307             : 
     308             :         /* Port address */
     309         482 :         twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
     310         482 :         twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
     311         482 :         twr->tower.floors[3].rhs.tcp.port = 0;
     312             : 
     313             :         /* Transport */
     314         482 :         twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
     315         482 :         twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
     316         482 :         twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
     317             : 
     318         482 :         status = dcerpc_epm_Map_r(b, tctx, &r);
     319         482 :         if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
     320         396 :                 for (i=0;i<*r.out.num_towers;i++) {
     321         198 :                         if (r.out.towers[i].twr) {
     322         198 :                                 display_tower(tctx, &r.out.towers[i].twr->tower);
     323             :                         }
     324             :                 }
     325             :         }
     326             : 
     327         482 :         twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
     328         482 :         twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
     329         482 :         twr->tower.floors[3].rhs.http.port = 0;
     330             : 
     331         482 :         status = dcerpc_epm_Map_r(b, tctx, &r);
     332         482 :         if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
     333         114 :                 for (i=0;i<*r.out.num_towers;i++) {
     334          57 :                         if (r.out.towers[i].twr) {
     335          57 :                                 display_tower(tctx, &r.out.towers[i].twr->tower);
     336             :                         }
     337             :                 }
     338             :         }
     339             : 
     340         482 :         twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
     341         482 :         twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
     342         482 :         twr->tower.floors[3].rhs.udp.port = 0;
     343             : 
     344         482 :         status = dcerpc_epm_Map_r(b, tctx, &r);
     345         482 :         if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
     346           0 :                 for (i=0;i<*r.out.num_towers;i++) {
     347           0 :                         if (r.out.towers[i].twr) {
     348           0 :                                 display_tower(tctx, &r.out.towers[i].twr->tower);
     349             :                         }
     350             :                 }
     351             :         }
     352             : 
     353         482 :         twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
     354         482 :         twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
     355         482 :         twr->tower.floors[3].rhs.smb.unc = "";
     356             : 
     357         482 :         twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
     358         482 :         twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
     359         482 :         twr->tower.floors[4].rhs.netbios.name = "";
     360             : 
     361         482 :         status = dcerpc_epm_Map_r(b, tctx, &r);
     362         482 :         if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
     363        3842 :                 for (i = 0; i < *r.out.num_towers; i++) {
     364        3363 :                         if (r.out.towers[i].twr) {
     365        3363 :                                 display_tower(tctx, &r.out.towers[i].twr->tower);
     366             :                         }
     367             :                 }
     368             :         }
     369             : 
     370             :         /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
     371             : 
     372         482 :         return true;
     373             : }
     374             : 
     375           5 : static bool test_Map_simple(struct torture_context *tctx,
     376             :                             struct dcerpc_pipe *p)
     377             : {
     378             :         NTSTATUS status;
     379             :         struct epm_Lookup r;
     380             :         struct policy_handle entry_handle;
     381           5 :         uint32_t num_ents = 0;
     382           5 :         struct dcerpc_binding_handle *h = p->binding_handle;
     383             : 
     384           5 :         ZERO_STRUCT(entry_handle);
     385             : 
     386           5 :         torture_comment(tctx, "Testing epm_Map\n");
     387             : 
     388             :         /* get all elements */
     389           5 :         r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
     390           5 :         r.in.object = NULL;
     391           5 :         r.in.interface_id = NULL;
     392           5 :         r.in.vers_option = RPC_C_VERS_ALL;
     393             : 
     394           5 :         r.in.entry_handle = &entry_handle;
     395           5 :         r.in.max_ents = 10;
     396             : 
     397           5 :         r.out.entry_handle = &entry_handle;
     398           5 :         r.out.num_ents = &num_ents;
     399             : 
     400             :         do {
     401             :                 int i;
     402             : 
     403          60 :                 status = dcerpc_epm_Lookup_r(h, tctx, &r);
     404         120 :                 if (!NT_STATUS_IS_OK(status) ||
     405          60 :                     r.out.result != EPMAPPER_STATUS_OK) {
     406             :                         break;
     407             :                 }
     408             : 
     409         632 :                 for (i = 0; i < *r.out.num_ents; i++) {
     410         574 :                         if (r.out.entries[i].tower->tower.num_floors == 5) {
     411         482 :                                 test_Map_display(h, tctx, &r.out.entries[i]);
     412             :                         }
     413             :                 }
     414         116 :         } while (NT_STATUS_IS_OK(status) &&
     415         116 :                  r.out.result == EPMAPPER_STATUS_OK &&
     416         113 :                  *r.out.num_ents == r.in.max_ents &&
     417         113 :                  !ndr_policy_handle_empty(&entry_handle));
     418             : 
     419           5 :         torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
     420             : 
     421           5 :         torture_assert(tctx,
     422             :                        ndr_policy_handle_empty(&entry_handle),
     423             :                        "epm_Map_simple failed - The policy handle should be empty.");
     424             : 
     425           2 :         return true;
     426             : }
     427             : 
     428           5 : static bool test_LookupHandleFree(struct torture_context *tctx,
     429             :                                   struct dcerpc_binding_handle *h,
     430             :                                   struct policy_handle *entry_handle) {
     431             :         NTSTATUS status;
     432             :         struct epm_LookupHandleFree r;
     433             : 
     434           5 :         if (ndr_policy_handle_empty(entry_handle)) {
     435           0 :                 torture_comment(tctx,
     436             :                                 "epm_LookupHandleFree failed - empty policy_handle\n");
     437           0 :                 return false;
     438             :         }
     439             : 
     440           5 :         r.in.entry_handle = entry_handle;
     441           5 :         r.out.entry_handle = entry_handle;
     442             : 
     443           5 :         status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r);
     444           5 :         if (NT_STATUS_IS_ERR(status)) {
     445           0 :                 torture_comment(tctx,
     446             :                                 "epm_LookupHandleFree failed - %s\n",
     447             :                                 nt_errstr(status));
     448           0 :                 return false;
     449             :         }
     450             : 
     451           5 :         if (r.out.result != EPMAPPER_STATUS_OK) {
     452           0 :                 torture_comment(tctx,
     453             :                                 "epm_LookupHandleFree failed - internal error: "
     454             :                                 "0x%.4x\n",
     455             :                                 r.out.result);
     456           0 :                 return false;
     457             :         }
     458             : 
     459           5 :         return true;
     460             : }
     461             : 
     462           5 : static bool test_Lookup_simple(struct torture_context *tctx,
     463             :                                struct dcerpc_pipe *p)
     464             : {
     465             :         NTSTATUS status;
     466             :         struct epm_Lookup r;
     467             :         struct policy_handle entry_handle;
     468           5 :         uint32_t num_ents = 0;
     469           5 :         struct dcerpc_binding_handle *h = p->binding_handle;
     470             : 
     471           5 :         ZERO_STRUCT(entry_handle);
     472             : 
     473           5 :         torture_comment(tctx, "Testing epm_Lookup\n");
     474             : 
     475             :         /* get all elements */
     476           5 :         r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
     477           5 :         r.in.object = NULL;
     478           5 :         r.in.interface_id = NULL;
     479           5 :         r.in.vers_option = RPC_C_VERS_ALL;
     480             : 
     481           5 :         r.in.entry_handle = &entry_handle;
     482           5 :         r.in.max_ents = 10;
     483             : 
     484           5 :         r.out.entry_handle = &entry_handle;
     485           5 :         r.out.num_ents = &num_ents;
     486             : 
     487             :         do {
     488             :                 int i;
     489             : 
     490          60 :                 status = dcerpc_epm_Lookup_r(h, tctx, &r);
     491         120 :                 if (!NT_STATUS_IS_OK(status) ||
     492          60 :                     r.out.result != EPMAPPER_STATUS_OK) {
     493             :                         break;
     494             :                 }
     495             : 
     496         116 :                 torture_comment(tctx,
     497             :                                 "epm_Lookup returned %d events, entry_handle: %s\n",
     498          58 :                                 *r.out.num_ents,
     499             :                                 GUID_string(tctx, &entry_handle.uuid));
     500             : 
     501         632 :                 for (i = 0; i < *r.out.num_ents; i++) {
     502        1148 :                         torture_comment(tctx,
     503             :                                         "\n  Found '%s' Object[%s]\n",
     504         574 :                                         r.out.entries[i].annotation,
     505         574 :                                         GUID_string(tctx, &r.out.entries[i].object));
     506             : 
     507         574 :                         display_tower(tctx, &r.out.entries[i].tower->tower);
     508             :                 }
     509         116 :         } while (NT_STATUS_IS_OK(status) &&
     510         116 :                  r.out.result == EPMAPPER_STATUS_OK &&
     511         113 :                  *r.out.num_ents == r.in.max_ents &&
     512         113 :                  !ndr_policy_handle_empty(&entry_handle));
     513             : 
     514           5 :         torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
     515           5 :         torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed");
     516             : 
     517           2 :         torture_assert(tctx,
     518             :                        ndr_policy_handle_empty(&entry_handle),
     519             :                        "epm_Lookup failed - The policy handle should be empty.");
     520             : 
     521           2 :         return true;
     522             : }
     523             : 
     524             : /*
     525             :  * This test starts a epm_Lookup request, but doesn't finish the
     526             :  * call terminates the search. So it will call epm_LookupHandleFree.
     527             :  */
     528           5 : static bool test_Lookup_terminate_search(struct torture_context *tctx,
     529             :                                          struct dcerpc_pipe *p)
     530             : {
     531             :         bool ok;
     532             :         NTSTATUS status;
     533             :         struct epm_Lookup r;
     534             :         struct policy_handle entry_handle;
     535           5 :         uint32_t i, num_ents = 0;
     536           5 :         struct dcerpc_binding_handle *h = p->binding_handle;
     537             : 
     538           5 :         ZERO_STRUCT(entry_handle);
     539             : 
     540           5 :         torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n");
     541             : 
     542             :         /* get all elements */
     543           5 :         r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
     544           5 :         r.in.object = NULL;
     545           5 :         r.in.interface_id = NULL;
     546           5 :         r.in.vers_option = RPC_C_VERS_ALL;
     547             : 
     548           5 :         r.in.entry_handle = &entry_handle;
     549           5 :         r.in.max_ents = 2;
     550             : 
     551           5 :         r.out.entry_handle = &entry_handle;
     552           5 :         r.out.num_ents = &num_ents;
     553             : 
     554           5 :         status = dcerpc_epm_Lookup_r(h, tctx, &r);
     555             : 
     556           5 :         torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
     557           5 :         torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed");
     558             : 
     559          10 :         torture_comment(tctx,
     560             :                         "epm_Lookup returned %d events, entry_handle: %s\n",
     561           5 :                         *r.out.num_ents,
     562             :                         GUID_string(tctx, &entry_handle.uuid));
     563             : 
     564          15 :         for (i = 0; i < *r.out.num_ents; i++) {
     565          10 :                 torture_comment(tctx,
     566             :                                 "\n  Found '%s'\n",
     567          10 :                                 r.out.entries[i].annotation);
     568             :         }
     569             : 
     570           5 :         ok = test_LookupHandleFree(tctx,
     571             :                                    h,
     572             :                                    &entry_handle);
     573           5 :         if (!ok) {
     574           0 :                 return false;
     575             :         }
     576             : 
     577           5 :         return true;
     578             : }
     579             : 
     580           5 : static bool test_Insert_noreplace(struct torture_context *tctx,
     581             :                                   struct dcerpc_pipe *p)
     582             : {
     583             :         bool ok;
     584             :         NTSTATUS status;
     585             :         struct epm_Insert r;
     586             :         struct dcerpc_binding *b;
     587           5 :         struct dcerpc_binding_handle *h = p->binding_handle;
     588             : 
     589           5 :         torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n");
     590             : 
     591           5 :         if (torture_setting_bool(tctx, "samba4", false)) {
     592           3 :                 torture_skip(tctx, "Skip Insert test against Samba4");
     593             :         }
     594             : 
     595           2 :         r.in.num_ents = 1;
     596           2 :         r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
     597             : 
     598           2 :         ZERO_STRUCT(r.in.entries[0].object);
     599           2 :         r.in.entries[0].annotation = "smbtorture endpoint";
     600             : 
     601           2 :         status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b);
     602           2 :         torture_assert_ntstatus_ok(tctx,
     603             :                                    status,
     604             :                                    "Unable to generate dcerpc_binding struct");
     605             : 
     606           2 :         r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
     607             : 
     608           2 :         status = dcerpc_binding_build_tower(tctx,
     609             :                                             b,
     610           2 :                                             &r.in.entries[0].tower->tower);
     611           2 :         torture_assert_ntstatus_ok(tctx,
     612             :                                    status,
     613             :                                    "Unable to build tower from binding struct");
     614           2 :         r.in.replace = 0;
     615             : 
     616           2 :         status = dcerpc_epm_Insert_r(h, tctx, &r);
     617           2 :         torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed");
     618             : 
     619           2 :         torture_assert(tctx, r.out.result == 0, "epm_Insert failed");
     620             : 
     621           2 :         ok = test_Delete(tctx, h, "smbtorture", b);
     622           2 :         if (!ok) {
     623           0 :                 return false;
     624             :         }
     625             : 
     626           2 :         return true;
     627             : }
     628             : 
     629             : #if 0
     630             : /*
     631             :  * The MS-RPCE documentation states that this function isn't implemented and
     632             :  * SHOULD NOT be called by a client.
     633             :  */
     634             : static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
     635             : {
     636             :         NTSTATUS status;
     637             :         struct epm_InqObject r;
     638             :         struct dcerpc_binding_handle *b = p->binding_handle;
     639             : 
     640             :         r.in.epm_object = talloc(tctx, struct GUID);
     641             :         *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
     642             : 
     643             :         status = dcerpc_epm_InqObject_r(b, tctx, &r);
     644             :         torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
     645             : 
     646             :         return true;
     647             : }
     648             : #endif
     649             : 
     650        2355 : struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
     651             : {
     652        2355 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "epmapper");
     653             :         struct torture_rpc_tcase *tcase;
     654             : 
     655        2355 :         tcase = torture_suite_add_rpc_iface_tcase(suite,
     656             :                                                   "epmapper",
     657             :                                                   &ndr_table_epmapper);
     658             : 
     659             :         /* This is a stack */
     660        2355 :         torture_rpc_tcase_add_test(tcase,
     661             :                                    "Map_simple",
     662             :                                    test_Map_simple);
     663        2355 :         torture_rpc_tcase_add_test(tcase,
     664             :                                    "Map_full",
     665             :                                    test_Map_full);
     666        2355 :         torture_rpc_tcase_add_test(tcase,
     667             :                                    "Lookup_simple",
     668             :                                    test_Lookup_simple);
     669        2355 :         torture_rpc_tcase_add_test(tcase,
     670             :                                    "Lookup_terminate_search",
     671             :                                    test_Lookup_terminate_search);
     672        2355 :         torture_rpc_tcase_add_test(tcase,
     673             :                                    "Insert_noreplace",
     674             :                                    test_Insert_noreplace);
     675             : 
     676        2355 :         return suite;
     677             : }
     678             : 
     679             : /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */

Generated by: LCOV version 1.13