rpcclient/cmd_dfs.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    RPC pipe client
00004 
00005    Copyright (C) Tim Potter 2000
00006    Copyright (C) Jelmer Vernooij       2005.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012    
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017    
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 
00023 #include "includes.h"
00024 #include "rpcclient.h"
00025 
00026 /* Check DFS is supported by the remote server */
00027 
00028 static NTSTATUS cmd_dfs_exist(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00029                               int argc, const char **argv)
00030 {
00031         uint32 dfs_exists;
00032         NTSTATUS result;
00033 
00034         if (argc != 1) {
00035                 printf("Usage: %s\n", argv[0]);
00036                 return NT_STATUS_OK;
00037         }
00038 
00039         result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &dfs_exists);
00040 
00041         if (NT_STATUS_IS_OK(result))
00042                 printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
00043 
00044         return result;
00045 }
00046 
00047 static NTSTATUS cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00048                             int argc, const char **argv)
00049 {
00050         NTSTATUS result;
00051         const char *path, *servername, *sharename, *comment;
00052         uint32 flags = 0;
00053 
00054         if (argc != 5) {
00055                 printf("Usage: %s path servername sharename comment\n", 
00056                        argv[0]);
00057                 return NT_STATUS_OK;
00058         }
00059 
00060         path = argv[1];
00061         servername = argv[2];
00062         sharename = argv[3];
00063         comment = argv[4];
00064 
00065         result = rpccli_dfs_Add(cli, mem_ctx, path, servername, 
00066                              sharename, comment, flags);
00067 
00068         return result;
00069 }
00070 
00071 static NTSTATUS cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00072                                int argc, const char **argv)
00073 {
00074         NTSTATUS result;
00075         const char *path, *servername, *sharename;
00076 
00077         if (argc != 4) {
00078                 printf("Usage: %s path servername sharename\n", argv[0]);
00079                 return NT_STATUS_OK;
00080         }
00081 
00082         path = argv[1];
00083         servername = argv[2];
00084         sharename = argv[3];
00085 
00086         result = rpccli_dfs_Remove(cli, mem_ctx, path, servername, 
00087                                 sharename);
00088 
00089         return result;
00090 }
00091 
00092 /* Display a DFS_INFO_1 structure */
00093 
00094 static void display_dfs_info_1(NETDFS_DFS_INFO1 *info1)
00095 {
00096         fstring temp;
00097 
00098         unistr2_to_ascii(temp, &info1->path, sizeof(temp) - 1);
00099         printf("path: %s\n", temp);
00100 }
00101 
00102 /* Display a DFS_INFO_2 structure */
00103 
00104 static void display_dfs_info_2(NETDFS_DFS_INFO2 *info2)
00105 {
00106         fstring temp;
00107 
00108         unistr2_to_ascii(temp, &info2->path, sizeof(temp) - 1);
00109         printf("path: %s\n", temp);
00110 
00111         unistr2_to_ascii(temp, &info2->comment, sizeof(temp) - 1);
00112         printf("\tcomment: %s\n", temp);
00113 
00114         printf("\tstate: %d\n", info2->state);
00115         printf("\tnum_stores: %d\n", info2->num_stores);
00116 }
00117 
00118 /* Display a DFS_INFO_3 structure */
00119 
00120 static void display_dfs_info_3(NETDFS_DFS_INFO3 *info3)
00121 {
00122         fstring temp;
00123         int i;
00124 
00125         unistr2_to_ascii(temp, &info3->path, sizeof(temp) - 1);
00126         printf("path: %s\n", temp);
00127 
00128         unistr2_to_ascii(temp, &info3->comment, sizeof(temp) - 1);
00129         printf("\tcomment: %s\n", temp);
00130 
00131         printf("\tstate: %d\n", info3->state);
00132         printf("\tnum_stores: %d\n", info3->num_stores);
00133 
00134         for (i = 0; i < info3->num_stores; i++) {
00135                 NETDFS_DFS_STORAGEINFO *dsi = &info3->stores[i];
00136 
00137                 unistr2_to_ascii(temp, &dsi->server, sizeof(temp) - 1);
00138                 printf("\t\tstorage[%d] server: %s\n", i, temp);
00139 
00140                 unistr2_to_ascii(temp, &dsi->share, sizeof(temp) - 1);
00141                 printf("\t\tstorage[%d] share: %s\n", i, temp);
00142         }
00143 }
00144 
00145 
00146 /* Display a DFS_INFO_CTR structure */
00147 static void display_dfs_info(NETDFS_DFS_INFO_CTR *ctr)
00148 {
00149         switch (ctr->switch_value) {
00150                 case 0x01:
00151                         display_dfs_info_1(&ctr->u.info1);
00152                         break;
00153                 case 0x02:
00154                         display_dfs_info_2(&ctr->u.info2);
00155                         break;
00156                 case 0x03:
00157                         display_dfs_info_3(&ctr->u.info3);
00158                         break;
00159                 default:
00160                         printf("unsupported info level %d\n", 
00161                                ctr->switch_value);
00162                         break;
00163         }
00164 }
00165 
00166 static void display_dfs_enumstruct(NETDFS_DFS_ENUMSTRUCT *ctr)
00167 {
00168         int i;
00169         
00170         /* count is always the first element, so we can just use info1 here */
00171         for (i = 0; i < ctr->e.u.info1.count; i++) {
00172                 switch (ctr->level) {
00173                 case 1: display_dfs_info_1(&ctr->e.u.info1.s[i]); break;
00174                 case 2: display_dfs_info_2(&ctr->e.u.info2.s[i]); break;
00175                 case 3: display_dfs_info_3(&ctr->e.u.info3.s[i]); break;
00176                 default:
00177                                 printf("unsupported info level %d\n", 
00178                                ctr->level);
00179                                 return;
00180                 }
00181         }
00182 }
00183 
00184 /* Enumerate dfs shares */
00185 
00186 static NTSTATUS cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00187                              int argc, const char **argv)
00188 {
00189         NETDFS_DFS_ENUMSTRUCT str;
00190         NETDFS_DFS_ENUMINFO_CTR ctr;
00191         NTSTATUS result;
00192         uint32 info_level = 1;
00193         uint32 total = 0;
00194 
00195         if (argc > 2) {
00196                 printf("Usage: %s [info_level]\n", argv[0]);
00197                 return NT_STATUS_OK;
00198         }
00199 
00200         if (argc == 2)
00201                 info_level = atoi(argv[1]);
00202 
00203         ZERO_STRUCT(ctr);
00204         init_netdfs_dfs_EnumStruct(&str, info_level, ctr);
00205         str.e.ptr0 = 1;
00206 
00207         result = rpccli_dfs_Enum(cli, mem_ctx, info_level, 0xFFFFFFFF, &str, &total);
00208 
00209         if (NT_STATUS_IS_OK(result))
00210                 display_dfs_enumstruct(&str);
00211 
00212         return result;
00213 }
00214 
00215 static NTSTATUS cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
00216                                 int argc, const char **argv)
00217 {
00218         NTSTATUS result;
00219         const char *path, *servername, *sharename;
00220         uint32 info_level = 1;
00221         NETDFS_DFS_INFO_CTR ctr;
00222 
00223         if (argc < 4 || argc > 5) {
00224                 printf("Usage: %s path servername sharename "
00225                        "[info_level]\n", argv[0]);
00226                 return NT_STATUS_OK;
00227         }
00228 
00229         path = argv[1];
00230         servername = argv[2];
00231         sharename = argv[3];
00232 
00233         if (argc == 5)
00234                 info_level = atoi(argv[4]);
00235 
00236         result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername, 
00237                                   sharename, info_level, &ctr);
00238 
00239         if (NT_STATUS_IS_OK(result))
00240                 display_dfs_info(&ctr);
00241 
00242         return result;
00243 }
00244 
00245 /* List of commands exported by this module */
00246 
00247 struct cmd_set dfs_commands[] = {
00248 
00249         { "DFS" },
00250 
00251         { "dfsexist",  RPC_RTYPE_NTSTATUS, cmd_dfs_exist,   NULL, PI_NETDFS, NULL, "Query DFS support",    "" },
00252         { "dfsadd",    RPC_RTYPE_NTSTATUS, cmd_dfs_add,     NULL, PI_NETDFS, NULL, "Add a DFS share",      "" },
00253         { "dfsremove", RPC_RTYPE_NTSTATUS, cmd_dfs_remove,  NULL, PI_NETDFS, NULL, "Remove a DFS share",   "" },
00254         { "dfsgetinfo",RPC_RTYPE_NTSTATUS, cmd_dfs_getinfo, NULL, PI_NETDFS, NULL, "Query DFS share info", "" },
00255         { "dfsenum",   RPC_RTYPE_NTSTATUS, cmd_dfs_enum,    NULL, PI_NETDFS, NULL, "Enumerate dfs shares", "" },
00256 
00257         { NULL }
00258 };

Sambaに対してSat Aug 29 21:23:22 2009に生成されました。  doxygen 1.4.7