summaryrefslogtreecommitdiffstats
path: root/source3/rpcclient/cmd_wkssvc.c
blob: b1ffd5fc386c61bb1056b9a068dc8e7c6d3c0a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
   Unix SMB/CIFS implementation.
   RPC pipe client

   Copyright (C) Günther Deschner 2007

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "includes.h"
#include "rpcclient.h"
#include "../librpc/gen_ndr/ndr_wkssvc_c.h"

static WERROR cmd_wkssvc_wkstagetinfo(struct rpc_pipe_client *cli,
				      TALLOC_CTX *mem_ctx,
				      int argc,
				      const char **argv)
{
	NTSTATUS status;
	WERROR werr;
	uint32_t level = 100;
	union wkssvc_NetWkstaInfo info;
	const char *server_name;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	if (argc > 2) {
		printf("usage: %s <level>\n", argv[0]);
		return WERR_OK;
	}

	if (argc > 1) {
		level = atoi(argv[1]);
	}

	server_name = cli->desthost;

	status = dcerpc_wkssvc_NetWkstaGetInfo(b, mem_ctx,
					       server_name,
					       level,
					       &info,
					       &werr);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	return werr;
}

static WERROR cmd_wkssvc_getjoininformation(struct rpc_pipe_client *cli,
					    TALLOC_CTX *mem_ctx,
					    int argc,
					    const char **argv)
{
	const char *server_name;
	const char *name_buffer;
	enum wkssvc_NetJoinStatus name_type;
	NTSTATUS status;
	WERROR werr;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	server_name = cli->desthost;
	name_buffer = "";

	status = dcerpc_wkssvc_NetrGetJoinInformation(b, mem_ctx,
						      server_name,
						      &name_buffer,
						      &name_type,
						      &werr);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_IS_OK(werr)) {
		printf("%s (%d)\n", name_buffer, name_type);
	}

	return werr;
}

static WERROR cmd_wkssvc_messagebuffersend(struct rpc_pipe_client *cli,
					   TALLOC_CTX *mem_ctx,
					   int argc,
					   const char **argv)
{
	const char *server_name = cli->desthost;
	const char *message_name = cli->desthost;
	const char *message_sender_name = cli->desthost;
	smb_ucs2_t *message_buffer = NULL;
	size_t message_size = 0;
	const char *message = "my message";
	NTSTATUS status;
	WERROR werr;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	if (argc > 1) {
		message = argv[1];
	}

	if (!push_ucs2_talloc(mem_ctx, &message_buffer, message,
			      &message_size))
	{
		return WERR_NOT_ENOUGH_MEMORY;
	}

	status = dcerpc_wkssvc_NetrMessageBufferSend(b, mem_ctx,
						     server_name,
						     message_name,
						     message_sender_name,
						     (uint8_t *)message_buffer,
						     message_size,
						     &werr);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	return werr;
}

static WERROR cmd_wkssvc_enumeratecomputernames(struct rpc_pipe_client *cli,
						TALLOC_CTX *mem_ctx,
						int argc,
						const char **argv)
{
	const char *server_name;
	enum wkssvc_ComputerNameType name_type = NetAllComputerNames;
	NTSTATUS status;
	struct wkssvc_ComputerNamesCtr *ctr = NULL;
	WERROR werr;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	server_name = cli->desthost;

	if (argc >= 2) {
		name_type = atoi(argv[1]);
	}

	status = dcerpc_wkssvc_NetrEnumerateComputerNames(b, mem_ctx,
							  server_name,
							  name_type, 0,
							  &ctr,
							  &werr);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}

	if (W_ERROR_IS_OK(werr)) {
		int i=0;
		for (i = 0; i < ctr->count; i++) {
			printf("name: %d %s\n", i, ctr->computer_name->string);
		}
	}

	return werr;
}

static WERROR cmd_wkssvc_enumerateusers(struct rpc_pipe_client *cli,
					TALLOC_CTX *mem_ctx,
					int argc,
					const char **argv)
{
	const char *server_name;
	NTSTATUS status;
	struct wkssvc_NetWkstaEnumUsersInfo info;
	WERROR werr;
	uint32_t i, num_entries, resume_handle;
	struct dcerpc_binding_handle *b = cli->binding_handle;

	server_name = cli->desthost;

	ZERO_STRUCT(info);

	if (argc >= 2) {
		info.level = atoi(argv[1]);
	}

	status = dcerpc_wkssvc_NetWkstaEnumUsers(b, mem_ctx, server_name,
						 &info, 1000, &num_entries,
						 &resume_handle, &werr);
	if (!NT_STATUS_IS_OK(status)) {
		return ntstatus_to_werror(status);
	}
	if (!W_ERROR_IS_OK(werr)) {
		return werr;
	}

	for (i=0; i<num_entries; i++) {
		const char *user = NULL;
		switch (info.level) {
		case 0:
			user = info.ctr.user0->user0[i].user_name;
			break;
		case 1:
			user = talloc_asprintf(
				talloc_tos(), "%s\\%s",
				info.ctr.user1->user1[i].logon_domain,
				info.ctr.user1->user1[i].user_name);
			break;
		}
		printf("%s\n", user ? user : "(null)");
	}

	return werr;
}

struct cmd_set wkssvc_commands[] = {

	{
		.name = "WKSSVC",
	},
	{
		.name               = "wkssvc_wkstagetinfo",
		.returntype         = RPC_RTYPE_WERROR,
		.ntfn               = NULL,
		.wfn                = cmd_wkssvc_wkstagetinfo,
		.table              = &ndr_table_wkssvc,
		.rpc_pipe           = NULL,
		.description        = "Query WKSSVC Workstation Information",
		.usage              = "",
	},
	{
		.name               = "wkssvc_getjoininformation",
		.returntype         = RPC_RTYPE_WERROR,
		.ntfn               = NULL,
		.wfn                = cmd_wkssvc_getjoininformation,
		.table              = &ndr_table_wkssvc,
		.rpc_pipe           = NULL,
		.description        = "Query WKSSVC Join Information",
		.usage              = "",
	},
	{
		.name               = "wkssvc_messagebuffersend",
		.returntype         = RPC_RTYPE_WERROR,
		.ntfn               = NULL,
		.wfn                = cmd_wkssvc_messagebuffersend,
		.table              = &ndr_table_wkssvc,
		.rpc_pipe           = NULL,
		.description        = "Send WKSSVC message",
		.usage              = "",
	},
	{
		.name               = "wkssvc_enumeratecomputernames",
		.returntype         = RPC_RTYPE_WERROR,
		.ntfn               = NULL,
		.wfn                = cmd_wkssvc_enumeratecomputernames,
		.table              = &ndr_table_wkssvc,
		.rpc_pipe           = NULL,
		.description        = "Enumerate WKSSVC computer names",
		.usage              = "",
	},
	{
		.name               = "wkssvc_enumerateusers",
		.returntype         = RPC_RTYPE_WERROR,
		.ntfn               = NULL,
		.wfn                = cmd_wkssvc_enumerateusers,
		.table              = &ndr_table_wkssvc,
		.rpc_pipe           = NULL,
		.description        = "Enumerate WKSSVC users",
		.usage              = "",
	},
	{
		.name =NULL,
	},
};