ctdb-scripts: Support storing statd-callout state in cluster filesystem
[samba4-gss.git] / source4 / rpc_server / echo / rpc_echo.c
blob82d9556d6a728e60f981849b75a93640e8e7ca34
1 /*
2 Unix SMB/CIFS implementation.
4 endpoint server for the echo pipe
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Stefan (metze) Metzmacher 2005
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.
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.
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/>.
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"
29 #define DCESRV_INTERFACE_RPCECHO_BIND(context, iface) \
30 dcesrv_interface_rpcecho_bind(context, iface)
31 static NTSTATUS dcesrv_interface_rpcecho_bind(struct dcesrv_connection_context *context,
32 const struct dcesrv_interface *iface)
34 return dcesrv_interface_bind_allow_connect(context, iface);
37 static NTSTATUS dcesrv_echo_AddOne(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_AddOne *r)
39 *r->out.out_data = r->in.in_data + 1;
40 return NT_STATUS_OK;
43 static NTSTATUS dcesrv_echo_EchoData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_EchoData *r)
45 if (!r->in.len) {
46 return NT_STATUS_OK;
49 r->out.out_data = (uint8_t *)talloc_memdup(mem_ctx, r->in.in_data, r->in.len);
50 if (!r->out.out_data) {
51 return NT_STATUS_NO_MEMORY;
54 return NT_STATUS_OK;
57 static NTSTATUS dcesrv_echo_SinkData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SinkData *r)
59 return NT_STATUS_OK;
62 static NTSTATUS dcesrv_echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
64 unsigned int i;
66 r->out.data = talloc_array(mem_ctx, uint8_t, r->in.len);
67 if (!r->out.data) {
68 return NT_STATUS_NO_MEMORY;
71 for (i=0;i<r->in.len;i++) {
72 r->out.data[i] = i;
75 return NT_STATUS_OK;
78 static NTSTATUS dcesrv_echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
80 *r->out.s2 = talloc_strdup(mem_ctx, r->in.s1);
81 if (r->in.s1 && !*r->out.s2) {
82 return NT_STATUS_NO_MEMORY;
84 return NT_STATUS_OK;
87 static NTSTATUS dcesrv_echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
89 r->out.info = talloc(mem_ctx, union echo_Info);
90 if (!r->out.info) {
91 return NT_STATUS_NO_MEMORY;
94 switch (r->in.level) {
95 case 1:
96 r->out.info->info1.v = 10;
97 break;
98 case 2:
99 r->out.info->info2.v = 20;
100 break;
101 case 3:
102 r->out.info->info3.v = 30;
103 break;
104 case 4:
105 r->out.info->info4.v = 40;
106 break;
107 case 5:
108 r->out.info->info5.v1 = 50;
109 r->out.info->info5.v2 = 60;
110 break;
111 case 6:
112 r->out.info->info6.v1 = 70;
113 r->out.info->info6.info1.v= 80;
114 break;
115 case 7:
116 r->out.info->info7.v1 = 80;
117 r->out.info->info7.info4.v = 90;
118 break;
119 default:
120 return NT_STATUS_INVALID_LEVEL;
123 return NT_STATUS_OK;
126 static NTSTATUS dcesrv_echo_TestEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestEnum *r)
128 r->out.foo2->e1 = ECHO_ENUM2;
129 return NT_STATUS_OK;
132 static NTSTATUS dcesrv_echo_TestSurrounding(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSurrounding *r)
134 if (!r->in.data) {
135 r->out.data = NULL;
136 return NT_STATUS_OK;
139 r->out.data = talloc(mem_ctx, struct echo_Surrounding);
140 if (!r->out.data) {
141 return NT_STATUS_NO_MEMORY;
143 r->out.data->x = 2 * r->in.data->x;
144 r->out.data->surrounding = talloc_zero_array(mem_ctx, uint16_t, r->out.data->x);
145 if (!r->out.data->surrounding) {
146 return NT_STATUS_NO_MEMORY;
149 return NT_STATUS_OK;
152 static uint16_t dcesrv_echo_TestDoublePointer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestDoublePointer *r)
154 if (!*r->in.data)
155 return 0;
156 if (!**r->in.data)
157 return 0;
158 return ***r->in.data;
161 struct echo_TestSleep_private {
162 struct dcesrv_call_state *dce_call;
163 struct echo_TestSleep *r;
166 static void echo_TestSleep_handler(struct tevent_context *ev, struct tevent_timer *te,
167 struct timeval t, void *private_data)
169 struct echo_TestSleep_private *p = talloc_get_type(private_data,
170 struct echo_TestSleep_private);
171 struct echo_TestSleep *r = p->r;
173 r->out.result = r->in.seconds;
175 dcesrv_async_reply(p->dce_call);
178 static long dcesrv_echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSleep *r)
180 struct echo_TestSleep_private *p;
182 if (!(dce_call->state_flags & DCESRV_CALL_STATE_FLAG_MAY_ASYNC)) {
183 /* we're not allowed to reply async */
184 sleep(r->in.seconds);
185 return r->in.seconds;
188 /* we're allowed to reply async */
189 p = talloc(mem_ctx, struct echo_TestSleep_private);
190 if (!p) {
191 return 0;
194 p->dce_call = dce_call;
195 p->r = r;
197 tevent_add_timer(dce_call->event_ctx, p,
198 timeval_add(&dce_call->time, r->in.seconds, 0),
199 echo_TestSleep_handler, p);
201 dce_call->state_flags |= DCESRV_CALL_STATE_FLAG_ASYNC;
202 return 0;
205 /* include the generated boilerplate */
206 #include "librpc/gen_ndr/ndr_echo_s.c"