1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/*
Unix SMB/Netbios implementation.
Version 2.2
RPC pipe client
Copyright (C) Tim Potter 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
extern pstring server;
/* Check DFS is supported by the remote server */
static NTSTATUS cmd_dfs_exist(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
BOOL dfs_exists;
NTSTATUS result;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_exist: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
if (NT_STATUS_IS_OK(result))
printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
cli_nt_session_close(cli);
done:
talloc_destroy(mem_ctx);
return result;
}
static NTSTATUS cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename, *comment;
uint32 flags = 0;
if (argc != 5) {
printf("Usage: %s entrypath servername sharename comment\n",
argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
comment = argv[4];
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
sharename, comment, flags);
cli_nt_session_close(cli);
done:
talloc_destroy(mem_ctx);
return result;
}
static NTSTATUS cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename;
if (argc != 4) {
printf("Usage: %s entrypath servername sharename\n", argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
sharename);
cli_nt_session_close(cli);
done:
talloc_destroy(mem_ctx);
return result;
}
/* Display a DFS_INFO_1 structure */
static void display_dfs_info_1(DFS_INFO_1 *info1)
{
fstring temp;
unistr2_to_ascii(temp, &info1->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
}
/* Display a DFS_INFO_2 structure */
static void display_dfs_info_2(DFS_INFO_2 *info2)
{
fstring temp;
unistr2_to_ascii(temp, &info2->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info2->state);
printf("\tnum_storages: %d\n", info2->num_storages);
}
/* Display a DFS_INFO_3 structure */
static void display_dfs_info_3(DFS_INFO_3 *info3)
{
fstring temp;
int i;
unistr2_to_ascii(temp, &info3->entrypath, sizeof(temp) - 1);
printf("entrypath: %s\n", temp);
unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
printf("\tcomment: %s\n", temp);
printf("\tstate: %d\n", info3->state);
printf("\tnum_storages: %d\n", info3->num_storages);
for (i = 0; i < info3->num_storages; i++) {
DFS_STORAGE_INFO *dsi = &info3->storages[i];
unistr2_to_ascii(temp, &dsi->servername, sizeof(temp) - 1);
printf("\t\tstorage[%d] servername: %s\n", i, temp);
unistr2_to_ascii(temp, &dsi->sharename, sizeof(temp) - 1);
printf("\t\tstorage[%d] sharename: %s\n", i, temp);
}
}
/* Display a DFS_INFO_CTR structure */
static void display_dfs_info_ctr(DFS_INFO_CTR *ctr)
{
int i;
for (i = 0; i < ctr->num_entries; i++) {
switch (ctr->switch_value) {
case 0x01:
display_dfs_info_1(&ctr->dfs.info1[i]);
break;
case 0x02:
display_dfs_info_2(&ctr->dfs.info2[i]);
break;
case 0x03:
display_dfs_info_3(&ctr->dfs.info3[i]);
break;
default:
printf("unsupported info level %d\n",
ctr->switch_value);
break;
}
}
}
/* Enumerate dfs shares */
static NTSTATUS cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
DFS_INFO_CTR ctr;
NTSTATUS result;
uint32 info_level = 1;
if (argc > 2) {
printf("Usage: %s [info_level]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_enum: talloc_init failed\n"));
return NT_STATUS_NO_MEMORY;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
/* Call RPC function */
result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr);
if (NT_STATUS_IS_OK(result)) {
/* Print results */
display_dfs_info_ctr(&ctr);
}
cli_nt_session_close(cli);
done:
talloc_destroy(mem_ctx);
return result;
}
static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
{
TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename;
uint32 info_level = 1;
DFS_INFO_CTR ctr;
if (argc < 4 || argc > 5) {
printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
return NT_STATUS_OK;
}
entrypath = argv[1];
servername = argv[2];
sharename = argv[3];
if (argc == 5)
info_level = atoi(argv[4]);
if (!(mem_ctx = talloc_init())) {
DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
return NT_STATUS_UNSUCCESSFUL;
}
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
DEBUG(0, ("Could not initialize netdfs pipe!\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
/* Call RPC function */
result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
sharename, info_level, &ctr);
if (NT_STATUS_IS_OK(result)) {
/* Print results */
display_dfs_info_ctr(&ctr);
}
cli_nt_session_close(cli);
done:
talloc_destroy(mem_ctx);
return result;
}
/* List of commands exported by this module */
struct cmd_set dfs_commands[] = {
{ "DFS" },
{ "dfsexist", cmd_dfs_exist, "Query DFS support", "" },
{ "dfsadd", cmd_dfs_add, "Add a DFS share", "" },
{ "dfsremove", cmd_dfs_remove, "Remove a DFS share", "" },
{ "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info", "" },
{ "dfsenum", cmd_dfs_enum, "Enumerate dfs shares", "" },
{ NULL }
};
|