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/* Query DFS support */
24
25NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
26                       BOOL *dfs_exists)
27{
28	prs_struct qbuf, rbuf;
29	DFS_Q_DFS_EXIST q;
30	DFS_R_DFS_EXIST r;
31	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
32
33	ZERO_STRUCT(q);
34	ZERO_STRUCT(r);
35
36	/* Initialise parse structures */
37
38	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
39	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
40
41	/* Marshall data and send request */
42
43        init_dfs_q_dfs_exist(&q);
44
45	if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
46	    !rpc_api_pipe_req(cli, PI_NETDFS, DFS_EXIST, &qbuf, &rbuf)) {
47		goto done;
48	}
49
50	/* Unmarshall response */
51
52	if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
53		goto done;
54	}
55
56	/* Return result */
57
58	*dfs_exists = (r.status != 0);
59
60	result = NT_STATUS_OK;
61
62 done:
63	prs_mem_free(&qbuf);
64	prs_mem_free(&rbuf);
65
66	return result;
67}
68
69NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
70                     const char *entrypath, const char *servername,
71		     const char *sharename, const char *comment, uint32 flags)
72{
73	prs_struct qbuf, rbuf;
74	DFS_Q_DFS_ADD q;
75	DFS_R_DFS_ADD r;
76	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
77
78	ZERO_STRUCT(q);
79	ZERO_STRUCT(r);
80
81	/* Initialise parse structures */
82
83	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
84	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
85
86	/* Marshall data and send request */
87
88        init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
89			   flags);
90
91	if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
92	    !rpc_api_pipe_req(cli, PI_NETDFS, DFS_ADD, &qbuf, &rbuf)) {
93		goto done;
94	}
95
96	/* Unmarshall response */
97
98	if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
99		goto done;
100	}
101
102	/* Return result */
103
104        result = werror_to_ntstatus(r.status);
105
106 done:
107	prs_mem_free(&qbuf);
108	prs_mem_free(&rbuf);
109
110	return result;
111}
112
113NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
114                        const char *entrypath, const char *servername,
115			const char *sharename)
116{
117	prs_struct qbuf, rbuf;
118	DFS_Q_DFS_REMOVE q;
119	DFS_R_DFS_REMOVE r;
120	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
121
122	ZERO_STRUCT(q);
123	ZERO_STRUCT(r);
124
125	/* Initialise parse structures */
126
127	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
128	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
129
130	/* Marshall data and send request */
131
132        init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
133
134	if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
135	    !rpc_api_pipe_req(cli, PI_NETDFS, DFS_REMOVE, &qbuf, &rbuf)) {
136		goto done;
137	}
138
139	/* Unmarshall response */
140
141	if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
142		goto done;
143	}
144
145	/* Return result */
146
147	result = werror_to_ntstatus(r.status);
148
149 done:
150	prs_mem_free(&qbuf);
151	prs_mem_free(&rbuf);
152
153	return result;
154}
155
156NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
157                          const char *entrypath, const char *servername,
158			  const char *sharename, uint32 info_level,
159			  DFS_INFO_CTR *ctr)
160
161{
162	prs_struct qbuf, rbuf;
163	DFS_Q_DFS_GET_INFO q;
164	DFS_R_DFS_GET_INFO r;
165	NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
166
167	ZERO_STRUCT(q);
168	ZERO_STRUCT(r);
169
170	/* Initialise parse structures */
171
172	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
173	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
174
175	/* Marshall data and send request */
176
177        init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
178				info_level);
179
180	if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
181	    !rpc_api_pipe_req(cli, PI_NETDFS, DFS_GET_INFO, &qbuf, &rbuf)) {
182		goto done;
183	}
184
185	/* Unmarshall response */
186
187	if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
188		goto done;
189	}
190
191	/* Return result */
192
193	result = werror_to_ntstatus(r.status);
194	*ctr = r.ctr;
195
196 done:
197	prs_mem_free(&qbuf);
198	prs_mem_free(&rbuf);
199
200	return result;
201}
202
203/* Enumerate dfs shares */
204
205NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
206                      uint32 info_level, DFS_INFO_CTR *ctr)
207{
208	prs_struct qbuf, rbuf;
209	DFS_Q_DFS_ENUM q;
210	DFS_R_DFS_ENUM r;
211        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
212
213	ZERO_STRUCT(q);
214	ZERO_STRUCT(r);
215
216	/* Initialise parse structures */
217
218	prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
219	prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
220
221	/* Marshall data and send request */
222
223        init_dfs_q_dfs_enum(&q, info_level, ctr);
224
225	if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
226	    !rpc_api_pipe_req(cli, PI_NETDFS, DFS_ENUM, &qbuf, &rbuf)) {
227		goto done;
228	}
229
230	/* Unmarshall response */
231
232	r.ctr = ctr;
233
234	if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
235		goto done;
236	}
237
238	/* Return result */
239
240	result = werror_to_ntstatus(r.status);
241
242 done:
243	prs_mem_free(&qbuf);
244	prs_mem_free(&rbuf);
245
246	return result;
247}
248