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.
28 WERROR
rpccli_srvsvc_net_srv_get_info(struct rpc_pipe_client
*cli
,
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
);
41 /* Initialise input parameters */
43 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
46 init_srv_q_net_srv_get_info(&q
, server
, switch_value
);
49 /* Marshall data and send request */
51 CLI_DO_RPC_WERR(cli
, mem_ctx
, PI_SRVSVC
, SRV_NET_SRV_GET_INFO
,
54 srv_io_q_net_srv_get_info
,
55 srv_io_r_net_srv_get_info
,
56 WERR_GENERAL_FAILURE
);
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
);
76 /* Initialise input parameters */
78 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
88 srv_io_q_net_share_enum
,
89 srv_io_r_net_share_enum
,
90 WERR_GENERAL_FAILURE
);
94 if (!W_ERROR_IS_OK(result
))
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. */
104 if (!r
.ctr
.num_entries
)
107 ctr
->info_level
= info_level
;
108 ctr
->num_entries
= r
.ctr
.num_entries
;
112 ctr
->share
.info1
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_1
, ctr
->num_entries
);
113 if (ctr
->share
.info1
== NULL
) {
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
];
123 /* Copy pointer crap */
125 memcpy(&info1
->info_1
, &r
.ctr
.share
.info1
[i
].info_1
,
128 /* Duplicate strings */
130 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info1
[i
].info_1_str
.uni_netname
);
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
);
136 init_unistr2(&info1
->info_1_str
.uni_remark
, s
, UNI_STR_TERMINATE
);
142 ctr
->share
.info2
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_2
, ctr
->num_entries
);
143 if (ctr
->share
.info2
== NULL
) {
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
];
153 /* Copy pointer crap */
155 memcpy(&info2
->info_2
, &r
.ctr
.share
.info2
[i
].info_2
,
158 /* Duplicate strings */
160 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info2
[i
].info_2_str
.uni_netname
);
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
);
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
);
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
);
174 init_unistr2(&info2
->info_2_str
.uni_passwd
, s
, UNI_STR_TERMINATE
);
177 /* adding info-level 502 here */
179 ctr
->share
.info502
= TALLOC_ARRAY(mem_ctx
, SRV_SHARE_INFO_502
, ctr
->num_entries
);
181 if (ctr
->share
.info502
== NULL
) {
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
];
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
);
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
);
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
);
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
);
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
);
223 WERROR
rpccli_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
225 const char *sharename
,
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
);
238 /* Initialise input parameters */
240 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
250 srv_io_q_net_share_get_info
,
251 srv_io_r_net_share_get_info
,
252 WERR_GENERAL_FAILURE
);
256 if (!W_ERROR_IS_OK(result
))
261 info
->switch_value
= info_level
;
266 SRV_SHARE_INFO_1
*info1
= &info
->share
.info1
;
267 SH_INFO_1_STR
*info1_str
= &info1
->info_1_str
;
271 info
->share
.info1
= r
.info
.share
.info1
;
273 /* Duplicate strings */
275 s
= unistr2_tdup(mem_ctx
, &info1_str
->uni_netname
);
277 init_unistr2(&info1_str
->uni_netname
,
278 s
, UNI_STR_TERMINATE
);
280 s
= unistr2_tdup(mem_ctx
, &info1_str
->uni_remark
);
282 init_unistr2(&info1_str
->uni_remark
,
283 s
, UNI_STR_TERMINATE
);
289 SRV_SHARE_INFO_2
*info2
= &info
->share
.info2
;
290 SH_INFO_2_STR
*info2_str
= &info2
->info_2_str
;
294 info
->share
.info2
= r
.info
.share
.info2
;
296 /* Duplicate strings */
298 s
= unistr2_tdup(mem_ctx
, &info2_str
->uni_netname
);
300 init_unistr2(&info2_str
->uni_netname
,
301 s
, UNI_STR_TERMINATE
);
303 s
= unistr2_tdup(mem_ctx
, &info2_str
->uni_remark
);
305 init_unistr2(&info2_str
->uni_remark
,
306 s
, UNI_STR_TERMINATE
);
308 s
= unistr2_tdup(mem_ctx
, &info2_str
->uni_path
);
310 init_unistr2(&info2_str
->uni_path
,
311 s
, UNI_STR_TERMINATE
);
313 s
= unistr2_tdup(mem_ctx
, &info2_str
->uni_passwd
);
315 init_unistr2(&info2_str
->uni_passwd
,
316 s
, UNI_STR_TERMINATE
);
323 SRV_SHARE_INFO_502
*info502
= &info
->share
.info502
;
324 SH_INFO_502_STR
*info502_str
= &info502
->info_502_str
;
328 info
->share
.info502
= r
.info
.share
.info502
;
330 /* Duplicate strings */
332 s
= unistr2_tdup(mem_ctx
, &info502_str
->uni_netname
);
334 init_unistr2(&info502_str
->uni_netname
,
335 s
, UNI_STR_TERMINATE
);
337 s
= unistr2_tdup(mem_ctx
, &info502_str
->uni_remark
);
339 init_unistr2(&info502_str
->uni_remark
,
340 s
, UNI_STR_TERMINATE
);
342 s
= unistr2_tdup(mem_ctx
, &info502_str
->uni_path
);
344 init_unistr2(&info502_str
->uni_path
,
345 s
, UNI_STR_TERMINATE
);
347 s
= unistr2_tdup(mem_ctx
, &info502_str
->uni_passwd
);
349 init_unistr2(&info502_str
->uni_passwd
,
350 s
, UNI_STR_TERMINATE
);
352 info502_str
->sd
= dup_sec_desc(mem_ctx
, info502_str
->sd
);
356 DEBUG(0,("unimplemented info-level: %d\n", info_level
));
365 WERROR
rpccli_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
367 const char *sharename
,
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
);
380 /* Initialise input parameters */
382 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
392 srv_io_q_net_share_set_info
,
393 srv_io_r_net_share_set_info
,
394 WERR_GENERAL_FAILURE
);
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
);
412 /* Initialise input parameters */
414 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
424 srv_io_q_net_share_del
,
425 srv_io_r_net_share_del
,
426 WERR_GENERAL_FAILURE
);
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
);
448 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
451 init_srv_q_net_share_add(&q
,server
, netname
, type
, remark
,
452 perms
, max_uses
, num_uses
, path
, passwd
,
455 /* Marshall data and send request */
457 CLI_DO_RPC_WERR(cli
, mem_ctx
, PI_SRVSVC
, SRV_NET_SHARE_ADD
,
460 srv_io_q_net_share_add
,
461 srv_io_r_net_share_add
,
462 WERR_GENERAL_FAILURE
);
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
;
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
);
488 /* Marshall data and send request */
490 CLI_DO_RPC_WERR(cli
, mem_ctx
, PI_SRVSVC
, SRV_NET_REMOTE_TOD
,
493 srv_io_q_net_remote_tod
,
494 srv_io_r_net_remote_tod
,
495 WERR_GENERAL_FAILURE
);
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
,
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
);
516 /* Initialise input parameters */
518 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
529 srv_io_q_net_file_enum
,
530 srv_io_r_net_file_enum
,
531 WERR_GENERAL_FAILURE
);
535 if (!W_ERROR_IS_OK(result
))
538 /* copy the data over to the ctr */
542 ctr
->level
= file_level
;
544 ctr
->num_entries
= ctr
->num_entries2
= r
.ctr
.num_entries
;
548 if (ctr
->num_entries
) {
549 if ( (ctr
->file
.info3
= TALLOC_ARRAY(mem_ctx
, FILE_INFO_3
, ctr
->num_entries
)) == NULL
) {
553 memset(ctr
->file
.info3
, 0, sizeof(FILE_INFO_3
) * ctr
->num_entries
);
555 ctr
->file
.info3
= NULL
;
558 for (i
= 0; i
< r
.ctr
.num_entries
; i
++) {
559 FILE_INFO_3
*info3
= &ctr
->file
.info3
[i
];
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
);
587 WERROR
rpccli_srvsvc_net_file_close(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
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
);
599 /* Initialise input parameters */
601 slprintf(server
, sizeof(fstring
)-1, "\\\\%s", cli
->cli
->desthost
);
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
,
611 srv_io_q_net_file_close
,
612 srv_io_r_net_file_close
,
613 WERR_GENERAL_FAILURE
);