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 result = NT_STATUS_UNSUCCESSFUL;
54 result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
56 if (result == NT_STATUS_OK)
57 printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
59 cli_nt_session_close(cli);
62 talloc_destroy(mem_ctx);
66 static uint32 cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
70 char *entrypath, *servername, *sharename, *comment;
74 printf("Usage: %s entrypath servername sharename comment\n",
84 if (!(mem_ctx = talloc_init())) {
85 DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
86 return NT_STATUS_UNSUCCESSFUL;
89 /* Initialise RPC connection */
91 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
92 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
93 result = NT_STATUS_UNSUCCESSFUL;
97 result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
98 sharename, comment, flags);
100 cli_nt_session_close(cli);
103 talloc_destroy(mem_ctx);
107 static uint32 cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
111 char *entrypath, *servername, *sharename;
114 printf("Usage: %s entrypath servername sharename\n", argv[0]);
119 servername = argv[2];
122 if (!(mem_ctx = talloc_init())) {
123 DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
124 return NT_STATUS_UNSUCCESSFUL;
127 /* Initialise RPC connection */
129 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
130 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
131 result = NT_STATUS_UNSUCCESSFUL;
135 result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
138 cli_nt_session_close(cli);
141 talloc_destroy(mem_ctx);
145 /* Display a DFS_INFO_1 structure */
147 static void display_dfs_info_1(DFS_INFO_1 *info1)
151 unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
152 printf("entrypath: %s\n", temp);
155 /* Display a DFS_INFO_2 structure */
157 static void display_dfs_info_2(DFS_INFO_2 *info2)
161 unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
162 printf("entrypath: %s\n", temp);
164 unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
165 printf("\tcomment: %s\n", temp);
167 printf("\tstate: %d\n", info2->state);
168 printf("\tnum_storages: %d\n", info2->num_storages);
171 /* Display a DFS_INFO_3 structure */
173 static void display_dfs_info_3(DFS_INFO_3 *info3)
178 unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
179 printf("entrypath: %s\n", temp);
181 unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
182 printf("\tcomment: %s\n", temp);
184 printf("\tstate: %d\n", info3->state);
185 printf("\tnum_storages: %d\n", info3->num_storages);
187 for (i = 0; i < info3->num_storages; i++) {
188 DFS_STORAGE_INFO *dsi = &info3->storages[i];
190 unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
191 printf("\t\tstorage[%d] servername: %s\n", i, temp);
193 unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
194 printf("\t\tstorage[%d] sharename: %s\n", i, temp);
198 /* Display a DFS_INFO_CTR structure */
200 static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
204 for (i = 0; i < ctr->num_entries; i++) {
205 switch (ctr->switch_value) {
207 display_dfs_info_1(&ctr->dfs.info1[i]);
210 display_dfs_info_2(&ctr->dfs.info2[i]);
213 display_dfs_info_3(&ctr->dfs.info3[i]);
216 printf("unsupported info level %d\n",
223 /* Enumerate dfs shares */
225 static uint32 cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
229 uint32 result, 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_UNSUCCESSFUL;
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 if ((result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr))
258 display_dfs_info_ctr(&ctr);
261 cli_nt_session_close(cli);
264 talloc_destroy(mem_ctx);
268 static uint32 cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
272 char *entrypath, *servername, *sharename;
273 uint32 info_level = 1;
276 if (argc < 4 || argc > 5) {
277 printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
282 servername = argv[2];
286 info_level = atoi(argv[4]);
288 if (!(mem_ctx = talloc_init())) {
289 DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
290 return NT_STATUS_UNSUCCESSFUL;
293 /* Initialise RPC connection */
295 if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
296 DEBUG(0, ("Could not initialize netdfs pipe!\n"));
297 result = NT_STATUS_UNSUCCESSFUL;
301 /* Call RPC function */
303 if ((result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
304 sharename, info_level, &ctr))
309 display_dfs_info_ctr(&ctr);
312 cli_nt_session_close(cli);
315 talloc_destroy(mem_ctx);
319 /* List of commands exported by this module */
321 struct cmd_set dfs_commands[] = {
325 { "dfsexist", cmd_dfs_exist, "Query DFS support", "" },
326 { "dfsadd", cmd_dfs_add, "Add a DFS share", "" },
327 { "dfsremove", cmd_dfs_remove, "Remove a DFS share", "" },
328 { "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info", "" },
329 { "dfsenum", cmd_dfs_enum, "Enumerate dfs shares", "" },