LCOV - code coverage report
Current view: top level - source4/rpc_server/echo - rpc_echo.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 82 99 82.8 %
Date: 2024-06-13 04:01:37 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    endpoint server for the echo pipe
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2003
       7             :    Copyright (C) Stefan (metze) Metzmacher 2005
       8             :    
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             :    
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             :    
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "system/filesys.h"
      25             : #include "rpc_server/dcerpc_server.h"
      26             : #include "librpc/gen_ndr/ndr_echo.h"
      27             : #include "lib/events/events.h"
      28             : 
      29             : #define DCESRV_INTERFACE_RPCECHO_BIND(context, iface) \
      30             :        dcesrv_interface_rpcecho_bind(context, iface)
      31         321 : static NTSTATUS dcesrv_interface_rpcecho_bind(struct dcesrv_connection_context *context,
      32             :                                               const struct dcesrv_interface *iface)
      33             : {
      34         321 :         return dcesrv_interface_bind_allow_connect(context, iface);
      35             : }
      36             : 
      37        3605 : static NTSTATUS dcesrv_echo_AddOne(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_AddOne *r)
      38             : {
      39        3605 :         *r->out.out_data = r->in.in_data + 1;
      40        3605 :         return NT_STATUS_OK;
      41             : }
      42             : 
      43         264 : static NTSTATUS dcesrv_echo_EchoData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_EchoData *r)
      44             : {
      45         264 :         if (!r->in.len) {
      46           0 :                 return NT_STATUS_OK;
      47             :         }
      48             : 
      49         264 :         r->out.out_data = (uint8_t *)talloc_memdup(mem_ctx, r->in.in_data, r->in.len);
      50         264 :         if (!r->out.out_data) {
      51           0 :                 return NT_STATUS_NO_MEMORY;
      52             :         }
      53             : 
      54         264 :         return NT_STATUS_OK;
      55             : }
      56             : 
      57         257 : static NTSTATUS dcesrv_echo_SinkData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SinkData *r)
      58             : {
      59         257 :         return NT_STATUS_OK;
      60             : }
      61             : 
      62         257 : static NTSTATUS dcesrv_echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
      63             : {
      64             :         unsigned int i;
      65             : 
      66         257 :         r->out.data = talloc_array(mem_ctx, uint8_t, r->in.len);
      67         257 :         if (!r->out.data) {
      68           0 :                 return NT_STATUS_NO_MEMORY;
      69             :         }
      70             :         
      71    48806312 :         for (i=0;i<r->in.len;i++) {
      72    48806055 :                 r->out.data[i] = i;
      73             :         }
      74             : 
      75         257 :         return NT_STATUS_OK;
      76             : }
      77             : 
      78         258 : static NTSTATUS dcesrv_echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
      79             : {
      80         258 :         *r->out.s2 = talloc_strdup(mem_ctx, r->in.s1);
      81         258 :         if (r->in.s1 && !*r->out.s2) {
      82           0 :                 return NT_STATUS_NO_MEMORY;
      83             :         }
      84         258 :         return NT_STATUS_OK;
      85             : }
      86             : 
      87        1799 : static NTSTATUS dcesrv_echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
      88             : {
      89        1799 :         r->out.info = talloc(mem_ctx, union echo_Info);
      90        1799 :         if (!r->out.info) {
      91           0 :                 return NT_STATUS_NO_MEMORY;
      92             :         }
      93             : 
      94        1799 :         switch (r->in.level) {
      95         257 :         case 1:
      96         257 :                 r->out.info->info1.v = 10;
      97         257 :                 break;
      98         257 :         case 2:
      99         257 :                 r->out.info->info2.v = 20;
     100         257 :                 break;
     101         257 :         case 3:
     102         257 :                 r->out.info->info3.v = 30;
     103         257 :                 break;
     104         257 :         case 4:
     105         257 :                 r->out.info->info4.v = 40;
     106         257 :                 break;
     107         257 :         case 5:
     108         257 :                 r->out.info->info5.v1 = 50;
     109         257 :                 r->out.info->info5.v2 = 60;
     110         257 :                 break;
     111         257 :         case 6:
     112         257 :                 r->out.info->info6.v1 = 70;
     113         257 :                 r->out.info->info6.info1.v= 80;
     114         257 :                 break;
     115         257 :         case 7:
     116         257 :                 r->out.info->info7.v1 = 80;
     117         257 :                 r->out.info->info7.info4.v = 90;
     118         257 :                 break;
     119           0 :         default:
     120           0 :                 return NT_STATUS_INVALID_LEVEL;
     121             :         }
     122             : 
     123        1799 :         return NT_STATUS_OK;
     124             : }
     125             : 
     126         257 : static NTSTATUS dcesrv_echo_TestEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestEnum *r)
     127             : {
     128         257 :         r->out.foo2->e1 = ECHO_ENUM2;
     129         257 :         return NT_STATUS_OK;
     130             : }
     131             : 
     132         258 : static NTSTATUS dcesrv_echo_TestSurrounding(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSurrounding *r)
     133             : {
     134         258 :         if (!r->in.data) {
     135           0 :                 r->out.data = NULL;
     136           0 :                 return NT_STATUS_OK;
     137             :         }
     138             : 
     139         258 :         r->out.data = talloc(mem_ctx, struct echo_Surrounding);
     140         258 :         if (!r->out.data) {
     141           0 :                 return NT_STATUS_NO_MEMORY;
     142             :         }
     143         258 :         r->out.data->x = 2 * r->in.data->x;
     144         258 :         r->out.data->surrounding = talloc_zero_array(mem_ctx, uint16_t, r->out.data->x);
     145         258 :         if (!r->out.data->surrounding) {
     146           0 :                 return NT_STATUS_NO_MEMORY;
     147             :         }
     148             : 
     149         258 :         return NT_STATUS_OK;
     150             : }
     151             : 
     152         257 : static uint16_t dcesrv_echo_TestDoublePointer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestDoublePointer *r) 
     153             : {
     154         257 :         if (!*r->in.data) 
     155           0 :                 return 0;
     156         257 :         if (!**r->in.data)
     157           0 :                 return 0;
     158         257 :         return ***r->in.data;
     159             : }
     160             : 
     161             : struct echo_TestSleep_private {
     162             :         struct dcesrv_call_state *dce_call;
     163             :         struct echo_TestSleep *r;
     164             : };
     165             : 
     166         135 : static void echo_TestSleep_handler(struct tevent_context *ev, struct tevent_timer *te, 
     167             :                                    struct timeval t, void *private_data)
     168             : {
     169         135 :         struct echo_TestSleep_private *p = talloc_get_type(private_data,
     170             :                                                            struct echo_TestSleep_private);
     171         135 :         struct echo_TestSleep *r = p->r;
     172             :         NTSTATUS status;
     173             : 
     174         135 :         r->out.result = r->in.seconds;
     175             : 
     176         135 :         status = dcesrv_reply(p->dce_call);
     177         135 :         if (!NT_STATUS_IS_OK(status)) {
     178           0 :                 DEBUG(0,("echo_TestSleep_handler: dcesrv_reply() failed - %s\n",
     179             :                         nt_errstr(status)));
     180             :         }
     181         135 : }
     182             : 
     183         135 : static long dcesrv_echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSleep *r)
     184             : {
     185             :         struct echo_TestSleep_private *p;
     186             : 
     187         135 :         if (!(dce_call->state_flags & DCESRV_CALL_STATE_FLAG_MAY_ASYNC)) {
     188             :                 /* we're not allowed to reply async */
     189           0 :                 sleep(r->in.seconds);
     190           0 :                 return r->in.seconds;
     191             :         }
     192             : 
     193             :         /* we're allowed to reply async */
     194         135 :         p = talloc(mem_ctx, struct echo_TestSleep_private);
     195         135 :         if (!p) {
     196           0 :                 return 0;
     197             :         }
     198             : 
     199         135 :         p->dce_call  = dce_call;
     200         135 :         p->r         = r;
     201             : 
     202         135 :         tevent_add_timer(dce_call->event_ctx, p,
     203             :                         timeval_add(&dce_call->time, r->in.seconds, 0),
     204             :                         echo_TestSleep_handler, p);
     205             : 
     206         135 :         dce_call->state_flags |= DCESRV_CALL_STATE_FLAG_ASYNC;
     207         135 :         return 0;
     208             : }
     209             : 
     210             : /* include the generated boilerplate */
     211             : #include "librpc/gen_ndr/ndr_echo_s.c"

Generated by: LCOV version 1.13