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_exist(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
29 int argc
, const char **argv
)
35 printf("Usage: %s\n", argv
[0]);
39 result
= rpccli_dfs_GetManagerVersion(cli
, mem_ctx
, &dfs_exists
);
41 if (NT_STATUS_IS_OK(result
))
42 printf("dfs is %spresent\n", dfs_exists
? "" : "not ");
47 static NTSTATUS
cmd_dfs_add(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
48 int argc
, const char **argv
)
51 const char *path
, *servername
, *sharename
, *comment
;
55 printf("Usage: %s path servername sharename comment\n",
65 result
= rpccli_dfs_Add(cli
, mem_ctx
, path
, servername
,
66 sharename
, comment
, flags
);
71 static NTSTATUS
cmd_dfs_remove(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
72 int argc
, const char **argv
)
75 const char *path
, *servername
, *sharename
;
78 printf("Usage: %s path servername sharename\n", argv
[0]);
86 result
= rpccli_dfs_Remove(cli
, mem_ctx
, path
, servername
,
92 /* Display a DFS_INFO_1 structure */
94 static void display_dfs_info_1(NETDFS_DFS_INFO1
*info1
)
98 unistr2_to_ascii(temp
, &info1
->path
, sizeof(temp
) - 1);
99 printf("path: %s\n", temp
);
102 /* Display a DFS_INFO_2 structure */
104 static void display_dfs_info_2(NETDFS_DFS_INFO2
*info2
)
108 unistr2_to_ascii(temp
, &info2
->path
, sizeof(temp
) - 1);
109 printf("path: %s\n", temp
);
111 unistr2_to_ascii(temp
, &info2
->comment
, sizeof(temp
) - 1);
112 printf("\tcomment: %s\n", temp
);
114 printf("\tstate: %d\n", info2
->state
);
115 printf("\tnum_stores: %d\n", info2
->num_stores
);
118 /* Display a DFS_INFO_3 structure */
120 static void display_dfs_info_3(NETDFS_DFS_INFO3
*info3
)
125 unistr2_to_ascii(temp
, &info3
->path
, sizeof(temp
) - 1);
126 printf("path: %s\n", temp
);
128 unistr2_to_ascii(temp
, &info3
->comment
, sizeof(temp
) - 1);
129 printf("\tcomment: %s\n", temp
);
131 printf("\tstate: %d\n", info3
->state
);
132 printf("\tnum_stores: %d\n", info3
->num_stores
);
134 for (i
= 0; i
< info3
->num_stores
; i
++) {
135 NETDFS_DFS_STORAGEINFO
*dsi
= &info3
->stores
[i
];
137 unistr2_to_ascii(temp
, &dsi
->server
, sizeof(temp
) - 1);
138 printf("\t\tstorage[%d] server: %s\n", i
, temp
);
140 unistr2_to_ascii(temp
, &dsi
->share
, sizeof(temp
) - 1);
141 printf("\t\tstorage[%d] share: %s\n", i
, temp
);
146 /* Display a DFS_INFO_CTR structure */
147 static void display_dfs_info(NETDFS_DFS_INFO_CTR
*ctr
)
149 switch (ctr
->switch_value
) {
151 display_dfs_info_1(&ctr
->u
.info1
);
154 display_dfs_info_2(&ctr
->u
.info2
);
157 display_dfs_info_3(&ctr
->u
.info3
);
160 printf("unsupported info level %d\n",
166 static void display_dfs_enumstruct(NETDFS_DFS_ENUMSTRUCT
*ctr
)
170 /* count is always the first element, so we can just use info1 here */
171 for (i
= 0; i
< ctr
->e
.u
.info1
.count
; i
++) {
172 switch (ctr
->level
) {
173 case 1: display_dfs_info_1(&ctr
->e
.u
.info1
.s
[i
]); break;
174 case 2: display_dfs_info_2(&ctr
->e
.u
.info2
.s
[i
]); break;
175 case 3: display_dfs_info_3(&ctr
->e
.u
.info3
.s
[i
]); break;
177 printf("unsupported info level %d\n",
184 /* Enumerate dfs shares */
186 static NTSTATUS
cmd_dfs_enum(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
187 int argc
, const char **argv
)
189 NETDFS_DFS_ENUMSTRUCT str
;
190 NETDFS_DFS_ENUMINFO_CTR ctr
;
192 uint32 info_level
= 1;
196 printf("Usage: %s [info_level]\n", argv
[0]);
201 info_level
= atoi(argv
[1]);
204 init_netdfs_dfs_EnumStruct(&str
, info_level
, ctr
);
207 result
= rpccli_dfs_Enum(cli
, mem_ctx
, info_level
, 0xFFFFFFFF, &str
, &total
);
209 if (NT_STATUS_IS_OK(result
))
210 display_dfs_enumstruct(&str
);
215 static NTSTATUS
cmd_dfs_getinfo(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
216 int argc
, const char **argv
)
219 const char *path
, *servername
, *sharename
;
220 uint32 info_level
= 1;
221 NETDFS_DFS_INFO_CTR ctr
;
223 if (argc
< 4 || argc
> 5) {
224 printf("Usage: %s path servername sharename "
225 "[info_level]\n", argv
[0]);
230 servername
= argv
[2];
234 info_level
= atoi(argv
[4]);
236 result
= rpccli_dfs_GetInfo(cli
, mem_ctx
, path
, servername
,
237 sharename
, info_level
, &ctr
);
239 if (NT_STATUS_IS_OK(result
))
240 display_dfs_info(&ctr
);
245 /* List of commands exported by this module */
247 struct cmd_set dfs_commands
[] = {
251 { "dfsexist", RPC_RTYPE_NTSTATUS
, cmd_dfs_exist
, NULL
, PI_NETDFS
, NULL
, "Query DFS support", "" },
252 { "dfsadd", RPC_RTYPE_NTSTATUS
, cmd_dfs_add
, NULL
, PI_NETDFS
, NULL
, "Add a DFS share", "" },
253 { "dfsremove", RPC_RTYPE_NTSTATUS
, cmd_dfs_remove
, NULL
, PI_NETDFS
, NULL
, "Remove a DFS share", "" },
254 { "dfsgetinfo",RPC_RTYPE_NTSTATUS
, cmd_dfs_getinfo
, NULL
, PI_NETDFS
, NULL
, "Query DFS share info", "" },
255 { "dfsenum", RPC_RTYPE_NTSTATUS
, cmd_dfs_enum
, NULL
, PI_NETDFS
, NULL
, "Enumerate dfs shares", "" },