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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "system/filesys.h"
26 #include "rpc_server/dcerpc_server.h"
27 #include "librpc/gen_ndr/ndr_echo.h"
28 #include "lib/events/events.h"
31 static NTSTATUS echo_AddOne(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_AddOne *r)
33 *r->out.out_data = r->in.in_data + 1;
37 static NTSTATUS echo_EchoData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_EchoData *r)
43 r->out.out_data = talloc_memdup(mem_ctx, r->in.in_data, r->in.len);
44 if (!r->out.out_data) {
45 return NT_STATUS_NO_MEMORY;
51 static NTSTATUS echo_SinkData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SinkData *r)
56 static NTSTATUS echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
60 r->out.data = talloc_array(mem_ctx, uint8_t, r->in.len);
62 for (i=0;i<r->in.len;i++) {
69 static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
71 r->out.s2 = talloc_strdup(mem_ctx, "this is a test string");
76 static NTSTATUS echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
78 r->out.info = talloc(mem_ctx, union echo_Info);
80 return NT_STATUS_NO_MEMORY;
83 switch (r->in.level) {
85 r->out.info->info1.v = 10;
88 r->out.info->info2.v = 20;
91 r->out.info->info3.v = 30;
94 r->out.info->info4.v = 40;
97 r->out.info->info5.v1 = 50;
98 r->out.info->info5.v2 = 60;
101 r->out.info->info6.v1 = 70;
102 r->out.info->info6.info1.v= 80;
105 r->out.info->info7.v1 = 80;
106 r->out.info->info7.info4.v = 90;
109 return NT_STATUS_INVALID_LEVEL;
115 static NTSTATUS echo_TestEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestEnum *r)
117 r->out.foo2->e1 = ECHO_ENUM2;
121 static NTSTATUS echo_TestSurrounding(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSurrounding *r)
128 r->out.data = talloc(mem_ctx, struct echo_Surrounding);
129 r->out.data->x = 2 * r->in.data->x;
130 r->out.data->surrounding = talloc_zero_array(mem_ctx, uint16_t, r->out.data->x);
135 static uint16_t echo_TestDoublePointer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestDoublePointer *r)
141 return ***r->in.data;
144 struct echo_TestSleep_private {
145 struct dcesrv_call_state *dce_call;
146 struct echo_TestSleep *r;
149 static void echo_TestSleep_handler(struct event_context *ev, struct timed_event *te,
150 struct timeval t, void *private)
152 struct echo_TestSleep_private *p = talloc_get_type(private,
153 struct echo_TestSleep_private);
154 struct echo_TestSleep *r = p->r;
157 r->out.result = r->in.seconds;
159 status = dcesrv_reply(p->dce_call);
160 if (!NT_STATUS_IS_OK(status)) {
161 DEBUG(0,("echo_TestSleep_handler: dcesrv_reply() failed - %s\n",
166 static long echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSleep *r)
168 struct echo_TestSleep_private *p;
170 if (!(dce_call->state_flags & DCESRV_CALL_STATE_FLAG_MAY_ASYNC)) {
171 /* we're not allowed to reply async */
172 sleep(r->in.seconds);
173 return r->in.seconds;
176 /* we're allowed to reply async */
177 p = talloc(mem_ctx, struct echo_TestSleep_private);
182 p->dce_call = dce_call;
185 event_add_timed(dce_call->event_ctx, p,
186 timeval_add(&dce_call->time, r->in.seconds, 0),
187 echo_TestSleep_handler, p);
189 dce_call->state_flags |= DCESRV_CALL_STATE_FLAG_ASYNC;
193 /* include the generated boilerplate */
194 #include "librpc/gen_ndr/ndr_echo_s.c"