tevent: expose tevent_context_init_ops
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_wkssvc.c
blob7ebc0aaa1b031b1e8674ff0e97ca084444048d5e
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_NOMEM;
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[] = {
218 { "WKSSVC" },
219 { "wkssvc_wkstagetinfo", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_wkstagetinfo, &ndr_table_wkssvc, NULL, "Query WKSSVC Workstation Information", "" },
220 { "wkssvc_getjoininformation", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_getjoininformation, &ndr_table_wkssvc, NULL, "Query WKSSVC Join Information", "" },
221 { "wkssvc_messagebuffersend", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_messagebuffersend, &ndr_table_wkssvc, NULL, "Send WKSSVC message", "" },
222 { "wkssvc_enumeratecomputernames", RPC_RTYPE_WERROR, NULL, cmd_wkssvc_enumeratecomputernames, &ndr_table_wkssvc, NULL, "Enumerate WKSSVC computer names", "" },
223 { "wkssvc_enumerateusers", RPC_RTYPE_WERROR, NULL,
224 cmd_wkssvc_enumerateusers, &ndr_table_wkssvc, NULL,
225 "Enumerate WKSSVC users", "" },
226 { NULL }