KCC: improved documentation for verify_graph_directed_double_ring
[Samba.git] / source3 / rpcclient / cmd_epmapper.c
blob52144c3922eedbae682dfed7eb135c94d16a77bb
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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/>.
21 #include "includes.h"
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_epmapper_c.h"
24 #include "../librpc/gen_ndr/ndr_lsa.h"
26 static NTSTATUS cmd_epmapper_map(struct rpc_pipe_client *p,
27 TALLOC_CTX *mem_ctx,
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;
36 uint32_t num_towers;
37 TALLOC_CTX *tmp_ctx = talloc_stackframe();
38 NTSTATUS status;
39 uint32_t result;
40 uint32_t i;
42 abstract_syntax = ndr_table_lsarpc.syntax_id;
44 /* 127.0.0.1[0] => correct? needed? */
45 status = dcerpc_parse_binding(tmp_ctx, "ncacn_np:127.0.0.1[0]",
46 &map_binding);
47 if (!NT_STATUS_IS_OK(status)) {
48 d_fprintf(stderr, "dcerpc_parse_binding returned %s\n",
49 nt_errstr(status));
50 goto done;
53 status = dcerpc_binding_set_abstract_syntax(map_binding,
54 &abstract_syntax);
55 if (!NT_STATUS_IS_OK(status)) {
56 d_fprintf(stderr, "dcerpc_binding_set_abstract_syntax returned %s\n",
57 nt_errstr(status));
58 goto done;
61 status = dcerpc_binding_build_tower(tmp_ctx, map_binding,
62 &map_tower.tower);
63 if (!NT_STATUS_IS_OK(status)) {
64 d_fprintf(stderr, "dcerpc_binding_build_tower returned %s\n",
65 nt_errstr(status));
66 goto done;
69 ZERO_STRUCT(towers);
70 ZERO_STRUCT(entry_handle);
72 status = dcerpc_epm_Map(
73 b, tmp_ctx, &abstract_syntax.uuid,
74 &map_tower, &entry_handle, ARRAY_SIZE(towers),
75 &num_towers, towers, &result);
76 if (!NT_STATUS_IS_OK(status)) {
77 d_fprintf(stderr, "dcerpc_epm_Map returned %s\n",
78 nt_errstr(status));
79 goto done;
82 if (result != EPMAPPER_STATUS_OK) {
83 d_fprintf(stderr, "epm_Map returned %u (0x%08X)\n",
84 result, result);
85 status = NT_STATUS_UNSUCCESSFUL;
86 goto done;
89 d_printf("num_tower[%u]\n", num_towers);
91 for (i=0; i < num_towers; i++) {
92 struct dcerpc_binding *binding;
94 if (towers[i].twr == NULL) {
95 d_fprintf(stderr, "tower[%u] NULL\n", i);
96 break;
99 status = dcerpc_binding_from_tower(tmp_ctx, &towers[i].twr->tower,
100 &binding);
101 if (!NT_STATUS_IS_OK(status)) {
102 break;
105 d_printf("tower[%u] %s\n", i, dcerpc_binding_string(tmp_ctx, binding));
107 done:
108 TALLOC_FREE(tmp_ctx);
109 return status;
112 static NTSTATUS cmd_epmapper_lookup(struct rpc_pipe_client *p,
113 TALLOC_CTX *mem_ctx,
114 int argc, const char **argv)
116 struct dcerpc_binding_handle *b = p->binding_handle;
117 struct policy_handle entry_handle;
119 ZERO_STRUCT(entry_handle);
121 while (true) {
122 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
123 uint32_t num_entries;
124 struct epm_entry_t entry;
125 NTSTATUS status;
126 char *guid_string;
127 struct dcerpc_binding *binding;
128 uint32_t result;
130 status = dcerpc_epm_Lookup(b, tmp_ctx,
131 0, /* rpc_c_ep_all */
132 NULL,
133 NULL,
134 0, /* rpc_c_vers_all */
135 &entry_handle,
136 1, /* max_ents */
137 &num_entries, &entry,
138 &result);
139 if (!NT_STATUS_IS_OK(status)) {
140 d_fprintf(stderr, "dcerpc_epm_Lookup returned %s\n",
141 nt_errstr(status));
142 break;
145 if (result == EPMAPPER_STATUS_NO_MORE_ENTRIES) {
146 d_fprintf(stderr, "epm_Lookup no more entries\n");
147 break;
150 if (result != EPMAPPER_STATUS_OK) {
151 d_fprintf(stderr, "epm_Lookup returned %u (0x%08X)\n",
152 result, result);
153 break;
156 if (num_entries != 1) {
157 d_fprintf(stderr, "epm_Lookup returned %d "
158 "entries, expected one\n", (int)num_entries);
159 break;
162 guid_string = GUID_string(tmp_ctx, &entry.object);
163 if (guid_string == NULL) {
164 break;
167 status = dcerpc_binding_from_tower(tmp_ctx, &entry.tower->tower,
168 &binding);
169 if (!NT_STATUS_IS_OK(status)) {
170 break;
173 d_printf("%s %s: %s\n", guid_string,
174 dcerpc_binding_string(tmp_ctx, binding),
175 entry.annotation);
177 TALLOC_FREE(tmp_ctx);
180 return NT_STATUS_OK;
184 /* List of commands exported by this module */
186 struct cmd_set epmapper_commands[] = {
188 { "EPMAPPER" },
190 { "epmmap", RPC_RTYPE_NTSTATUS, cmd_epmapper_map, NULL,
191 &ndr_table_epmapper, NULL, "Map a binding", "" },
192 { "epmlookup", RPC_RTYPE_NTSTATUS, cmd_epmapper_lookup, NULL,
193 &ndr_table_epmapper, NULL, "Lookup bindings", "" },
194 { NULL }