Line data Source code
1 : /* s3 compat server functions auto-generated by pidl */
2 : #include "bin/default/librpc/gen_ndr/ndr_epmapper.h"
3 : #include "bin/default/librpc/gen_ndr/ndr_epmapper_scompat.h"
4 : #include <librpc/rpc/dcesrv_core.h>
5 : #include <rpc_server/rpc_config.h>
6 : #include <rpc_server/rpc_server.h>
7 : #include <util/debug.h>
8 :
9 : enum s3compat_rpc_dispatch {
10 : S3COMPAT_RPC_DISPATCH_EXTERNAL = 0x00000001,
11 : S3COMPAT_RPC_DISPATCH_INTERNAL = 0x00000002,
12 : };
13 :
14 : /* epmapper - dcerpc server boilerplate generated by pidl */
15 438 : static NTSTATUS epmapper__op_bind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
16 : {
17 : #ifdef DCESRV_INTERFACE_EPMAPPER_BIND
18 : return DCESRV_INTERFACE_EPMAPPER_BIND(context,iface);
19 : #else
20 438 : return NT_STATUS_OK;
21 : #endif
22 : }
23 :
24 438 : static void epmapper__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)
25 : {
26 : #ifdef DCESRV_INTERFACE_EPMAPPER_UNBIND
27 : DCESRV_INTERFACE_EPMAPPER_UNBIND(context, iface);
28 : #else
29 438 : return;
30 : #endif
31 : }
32 :
33 756 : NTSTATUS epmapper__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
34 : {
35 0 : enum ndr_err_code ndr_err;
36 756 : uint16_t opnum = dce_call->pkt.u.request.opnum;
37 :
38 756 : dce_call->fault_code = 0;
39 :
40 756 : if (opnum >= ndr_table_epmapper.num_calls) {
41 0 : dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
42 0 : return NT_STATUS_NET_WRITE_FAULT;
43 : }
44 :
45 756 : *r = talloc_named(mem_ctx, ndr_table_epmapper.calls[opnum].struct_size, "struct %s", ndr_table_epmapper.calls[opnum].name);
46 756 : NT_STATUS_HAVE_NO_MEMORY(*r);
47 :
48 : /* unravel the NDR for the packet */
49 756 : ndr_err = ndr_table_epmapper.calls[opnum].ndr_pull(pull, NDR_IN, *r);
50 756 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
51 0 : dce_call->fault_code = DCERPC_FAULT_NDR;
52 0 : return NT_STATUS_NET_WRITE_FAULT;
53 : }
54 :
55 756 : return NT_STATUS_OK;
56 : }
57 :
58 756 : static NTSTATUS epmapper__op_dispatch_internal(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r, enum s3compat_rpc_dispatch dispatch)
59 : {
60 756 : uint16_t opnum = dce_call->pkt.u.request.opnum;
61 756 : struct pipes_struct *p = NULL;
62 756 : NTSTATUS status = NT_STATUS_OK;
63 756 : bool impersonated = false;
64 :
65 : /* Retrieve pipes struct */
66 756 : p = dcesrv_get_pipes_struct(dce_call->conn);
67 756 : p->dce_call = dce_call;
68 756 : p->mem_ctx = mem_ctx;
69 : /* Reset pipes struct fault state */
70 756 : p->fault_state = 0;
71 :
72 : /* Impersonate */
73 756 : if (dispatch == S3COMPAT_RPC_DISPATCH_EXTERNAL) {
74 756 : impersonated = become_authenticated_pipe_user(dce_call->auth_state->session_info);
75 756 : if (!impersonated) {
76 0 : dce_call->fault_code = DCERPC_FAULT_ACCESS_DENIED;
77 0 : status = NT_STATUS_NET_WRITE_FAULT;
78 0 : goto fail;
79 : }
80 : }
81 :
82 756 : switch (opnum) {
83 4 : case 0: { /* epm_Insert */
84 4 : struct epm_Insert *r2 = (struct epm_Insert *)r;
85 4 : if (DEBUGLEVEL >= 10) {
86 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Insert, NDR_IN, r2);
87 : }
88 4 : r2->out.result = _epm_Insert(p, r2);
89 4 : break;
90 : }
91 0 : case 1: { /* epm_Delete */
92 0 : struct epm_Delete *r2 = (struct epm_Delete *)r;
93 0 : if (DEBUGLEVEL >= 10) {
94 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Delete, NDR_IN, r2);
95 : }
96 0 : r2->out.result = _epm_Delete(p, r2);
97 0 : break;
98 : }
99 28 : case 2: { /* epm_Lookup */
100 28 : struct epm_Lookup *r2 = (struct epm_Lookup *)r;
101 28 : if (DEBUGLEVEL >= 10) {
102 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Lookup, NDR_IN, r2);
103 : }
104 28 : NDR_ZERO_STRUCT(r2->out);
105 28 : r2->out.entry_handle = r2->in.entry_handle;
106 28 : r2->out.num_ents = talloc_zero(r2, uint32_t);
107 28 : if (r2->out.num_ents == NULL) {
108 0 : status = NT_STATUS_NO_MEMORY;
109 0 : p->fault_state = DCERPC_FAULT_CANT_PERFORM;
110 0 : goto fail;
111 : }
112 :
113 28 : r2->out.entries = talloc_zero_array(r2, struct epm_entry_t, r2->in.max_ents);
114 28 : if (r2->out.entries == NULL) {
115 0 : status = NT_STATUS_NO_MEMORY;
116 0 : p->fault_state = DCERPC_FAULT_CANT_PERFORM;
117 0 : goto fail;
118 : }
119 :
120 28 : r2->out.result = _epm_Lookup(p, r2);
121 28 : break;
122 : }
123 720 : case 3: { /* epm_Map */
124 720 : struct epm_Map *r2 = (struct epm_Map *)r;
125 720 : if (DEBUGLEVEL >= 10) {
126 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Map, NDR_IN, r2);
127 : }
128 720 : NDR_ZERO_STRUCT(r2->out);
129 720 : r2->out.entry_handle = r2->in.entry_handle;
130 720 : r2->out.num_towers = talloc_zero(r2, uint32_t);
131 720 : if (r2->out.num_towers == NULL) {
132 0 : status = NT_STATUS_NO_MEMORY;
133 0 : p->fault_state = DCERPC_FAULT_CANT_PERFORM;
134 0 : goto fail;
135 : }
136 :
137 720 : r2->out.towers = talloc_zero_array(r2, struct epm_twr_p_t, r2->in.max_towers);
138 720 : if (r2->out.towers == NULL) {
139 0 : status = NT_STATUS_NO_MEMORY;
140 0 : p->fault_state = DCERPC_FAULT_CANT_PERFORM;
141 0 : goto fail;
142 : }
143 :
144 720 : r2->out.result = _epm_Map(p, r2);
145 720 : break;
146 : }
147 4 : case 4: { /* epm_LookupHandleFree */
148 4 : struct epm_LookupHandleFree *r2 = (struct epm_LookupHandleFree *)r;
149 4 : if (DEBUGLEVEL >= 10) {
150 0 : NDR_PRINT_FUNCTION_DEBUG(epm_LookupHandleFree, NDR_IN, r2);
151 : }
152 4 : NDR_ZERO_STRUCT(r2->out);
153 4 : r2->out.entry_handle = r2->in.entry_handle;
154 4 : r2->out.result = _epm_LookupHandleFree(p, r2);
155 4 : break;
156 : }
157 0 : case 5: { /* epm_InqObject */
158 0 : struct epm_InqObject *r2 = (struct epm_InqObject *)r;
159 0 : if (DEBUGLEVEL >= 10) {
160 0 : NDR_PRINT_FUNCTION_DEBUG(epm_InqObject, NDR_IN, r2);
161 : }
162 0 : r2->out.result = _epm_InqObject(p, r2);
163 0 : break;
164 : }
165 0 : case 6: { /* epm_MgmtDelete */
166 0 : struct epm_MgmtDelete *r2 = (struct epm_MgmtDelete *)r;
167 0 : if (DEBUGLEVEL >= 10) {
168 0 : NDR_PRINT_FUNCTION_DEBUG(epm_MgmtDelete, NDR_IN, r2);
169 : }
170 0 : r2->out.result = _epm_MgmtDelete(p, r2);
171 0 : break;
172 : }
173 0 : case 7: { /* epm_MapAuth */
174 0 : struct epm_MapAuth *r2 = (struct epm_MapAuth *)r;
175 0 : if (DEBUGLEVEL >= 10) {
176 0 : NDR_PRINT_FUNCTION_DEBUG(epm_MapAuth, NDR_IN, r2);
177 : }
178 0 : r2->out.result = _epm_MapAuth(p, r2);
179 0 : break;
180 : }
181 0 : default:
182 0 : dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
183 0 : break;
184 : }
185 :
186 756 : fail:
187 : /* Unimpersonate */
188 756 : if (impersonated) {
189 756 : unbecome_authenticated_pipe_user();
190 : }
191 :
192 756 : p->dce_call = NULL;
193 756 : p->mem_ctx = NULL;
194 : /* Check pipes struct fault state */
195 756 : if (p->fault_state != 0) {
196 6 : dce_call->fault_code = p->fault_state;
197 : }
198 756 : if (dce_call->fault_code != 0) {
199 6 : status = NT_STATUS_NET_WRITE_FAULT;
200 : }
201 :
202 756 : return status;
203 : }
204 :
205 756 : NTSTATUS epmapper__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
206 : {
207 756 : return epmapper__op_dispatch_internal(dce_call, mem_ctx, r, S3COMPAT_RPC_DISPATCH_EXTERNAL);
208 : }
209 :
210 750 : NTSTATUS epmapper__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
211 : {
212 750 : uint16_t opnum = dce_call->pkt.u.request.opnum;
213 :
214 750 : switch (opnum) {
215 0 : case 0: { /* epm_Insert */
216 0 : struct epm_Insert *r2 = (struct epm_Insert *)r;
217 0 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
218 0 : DEBUG(5,("function epm_Insert replied async\n"));
219 : }
220 0 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
221 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Insert, NDR_OUT | NDR_SET_VALUES, r2);
222 : }
223 0 : if (dce_call->fault_code != 0) {
224 0 : DBG_WARNING("dcerpc_fault %s in epm_Insert\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
225 : }
226 0 : break;
227 : }
228 0 : case 1: { /* epm_Delete */
229 0 : struct epm_Delete *r2 = (struct epm_Delete *)r;
230 0 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
231 0 : DEBUG(5,("function epm_Delete replied async\n"));
232 : }
233 0 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
234 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Delete, NDR_OUT | NDR_SET_VALUES, r2);
235 : }
236 0 : if (dce_call->fault_code != 0) {
237 0 : DBG_WARNING("dcerpc_fault %s in epm_Delete\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
238 : }
239 0 : break;
240 : }
241 26 : case 2: { /* epm_Lookup */
242 26 : struct epm_Lookup *r2 = (struct epm_Lookup *)r;
243 26 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
244 0 : DEBUG(5,("function epm_Lookup replied async\n"));
245 : }
246 26 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
247 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Lookup, NDR_OUT | NDR_SET_VALUES, r2);
248 : }
249 26 : if (dce_call->fault_code != 0) {
250 0 : DBG_WARNING("dcerpc_fault %s in epm_Lookup\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
251 : }
252 26 : break;
253 : }
254 720 : case 3: { /* epm_Map */
255 720 : struct epm_Map *r2 = (struct epm_Map *)r;
256 720 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
257 0 : DEBUG(5,("function epm_Map replied async\n"));
258 : }
259 720 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
260 0 : NDR_PRINT_FUNCTION_DEBUG(epm_Map, NDR_OUT | NDR_SET_VALUES, r2);
261 : }
262 720 : if (dce_call->fault_code != 0) {
263 0 : DBG_WARNING("dcerpc_fault %s in epm_Map\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
264 : }
265 720 : break;
266 : }
267 4 : case 4: { /* epm_LookupHandleFree */
268 4 : struct epm_LookupHandleFree *r2 = (struct epm_LookupHandleFree *)r;
269 4 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
270 0 : DEBUG(5,("function epm_LookupHandleFree replied async\n"));
271 : }
272 4 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
273 0 : NDR_PRINT_FUNCTION_DEBUG(epm_LookupHandleFree, NDR_OUT | NDR_SET_VALUES, r2);
274 : }
275 4 : if (dce_call->fault_code != 0) {
276 0 : DBG_WARNING("dcerpc_fault %s in epm_LookupHandleFree\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
277 : }
278 4 : break;
279 : }
280 0 : case 5: { /* epm_InqObject */
281 0 : struct epm_InqObject *r2 = (struct epm_InqObject *)r;
282 0 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
283 0 : DEBUG(5,("function epm_InqObject replied async\n"));
284 : }
285 0 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
286 0 : NDR_PRINT_FUNCTION_DEBUG(epm_InqObject, NDR_OUT | NDR_SET_VALUES, r2);
287 : }
288 0 : if (dce_call->fault_code != 0) {
289 0 : DBG_WARNING("dcerpc_fault %s in epm_InqObject\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
290 : }
291 0 : break;
292 : }
293 0 : case 6: { /* epm_MgmtDelete */
294 0 : struct epm_MgmtDelete *r2 = (struct epm_MgmtDelete *)r;
295 0 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
296 0 : DEBUG(5,("function epm_MgmtDelete replied async\n"));
297 : }
298 0 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
299 0 : NDR_PRINT_FUNCTION_DEBUG(epm_MgmtDelete, NDR_OUT | NDR_SET_VALUES, r2);
300 : }
301 0 : if (dce_call->fault_code != 0) {
302 0 : DBG_WARNING("dcerpc_fault %s in epm_MgmtDelete\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
303 : }
304 0 : break;
305 : }
306 0 : case 7: { /* epm_MapAuth */
307 0 : struct epm_MapAuth *r2 = (struct epm_MapAuth *)r;
308 0 : if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {
309 0 : DEBUG(5,("function epm_MapAuth replied async\n"));
310 : }
311 0 : if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {
312 0 : NDR_PRINT_FUNCTION_DEBUG(epm_MapAuth, NDR_OUT | NDR_SET_VALUES, r2);
313 : }
314 0 : if (dce_call->fault_code != 0) {
315 0 : DBG_WARNING("dcerpc_fault %s in epm_MapAuth\n", dcerpc_errstr(mem_ctx, dce_call->fault_code));
316 : }
317 0 : break;
318 : }
319 0 : default:
320 0 : dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
321 0 : break;
322 : }
323 :
324 750 : if (dce_call->fault_code != 0) {
325 0 : return NT_STATUS_NET_WRITE_FAULT;
326 : }
327 :
328 750 : return NT_STATUS_OK;
329 : }
330 :
331 750 : NTSTATUS epmapper__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)
332 : {
333 0 : enum ndr_err_code ndr_err;
334 750 : uint16_t opnum = dce_call->pkt.u.request.opnum;
335 :
336 750 : ndr_err = ndr_table_epmapper.calls[opnum].ndr_push(push, NDR_OUT, r);
337 750 : if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
338 0 : dce_call->fault_code = DCERPC_FAULT_NDR;
339 0 : return NT_STATUS_NET_WRITE_FAULT;
340 : }
341 :
342 750 : return NT_STATUS_OK;
343 : }
344 :
345 0 : NTSTATUS epmapper__op_local(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
346 : {
347 0 : return epmapper__op_dispatch_internal(dce_call, mem_ctx, r, S3COMPAT_RPC_DISPATCH_INTERNAL);
348 : }
349 :
350 : static const struct dcesrv_interface dcesrv_epmapper_interface = {
351 : .name = "epmapper",
352 : .syntax_id = {{0xe1af8308,0x5d1f,0x11c9,{0x91,0xa4},{0x08,0x00,0x2b,0x14,0xa0,0xfa}},3.0},
353 : .bind = epmapper__op_bind,
354 : .unbind = epmapper__op_unbind,
355 : .ndr_pull = epmapper__op_ndr_pull,
356 : .dispatch = epmapper__op_dispatch,
357 : .reply = epmapper__op_reply,
358 : .ndr_push = epmapper__op_ndr_push,
359 : .local = epmapper__op_local,
360 : #ifdef DCESRV_INTERFACE_EPMAPPER_FLAGS
361 : .flags = DCESRV_INTERFACE_EPMAPPER_FLAGS
362 : #else
363 : .flags = 0
364 : #endif
365 : };
366 :
367 30 : static NTSTATUS epmapper__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
368 : {
369 0 : uint32_t i;
370 0 : NTSTATUS ret;
371 :
372 : #ifdef DCESRV_INTERFACE_EPMAPPER_NCACN_NP_SECONDARY_ENDPOINT
373 : const char *ncacn_np_secondary_endpoint = DCESRV_INTERFACE_EPMAPPER_NCACN_NP_SECONDARY_ENDPOINT;
374 : #else
375 30 : const char *ncacn_np_secondary_endpoint = NULL;
376 : #endif
377 :
378 150 : for (i=0;i<ndr_table_epmapper.endpoints->count;i++) {
379 120 : const char *name = ndr_table_epmapper.endpoints->names[i];
380 :
381 120 : ret = dcesrv_interface_register(dce_ctx, name, ncacn_np_secondary_endpoint, &dcesrv_epmapper_interface, NULL);
382 120 : if (!NT_STATUS_IS_OK(ret)) {
383 0 : DBG_ERR("Failed to register endpoint '%s'\n",name);
384 0 : return ret;
385 : }
386 : }
387 :
388 30 : return NT_STATUS_OK;
389 : }
390 :
391 30 : static NTSTATUS epmapper__op_shutdown_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
392 : {
393 30 : return NT_STATUS_OK;
394 : }
395 :
396 0 : static bool epmapper__op_interface_by_uuid(struct dcesrv_interface *iface, const struct GUID *uuid, uint32_t if_version)
397 : {
398 0 : if (dcesrv_epmapper_interface.syntax_id.if_version == if_version && GUID_equal(&dcesrv_epmapper_interface.syntax_id.uuid, uuid)) {
399 0 : memcpy(iface,&dcesrv_epmapper_interface, sizeof(*iface));
400 0 : return true;
401 : }
402 :
403 0 : return false;
404 : }
405 :
406 0 : static bool epmapper__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
407 : {
408 0 : if (strcmp(dcesrv_epmapper_interface.name, name)==0) {
409 0 : memcpy(iface, &dcesrv_epmapper_interface, sizeof(*iface));
410 0 : return true;
411 : }
412 :
413 0 : return false;
414 : }
415 :
416 : static const struct dcesrv_endpoint_server epmapper_ep_server = {
417 : /* fill in our name */
418 : .name = "epmapper",
419 :
420 : /* Initialization flag */
421 : .initialized = false,
422 :
423 : /* fill in all the operations */
424 : #ifdef DCESRV_INTERFACE_EPMAPPER_INIT_SERVER
425 : .init_server = DCESRV_INTERFACE_EPMAPPER_INIT_SERVER,
426 : #else
427 : .init_server = epmapper__op_init_server,
428 : #endif
429 : #ifdef DCESRV_INTERFACE_EPMAPPER_SHUTDOWN_SERVER
430 : .shutdown_server = DCESRV_INTERFACE_EPMAPPER_SHUTDOWN_SERVER,
431 : #else
432 : .shutdown_server = epmapper__op_shutdown_server,
433 : #endif
434 : .interface_by_uuid = epmapper__op_interface_by_uuid,
435 : .interface_by_name = epmapper__op_interface_by_name
436 : };
437 :
438 30 : const struct dcesrv_endpoint_server *epmapper_get_ep_server(void)
439 : {
440 30 : return &epmapper_ep_server;
441 : }
|