58c59aa50645c933cdb32db318532fb2bdb996c0
[samba.git] / source / rpc_server / srv_echo_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines for rpcecho
4  *  Copyright (C) Tim Potter                   2003
5  *  Copyright (C) Jelmer Vernooij              2006
6  *  Copyright (C) Gerald (Jerry) Carter        2007
7  *  
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 3 of the License, or
11  *  (at your option) any later version.
12  *  
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *  
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /* This is the interface to the rpcecho pipe. */
23
24 #include "includes.h"
25 #include "nterr.h"
26
27 #ifdef DEVELOPER
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_SRV
31
32 /* Add one to the input and return it */
33
34 void _echo_AddOne(pipes_struct *p, struct echo_AddOne *r )
35 {
36         DEBUG(10, ("_echo_AddOne\n"));
37
38         *r->out.out_data = r->in.in_data + 1;
39 }
40
41 /* Echo back an array of data */
42
43 void _echo_EchoData(pipes_struct *p, struct echo_EchoData *r)
44 {
45         DEBUG(10, ("_echo_EchoData\n"));
46
47         if ( r->in.len == 0 ) {         
48                 r->out.out_data = NULL;
49                 return;
50         }
51
52         r->out.out_data = TALLOC_ARRAY(p->mem_ctx, uint8, r->in.len);
53         memcpy( r->out.out_data, r->in.in_data, r->in.len );
54         return; 
55 }
56
57 /* Sink an array of data */
58
59 void _echo_SinkData(pipes_struct *p, struct echo_SinkData *r)
60 {
61         DEBUG(10, ("_echo_SinkData\n"));
62
63         /* My that was some yummy data! */
64         return; 
65 }
66
67 /* Source an array of data */
68
69 void _echo_SourceData(pipes_struct *p, struct echo_SourceData *r)
70 {
71         uint32 i;
72
73         DEBUG(10, ("_echo_SourceData\n"));
74
75         if ( r->in.len == 0 ) {
76                 r->out.data = NULL;             
77                 return;
78         }
79
80         r->out.data = TALLOC_ARRAY(p->mem_ctx, uint8, r->in.len );
81
82         for (i = 0; i < r->in.len; i++ ) {              
83                 r->out.data[i] = i & 0xff;
84         }
85         
86         return; 
87 }
88
89 void _echo_TestCall(pipes_struct *p, struct echo_TestCall *r)
90 {
91         *r->out.s2 = talloc_strdup(p->mem_ctx, r->in.s1);
92 }
93
94 NTSTATUS _echo_TestCall2(pipes_struct *p, struct echo_TestCall2 *r)
95 {
96         switch (r->in.level) {
97         case 1:
98                 r->out.info->info1.v = 10;
99                 break;
100         case 2:
101                 r->out.info->info2.v = 20;
102                 break;
103         case 3:
104                 r->out.info->info3.v = 30;
105                 break;
106         case 4:
107                 r->out.info->info4.v = 40;
108                 break;
109         case 5:
110                 r->out.info->info5.v1 = 50;
111                 r->out.info->info5.v2 = 60;
112                 break;
113         case 6:
114                 r->out.info->info6.v1 = 70;
115                 r->out.info->info6.info1.v= 80;
116                 break;
117         case 7:
118                 r->out.info->info7.v1 = 80;
119                 r->out.info->info7.info4.v = 90;
120                 break;
121         default:
122                 return NT_STATUS_INVALID_LEVEL;
123         }
124
125         return NT_STATUS_OK;
126 }
127
128 uint32 _echo_TestSleep(pipes_struct *p, struct echo_TestSleep *r)
129 {
130         sleep(r->in.seconds);
131         return r->in.seconds;
132 }
133
134 void _echo_TestEnum(pipes_struct *p, struct echo_TestEnum *r)
135 {
136 }
137
138 void _echo_TestSurrounding(pipes_struct *p, struct echo_TestSurrounding *r)
139 {
140         r->out.data->x *= 2;
141         r->out.data->surrounding = TALLOC_ZERO_ARRAY(p->mem_ctx, uint16_t, r->in.data->x);
142 }
143
144 uint16 _echo_TestDoublePointer(pipes_struct *p, struct echo_TestDoublePointer *r)
145 {
146         if (!*r->in.data) 
147                 return 0;
148         if (!**r->in.data)
149                 return 0;
150         return ***r->in.data;
151 }
152
153 #endif /* DEVELOPER */