Removed version number from file header.
[jpeach/samba.git] / source / libsmb / cli_dfs.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4    Copyright (C) Tim Potter                        2000-2001,
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22
23 /* Opens a SMB connection to the netdfs pipe */
24
25 struct cli_state *cli_dfs_initialise(struct cli_state *cli, char *system_name,
26                                      struct ntuser_creds *creds)
27 {
28         return cli_pipe_initialise(cli, system_name, PIPE_NETDFS, creds);
29 }
30
31 /* Query DFS support */
32
33 NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
34                        BOOL *dfs_exists)
35 {
36         prs_struct qbuf, rbuf;
37         DFS_Q_DFS_EXIST q;
38         DFS_R_DFS_EXIST r;
39         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
40
41         ZERO_STRUCT(q);
42         ZERO_STRUCT(r);
43
44         /* Initialise parse structures */
45
46         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
47         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
48
49         /* Marshall data and send request */
50
51         init_dfs_q_dfs_exist(&q);
52
53         if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
54             !rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
55                 goto done;
56         }
57
58         /* Unmarshall response */
59
60         if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
61                 goto done;
62         }
63
64         /* Return result */
65
66         *dfs_exists = (r.status != 0);
67
68         result = NT_STATUS_OK;
69
70  done:
71         prs_mem_free(&qbuf);
72         prs_mem_free(&rbuf);
73
74         return result;
75 }
76
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)
80 {
81         prs_struct qbuf, rbuf;
82         DFS_Q_DFS_ADD q;
83         DFS_R_DFS_ADD r;
84         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
85
86         ZERO_STRUCT(q);
87         ZERO_STRUCT(r);
88
89         /* Initialise parse structures */
90
91         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
92         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
93
94         /* Marshall data and send request */
95
96         init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
97                            flags);
98
99         if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
100             !rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
101                 goto done;
102         }
103
104         /* Unmarshall response */
105
106         if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
107                 goto done;
108         }
109
110         /* Return result */
111
112         result = werror_to_ntstatus(r.status);
113
114  done:
115         prs_mem_free(&qbuf);
116         prs_mem_free(&rbuf);
117
118         return result;
119 }
120
121 NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
122                         char *entrypath, char *servername, char *sharename)
123 {
124         prs_struct qbuf, rbuf;
125         DFS_Q_DFS_REMOVE q;
126         DFS_R_DFS_REMOVE r;
127         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
128
129         ZERO_STRUCT(q);
130         ZERO_STRUCT(r);
131
132         /* Initialise parse structures */
133
134         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
135         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
136
137         /* Marshall data and send request */
138
139         init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
140
141         if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
142             !rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
143                 goto done;
144         }
145
146         /* Unmarshall response */
147
148         if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
149                 goto done;
150         }
151
152         /* Return result */
153
154         result = werror_to_ntstatus(r.status);
155
156  done:
157         prs_mem_free(&qbuf);
158         prs_mem_free(&rbuf);
159
160         return result;
161 }
162
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)
166
167 {
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;
172
173         ZERO_STRUCT(q);
174         ZERO_STRUCT(r);
175
176         /* Initialise parse structures */
177
178         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
179         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
180
181         /* Marshall data and send request */
182
183         init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
184                                 info_level);
185
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;
189         }
190
191         /* Unmarshall response */
192
193         if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
194                 goto done;
195         }
196
197         /* Return result */
198
199         result = werror_to_ntstatus(r.status);
200         *ctr = r.ctr;
201         
202  done:
203         prs_mem_free(&qbuf);
204         prs_mem_free(&rbuf);
205
206         return result;
207 }
208
209 /* Enumerate dfs shares */
210
211 NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
212                       uint32 info_level, DFS_INFO_CTR *ctr)
213 {
214         prs_struct qbuf, rbuf;
215         DFS_Q_DFS_ENUM q;
216         DFS_R_DFS_ENUM r;
217         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
218
219         ZERO_STRUCT(q);
220         ZERO_STRUCT(r);
221
222         /* Initialise parse structures */
223
224         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
225         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
226
227         /* Marshall data and send request */
228
229         init_dfs_q_dfs_enum(&q, info_level, ctr);
230
231         if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
232             !rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
233                 goto done;
234         }
235
236         /* Unmarshall response */
237         
238         r.ctr = ctr;
239
240         if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
241                 goto done;
242         }
243
244         /* Return result */
245
246         result = werror_to_ntstatus(r.status);
247
248  done:
249         prs_mem_free(&qbuf);
250         prs_mem_free(&rbuf);
251
252         return result;
253 }