83220fd1afccc44ff4782c5c91ab9ec54f35af51
[ira/wip.git] / source3 / libsmb / cli_dfs.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.2
4    RPC pipe client
5    Copyright (C) Tim Potter                        2000-2001,
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 /* Opens a SMB connection to the netdfs pipe */
25
26 struct cli_state *cli_dfs_initialise(struct cli_state *cli, char *system_name,
27                                      struct ntuser_creds *creds)
28 {
29         return cli_pipe_initialise(cli, system_name, PIPE_NETDFS, creds);
30 }
31
32 /* Query DFS support */
33
34 NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
35                        BOOL *dfs_exists)
36 {
37         prs_struct qbuf, rbuf;
38         DFS_Q_DFS_EXIST q;
39         DFS_R_DFS_EXIST r;
40         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
41
42         ZERO_STRUCT(q);
43         ZERO_STRUCT(r);
44
45         /* Initialise parse structures */
46
47         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
48         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
49
50         /* Marshall data and send request */
51
52         init_dfs_q_dfs_exist(&q);
53
54         if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
55             !rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
56                 goto done;
57         }
58
59         /* Unmarshall response */
60
61         if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
62                 goto done;
63         }
64
65         /* Return result */
66
67         *dfs_exists = (r.status != 0);
68
69         result = NT_STATUS_OK;
70
71  done:
72         prs_mem_free(&qbuf);
73         prs_mem_free(&rbuf);
74
75         return result;
76 }
77
78 NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
79                      char *entrypath, char *servername, char *sharename,
80                      char *comment, uint32 flags)
81 {
82         prs_struct qbuf, rbuf;
83         DFS_Q_DFS_ADD q;
84         DFS_R_DFS_ADD r;
85         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
86
87         ZERO_STRUCT(q);
88         ZERO_STRUCT(r);
89
90         /* Initialise parse structures */
91
92         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
93         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
94
95         /* Marshall data and send request */
96
97         init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
98                            flags);
99
100         if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
101             !rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
102                 goto done;
103         }
104
105         /* Unmarshall response */
106
107         if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
108                 goto done;
109         }
110
111         /* Return result */
112
113         result = werror_to_ntstatus(r.status);
114
115  done:
116         prs_mem_free(&qbuf);
117         prs_mem_free(&rbuf);
118
119         return result;
120 }
121
122 NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
123                         char *entrypath, char *servername, char *sharename)
124 {
125         prs_struct qbuf, rbuf;
126         DFS_Q_DFS_REMOVE q;
127         DFS_R_DFS_REMOVE r;
128         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
129
130         ZERO_STRUCT(q);
131         ZERO_STRUCT(r);
132
133         /* Initialise parse structures */
134
135         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
136         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
137
138         /* Marshall data and send request */
139
140         init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
141
142         if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
143             !rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
144                 goto done;
145         }
146
147         /* Unmarshall response */
148
149         if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
150                 goto done;
151         }
152
153         /* Return result */
154
155         result = werror_to_ntstatus(r.status);
156
157  done:
158         prs_mem_free(&qbuf);
159         prs_mem_free(&rbuf);
160
161         return result;
162 }
163
164 NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
165                           char *entrypath, char *servername, char *sharename,
166                           uint32 info_level, DFS_INFO_CTR *ctr)
167
168 {
169         prs_struct qbuf, rbuf;
170         DFS_Q_DFS_GET_INFO q;
171         DFS_R_DFS_GET_INFO r;
172         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
173
174         ZERO_STRUCT(q);
175         ZERO_STRUCT(r);
176
177         /* Initialise parse structures */
178
179         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
180         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
181
182         /* Marshall data and send request */
183
184         init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
185                                 info_level);
186
187         if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
188             !rpc_api_pipe_req(cli, DFS_GET_INFO, &qbuf, &rbuf)) {
189                 goto done;
190         }
191
192         /* Unmarshall response */
193
194         if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
195                 goto done;
196         }
197
198         /* Return result */
199
200         result = werror_to_ntstatus(r.status);
201         *ctr = r.ctr;
202         
203  done:
204         prs_mem_free(&qbuf);
205         prs_mem_free(&rbuf);
206
207         return result;
208 }
209
210 /* Enumerate dfs shares */
211
212 NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
213                       uint32 info_level, DFS_INFO_CTR *ctr)
214 {
215         prs_struct qbuf, rbuf;
216         DFS_Q_DFS_ENUM q;
217         DFS_R_DFS_ENUM r;
218         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
219
220         ZERO_STRUCT(q);
221         ZERO_STRUCT(r);
222
223         /* Initialise parse structures */
224
225         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
226         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
227
228         /* Marshall data and send request */
229
230         init_dfs_q_dfs_enum(&q, info_level, ctr);
231
232         if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
233             !rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
234                 goto done;
235         }
236
237         /* Unmarshall response */
238         
239         r.ctr = ctr;
240
241         if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
242                 goto done;
243         }
244
245         /* Return result */
246
247         result = werror_to_ntstatus(r.status);
248
249  done:
250         prs_mem_free(&qbuf);
251         prs_mem_free(&rbuf);
252
253         return result;
254 }