s3:winbindd: Remove unused set_routing_domain()
[samba.git] / source3 / rpcclient / cmd_wkssvc.c
blobb1ffd5fc386c61bb1056b9a068dc8e7c6d3c0a69
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Günther Deschner 2007
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_wkssvc_c.h"
25 static WERROR cmd_wkssvc_wkstagetinfo(struct rpc_pipe_client *cli,
26 TALLOC_CTX *mem_ctx,
27 int argc,
28 const char **argv)
30 NTSTATUS status;
31 WERROR werr;
32 uint32_t level = 100;
33 union wkssvc_NetWkstaInfo info;
34 const char *server_name;
35 struct dcerpc_binding_handle *b = cli->binding_handle;
37 if (argc > 2) {
38 printf("usage: %s <level>\n", argv[0]);
39 return WERR_OK;
42 if (argc > 1) {
43 level = atoi(argv[1]);
46 server_name = cli->desthost;
48 status = dcerpc_wkssvc_NetWkstaGetInfo(b, mem_ctx,
49 server_name,
50 level,
51 &info,
52 &werr);
53 if (!NT_STATUS_IS_OK(status)) {
54 return ntstatus_to_werror(status);
57 return werr;
60 static WERROR cmd_wkssvc_getjoininformation(struct rpc_pipe_client *cli,
61 TALLOC_CTX *mem_ctx,
62 int argc,
63 const char **argv)
65 const char *server_name;
66 const char *name_buffer;
67 enum wkssvc_NetJoinStatus name_type;
68 NTSTATUS status;
69 WERROR werr;
70 struct dcerpc_binding_handle *b = cli->binding_handle;
72 server_name = cli->desthost;
73 name_buffer = "";
75 status = dcerpc_wkssvc_NetrGetJoinInformation(b, mem_ctx,
76 server_name,
77 &name_buffer,
78 &name_type,
79 &werr);
80 if (!NT_STATUS_IS_OK(status)) {
81 return ntstatus_to_werror(status);
84 if (W_ERROR_IS_OK(werr)) {
85 printf("%s (%d)\n", name_buffer, name_type);
88 return werr;
91 static WERROR cmd_wkssvc_messagebuffersend(struct rpc_pipe_client *cli,
92 TALLOC_CTX *mem_ctx,
93 int argc,
94 const char **argv)
96 const char *server_name = cli->desthost;
97 const char *message_name = cli->desthost;
98 const char *message_sender_name = cli->desthost;
99 smb_ucs2_t *message_buffer = NULL;
100 size_t message_size = 0;
101 const char *message = "my message";
102 NTSTATUS status;
103 WERROR werr;
104 struct dcerpc_binding_handle *b = cli->binding_handle;
106 if (argc > 1) {
107 message = argv[1];
110 if (!push_ucs2_talloc(mem_ctx, &message_buffer, message,
111 &message_size))
113 return WERR_NOT_ENOUGH_MEMORY;
116 status = dcerpc_wkssvc_NetrMessageBufferSend(b, mem_ctx,
117 server_name,
118 message_name,
119 message_sender_name,
120 (uint8_t *)message_buffer,
121 message_size,
122 &werr);
123 if (!NT_STATUS_IS_OK(status)) {
124 return ntstatus_to_werror(status);
127 return werr;
130 static WERROR cmd_wkssvc_enumeratecomputernames(struct rpc_pipe_client *cli,
131 TALLOC_CTX *mem_ctx,
132 int argc,
133 const char **argv)
135 const char *server_name;
136 enum wkssvc_ComputerNameType name_type = NetAllComputerNames;
137 NTSTATUS status;
138 struct wkssvc_ComputerNamesCtr *ctr = NULL;
139 WERROR werr;
140 struct dcerpc_binding_handle *b = cli->binding_handle;
142 server_name = cli->desthost;
144 if (argc >= 2) {
145 name_type = atoi(argv[1]);
148 status = dcerpc_wkssvc_NetrEnumerateComputerNames(b, mem_ctx,
149 server_name,
150 name_type, 0,
151 &ctr,
152 &werr);
153 if (!NT_STATUS_IS_OK(status)) {
154 return ntstatus_to_werror(status);
157 if (W_ERROR_IS_OK(werr)) {
158 int i=0;
159 for (i = 0; i < ctr->count; i++) {
160 printf("name: %d %s\n", i, ctr->computer_name->string);
164 return werr;
167 static WERROR cmd_wkssvc_enumerateusers(struct rpc_pipe_client *cli,
168 TALLOC_CTX *mem_ctx,
169 int argc,
170 const char **argv)
172 const char *server_name;
173 NTSTATUS status;
174 struct wkssvc_NetWkstaEnumUsersInfo info;
175 WERROR werr;
176 uint32_t i, num_entries, resume_handle;
177 struct dcerpc_binding_handle *b = cli->binding_handle;
179 server_name = cli->desthost;
181 ZERO_STRUCT(info);
183 if (argc >= 2) {
184 info.level = atoi(argv[1]);
187 status = dcerpc_wkssvc_NetWkstaEnumUsers(b, mem_ctx, server_name,
188 &info, 1000, &num_entries,
189 &resume_handle, &werr);
190 if (!NT_STATUS_IS_OK(status)) {
191 return ntstatus_to_werror(status);
193 if (!W_ERROR_IS_OK(werr)) {
194 return werr;
197 for (i=0; i<num_entries; i++) {
198 const char *user = NULL;
199 switch (info.level) {
200 case 0:
201 user = info.ctr.user0->user0[i].user_name;
202 break;
203 case 1:
204 user = talloc_asprintf(
205 talloc_tos(), "%s\\%s",
206 info.ctr.user1->user1[i].logon_domain,
207 info.ctr.user1->user1[i].user_name);
208 break;
210 printf("%s\n", user ? user : "(null)");
213 return werr;
216 struct cmd_set wkssvc_commands[] = {
219 .name = "WKSSVC",
222 .name = "wkssvc_wkstagetinfo",
223 .returntype = RPC_RTYPE_WERROR,
224 .ntfn = NULL,
225 .wfn = cmd_wkssvc_wkstagetinfo,
226 .table = &ndr_table_wkssvc,
227 .rpc_pipe = NULL,
228 .description = "Query WKSSVC Workstation Information",
229 .usage = "",
232 .name = "wkssvc_getjoininformation",
233 .returntype = RPC_RTYPE_WERROR,
234 .ntfn = NULL,
235 .wfn = cmd_wkssvc_getjoininformation,
236 .table = &ndr_table_wkssvc,
237 .rpc_pipe = NULL,
238 .description = "Query WKSSVC Join Information",
239 .usage = "",
242 .name = "wkssvc_messagebuffersend",
243 .returntype = RPC_RTYPE_WERROR,
244 .ntfn = NULL,
245 .wfn = cmd_wkssvc_messagebuffersend,
246 .table = &ndr_table_wkssvc,
247 .rpc_pipe = NULL,
248 .description = "Send WKSSVC message",
249 .usage = "",
252 .name = "wkssvc_enumeratecomputernames",
253 .returntype = RPC_RTYPE_WERROR,
254 .ntfn = NULL,
255 .wfn = cmd_wkssvc_enumeratecomputernames,
256 .table = &ndr_table_wkssvc,
257 .rpc_pipe = NULL,
258 .description = "Enumerate WKSSVC computer names",
259 .usage = "",
262 .name = "wkssvc_enumerateusers",
263 .returntype = RPC_RTYPE_WERROR,
264 .ntfn = NULL,
265 .wfn = cmd_wkssvc_enumerateusers,
266 .table = &ndr_table_wkssvc,
267 .rpc_pipe = NULL,
268 .description = "Enumerate WKSSVC users",
269 .usage = "",
272 .name =NULL,