r22122: Start to fix csc issue with Vista. Make smbd support
[Samba/bb.git] / source3 / rpcclient / cmd_dfs.c
blob7e898ddc52a3d5b7acbe85654690911a809f2ed5
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "rpcclient.h"
26 /* Check DFS is supported by the remote server */
28 static NTSTATUS cmd_dfs_exist(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
29 int argc, const char **argv)
31 uint32 dfs_exists;
32 NTSTATUS result;
34 if (argc != 1) {
35 printf("Usage: %s\n", argv[0]);
36 return NT_STATUS_OK;
39 result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &dfs_exists);
41 if (NT_STATUS_IS_OK(result))
42 printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
44 return result;
47 static NTSTATUS cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
48 int argc, const char **argv)
50 NTSTATUS result;
51 const char *path, *servername, *sharename, *comment;
52 uint32 flags = 0;
54 if (argc != 5) {
55 printf("Usage: %s path servername sharename comment\n",
56 argv[0]);
57 return NT_STATUS_OK;
60 path = argv[1];
61 servername = argv[2];
62 sharename = argv[3];
63 comment = argv[4];
65 result = rpccli_dfs_Add(cli, mem_ctx, path, servername,
66 sharename, comment, flags);
68 return result;
71 static NTSTATUS cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
72 int argc, const char **argv)
74 NTSTATUS result;
75 const char *path, *servername, *sharename;
77 if (argc != 4) {
78 printf("Usage: %s path servername sharename\n", argv[0]);
79 return NT_STATUS_OK;
82 path = argv[1];
83 servername = argv[2];
84 sharename = argv[3];
86 result = rpccli_dfs_Remove(cli, mem_ctx, path, servername,
87 sharename);
89 return result;
92 /* Display a DFS_INFO_1 structure */
94 static void display_dfs_info_1(struct dfs_Info1 *info1)
96 printf("path: %s\n", info1->path);
99 /* Display a DFS_INFO_2 structure */
101 static void display_dfs_info_2(struct dfs_Info2 *info2)
103 printf("path: %s\n", info2->path);
104 printf("\tcomment: %s\n", info2->comment);
106 printf("\tstate: %d\n", info2->state);
107 printf("\tnum_stores: %d\n", info2->num_stores);
110 /* Display a DFS_INFO_3 structure */
112 static void display_dfs_info_3(struct dfs_Info3 *info3)
114 int i;
116 printf("path: %s\n", info3->path);
118 printf("\tcomment: %s\n", info3->comment);
120 printf("\tstate: %d\n", info3->state);
121 printf("\tnum_stores: %d\n", info3->num_stores);
123 for (i = 0; i < info3->num_stores; i++) {
124 struct dfs_StorageInfo *dsi = &info3->stores[i];
126 printf("\t\tstorage[%d] server: %s\n", i, dsi->server);
128 printf("\t\tstorage[%d] share: %s\n", i, dsi->share);
133 /* Display a DFS_INFO_CTR structure */
134 static void display_dfs_info(uint32 level, union dfs_Info *ctr)
136 switch (level) {
137 case 0x01:
138 display_dfs_info_1(ctr->info1);
139 break;
140 case 0x02:
141 display_dfs_info_2(ctr->info2);
142 break;
143 case 0x03:
144 display_dfs_info_3(ctr->info3);
145 break;
146 default:
147 printf("unsupported info level %d\n",
148 level);
149 break;
153 static void display_dfs_enumstruct(struct dfs_EnumStruct *ctr)
155 int i;
157 /* count is always the first element, so we can just use info1 here */
158 for (i = 0; i < ctr->e.info1->count; i++) {
159 switch (ctr->level) {
160 case 1: display_dfs_info_1(&ctr->e.info1->s[i]); break;
161 case 2: display_dfs_info_2(&ctr->e.info2->s[i]); break;
162 case 3: display_dfs_info_3(&ctr->e.info3->s[i]); break;
163 default:
164 printf("unsupported info level %d\n",
165 ctr->level);
166 return;
171 /* Enumerate dfs shares */
173 static NTSTATUS cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
174 int argc, const char **argv)
176 struct dfs_EnumStruct str;
177 struct dfs_EnumArray1 info1;
178 struct dfs_EnumArray2 info2;
179 struct dfs_EnumArray3 info3;
180 struct dfs_EnumArray4 info4;
181 struct dfs_EnumArray200 info200;
182 struct dfs_EnumArray300 info300;
184 NTSTATUS result;
185 uint32 total = 0;
186 uint32 unknown = 0;
188 if (argc > 2) {
189 printf("Usage: %s [info_level]\n", argv[0]);
190 return NT_STATUS_OK;
193 str.level = 1;
194 if (argc == 2)
195 str.level = atoi(argv[1]);
197 switch (str.level) {
198 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
199 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
200 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
201 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
202 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
203 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
204 default:
205 printf("Unknown info level %d\n", str.level);
206 break;
209 result = rpccli_dfs_Enum(cli, mem_ctx, str.level, 0xFFFFFFFF, &str,
210 &unknown, &total);
212 if (NT_STATUS_IS_OK(result))
213 display_dfs_enumstruct(&str);
215 return result;
218 /* Enumerate dfs shares */
220 static NTSTATUS cmd_dfs_enumex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
221 int argc, const char **argv)
223 struct dfs_EnumStruct str;
224 struct dfs_EnumArray1 info1;
225 struct dfs_EnumArray2 info2;
226 struct dfs_EnumArray3 info3;
227 struct dfs_EnumArray4 info4;
228 struct dfs_EnumArray200 info200;
229 struct dfs_EnumArray300 info300;
231 NTSTATUS result;
232 uint32 total = 0;
234 if (argc < 2 || argc > 3) {
235 printf("Usage: %s dfs_name [info_level]\n", argv[0]);
236 return NT_STATUS_OK;
239 if (argc == 3)
240 str.level = atoi(argv[2]);
242 switch (str.level) {
243 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
244 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
245 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
246 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
247 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
248 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
249 default:
250 printf("Unknown info level %d\n", str.level);
251 break;
254 result = rpccli_dfs_EnumEx(cli, mem_ctx, argv[1], str.level,
255 0xFFFFFFFF, &str, &total);
257 if (NT_STATUS_IS_OK(result))
258 display_dfs_enumstruct(&str);
260 return result;
264 static NTSTATUS cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
265 int argc, const char **argv)
267 NTSTATUS result;
268 const char *path, *servername, *sharename;
269 uint32 info_level = 1;
270 union dfs_Info ctr;
272 if (argc < 4 || argc > 5) {
273 printf("Usage: %s path servername sharename "
274 "[info_level]\n", argv[0]);
275 return NT_STATUS_OK;
278 path = argv[1];
279 servername = argv[2];
280 sharename = argv[3];
282 if (argc == 5)
283 info_level = atoi(argv[4]);
285 result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername,
286 sharename, info_level, &ctr);
288 if (NT_STATUS_IS_OK(result))
289 display_dfs_info(info_level, &ctr);
291 return result;
294 /* List of commands exported by this module */
296 struct cmd_set dfs_commands[] = {
298 { "DFS" },
300 { "dfsexist", RPC_RTYPE_NTSTATUS, cmd_dfs_exist, NULL, PI_NETDFS, NULL, "Query DFS support", "" },
301 { "dfsadd", RPC_RTYPE_NTSTATUS, cmd_dfs_add, NULL, PI_NETDFS, NULL, "Add a DFS share", "" },
302 { "dfsremove", RPC_RTYPE_NTSTATUS, cmd_dfs_remove, NULL, PI_NETDFS, NULL, "Remove a DFS share", "" },
303 { "dfsgetinfo",RPC_RTYPE_NTSTATUS, cmd_dfs_getinfo, NULL, PI_NETDFS, NULL, "Query DFS share info", "" },
304 { "dfsenum", RPC_RTYPE_NTSTATUS, cmd_dfs_enum, NULL, PI_NETDFS, NULL, "Enumerate dfs shares", "" },
305 { "dfsenumex", RPC_RTYPE_NTSTATUS, cmd_dfs_enumex, NULL, PI_NETDFS, NULL, "Enumerate dfs shares", "" },
307 { NULL }