s3: client: Add new utility function client_clean_name().
[Samba.git] / source3 / rpcclient / cmd_dfs.c
blob43d17b346082451f92fbd0a358271494dbf3820f
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Tim Potter 2000
6 Copyright (C) Jelmer Vernooij 2005.
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.
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.
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/>.
22 #include "includes.h"
23 #include "rpcclient.h"
24 #include "../librpc/gen_ndr/ndr_dfs_c.h"
26 /* Check DFS is supported by the remote server */
28 static WERROR cmd_dfs_version(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
29 int argc, const char **argv)
31 enum dfs_ManagerVersion version;
32 NTSTATUS result;
33 struct dcerpc_binding_handle *b = cli->binding_handle;
35 if (argc != 1) {
36 printf("Usage: %s\n", argv[0]);
37 return WERR_OK;
40 result = dcerpc_dfs_GetManagerVersion(b, mem_ctx, &version);
42 if (!NT_STATUS_IS_OK(result)) {
43 return ntstatus_to_werror(result);
46 if (version > 0) {
47 printf("dfs is present (%d)\n", version);
48 } else {
49 printf("dfs is not present\n");
52 return WERR_OK;
55 static WERROR cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
56 int argc, const char **argv)
58 NTSTATUS result;
59 WERROR werr;
60 const char *path, *servername, *sharename, *comment;
61 uint32_t flags = 0;
62 struct dcerpc_binding_handle *b = cli->binding_handle;
64 if (argc != 5) {
65 printf("Usage: %s path servername sharename comment\n",
66 argv[0]);
67 return WERR_OK;
70 path = argv[1];
71 servername = argv[2];
72 sharename = argv[3];
73 comment = argv[4];
75 result = dcerpc_dfs_Add(b, mem_ctx, path, servername,
76 sharename, comment, flags, &werr);
77 if (!NT_STATUS_IS_OK(result)) {
78 return ntstatus_to_werror(result);
81 return werr;
84 static WERROR cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
85 int argc, const char **argv)
87 NTSTATUS result;
88 WERROR werr;
89 const char *path, *servername, *sharename;
90 struct dcerpc_binding_handle *b = cli->binding_handle;
92 if (argc != 4) {
93 printf("Usage: %s path servername sharename\n", argv[0]);
94 return WERR_OK;
97 path = argv[1];
98 servername = argv[2];
99 sharename = argv[3];
101 result = dcerpc_dfs_Remove(b, mem_ctx, path, servername,
102 sharename, &werr);
103 if (!NT_STATUS_IS_OK(result)) {
104 return ntstatus_to_werror(result);
107 return werr;
110 /* Display a DFS_INFO_1 structure */
112 static void display_dfs_info_1(struct dfs_Info1 *info1)
114 printf("path: %s\n", info1->path);
117 /* Display a DFS_INFO_2 structure */
119 static void display_dfs_info_2(struct dfs_Info2 *info2)
121 printf("path: %s\n", info2->path);
122 printf("\tcomment: %s\n", info2->comment);
124 printf("\tstate: %d\n", info2->state);
125 printf("\tnum_stores: %d\n", info2->num_stores);
128 /* Display a DFS_INFO_3 structure */
130 static void display_dfs_info_3(struct dfs_Info3 *info3)
132 int i;
134 printf("path: %s\n", info3->path);
136 printf("\tcomment: %s\n", info3->comment);
138 printf("\tstate: %d\n", info3->state);
139 printf("\tnum_stores: %d\n", info3->num_stores);
141 for (i = 0; i < info3->num_stores; i++) {
142 struct dfs_StorageInfo *dsi = &info3->stores[i];
144 printf("\t\tstorage[%d] server: %s\n", i, dsi->server);
146 printf("\t\tstorage[%d] share: %s\n", i, dsi->share);
151 /* Display a DFS_INFO_CTR structure */
152 static void display_dfs_info(uint32_t level, union dfs_Info *ctr)
154 switch (level) {
155 case 0x01:
156 display_dfs_info_1(ctr->info1);
157 break;
158 case 0x02:
159 display_dfs_info_2(ctr->info2);
160 break;
161 case 0x03:
162 display_dfs_info_3(ctr->info3);
163 break;
164 default:
165 printf("unsupported info level %d\n",
166 level);
167 break;
171 static void display_dfs_enumstruct(struct dfs_EnumStruct *ctr)
173 int i;
175 /* count is always the first element, so we can just use info1 here */
176 for (i = 0; i < ctr->e.info1->count; i++) {
177 switch (ctr->level) {
178 case 1: display_dfs_info_1(&ctr->e.info1->s[i]); break;
179 case 2: display_dfs_info_2(&ctr->e.info2->s[i]); break;
180 case 3: display_dfs_info_3(&ctr->e.info3->s[i]); break;
181 default:
182 printf("unsupported info level %d\n",
183 ctr->level);
184 return;
189 /* Enumerate dfs shares */
191 static WERROR cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
192 int argc, const char **argv)
194 struct dfs_EnumStruct str;
195 struct dfs_EnumArray1 info1;
196 struct dfs_EnumArray2 info2;
197 struct dfs_EnumArray3 info3;
198 struct dfs_EnumArray4 info4;
199 struct dfs_EnumArray200 info200;
200 struct dfs_EnumArray300 info300;
201 struct dcerpc_binding_handle *b = cli->binding_handle;
203 NTSTATUS result;
204 WERROR werr;
205 uint32_t total = 0;
207 if (argc > 2) {
208 printf("Usage: %s [info_level]\n", argv[0]);
209 return WERR_OK;
212 str.level = 1;
213 if (argc == 2)
214 str.level = atoi(argv[1]);
216 switch (str.level) {
217 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
218 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
219 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
220 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
221 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
222 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
223 default:
224 printf("Unknown info level %d\n", str.level);
225 break;
228 result = dcerpc_dfs_Enum(b, mem_ctx, str.level, 0xFFFFFFFF, &str,
229 &total, &werr);
230 if (!NT_STATUS_IS_OK(result)) {
231 return ntstatus_to_werror(result);
233 if (W_ERROR_IS_OK(werr)) {
234 display_dfs_enumstruct(&str);
237 return werr;
240 /* Enumerate dfs shares */
242 static WERROR cmd_dfs_enumex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
243 int argc, const char **argv)
245 struct dfs_EnumStruct str;
246 struct dfs_EnumArray1 info1;
247 struct dfs_EnumArray2 info2;
248 struct dfs_EnumArray3 info3;
249 struct dfs_EnumArray4 info4;
250 struct dfs_EnumArray200 info200;
251 struct dfs_EnumArray300 info300;
252 struct dcerpc_binding_handle *b = cli->binding_handle;
254 NTSTATUS result;
255 WERROR werr;
256 uint32_t total = 0;
258 if (argc < 2 || argc > 3) {
259 printf("Usage: %s dfs_name [info_level]\n", argv[0]);
260 return WERR_OK;
263 str.level = 1;
265 if (argc == 3)
266 str.level = atoi(argv[2]);
268 switch (str.level) {
269 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
270 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
271 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
272 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
273 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
274 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
275 default:
276 printf("Unknown info level %d\n", str.level);
277 break;
280 result = dcerpc_dfs_EnumEx(b, mem_ctx, argv[1], str.level,
281 0xFFFFFFFF, &str, &total, &werr);
282 if (!NT_STATUS_IS_OK(result)) {
283 return ntstatus_to_werror(result);
285 if (W_ERROR_IS_OK(werr)) {
286 display_dfs_enumstruct(&str);
289 return werr;
293 static WERROR cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
294 int argc, const char **argv)
296 NTSTATUS result;
297 WERROR werr;
298 const char *path, *servername, *sharename;
299 uint32_t info_level = 1;
300 union dfs_Info ctr;
301 struct dcerpc_binding_handle *b = cli->binding_handle;
303 if (argc < 4 || argc > 5) {
304 printf("Usage: %s path servername sharename "
305 "[info_level]\n", argv[0]);
306 return WERR_OK;
309 path = argv[1];
310 servername = argv[2];
311 sharename = argv[3];
313 if (argc == 5)
314 info_level = atoi(argv[4]);
316 result = dcerpc_dfs_GetInfo(b, mem_ctx, path, servername,
317 sharename, info_level, &ctr, &werr);
318 if (!NT_STATUS_IS_OK(result)) {
319 return ntstatus_to_werror(result);
321 if (W_ERROR_IS_OK(werr)) {
322 display_dfs_info(info_level, &ctr);
325 return werr;
328 /* List of commands exported by this module */
330 struct cmd_set dfs_commands[] = {
332 { "DFS" },
334 { "dfsversion", RPC_RTYPE_WERROR, NULL, cmd_dfs_version, &ndr_table_netdfs, NULL, "Query DFS support", "" },
335 { "dfsadd", RPC_RTYPE_WERROR, NULL, cmd_dfs_add, &ndr_table_netdfs, NULL, "Add a DFS share", "" },
336 { "dfsremove", RPC_RTYPE_WERROR, NULL, cmd_dfs_remove, &ndr_table_netdfs, NULL, "Remove a DFS share", "" },
337 { "dfsgetinfo", RPC_RTYPE_WERROR, NULL, cmd_dfs_getinfo, &ndr_table_netdfs, NULL, "Query DFS share info", "" },
338 { "dfsenum", RPC_RTYPE_WERROR, NULL, cmd_dfs_enum, &ndr_table_netdfs, NULL, "Enumerate dfs shares", "" },
339 { "dfsenumex", RPC_RTYPE_WERROR, NULL, cmd_dfs_enumex, &ndr_table_netdfs, NULL, "Enumerate dfs shares", "" },
341 { NULL }