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/>.
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;
43 static NTSTATUS
dcesrv_echo_EchoData(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
, struct echo_EchoData
*r
)
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
;
57 static NTSTATUS
dcesrv_echo_SinkData(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
, struct echo_SinkData
*r
)
62 static NTSTATUS
dcesrv_echo_SourceData(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
, struct echo_SourceData
*r
)
66 r
->out
.data
= talloc_array(mem_ctx
, uint8_t, r
->in
.len
);
68 return NT_STATUS_NO_MEMORY
;
71 for (i
=0;i
<r
->in
.len
;i
++) {
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
;
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
);
91 return NT_STATUS_NO_MEMORY
;
94 switch (r
->in
.level
) {
96 r
->out
.info
->info1
.v
= 10;
99 r
->out
.info
->info2
.v
= 20;
102 r
->out
.info
->info3
.v
= 30;
105 r
->out
.info
->info4
.v
= 40;
108 r
->out
.info
->info5
.v1
= 50;
109 r
->out
.info
->info5
.v2
= 60;
112 r
->out
.info
->info6
.v1
= 70;
113 r
->out
.info
->info6
.info1
.v
= 80;
116 r
->out
.info
->info7
.v1
= 80;
117 r
->out
.info
->info7
.info4
.v
= 90;
120 return NT_STATUS_INVALID_LEVEL
;
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
;
132 static NTSTATUS
dcesrv_echo_TestSurrounding(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
, struct echo_TestSurrounding
*r
)
139 r
->out
.data
= talloc(mem_ctx
, struct echo_Surrounding
);
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
;
152 static uint16_t dcesrv_echo_TestDoublePointer(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
, struct echo_TestDoublePointer
*r
)
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
);
194 p
->dce_call
= dce_call
;
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
;
205 /* include the generated boilerplate */
206 #include "librpc/gen_ndr/ndr_echo_s.c"