1 ###################################################
2 # server boilerplate generator
3 # Copyright tridge@samba.org 2003
4 # Copyright metze@samba.org 2004
5 # released under the GNU GPL
19 #####################################################
20 # generate the switch statement for function dispatch
21 sub gen_dispatch_switch
($)
26 foreach my $d (@
{$data}) {
27 next if ($d->{TYPE
} ne "FUNCTION");
29 pidl
"\tcase $count: {\n";
30 pidl
"\t\tstruct $d->{NAME} *r2 = r;\n";
31 pidl
"\t\tif (DEBUGLEVEL > 10) {\n";
32 pidl
"\t\t\tNDR_PRINT_FUNCTION_DEBUG($d->{NAME}, NDR_IN, r2);\n";
34 if ($d->{RETURN_TYPE
} && $d->{RETURN_TYPE
} ne "void") {
35 pidl
"\t\tr2->out.result = $d->{NAME}(dce_call, mem_ctx, r2);\n";
37 pidl
"\t\t$d->{NAME}(dce_call, mem_ctx, r2);\n";
39 pidl
"\t\tif (DEBUGLEVEL > 10 && dce_call->fault_code == 0) {\n";
40 pidl
"\t\t\tNDR_PRINT_FUNCTION_DEBUG($d->{NAME}, NDR_OUT | NDR_SET_VALUES, r2);\n";
42 pidl
"\t\tif (dce_call->fault_code != 0) {\n";
43 pidl
"\t\t\tDEBUG(2,(\"dcerpc_fault %s in $d->{NAME}\\n\", dcerpc_errstr(mem_ctx, dce_call->fault_code)));\n";
45 pidl
"\t\tbreak;\n\t}\n";
51 #####################################################################
52 # produce boilerplate code for a interface
53 sub Boilerplate_Iface
($)
55 my($interface) = shift;
56 my($data) = $interface->{DATA
};
57 my $name = $interface->{NAME
};
59 my $uuid = util
::make_str
($interface->{PROPERTIES
}->{uuid
});
60 my $if_version = $interface->{PROPERTIES
}->{version
};
63 static NTSTATUS $name\__op_bind(struct dcesrv_call_state *dce_call, const struct dcesrv_interface *iface)
65 #ifdef DCESRV_INTERFACE_$uname\_BIND
66 return DCESRV_INTERFACE_$uname\_BIND(dce_call,iface);
72 static void $name\__op_unbind(struct dcesrv_connection *dce_conn, const struct dcesrv_interface *iface)
74 #ifdef DCESRV_INTERFACE_$uname\_UNBIND
75 DCESRV_INTERFACE_$uname\_UNBIND(dce_conn,iface);
81 static NTSTATUS $name\__op_ndr_pull(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_pull *pull, void **r)
84 uint16 opnum = dce_call->pkt.u.request.opnum;
86 dce_call->fault_code = 0;
88 if (opnum >= dcerpc_table_$name.num_calls) {
89 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
90 return NT_STATUS_NET_WRITE_FAULT;
93 *r = talloc_size(mem_ctx, dcerpc_table_$name.calls[opnum].struct_size);
95 return NT_STATUS_NO_MEMORY;
98 /* unravel the NDR for the packet */
99 status = dcerpc_table_$name.calls[opnum].ndr_pull(pull, NDR_IN, *r);
100 if (!NT_STATUS_IS_OK(status)) {
101 dcerpc_log_packet(&dcerpc_table_$name, opnum, NDR_IN,
102 &dce_call->pkt.u.request.stub_and_verifier);
103 dce_call->fault_code = DCERPC_FAULT_NDR;
104 return NT_STATUS_NET_WRITE_FAULT;
110 static NTSTATUS $name\__op_dispatch(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
112 uint16 opnum = dce_call->pkt.u.request.opnum;
114 dce_call->fault_code = 0;
118 gen_dispatch_switch
($data);
122 dce_call->fault_code = DCERPC_FAULT_OP_RNG_ERROR;
126 if (dce_call->fault_code != 0) {
127 return NT_STATUS_NET_WRITE_FAULT;
133 static NTSTATUS $name\__op_ndr_push(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct ndr_push *push, void *r)
136 uint16 opnum = dce_call->pkt.u.request.opnum;
138 status = dcerpc_table_$name.calls[opnum].ndr_push(push, NDR_OUT, r);
139 if (!NT_STATUS_IS_OK(status)) {
140 dce_call->fault_code = DCERPC_FAULT_NDR;
141 return NT_STATUS_NET_WRITE_FAULT;
147 static const struct dcesrv_interface $name\_interface = {
161 #####################################################################
162 # produce boilerplate code for an endpoint server
163 sub Boilerplate_Ep_Server
($)
165 my($interface) = shift;
166 my $name = $interface->{NAME
};
167 my $uname = uc $name;
170 static NTSTATUS $name\__op_init_server(struct dcesrv_context *dce_ctx, const struct dcesrv_endpoint_server *ep_server)
174 for (i=0;i<dcerpc_table_$name.endpoints->count;i++) {
176 const char *name = dcerpc_table_$name.endpoints->names[i];
178 ret = dcesrv_interface_register(dce_ctx, name, &$name\_interface, NULL);
179 if (!NT_STATUS_IS_OK(ret)) {
180 DEBUG(1,(\"$name\_op_init_server: failed to register endpoint \'%s\'\\n\",name));
188 static BOOL $name\__op_interface_by_uuid(struct dcesrv_interface *iface, const char *uuid, uint32 if_version)
190 if ($name\_interface.if_version == if_version &&
191 strcmp($name\_interface.uuid, uuid)==0) {
192 memcpy(iface,&$name\_interface, sizeof(*iface));
199 static BOOL $name\__op_interface_by_name(struct dcesrv_interface *iface, const char *name)
201 if (strcmp($name\_interface.name, name)==0) {
202 memcpy(iface,&$name\_interface, sizeof(*iface));
209 NTSTATUS dcerpc_server_$name\_init(void)
212 struct dcesrv_endpoint_server ep_server;
214 /* fill in our name */
215 ep_server.name = \"$name\";
217 /* fill in all the operations */
218 ep_server.init_server = $name\__op_init_server;
220 ep_server.interface_by_uuid = $name\__op_interface_by_uuid;
221 ep_server.interface_by_name = $name\__op_interface_by_name;
223 /* register ourselves with the DCERPC subsystem. */
224 ret = dcerpc_register_ep_server(&ep_server);
226 if (!NT_STATUS_IS_OK(ret)) {
227 DEBUG(0,(\"Failed to register \'$name\' endpoint server!\\n\"));
237 #####################################################################
238 # parse a parsed IDL structure back into an IDL file
239 sub ParseInterface
($)
241 my($interface) = shift;
242 my($data) = $interface->{DATA
};
247 if (!defined $interface->{PROPERTIES
}->{uuid
}) {
251 if (!defined $interface->{PROPERTIES
}->{version
}) {
252 $interface->{PROPERTIES
}->{version
} = "0.0";
255 foreach my $d (@
{$data}) {
256 if ($d->{TYPE
} eq "FUNCTION") { $count++; }
263 $res = "/* dcerpc server boilerplate generated by pidl */\n\n";
264 Boilerplate_Iface
($interface);
265 Boilerplate_Ep_Server
($interface);