1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | RPC pipe client
|
---|
4 |
|
---|
5 | Copyright (C) Tim Potter 2000
|
---|
6 | Copyright (C) Jelmer Vernooij 2005.
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 3 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 | #include "rpcclient.h"
|
---|
24 | #include "../librpc/gen_ndr/cli_dfs.h"
|
---|
25 |
|
---|
26 | /* Check DFS is supported by the remote server */
|
---|
27 |
|
---|
28 | static WERROR cmd_dfs_version(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
29 | int argc, const char **argv)
|
---|
30 | {
|
---|
31 | enum dfs_ManagerVersion version;
|
---|
32 | NTSTATUS result;
|
---|
33 |
|
---|
34 | if (argc != 1) {
|
---|
35 | printf("Usage: %s\n", argv[0]);
|
---|
36 | return WERR_OK;
|
---|
37 | }
|
---|
38 |
|
---|
39 | result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &version);
|
---|
40 |
|
---|
41 | if (!NT_STATUS_IS_OK(result)) {
|
---|
42 | return ntstatus_to_werror(result);
|
---|
43 | }
|
---|
44 |
|
---|
45 | if (version > 0) {
|
---|
46 | printf("dfs is present (%d)\n", version);
|
---|
47 | } else {
|
---|
48 | printf("dfs is not present\n");
|
---|
49 | }
|
---|
50 |
|
---|
51 | return WERR_OK;
|
---|
52 | }
|
---|
53 |
|
---|
54 | static WERROR cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
55 | int argc, const char **argv)
|
---|
56 | {
|
---|
57 | NTSTATUS result;
|
---|
58 | WERROR werr;
|
---|
59 | const char *path, *servername, *sharename, *comment;
|
---|
60 | uint32 flags = 0;
|
---|
61 |
|
---|
62 | if (argc != 5) {
|
---|
63 | printf("Usage: %s path servername sharename comment\n",
|
---|
64 | argv[0]);
|
---|
65 | return WERR_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 | path = argv[1];
|
---|
69 | servername = argv[2];
|
---|
70 | sharename = argv[3];
|
---|
71 | comment = argv[4];
|
---|
72 |
|
---|
73 | result = rpccli_dfs_Add(cli, mem_ctx, path, servername,
|
---|
74 | sharename, comment, flags, &werr);
|
---|
75 | if (!NT_STATUS_IS_OK(result)) {
|
---|
76 | return ntstatus_to_werror(result);
|
---|
77 | }
|
---|
78 |
|
---|
79 | return werr;
|
---|
80 | }
|
---|
81 |
|
---|
82 | static WERROR cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
83 | int argc, const char **argv)
|
---|
84 | {
|
---|
85 | NTSTATUS result;
|
---|
86 | WERROR werr;
|
---|
87 | const char *path, *servername, *sharename;
|
---|
88 |
|
---|
89 | if (argc != 4) {
|
---|
90 | printf("Usage: %s path servername sharename\n", argv[0]);
|
---|
91 | return WERR_OK;
|
---|
92 | }
|
---|
93 |
|
---|
94 | path = argv[1];
|
---|
95 | servername = argv[2];
|
---|
96 | sharename = argv[3];
|
---|
97 |
|
---|
98 | result = rpccli_dfs_Remove(cli, mem_ctx, path, servername,
|
---|
99 | sharename, &werr);
|
---|
100 | if (!NT_STATUS_IS_OK(result)) {
|
---|
101 | return ntstatus_to_werror(result);
|
---|
102 | }
|
---|
103 |
|
---|
104 | return werr;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* Display a DFS_INFO_1 structure */
|
---|
108 |
|
---|
109 | static void display_dfs_info_1(struct dfs_Info1 *info1)
|
---|
110 | {
|
---|
111 | printf("path: %s\n", info1->path);
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* Display a DFS_INFO_2 structure */
|
---|
115 |
|
---|
116 | static void display_dfs_info_2(struct dfs_Info2 *info2)
|
---|
117 | {
|
---|
118 | printf("path: %s\n", info2->path);
|
---|
119 | printf("\tcomment: %s\n", info2->comment);
|
---|
120 |
|
---|
121 | printf("\tstate: %d\n", info2->state);
|
---|
122 | printf("\tnum_stores: %d\n", info2->num_stores);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /* Display a DFS_INFO_3 structure */
|
---|
126 |
|
---|
127 | static void display_dfs_info_3(struct dfs_Info3 *info3)
|
---|
128 | {
|
---|
129 | int i;
|
---|
130 |
|
---|
131 | printf("path: %s\n", info3->path);
|
---|
132 |
|
---|
133 | printf("\tcomment: %s\n", info3->comment);
|
---|
134 |
|
---|
135 | printf("\tstate: %d\n", info3->state);
|
---|
136 | printf("\tnum_stores: %d\n", info3->num_stores);
|
---|
137 |
|
---|
138 | for (i = 0; i < info3->num_stores; i++) {
|
---|
139 | struct dfs_StorageInfo *dsi = &info3->stores[i];
|
---|
140 |
|
---|
141 | printf("\t\tstorage[%d] server: %s\n", i, dsi->server);
|
---|
142 |
|
---|
143 | printf("\t\tstorage[%d] share: %s\n", i, dsi->share);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | /* Display a DFS_INFO_CTR structure */
|
---|
149 | static void display_dfs_info(uint32 level, union dfs_Info *ctr)
|
---|
150 | {
|
---|
151 | switch (level) {
|
---|
152 | case 0x01:
|
---|
153 | display_dfs_info_1(ctr->info1);
|
---|
154 | break;
|
---|
155 | case 0x02:
|
---|
156 | display_dfs_info_2(ctr->info2);
|
---|
157 | break;
|
---|
158 | case 0x03:
|
---|
159 | display_dfs_info_3(ctr->info3);
|
---|
160 | break;
|
---|
161 | default:
|
---|
162 | printf("unsupported info level %d\n",
|
---|
163 | level);
|
---|
164 | break;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | static void display_dfs_enumstruct(struct dfs_EnumStruct *ctr)
|
---|
169 | {
|
---|
170 | int i;
|
---|
171 |
|
---|
172 | /* count is always the first element, so we can just use info1 here */
|
---|
173 | for (i = 0; i < ctr->e.info1->count; i++) {
|
---|
174 | switch (ctr->level) {
|
---|
175 | case 1: display_dfs_info_1(&ctr->e.info1->s[i]); break;
|
---|
176 | case 2: display_dfs_info_2(&ctr->e.info2->s[i]); break;
|
---|
177 | case 3: display_dfs_info_3(&ctr->e.info3->s[i]); break;
|
---|
178 | default:
|
---|
179 | printf("unsupported info level %d\n",
|
---|
180 | ctr->level);
|
---|
181 | return;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | /* Enumerate dfs shares */
|
---|
187 |
|
---|
188 | static WERROR cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
189 | int argc, const char **argv)
|
---|
190 | {
|
---|
191 | struct dfs_EnumStruct str;
|
---|
192 | struct dfs_EnumArray1 info1;
|
---|
193 | struct dfs_EnumArray2 info2;
|
---|
194 | struct dfs_EnumArray3 info3;
|
---|
195 | struct dfs_EnumArray4 info4;
|
---|
196 | struct dfs_EnumArray200 info200;
|
---|
197 | struct dfs_EnumArray300 info300;
|
---|
198 |
|
---|
199 | NTSTATUS result;
|
---|
200 | WERROR werr;
|
---|
201 | uint32 total = 0;
|
---|
202 |
|
---|
203 | if (argc > 2) {
|
---|
204 | printf("Usage: %s [info_level]\n", argv[0]);
|
---|
205 | return WERR_OK;
|
---|
206 | }
|
---|
207 |
|
---|
208 | str.level = 1;
|
---|
209 | if (argc == 2)
|
---|
210 | str.level = atoi(argv[1]);
|
---|
211 |
|
---|
212 | switch (str.level) {
|
---|
213 | case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
|
---|
214 | case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
|
---|
215 | case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
|
---|
216 | case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
|
---|
217 | case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
|
---|
218 | case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
|
---|
219 | default:
|
---|
220 | printf("Unknown info level %d\n", str.level);
|
---|
221 | break;
|
---|
222 | }
|
---|
223 |
|
---|
224 | result = rpccli_dfs_Enum(cli, mem_ctx, str.level, 0xFFFFFFFF, &str,
|
---|
225 | &total, &werr);
|
---|
226 |
|
---|
227 | if (NT_STATUS_IS_OK(result)) {
|
---|
228 | display_dfs_enumstruct(&str);
|
---|
229 | }
|
---|
230 |
|
---|
231 | return werr;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /* Enumerate dfs shares */
|
---|
235 |
|
---|
236 | static WERROR cmd_dfs_enumex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
237 | int argc, const char **argv)
|
---|
238 | {
|
---|
239 | struct dfs_EnumStruct str;
|
---|
240 | struct dfs_EnumArray1 info1;
|
---|
241 | struct dfs_EnumArray2 info2;
|
---|
242 | struct dfs_EnumArray3 info3;
|
---|
243 | struct dfs_EnumArray4 info4;
|
---|
244 | struct dfs_EnumArray200 info200;
|
---|
245 | struct dfs_EnumArray300 info300;
|
---|
246 |
|
---|
247 | NTSTATUS result;
|
---|
248 | WERROR werr;
|
---|
249 | uint32 total = 0;
|
---|
250 |
|
---|
251 | if (argc < 2 || argc > 3) {
|
---|
252 | printf("Usage: %s dfs_name [info_level]\n", argv[0]);
|
---|
253 | return WERR_OK;
|
---|
254 | }
|
---|
255 |
|
---|
256 | str.level = 1;
|
---|
257 |
|
---|
258 | if (argc == 3)
|
---|
259 | str.level = atoi(argv[2]);
|
---|
260 |
|
---|
261 | switch (str.level) {
|
---|
262 | case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
|
---|
263 | case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
|
---|
264 | case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
|
---|
265 | case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
|
---|
266 | case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
|
---|
267 | case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
|
---|
268 | default:
|
---|
269 | printf("Unknown info level %d\n", str.level);
|
---|
270 | break;
|
---|
271 | }
|
---|
272 |
|
---|
273 | result = rpccli_dfs_EnumEx(cli, mem_ctx, argv[1], str.level,
|
---|
274 | 0xFFFFFFFF, &str, &total, &werr);
|
---|
275 |
|
---|
276 | if (NT_STATUS_IS_OK(result)) {
|
---|
277 | display_dfs_enumstruct(&str);
|
---|
278 | }
|
---|
279 |
|
---|
280 | return werr;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | static WERROR cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
|
---|
285 | int argc, const char **argv)
|
---|
286 | {
|
---|
287 | NTSTATUS result;
|
---|
288 | WERROR werr;
|
---|
289 | const char *path, *servername, *sharename;
|
---|
290 | uint32 info_level = 1;
|
---|
291 | union dfs_Info ctr;
|
---|
292 |
|
---|
293 | if (argc < 4 || argc > 5) {
|
---|
294 | printf("Usage: %s path servername sharename "
|
---|
295 | "[info_level]\n", argv[0]);
|
---|
296 | return WERR_OK;
|
---|
297 | }
|
---|
298 |
|
---|
299 | path = argv[1];
|
---|
300 | servername = argv[2];
|
---|
301 | sharename = argv[3];
|
---|
302 |
|
---|
303 | if (argc == 5)
|
---|
304 | info_level = atoi(argv[4]);
|
---|
305 |
|
---|
306 | result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername,
|
---|
307 | sharename, info_level, &ctr, &werr);
|
---|
308 |
|
---|
309 | if (NT_STATUS_IS_OK(result)) {
|
---|
310 | display_dfs_info(info_level, &ctr);
|
---|
311 | }
|
---|
312 |
|
---|
313 | return werr;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /* List of commands exported by this module */
|
---|
317 |
|
---|
318 | struct cmd_set dfs_commands[] = {
|
---|
319 |
|
---|
320 | { "DFS" },
|
---|
321 |
|
---|
322 | { "dfsversion", RPC_RTYPE_WERROR, NULL, cmd_dfs_version, &ndr_table_netdfs.syntax_id, NULL, "Query DFS support", "" },
|
---|
323 | { "dfsadd", RPC_RTYPE_WERROR, NULL, cmd_dfs_add, &ndr_table_netdfs.syntax_id, NULL, "Add a DFS share", "" },
|
---|
324 | { "dfsremove", RPC_RTYPE_WERROR, NULL, cmd_dfs_remove, &ndr_table_netdfs.syntax_id, NULL, "Remove a DFS share", "" },
|
---|
325 | { "dfsgetinfo", RPC_RTYPE_WERROR, NULL, cmd_dfs_getinfo, &ndr_table_netdfs.syntax_id, NULL, "Query DFS share info", "" },
|
---|
326 | { "dfsenum", RPC_RTYPE_WERROR, NULL, cmd_dfs_enum, &ndr_table_netdfs.syntax_id, NULL, "Enumerate dfs shares", "" },
|
---|
327 | { "dfsenumex", RPC_RTYPE_WERROR, NULL, cmd_dfs_enumex, &ndr_table_netdfs.syntax_id, NULL, "Enumerate dfs shares", "" },
|
---|
328 |
|
---|
329 | { NULL }
|
---|
330 | };
|
---|