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/cli_epmapper.h"
24 #include "../librpc/gen_ndr/ndr_lsa.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_t res_tower;
34 struct epm_twr_p_t towers;
35 struct policy_handle entry_handle;
36 struct ndr_syntax_id abstract_syntax;
38 TALLOC_CTX *tmp_ctx = talloc_stackframe();
42 abstract_syntax = ndr_table_lsarpc.syntax_id;
44 map_binding.transport = NCACN_NP;
45 map_binding.object = abstract_syntax;
46 map_binding.host = "127.0.0.1"; /* needed? */
47 map_binding.endpoint = "0"; /* correct? needed? */
49 status = dcerpc_binding_build_tower(tmp_ctx, &map_binding,
51 if (!NT_STATUS_IS_OK(status)) {
52 d_fprintf(stderr, "dcerpc_binding_build_tower returned %s\n",
57 towers.twr = &res_tower;
59 ZERO_STRUCT(entry_handle);
60 status = dcerpc_epm_Map(
61 b, tmp_ctx, &abstract_syntax.uuid,
62 &map_tower, &entry_handle, 1,
63 &num_towers, &towers, &result);
64 if (!NT_STATUS_IS_OK(status)) {
65 d_fprintf(stderr, "dcerpc_epm_Map returned %s\n",
70 if (result != EPMAPPER_STATUS_OK) {
71 d_fprintf(stderr, "epm_Map returned %u (0x%08X)\n",
73 return NT_STATUS_UNSUCCESSFUL;
79 static NTSTATUS cmd_epmapper_lookup(struct rpc_pipe_client *p,
81 int argc, const char **argv)
83 struct dcerpc_binding_handle *b = p->binding_handle;
84 struct policy_handle entry_handle;
86 ZERO_STRUCT(entry_handle);
89 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
91 struct epm_entry_t entry;
94 struct dcerpc_binding *binding;
97 status = dcerpc_epm_Lookup(b, tmp_ctx,
101 0, /* rpc_c_vers_all */
104 &num_entries, &entry,
106 if (!NT_STATUS_IS_OK(status)) {
107 d_fprintf(stderr, "dcerpc_epm_Lookup returned %s\n",
112 if (result == EPMAPPER_STATUS_NO_MORE_ENTRIES) {
113 d_fprintf(stderr, "epm_Lookup no more entries\n");
117 if (result != EPMAPPER_STATUS_OK) {
118 d_fprintf(stderr, "epm_Lookup returned %u (0x%08X)\n",
123 if (num_entries != 1) {
124 d_fprintf(stderr, "epm_Lookup returned %d "
125 "entries, expected one\n", (int)num_entries);
129 guid_string = GUID_string(tmp_ctx, &entry.object);
130 if (guid_string == NULL) {
134 status = dcerpc_binding_from_tower(tmp_ctx, &entry.tower->tower,
136 if (!NT_STATUS_IS_OK(status)) {
140 d_printf("%s %s: %s\n", guid_string,
141 dcerpc_binding_string(tmp_ctx, binding),
144 TALLOC_FREE(tmp_ctx);
151 /* List of commands exported by this module */
153 struct cmd_set epmapper_commands[] = {
157 { "epmmap", RPC_RTYPE_NTSTATUS, cmd_epmapper_map, NULL,
158 &ndr_table_epmapper.syntax_id, NULL, "Map a binding", "" },
159 { "epmlookup", RPC_RTYPE_NTSTATUS, cmd_epmapper_lookup, NULL,
160 &ndr_table_epmapper.syntax_id, NULL, "Lookup bindings", "" },