r4904: sync up with 3.0 for 3.0.11pre2
[Samba.git] / source / rpc_client / cli_srvsvc.c
blobdd12367e0329bf6a69c7c505d6c50d6b317e79c5
1 /*
2 Unix SMB/CIFS implementation.
3 NT Domain Authentication SMB / MSRPC client
4 Copyright (C) Andrew Tridgell 1994-2000
5 Copyright (C) Luke Kenneth Casson Leighton 1996-2000
6 Copyright (C) Tim Potter 2001
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
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 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 WERROR cli_srvsvc_net_srv_get_info(struct cli_state *cli,
27 TALLOC_CTX *mem_ctx,
28 uint32 switch_value, SRV_INFO_CTR *ctr)
30 prs_struct qbuf, rbuf;
31 SRV_Q_NET_SRV_GET_INFO q;
32 SRV_R_NET_SRV_GET_INFO r;
33 WERROR result = W_ERROR(ERRgeneral);
35 ZERO_STRUCT(q);
36 ZERO_STRUCT(r);
38 /* Initialise parse structures */
40 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
41 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
43 /* Initialise input parameters */
45 init_srv_q_net_srv_get_info(&q, cli->srv_name_slash, switch_value);
47 /* Marshall data and send request */
49 if (!srv_io_q_net_srv_get_info("", &q, &qbuf, 0) ||
50 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_SRV_GET_INFO, &qbuf, &rbuf))
51 goto done;
53 /* Unmarshall response */
55 r.ctr = ctr;
57 if (!srv_io_r_net_srv_get_info("", &r, &rbuf, 0))
58 goto done;
60 result = r.status;
62 done:
63 prs_mem_free(&qbuf);
64 prs_mem_free(&rbuf);
66 return result;
69 WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
70 uint32 info_level, SRV_SHARE_INFO_CTR *ctr,
71 int preferred_len, ENUM_HND *hnd)
73 prs_struct qbuf, rbuf;
74 SRV_Q_NET_SHARE_ENUM q;
75 SRV_R_NET_SHARE_ENUM r;
76 WERROR result = W_ERROR(ERRgeneral);
77 int i;
79 ZERO_STRUCT(q);
80 ZERO_STRUCT(r);
82 /* Initialise parse structures */
84 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
85 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
87 /* Initialise input parameters */
89 init_srv_q_net_share_enum(
90 &q, cli->srv_name_slash, info_level, preferred_len, hnd);
92 /* Marshall data and send request */
94 if (!srv_io_q_net_share_enum("", &q, &qbuf, 0) ||
95 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_SHARE_ENUM_ALL, &qbuf, &rbuf))
96 goto done;
98 /* Unmarshall response */
100 if (!srv_io_r_net_share_enum("", &r, &rbuf, 0))
101 goto done;
103 result = r.status;
105 if (!W_ERROR_IS_OK(result))
106 goto done;
108 /* Oh yuck yuck yuck - we have to copy all the info out of the
109 SRV_SHARE_INFO_CTR in the SRV_R_NET_SHARE_ENUM as when we do a
110 prs_mem_free() it will all be invalidated. The various share
111 info structures suck badly too. This really is gross. */
113 ZERO_STRUCTP(ctr);
115 if (!r.ctr.num_entries)
116 goto done;
118 ctr->info_level = info_level;
119 ctr->num_entries = r.ctr.num_entries;
121 switch(info_level) {
122 case 1:
123 ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, ctr->num_entries);
125 memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
127 for (i = 0; i < ctr->num_entries; i++) {
128 SRV_SHARE_INFO_1 *info1 = &ctr->share.info1[i];
129 char *s;
131 /* Copy pointer crap */
133 memcpy(&info1->info_1, &r.ctr.share.info1[i].info_1,
134 sizeof(SH_INFO_1));
136 /* Duplicate strings */
138 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_netname);
139 if (s)
140 init_unistr2(&info1->info_1_str.uni_netname, s, UNI_STR_TERMINATE);
142 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_remark);
143 if (s)
144 init_unistr2(&info1->info_1_str.uni_remark, s, UNI_STR_TERMINATE);
148 break;
149 case 2:
150 ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, ctr->num_entries);
152 memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
154 for (i = 0; i < ctr->num_entries; i++) {
155 SRV_SHARE_INFO_2 *info2 = &ctr->share.info2[i];
156 char *s;
158 /* Copy pointer crap */
160 memcpy(&info2->info_2, &r.ctr.share.info2[i].info_2,
161 sizeof(SH_INFO_2));
163 /* Duplicate strings */
165 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_netname);
166 if (s)
167 init_unistr2(&info2->info_2_str.uni_netname, s, UNI_STR_TERMINATE);
169 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_remark);
170 if (s)
171 init_unistr2(&info2->info_2_str.uni_remark, s, UNI_STR_TERMINATE);
173 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_path);
174 if (s)
175 init_unistr2(&info2->info_2_str.uni_path, s, UNI_STR_TERMINATE);
177 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_passwd);
178 if (s)
179 init_unistr2(&info2->info_2_str.uni_passwd, s, UNI_STR_TERMINATE);
181 break;
182 /* adding info-level 502 here */
183 case 502:
184 ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, ctr->num_entries);
186 memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
188 for (i = 0; i < ctr->num_entries; i++) {
189 SRV_SHARE_INFO_502 *info502 = &ctr->share.info502[i];
190 char *s;
192 /* Copy pointer crap */
193 memcpy(&info502->info_502, &r.ctr.share.info502[i].info_502,
194 sizeof(SH_INFO_502));
196 /* Duplicate strings */
198 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_netname);
199 if (s)
200 init_unistr2(&info502->info_502_str.uni_netname, s, UNI_STR_TERMINATE);
202 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_remark);
203 if (s)
204 init_unistr2(&info502->info_502_str.uni_remark, s, UNI_STR_TERMINATE);
206 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_path);
207 if (s)
208 init_unistr2(&info502->info_502_str.uni_path, s, UNI_STR_TERMINATE);
210 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_passwd);
211 if (s)
212 init_unistr2(&info502->info_502_str.uni_passwd, s, UNI_STR_TERMINATE);
214 info502->info_502_str.sd = dup_sec_desc(mem_ctx, r.ctr.share.info502[i].info_502_str.sd);
216 break;
218 done:
219 prs_mem_free(&qbuf);
220 prs_mem_free(&rbuf);
222 return result;
225 WERROR cli_srvsvc_net_share_get_info(struct cli_state *cli,
226 TALLOC_CTX *mem_ctx,
227 const char *sharename,
228 uint32 info_level,
229 SRV_SHARE_INFO *info)
231 prs_struct qbuf, rbuf;
232 SRV_Q_NET_SHARE_GET_INFO q;
233 SRV_R_NET_SHARE_GET_INFO r;
234 WERROR result = W_ERROR(ERRgeneral);
236 ZERO_STRUCT(q);
237 ZERO_STRUCT(r);
239 /* Initialise parse structures */
241 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
242 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
244 /* Initialise input parameters */
246 init_srv_q_net_share_get_info(&q, cli->srv_name_slash, sharename,
247 info_level);
249 /* Marshall data and send request */
251 if (!srv_io_q_net_share_get_info("", &q, &qbuf, 0) ||
252 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_SHARE_GET_INFO, &qbuf, &rbuf))
253 goto done;
255 /* Unmarshall response */
257 if (!srv_io_r_net_share_get_info("", &r, &rbuf, 0))
258 goto done;
260 result = r.status;
262 if (!W_ERROR_IS_OK(result))
263 goto done;
265 ZERO_STRUCTP(info);
267 info->switch_value = info_level;
269 switch(info_level) {
270 case 502:
272 SRV_SHARE_INFO_502 *info502 = &info->share.info502;
273 SH_INFO_502_STR *info502_str = &info502->info_502_str;
275 char *s;
277 info->share.info502 = r.info.share.info502;
279 /* Duplicate strings */
281 s = unistr2_tdup(mem_ctx, &info502_str->uni_netname);
282 if (s)
283 init_unistr2(&info502_str->uni_netname,
284 s, UNI_STR_TERMINATE);
286 s = unistr2_tdup(mem_ctx, &info502_str->uni_remark);
287 if (s)
288 init_unistr2(&info502_str->uni_remark,
289 s, UNI_STR_TERMINATE);
291 s = unistr2_tdup(mem_ctx, &info502_str->uni_path);
292 if (s)
293 init_unistr2(&info502_str->uni_path,
294 s, UNI_STR_TERMINATE);
296 s = unistr2_tdup(mem_ctx, &info502_str->uni_passwd);
297 if (s)
298 init_unistr2(&info502_str->uni_passwd,
299 s, UNI_STR_TERMINATE);
301 info502_str->sd = dup_sec_desc(mem_ctx, info502_str->sd);
302 break;
306 done:
307 prs_mem_free(&qbuf);
308 prs_mem_free(&rbuf);
310 return result;
313 WERROR cli_srvsvc_net_share_del(struct cli_state *cli, TALLOC_CTX *mem_ctx,
314 const char *sharename)
316 prs_struct qbuf, rbuf;
317 SRV_Q_NET_SHARE_DEL q;
318 SRV_R_NET_SHARE_DEL r;
319 WERROR result = W_ERROR(ERRgeneral);
321 ZERO_STRUCT(q);
322 ZERO_STRUCT(r);
324 /* Initialise parse structures */
326 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
327 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
329 /* Initialise input parameters */
331 init_srv_q_net_share_del(&q, cli->srv_name_slash, sharename);
333 /* Marshall data and send request */
335 if (!srv_io_q_net_share_del("", &q, &qbuf, 0) ||
336 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_SHARE_DEL, &qbuf, &rbuf))
337 goto done;
339 /* Unmarshall response */
341 if (!srv_io_r_net_share_del("", &r, &rbuf, 0))
342 goto done;
344 result = r.status;
346 done:
347 prs_mem_free(&qbuf);
348 prs_mem_free(&rbuf);
350 return result;
353 WERROR cli_srvsvc_net_share_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
354 const char *netname, uint32 type,
355 const char *remark, uint32 perms,
356 uint32 max_uses, uint32 num_uses,
357 const char *path, const char *passwd,
358 int level, SEC_DESC *sd)
360 prs_struct qbuf, rbuf;
361 SRV_Q_NET_SHARE_ADD q;
362 SRV_R_NET_SHARE_ADD r;
363 WERROR result = W_ERROR(ERRgeneral);
365 ZERO_STRUCT(q);
366 ZERO_STRUCT(r);
368 /* Initialise parse structures */
370 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
371 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
373 init_srv_q_net_share_add(&q,cli->srv_name_slash, netname, type, remark,
374 perms, max_uses, num_uses, path, passwd,
375 level, sd);
377 /* Marshall data and send request */
379 if (!srv_io_q_net_share_add("", &q, &qbuf, 0) ||
380 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_SHARE_ADD, &qbuf, &rbuf))
381 goto done;
383 /* Unmarshall response */
385 if (!srv_io_r_net_share_add("", &r, &rbuf, 0))
386 goto done;
388 result = r.status;
390 done:
391 prs_mem_free(&qbuf);
392 prs_mem_free(&rbuf);
394 return result;
397 WERROR cli_srvsvc_net_remote_tod(struct cli_state *cli, TALLOC_CTX *mem_ctx,
398 char *server, TIME_OF_DAY_INFO *tod)
400 prs_struct qbuf, rbuf;
401 SRV_Q_NET_REMOTE_TOD q;
402 SRV_R_NET_REMOTE_TOD r;
403 WERROR result = W_ERROR(ERRgeneral);
405 ZERO_STRUCT(q);
406 ZERO_STRUCT(r);
408 /* Initialise parse structures */
410 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
411 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
413 /* Initialise input parameters */
415 init_srv_q_net_remote_tod(&q, cli->srv_name_slash);
417 /* Marshall data and send request */
419 if (!srv_io_q_net_remote_tod("", &q, &qbuf, 0) ||
420 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_REMOTE_TOD, &qbuf, &rbuf))
421 goto done;
423 /* Unmarshall response */
425 r.tod = tod;
427 if (!srv_io_r_net_remote_tod("", &r, &rbuf, 0))
428 goto done;
430 result = r.status;
432 if (!W_ERROR_IS_OK(result))
433 goto done;
435 done:
436 prs_mem_free(&qbuf);
437 prs_mem_free(&rbuf);
439 return result;
442 WERROR cli_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
443 uint32 file_level, const char *user_name,
444 SRV_FILE_INFO_CTR *ctr, int preferred_len,
445 ENUM_HND *hnd)
447 prs_struct qbuf, rbuf;
448 SRV_Q_NET_FILE_ENUM q;
449 SRV_R_NET_FILE_ENUM r;
450 WERROR result = W_ERROR(ERRgeneral);
451 int i;
453 ZERO_STRUCT(q);
454 ZERO_STRUCT(r);
456 /* Initialise parse structures */
458 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
459 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
461 /* Initialise input parameters */
463 init_srv_q_net_file_enum(&q, cli->srv_name_slash, NULL, user_name,
464 file_level, ctr, preferred_len, hnd);
466 /* Marshall data and send request */
468 if (!srv_io_q_net_file_enum("", &q, &qbuf, 0) ||
469 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_FILE_ENUM, &qbuf, &rbuf))
470 goto done;
472 /* Unmarshall response */
474 if (!srv_io_r_net_file_enum("", &r, &rbuf, 0))
475 goto done;
477 result = r.status;
479 if (!W_ERROR_IS_OK(result))
480 goto done;
482 /* copy the data over to the ctr */
484 ZERO_STRUCTP(ctr);
486 ctr->switch_value = file_level;
488 ctr->num_entries = ctr->num_entries2 = r.ctr.num_entries;
490 switch(file_level) {
491 case 3:
492 ctr->file.info3 = TALLOC_ARRAY(mem_ctx, SRV_FILE_INFO_3, ctr->num_entries);
494 memset(ctr->file.info3, 0,
495 sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
497 for (i = 0; i < r.ctr.num_entries; i++) {
498 SRV_FILE_INFO_3 *info3 = &ctr->file.info3[i];
499 char *s;
501 /* Copy pointer crap */
503 memcpy(&info3->info_3, &r.ctr.file.info3[i].info_3,
504 sizeof(FILE_INFO_3));
506 /* Duplicate strings */
508 s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_path_name);
509 if (s)
510 init_unistr2(&info3->info_3_str.uni_path_name, s, UNI_STR_TERMINATE);
512 s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_user_name);
513 if (s)
514 init_unistr2(&info3->info_3_str.uni_user_name, s, UNI_STR_TERMINATE);
518 break;
521 done:
522 prs_mem_free(&qbuf);
523 prs_mem_free(&rbuf);
525 return result;
528 WERROR cli_srvsvc_net_file_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
529 uint32 file_id)
531 prs_struct qbuf, rbuf;
532 SRV_Q_NET_FILE_CLOSE q;
533 SRV_R_NET_FILE_CLOSE r;
534 WERROR result = W_ERROR(ERRgeneral);
536 ZERO_STRUCT(q);
537 ZERO_STRUCT(r);
539 /* Initialise parse structures */
541 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
542 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
544 /* Initialise input parameters */
546 init_srv_q_net_file_close(&q, cli->srv_name_slash, file_id);
548 /* Marshall data and send request */
550 if (!srv_io_q_net_file_close("", &q, &qbuf, 0) ||
551 !rpc_api_pipe_req(cli, PI_SRVSVC, SRV_NET_FILE_CLOSE, &qbuf, &rbuf))
552 goto done;
554 /* Unmarshall response */
556 if (!srv_io_r_net_file_close("", &r, &rbuf, 0))
557 goto done;
559 result = r.status;
560 done:
561 prs_mem_free(&qbuf);
562 prs_mem_free(&rbuf);
563 return result;