2 Unix SMB/CIFS implementation.
5 Copyright (C) Tim Potter 2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpcclient.h"
25 /* Check DFS is supported by the remote server */
27 static NTSTATUS
cmd_dfs_exist(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
28 int argc
, char **argv
)
34 printf("Usage: %s\n", argv
[0]);
38 result
= cli_dfs_exist(cli
, mem_ctx
, &dfs_exists
);
40 if (NT_STATUS_IS_OK(result
))
41 printf("dfs is %spresent\n", dfs_exists
? "" : "not ");
46 static NTSTATUS
cmd_dfs_add(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
47 int argc
, char **argv
)
50 char *entrypath
, *servername
, *sharename
, *comment
;
54 printf("Usage: %s entrypath servername sharename comment\n",
64 result
= cli_dfs_add(cli
, mem_ctx
, entrypath
, servername
,
65 sharename
, comment
, flags
);
70 static NTSTATUS
cmd_dfs_remove(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
71 int argc
, char **argv
)
74 char *entrypath
, *servername
, *sharename
;
77 printf("Usage: %s entrypath servername sharename\n", argv
[0]);
85 result
= cli_dfs_remove(cli
, mem_ctx
, entrypath
, servername
,
91 /* Display a DFS_INFO_1 structure */
93 static void display_dfs_info_1(DFS_INFO_1
*info1
)
97 unistr2_to_ascii(temp
, &info1
->entrypath
, sizeof(temp
) - 1);
98 printf("entrypath: %s\n", temp
);
101 /* Display a DFS_INFO_2 structure */
103 static void display_dfs_info_2(DFS_INFO_2
*info2
)
107 unistr2_to_ascii(temp
, &info2
->entrypath
, sizeof(temp
) - 1);
108 printf("entrypath: %s\n", temp
);
110 unistr2_to_ascii(temp
, &info2
->comment
, sizeof(temp
) - 1);
111 printf("\tcomment: %s\n", temp
);
113 printf("\tstate: %d\n", info2
->state
);
114 printf("\tnum_storages: %d\n", info2
->num_storages
);
117 /* Display a DFS_INFO_3 structure */
119 static void display_dfs_info_3(DFS_INFO_3
*info3
)
124 unistr2_to_ascii(temp
, &info3
->entrypath
, sizeof(temp
) - 1);
125 printf("entrypath: %s\n", temp
);
127 unistr2_to_ascii(temp
, &info3
->comment
, sizeof(temp
) - 1);
128 printf("\tcomment: %s\n", temp
);
130 printf("\tstate: %d\n", info3
->state
);
131 printf("\tnum_storages: %d\n", info3
->num_storages
);
133 for (i
= 0; i
< info3
->num_storages
; i
++) {
134 DFS_STORAGE_INFO
*dsi
= &info3
->storages
[i
];
136 unistr2_to_ascii(temp
, &dsi
->servername
, sizeof(temp
) - 1);
137 printf("\t\tstorage[%d] servername: %s\n", i
, temp
);
139 unistr2_to_ascii(temp
, &dsi
->sharename
, sizeof(temp
) - 1);
140 printf("\t\tstorage[%d] sharename: %s\n", i
, temp
);
144 /* Display a DFS_INFO_CTR structure */
146 static void display_dfs_info_ctr(DFS_INFO_CTR
*ctr
)
150 for (i
= 0; i
< ctr
->num_entries
; i
++) {
151 switch (ctr
->switch_value
) {
153 display_dfs_info_1(&ctr
->dfs
.info1
[i
]);
156 display_dfs_info_2(&ctr
->dfs
.info2
[i
]);
159 display_dfs_info_3(&ctr
->dfs
.info3
[i
]);
162 printf("unsupported info level %d\n",
169 /* Enumerate dfs shares */
171 static NTSTATUS
cmd_dfs_enum(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
172 int argc
, char **argv
)
176 uint32 info_level
= 1;
179 printf("Usage: %s [info_level]\n", argv
[0]);
184 info_level
= atoi(argv
[1]);
186 result
= cli_dfs_enum(cli
, mem_ctx
, info_level
, &ctr
);
188 if (NT_STATUS_IS_OK(result
))
189 display_dfs_info_ctr(&ctr
);
194 static NTSTATUS
cmd_dfs_getinfo(struct cli_state
*cli
, TALLOC_CTX
*mem_ctx
,
195 int argc
, char **argv
)
198 char *entrypath
, *servername
, *sharename
;
199 uint32 info_level
= 1;
202 if (argc
< 4 || argc
> 5) {
203 printf("Usage: %s entrypath servername sharename "
204 "[info_level]\n", argv
[0]);
209 servername
= argv
[2];
213 info_level
= atoi(argv
[4]);
215 result
= cli_dfs_get_info(cli
, mem_ctx
, entrypath
, servername
,
216 sharename
, info_level
, &ctr
);
218 if (NT_STATUS_IS_OK(result
))
219 display_dfs_info_ctr(&ctr
);
224 /* List of commands exported by this module */
226 struct cmd_set dfs_commands
[] = {
230 { "dfsexist", cmd_dfs_exist
, PI_NETDFS
, "Query DFS support", "" },
231 { "dfsadd", cmd_dfs_add
, PI_NETDFS
, "Add a DFS share", "" },
232 { "dfsremove", cmd_dfs_remove
, PI_NETDFS
, "Remove a DFS share", "" },
233 { "dfsgetinfo", cmd_dfs_getinfo
, PI_NETDFS
, "Query DFS share info", "" },
234 { "dfsenum", cmd_dfs_enum
, PI_NETDFS
, "Enumerate dfs shares", "" },