r23954: merge from 3_0-ctdb-tridge:
[Samba/nascimento.git] / source3 / rpcclient / cmd_dfs.c
blob7f3aab3997f25ef7d2730b34a09ffa231cebe04c
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"
25 /* Check DFS is supported by the remote server */
27 static NTSTATUS cmd_dfs_version(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
28 int argc, const char **argv)
30 enum dfs_ManagerVersion version;
31 NTSTATUS result;
33 if (argc != 1) {
34 printf("Usage: %s\n", argv[0]);
35 return NT_STATUS_OK;
38 result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &version);
40 if (!NT_STATUS_IS_OK(result)) {
41 return result;
44 if (version > 0) {
45 printf("dfs is present (%d)\n", version);
46 } else {
47 printf("dfs is not present\n");
50 return NT_STATUS_OK;
53 static NTSTATUS cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
54 int argc, const char **argv)
56 NTSTATUS result;
57 const char *path, *servername, *sharename, *comment;
58 uint32 flags = 0;
60 if (argc != 5) {
61 printf("Usage: %s path servername sharename comment\n",
62 argv[0]);
63 return NT_STATUS_OK;
66 path = argv[1];
67 servername = argv[2];
68 sharename = argv[3];
69 comment = argv[4];
71 result = rpccli_dfs_Add(cli, mem_ctx, path, servername,
72 sharename, comment, flags);
74 return result;
77 static NTSTATUS cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
78 int argc, const char **argv)
80 NTSTATUS result;
81 const char *path, *servername, *sharename;
83 if (argc != 4) {
84 printf("Usage: %s path servername sharename\n", argv[0]);
85 return NT_STATUS_OK;
88 path = argv[1];
89 servername = argv[2];
90 sharename = argv[3];
92 result = rpccli_dfs_Remove(cli, mem_ctx, path, servername,
93 sharename);
95 return result;
98 /* Display a DFS_INFO_1 structure */
100 static void display_dfs_info_1(struct dfs_Info1 *info1)
102 printf("path: %s\n", info1->path);
105 /* Display a DFS_INFO_2 structure */
107 static void display_dfs_info_2(struct dfs_Info2 *info2)
109 printf("path: %s\n", info2->path);
110 printf("\tcomment: %s\n", info2->comment);
112 printf("\tstate: %d\n", info2->state);
113 printf("\tnum_stores: %d\n", info2->num_stores);
116 /* Display a DFS_INFO_3 structure */
118 static void display_dfs_info_3(struct dfs_Info3 *info3)
120 int i;
122 printf("path: %s\n", info3->path);
124 printf("\tcomment: %s\n", info3->comment);
126 printf("\tstate: %d\n", info3->state);
127 printf("\tnum_stores: %d\n", info3->num_stores);
129 for (i = 0; i < info3->num_stores; i++) {
130 struct dfs_StorageInfo *dsi = &info3->stores[i];
132 printf("\t\tstorage[%d] server: %s\n", i, dsi->server);
134 printf("\t\tstorage[%d] share: %s\n", i, dsi->share);
139 /* Display a DFS_INFO_CTR structure */
140 static void display_dfs_info(uint32 level, union dfs_Info *ctr)
142 switch (level) {
143 case 0x01:
144 display_dfs_info_1(ctr->info1);
145 break;
146 case 0x02:
147 display_dfs_info_2(ctr->info2);
148 break;
149 case 0x03:
150 display_dfs_info_3(ctr->info3);
151 break;
152 default:
153 printf("unsupported info level %d\n",
154 level);
155 break;
159 static void display_dfs_enumstruct(struct dfs_EnumStruct *ctr)
161 int i;
163 /* count is always the first element, so we can just use info1 here */
164 for (i = 0; i < ctr->e.info1->count; i++) {
165 switch (ctr->level) {
166 case 1: display_dfs_info_1(&ctr->e.info1->s[i]); break;
167 case 2: display_dfs_info_2(&ctr->e.info2->s[i]); break;
168 case 3: display_dfs_info_3(&ctr->e.info3->s[i]); break;
169 default:
170 printf("unsupported info level %d\n",
171 ctr->level);
172 return;
177 /* Enumerate dfs shares */
179 static NTSTATUS cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
180 int argc, const char **argv)
182 struct dfs_EnumStruct str;
183 struct dfs_EnumArray1 info1;
184 struct dfs_EnumArray2 info2;
185 struct dfs_EnumArray3 info3;
186 struct dfs_EnumArray4 info4;
187 struct dfs_EnumArray200 info200;
188 struct dfs_EnumArray300 info300;
190 NTSTATUS result;
191 uint32 total = 0;
193 if (argc > 2) {
194 printf("Usage: %s [info_level]\n", argv[0]);
195 return NT_STATUS_OK;
198 str.level = 1;
199 if (argc == 2)
200 str.level = atoi(argv[1]);
202 switch (str.level) {
203 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
204 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
205 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
206 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
207 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
208 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
209 default:
210 printf("Unknown info level %d\n", str.level);
211 break;
214 result = rpccli_dfs_Enum(cli, mem_ctx, str.level, 0xFFFFFFFF, &str,
215 &total);
217 if (NT_STATUS_IS_OK(result))
218 display_dfs_enumstruct(&str);
220 return result;
223 /* Enumerate dfs shares */
225 static NTSTATUS cmd_dfs_enumex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
226 int argc, const char **argv)
228 struct dfs_EnumStruct str;
229 struct dfs_EnumArray1 info1;
230 struct dfs_EnumArray2 info2;
231 struct dfs_EnumArray3 info3;
232 struct dfs_EnumArray4 info4;
233 struct dfs_EnumArray200 info200;
234 struct dfs_EnumArray300 info300;
236 NTSTATUS result;
237 uint32 total = 0;
239 if (argc < 2 || argc > 3) {
240 printf("Usage: %s dfs_name [info_level]\n", argv[0]);
241 return NT_STATUS_OK;
244 if (argc == 3)
245 str.level = atoi(argv[2]);
247 switch (str.level) {
248 case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
249 case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
250 case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
251 case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
252 case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
253 case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
254 default:
255 printf("Unknown info level %d\n", str.level);
256 break;
259 result = rpccli_dfs_EnumEx(cli, mem_ctx, argv[1], str.level,
260 0xFFFFFFFF, &str, &total);
262 if (NT_STATUS_IS_OK(result))
263 display_dfs_enumstruct(&str);
265 return result;
269 static NTSTATUS cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
270 int argc, const char **argv)
272 NTSTATUS result;
273 const char *path, *servername, *sharename;
274 uint32 info_level = 1;
275 union dfs_Info ctr;
277 if (argc < 4 || argc > 5) {
278 printf("Usage: %s path servername sharename "
279 "[info_level]\n", argv[0]);
280 return NT_STATUS_OK;
283 path = argv[1];
284 servername = argv[2];
285 sharename = argv[3];
287 if (argc == 5)
288 info_level = atoi(argv[4]);
290 result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername,
291 sharename, info_level, &ctr);
293 if (NT_STATUS_IS_OK(result))
294 display_dfs_info(info_level, &ctr);
296 return result;
299 /* List of commands exported by this module */
301 struct cmd_set dfs_commands[] = {
303 { "DFS" },
305 { "dfsversion", RPC_RTYPE_NTSTATUS, cmd_dfs_version, NULL, PI_NETDFS, NULL, "Query DFS support", "" },
306 { "dfsadd", RPC_RTYPE_NTSTATUS, cmd_dfs_add, NULL, PI_NETDFS, NULL, "Add a DFS share", "" },
307 { "dfsremove", RPC_RTYPE_NTSTATUS, cmd_dfs_remove, NULL, PI_NETDFS, NULL, "Remove a DFS share", "" },
308 { "dfsgetinfo",RPC_RTYPE_NTSTATUS, cmd_dfs_getinfo, NULL, PI_NETDFS, NULL, "Query DFS share info", "" },
309 { "dfsenum", RPC_RTYPE_NTSTATUS, cmd_dfs_enum, NULL, PI_NETDFS, NULL, "Enumerate dfs shares", "" },
310 { "dfsenumex", RPC_RTYPE_NTSTATUS, cmd_dfs_enumex, NULL, PI_NETDFS, NULL, "Enumerate dfs shares", "" },
312 { NULL }