2 Unix SMB/CIFS implementation.
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.
24 #include "rpcclient.h"
26 /* Check DFS is supported by the remote server */
28 static NTSTATUS
cmd_dfs_version(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
29 int argc
, const char **argv
)
31 enum dfs_ManagerVersion version
;
35 printf("Usage: %s\n", argv
[0]);
39 result
= rpccli_dfs_GetManagerVersion(cli
, mem_ctx
, &version
);
41 if (!NT_STATUS_IS_OK(result
)) {
46 printf("dfs is present (%d)\n", version
);
48 printf("dfs is not present\n");
54 static NTSTATUS
cmd_dfs_add(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
55 int argc
, const char **argv
)
58 const char *path
, *servername
, *sharename
, *comment
;
62 printf("Usage: %s path servername sharename comment\n",
72 result
= rpccli_dfs_Add(cli
, mem_ctx
, path
, servername
,
73 sharename
, comment
, flags
);
78 static NTSTATUS
cmd_dfs_remove(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
79 int argc
, const char **argv
)
82 const char *path
, *servername
, *sharename
;
85 printf("Usage: %s path servername sharename\n", argv
[0]);
93 result
= rpccli_dfs_Remove(cli
, mem_ctx
, path
, servername
,
99 /* Display a DFS_INFO_1 structure */
101 static void display_dfs_info_1(struct dfs_Info1
*info1
)
103 printf("path: %s\n", info1
->path
);
106 /* Display a DFS_INFO_2 structure */
108 static void display_dfs_info_2(struct dfs_Info2
*info2
)
110 printf("path: %s\n", info2
->path
);
111 printf("\tcomment: %s\n", info2
->comment
);
113 printf("\tstate: %d\n", info2
->state
);
114 printf("\tnum_stores: %d\n", info2
->num_stores
);
117 /* Display a DFS_INFO_3 structure */
119 static void display_dfs_info_3(struct dfs_Info3
*info3
)
123 printf("path: %s\n", info3
->path
);
125 printf("\tcomment: %s\n", info3
->comment
);
127 printf("\tstate: %d\n", info3
->state
);
128 printf("\tnum_stores: %d\n", info3
->num_stores
);
130 for (i
= 0; i
< info3
->num_stores
; i
++) {
131 struct dfs_StorageInfo
*dsi
= &info3
->stores
[i
];
133 printf("\t\tstorage[%d] server: %s\n", i
, dsi
->server
);
135 printf("\t\tstorage[%d] share: %s\n", i
, dsi
->share
);
140 /* Display a DFS_INFO_CTR structure */
141 static void display_dfs_info(uint32 level
, union dfs_Info
*ctr
)
145 display_dfs_info_1(ctr
->info1
);
148 display_dfs_info_2(ctr
->info2
);
151 display_dfs_info_3(ctr
->info3
);
154 printf("unsupported info level %d\n",
160 static void display_dfs_enumstruct(struct dfs_EnumStruct
*ctr
)
164 /* count is always the first element, so we can just use info1 here */
165 for (i
= 0; i
< ctr
->e
.info1
->count
; i
++) {
166 switch (ctr
->level
) {
167 case 1: display_dfs_info_1(&ctr
->e
.info1
->s
[i
]); break;
168 case 2: display_dfs_info_2(&ctr
->e
.info2
->s
[i
]); break;
169 case 3: display_dfs_info_3(&ctr
->e
.info3
->s
[i
]); break;
171 printf("unsupported info level %d\n",
178 /* Enumerate dfs shares */
180 static NTSTATUS
cmd_dfs_enum(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
181 int argc
, const char **argv
)
183 struct dfs_EnumStruct str
;
184 struct dfs_EnumArray1 info1
;
185 struct dfs_EnumArray2 info2
;
186 struct dfs_EnumArray3 info3
;
187 struct dfs_EnumArray4 info4
;
188 struct dfs_EnumArray200 info200
;
189 struct dfs_EnumArray300 info300
;
195 printf("Usage: %s [info_level]\n", argv
[0]);
201 str
.level
= atoi(argv
[1]);
204 case 1: str
.e
.info1
= &info1
; ZERO_STRUCT(info1
); break;
205 case 2: str
.e
.info2
= &info2
; ZERO_STRUCT(info2
); break;
206 case 3: str
.e
.info3
= &info3
; ZERO_STRUCT(info3
); break;
207 case 4: str
.e
.info4
= &info4
; ZERO_STRUCT(info4
); break;
208 case 200: str
.e
.info200
= &info200
; ZERO_STRUCT(info200
); break;
209 case 300: str
.e
.info300
= &info300
; ZERO_STRUCT(info300
); break;
211 printf("Unknown info level %d\n", str
.level
);
215 result
= rpccli_dfs_Enum(cli
, mem_ctx
, str
.level
, 0xFFFFFFFF, &str
,
218 if (NT_STATUS_IS_OK(result
))
219 display_dfs_enumstruct(&str
);
224 /* Enumerate dfs shares */
226 static NTSTATUS
cmd_dfs_enumex(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
227 int argc
, const char **argv
)
229 struct dfs_EnumStruct str
;
230 struct dfs_EnumArray1 info1
;
231 struct dfs_EnumArray2 info2
;
232 struct dfs_EnumArray3 info3
;
233 struct dfs_EnumArray4 info4
;
234 struct dfs_EnumArray200 info200
;
235 struct dfs_EnumArray300 info300
;
240 if (argc
< 2 || argc
> 3) {
241 printf("Usage: %s dfs_name [info_level]\n", argv
[0]);
246 str
.level
= atoi(argv
[2]);
249 case 1: str
.e
.info1
= &info1
; ZERO_STRUCT(info1
); break;
250 case 2: str
.e
.info2
= &info2
; ZERO_STRUCT(info2
); break;
251 case 3: str
.e
.info3
= &info3
; ZERO_STRUCT(info3
); break;
252 case 4: str
.e
.info4
= &info4
; ZERO_STRUCT(info4
); break;
253 case 200: str
.e
.info200
= &info200
; ZERO_STRUCT(info200
); break;
254 case 300: str
.e
.info300
= &info300
; ZERO_STRUCT(info300
); break;
256 printf("Unknown info level %d\n", str
.level
);
260 result
= rpccli_dfs_EnumEx(cli
, mem_ctx
, argv
[1], str
.level
,
261 0xFFFFFFFF, &str
, &total
);
263 if (NT_STATUS_IS_OK(result
))
264 display_dfs_enumstruct(&str
);
270 static NTSTATUS
cmd_dfs_getinfo(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
271 int argc
, const char **argv
)
274 const char *path
, *servername
, *sharename
;
275 uint32 info_level
= 1;
278 if (argc
< 4 || argc
> 5) {
279 printf("Usage: %s path servername sharename "
280 "[info_level]\n", argv
[0]);
285 servername
= argv
[2];
289 info_level
= atoi(argv
[4]);
291 result
= rpccli_dfs_GetInfo(cli
, mem_ctx
, path
, servername
,
292 sharename
, info_level
, &ctr
);
294 if (NT_STATUS_IS_OK(result
))
295 display_dfs_info(info_level
, &ctr
);
300 /* List of commands exported by this module */
302 struct cmd_set dfs_commands
[] = {
306 { "dfsversion", RPC_RTYPE_NTSTATUS
, cmd_dfs_version
, NULL
, PI_NETDFS
, NULL
, "Query DFS support", "" },
307 { "dfsadd", RPC_RTYPE_NTSTATUS
, cmd_dfs_add
, NULL
, PI_NETDFS
, NULL
, "Add a DFS share", "" },
308 { "dfsremove", RPC_RTYPE_NTSTATUS
, cmd_dfs_remove
, NULL
, PI_NETDFS
, NULL
, "Remove a DFS share", "" },
309 { "dfsgetinfo",RPC_RTYPE_NTSTATUS
, cmd_dfs_getinfo
, NULL
, PI_NETDFS
, NULL
, "Query DFS share info", "" },
310 { "dfsenum", RPC_RTYPE_NTSTATUS
, cmd_dfs_enum
, NULL
, PI_NETDFS
, NULL
, "Enumerate dfs shares", "" },
311 { "dfsenumex", RPC_RTYPE_NTSTATUS
, cmd_dfs_enumex
, NULL
, PI_NETDFS
, NULL
, "Enumerate dfs shares", "" },