1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
###################################################
# client calls generator
# Copyright tridge@samba.org 2003
# released under the GNU GPL
package IdlClient;
use strict;
my($res);
#####################################################################
# parse a function
sub ParseFunction($)
{
my $fn = shift;
my $name = $fn->{NAME};
my $uname = uc $name;
return if (util::has_property($fn, "local"));
my $objarg;
if (util::has_property($fn, "object")) {
$objarg = "&d->objref->u_objref.u_standard.std.ipid";
# FIXME: Support custom marshalling
$res .= "
struct rpc_request *dcerpc_$name\_send(struct dcom_interface *d, TALLOC_CTX *mem_ctx, struct $name *r)
{
struct dcerpc_pipe *p;
NTSTATUS status = dcom_get_pipe(d, &p);
if (NT_STATUS_IS_ERR(status)) {
return NULL;
}
ZERO_STRUCT(r->in.ORPCthis);
r->in.ORPCthis.version.MajorVersion = 5;
r->in.ORPCthis.version.MinorVersion = 1;
";
} else {
$objarg = "NULL";
$res .= "
struct rpc_request *dcerpc_$name\_send(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{";
}
$res.="
if (p->flags & DCERPC_DEBUG_PRINT_IN) {
NDR_PRINT_IN_DEBUG($name, r);
}
return dcerpc_ndr_request_send(p, $objarg, DCERPC_$uname, mem_ctx,
(ndr_push_flags_fn_t) ndr_push_$name,
(ndr_pull_flags_fn_t) ndr_pull_$name,
r, sizeof(*r));
}
";
if (util::has_property($fn, "object")) {
$res .=
"
NTSTATUS dcerpc_$name(struct dcom_interface *d, TALLOC_CTX *mem_ctx, struct $name *r)
{
struct dcerpc_pipe *p;
NTSTATUS status = dcom_get_pipe(d, &p);
struct rpc_request *req;
if (NT_STATUS_IS_ERR(status)) {
return status;
}
";
$objarg = "d";
} else {
$res .=
"
NTSTATUS dcerpc_$name(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct $name *r)
{
struct rpc_request *req;
NTSTATUS status;
";
$objarg = "p";
}
$res .= "
req = dcerpc_$name\_send($objarg, mem_ctx, r);
if (req == NULL) return NT_STATUS_NO_MEMORY;
status = dcerpc_ndr_request_recv(req);
if (NT_STATUS_IS_OK(status) && (p->flags & DCERPC_DEBUG_PRINT_OUT)) {
NDR_PRINT_OUT_DEBUG($name, r);
}
";
if ($fn->{RETURN_TYPE} eq "NTSTATUS") {
$res .= "\tif (NT_STATUS_IS_OK(status)) status = r->out.result;\n";
}
$res .=
"
return status;
}
";
}
#####################################################################
# parse the interface definitions
sub ParseInterface($)
{
my($interface) = shift;
my($data) = $interface->{DATA};
foreach my $d (@{$data}) {
($d->{TYPE} eq "FUNCTION") &&
ParseFunction($d);
}
}
#####################################################################
# parse a parsed IDL structure back into an IDL file
sub Parse($)
{
my($idl) = shift;
$res = "/* dcerpc client calls generated by pidl */\n\n";
foreach my $x (@{$idl}) {
($x->{TYPE} eq "INTERFACE") &&
ParseInterface($x);
}
return $res;
}
1;
|