2 Unix SMB/Netbios implementation.
6 Copyright (C) Tim Potter 2000
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.
25 extern pstring server;
27 /* Check DFS is supported by the remote server */
29 static NTSTATUS cmd_dfs_exist(struct cli_state *cli, int argc, char **argv)
36 printf("Usage: %s\n", argv[0]);
40 if (!(mem_ctx = talloc_init())) {
41 DEBUG(0,("cmd_dfs_exist: talloc_init failed\n"));
42 return NT_STATUS_UNSUCCESSFUL;
45 /* Initialise RPC connection */
47 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
48 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
49 result = NT_STATUS_UNSUCCESSFUL;
53 result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
55 if (NT_STATUS_IS_OK(result))
56 printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
58 cli_nt_session_close(cli);
61 talloc_destroy(mem_ctx);
65 static NTSTATUS cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
69 char *entrypath, *servername, *sharename, *comment;
73 printf("Usage: %s entrypath servername sharename comment\n",
83 if (!(mem_ctx = talloc_init())) {
84 DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
85 return NT_STATUS_UNSUCCESSFUL;
88 /* Initialise RPC connection */
90 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
91 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
92 result = NT_STATUS_UNSUCCESSFUL;
96 result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
97 sharename, comment, flags);
99 cli_nt_session_close(cli);
102 talloc_destroy(mem_ctx);
106 static NTSTATUS cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
110 char *entrypath, *servername, *sharename;
113 printf("Usage: %s entrypath servername sharename\n", argv[0]);
118 servername = argv[2];
121 if (!(mem_ctx = talloc_init())) {
122 DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
123 return NT_STATUS_UNSUCCESSFUL;
126 /* Initialise RPC connection */
128 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
129 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
130 result = NT_STATUS_UNSUCCESSFUL;
134 result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
137 cli_nt_session_close(cli);
140 talloc_destroy(mem_ctx);
144 /* Display a DFS_INFO_1 structure */
146 static void display_dfs_info_1(DFS_INFO_1 *info1)
150 unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
151 printf("entrypath: %s\n", temp);
154 /* Display a DFS_INFO_2 structure */
156 static void display_dfs_info_2(DFS_INFO_2 *info2)
160 unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
161 printf("entrypath: %s\n", temp);
163 unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
164 printf("\tcomment: %s\n", temp);
166 printf("\tstate: %d\n", info2->state);
167 printf("\tnum_storages: %d\n", info2->num_storages);
170 /* Display a DFS_INFO_3 structure */
172 static void display_dfs_info_3(DFS_INFO_3 *info3)
177 unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
178 printf("entrypath: %s\n", temp);
180 unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
181 printf("\tcomment: %s\n", temp);
183 printf("\tstate: %d\n", info3->state);
184 printf("\tnum_storages: %d\n", info3->num_storages);
186 for (i = 0; i < info3->num_storages; i++) {
187 DFS_STORAGE_INFO *dsi = &info3->storages[i];
189 unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
190 printf("\t\tstorage[%d] servername: %s\n", i, temp);
192 unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
193 printf("\t\tstorage[%d] sharename: %s\n", i, temp);
197 /* Display a DFS_INFO_CTR structure */
199 static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
203 for (i = 0; i < ctr->num_entries; i++) {
204 switch (ctr->switch_value) {
206 display_dfs_info_1(&ctr->dfs.info1[i]);
209 display_dfs_info_2(&ctr->dfs.info2[i]);
212 display_dfs_info_3(&ctr->dfs.info3[i]);
215 printf("unsupported info level %d\n",
222 /* Enumerate dfs shares */
224 static NTSTATUS cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
229 uint32 info_level = 1;
232 printf("Usage: %s [info_level]\n", argv[0]);
237 info_level = atoi(argv[1]);
239 if (!(mem_ctx = talloc_init())) {
240 DEBUG(0,("cmd_dfs_enum: talloc_init failed\n"));
241 return NT_STATUS_NO_MEMORY;
244 /* Initialise RPC connection */
246 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
247 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
248 result = NT_STATUS_UNSUCCESSFUL;
252 /* Call RPC function */
254 result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr);
255 if (NT_STATUS_IS_OK(result)) {
257 display_dfs_info_ctr(&ctr);
260 cli_nt_session_close(cli);
263 talloc_destroy(mem_ctx);
267 static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
271 char *entrypath, *servername, *sharename;
272 uint32 info_level = 1;
275 if (argc < 4 || argc > 5) {
276 printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
281 servername = argv[2];
285 info_level = atoi(argv[4]);
287 if (!(mem_ctx = talloc_init())) {
288 DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
289 return NT_STATUS_UNSUCCESSFUL;
292 /* Initialise RPC connection */
294 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
295 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
296 result = NT_STATUS_UNSUCCESSFUL;
300 /* Call RPC function */
302 result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
303 sharename, info_level, &ctr);
304 if (NT_STATUS_IS_OK(result)) {
306 display_dfs_info_ctr(&ctr);
309 cli_nt_session_close(cli);
312 talloc_destroy(mem_ctx);
316 /* List of commands exported by this module */
318 struct cmd_set dfs_commands[] = {
322 { "dfsexist", cmd_dfs_exist, "Query DFS support", "" },
323 { "dfsadd", cmd_dfs_add, "Add a DFS share", "" },
324 { "dfsremove", cmd_dfs_remove, "Remove a DFS share", "" },
325 { "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info", "" },
326 { "dfsenum", cmd_dfs_enum, "Enumerate dfs shares", "" },