2 Unix SMB/CIFS implementation.
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/>.
22 #include "rpcclient.h"
23 #include "../librpc/gen_ndr/ndr_wkssvc_c.h"
25 static WERROR
cmd_wkssvc_wkstagetinfo(struct rpc_pipe_client
*cli
,
33 union wkssvc_NetWkstaInfo info
;
34 const char *server_name
;
35 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
38 printf("usage: %s <level>\n", argv
[0]);
43 level
= atoi(argv
[1]);
46 server_name
= cli
->desthost
;
48 status
= dcerpc_wkssvc_NetWkstaGetInfo(b
, mem_ctx
,
53 if (!NT_STATUS_IS_OK(status
)) {
54 return ntstatus_to_werror(status
);
60 static WERROR
cmd_wkssvc_getjoininformation(struct rpc_pipe_client
*cli
,
65 const char *server_name
;
66 const char *name_buffer
;
67 enum wkssvc_NetJoinStatus name_type
;
70 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
72 server_name
= cli
->desthost
;
75 status
= dcerpc_wkssvc_NetrGetJoinInformation(b
, mem_ctx
,
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
);
91 static WERROR
cmd_wkssvc_messagebuffersend(struct rpc_pipe_client
*cli
,
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";
104 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
110 if (!push_ucs2_talloc(mem_ctx
, &message_buffer
, message
,
113 return WERR_NOT_ENOUGH_MEMORY
;
116 status
= dcerpc_wkssvc_NetrMessageBufferSend(b
, mem_ctx
,
120 (uint8_t *)message_buffer
,
123 if (!NT_STATUS_IS_OK(status
)) {
124 return ntstatus_to_werror(status
);
130 static WERROR
cmd_wkssvc_enumeratecomputernames(struct rpc_pipe_client
*cli
,
135 const char *server_name
;
136 enum wkssvc_ComputerNameType name_type
= NetAllComputerNames
;
138 struct wkssvc_ComputerNamesCtr
*ctr
= NULL
;
140 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
142 server_name
= cli
->desthost
;
145 name_type
= atoi(argv
[1]);
148 status
= dcerpc_wkssvc_NetrEnumerateComputerNames(b
, mem_ctx
,
153 if (!NT_STATUS_IS_OK(status
)) {
154 return ntstatus_to_werror(status
);
157 if (W_ERROR_IS_OK(werr
)) {
159 for (i
= 0; i
< ctr
->count
; i
++) {
160 printf("name: %d %s\n", i
, ctr
->computer_name
->string
);
167 static WERROR
cmd_wkssvc_enumerateusers(struct rpc_pipe_client
*cli
,
172 const char *server_name
;
174 struct wkssvc_NetWkstaEnumUsersInfo info
;
176 uint32_t i
, num_entries
, resume_handle
;
177 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
179 server_name
= cli
->desthost
;
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
)) {
197 for (i
=0; i
<num_entries
; i
++) {
198 const char *user
= NULL
;
199 switch (info
.level
) {
201 user
= info
.ctr
.user0
->user0
[i
].user_name
;
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
);
210 printf("%s\n", user
? user
: "(null)");
216 struct cmd_set wkssvc_commands
[] = {
222 .name
= "wkssvc_wkstagetinfo",
223 .returntype
= RPC_RTYPE_WERROR
,
225 .wfn
= cmd_wkssvc_wkstagetinfo
,
226 .table
= &ndr_table_wkssvc
,
228 .description
= "Query WKSSVC Workstation Information",
232 .name
= "wkssvc_getjoininformation",
233 .returntype
= RPC_RTYPE_WERROR
,
235 .wfn
= cmd_wkssvc_getjoininformation
,
236 .table
= &ndr_table_wkssvc
,
238 .description
= "Query WKSSVC Join Information",
242 .name
= "wkssvc_messagebuffersend",
243 .returntype
= RPC_RTYPE_WERROR
,
245 .wfn
= cmd_wkssvc_messagebuffersend
,
246 .table
= &ndr_table_wkssvc
,
248 .description
= "Send WKSSVC message",
252 .name
= "wkssvc_enumeratecomputernames",
253 .returntype
= RPC_RTYPE_WERROR
,
255 .wfn
= cmd_wkssvc_enumeratecomputernames
,
256 .table
= &ndr_table_wkssvc
,
258 .description
= "Enumerate WKSSVC computer names",
262 .name
= "wkssvc_enumerateusers",
263 .returntype
= RPC_RTYPE_WERROR
,
265 .wfn
= cmd_wkssvc_enumerateusers
,
266 .table
= &ndr_table_wkssvc
,
268 .description
= "Enumerate WKSSVC users",