Fix another join problem. Don't use a TALLOC_CTX before it has been
[Samba/gebeck_regimport.git] / source / rpc_client / cli_dfs.c
blob2136b69df0776d90029ec73f327c19bed8229ae0
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 /* Query DFS support */
25 NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
26 BOOL *dfs_exists)
28 prs_struct qbuf, rbuf;
29 DFS_Q_DFS_EXIST q;
30 DFS_R_DFS_EXIST r;
31 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
33 ZERO_STRUCT(q);
34 ZERO_STRUCT(r);
36 /* Initialise parse structures */
38 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
39 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
41 /* Marshall data and send request */
43 init_dfs_q_dfs_exist(&q);
45 if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
46 !rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
47 goto done;
50 /* Unmarshall response */
52 if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
53 goto done;
56 /* Return result */
58 *dfs_exists = (r.status != 0);
60 result = NT_STATUS_OK;
62 done:
63 prs_mem_free(&qbuf);
64 prs_mem_free(&rbuf);
66 return result;
69 NTSTATUS 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)
73 prs_struct qbuf, rbuf;
74 DFS_Q_DFS_ADD q;
75 DFS_R_DFS_ADD r;
76 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
78 ZERO_STRUCT(q);
79 ZERO_STRUCT(r);
81 /* Initialise parse structures */
83 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
84 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
86 /* Marshall data and send request */
88 init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
89 flags);
91 if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
92 !rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
93 goto done;
96 /* Unmarshall response */
98 if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
99 goto done;
102 /* Return result */
104 result = werror_to_ntstatus(r.status);
106 done:
107 prs_mem_free(&qbuf);
108 prs_mem_free(&rbuf);
110 return result;
113 NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
114 const char *entrypath, const char *servername,
115 const char *sharename)
117 prs_struct qbuf, rbuf;
118 DFS_Q_DFS_REMOVE q;
119 DFS_R_DFS_REMOVE r;
120 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
122 ZERO_STRUCT(q);
123 ZERO_STRUCT(r);
125 /* Initialise parse structures */
127 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
128 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
130 /* Marshall data and send request */
132 init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
134 if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
135 !rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
136 goto done;
139 /* Unmarshall response */
141 if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
142 goto done;
145 /* Return result */
147 result = werror_to_ntstatus(r.status);
149 done:
150 prs_mem_free(&qbuf);
151 prs_mem_free(&rbuf);
153 return result;
156 NTSTATUS 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)
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;
167 ZERO_STRUCT(q);
168 ZERO_STRUCT(r);
170 /* Initialise parse structures */
172 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
173 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
175 /* Marshall data and send request */
177 init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
178 info_level);
180 if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
181 !rpc_api_pipe_req(cli, DFS_GET_INFO, &qbuf, &rbuf)) {
182 goto done;
185 /* Unmarshall response */
187 if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
188 goto done;
191 /* Return result */
193 result = werror_to_ntstatus(r.status);
194 *ctr = r.ctr;
196 done:
197 prs_mem_free(&qbuf);
198 prs_mem_free(&rbuf);
200 return result;
203 /* Enumerate dfs shares */
205 NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
206 uint32 info_level, DFS_INFO_CTR *ctr)
208 prs_struct qbuf, rbuf;
209 DFS_Q_DFS_ENUM q;
210 DFS_R_DFS_ENUM r;
211 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
213 ZERO_STRUCT(q);
214 ZERO_STRUCT(r);
216 /* Initialise parse structures */
218 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
219 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
221 /* Marshall data and send request */
223 init_dfs_q_dfs_enum(&q, info_level, ctr);
225 if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
226 !rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
227 goto done;
230 /* Unmarshall response */
232 r.ctr = ctr;
234 if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
235 goto done;
238 /* Return result */
240 result = werror_to_ntstatus(r.status);
242 done:
243 prs_mem_free(&qbuf);
244 prs_mem_free(&rbuf);
246 return result;