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 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.
26 NTSTATUS
cli_srvsvc_net_srv_get_info(struct cli_state
*cli
,
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
;
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 result
= NT_STATUS_UNSUCCESSFUL
;
55 /* Unmarshall response */
59 if (!srv_io_r_net_srv_get_info("", &r
, &rbuf
, 0)) {
60 result
= NT_STATUS_UNSUCCESSFUL
;
64 result
= werror_to_ntstatus(r
.status
);
73 WERROR
cli_srvsvc_net_share_enum(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
74 uint32 info_level
, SRV_SHARE_INFO_CTR
*ctr
,
75 int preferred_len
, ENUM_HND
*hnd
)
77 prs_struct qbuf
, rbuf
;
78 SRV_Q_NET_SHARE_ENUM q
;
79 SRV_R_NET_SHARE_ENUM r
;
80 WERROR result
= W_ERROR(ERRgeneral
);
86 /* Initialise parse structures */
88 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
89 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
91 /* Initialise input parameters */
93 init_srv_q_net_share_enum(
94 &q
, cli
->srv_name_slash
, info_level
, preferred_len
, hnd
);
96 /* Marshall data and send request */
98 if (!srv_io_q_net_share_enum("", &q
, &qbuf
, 0) ||
99 !rpc_api_pipe_req(cli
, SRV_NET_SHARE_ENUM_ALL
, &qbuf
, &rbuf
))
102 /* Unmarshall response */
104 if (!srv_io_r_net_share_enum("", &r
, &rbuf
, 0))
109 if (!W_ERROR_IS_OK(result
))
112 /* Oh yuck yuck yuck - we have to copy all the info out of the
113 SRV_SHARE_INFO_CTR in the SRV_R_NET_SHARE_ENUM as when we do a
114 prs_mem_free() it will all be invalidated. The various share
115 info structures suck badly too. This really is gross. */
119 ctr
->info_level
= info_level
;
120 ctr
->num_entries
= r
.ctr
.num_entries
;
124 ctr
->share
.info1
= (SRV_SHARE_INFO_1
*)talloc(
125 mem_ctx
, sizeof(SRV_SHARE_INFO_1
) * ctr
->num_entries
);
127 memset(ctr
->share
.info1
, 0, sizeof(SRV_SHARE_INFO_1
));
129 for (i
= 0; i
< ctr
->num_entries
; i
++) {
130 SRV_SHARE_INFO_1
*info1
= &ctr
->share
.info1
[i
];
133 /* Copy pointer crap */
135 memcpy(&info1
->info_1
, &r
.ctr
.share
.info1
[i
].info_1
,
138 /* Duplicate strings */
140 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info1
[i
].info_1_str
.uni_netname
);
142 init_unistr2(&info1
->info_1_str
.uni_netname
, s
, strlen(s
) + 1);
144 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info1
[i
].info_1_str
.uni_remark
);
146 init_unistr2(&info1
->info_1_str
.uni_remark
, s
, strlen(s
) + 1);
152 ctr
->share
.info2
= (SRV_SHARE_INFO_2
*)talloc(
153 mem_ctx
, sizeof(SRV_SHARE_INFO_2
) * ctr
->num_entries
);
155 memset(ctr
->share
.info2
, 0, sizeof(SRV_SHARE_INFO_2
));
157 for (i
= 0; i
< ctr
->num_entries
; i
++) {
158 SRV_SHARE_INFO_2
*info2
= &ctr
->share
.info2
[i
];
161 /* Copy pointer crap */
163 memcpy(&info2
->info_2
, &r
.ctr
.share
.info2
[i
].info_2
,
166 /* Duplicate strings */
168 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info2
[i
].info_2_str
.uni_netname
);
170 init_unistr2(&info2
->info_2_str
.uni_netname
, s
, strlen(s
) + 1);
172 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info2
[i
].info_2_str
.uni_remark
);
174 init_unistr2(&info2
->info_2_str
.uni_remark
, s
, strlen(s
) + 1);
176 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info2
[i
].info_2_str
.uni_path
);
178 init_unistr2(&info2
->info_2_str
.uni_path
, s
, strlen(s
) + 1);
180 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.share
.info2
[i
].info_2_str
.uni_passwd
);
182 init_unistr2(&info2
->info_2_str
.uni_passwd
, s
, strlen(s
) + 1);
193 WERROR
cli_srvsvc_net_share_del(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
194 const char *sharename
)
196 prs_struct qbuf
, rbuf
;
197 SRV_Q_NET_SHARE_DEL q
;
198 SRV_R_NET_SHARE_DEL r
;
199 WERROR result
= W_ERROR(ERRgeneral
);
204 /* Initialise parse structures */
206 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
207 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
209 /* Initialise input parameters */
211 init_srv_q_net_share_del(&q
, cli
->srv_name_slash
, sharename
);
213 /* Marshall data and send request */
215 if (!srv_io_q_net_share_del("", &q
, &qbuf
, 0) ||
216 !rpc_api_pipe_req(cli
, SRV_NET_SHARE_DEL
, &qbuf
, &rbuf
))
219 /* Unmarshall response */
221 if (!srv_io_r_net_share_del("", &r
, &rbuf
, 0))
233 WERROR
cli_srvsvc_net_share_add(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
234 char *netname
, uint32 type
, char *remark
,
235 uint32 perms
, uint32 max_uses
, uint32 num_uses
,
236 char *path
, char *passwd
)
238 prs_struct qbuf
, rbuf
;
239 SRV_Q_NET_SHARE_ADD q
;
240 SRV_R_NET_SHARE_ADD r
;
241 WERROR result
= W_ERROR(ERRgeneral
);
246 /* Initialise parse structures */
248 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
249 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
251 init_srv_q_net_share_add(&q
,cli
->srv_name_slash
, netname
, type
, remark
,
252 perms
, max_uses
, num_uses
, path
, passwd
);
254 /* Marshall data and send request */
256 if (!srv_io_q_net_share_add("", &q
, &qbuf
, 0) ||
257 !rpc_api_pipe_req(cli
, SRV_NET_SHARE_ADD
, &qbuf
, &rbuf
))
260 /* Unmarshall response */
262 if (!srv_io_r_net_share_add("", &r
, &rbuf
, 0))
274 WERROR
cli_srvsvc_net_remote_tod(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
275 char *server
, TIME_OF_DAY_INFO
*tod
)
277 prs_struct qbuf
, rbuf
;
278 SRV_Q_NET_REMOTE_TOD q
;
279 SRV_R_NET_REMOTE_TOD r
;
280 WERROR result
= W_ERROR(ERRgeneral
);
285 /* Initialise parse structures */
287 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
288 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
290 /* Initialise input parameters */
292 init_srv_q_net_remote_tod(&q
, cli
->srv_name_slash
);
294 /* Marshall data and send request */
296 if (!srv_io_q_net_remote_tod("", &q
, &qbuf
, 0) ||
297 !rpc_api_pipe_req(cli
, SRV_NET_REMOTE_TOD
, &qbuf
, &rbuf
))
300 /* Unmarshall response */
304 if (!srv_io_r_net_remote_tod("", &r
, &rbuf
, 0))
309 if (!W_ERROR_IS_OK(result
))
319 WERROR
cli_srvsvc_net_file_enum(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
320 uint32 file_level
, const char *user_name
,
321 SRV_FILE_INFO_CTR
*ctr
, int preferred_len
,
324 prs_struct qbuf
, rbuf
;
325 SRV_Q_NET_FILE_ENUM q
;
326 SRV_R_NET_FILE_ENUM r
;
327 WERROR result
= W_ERROR(ERRgeneral
);
333 /* Initialise parse structures */
335 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
336 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
338 /* Initialise input parameters */
340 init_srv_q_net_file_enum(&q
, cli
->srv_name_slash
, NULL
, user_name
,
341 file_level
, ctr
, preferred_len
, hnd
);
343 /* Marshall data and send request */
345 if (!srv_io_q_net_file_enum("", &q
, &qbuf
, 0) ||
346 !rpc_api_pipe_req(cli
, SRV_NET_FILE_ENUM
, &qbuf
, &rbuf
))
349 /* Unmarshall response */
351 if (!srv_io_r_net_file_enum("", &r
, &rbuf
, 0))
356 if (!W_ERROR_IS_OK(result
))
359 /* copy the data over to the ctr */
363 ctr
->switch_value
= file_level
;
365 ctr
->num_entries
= ctr
->num_entries2
= r
.ctr
.num_entries
;
369 ctr
->file
.info3
= (SRV_FILE_INFO_3
*)talloc(
370 mem_ctx
, sizeof(SRV_FILE_INFO_3
) * ctr
->num_entries
);
372 memset(ctr
->file
.info3
, 0,
373 sizeof(SRV_FILE_INFO_3
) * ctr
->num_entries
);
375 for (i
= 0; i
< r
.ctr
.num_entries
; i
++) {
376 SRV_FILE_INFO_3
*info3
= &ctr
->file
.info3
[i
];
379 /* Copy pointer crap */
381 memcpy(&info3
->info_3
, &r
.ctr
.file
.info3
[i
].info_3
,
382 sizeof(FILE_INFO_3
));
384 /* Duplicate strings */
386 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.file
.info3
[i
].info_3_str
.uni_path_name
);
388 init_unistr2(&info3
->info_3_str
.uni_path_name
, s
, strlen(s
) + 1);
390 s
= unistr2_tdup(mem_ctx
, &r
.ctr
.file
.info3
[i
].info_3_str
.uni_user_name
);
392 init_unistr2(&info3
->info_3_str
.uni_user_name
, s
, strlen(s
) + 1);
406 WERROR
cli_srvsvc_net_file_close(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
409 prs_struct qbuf
, rbuf
;
410 SRV_Q_NET_FILE_CLOSE q
;
411 SRV_R_NET_FILE_CLOSE r
;
412 WERROR result
= W_ERROR(ERRgeneral
);
417 /* Initialise parse structures */
419 prs_init(&qbuf
, MAX_PDU_FRAG_LEN
, mem_ctx
, MARSHALL
);
420 prs_init(&rbuf
, 0, mem_ctx
, UNMARSHALL
);
422 /* Initialise input parameters */
424 init_srv_q_net_file_close(&q
, cli
->srv_name_slash
, file_id
);
426 /* Marshall data and send request */
428 if (!srv_io_q_net_file_close("", &q
, &qbuf
, 0) ||
429 !rpc_api_pipe_req(cli
, SRV_NET_FILE_CLOSE
, &qbuf
, &rbuf
))
432 /* Unmarshall response */
434 if (!srv_io_r_net_file_close("", &r
, &rbuf
, 0))