1 ###################################################
2 # Samba3 server generator for IDL structures
3 # Copyright jelmer@samba.org 2005-2006
4 # Copyright metze@samba.org 2014
5 # released under the GNU GPL
7 package Parse::Pidl::Samba3::CompatServer;
13 use Parse::Pidl qw(warning error fatal);
14 use Parse::Pidl::Util qw(has_property);
15 use Parse::Pidl::Samba3::ServerNDR qw(CallWithStructExported);
17 use vars qw($VERSION);
23 sub pidl_reset() { $res=""; $res_hdr="", $tabs=""; }
24 sub pidl_return() { my $s = $res; my $h = $res_hdr; pidl_reset(); return ($s, $h) }
25 sub indent() { $tabs.="\t"; }
26 sub deindent() { $tabs = substr($tabs, 1); }
27 sub pidl($) { my ($txt) = @_; $res .= $txt?$tabs.(shift)."\n":"\n"; }
28 sub pidl_hdr($) { $res_hdr .= (shift)."\n"; }
29 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
31 sub ParseFunctionState($$)
35 my $op = "NDR_".uc($fn->{NAME});
37 my $fnprefix = "_s3_compat_$fn->{NAME}";
39 pidl "struct ${fnprefix}_state {";
41 pidl "struct tevent_context *ev;";
42 pidl "struct dcerpc_call_handle *call;";
43 pidl "struct $fn->{NAME} *r;";
49 sub ParseFunctionSend($$)
53 my $op = "NDR_".uc($fn->{NAME});
55 my $fnprefix = "_s3_compat_$fn->{NAME}";
57 pidl "static struct tevent_req *${fnprefix}_send(TALLOC_CTX *mem_ctx,";
58 pidl "\t\t\t\t\tstruct tevent_context *ev,";
59 pidl "\t\t\t\t\tstruct dcerpc_call_handle *call,";
60 pidl "\t\t\t\t\tstruct $fn->{NAME} *r)";
63 pidl "struct tevent_req *req;";
64 pidl "struct ${fnprefix}_state *state;";
65 pidl "struct pipes_struct *p;";
67 pidl "req = tevent_req_create(mem_ctx, &state,";
68 pidl "\t\t\tstruct ${fnprefix}_state);";
69 pidl "if (req == NULL) {";
74 pidl "state->ev = ev;";
75 pidl "state->call = call;";
79 pidl "p = dcerpc_call_handle_get_pipes_struct(call);";
82 my ($s, $h) = CallWithStructExported("p", "r", $fn,
85 return "tevent_req_nomem(${name}, req)";
89 return "return tevent_req_post(req, ev);";
96 pidl "if (p->fault_state) {";
98 pidl "NTSTATUS status = dcerpc_fault_to_nt_status(p->fault_state);";
99 pidl "tevent_req_nterror(status);";
100 pidl "return tevent_req_post(req, ev);";
105 pidl "tevent_req_done(req);";
106 pidl "return tevent_req_post(req, ev);";
112 sub ParseFunctionRecv($$)
116 my $op = "NDR_".uc($fn->{NAME});
118 my $fnprefix = "_s3_compat_$fn->{NAME}";
120 pidl "static NTSTATUS ${fnprefix}_recv(struct tevent_req *req)";
123 pidl "return tevent_req_simple_recv_ntstatus(req);";
129 sub ParseFunction($$)
133 ParseFunctionState($fn, $fn);
134 ParseFunctionSend($fn, $fn);
135 ParseFunctionRecv($fn, $fn);
138 sub ParseInterface($)
142 my $uif = uc($if->{NAME});
144 pidl_hdr "#ifndef __S3COMPAT_$uif\__";
145 pidl_hdr "#define __S3COMPAT_$uif\__";
147 foreach (@{$if->{FUNCTIONS}}) {
148 next if ($_->{PROPERTIES}{noopnum});
149 ParseFunction($if, $_);
153 pidl "static const struct dcerpc_call_entry_point_fns struct _s3_compat_$if->{NAME}_fns[] = {";
157 foreach (@{$if->{FUNCTIONS}}) {
158 next if ($_->{PROPERTIES}{noopnum});
159 my $op = "NDR_".uc($_->{NAME});
160 my $fnprefix = "_s3_compat_$_->{NAME}";
164 pidl ".send_fn = (dcerpc_call_entry_point_send_fn_t)";
165 pidl "\t${fnprefix}_send,";
166 pidl ".recv_fn = (dcerpc_call_entry_point_recv_fn_t)";
167 pidl "\t${fnprefix}_recv,";
176 pidl ".send_fn = NULL,";
177 pidl ".recv_fn = NULL,";
184 pidl "static const struct dcerpc_call_entry_point_vector _s3_compat_$if->{NAME}_epv[] = {";
186 pidl ".name = \"_s3_compat_$if->{NAME}\",";
187 pidl ".table = &ndr_table_$if->{NAME},";
188 pidl ".num_fns = $count,";
189 pidl ".fns = _s3_compat_$if->{NAME}_fns,";
194 if (not has_property($if, "no_srv_register")) {
195 pidl_hdr "struct dcerpc_server;";
196 fn_declare "NTSTATUS dcerpc_server_setup_s3compat_$if->{NAME}(struct dcerpc_server *server)";
199 pidl "return NT_STATUS_NOT_IMPLEMENTED;";
204 pidl_hdr "#endif /* __S3COMPAT_$uif\__ */";
209 my($ndr,$header,$ndr_header) = @_;
214 pidl_hdr " * Unix SMB/CIFS implementation.";
215 pidl_hdr " * server auto-generated by pidl. DO NOT MODIFY!";
218 pidl "#include \"includes.h\"";
219 pidl "#include \"ntdomain.h\"";
220 pidl "#include \"$header\"";
221 pidl_hdr "#include \"$ndr_header\"";
225 ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");