2 Unix SMB/CIFS implementation.
5 Copyright (C) Volker Lendecke 2009
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_epmapper_c.h"
24 #include "librpc/ndr/ndr_table.h"
26 static NTSTATUS
cmd_epmapper_map(struct rpc_pipe_client
*p
,
28 int argc
, const char **argv
)
30 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
31 struct dcerpc_binding
*map_binding
;
32 struct epm_twr_t map_tower
;
33 struct epm_twr_p_t towers
[500];
34 struct policy_handle entry_handle
;
35 struct ndr_syntax_id abstract_syntax
;
37 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
41 const struct ndr_interface_list
*l
;
42 const char *interface_name
= "lsarpc";
43 enum dcerpc_transport_t transport
= NCACN_NP
;
45 struct GUID object_uuid
= GUID_zero();
49 "Usage: %s [interface_name] [transport] "
56 interface_name
= argv
[1];
59 for (l
= ndr_table_list(); l
!= NULL
; l
= l
->next
) {
61 ok
= strequal(interface_name
, l
->table
->name
);
63 abstract_syntax
= l
->table
->syntax_id
;
69 d_fprintf(stderr
, "unknown interface: %s\n",
71 status
= NT_STATUS_UNSUCCESSFUL
;
76 transport
= dcerpc_transport_by_name(argv
[2]);
77 if (transport
== NCA_UNKNOWN
) {
78 d_fprintf(stderr
, "unknown transport: %s\n",
80 status
= NT_STATUS_UNSUCCESSFUL
;
86 status
= GUID_from_string(argv
[3], &object_uuid
);
87 if (!NT_STATUS_IS_OK(status
)) {
92 /* 127.0.0.1[0] => correct? needed? */
93 status
= dcerpc_parse_binding(tmp_ctx
, "ncacn_np:127.0.0.1[0]",
95 if (!NT_STATUS_IS_OK(status
)) {
96 d_fprintf(stderr
, "dcerpc_parse_binding returned %s\n",
101 status
= dcerpc_binding_set_transport(map_binding
, transport
);
102 if (!NT_STATUS_IS_OK(status
)) {
103 d_fprintf(stderr
, "dcerpc_binding_set_transport returned %s\n",
108 status
= dcerpc_binding_set_abstract_syntax(map_binding
,
110 if (!NT_STATUS_IS_OK(status
)) {
111 d_fprintf(stderr
, "dcerpc_binding_set_abstract_syntax returned %s\n",
116 status
= dcerpc_binding_build_tower(tmp_ctx
, map_binding
,
118 if (!NT_STATUS_IS_OK(status
)) {
119 d_fprintf(stderr
, "dcerpc_binding_build_tower returned %s\n",
125 ZERO_STRUCT(entry_handle
);
127 status
= dcerpc_epm_Map(
128 b
, tmp_ctx
, &object_uuid
,
129 &map_tower
, &entry_handle
, ARRAY_SIZE(towers
),
130 &num_towers
, towers
, &result
);
131 if (!NT_STATUS_IS_OK(status
)) {
132 d_fprintf(stderr
, "dcerpc_epm_Map returned %s\n",
137 if (result
!= EPMAPPER_STATUS_OK
) {
138 d_fprintf(stderr
, "epm_Map returned %u (0x%08X)\n",
140 status
= NT_STATUS_UNSUCCESSFUL
;
144 d_printf("num_tower[%u]\n", num_towers
);
146 for (i
=0; i
< num_towers
; i
++) {
147 struct dcerpc_binding
*binding
;
149 if (towers
[i
].twr
== NULL
) {
150 d_fprintf(stderr
, "tower[%u] NULL\n", i
);
154 status
= dcerpc_binding_from_tower(tmp_ctx
, &towers
[i
].twr
->tower
,
156 if (!NT_STATUS_IS_OK(status
)) {
160 d_printf("tower[%u] %s\n", i
, dcerpc_binding_string(tmp_ctx
, binding
));
163 TALLOC_FREE(tmp_ctx
);
167 static NTSTATUS
cmd_epmapper_lookup(struct rpc_pipe_client
*p
,
169 int argc
, const char **argv
)
171 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
172 struct policy_handle entry_handle
;
174 ZERO_STRUCT(entry_handle
);
177 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
178 uint32_t num_entries
;
179 struct epm_entry_t entry
;
182 struct dcerpc_binding
*binding
;
185 status
= dcerpc_epm_Lookup(b
, tmp_ctx
,
186 0, /* rpc_c_ep_all */
189 0, /* rpc_c_vers_all */
192 &num_entries
, &entry
,
194 if (!NT_STATUS_IS_OK(status
)) {
195 d_fprintf(stderr
, "dcerpc_epm_Lookup returned %s\n",
200 if (result
== EPMAPPER_STATUS_NO_MORE_ENTRIES
) {
201 d_fprintf(stderr
, "epm_Lookup no more entries\n");
205 if (result
!= EPMAPPER_STATUS_OK
) {
206 d_fprintf(stderr
, "epm_Lookup returned %u (0x%08X)\n",
211 if (num_entries
!= 1) {
212 d_fprintf(stderr
, "epm_Lookup returned %d "
213 "entries, expected one\n", (int)num_entries
);
217 guid_string
= GUID_string(tmp_ctx
, &entry
.object
);
218 if (guid_string
== NULL
) {
222 status
= dcerpc_binding_from_tower(tmp_ctx
, &entry
.tower
->tower
,
224 if (!NT_STATUS_IS_OK(status
)) {
228 d_printf("%s %s: %s\n", guid_string
,
229 dcerpc_binding_string(tmp_ctx
, binding
),
232 TALLOC_FREE(tmp_ctx
);
239 /* List of commands exported by this module */
241 struct cmd_set epmapper_commands
[] = {
249 .returntype
= RPC_RTYPE_NTSTATUS
,
250 .ntfn
= cmd_epmapper_map
,
252 .table
= &ndr_table_epmapper
,
254 .description
= "Map a binding",
259 .returntype
= RPC_RTYPE_NTSTATUS
,
260 .ntfn
= cmd_epmapper_lookup
,
262 .table
= &ndr_table_epmapper
,
264 .description
= "Lookup bindings",