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 int DEBUGLEVEL;
26 extern pstring server;
28 /* Check DFS is supported by the remote server */
30 static uint32 cmd_dfs_exist(struct cli_state *cli, int argc, char **argv)
37 printf("Usage: %s\n", argv[0]);
41 if (!(mem_ctx = talloc_init())) {
42 DEBUG(0,("cmd_dfs_exist: talloc_init failed\n"));
43 return NT_STATUS_UNSUCCESSFUL;
46 /* Initialise RPC connection */
48 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
49 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
50 return NT_STATUS_UNSUCCESSFUL;
53 result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
55 if (result == NT_STATUS_NOPROBLEMO)
56 printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
58 cli_nt_session_close(cli);
63 static uint32 cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
67 char *entrypath, *servername, *sharename, *comment;
71 printf("Usage: %s entrypath servername sharename comment\n",
81 if (!(mem_ctx = talloc_init())) {
82 DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
83 return NT_STATUS_UNSUCCESSFUL;
86 /* Initialise RPC connection */
88 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
89 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
90 return NT_STATUS_UNSUCCESSFUL;
93 result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
94 sharename, comment, flags);
96 cli_nt_session_close(cli);
101 static uint32 cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
105 char *entrypath, *servername, *sharename;
108 printf("Usage: %s entrypath servername sharename\n", argv[0]);
113 servername = argv[2];
116 if (!(mem_ctx = talloc_init())) {
117 DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
118 return NT_STATUS_UNSUCCESSFUL;
121 /* Initialise RPC connection */
123 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
124 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
125 return NT_STATUS_UNSUCCESSFUL;
128 result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
131 cli_nt_session_close(cli);
136 /* Display a DFS_INFO_1 structure */
138 static void display_dfs_info_1(DFS_INFO_1 *info1)
142 unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
143 printf("entrypath: %s\n", temp);
146 /* Display a DFS_INFO_2 structure */
148 static void display_dfs_info_2(DFS_INFO_2 *info2)
152 unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
153 printf("entrypath: %s\n", temp);
155 unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
156 printf("\tcomment: %s\n", temp);
158 printf("\tstate: %d\n", info2->state);
159 printf("\tnum_storages: %d\n", info2->num_storages);
162 /* Display a DFS_INFO_3 structure */
164 static void display_dfs_info_3(DFS_INFO_3 *info3)
169 unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
170 printf("entrypath: %s\n", temp);
172 unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
173 printf("\tcomment: %s\n", temp);
175 printf("\tstate: %d\n", info3->state);
176 printf("\tnum_storages: %d\n", info3->num_storages);
178 for (i = 0; i < info3->num_storages; i++) {
179 DFS_STORAGE_INFO *dsi = &info3->storages[i];
181 unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
182 printf("\t\tstorage[%d] servername: %s\n", i, temp);
184 unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
185 printf("\t\tstorage[%d] sharename: %s\n", i, temp);
189 /* Display a DFS_INFO_CTR structure */
191 static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
195 for (i = 0; i < ctr->num_entries; i++) {
196 switch (ctr->switch_value) {
198 display_dfs_info_1(&ctr->dfs.info1[i]);
201 display_dfs_info_2(&ctr->dfs.info2[i]);
204 display_dfs_info_3(&ctr->dfs.info3[i]);
207 printf("unsupported info level %d\n",
214 /* Enumerate dfs shares */
216 static uint32 cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
220 uint32 result, info_level = 1;
223 printf("Usage: %s [info_level]\n", argv[0]);
228 info_level = atoi(argv[1]);
230 if (!(mem_ctx = talloc_init())) {
231 DEBUG(0,("cmd_dfs_enum: talloc_init failed\n"));
232 return NT_STATUS_UNSUCCESSFUL;
235 /* Initialise RPC connection */
237 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
238 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
239 return NT_STATUS_UNSUCCESSFUL;
242 /* Call RPC function */
244 if ((result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr))
245 != NT_STATUS_NOPROBLEMO) {
251 display_dfs_info_ctr(&ctr);
255 cli_nt_session_close(cli);
260 static uint32 cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
264 char *entrypath, *servername, *sharename;
265 uint32 info_level = 1;
268 if (argc < 4 || argc > 5) {
269 printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
274 servername = argv[2];
278 info_level = atoi(argv[4]);
280 if (!(mem_ctx = talloc_init())) {
281 DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
282 return NT_STATUS_UNSUCCESSFUL;
285 /* Initialise RPC connection */
287 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
288 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
289 return NT_STATUS_UNSUCCESSFUL;
292 /* Call RPC function */
294 if ((result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
295 sharename, info_level, &ctr))
296 != NT_STATUS_NOPROBLEMO) {
302 display_dfs_info_ctr(&ctr);
306 cli_nt_session_close(cli);
311 /* List of commands exported by this module */
313 struct cmd_set dfs_commands[] = {
317 { "dfsexist", cmd_dfs_exist, "Query DFS support", "" },
318 { "dfsadd", cmd_dfs_add, "Add a DFS share", "" },
319 { "dfsremove", cmd_dfs_remove, "Remove a DFS share", "" },
320 { "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info", "" },
321 { "dfsenum", cmd_dfs_enum, "Enumerate dfs shares", "" },