LCOV - code coverage report
Current view: top level - source4/rpc_server/echo - rpc_echo.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 82 99 82.8 %
Date: 2024-02-28 12:06:22 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         327 : static NTSTATUS dcesrv_interface_rpcecho_bind(struct dcesrv_connection_context *context,
      32             :                                               const struct dcesrv_interface *iface)
      33             : {
      34         327 :         return dcesrv_interface_bind_allow_connect(context, iface);
      35             : }
      36             : 
      37        3689 : static NTSTATUS dcesrv_echo_AddOne(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_AddOne *r)
      38             : {
      39        3689 :         *r->out.out_data = r->in.in_data + 1;
      40        3689 :         return NT_STATUS_OK;
      41             : }
      42             : 
      43         270 : static NTSTATUS dcesrv_echo_EchoData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_EchoData *r)
      44             : {
      45         270 :         if (!r->in.len) {
      46           0 :                 return NT_STATUS_OK;
      47             :         }
      48             : 
      49         270 :         r->out.out_data = (uint8_t *)talloc_memdup(mem_ctx, r->in.in_data, r->in.len);
      50         270 :         if (!r->out.out_data) {
      51           0 :                 return NT_STATUS_NO_MEMORY;
      52             :         }
      53             : 
      54         270 :         return NT_STATUS_OK;
      55             : }
      56             : 
      57         261 : static NTSTATUS dcesrv_echo_SinkData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SinkData *r)
      58             : {
      59         263 :         return NT_STATUS_OK;
      60             : }
      61             : 
      62         263 : static NTSTATUS dcesrv_echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
      63             : {
      64           2 :         unsigned int i;
      65             : 
      66         263 :         r->out.data = talloc_array(mem_ctx, uint8_t, r->in.len);
      67         263 :         if (!r->out.data) {
      68           0 :                 return NT_STATUS_NO_MEMORY;
      69             :         }
      70             :         
      71    50032179 :         for (i=0;i<r->in.len;i++) {
      72    50031916 :                 r->out.data[i] = i;
      73             :         }
      74             : 
      75         263 :         return NT_STATUS_OK;
      76             : }
      77             : 
      78         264 : static NTSTATUS dcesrv_echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
      79             : {
      80         264 :         *r->out.s2 = talloc_strdup(mem_ctx, r->in.s1);
      81         264 :         if (r->in.s1 && !*r->out.s2) {
      82           0 :                 return NT_STATUS_NO_MEMORY;
      83             :         }
      84         264 :         return NT_STATUS_OK;
      85             : }
      86             : 
      87        1841 : static NTSTATUS dcesrv_echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
      88             : {
      89        1841 :         r->out.info = talloc(mem_ctx, union echo_Info);
      90        1841 :         if (!r->out.info) {
      91           0 :                 return NT_STATUS_NO_MEMORY;
      92             :         }
      93             : 
      94        1841 :         switch (r->in.level) {
      95         263 :         case 1:
      96         263 :                 r->out.info->info1.v = 10;
      97         263 :                 break;
      98         263 :         case 2:
      99         263 :                 r->out.info->info2.v = 20;
     100         263 :                 break;
     101         263 :         case 3:
     102         263 :                 r->out.info->info3.v = 30;
     103         263 :                 break;
     104         263 :         case 4:
     105         263 :                 r->out.info->info4.v = 40;
     106         263 :                 break;
     107         263 :         case 5:
     108         263 :                 r->out.info->info5.v1 = 50;
     109         263 :                 r->out.info->info5.v2 = 60;
     110         263 :                 break;
     111         263 :         case 6:
     112         263 :                 r->out.info->info6.v1 = 70;
     113         263 :                 r->out.info->info6.info1.v= 80;
     114         263 :                 break;
     115         263 :         case 7:
     116         263 :                 r->out.info->info7.v1 = 80;
     117         263 :                 r->out.info->info7.info4.v = 90;
     118         263 :                 break;
     119           0 :         default:
     120           0 :                 return NT_STATUS_INVALID_LEVEL;
     121             :         }
     122             : 
     123        1841 :         return NT_STATUS_OK;
     124             : }
     125             : 
     126         263 : static NTSTATUS dcesrv_echo_TestEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestEnum *r)
     127             : {
     128         263 :         r->out.foo2->e1 = ECHO_ENUM2;
     129         263 :         return NT_STATUS_OK;
     130             : }
     131             : 
     132         264 : static NTSTATUS dcesrv_echo_TestSurrounding(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSurrounding *r)
     133             : {
     134         264 :         if (!r->in.data) {
     135           0 :                 r->out.data = NULL;
     136           0 :                 return NT_STATUS_OK;
     137             :         }
     138             : 
     139         264 :         r->out.data = talloc(mem_ctx, struct echo_Surrounding);
     140         264 :         if (!r->out.data) {
     141           0 :                 return NT_STATUS_NO_MEMORY;
     142             :         }
     143         264 :         r->out.data->x = 2 * r->in.data->x;
     144         264 :         r->out.data->surrounding = talloc_zero_array(mem_ctx, uint16_t, r->out.data->x);
     145         264 :         if (!r->out.data->surrounding) {
     146           0 :                 return NT_STATUS_NO_MEMORY;
     147             :         }
     148             : 
     149         264 :         return NT_STATUS_OK;
     150             : }
     151             : 
     152         263 : static uint16_t dcesrv_echo_TestDoublePointer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestDoublePointer *r) 
     153             : {
     154         263 :         if (!*r->in.data) 
     155           0 :                 return 0;
     156         263 :         if (!**r->in.data)
     157           0 :                 return 0;
     158         263 :         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             : 
     173         135 :         r->out.result = r->in.seconds;
     174             : 
     175         135 :         dcesrv_async_reply(p->dce_call);
     176         135 : }
     177             : 
     178         135 : static long dcesrv_echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSleep *r)
     179             : {
     180           0 :         struct echo_TestSleep_private *p;
     181             : 
     182         135 :         if (!(dce_call->state_flags & DCESRV_CALL_STATE_FLAG_MAY_ASYNC)) {
     183             :                 /* we're not allowed to reply async */
     184           0 :                 sleep(r->in.seconds);
     185           0 :                 return r->in.seconds;
     186             :         }
     187             : 
     188             :         /* we're allowed to reply async */
     189         135 :         p = talloc(mem_ctx, struct echo_TestSleep_private);
     190         135 :         if (!p) {
     191           0 :                 return 0;
     192             :         }
     193             : 
     194         135 :         p->dce_call  = dce_call;
     195         135 :         p->r         = r;
     196             : 
     197         135 :         tevent_add_timer(dce_call->event_ctx, p,
     198             :                         timeval_add(&dce_call->time, r->in.seconds, 0),
     199             :                         echo_TestSleep_handler, p);
     200             : 
     201         135 :         dce_call->state_flags |= DCESRV_CALL_STATE_FLAG_ASYNC;
     202         135 :         return 0;
     203             : }
     204             : 
     205             : /* include the generated boilerplate */
     206             : #include "librpc/gen_ndr/ndr_echo_s.c"

Generated by: LCOV version 1.14