LCOV - code coverage report
Current view: top level - source3/torture - test_async_echo.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 0 75 0.0 %
Date: 2021-09-23 10:06:22 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Run the async echo responder
       4             :    Copyright (C) Volker Lendecke 2010
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "torture/proto.h"
      22             : #include "libsmb/libsmb.h"
      23             : #include "rpc_client/cli_pipe.h"
      24             : #include "librpc/gen_ndr/ndr_echo_c.h"
      25             : 
      26           0 : static void rpccli_sleep_done(struct tevent_req *req)
      27             : {
      28           0 :         int *done = (int *)tevent_req_callback_data_void(req);
      29             :         NTSTATUS status;
      30           0 :         uint32_t result = UINT32_MAX;
      31             : 
      32           0 :         status = dcerpc_echo_TestSleep_recv(req, talloc_tos(), &result);
      33           0 :         TALLOC_FREE(req);
      34           0 :         printf("sleep returned %s, %d\n", nt_errstr(status), (int)result);
      35           0 :         *done -= 1;
      36           0 : }
      37             : 
      38           0 : static void cli_echo_done(struct tevent_req *req)
      39             : {
      40           0 :         int *done = (int *)tevent_req_callback_data_void(req);
      41             :         NTSTATUS status;
      42             : 
      43           0 :         status = cli_echo_recv(req);
      44           0 :         TALLOC_FREE(req);
      45           0 :         printf("echo returned %s\n", nt_errstr(status));
      46           0 :         *done -= 1;
      47           0 : }
      48             : 
      49           0 : static void write_andx_done(struct tevent_req *req)
      50             : {
      51           0 :         int *done = (int *)tevent_req_callback_data_void(req);
      52             :         NTSTATUS status;
      53             :         size_t written;
      54             : 
      55           0 :         status = cli_write_andx_recv(req, &written);
      56           0 :         TALLOC_FREE(req);
      57           0 :         printf("cli_write_andx returned %s\n", nt_errstr(status));
      58           0 :         *done -= 1;
      59           0 : }
      60             : 
      61           0 : bool run_async_echo(int dummy)
      62             : {
      63           0 :         struct cli_state *cli = NULL;
      64             :         struct rpc_pipe_client *p;
      65             :         struct dcerpc_binding_handle *b;
      66             :         struct tevent_context *ev;
      67             :         struct tevent_req *req;
      68             :         NTSTATUS status;
      69           0 :         bool ret = false;
      70             :         int i, num_reqs;
      71             :         uint8_t buf[65536];
      72             : 
      73           0 :         printf("Starting ASYNC_ECHO\n");
      74             : 
      75           0 :         ev = samba_tevent_context_init(talloc_tos());
      76           0 :         if (ev == NULL) {
      77           0 :                 printf("tevent_context_init failed\n");
      78           0 :                 goto fail;
      79             :         }
      80             : 
      81           0 :         if (!torture_open_connection(&cli, 0)) {
      82           0 :                 printf("torture_open_connection failed\n");
      83           0 :                 goto fail;
      84             :         }
      85           0 :         status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho,
      86             :                                           &p);
      87           0 :         if (!NT_STATUS_IS_OK(status)) {
      88           0 :                 printf("Could not open echo pipe: %s\n", nt_errstr(status));
      89           0 :                 goto fail;
      90             :         }
      91           0 :         b = p->binding_handle;
      92             : 
      93           0 :         num_reqs = 0;
      94             : 
      95           0 :         req = dcerpc_echo_TestSleep_send(ev, ev, b, 15);
      96           0 :         if (req == NULL) {
      97           0 :                 printf("rpccli_echo_TestSleep_send failed\n");
      98           0 :                 goto fail;
      99             :         }
     100           0 :         tevent_req_set_callback(req, rpccli_sleep_done, &num_reqs);
     101           0 :         num_reqs += 1;
     102             : 
     103           0 :         req = cli_echo_send(ev, ev, cli, 1, data_blob_const("hello", 5));
     104           0 :         if (req == NULL) {
     105           0 :                 printf("cli_echo_send failed\n");
     106           0 :                 goto fail;
     107             :         }
     108           0 :         tevent_req_set_callback(req, cli_echo_done, &num_reqs);
     109           0 :         num_reqs += 1;
     110             : 
     111           0 :         memset(buf, 0, sizeof(buf));
     112             : 
     113           0 :         for (i=0; i<10; i++) {
     114           0 :                 req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0,
     115             :                                           sizeof(buf));
     116           0 :                 if (req == NULL) {
     117           0 :                         printf("cli_write_andx_send failed\n");
     118           0 :                         goto fail;
     119             :                 }
     120           0 :                 tevent_req_set_callback(req, write_andx_done, &num_reqs);
     121           0 :                 num_reqs += 1;
     122             : 
     123           0 :                 req = cli_echo_send(ev, ev, cli, 1,
     124             :                                     data_blob_const("hello", 5));
     125           0 :                 if (req == NULL) {
     126           0 :                         printf("cli_echo_send failed\n");
     127           0 :                         goto fail;
     128             :                 }
     129           0 :                 tevent_req_set_callback(req, cli_echo_done, &num_reqs);
     130           0 :                 num_reqs += 1;
     131             :         }
     132             : 
     133           0 :         while (num_reqs > 0) {
     134           0 :                 if (tevent_loop_once(ev) != 0) {
     135           0 :                         printf("tevent_loop_once failed\n");
     136           0 :                         goto fail;
     137             :                 }
     138             :         }
     139             : 
     140           0 :         TALLOC_FREE(p);
     141             : 
     142           0 :         ret = true;
     143           0 : fail:
     144           0 :         if (cli != NULL) {
     145           0 :                 torture_close_connection(cli);
     146             :         }
     147           0 :         return ret;
     148             : }

Generated by: LCOV version 1.13