Make 3.0.x in sync with 3.2 here.
[Samba.git] / source / rpc_client / cli_srvsvc.c
blobe471de7c3ba57bd1d50aca41334d61b9257c1506
1 /*
2 Unix SMB/CIFS implementation.
3 NT Domain Authentication SMB / MSRPC client
4 Copyright (C) Andrew Tridgell 1994-2000
5 Copyright (C) Tim Potter 2001
6 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
7 Copyright (C) Jeremy Allison 2005.
8 Copyright (C) Gerald (Jerry) Carter 2006.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "includes.h"
28 WERROR rpccli_srvsvc_net_srv_get_info(struct rpc_pipe_client *cli,
29 TALLOC_CTX *mem_ctx,
30 uint32 switch_value, SRV_INFO_CTR *ctr)
32 prs_struct qbuf, rbuf;
33 SRV_Q_NET_SRV_GET_INFO q;
34 SRV_R_NET_SRV_GET_INFO r;
35 WERROR result = W_ERROR(ERRgeneral);
36 fstring server;
38 ZERO_STRUCT(q);
39 ZERO_STRUCT(r);
41 /* Initialise input parameters */
43 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
44 strupper_m(server);
46 init_srv_q_net_srv_get_info(&q, server, switch_value);
47 r.ctr = ctr;
49 /* Marshall data and send request */
51 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SRV_GET_INFO,
52 q, r,
53 qbuf, rbuf,
54 srv_io_q_net_srv_get_info,
55 srv_io_r_net_srv_get_info,
56 WERR_GENERAL_FAILURE);
58 result = r.status;
59 return result;
62 WERROR rpccli_srvsvc_net_share_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
63 uint32 info_level, SRV_SHARE_INFO_CTR *ctr,
64 int preferred_len, ENUM_HND *hnd)
66 prs_struct qbuf, rbuf;
67 SRV_Q_NET_SHARE_ENUM q;
68 SRV_R_NET_SHARE_ENUM r;
69 WERROR result = W_ERROR(ERRgeneral);
70 fstring server;
71 int i;
73 ZERO_STRUCT(q);
74 ZERO_STRUCT(r);
76 /* Initialise input parameters */
78 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
79 strupper_m(server);
81 init_srv_q_net_share_enum(&q, server, info_level, preferred_len, hnd);
83 /* Marshall data and send request */
85 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SHARE_ENUM_ALL,
86 q, r,
87 qbuf, rbuf,
88 srv_io_q_net_share_enum,
89 srv_io_r_net_share_enum,
90 WERR_GENERAL_FAILURE);
92 result = r.status;
94 if (!W_ERROR_IS_OK(result))
95 goto done;
97 /* Oh yuck yuck yuck - we have to copy all the info out of the
98 SRV_SHARE_INFO_CTR in the SRV_R_NET_SHARE_ENUM as when we do a
99 prs_mem_free() it will all be invalidated. The various share
100 info structures suck badly too. This really is gross. */
102 ZERO_STRUCTP(ctr);
104 if (!r.ctr.num_entries)
105 goto done;
107 ctr->info_level = info_level;
108 ctr->num_entries = r.ctr.num_entries;
110 switch(info_level) {
111 case 1:
112 ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, ctr->num_entries);
113 if (ctr->share.info1 == NULL) {
114 return WERR_NOMEM;
117 memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
119 for (i = 0; i < ctr->num_entries; i++) {
120 SRV_SHARE_INFO_1 *info1 = &ctr->share.info1[i];
121 char *s;
123 /* Copy pointer crap */
125 memcpy(&info1->info_1, &r.ctr.share.info1[i].info_1,
126 sizeof(SH_INFO_1));
128 /* Duplicate strings */
130 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_netname);
131 if (s)
132 init_unistr2(&info1->info_1_str.uni_netname, s, UNI_STR_TERMINATE);
134 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_remark);
135 if (s)
136 init_unistr2(&info1->info_1_str.uni_remark, s, UNI_STR_TERMINATE);
140 break;
141 case 2:
142 ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, ctr->num_entries);
143 if (ctr->share.info2 == NULL) {
144 return WERR_NOMEM;
147 memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
149 for (i = 0; i < ctr->num_entries; i++) {
150 SRV_SHARE_INFO_2 *info2 = &ctr->share.info2[i];
151 char *s;
153 /* Copy pointer crap */
155 memcpy(&info2->info_2, &r.ctr.share.info2[i].info_2,
156 sizeof(SH_INFO_2));
158 /* Duplicate strings */
160 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_netname);
161 if (s)
162 init_unistr2(&info2->info_2_str.uni_netname, s, UNI_STR_TERMINATE);
164 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_remark);
165 if (s)
166 init_unistr2(&info2->info_2_str.uni_remark, s, UNI_STR_TERMINATE);
168 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_path);
169 if (s)
170 init_unistr2(&info2->info_2_str.uni_path, s, UNI_STR_TERMINATE);
172 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_passwd);
173 if (s)
174 init_unistr2(&info2->info_2_str.uni_passwd, s, UNI_STR_TERMINATE);
176 break;
177 /* adding info-level 502 here */
178 case 502:
179 ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, ctr->num_entries);
181 if (ctr->share.info502 == NULL) {
182 return WERR_NOMEM;
185 memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
187 for (i = 0; i < ctr->num_entries; i++) {
188 SRV_SHARE_INFO_502 *info502 = &ctr->share.info502[i];
189 char *s;
191 /* Copy pointer crap */
192 memcpy(&info502->info_502, &r.ctr.share.info502[i].info_502,
193 sizeof(SH_INFO_502));
195 /* Duplicate strings */
197 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_netname);
198 if (s)
199 init_unistr2(&info502->info_502_str.uni_netname, s, UNI_STR_TERMINATE);
201 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_remark);
202 if (s)
203 init_unistr2(&info502->info_502_str.uni_remark, s, UNI_STR_TERMINATE);
205 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_path);
206 if (s)
207 init_unistr2(&info502->info_502_str.uni_path, s, UNI_STR_TERMINATE);
209 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_passwd);
210 if (s)
211 init_unistr2(&info502->info_502_str.uni_passwd, s, UNI_STR_TERMINATE);
213 info502->info_502_str.sd = dup_sec_desc(mem_ctx, r.ctr.share.info502[i].info_502_str.sd);
215 break;
218 done:
220 return result;
223 WERROR rpccli_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
224 TALLOC_CTX *mem_ctx,
225 const char *sharename,
226 uint32 info_level,
227 SRV_SHARE_INFO *info)
229 prs_struct qbuf, rbuf;
230 SRV_Q_NET_SHARE_GET_INFO q;
231 SRV_R_NET_SHARE_GET_INFO r;
232 WERROR result = W_ERROR(ERRgeneral);
233 fstring server;
235 ZERO_STRUCT(q);
236 ZERO_STRUCT(r);
238 /* Initialise input parameters */
240 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
241 strupper_m(server);
243 init_srv_q_net_share_get_info(&q, server, sharename, info_level);
245 /* Marshall data and send request */
247 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SHARE_GET_INFO,
248 q, r,
249 qbuf, rbuf,
250 srv_io_q_net_share_get_info,
251 srv_io_r_net_share_get_info,
252 WERR_GENERAL_FAILURE);
254 result = r.status;
256 if (!W_ERROR_IS_OK(result))
257 goto done;
259 ZERO_STRUCTP(info);
261 info->switch_value = info_level;
263 switch(info_level) {
264 case 1:
266 SRV_SHARE_INFO_1 *info1 = &info->share.info1;
267 SH_INFO_1_STR *info1_str = &info1->info_1_str;
269 char *s;
271 info->share.info1 = r.info.share.info1;
273 /* Duplicate strings */
275 s = unistr2_tdup(mem_ctx, &info1_str->uni_netname);
276 if (s)
277 init_unistr2(&info1_str->uni_netname,
278 s, UNI_STR_TERMINATE);
280 s = unistr2_tdup(mem_ctx, &info1_str->uni_remark);
281 if (s)
282 init_unistr2(&info1_str->uni_remark,
283 s, UNI_STR_TERMINATE);
285 break;
287 case 2:
289 SRV_SHARE_INFO_2 *info2 = &info->share.info2;
290 SH_INFO_2_STR *info2_str = &info2->info_2_str;
292 char *s;
294 info->share.info2 = r.info.share.info2;
296 /* Duplicate strings */
298 s = unistr2_tdup(mem_ctx, &info2_str->uni_netname);
299 if (s)
300 init_unistr2(&info2_str->uni_netname,
301 s, UNI_STR_TERMINATE);
303 s = unistr2_tdup(mem_ctx, &info2_str->uni_remark);
304 if (s)
305 init_unistr2(&info2_str->uni_remark,
306 s, UNI_STR_TERMINATE);
308 s = unistr2_tdup(mem_ctx, &info2_str->uni_path);
309 if (s)
310 init_unistr2(&info2_str->uni_path,
311 s, UNI_STR_TERMINATE);
313 s = unistr2_tdup(mem_ctx, &info2_str->uni_passwd);
314 if (s)
315 init_unistr2(&info2_str->uni_passwd,
316 s, UNI_STR_TERMINATE);
319 break;
321 case 502:
323 SRV_SHARE_INFO_502 *info502 = &info->share.info502;
324 SH_INFO_502_STR *info502_str = &info502->info_502_str;
326 char *s;
328 info->share.info502 = r.info.share.info502;
330 /* Duplicate strings */
332 s = unistr2_tdup(mem_ctx, &info502_str->uni_netname);
333 if (s)
334 init_unistr2(&info502_str->uni_netname,
335 s, UNI_STR_TERMINATE);
337 s = unistr2_tdup(mem_ctx, &info502_str->uni_remark);
338 if (s)
339 init_unistr2(&info502_str->uni_remark,
340 s, UNI_STR_TERMINATE);
342 s = unistr2_tdup(mem_ctx, &info502_str->uni_path);
343 if (s)
344 init_unistr2(&info502_str->uni_path,
345 s, UNI_STR_TERMINATE);
347 s = unistr2_tdup(mem_ctx, &info502_str->uni_passwd);
348 if (s)
349 init_unistr2(&info502_str->uni_passwd,
350 s, UNI_STR_TERMINATE);
352 info502_str->sd = dup_sec_desc(mem_ctx, info502_str->sd);
353 break;
355 default:
356 DEBUG(0,("unimplemented info-level: %d\n", info_level));
357 break;
360 done:
362 return result;
365 WERROR rpccli_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
366 TALLOC_CTX *mem_ctx,
367 const char *sharename,
368 uint32 info_level,
369 SRV_SHARE_INFO *info)
371 prs_struct qbuf, rbuf;
372 SRV_Q_NET_SHARE_SET_INFO q;
373 SRV_R_NET_SHARE_SET_INFO r;
374 WERROR result = W_ERROR(ERRgeneral);
375 fstring server;
377 ZERO_STRUCT(q);
378 ZERO_STRUCT(r);
380 /* Initialise input parameters */
382 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
383 strupper_m(server);
385 init_srv_q_net_share_set_info(&q, server, sharename, info_level, info);
387 /* Marshall data and send request */
389 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SHARE_SET_INFO,
390 q, r,
391 qbuf, rbuf,
392 srv_io_q_net_share_set_info,
393 srv_io_r_net_share_set_info,
394 WERR_GENERAL_FAILURE);
396 result = r.status;
397 return result;
400 WERROR rpccli_srvsvc_net_share_del(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
401 const char *sharename)
403 prs_struct qbuf, rbuf;
404 SRV_Q_NET_SHARE_DEL q;
405 SRV_R_NET_SHARE_DEL r;
406 WERROR result = W_ERROR(ERRgeneral);
407 fstring server;
409 ZERO_STRUCT(q);
410 ZERO_STRUCT(r);
412 /* Initialise input parameters */
414 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
415 strupper_m(server);
417 init_srv_q_net_share_del(&q, server, sharename);
419 /* Marshall data and send request */
421 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SHARE_DEL,
422 q, r,
423 qbuf, rbuf,
424 srv_io_q_net_share_del,
425 srv_io_r_net_share_del,
426 WERR_GENERAL_FAILURE);
428 result = r.status;
429 return result;
432 WERROR rpccli_srvsvc_net_share_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
433 const char *netname, uint32 type,
434 const char *remark, uint32 perms,
435 uint32 max_uses, uint32 num_uses,
436 const char *path, const char *passwd,
437 int level, SEC_DESC *sd)
439 prs_struct qbuf, rbuf;
440 SRV_Q_NET_SHARE_ADD q;
441 SRV_R_NET_SHARE_ADD r;
442 WERROR result = W_ERROR(ERRgeneral);
443 fstring server;
445 ZERO_STRUCT(q);
446 ZERO_STRUCT(r);
448 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
449 strupper_m(server);
451 init_srv_q_net_share_add(&q,server, netname, type, remark,
452 perms, max_uses, num_uses, path, passwd,
453 level, sd);
455 /* Marshall data and send request */
457 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_SHARE_ADD,
458 q, r,
459 qbuf, rbuf,
460 srv_io_q_net_share_add,
461 srv_io_r_net_share_add,
462 WERR_GENERAL_FAILURE);
464 result = r.status;
465 return result;
468 WERROR rpccli_srvsvc_net_remote_tod(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
469 char *server, TIME_OF_DAY_INFO *tod)
471 prs_struct qbuf, rbuf;
472 SRV_Q_NET_REMOTE_TOD q;
473 SRV_R_NET_REMOTE_TOD r;
474 WERROR result = W_ERROR(ERRgeneral);
475 fstring server_slash;
477 ZERO_STRUCT(q);
478 ZERO_STRUCT(r);
480 /* Initialise input parameters */
482 slprintf(server_slash, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
483 strupper_m(server_slash);
485 init_srv_q_net_remote_tod(&q, server_slash);
486 r.tod = tod;
488 /* Marshall data and send request */
490 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_REMOTE_TOD,
491 q, r,
492 qbuf, rbuf,
493 srv_io_q_net_remote_tod,
494 srv_io_r_net_remote_tod,
495 WERR_GENERAL_FAILURE);
497 result = r.status;
498 return result;
501 WERROR rpccli_srvsvc_net_file_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
502 uint32 file_level, const char *user_name,
503 SRV_FILE_INFO_CTR *ctr, int preferred_len,
504 ENUM_HND *hnd)
506 prs_struct qbuf, rbuf;
507 SRV_Q_NET_FILE_ENUM q;
508 SRV_R_NET_FILE_ENUM r;
509 WERROR result = W_ERROR(ERRgeneral);
510 fstring server;
511 int i;
513 ZERO_STRUCT(q);
514 ZERO_STRUCT(r);
516 /* Initialise input parameters */
518 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
519 strupper_m(server);
521 init_srv_q_net_file_enum(&q, server, NULL, user_name,
522 file_level, ctr, preferred_len, hnd);
524 /* Marshall data and send request */
526 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_FILE_ENUM,
527 q, r,
528 qbuf, rbuf,
529 srv_io_q_net_file_enum,
530 srv_io_r_net_file_enum,
531 WERR_GENERAL_FAILURE);
533 result = r.status;
535 if (!W_ERROR_IS_OK(result))
536 goto done;
538 /* copy the data over to the ctr */
540 ZERO_STRUCTP(ctr);
542 ctr->level = file_level;
544 ctr->num_entries = ctr->num_entries2 = r.ctr.num_entries;
546 switch(file_level) {
547 case 3:
548 if (ctr->num_entries) {
549 if ( (ctr->file.info3 = TALLOC_ARRAY(mem_ctx, FILE_INFO_3, ctr->num_entries)) == NULL ) {
550 return WERR_NOMEM;
553 memset(ctr->file.info3, 0, sizeof(FILE_INFO_3) * ctr->num_entries);
554 } else {
555 ctr->file.info3 = NULL;
558 for (i = 0; i < r.ctr.num_entries; i++) {
559 FILE_INFO_3 *info3 = &ctr->file.info3[i];
560 char *s;
562 /* Copy pointer crap */
564 memcpy(info3, &r.ctr.file.info3[i], sizeof(FILE_INFO_3));
566 /* Duplicate strings */
568 if ( (s = unistr2_tdup(mem_ctx, r.ctr.file.info3[i].path)) != NULL ) {
569 info3->path = TALLOC_P( mem_ctx, UNISTR2 );
570 init_unistr2(info3->path, s, UNI_STR_TERMINATE);
573 if ( (s = unistr2_tdup(mem_ctx, r.ctr.file.info3[i].user)) != NULL ) {
574 info3->user = TALLOC_P( mem_ctx, UNISTR2 );
575 init_unistr2(info3->user, s, UNI_STR_TERMINATE);
580 break;
583 done:
584 return result;
587 WERROR rpccli_srvsvc_net_file_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
588 uint32 file_id)
590 prs_struct qbuf, rbuf;
591 SRV_Q_NET_FILE_CLOSE q;
592 SRV_R_NET_FILE_CLOSE r;
593 WERROR result = W_ERROR(ERRgeneral);
594 fstring server;
596 ZERO_STRUCT(q);
597 ZERO_STRUCT(r);
599 /* Initialise input parameters */
601 slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->cli->desthost);
602 strupper_m(server);
604 init_srv_q_net_file_close(&q, server, file_id);
606 /* Marshall data and send request */
608 CLI_DO_RPC_WERR(cli, mem_ctx, PI_SRVSVC, SRV_NET_FILE_CLOSE,
609 q, r,
610 qbuf, rbuf,
611 srv_io_q_net_file_close,
612 srv_io_r_net_file_close,
613 WERR_GENERAL_FAILURE);
615 result = r.status;
616 return result;