LCOV - code coverage report
Current view: top level - source3/rpcclient - cmd_echo.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 0 84 0.0 %
Date: 2024-04-13 12:30:31 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    RPC pipe client
       4             : 
       5             :    Copyright (C) Tim Potter 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 "rpcclient.h"
      23             : #include "../librpc/gen_ndr/ndr_echo_c.h"
      24             : 
      25           0 : static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
      26             :                                  int argc, const char **argv)
      27             : {
      28           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      29           0 :         uint32_t request = 1, response;
      30             :         NTSTATUS status;
      31             : 
      32           0 :         if (argc > 2) {
      33           0 :                 printf("Usage: %s [num]\n", argv[0]);
      34           0 :                 return NT_STATUS_OK;
      35             :         }
      36             : 
      37           0 :         if (argc == 2) {
      38           0 :                 request = atoi(argv[1]);
      39             :         }
      40             : 
      41           0 :         status = dcerpc_echo_AddOne(b, mem_ctx, request, &response);
      42           0 :         if (!NT_STATUS_IS_OK(status)) {
      43           0 :                 goto done;
      44             :         }
      45             : 
      46           0 :         printf("%d + 1 = %d\n", request, response);
      47             : 
      48           0 : done:
      49           0 :         return status;
      50             : }
      51             : 
      52           0 : static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
      53             :                               int argc, const char **argv)
      54             : {
      55           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
      56             :         uint32_t size, i;
      57             :         NTSTATUS status;
      58           0 :         uint8_t *in_data = NULL, *out_data = NULL;
      59             : 
      60           0 :         if (argc != 2) {
      61           0 :                 printf("Usage: %s num\n", argv[0]);
      62           0 :                 return NT_STATUS_OK;
      63             :         }
      64             : 
      65           0 :         size = atoi(argv[1]);
      66           0 :         if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
      67           0 :                 printf("Failure to allocate buff of %d bytes\n",
      68             :                        size);
      69           0 :                 status = NT_STATUS_NO_MEMORY;
      70           0 :                 goto done;
      71             :         }
      72           0 :         if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
      73           0 :                 printf("Failure to allocate buff of %d bytes\n",
      74             :                        size);
      75           0 :                 status = NT_STATUS_NO_MEMORY;
      76           0 :                 goto done;
      77             :         }
      78             : 
      79           0 :         for (i = 0; i < size; i++) {
      80           0 :                 in_data[i] = i & 0xff;
      81             :         }
      82             : 
      83           0 :         status = dcerpc_echo_EchoData(b, mem_ctx, size, in_data, out_data);
      84           0 :         if (!NT_STATUS_IS_OK(status)) {
      85           0 :                 goto done;
      86             :         }
      87             : 
      88           0 :         for (i = 0; i < size; i++) {
      89           0 :                 if (in_data[i] != out_data[i]) {
      90           0 :                         printf("mismatch at offset %d, %d != %d\n",
      91           0 :                                i, in_data[i], out_data[i]);
      92           0 :                         status = NT_STATUS_UNSUCCESSFUL;
      93             :                 }
      94             :         }
      95             : 
      96           0 : done:
      97           0 :         SAFE_FREE(in_data);
      98           0 :         SAFE_FREE(out_data);
      99             : 
     100           0 :         return status;
     101             : }
     102             : 
     103           0 : static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli, 
     104             :                                      TALLOC_CTX *mem_ctx, int argc, 
     105             :                                      const char **argv)
     106             : {
     107           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     108             :         uint32_t size, i;
     109             :         NTSTATUS status;
     110           0 :         uint8_t *out_data = NULL;
     111             : 
     112           0 :         if (argc != 2) {
     113           0 :                 printf("Usage: %s num\n", argv[0]);
     114           0 :                 return NT_STATUS_OK;
     115             :         }
     116             : 
     117           0 :         size = atoi(argv[1]);
     118           0 :         if ( (out_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
     119           0 :                 printf("Failure to allocate buff of %d bytes\n",
     120             :                        size);
     121           0 :                 status = NT_STATUS_NO_MEMORY;
     122           0 :                 goto done;              
     123             :         }
     124             :         
     125             : 
     126           0 :         status = dcerpc_echo_SourceData(b, mem_ctx, size, out_data);
     127           0 :         if (!NT_STATUS_IS_OK(status)) {
     128           0 :                 goto done;
     129             :         }
     130             : 
     131           0 :         for (i = 0; i < size; i++) {
     132           0 :                 if (out_data && out_data[i] != (i & 0xff)) {
     133           0 :                         printf("mismatch at offset %d, %d != %d\n",
     134           0 :                                i, out_data[i], i & 0xff);
     135           0 :                         status = NT_STATUS_UNSUCCESSFUL;
     136             :                 }
     137             :         }
     138             : 
     139           0 : done:
     140             : 
     141           0 :         SAFE_FREE(out_data);
     142           0 :         return status;
     143             : }
     144             : 
     145           0 : static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     146             :                                    int argc, const char **argv)
     147             : {
     148           0 :         struct dcerpc_binding_handle *b = cli->binding_handle;
     149             :         uint32_t size, i;
     150             :         NTSTATUS status;
     151           0 :         uint8_t *in_data = NULL;
     152             : 
     153           0 :         if (argc != 2) {
     154           0 :                 printf("Usage: %s num\n", argv[0]);
     155           0 :                 return NT_STATUS_OK;
     156             :         }
     157             : 
     158           0 :         size = atoi(argv[1]);
     159           0 :         if ( (in_data = (uint8_t*)SMB_MALLOC(size)) == NULL ) {
     160           0 :                 printf("Failure to allocate buff of %d bytes\n",
     161             :                        size);
     162           0 :                 status = NT_STATUS_NO_MEMORY;
     163           0 :                 goto done;              
     164             :         }
     165             : 
     166           0 :         for (i = 0; i < size; i++) {
     167           0 :                 in_data[i] = i & 0xff;
     168             :         }
     169             : 
     170           0 :         status = dcerpc_echo_SinkData(b, mem_ctx, size, in_data);
     171           0 :         if (!NT_STATUS_IS_OK(status)) {
     172           0 :                 goto done;
     173             :         }
     174             : 
     175           0 : done:
     176           0 :         SAFE_FREE(in_data);
     177             : 
     178           0 :         return status;
     179             : }
     180             : 
     181             : /* List of commands exported by this module */
     182             : 
     183             : struct cmd_set echo_commands[] = {
     184             : 
     185             :         {
     186             :                 .name = "ECHO",
     187             :         },
     188             : 
     189             :         {
     190             :                 .name               = "echoaddone",
     191             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     192             :                 .ntfn               = cmd_echo_add_one,
     193             :                 .wfn                = NULL,
     194             :                 .table              = &ndr_table_rpcecho,
     195             :                 .rpc_pipe           = NULL,
     196             :                 .description        = "Add one to a number",
     197             :                 .usage              = "",
     198             :         },
     199             :         {
     200             :                 .name               = "echodata",
     201             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     202             :                 .ntfn               = cmd_echo_data,
     203             :                 .wfn                = NULL,
     204             :                 .table              = &ndr_table_rpcecho,
     205             :                 .rpc_pipe           = NULL,
     206             :                 .description        = "Echo data",
     207             :                 .usage              = "",
     208             :         },
     209             :         {
     210             :                 .name               = "sinkdata",
     211             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     212             :                 .ntfn               = cmd_echo_sink_data,
     213             :                 .wfn                = NULL,
     214             :                 .table              = &ndr_table_rpcecho,
     215             :                 .rpc_pipe           = NULL,
     216             :                 .description        = "Sink data",
     217             :                 .usage              = "",
     218             :         },
     219             :         {
     220             :                 .name               = "sourcedata",
     221             :                 .returntype         = RPC_RTYPE_NTSTATUS,
     222             :                 .ntfn               = cmd_echo_source_data,
     223             :                 .wfn                = NULL,
     224             :                 .table              = &ndr_table_rpcecho,
     225             :                 .rpc_pipe           = NULL,
     226             :                 .description        = "Source data",
     227             :                 .usage              = "",
     228             :         },
     229             :         {
     230             :                 .name = NULL
     231             :         },
     232             : };

Generated by: LCOV version 1.14