Lots of doc updates. Getting ready for 2.2.5 release.
[Samba.git] / source / libsmb / cli_dfs.c
blob312275926c79abad0b1facef3c67f76d8a0e1bab
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
4 Copyright (C) Tim Potter 2000-2001,
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 /* Opens a SMB connection to the netdfs pipe */
25 struct cli_state *cli_dfs_initialise(struct cli_state *cli, char *system_name,
26 struct ntuser_creds *creds)
28 return cli_pipe_initialise(cli, system_name, PIPE_NETDFS, creds);
31 /* Query DFS support */
33 NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
34 BOOL *dfs_exists)
36 prs_struct qbuf, rbuf;
37 DFS_Q_DFS_EXIST q;
38 DFS_R_DFS_EXIST r;
39 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
41 ZERO_STRUCT(q);
42 ZERO_STRUCT(r);
44 /* Initialise parse structures */
46 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
47 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
49 /* Marshall data and send request */
51 init_dfs_q_dfs_exist(&q);
53 if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
54 !rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
55 goto done;
58 /* Unmarshall response */
60 if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
61 goto done;
64 /* Return result */
66 *dfs_exists = (r.status != 0);
68 result = NT_STATUS_OK;
70 done:
71 prs_mem_free(&qbuf);
72 prs_mem_free(&rbuf);
74 return result;
77 NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
78 char *entrypath, char *servername, char *sharename,
79 char *comment, uint32 flags)
81 prs_struct qbuf, rbuf;
82 DFS_Q_DFS_ADD q;
83 DFS_R_DFS_ADD r;
84 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
86 ZERO_STRUCT(q);
87 ZERO_STRUCT(r);
89 /* Initialise parse structures */
91 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
92 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
94 /* Marshall data and send request */
96 init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
97 flags);
99 if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
100 !rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
101 goto done;
104 /* Unmarshall response */
106 if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
107 goto done;
110 /* Return result */
112 result = werror_to_ntstatus(r.status);
114 done:
115 prs_mem_free(&qbuf);
116 prs_mem_free(&rbuf);
118 return result;
121 NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
122 char *entrypath, char *servername, char *sharename)
124 prs_struct qbuf, rbuf;
125 DFS_Q_DFS_REMOVE q;
126 DFS_R_DFS_REMOVE r;
127 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
129 ZERO_STRUCT(q);
130 ZERO_STRUCT(r);
132 /* Initialise parse structures */
134 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
135 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
137 /* Marshall data and send request */
139 init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
141 if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
142 !rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
143 goto done;
146 /* Unmarshall response */
148 if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
149 goto done;
152 /* Return result */
154 result = werror_to_ntstatus(r.status);
156 done:
157 prs_mem_free(&qbuf);
158 prs_mem_free(&rbuf);
160 return result;
163 NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
164 char *entrypath, char *servername, char *sharename,
165 uint32 info_level, DFS_INFO_CTR *ctr)
168 prs_struct qbuf, rbuf;
169 DFS_Q_DFS_GET_INFO q;
170 DFS_R_DFS_GET_INFO r;
171 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
173 ZERO_STRUCT(q);
174 ZERO_STRUCT(r);
176 /* Initialise parse structures */
178 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
179 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
181 /* Marshall data and send request */
183 init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
184 info_level);
186 if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
187 !rpc_api_pipe_req(cli, DFS_GET_INFO, &qbuf, &rbuf)) {
188 goto done;
191 /* Unmarshall response */
193 if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
194 goto done;
197 /* Return result */
199 result = werror_to_ntstatus(r.status);
200 *ctr = r.ctr;
202 done:
203 prs_mem_free(&qbuf);
204 prs_mem_free(&rbuf);
206 return result;
209 /* Enumerate dfs shares */
211 NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
212 uint32 info_level, DFS_INFO_CTR *ctr)
214 prs_struct qbuf, rbuf;
215 DFS_Q_DFS_ENUM q;
216 DFS_R_DFS_ENUM r;
217 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
219 ZERO_STRUCT(q);
220 ZERO_STRUCT(r);
222 /* Initialise parse structures */
224 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
225 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
227 /* Marshall data and send request */
229 init_dfs_q_dfs_enum(&q, info_level, ctr);
231 if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
232 !rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
233 goto done;
236 /* Unmarshall response */
238 r.ctr = ctr;
240 if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
241 goto done;
244 /* Return result */
246 result = werror_to_ntstatus(r.status);
248 done:
249 prs_mem_free(&qbuf);
250 prs_mem_free(&rbuf);
252 return result;