r560: Fix bugzilla 1279: cannot control individual print jobs using cups
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_dfs.c
blob44e97f9881e7bba20d4b6ed5cd2aca5422b6b52f
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
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.
22 #include "includes.h"
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, const char **argv)
30 BOOL dfs_exists;
31 NTSTATUS result;
33 if (argc != 1) {
34 printf("Usage: %s\n", argv[0]);
35 return NT_STATUS_OK;
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 ");
43 return result;
46 static NTSTATUS cmd_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
47 int argc, const char **argv)
49 NTSTATUS result;
50 const char *entrypath, *servername, *sharename, *comment;
51 uint32 flags = 0;
53 if (argc != 5) {
54 printf("Usage: %s entrypath servername sharename comment\n",
55 argv[0]);
56 return NT_STATUS_OK;
59 entrypath = argv[1];
60 servername = argv[2];
61 sharename = argv[3];
62 comment = argv[4];
64 result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
65 sharename, comment, flags);
67 return result;
70 static NTSTATUS cmd_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
71 int argc, const char **argv)
73 NTSTATUS result;
74 const char *entrypath, *servername, *sharename;
76 if (argc != 4) {
77 printf("Usage: %s entrypath servername sharename\n", argv[0]);
78 return NT_STATUS_OK;
81 entrypath = argv[1];
82 servername = argv[2];
83 sharename = argv[3];
85 result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
86 sharename);
88 return result;
91 /* Display a DFS_INFO_1 structure */
93 static void display_dfs_info_1(DFS_INFO_1 *info1)
95 fstring temp;
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)
105 fstring temp;
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)
121 fstring temp;
122 int i;
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)
148 int i;
150 for (i = 0; i < ctr->num_entries; i++) {
151 switch (ctr->switch_value) {
152 case 0x01:
153 display_dfs_info_1(&ctr->dfs.info1[i]);
154 break;
155 case 0x02:
156 display_dfs_info_2(&ctr->dfs.info2[i]);
157 break;
158 case 0x03:
159 display_dfs_info_3(&ctr->dfs.info3[i]);
160 break;
161 default:
162 printf("unsupported info level %d\n",
163 ctr->switch_value);
164 break;
169 /* Enumerate dfs shares */
171 static NTSTATUS cmd_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
172 int argc, const char **argv)
174 DFS_INFO_CTR ctr;
175 NTSTATUS result;
176 uint32 info_level = 1;
178 if (argc > 2) {
179 printf("Usage: %s [info_level]\n", argv[0]);
180 return NT_STATUS_OK;
183 if (argc == 2)
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);
191 return result;
194 static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
195 int argc, const char **argv)
197 NTSTATUS result;
198 const char *entrypath, *servername, *sharename;
199 uint32 info_level = 1;
200 DFS_INFO_CTR ctr;
202 if (argc < 4 || argc > 5) {
203 printf("Usage: %s entrypath servername sharename "
204 "[info_level]\n", argv[0]);
205 return NT_STATUS_OK;
208 entrypath = argv[1];
209 servername = argv[2];
210 sharename = argv[3];
212 if (argc == 5)
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);
221 return result;
224 /* List of commands exported by this module */
226 struct cmd_set dfs_commands[] = {
228 { "DFS" },
230 { "dfsexist", RPC_RTYPE_NTSTATUS, cmd_dfs_exist, NULL, PI_NETDFS, "Query DFS support", "" },
231 { "dfsadd", RPC_RTYPE_NTSTATUS, cmd_dfs_add, NULL, PI_NETDFS, "Add a DFS share", "" },
232 { "dfsremove", RPC_RTYPE_NTSTATUS, cmd_dfs_remove, NULL, PI_NETDFS, "Remove a DFS share", "" },
233 { "dfsgetinfo",RPC_RTYPE_NTSTATUS, cmd_dfs_getinfo, NULL, PI_NETDFS, "Query DFS share info", "" },
234 { "dfsenum", RPC_RTYPE_NTSTATUS, cmd_dfs_enum, NULL, PI_NETDFS, "Enumerate dfs shares", "" },
236 { NULL }