Debian Codegraph @

pidl/lib/Parse/Pidl/Samba4/NDR/ServerCompat.pm

raw
1 ###################################################
2 # server boilerplate generator
3 # Copyright [email protected] 2003
4 # Copyright [email protected] 2004
5 # Copyright [email protected] 2019
6 # released under the GNU GPL
7
8 package Parse::Pidl::Samba4::NDR::ServerCompat;
9
10 use Exporter;
11 @ISA = qw(Exporter);
12 @EXPORT_OK = qw(Parse);
13
14 use Parse::Pidl::Util qw(print_uuid has_property ParseExpr);
15 use Parse::Pidl::Typelist qw(mapTypeName);
16 use Parse::Pidl qw(error fatal);
17 use Parse::Pidl::NDR qw(ContainsPipe GetNextLevel);
18 use Parse::Pidl::Samba4 qw(ElementStars);
19 use Parse::Pidl::Samba4::Header qw(GenerateFunctionOutEnv);
20
21 use vars qw($VERSION);
22 $VERSION = '1.0';
23
24 use strict;
25
26 sub indent($) { my ($self) = @_; $self->{tabs}.="\t"; }
27 sub deindent($) { my ($self) = @_; $self->{tabs} = substr($self->{tabs}, 1); }
28 sub pidl($$) { my ($self,$txt) = @_; $self->{res} .= $txt ? "$self->{tabs}$txt\n" : "\n"; }
29 sub pidlnoindent($$) { my ($self,$txt) = @_; $self->{res} .= $txt ? "$txt\n" : "\n"; }
30 sub pidl_hdr($$) { my ($self, $txt) = @_; $self->{res_hdr} .= "$txt\n"; }
31 sub pidl_both($$) { my ($self, $txt) = @_; $self->{hdr} .= "$txt\n"; $self->{res_hdr} .= "$txt\n"; }
32
33 sub new($)
34 {
35 my ($class) = shift;
36 my $self = { res => "", res_hdr => "", tabs => "" };
37 bless($self, $class);
38 }
39
40 sub decl_level($$)
41 {
42 my ($self, $e, $l) = @_;
43 my $res = "";
44
45 if (has_property($e, "charset")) {
46 $res .= "const char";
47 } else {
48 $res .= mapTypeName($e->{TYPE});
49 }
50
51 my $stars = ElementStars($e, $l);
52
53 $res .= " ".$stars unless ($stars eq "");
54
55 return $res;
56 }
57
58 sub alloc_out_var($$$$$)
59 {
60 my ($self, $e, $mem_ctx, $name, $env, $alloc_error_block) = @_;
61
62 my $l = $e->{LEVELS}[0];
63
64 # we skip pointer to arrays
65 if ($l->{TYPE} eq "POINTER") {
66 my $nl = GetNextLevel($e, $l);
67 $l = $nl if ($nl->{TYPE} eq "ARRAY");
68 } elsif
69
70 # we don't support multi-dimensional arrays yet
71 ($l->{TYPE} eq "ARRAY") {
72 my $nl = GetNextLevel($e, $l);
73 if ($nl->{TYPE} eq "ARRAY") {
74 fatal($e->{ORIGINAL},"multi-dimensional [out] arrays are not supported!");
75 }
76 } else {
77 # neither pointer nor array, no need to alloc something.
78 return;
79 }
80
81 if ($l->{TYPE} eq "ARRAY") {
82 unless(defined($l->{SIZE_IS})) {
83 error($e->{ORIGINAL}, "No size known for array `$e->{NAME}'");
84 $self->pidl("#error No size known for array `$e->{NAME}'");
85 } else {
86 my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
87 $self->pidl("$name = talloc_zero_array($mem_ctx, " . $self->decl_level($e, 1) . ", $size);");
88 }
89 } else {
90 $self->pidl("$name = talloc_zero($mem_ctx, " . $self->decl_level($e, 1) . ");");
91 }
92
93 $self->pidl("if ($name == NULL) {");
94 $self->indent();
95 foreach (@{$alloc_error_block}) {
96 $self->pidl($_);
97 }
98 $self->deindent();
99 $self->pidl("}");
100 $self->pidl("");
101 }
102
103 sub gen_fn_out($$)
104 {
105 my ($self, $fn, $alloc_error_block) = @_;
106
107 my $hasout = 0;
108 foreach (@{$fn->{ELEMENTS}}) {
109 if (grep(/out/, @{$_->{DIRECTION}})) {
110 $hasout = 1;
111 }
112 }
113
114 if ($hasout) {
115 $self->pidl("NDR_ZERO_STRUCT(r2->out);");
116 }
117
118 foreach (@{$fn->{ELEMENTS}}) {
119 my @dir = @{$_->{DIRECTION}};
120 if (grep(/in/, @dir) and grep(/out/, @dir)) {
121 $self->pidl("r2->out.$_->{NAME} = r2->in.$_->{NAME};");
122 }
123 }
124
125 foreach (@{$fn->{ELEMENTS}}) {
126 next if ContainsPipe($_, $_->{LEVELS}[0]);
127
128 my @dir = @{$_->{DIRECTION}};
129
130 if (grep(/in/, @dir) and grep(/out/, @dir)) {
131 # noop
132 } elsif (grep(/out/, @dir) and not has_property($_, "represent_as")) {
133 my $env = GenerateFunctionOutEnv($fn, "r2->");
134 $self->alloc_out_var($_, "r2", "r2->out.$_->{NAME}", $env, $alloc_error_block);
135 }
136
137 }
138 }
139
140 #####################################################
141 # generate the switch statement for function dispatch
142 sub gen_dispatch_switch($)
143 {
144 my ($self, $interface) = @_;
145
146 my @alloc_error_block = ("status = NT_STATUS_NO_MEMORY;",
147 "p->fault_state = DCERPC_FAULT_CANT_PERFORM;",
148 "goto fail;");
149 foreach my $fn (@{$interface->{FUNCTIONS}}) {
150 next if not defined($fn->{OPNUM});
151
152 my $fname = $fn->{NAME};
153 my $ufname = uc($fname);
154
155 $self->pidl("case $fn->{OPNUM}: { /* $fn->{NAME} */");
156 $self->indent();
157 $self->pidl("struct $fname *r2 = (struct $fname *)r;");
158 $self->pidl("if (DEBUGLEVEL >= 10) {");
159 $self->indent();
160 $self->pidl("NDR_PRINT_FUNCTION_DEBUG($fname, NDR_IN, r2);");
161 $self->deindent();
162 $self->pidl("}");
163
164 $self->gen_fn_out($fn, \@alloc_error_block);
165
166 $self->pidl_hdr("struct $fname;");
167
168 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
169 $self->pidl_hdr(mapTypeName($fn->{RETURN_TYPE}) . " _$fname(struct pipes_struct *p, struct $fname *r);");
170 $self->pidl("r2->out.result = _$fname(p, r2);");
171 } else {
172 $self->pidl_hdr("void _$fname(struct pipes_struct *p, struct $fname *r);");
173 $self->pidl("_$fname(p, r2);");
174 }
175
176 $self->pidl("break;");
177 $self->deindent();
178 $self->pidl("}");
179 }
180 }
181
182 #####################################################
183 # generate the switch statement for function reply
184 sub gen_reply_switch($)
185 {
186 my ($self, $interface) = @_;
187
188 foreach my $fn (@{$interface->{FUNCTIONS}}) {
189 next if not defined($fn->{OPNUM});
190
191 $self->pidl("case $fn->{OPNUM}: { /* $fn->{NAME} */");
192 $self->indent();
193 $self->pidl("struct $fn->{NAME} *r2 = (struct $fn->{NAME} *)r;");
194 $self->pidl("if (dce_call->state_flags & DCESRV_CALL_STATE_FLAG_ASYNC) {");
195 $self->indent();
196 $self->pidl("DEBUG(5,(\"function $fn->{NAME} replied async\\n\"));");
197 $self->deindent();
198 $self->pidl("}");
199 $self->pidl("if (DEBUGLEVEL >= 10 && dce_call->fault_code == 0) {");
200 $self->indent();
201 $self->pidl("NDR_PRINT_FUNCTION_DEBUG($fn->{NAME}, NDR_OUT | NDR_SET_VALUES, r2);");
202 $self->deindent();
203 $self->pidl("}");
204 $self->pidl("if (dce_call->fault_code != 0) {");
205 $self->indent();
206 $self->pidl("DBG_WARNING(\"dcerpc_fault %s in $fn->{NAME}\\n\", dcerpc_errstr(mem_ctx, dce_call->fault_code));");
207 $self->deindent();
208 $self->pidl("}");
209 $self->pidl("break;");
210 $self->deindent();
211 $self->pidl("}");
212 }
213 }
214
215 #####################################################################
216 # produce boilerplate code for a interface
217 sub boilerplate_iface($)
218 {
219 my ($self, $interface) = @_;
220
221 my $name = $interface->{NAME};
222 my $uname = uc $name;
223 my $uuid = lc($interface->{UUID});
224 my $if_version = $interface->{VERSION};
225
226 $self->pidl("static NTSTATUS $name\__op_bind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)");
227 $self->pidl("{");
228 $self->indent();
229 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_BIND");
230 $self->pidl("return DCESRV_INTERFACE_$uname\_BIND(context,iface);");
231 $self->pidlnoindent("#else");
232 $self->pidl("return NT_STATUS_OK;");
233 $self->deindent();
234 $self->pidl("#endif");
235 $self->pidl("}");
236 $self->pidl("");
237
238 $self->pidl("static void $name\__op_unbind(struct dcesrv_connection_context *context, const struct dcesrv_interface *iface)");
239 $self->pidl("{");
240 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_UNBIND");
241 $self->indent();
242 $self->pidl("DCESRV_INTERFACE_$uname\_UNBIND(context, iface);");
243 $self->pidlnoindent("#else");
244 $self->pidl("return;");
245 $self->pidlnoindent("#endif");
246 $self->deindent();
247 $self->pidl("}");
248 $self->pidl("");
249
250 $self->pidl_hdr("NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r);");
251 $self->pidl("NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)");
252 $self->pidl("{");
253 $self->indent();
254 $self->pidl("enum ndr_err_code ndr_err;");
255 $self->pidl("uint16_t opnum = dce_call->pkt.u.request.opnum;");
256 $self->pidl("");
257 $self->pidl("dce_call->fault_code = 0;");
258 $self->pidl("");
259 $self->pidl("if (opnum >= ndr_table_$name.num_calls) {");
260 $self->indent();
261 $self->pidl("dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;");
262 $self->pidl("return NT_STATUS_NET_WRITE_FAULT;");
263 $self->deindent();
264 $self->pidl("}");
265 $self->pidl("");
266 $self->pidl("*r = talloc_named(mem_ctx, ndr_table_$name.calls[opnum].struct_size, \"struct %s\", ndr_table_$name.calls[opnum].name);");
267 $self->pidl("NT_STATUS_HAVE_NO_MEMORY(*r);");
268 $self->pidl("");
269 $self->pidl("/* unravel the NDR for the packet */");
270 $self->pidl("ndr_err = ndr_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);");
271 $self->pidl("if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {");
272 $self->indent();
273 $self->pidl("dce_call->fault_code = DCERPC_FAULT_NDR;");
274 $self->pidl("return NT_STATUS_NET_WRITE_FAULT;");
275 $self->deindent();
276 $self->pidl("}");
277 $self->pidl("");
278 $self->pidl("return NT_STATUS_OK;");
279 $self->deindent();
280 $self->pidl("}");
281 $self->pidl("");
282
283 $self->pidl("static NTSTATUS $name\__op_dispatch_internal(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r, enum s3compat_rpc_dispatch dispatch)");
284 $self->pidl("{");
285 $self->indent();
286 $self->pidl("uint16_t opnum = dce_call->pkt.u.request.opnum;");
287 $self->pidl("struct pipes_struct *p = NULL;");
288 $self->pidl("NTSTATUS status = NT_STATUS_OK;");
289 $self->pidl("bool impersonated = false;");
290 $self->pidl("");
291 $self->pidl("/* Retrieve pipes struct */");
292 $self->pidl("p = dcesrv_get_pipes_struct(dce_call->conn);");
293 $self->pidl("p->dce_call = dce_call;");
294 $self->pidl("p->mem_ctx = mem_ctx;");
295 $self->pidl("/* Reset pipes struct fault state */");
296 $self->pidl("p->fault_state = 0;");
297 $self->pidl("");
298
299 $self->pidl("/* Impersonate */");
300 $self->pidl("if (dispatch == S3COMPAT_RPC_DISPATCH_EXTERNAL) {");
301 $self->indent();
302 $self->pidl("impersonated = become_authenticated_pipe_user(dce_call->auth_state->session_info);");
303 $self->pidl("if (!impersonated) {");
304 $self->indent();
305 $self->pidl("dce_call->fault_code = DCERPC_FAULT_ACCESS_DENIED;");
306 $self->pidl("status = NT_STATUS_NET_WRITE_FAULT;");
307 $self->pidl("goto fail;");
308 $self->deindent();
309 $self->pidl("}");
310 $self->deindent();
311 $self->pidl("}");
312 $self->pidl("");
313
314 $self->pidl("switch (opnum) {");
315 $self->gen_dispatch_switch($interface);
316 $self->pidl("default:");
317 $self->indent();
318 $self->pidl("dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;");
319 $self->pidl("break;");
320 $self->deindent();
321 $self->pidl("}");
322 $self->pidl("");
323
324 $self->pidlnoindent("fail:");
325 $self->pidl("/* Unimpersonate */");
326 $self->pidl("if (impersonated) {");
327 $self->indent();
328 $self->pidl("unbecome_authenticated_pipe_user();");
329 $self->deindent();
330 $self->pidl("}");
331 $self->pidl("");
332
333 $self->pidl("p->dce_call = NULL;");
334 $self->pidl("p->mem_ctx = NULL;");
335 $self->pidl("/* Check pipes struct fault state */");
336 $self->pidl("if (p->fault_state != 0) {");
337 $self->indent();
338 $self->pidl("dce_call->fault_code = p->fault_state;");
339 $self->deindent();
340 $self->pidl("}");
341 $self->pidl("if (dce_call->fault_code != 0) {");
342 $self->indent();
343 $self->pidl("status = NT_STATUS_NET_WRITE_FAULT;");
344 $self->deindent();
345 $self->pidl("}");
346 $self->pidl("");
347
348 $self->pidl("return status;");
349 $self->deindent();
350 $self->pidl("}");
351 $self->pidl("");
352
353 $self->pidl_hdr("NTSTATUS $name\__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r);");
354 $self->pidl("NTSTATUS $name\__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)");
355 $self->pidl("{");
356 $self->indent();
357 $self->pidl("return $name\__op_dispatch_internal(dce_call, mem_ctx, r, S3COMPAT_RPC_DISPATCH_EXTERNAL);");
358 $self->deindent();
359 $self->pidl("}");
360 $self->pidl("");
361
362 $self->pidl_hdr("NTSTATUS $name\__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r);");
363 $self->pidl("NTSTATUS $name\__op_reply(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)");
364 $self->pidl("{");
365 $self->indent();
366 $self->pidl("uint16_t opnum = dce_call->pkt.u.request.opnum;");
367 $self->pidl("");
368 $self->pidl("switch (opnum) {");
369 $self->gen_reply_switch($interface);
370 $self->pidl("default:");
371 $self->indent();
372 $self->pidl("dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;");
373 $self->pidl("break;");
374 $self->deindent();
375 $self->pidl("}");
376 $self->pidl("");
377
378 $self->pidl("if (dce_call->fault_code != 0) {");
379 $self->indent();
380 $self->pidl("return NT_STATUS_NET_WRITE_FAULT;");
381 $self->deindent();
382 $self->pidl("}");
383 $self->pidl("");
384 $self->pidl("return NT_STATUS_OK;");
385 $self->deindent();
386 $self->pidl("}");
387 $self->pidl("");
388
389 $self->pidl_hdr("NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r);");
390 $self->pidl("NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, const void *r)");
391 $self->pidl("{");
392 $self->indent();
393 $self->pidl("enum ndr_err_code ndr_err;");
394 $self->pidl("uint16_t opnum = dce_call->pkt.u.request.opnum;");
395 $self->pidl("");
396 $self->pidl("ndr_err = ndr_table_$name.calls[opnum].ndr_push(push, NDR_OUT, r);");
397 $self->pidl("if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {");
398 $self->indent();
399 $self->pidl("dce_call->fault_code = DCERPC_FAULT_NDR;");
400 $self->pidl("return NT_STATUS_NET_WRITE_FAULT;");
401 $self->deindent();
402 $self->pidl("}");
403 $self->pidl("");
404 $self->pidl("return NT_STATUS_OK;");
405 $self->deindent();
406 $self->pidl("}");
407 $self->pidl("");
408
409 ##############################
410 #### LOCAL DISPATCH ####
411 ##############################
412 $self->pidl_hdr("NTSTATUS $name\__op_local(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r);");
413 $self->pidl("NTSTATUS $name\__op_local(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)");
414 $self->pidl("{");
415 $self->indent();
416 $self->pidl("return $name\__op_dispatch_internal(dce_call, mem_ctx, r, S3COMPAT_RPC_DISPATCH_INTERNAL);");
417 $self->deindent();
418 $self->pidl("}");
419 $self->pidl("");
420
421 $self->pidl("static const struct dcesrv_interface dcesrv\_$name\_interface = {");
422 $self->indent();
423 $self->pidl(".name = \"$name\",");
424 $self->pidl(".syntax_id = {".print_uuid($uuid).",$if_version},");
425 $self->pidl(".bind = $name\__op_bind,");
426 $self->pidl(".unbind = $name\__op_unbind,");
427 $self->pidl(".ndr_pull = $name\__op_ndr_pull,");
428 $self->pidl(".dispatch = $name\__op_dispatch,");
429 $self->pidl(".reply = $name\__op_reply,");
430 $self->pidl(".ndr_push = $name\__op_ndr_push,");
431 $self->pidl(".local = $name\__op_local,");
432 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_FLAGS");
433 $self->pidl(".flags = DCESRV_INTERFACE_$uname\_FLAGS");
434 $self->pidlnoindent("#else");
435 $self->pidl(".flags = 0");
436 $self->pidlnoindent("#endif");
437 $self->deindent();
438 $self->pidl("};");
439 $self->pidl("");
440 }
441
442 #####################################################################
443 # produce boilerplate code for an endpoint server
444 sub boilerplate_ep_server($)
445 {
446 my ($self, $interface) = @_;
447 my $name = $interface->{NAME};
448 my $uname = uc $name;
449
450 $self->pidl("static NTSTATUS $name\__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)");
451 $self->pidl("{");
452 $self->indent();
453 $self->pidl("uint32_t i;");
454 $self->pidl("NTSTATUS ret;");
455 $self->pidl("");
456 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_NCACN_NP_SECONDARY_ENDPOINT");
457 $self->pidl("const char *ncacn_np_secondary_endpoint = DCESRV_INTERFACE_$uname\_NCACN_NP_SECONDARY_ENDPOINT;");
458 $self->pidlnoindent("#else");
459 $self->pidl("const char *ncacn_np_secondary_endpoint = NULL;");
460 $self->pidlnoindent("#endif");
461 $self->pidl("");
462 $self->pidl("for (i=0;i<ndr_table_$name.endpoints->count;i++) {");
463 $self->indent();
464 $self->pidl("const char *name = ndr_table_$name.endpoints->names[i];");
465 $self->pidl("");
466 $self->pidl("ret = dcesrv_interface_register(dce_ctx, name, ncacn_np_secondary_endpoint, &dcesrv_$name\_interface, NULL);");
467 $self->pidl("if (!NT_STATUS_IS_OK(ret)) {");
468 $self->indent();
469 $self->pidl("DBG_ERR(\"Failed to register endpoint \'%s\'\\n\",name);");
470 $self->pidl("return ret;");
471 $self->deindent();
472 $self->pidl("}");
473 $self->deindent();
474 $self->pidl("}");
475 $self->pidl("");
476 $self->pidl("return NT_STATUS_OK;");
477 $self->deindent();
478 $self->pidl("}");
479 $self->pidl("");
480
481 $self->pidl("static NTSTATUS $name\__op_shutdown_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)");
482 $self->pidl("{");
483 $self->indent();
484 $self->pidl("return NT_STATUS_OK;");
485 $self->deindent();
486 $self->pidl("}");
487 $self->pidl("");
488
489 $self->pidl("static bool $name\__op_interface_by_uuid(struct dcesrv_interface *iface, const struct GUID *uuid, uint32_t if_version)");
490 $self->pidl("{");
491 $self->indent();
492 $self->pidl("if (dcesrv_$name\_interface.syntax_id.if_version == if_version && GUID_equal(\&dcesrv\_$name\_interface.syntax_id.uuid, uuid)) {");
493 $self->indent();
494 $self->pidl("memcpy(iface,&dcesrv\_$name\_interface, sizeof(*iface));");
495 $self->pidl("return true;");
496 $self->deindent();
497 $self->pidl("}");
498 $self->pidl("");
499 $self->pidl("return false;");
500 $self->deindent();
501 $self->pidl("}");
502 $self->pidl("");
503
504 $self->pidl("static bool $name\__op_interface_by_name(struct dcesrv_interface *iface, const char *name)");
505 $self->pidl("{");
506 $self->indent();
507 $self->pidl("if (strcmp(dcesrv_$name\_interface.name, name)==0) {");
508 $self->indent();
509 $self->pidl("memcpy(iface, &dcesrv_$name\_interface, sizeof(*iface));");
510 $self->pidl("return true;");
511 $self->deindent();
512 $self->pidl("}");
513 $self->pidl("");
514 $self->pidl("return false;");
515 $self->deindent();
516 $self->pidl("}");
517 $self->pidl("");
518
519 $self->pidl("static const struct dcesrv_endpoint_server $name\_ep_server = {");
520 $self->indent();
521 $self->pidl("/* fill in our name */");
522 $self->pidl(".name = \"$name\",");
523 $self->pidl("");
524 $self->pidl("/* Initialization flag */");
525 $self->pidl(".initialized = false,");
526 $self->pidl("");
527 $self->pidl("/* fill in all the operations */");
528 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_INIT_SERVER");
529 $self->pidl(".init_server = DCESRV_INTERFACE_$uname\_INIT_SERVER,");
530 $self->pidlnoindent("#else");
531 $self->pidl(".init_server = $name\__op_init_server,");
532 $self->pidlnoindent("#endif");
533 $self->pidlnoindent("#ifdef DCESRV_INTERFACE_$uname\_SHUTDOWN_SERVER");
534 $self->pidl(".shutdown_server = DCESRV_INTERFACE_$uname\_SHUTDOWN_SERVER,");
535 $self->pidlnoindent("#else");
536 $self->pidl(".shutdown_server = $name\__op_shutdown_server,");
537 $self->pidlnoindent("#endif");
538 $self->pidl(".interface_by_uuid = $name\__op_interface_by_uuid,");
539 $self->pidl(".interface_by_name = $name\__op_interface_by_name");
540 $self->deindent();
541 $self->pidl("};");
542 $self->pidl("");
543
544 $self->pidl("const struct dcesrv_endpoint_server *$name\_get_ep_server(void)");
545 $self->pidl("{");
546 $self->indent();
547 $self->pidl("return &$name\_ep_server;");
548 $self->deindent();
549 $self->pidl("}");
550 }
551
552 #####################################################################
553 # dcerpc server boilerplate from a parsed IDL structure
554 sub parse_interface($)
555 {
556 my ($self, $interface) = @_;
557 my $count = 0;
558 my $uif = uc($interface->{NAME});
559
560
561 $self->pidl_hdr("#ifndef __NDR_${uif}_SCOMPAT_H__");
562 $self->pidl_hdr("#define __NDR_${uif}_SCOMPAT_H__");
563 $self->pidl_hdr("");
564 $self->pidl_hdr("struct pipes_struct;");
565 $self->pidl_hdr("struct dcesrv_endpoint_server;");
566 $self->pidl_hdr("struct dcesrv_call_state;");
567 $self->pidl_hdr("");
568 $self->pidl_hdr("const struct dcesrv_endpoint_server *$interface->{NAME}\_get_ep_server(void);");
569 $self->pidl_hdr("");
570
571 if (!defined $interface->{PROPERTIES}->{uuid}) {
572 $self->pidl_hdr("#endif /* __NDR_${uif}_SCOMPAT_H__ */");
573 return;
574 }
575
576 if (!defined $interface->{PROPERTIES}->{version}) {
577 $interface->{PROPERTIES}->{version} = "0.0";
578 }
579
580 foreach my $fn (@{$interface->{FUNCTIONS}}) {
581 if (defined($fn->{OPNUM})) { $count++; }
582 }
583
584 if ($count == 0) {
585 $self->pidl_hdr("#endif /* __NDR_${uif}_SCOMPAT_H__ */");
586 return;
587 }
588
589 $self->pidl("/* $interface->{NAME} - dcerpc server boilerplate generated by pidl */");
590 $self->boilerplate_iface($interface);
591 $self->boilerplate_ep_server($interface);
592
593 $self->pidl_hdr("#endif /* __NDR_${uif}_SCOMPAT_H__ */");
594 }
595
596 sub Parse($$)
597 {
598 my ($self, $ndr, $h_scompat, $header) = @_;
599
600 $self->pidl("/* s3 compat server functions auto-generated by pidl */");
601 $self->pidl("#include \"$header\"");
602 $self->pidl("#include \"$h_scompat\"");
603
604 $self->pidl("#include <librpc/rpc/dcesrv_core.h>");
605 $self->pidl("#include <rpc_server/rpc_config.h>");
606 $self->pidl("#include <rpc_server/rpc_server.h>");
607 $self->pidl("#include <util/debug.h>");
608 $self->pidl("");
609 $self->pidl("enum s3compat_rpc_dispatch {");
610 $self->indent();
611 $self->pidl("S3COMPAT_RPC_DISPATCH_EXTERNAL = 0x00000001,");
612 $self->pidl("S3COMPAT_RPC_DISPATCH_INTERNAL = 0x00000002,");
613 $self->deindent();
614 $self->pidl("};");
615 $self->pidl("");
616
617 foreach my $x (@{$ndr}) {
618 $self->parse_interface($x) if ($x->{TYPE} eq "INTERFACE" and not defined($x->{PROPERTIES}{object}));
619 }
620
621 return ($self->{res}, $self->{res_hdr});
622 }
623
624 1;