Return 0 domains from enum_trusteddoms
[Samba.git] / source3 / rpcclient / cmd_epmapper.c
blobcb334165f26d3fe492ca9a51a9271222cafc1da7
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"
24 static NTSTATUS cmd_epmapper_map(struct rpc_pipe_client *p,
25 TALLOC_CTX *mem_ctx,
26 int argc, const char **argv)
28 struct dcerpc_binding map_binding;
29 struct epm_twr_t map_tower;
30 struct epm_twr_t res_tower;
31 struct epm_twr_p_t towers;
32 struct policy_handle entry_handle;
33 struct ndr_syntax_id abstract_syntax;
34 uint32_t num_towers;
35 TALLOC_CTX *tmp_ctx = talloc_stackframe();
36 NTSTATUS status;
38 abstract_syntax = ndr_table_lsarpc.syntax_id;
40 map_binding.transport = NCACN_NP;
41 map_binding.object = abstract_syntax;
42 map_binding.host = "127.0.0.1"; /* needed? */
43 map_binding.endpoint = "0"; /* correct? needed? */
45 status = dcerpc_binding_build_tower(tmp_ctx, &map_binding,
46 &map_tower.tower);
47 if (!NT_STATUS_IS_OK(status)) {
48 d_fprintf(stderr, "dcerpc_binding_build_tower returned %s\n",
49 nt_errstr(status));
50 return status;
53 towers.twr = &res_tower;
55 ZERO_STRUCT(entry_handle);
56 status = rpccli_epm_Map(
57 p, tmp_ctx, &abstract_syntax.uuid,
58 &map_tower, &entry_handle, 1,
59 &num_towers, &towers);
61 return status;
64 static NTSTATUS cmd_epmapper_lookup(struct rpc_pipe_client *p,
65 TALLOC_CTX *mem_ctx,
66 int argc, const char **argv)
68 struct policy_handle entry_handle;
70 ZERO_STRUCT(entry_handle);
72 while (true) {
73 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
74 uint32_t num_entries;
75 struct epm_entry_t entry;
76 NTSTATUS status;
77 char *guid_string;
78 struct dcerpc_binding *binding;
80 status = rpccli_epm_Lookup(p, tmp_ctx,
81 0, /* rpc_c_ep_all */
82 NULL,
83 NULL,
84 0, /* rpc_c_vers_all */
85 &entry_handle,
86 1, /* max_ents */
87 &num_entries, &entry);
88 if (!NT_STATUS_IS_OK(status)) {
89 d_fprintf(stderr, "rpccli_epm_Lookup returned %s\n",
90 nt_errstr(status));
91 break;
94 if (num_entries != 1) {
95 d_fprintf(stderr, "rpccli_epm_Lookup returned %d "
96 "entries, expected one\n", (int)num_entries);
97 break;
100 guid_string = GUID_string(tmp_ctx, &entry.object);
101 if (guid_string == NULL) {
102 break;
105 status = dcerpc_binding_from_tower(tmp_ctx, &entry.tower->tower,
106 &binding);
107 if (!NT_STATUS_IS_OK(status)) {
108 break;
111 d_printf("%s %s: %s\n", guid_string,
112 dcerpc_binding_string(tmp_ctx, binding),
113 entry.annotation);
115 TALLOC_FREE(tmp_ctx);
118 return NT_STATUS_OK;
122 /* List of commands exported by this module */
124 struct cmd_set epmapper_commands[] = {
126 { "EPMAPPER" },
128 { "epmmap", RPC_RTYPE_NTSTATUS, cmd_epmapper_map, NULL,
129 &ndr_table_epmapper.syntax_id, NULL, "Map a binding", "" },
130 { "epmlookup", RPC_RTYPE_NTSTATUS, cmd_epmapper_lookup, NULL,
131 &ndr_table_epmapper.syntax_id, NULL, "Lookup bindings", "" },
132 { NULL }