1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | RPC pipe client
|
---|
4 |
|
---|
5 | Copyright (C) Andrew Tridgell 1992-1999
|
---|
6 | Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
|
---|
7 | Copyright (C) Tim Potter 2000,2002
|
---|
8 |
|
---|
9 | This program is free software; you can redistribute it and/or modify
|
---|
10 | it under the terms of the GNU General Public License as published by
|
---|
11 | the Free Software Foundation; either version 3 of the License, or
|
---|
12 | (at your option) any later version.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful,
|
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | GNU General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU General Public License
|
---|
20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 | #include "rpcclient.h"
|
---|
25 |
|
---|
26 | /* Display server query info */
|
---|
27 |
|
---|
28 | static char *get_server_type_str(uint32 type)
|
---|
29 | {
|
---|
30 | static fstring typestr;
|
---|
31 | int i;
|
---|
32 |
|
---|
33 | if (type == SV_TYPE_ALL) {
|
---|
34 | fstrcpy(typestr, "All");
|
---|
35 | return typestr;
|
---|
36 | }
|
---|
37 |
|
---|
38 | typestr[0] = 0;
|
---|
39 |
|
---|
40 | for (i = 0; i < 32; i++) {
|
---|
41 | if (type & (1 << i)) {
|
---|
42 | switch (1 << i) {
|
---|
43 | case SV_TYPE_WORKSTATION:
|
---|
44 | fstrcat(typestr, "Wk ");
|
---|
45 | break;
|
---|
46 | case SV_TYPE_SERVER:
|
---|
47 | fstrcat(typestr, "Sv ");
|
---|
48 | break;
|
---|
49 | case SV_TYPE_SQLSERVER:
|
---|
50 | fstrcat(typestr, "Sql ");
|
---|
51 | break;
|
---|
52 | case SV_TYPE_DOMAIN_CTRL:
|
---|
53 | fstrcat(typestr, "PDC ");
|
---|
54 | break;
|
---|
55 | case SV_TYPE_DOMAIN_BAKCTRL:
|
---|
56 | fstrcat(typestr, "BDC ");
|
---|
57 | break;
|
---|
58 | case SV_TYPE_TIME_SOURCE:
|
---|
59 | fstrcat(typestr, "Tim ");
|
---|
60 | break;
|
---|
61 | case SV_TYPE_AFP:
|
---|
62 | fstrcat(typestr, "AFP ");
|
---|
63 | break;
|
---|
64 | case SV_TYPE_NOVELL:
|
---|
65 | fstrcat(typestr, "Nov ");
|
---|
66 | break;
|
---|
67 | case SV_TYPE_DOMAIN_MEMBER:
|
---|
68 | fstrcat(typestr, "Dom ");
|
---|
69 | break;
|
---|
70 | case SV_TYPE_PRINTQ_SERVER:
|
---|
71 | fstrcat(typestr, "PrQ ");
|
---|
72 | break;
|
---|
73 | case SV_TYPE_DIALIN_SERVER:
|
---|
74 | fstrcat(typestr, "Din ");
|
---|
75 | break;
|
---|
76 | case SV_TYPE_SERVER_UNIX:
|
---|
77 | fstrcat(typestr, "Unx ");
|
---|
78 | break;
|
---|
79 | case SV_TYPE_NT:
|
---|
80 | fstrcat(typestr, "NT ");
|
---|
81 | break;
|
---|
82 | case SV_TYPE_WFW:
|
---|
83 | fstrcat(typestr, "Wfw ");
|
---|
84 | break;
|
---|
85 | case SV_TYPE_SERVER_MFPN:
|
---|
86 | fstrcat(typestr, "Mfp ");
|
---|
87 | break;
|
---|
88 | case SV_TYPE_SERVER_NT:
|
---|
89 | fstrcat(typestr, "SNT ");
|
---|
90 | break;
|
---|
91 | case SV_TYPE_POTENTIAL_BROWSER:
|
---|
92 | fstrcat(typestr, "PtB ");
|
---|
93 | break;
|
---|
94 | case SV_TYPE_BACKUP_BROWSER:
|
---|
95 | fstrcat(typestr, "BMB ");
|
---|
96 | break;
|
---|
97 | case SV_TYPE_MASTER_BROWSER:
|
---|
98 | fstrcat(typestr, "LMB ");
|
---|
99 | break;
|
---|
100 | case SV_TYPE_DOMAIN_MASTER:
|
---|
101 | fstrcat(typestr, "DMB ");
|
---|
102 | break;
|
---|
103 | case SV_TYPE_SERVER_OSF:
|
---|
104 | fstrcat(typestr, "OSF ");
|
---|
105 | break;
|
---|
106 | case SV_TYPE_SERVER_VMS:
|
---|
107 | fstrcat(typestr, "VMS ");
|
---|
108 | break;
|
---|
109 | case SV_TYPE_WIN95_PLUS:
|
---|
110 | fstrcat(typestr, "W95 ");
|
---|
111 | break;
|
---|
112 | case SV_TYPE_ALTERNATE_XPORT:
|
---|
113 | fstrcat(typestr, "Xpt ");
|
---|
114 | break;
|
---|
115 | case SV_TYPE_LOCAL_LIST_ONLY:
|
---|
116 | fstrcat(typestr, "Dom ");
|
---|
117 | break;
|
---|
118 | case SV_TYPE_DOMAIN_ENUM:
|
---|
119 | fstrcat(typestr, "Loc ");
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | i = strlen(typestr) - 1;
|
---|
126 |
|
---|
127 | if (typestr[i] == ' ')
|
---|
128 | typestr[i] = 0;
|
---|
129 |
|
---|
130 | return typestr;
|
---|
131 | }
|
---|
132 |
|
---|
133 | static void display_server(const char *sname, uint32 type, const char *comment)
|
---|
134 | {
|
---|
135 | printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
|
---|
136 | comment);
|
---|
137 | }
|
---|
138 |
|
---|
139 | static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
|
---|
140 | {
|
---|
141 | display_server(r->server_name, r->server_type, r->comment);
|
---|
142 |
|
---|
143 | printf("\tplatform_id :\t%d\n", r->platform_id);
|
---|
144 | printf("\tos version :\t%d.%d\n",
|
---|
145 | r->version_major, r->version_minor);
|
---|
146 | printf("\tserver type :\t0x%x\n", r->server_type);
|
---|
147 | }
|
---|
148 |
|
---|
149 | static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
|
---|
150 | {
|
---|
151 | display_server(r->server_name, r->server_type, r->comment);
|
---|
152 |
|
---|
153 | printf("\tplatform_id :\t%d\n", r->platform_id);
|
---|
154 | printf("\tos version :\t%d.%d\n",
|
---|
155 | r->version_major, r->version_minor);
|
---|
156 | printf("\tserver type :\t0x%x\n", r->server_type);
|
---|
157 |
|
---|
158 | printf("\tusers :\t%x\n", r->users);
|
---|
159 | printf("\tdisc, hidden :\t%x, %x\n", r->disc, r->hidden);
|
---|
160 | printf("\tannounce, delta :\t%d, %d\n", r->announce,
|
---|
161 | r->anndelta);
|
---|
162 | printf("\tlicenses :\t%d\n", r->licenses);
|
---|
163 | printf("\tuser path :\t%s\n", r->userpath);
|
---|
164 | }
|
---|
165 |
|
---|
166 | /* Server query info */
|
---|
167 | static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
|
---|
168 | TALLOC_CTX *mem_ctx,
|
---|
169 | int argc, const char **argv)
|
---|
170 | {
|
---|
171 | uint32 info_level = 101;
|
---|
172 | union srvsvc_NetSrvInfo info;
|
---|
173 | WERROR result;
|
---|
174 | NTSTATUS status;
|
---|
175 | const char *server_name;
|
---|
176 |
|
---|
177 | if (argc > 2) {
|
---|
178 | printf("Usage: %s [infolevel]\n", argv[0]);
|
---|
179 | return WERR_OK;
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (argc == 2)
|
---|
183 | info_level = atoi(argv[1]);
|
---|
184 |
|
---|
185 | server_name = talloc_asprintf_strupper_m(mem_ctx, "\\\\%s",
|
---|
186 | cli->cli->desthost);
|
---|
187 | W_ERROR_HAVE_NO_MEMORY(server_name);
|
---|
188 |
|
---|
189 | status = rpccli_srvsvc_NetSrvGetInfo(cli, mem_ctx,
|
---|
190 | server_name,
|
---|
191 | info_level,
|
---|
192 | &info,
|
---|
193 | &result);
|
---|
194 | if (!NT_STATUS_IS_OK(status)) {
|
---|
195 | return ntstatus_to_werror(status);
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (!W_ERROR_IS_OK(result)) {
|
---|
199 | goto done;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /* Display results */
|
---|
203 |
|
---|
204 | switch (info_level) {
|
---|
205 | case 101:
|
---|
206 | display_srv_info_101(info.info101);
|
---|
207 | break;
|
---|
208 | case 102:
|
---|
209 | display_srv_info_102(info.info102);
|
---|
210 | break;
|
---|
211 | default:
|
---|
212 | printf("unsupported info level %d\n", info_level);
|
---|
213 | break;
|
---|
214 | }
|
---|
215 |
|
---|
216 | done:
|
---|
217 | return result;
|
---|
218 | }
|
---|
219 |
|
---|
220 | static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
|
---|
221 | {
|
---|
222 | printf("netname: %s\n", r->name);
|
---|
223 | printf("\tremark:\t%s\n", r->comment);
|
---|
224 | }
|
---|
225 |
|
---|
226 | static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
|
---|
227 | {
|
---|
228 | printf("netname: %s\n", r->name);
|
---|
229 | printf("\tremark:\t%s\n", r->comment);
|
---|
230 | printf("\tpath:\t%s\n", r->path);
|
---|
231 | printf("\tpassword:\t%s\n", r->password);
|
---|
232 | }
|
---|
233 |
|
---|
234 | static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
|
---|
235 | {
|
---|
236 | printf("netname: %s\n", r->name);
|
---|
237 | printf("\tremark:\t%s\n", r->comment);
|
---|
238 | printf("\tpath:\t%s\n", r->path);
|
---|
239 | printf("\tpassword:\t%s\n", r->password);
|
---|
240 |
|
---|
241 | printf("\ttype:\t0x%x\n", r->type);
|
---|
242 | printf("\tperms:\t%d\n", r->permissions);
|
---|
243 | printf("\tmax_uses:\t%d\n", r->max_users);
|
---|
244 | printf("\tnum_uses:\t%d\n", r->current_users);
|
---|
245 |
|
---|
246 | if (r->sd_buf.sd)
|
---|
247 | display_sec_desc(r->sd_buf.sd);
|
---|
248 |
|
---|
249 | }
|
---|
250 |
|
---|
251 | static WERROR cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client *cli,
|
---|
252 | TALLOC_CTX *mem_ctx,
|
---|
253 | int argc, const char **argv,
|
---|
254 | uint32_t opcode)
|
---|
255 | {
|
---|
256 | uint32 info_level = 2;
|
---|
257 | struct srvsvc_NetShareInfoCtr info_ctr;
|
---|
258 | struct srvsvc_NetShareCtr0 ctr0;
|
---|
259 | struct srvsvc_NetShareCtr1 ctr1;
|
---|
260 | struct srvsvc_NetShareCtr2 ctr2;
|
---|
261 | struct srvsvc_NetShareCtr501 ctr501;
|
---|
262 | struct srvsvc_NetShareCtr502 ctr502;
|
---|
263 | struct srvsvc_NetShareCtr1004 ctr1004;
|
---|
264 | struct srvsvc_NetShareCtr1005 ctr1005;
|
---|
265 | struct srvsvc_NetShareCtr1006 ctr1006;
|
---|
266 | struct srvsvc_NetShareCtr1007 ctr1007;
|
---|
267 | struct srvsvc_NetShareCtr1501 ctr1501;
|
---|
268 | WERROR result;
|
---|
269 | NTSTATUS status;
|
---|
270 | uint32_t totalentries = 0;
|
---|
271 | uint32_t resume_handle = 0;
|
---|
272 | uint32_t *resume_handle_p = NULL;
|
---|
273 | uint32 preferred_len = 0xffffffff, i;
|
---|
274 |
|
---|
275 | if (argc > 3) {
|
---|
276 | printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
|
---|
277 | return WERR_OK;
|
---|
278 | }
|
---|
279 |
|
---|
280 | if (argc >= 2) {
|
---|
281 | info_level = atoi(argv[1]);
|
---|
282 | }
|
---|
283 |
|
---|
284 | if (argc == 3) {
|
---|
285 | resume_handle = atoi(argv[2]);
|
---|
286 | resume_handle_p = &resume_handle;
|
---|
287 | }
|
---|
288 |
|
---|
289 | ZERO_STRUCT(info_ctr);
|
---|
290 |
|
---|
291 | info_ctr.level = info_level;
|
---|
292 |
|
---|
293 | switch (info_level) {
|
---|
294 | case 0:
|
---|
295 | ZERO_STRUCT(ctr0);
|
---|
296 | info_ctr.ctr.ctr0 = &ctr0;
|
---|
297 | break;
|
---|
298 | case 1:
|
---|
299 | ZERO_STRUCT(ctr1);
|
---|
300 | info_ctr.ctr.ctr1 = &ctr1;
|
---|
301 | break;
|
---|
302 | case 2:
|
---|
303 | ZERO_STRUCT(ctr2);
|
---|
304 | info_ctr.ctr.ctr2 = &ctr2;
|
---|
305 | break;
|
---|
306 | case 501:
|
---|
307 | ZERO_STRUCT(ctr501);
|
---|
308 | info_ctr.ctr.ctr501 = &ctr501;
|
---|
309 | break;
|
---|
310 | case 502:
|
---|
311 | ZERO_STRUCT(ctr502);
|
---|
312 | info_ctr.ctr.ctr502 = &ctr502;
|
---|
313 | break;
|
---|
314 | case 1004:
|
---|
315 | ZERO_STRUCT(ctr1004);
|
---|
316 | info_ctr.ctr.ctr1004 = &ctr1004;
|
---|
317 | break;
|
---|
318 | case 1005:
|
---|
319 | ZERO_STRUCT(ctr1005);
|
---|
320 | info_ctr.ctr.ctr1005 = &ctr1005;
|
---|
321 | break;
|
---|
322 | case 1006:
|
---|
323 | ZERO_STRUCT(ctr1006);
|
---|
324 | info_ctr.ctr.ctr1006 = &ctr1006;
|
---|
325 | break;
|
---|
326 | case 1007:
|
---|
327 | ZERO_STRUCT(ctr1007);
|
---|
328 | info_ctr.ctr.ctr1007 = &ctr1007;
|
---|
329 | break;
|
---|
330 | case 1501:
|
---|
331 | ZERO_STRUCT(ctr1501);
|
---|
332 | info_ctr.ctr.ctr1501 = &ctr1501;
|
---|
333 | break;
|
---|
334 | }
|
---|
335 |
|
---|
336 | switch (opcode) {
|
---|
337 | case NDR_SRVSVC_NETSHAREENUM:
|
---|
338 | status = rpccli_srvsvc_NetShareEnum(cli, mem_ctx,
|
---|
339 | cli->cli->desthost,
|
---|
340 | &info_ctr,
|
---|
341 | preferred_len,
|
---|
342 | &totalentries,
|
---|
343 | resume_handle_p,
|
---|
344 | &result);
|
---|
345 | break;
|
---|
346 | case NDR_SRVSVC_NETSHAREENUMALL:
|
---|
347 | status = rpccli_srvsvc_NetShareEnumAll(cli, mem_ctx,
|
---|
348 | cli->cli->desthost,
|
---|
349 | &info_ctr,
|
---|
350 | preferred_len,
|
---|
351 | &totalentries,
|
---|
352 | resume_handle_p,
|
---|
353 | &result);
|
---|
354 | break;
|
---|
355 | default:
|
---|
356 | return WERR_INVALID_PARAM;
|
---|
357 | }
|
---|
358 |
|
---|
359 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
360 | goto done;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /* Display results */
|
---|
364 |
|
---|
365 | switch (info_level) {
|
---|
366 | case 1:
|
---|
367 | for (i = 0; i < totalentries; i++)
|
---|
368 | display_share_info_1(&info_ctr.ctr.ctr1->array[i]);
|
---|
369 | break;
|
---|
370 | case 2:
|
---|
371 | for (i = 0; i < totalentries; i++)
|
---|
372 | display_share_info_2(&info_ctr.ctr.ctr2->array[i]);
|
---|
373 | break;
|
---|
374 | case 502:
|
---|
375 | for (i = 0; i < totalentries; i++)
|
---|
376 | display_share_info_502(&info_ctr.ctr.ctr502->array[i]);
|
---|
377 | break;
|
---|
378 | default:
|
---|
379 | printf("unsupported info level %d\n", info_level);
|
---|
380 | break;
|
---|
381 | }
|
---|
382 |
|
---|
383 | done:
|
---|
384 | return result;
|
---|
385 | }
|
---|
386 |
|
---|
387 | static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
|
---|
388 | TALLOC_CTX *mem_ctx,
|
---|
389 | int argc, const char **argv)
|
---|
390 | {
|
---|
391 | return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
|
---|
392 | argc, argv,
|
---|
393 | NDR_SRVSVC_NETSHAREENUM);
|
---|
394 | }
|
---|
395 |
|
---|
396 | static WERROR cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client *cli,
|
---|
397 | TALLOC_CTX *mem_ctx,
|
---|
398 | int argc, const char **argv)
|
---|
399 | {
|
---|
400 | return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
|
---|
401 | argc, argv,
|
---|
402 | NDR_SRVSVC_NETSHAREENUMALL);
|
---|
403 | }
|
---|
404 |
|
---|
405 | static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
|
---|
406 | TALLOC_CTX *mem_ctx,
|
---|
407 | int argc, const char **argv)
|
---|
408 | {
|
---|
409 | uint32 info_level = 502;
|
---|
410 | union srvsvc_NetShareInfo info;
|
---|
411 | WERROR result;
|
---|
412 | NTSTATUS status;
|
---|
413 |
|
---|
414 | if (argc < 2 || argc > 3) {
|
---|
415 | printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
|
---|
416 | return WERR_OK;
|
---|
417 | }
|
---|
418 |
|
---|
419 | if (argc == 3)
|
---|
420 | info_level = atoi(argv[2]);
|
---|
421 |
|
---|
422 | status = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx,
|
---|
423 | cli->cli->desthost,
|
---|
424 | argv[1],
|
---|
425 | info_level,
|
---|
426 | &info,
|
---|
427 | &result);
|
---|
428 |
|
---|
429 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
430 | goto done;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /* Display results */
|
---|
434 |
|
---|
435 | switch (info_level) {
|
---|
436 | case 1:
|
---|
437 | display_share_info_1(info.info1);
|
---|
438 | break;
|
---|
439 | case 2:
|
---|
440 | display_share_info_2(info.info2);
|
---|
441 | break;
|
---|
442 | case 502:
|
---|
443 | display_share_info_502(info.info502);
|
---|
444 | break;
|
---|
445 | default:
|
---|
446 | printf("unsupported info level %d\n", info_level);
|
---|
447 | break;
|
---|
448 | }
|
---|
449 |
|
---|
450 | done:
|
---|
451 | return result;
|
---|
452 | }
|
---|
453 |
|
---|
454 | static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
|
---|
455 | TALLOC_CTX *mem_ctx,
|
---|
456 | int argc, const char **argv)
|
---|
457 | {
|
---|
458 | uint32 info_level = 502;
|
---|
459 | union srvsvc_NetShareInfo info_get;
|
---|
460 | WERROR result;
|
---|
461 | NTSTATUS status;
|
---|
462 | uint32_t parm_err = 0;
|
---|
463 |
|
---|
464 | if (argc > 3) {
|
---|
465 | printf("Usage: %s [sharename] [comment]\n", argv[0]);
|
---|
466 | return WERR_OK;
|
---|
467 | }
|
---|
468 |
|
---|
469 | /* retrieve share info */
|
---|
470 | status = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx,
|
---|
471 | cli->cli->desthost,
|
---|
472 | argv[1],
|
---|
473 | info_level,
|
---|
474 | &info_get,
|
---|
475 | &result);
|
---|
476 |
|
---|
477 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
478 | goto done;
|
---|
479 | }
|
---|
480 |
|
---|
481 | info_get.info502->comment = argv[2];
|
---|
482 |
|
---|
483 | /* set share info */
|
---|
484 | status = rpccli_srvsvc_NetShareSetInfo(cli, mem_ctx,
|
---|
485 | cli->cli->desthost,
|
---|
486 | argv[1],
|
---|
487 | info_level,
|
---|
488 | &info_get,
|
---|
489 | &parm_err,
|
---|
490 | &result);
|
---|
491 |
|
---|
492 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
493 | goto done;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /* re-retrieve share info and display */
|
---|
497 | status = rpccli_srvsvc_NetShareGetInfo(cli, mem_ctx,
|
---|
498 | cli->cli->desthost,
|
---|
499 | argv[1],
|
---|
500 | info_level,
|
---|
501 | &info_get,
|
---|
502 | &result);
|
---|
503 |
|
---|
504 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
505 | goto done;
|
---|
506 | }
|
---|
507 |
|
---|
508 | display_share_info_502(info_get.info502);
|
---|
509 |
|
---|
510 | done:
|
---|
511 | return result;
|
---|
512 | }
|
---|
513 |
|
---|
514 | static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli,
|
---|
515 | TALLOC_CTX *mem_ctx,
|
---|
516 | int argc, const char **argv)
|
---|
517 | {
|
---|
518 | struct srvsvc_NetRemoteTODInfo *tod = NULL;
|
---|
519 | WERROR result;
|
---|
520 | NTSTATUS status;
|
---|
521 |
|
---|
522 | if (argc > 1) {
|
---|
523 | printf("Usage: %s\n", argv[0]);
|
---|
524 | return WERR_OK;
|
---|
525 | }
|
---|
526 |
|
---|
527 | status = rpccli_srvsvc_NetRemoteTOD(cli, mem_ctx,
|
---|
528 | cli->cli->srv_name_slash,
|
---|
529 | &tod,
|
---|
530 | &result);
|
---|
531 | if (!NT_STATUS_IS_OK(status)) {
|
---|
532 | result = ntstatus_to_werror(status);
|
---|
533 | goto done;
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (!W_ERROR_IS_OK(result))
|
---|
537 | goto done;
|
---|
538 |
|
---|
539 | done:
|
---|
540 | return result;
|
---|
541 | }
|
---|
542 |
|
---|
543 | static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
|
---|
544 | TALLOC_CTX *mem_ctx,
|
---|
545 | int argc, const char **argv)
|
---|
546 | {
|
---|
547 | uint32 info_level = 3;
|
---|
548 | struct srvsvc_NetFileInfoCtr info_ctr;
|
---|
549 | struct srvsvc_NetFileCtr3 ctr3;
|
---|
550 | WERROR result;
|
---|
551 | NTSTATUS status;
|
---|
552 | uint32 preferred_len = 0xffff;
|
---|
553 | uint32_t total_entries = 0;
|
---|
554 | uint32_t resume_handle = 0;
|
---|
555 |
|
---|
556 | if (argc > 2) {
|
---|
557 | printf("Usage: %s [infolevel]\n", argv[0]);
|
---|
558 | return WERR_OK;
|
---|
559 | }
|
---|
560 |
|
---|
561 | if (argc == 2)
|
---|
562 | info_level = atoi(argv[1]);
|
---|
563 |
|
---|
564 | ZERO_STRUCT(info_ctr);
|
---|
565 | ZERO_STRUCT(ctr3);
|
---|
566 |
|
---|
567 | info_ctr.level = info_level;
|
---|
568 | info_ctr.ctr.ctr3 = &ctr3;
|
---|
569 |
|
---|
570 | status = rpccli_srvsvc_NetFileEnum(cli, mem_ctx,
|
---|
571 | cli->cli->desthost,
|
---|
572 | NULL,
|
---|
573 | NULL,
|
---|
574 | &info_ctr,
|
---|
575 | preferred_len,
|
---|
576 | &total_entries,
|
---|
577 | &resume_handle,
|
---|
578 | &result);
|
---|
579 |
|
---|
580 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
|
---|
581 | goto done;
|
---|
582 |
|
---|
583 | done:
|
---|
584 | return result;
|
---|
585 | }
|
---|
586 |
|
---|
587 | static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
|
---|
588 | TALLOC_CTX *mem_ctx,
|
---|
589 | int argc, const char **argv)
|
---|
590 | {
|
---|
591 | WERROR result;
|
---|
592 | NTSTATUS status;
|
---|
593 | uint32_t name_type = 9;
|
---|
594 | uint32_t flags = 0;
|
---|
595 |
|
---|
596 | if (argc < 2 || argc > 3) {
|
---|
597 | printf("Usage: %s [sharename] [type]\n", argv[0]);
|
---|
598 | return WERR_OK;
|
---|
599 | }
|
---|
600 |
|
---|
601 | if (argc == 3) {
|
---|
602 | name_type = atoi(argv[2]);
|
---|
603 | }
|
---|
604 |
|
---|
605 | status = rpccli_srvsvc_NetNameValidate(cli, mem_ctx,
|
---|
606 | cli->cli->desthost,
|
---|
607 | argv[1],
|
---|
608 | name_type,
|
---|
609 | flags,
|
---|
610 | &result);
|
---|
611 |
|
---|
612 | if (!W_ERROR_IS_OK(result))
|
---|
613 | goto done;
|
---|
614 |
|
---|
615 | done:
|
---|
616 | return result;
|
---|
617 | }
|
---|
618 |
|
---|
619 | static WERROR cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client *cli,
|
---|
620 | TALLOC_CTX *mem_ctx,
|
---|
621 | int argc, const char **argv)
|
---|
622 | {
|
---|
623 | WERROR result;
|
---|
624 | NTSTATUS status;
|
---|
625 | struct sec_desc_buf *sd_buf = NULL;
|
---|
626 |
|
---|
627 | if (argc < 2 || argc > 4) {
|
---|
628 | printf("Usage: %s [sharename] [file]\n", argv[0]);
|
---|
629 | return WERR_OK;
|
---|
630 | }
|
---|
631 |
|
---|
632 | status = rpccli_srvsvc_NetGetFileSecurity(cli, mem_ctx,
|
---|
633 | cli->cli->desthost,
|
---|
634 | argv[1],
|
---|
635 | argv[2],
|
---|
636 | SECINFO_DACL,
|
---|
637 | &sd_buf,
|
---|
638 | &result);
|
---|
639 |
|
---|
640 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
641 | goto done;
|
---|
642 | }
|
---|
643 |
|
---|
644 | display_sec_desc(sd_buf->sd);
|
---|
645 |
|
---|
646 | done:
|
---|
647 | return result;
|
---|
648 | }
|
---|
649 |
|
---|
650 | static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
|
---|
651 | TALLOC_CTX *mem_ctx,
|
---|
652 | int argc, const char **argv)
|
---|
653 | {
|
---|
654 | WERROR result;
|
---|
655 | NTSTATUS status;
|
---|
656 |
|
---|
657 | if (argc < 2 || argc > 4) {
|
---|
658 | printf("Usage: %s [client] [user]\n", argv[0]);
|
---|
659 | return WERR_OK;
|
---|
660 | }
|
---|
661 |
|
---|
662 | status = rpccli_srvsvc_NetSessDel(cli, mem_ctx,
|
---|
663 | cli->cli->desthost,
|
---|
664 | argv[1],
|
---|
665 | argv[2],
|
---|
666 | &result);
|
---|
667 |
|
---|
668 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
669 | goto done;
|
---|
670 | }
|
---|
671 |
|
---|
672 | done:
|
---|
673 | return result;
|
---|
674 | }
|
---|
675 |
|
---|
676 | static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
|
---|
677 | TALLOC_CTX *mem_ctx,
|
---|
678 | int argc, const char **argv)
|
---|
679 | {
|
---|
680 | WERROR result;
|
---|
681 | NTSTATUS status;
|
---|
682 | struct srvsvc_NetSessInfoCtr info_ctr;
|
---|
683 | struct srvsvc_NetSessCtr0 ctr0;
|
---|
684 | struct srvsvc_NetSessCtr1 ctr1;
|
---|
685 | struct srvsvc_NetSessCtr2 ctr2;
|
---|
686 | struct srvsvc_NetSessCtr10 ctr10;
|
---|
687 | struct srvsvc_NetSessCtr502 ctr502;
|
---|
688 | uint32_t total_entries = 0;
|
---|
689 | uint32_t resume_handle = 0;
|
---|
690 | uint32_t *resume_handle_p = NULL;
|
---|
691 | uint32_t level = 1;
|
---|
692 | const char *client = NULL;
|
---|
693 | const char *user = NULL;
|
---|
694 |
|
---|
695 | if (argc > 6) {
|
---|
696 | printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
|
---|
697 | return WERR_OK;
|
---|
698 | }
|
---|
699 |
|
---|
700 | if (argc >= 2) {
|
---|
701 | client = argv[1];
|
---|
702 | }
|
---|
703 |
|
---|
704 | if (argc >= 3) {
|
---|
705 | user = argv[2];
|
---|
706 | }
|
---|
707 |
|
---|
708 | if (argc >= 4) {
|
---|
709 | level = atoi(argv[3]);
|
---|
710 | }
|
---|
711 |
|
---|
712 | if (argc >= 5) {
|
---|
713 | resume_handle = atoi(argv[4]);
|
---|
714 | resume_handle_p = &resume_handle;
|
---|
715 | }
|
---|
716 |
|
---|
717 | ZERO_STRUCT(info_ctr);
|
---|
718 |
|
---|
719 | info_ctr.level = level;
|
---|
720 |
|
---|
721 | d_printf("trying level: %d\n", level);
|
---|
722 |
|
---|
723 | switch (level) {
|
---|
724 | case 0:
|
---|
725 | ZERO_STRUCT(ctr0);
|
---|
726 | info_ctr.ctr.ctr0 = &ctr0;
|
---|
727 | break;
|
---|
728 | case 1:
|
---|
729 | ZERO_STRUCT(ctr1);
|
---|
730 | info_ctr.ctr.ctr1 = &ctr1;
|
---|
731 | break;
|
---|
732 | case 2:
|
---|
733 | ZERO_STRUCT(ctr2);
|
---|
734 | info_ctr.ctr.ctr2 = &ctr2;
|
---|
735 | break;
|
---|
736 | case 10:
|
---|
737 | ZERO_STRUCT(ctr10);
|
---|
738 | info_ctr.ctr.ctr10 = &ctr10;
|
---|
739 | break;
|
---|
740 | case 502:
|
---|
741 | ZERO_STRUCT(ctr502);
|
---|
742 | info_ctr.ctr.ctr502 = &ctr502;
|
---|
743 | break;
|
---|
744 | }
|
---|
745 |
|
---|
746 | status = rpccli_srvsvc_NetSessEnum(cli, mem_ctx,
|
---|
747 | cli->cli->desthost,
|
---|
748 | client,
|
---|
749 | user,
|
---|
750 | &info_ctr,
|
---|
751 | 0xffffffff,
|
---|
752 | &total_entries,
|
---|
753 | resume_handle_p,
|
---|
754 | &result);
|
---|
755 |
|
---|
756 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
757 | goto done;
|
---|
758 | }
|
---|
759 |
|
---|
760 | done:
|
---|
761 | return result;
|
---|
762 | }
|
---|
763 |
|
---|
764 | static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
|
---|
765 | TALLOC_CTX *mem_ctx,
|
---|
766 | int argc, const char **argv)
|
---|
767 | {
|
---|
768 | struct srvsvc_NetDiskInfo info;
|
---|
769 | WERROR result;
|
---|
770 | NTSTATUS status;
|
---|
771 | uint32_t total_entries = 0;
|
---|
772 | uint32_t resume_handle = 0;
|
---|
773 | uint32_t level = 0;
|
---|
774 |
|
---|
775 | if (argc > 4) {
|
---|
776 | printf("Usage: %s [level] [resume_handle]\n", argv[0]);
|
---|
777 | return WERR_OK;
|
---|
778 | }
|
---|
779 |
|
---|
780 | if (argc >= 2) {
|
---|
781 | level = atoi(argv[1]);
|
---|
782 | }
|
---|
783 |
|
---|
784 | if (argc >= 3) {
|
---|
785 | resume_handle = atoi(argv[2]);
|
---|
786 | }
|
---|
787 |
|
---|
788 | ZERO_STRUCT(info);
|
---|
789 |
|
---|
790 | status = rpccli_srvsvc_NetDiskEnum(cli, mem_ctx,
|
---|
791 | cli->cli->desthost,
|
---|
792 | level,
|
---|
793 | &info,
|
---|
794 | 0xffffffff,
|
---|
795 | &total_entries,
|
---|
796 | &resume_handle,
|
---|
797 | &result);
|
---|
798 |
|
---|
799 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
800 | goto done;
|
---|
801 | }
|
---|
802 |
|
---|
803 | done:
|
---|
804 | return result;
|
---|
805 | }
|
---|
806 |
|
---|
807 | static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
|
---|
808 | TALLOC_CTX *mem_ctx,
|
---|
809 | int argc, const char **argv)
|
---|
810 | {
|
---|
811 | struct srvsvc_NetConnInfoCtr info_ctr;
|
---|
812 | struct srvsvc_NetConnCtr0 ctr0;
|
---|
813 | struct srvsvc_NetConnCtr1 ctr1;
|
---|
814 | WERROR result;
|
---|
815 | NTSTATUS status;
|
---|
816 | uint32_t total_entries = 0;
|
---|
817 | uint32_t resume_handle = 0;
|
---|
818 | uint32_t *resume_handle_p = NULL;
|
---|
819 | uint32_t level = 1;
|
---|
820 | const char *path = "IPC$";
|
---|
821 |
|
---|
822 | if (argc > 4) {
|
---|
823 | printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
|
---|
824 | return WERR_OK;
|
---|
825 | }
|
---|
826 |
|
---|
827 | if (argc >= 2) {
|
---|
828 | level = atoi(argv[1]);
|
---|
829 | }
|
---|
830 |
|
---|
831 | if (argc >= 3) {
|
---|
832 | path = argv[2];
|
---|
833 | }
|
---|
834 |
|
---|
835 | if (argc >= 4) {
|
---|
836 | resume_handle = atoi(argv[3]);
|
---|
837 | resume_handle_p = &resume_handle;
|
---|
838 | }
|
---|
839 |
|
---|
840 | ZERO_STRUCT(info_ctr);
|
---|
841 |
|
---|
842 | info_ctr.level = level;
|
---|
843 |
|
---|
844 | switch (level) {
|
---|
845 | case 0:
|
---|
846 | ZERO_STRUCT(ctr0);
|
---|
847 | info_ctr.ctr.ctr0 = &ctr0;
|
---|
848 | break;
|
---|
849 | case 1:
|
---|
850 | ZERO_STRUCT(ctr1);
|
---|
851 | info_ctr.ctr.ctr1 = &ctr1;
|
---|
852 | break;
|
---|
853 | default:
|
---|
854 | return WERR_INVALID_PARAM;
|
---|
855 | }
|
---|
856 |
|
---|
857 | status = rpccli_srvsvc_NetConnEnum(cli, mem_ctx,
|
---|
858 | cli->cli->desthost,
|
---|
859 | path,
|
---|
860 | &info_ctr,
|
---|
861 | 0xffffffff,
|
---|
862 | &total_entries,
|
---|
863 | resume_handle_p,
|
---|
864 | &result);
|
---|
865 |
|
---|
866 | if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
|
---|
867 | goto done;
|
---|
868 | }
|
---|
869 |
|
---|
870 | done:
|
---|
871 | return result;
|
---|
872 | }
|
---|
873 |
|
---|
874 |
|
---|
875 | /* List of commands exported by this module */
|
---|
876 |
|
---|
877 | struct cmd_set srvsvc_commands[] = {
|
---|
878 |
|
---|
879 | { "SRVSVC" },
|
---|
880 |
|
---|
881 | { "srvinfo", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, PI_SRVSVC, NULL, "Server query info", "" },
|
---|
882 | { "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, PI_SRVSVC, NULL, "Enumerate shares", "" },
|
---|
883 | { "netshareenumall",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum_all, PI_SRVSVC, NULL, "Enumerate all shares", "" },
|
---|
884 | { "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, PI_SRVSVC, NULL, "Get Share Info", "" },
|
---|
885 | { "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, PI_SRVSVC, NULL, "Set Share Info", "" },
|
---|
886 | { "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum, PI_SRVSVC, NULL, "Enumerate open files", "" },
|
---|
887 | { "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, PI_SRVSVC, NULL, "Fetch remote time of day", "" },
|
---|
888 | { "netnamevalidate", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_name_validate, PI_SRVSVC, NULL, "Validate sharename", "" },
|
---|
889 | { "netfilegetsec", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_get_sec, PI_SRVSVC, NULL, "Get File security", "" },
|
---|
890 | { "netsessdel", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_del, PI_SRVSVC, NULL, "Delete Session", "" },
|
---|
891 | { "netsessenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_enum, PI_SRVSVC, NULL, "Enumerate Sessions", "" },
|
---|
892 | { "netdiskenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_disk_enum, PI_SRVSVC, NULL, "Enumerate Disks", "" },
|
---|
893 | { "netconnenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_conn_enum, PI_SRVSVC, NULL, "Enumerate Connections", "" },
|
---|
894 |
|
---|
895 | { NULL }
|
---|
896 | };
|
---|