r1553: Good patch from Guenther Deschner <gd@sernet.de> to display share ACL
[Samba/bb.git] / source3 / rpc_client / cli_srvsvc.c
blob68eb17074f63fcb89bb6792f2e0f3fe3c596c77b
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, 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, 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 = (SRV_SHARE_INFO_1 *)talloc(
124 mem_ctx, sizeof(SRV_SHARE_INFO_1) * ctr->num_entries);
126 memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
128 for (i = 0; i < ctr->num_entries; i++) {
129 SRV_SHARE_INFO_1 *info1 = &ctr->share.info1[i];
130 char *s;
132 /* Copy pointer crap */
134 memcpy(&info1->info_1, &r.ctr.share.info1[i].info_1,
135 sizeof(SH_INFO_1));
137 /* Duplicate strings */
139 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_netname);
140 if (s)
141 init_unistr2(&info1->info_1_str.uni_netname, s, UNI_STR_TERMINATE);
143 s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_remark);
144 if (s)
145 init_unistr2(&info1->info_1_str.uni_remark, s, UNI_STR_TERMINATE);
149 break;
150 case 2:
151 ctr->share.info2 = (SRV_SHARE_INFO_2 *)talloc(
152 mem_ctx, sizeof(SRV_SHARE_INFO_2) * ctr->num_entries);
154 memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
156 for (i = 0; i < ctr->num_entries; i++) {
157 SRV_SHARE_INFO_2 *info2 = &ctr->share.info2[i];
158 char *s;
160 /* Copy pointer crap */
162 memcpy(&info2->info_2, &r.ctr.share.info2[i].info_2,
163 sizeof(SH_INFO_2));
165 /* Duplicate strings */
167 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_netname);
168 if (s)
169 init_unistr2(&info2->info_2_str.uni_netname, s, UNI_STR_TERMINATE);
171 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_remark);
172 if (s)
173 init_unistr2(&info2->info_2_str.uni_remark, s, UNI_STR_TERMINATE);
175 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_path);
176 if (s)
177 init_unistr2(&info2->info_2_str.uni_path, s, UNI_STR_TERMINATE);
179 s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_passwd);
180 if (s)
181 init_unistr2(&info2->info_2_str.uni_passwd, s, UNI_STR_TERMINATE);
183 break;
184 /* adding info-level 502 here */
185 case 502:
186 ctr->share.info502 = (SRV_SHARE_INFO_502 *)talloc(
187 mem_ctx, sizeof(SRV_SHARE_INFO_502) * ctr->num_entries);
189 memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
191 for (i = 0; i < ctr->num_entries; i++) {
192 SRV_SHARE_INFO_502 *info502 = &ctr->share.info502[i];
193 char *s;
195 /* Copy pointer crap */
196 memcpy(&info502->info_502, &r.ctr.share.info502[i].info_502,
197 sizeof(SH_INFO_502));
199 /* Duplicate strings */
201 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_netname);
202 if (s)
203 init_unistr2(&info502->info_502_str.uni_netname, s, UNI_STR_TERMINATE);
205 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_remark);
206 if (s)
207 init_unistr2(&info502->info_502_str.uni_remark, s, UNI_STR_TERMINATE);
209 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_path);
210 if (s)
211 init_unistr2(&info502->info_502_str.uni_path, s, UNI_STR_TERMINATE);
213 s = unistr2_tdup(mem_ctx, &r.ctr.share.info502[i].info_502_str.uni_passwd);
214 if (s)
215 init_unistr2(&info502->info_502_str.uni_passwd, s, UNI_STR_TERMINATE);
217 info502->info_502_str.sd = dup_sec_desc(mem_ctx, r.ctr.share.info502[i].info_502_str.sd);
219 break;
221 done:
222 prs_mem_free(&qbuf);
223 prs_mem_free(&rbuf);
225 return result;
228 WERROR cli_srvsvc_net_share_del(struct cli_state *cli, TALLOC_CTX *mem_ctx,
229 const char *sharename)
231 prs_struct qbuf, rbuf;
232 SRV_Q_NET_SHARE_DEL q;
233 SRV_R_NET_SHARE_DEL 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_del(&q, cli->srv_name_slash, sharename);
248 /* Marshall data and send request */
250 if (!srv_io_q_net_share_del("", &q, &qbuf, 0) ||
251 !rpc_api_pipe_req(cli, SRV_NET_SHARE_DEL, &qbuf, &rbuf))
252 goto done;
254 /* Unmarshall response */
256 if (!srv_io_r_net_share_del("", &r, &rbuf, 0))
257 goto done;
259 result = r.status;
261 done:
262 prs_mem_free(&qbuf);
263 prs_mem_free(&rbuf);
265 return result;
268 WERROR cli_srvsvc_net_share_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
269 const char *netname, uint32 type,
270 const char *remark, uint32 perms,
271 uint32 max_uses, uint32 num_uses,
272 const char *path, const char *passwd)
274 prs_struct qbuf, rbuf;
275 SRV_Q_NET_SHARE_ADD q;
276 SRV_R_NET_SHARE_ADD r;
277 WERROR result = W_ERROR(ERRgeneral);
279 ZERO_STRUCT(q);
280 ZERO_STRUCT(r);
282 /* Initialise parse structures */
284 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
285 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
287 init_srv_q_net_share_add(&q,cli->srv_name_slash, netname, type, remark,
288 perms, max_uses, num_uses, path, passwd);
290 /* Marshall data and send request */
292 if (!srv_io_q_net_share_add("", &q, &qbuf, 0) ||
293 !rpc_api_pipe_req(cli, SRV_NET_SHARE_ADD, &qbuf, &rbuf))
294 goto done;
296 /* Unmarshall response */
298 if (!srv_io_r_net_share_add("", &r, &rbuf, 0))
299 goto done;
301 result = r.status;
303 done:
304 prs_mem_free(&qbuf);
305 prs_mem_free(&rbuf);
307 return result;
310 WERROR cli_srvsvc_net_remote_tod(struct cli_state *cli, TALLOC_CTX *mem_ctx,
311 char *server, TIME_OF_DAY_INFO *tod)
313 prs_struct qbuf, rbuf;
314 SRV_Q_NET_REMOTE_TOD q;
315 SRV_R_NET_REMOTE_TOD r;
316 WERROR result = W_ERROR(ERRgeneral);
318 ZERO_STRUCT(q);
319 ZERO_STRUCT(r);
321 /* Initialise parse structures */
323 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
324 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
326 /* Initialise input parameters */
328 init_srv_q_net_remote_tod(&q, cli->srv_name_slash);
330 /* Marshall data and send request */
332 if (!srv_io_q_net_remote_tod("", &q, &qbuf, 0) ||
333 !rpc_api_pipe_req(cli, SRV_NET_REMOTE_TOD, &qbuf, &rbuf))
334 goto done;
336 /* Unmarshall response */
338 r.tod = tod;
340 if (!srv_io_r_net_remote_tod("", &r, &rbuf, 0))
341 goto done;
343 result = r.status;
345 if (!W_ERROR_IS_OK(result))
346 goto done;
348 done:
349 prs_mem_free(&qbuf);
350 prs_mem_free(&rbuf);
352 return result;
355 WERROR cli_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
356 uint32 file_level, const char *user_name,
357 SRV_FILE_INFO_CTR *ctr, int preferred_len,
358 ENUM_HND *hnd)
360 prs_struct qbuf, rbuf;
361 SRV_Q_NET_FILE_ENUM q;
362 SRV_R_NET_FILE_ENUM r;
363 WERROR result = W_ERROR(ERRgeneral);
364 int i;
366 ZERO_STRUCT(q);
367 ZERO_STRUCT(r);
369 /* Initialise parse structures */
371 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
372 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
374 /* Initialise input parameters */
376 init_srv_q_net_file_enum(&q, cli->srv_name_slash, NULL, user_name,
377 file_level, ctr, preferred_len, hnd);
379 /* Marshall data and send request */
381 if (!srv_io_q_net_file_enum("", &q, &qbuf, 0) ||
382 !rpc_api_pipe_req(cli, SRV_NET_FILE_ENUM, &qbuf, &rbuf))
383 goto done;
385 /* Unmarshall response */
387 if (!srv_io_r_net_file_enum("", &r, &rbuf, 0))
388 goto done;
390 result = r.status;
392 if (!W_ERROR_IS_OK(result))
393 goto done;
395 /* copy the data over to the ctr */
397 ZERO_STRUCTP(ctr);
399 ctr->switch_value = file_level;
401 ctr->num_entries = ctr->num_entries2 = r.ctr.num_entries;
403 switch(file_level) {
404 case 3:
405 ctr->file.info3 = (SRV_FILE_INFO_3 *)talloc(
406 mem_ctx, sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
408 memset(ctr->file.info3, 0,
409 sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
411 for (i = 0; i < r.ctr.num_entries; i++) {
412 SRV_FILE_INFO_3 *info3 = &ctr->file.info3[i];
413 char *s;
415 /* Copy pointer crap */
417 memcpy(&info3->info_3, &r.ctr.file.info3[i].info_3,
418 sizeof(FILE_INFO_3));
420 /* Duplicate strings */
422 s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_path_name);
423 if (s)
424 init_unistr2(&info3->info_3_str.uni_path_name, s, UNI_STR_TERMINATE);
426 s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_user_name);
427 if (s)
428 init_unistr2(&info3->info_3_str.uni_user_name, s, UNI_STR_TERMINATE);
432 break;
435 done:
436 prs_mem_free(&qbuf);
437 prs_mem_free(&rbuf);
439 return result;
442 WERROR cli_srvsvc_net_file_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
443 uint32 file_id)
445 prs_struct qbuf, rbuf;
446 SRV_Q_NET_FILE_CLOSE q;
447 SRV_R_NET_FILE_CLOSE r;
448 WERROR result = W_ERROR(ERRgeneral);
450 ZERO_STRUCT(q);
451 ZERO_STRUCT(r);
453 /* Initialise parse structures */
455 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
456 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
458 /* Initialise input parameters */
460 init_srv_q_net_file_close(&q, cli->srv_name_slash, file_id);
462 /* Marshall data and send request */
464 if (!srv_io_q_net_file_close("", &q, &qbuf, 0) ||
465 !rpc_api_pipe_req(cli, SRV_NET_FILE_CLOSE, &qbuf, &rbuf))
466 goto done;
468 /* Unmarshall response */
470 if (!srv_io_r_net_file_close("", &r, &rbuf, 0))
471 goto done;
473 result = r.status;
474 done:
475 prs_mem_free(&qbuf);
476 prs_mem_free(&rbuf);
477 return result;