root/source3/rpcclient/cmd_dfs.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cmd_dfs_version
  2. cmd_dfs_add
  3. cmd_dfs_remove
  4. display_dfs_info_1
  5. display_dfs_info_2
  6. display_dfs_info_3
  7. display_dfs_info
  8. display_dfs_enumstruct
  9. cmd_dfs_enum
  10. cmd_dfs_enumex
  11. cmd_dfs_getinfo

   1 /* 
   2    Unix SMB/CIFS implementation.
   3    RPC pipe client
   4 
   5    Copyright (C) Tim Potter 2000
   6    Copyright (C) Jelmer Vernooij       2005.
   7 
   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 3 of the License, or
  11    (at your option) any later version.
  12    
  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.
  17    
  18    You should have received a copy of the GNU General Public License
  19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20 */
  21 
  22 #include "includes.h"
  23 #include "rpcclient.h"
  24 
  25 /* Check DFS is supported by the remote server */
  26 
  27 static WERROR cmd_dfs_version(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  28                               int argc, const char **argv)
  29 {
  30         enum dfs_ManagerVersion version;
  31         NTSTATUS result;
  32 
  33         if (argc != 1) {
  34                 printf("Usage: %s\n", argv[0]);
  35                 return WERR_OK;
  36         }
  37 
  38         result = rpccli_dfs_GetManagerVersion(cli, mem_ctx, &version);
  39 
  40         if (!NT_STATUS_IS_OK(result)) {
  41                 return ntstatus_to_werror(result);
  42         }
  43 
  44         if (version > 0) {
  45                 printf("dfs is present (%d)\n", version);
  46         } else {
  47                 printf("dfs is not present\n");
  48         }
  49 
  50         return WERR_OK;
  51 }
  52 
  53 static WERROR cmd_dfs_add(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  54                           int argc, const char **argv)
  55 {
  56         NTSTATUS result;
  57         WERROR werr;
  58         const char *path, *servername, *sharename, *comment;
  59         uint32 flags = 0;
  60 
  61         if (argc != 5) {
  62                 printf("Usage: %s path servername sharename comment\n", 
  63                        argv[0]);
  64                 return WERR_OK;
  65         }
  66 
  67         path = argv[1];
  68         servername = argv[2];
  69         sharename = argv[3];
  70         comment = argv[4];
  71 
  72         result = rpccli_dfs_Add(cli, mem_ctx, path, servername,
  73                                 sharename, comment, flags, &werr);
  74         if (!NT_STATUS_IS_OK(result)) {
  75                 return ntstatus_to_werror(result);
  76         }
  77 
  78         return werr;
  79 }
  80 
  81 static WERROR cmd_dfs_remove(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  82                              int argc, const char **argv)
  83 {
  84         NTSTATUS result;
  85         WERROR werr;
  86         const char *path, *servername, *sharename;
  87 
  88         if (argc != 4) {
  89                 printf("Usage: %s path servername sharename\n", argv[0]);
  90                 return WERR_OK;
  91         }
  92 
  93         path = argv[1];
  94         servername = argv[2];
  95         sharename = argv[3];
  96 
  97         result = rpccli_dfs_Remove(cli, mem_ctx, path, servername,
  98                                    sharename, &werr);
  99         if (!NT_STATUS_IS_OK(result)) {
 100                 return ntstatus_to_werror(result);
 101         }
 102 
 103         return werr;
 104 }
 105 
 106 /* Display a DFS_INFO_1 structure */
 107 
 108 static void display_dfs_info_1(struct dfs_Info1 *info1)
     /* [<][>][^][v][top][bottom][index][help] */
 109 {
 110         printf("path: %s\n", info1->path);
 111 }
 112 
 113 /* Display a DFS_INFO_2 structure */
 114 
 115 static void display_dfs_info_2(struct dfs_Info2 *info2)
     /* [<][>][^][v][top][bottom][index][help] */
 116 {
 117         printf("path: %s\n", info2->path);
 118         printf("\tcomment: %s\n", info2->comment);
 119 
 120         printf("\tstate: %d\n", info2->state);
 121         printf("\tnum_stores: %d\n", info2->num_stores);
 122 }
 123 
 124 /* Display a DFS_INFO_3 structure */
 125 
 126 static void display_dfs_info_3(struct dfs_Info3 *info3)
     /* [<][>][^][v][top][bottom][index][help] */
 127 {
 128         int i;
 129 
 130         printf("path: %s\n", info3->path);
 131 
 132         printf("\tcomment: %s\n", info3->comment);
 133 
 134         printf("\tstate: %d\n", info3->state);
 135         printf("\tnum_stores: %d\n", info3->num_stores);
 136 
 137         for (i = 0; i < info3->num_stores; i++) {
 138                 struct dfs_StorageInfo *dsi = &info3->stores[i];
 139 
 140                 printf("\t\tstorage[%d] server: %s\n", i, dsi->server);
 141 
 142                 printf("\t\tstorage[%d] share: %s\n", i, dsi->share);
 143         }
 144 }
 145 
 146 
 147 /* Display a DFS_INFO_CTR structure */
 148 static void display_dfs_info(uint32 level, union dfs_Info *ctr)
     /* [<][>][^][v][top][bottom][index][help] */
 149 {
 150         switch (level) {
 151                 case 0x01:
 152                         display_dfs_info_1(ctr->info1);
 153                         break;
 154                 case 0x02:
 155                         display_dfs_info_2(ctr->info2);
 156                         break;
 157                 case 0x03:
 158                         display_dfs_info_3(ctr->info3);
 159                         break;
 160                 default:
 161                         printf("unsupported info level %d\n", 
 162                                level);
 163                         break;
 164         }
 165 }
 166 
 167 static void display_dfs_enumstruct(struct dfs_EnumStruct *ctr)
     /* [<][>][^][v][top][bottom][index][help] */
 168 {
 169         int i;
 170         
 171         /* count is always the first element, so we can just use info1 here */
 172         for (i = 0; i < ctr->e.info1->count; i++) {
 173                 switch (ctr->level) {
 174                 case 1: display_dfs_info_1(&ctr->e.info1->s[i]); break;
 175                 case 2: display_dfs_info_2(&ctr->e.info2->s[i]); break;
 176                 case 3: display_dfs_info_3(&ctr->e.info3->s[i]); break;
 177                 default:
 178                                 printf("unsupported info level %d\n", 
 179                                ctr->level);
 180                                 return;
 181                 }
 182         }
 183 }
 184 
 185 /* Enumerate dfs shares */
 186 
 187 static WERROR cmd_dfs_enum(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 188                            int argc, const char **argv)
 189 {
 190         struct dfs_EnumStruct str;
 191         struct dfs_EnumArray1 info1;
 192         struct dfs_EnumArray2 info2;
 193         struct dfs_EnumArray3 info3;
 194         struct dfs_EnumArray4 info4;
 195         struct dfs_EnumArray200 info200;
 196         struct dfs_EnumArray300 info300;
 197 
 198         NTSTATUS result;
 199         WERROR werr;
 200         uint32 total = 0;
 201 
 202         if (argc > 2) {
 203                 printf("Usage: %s [info_level]\n", argv[0]);
 204                 return WERR_OK;
 205         }
 206 
 207         str.level = 1;
 208         if (argc == 2)
 209                 str.level = atoi(argv[1]);
 210 
 211         switch (str.level) {
 212         case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
 213         case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
 214         case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
 215         case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
 216         case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
 217         case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
 218         default:
 219                           printf("Unknown info level %d\n", str.level);
 220                           break;
 221         }
 222 
 223         result = rpccli_dfs_Enum(cli, mem_ctx, str.level, 0xFFFFFFFF, &str,
 224                                  &total, &werr);
 225 
 226         if (NT_STATUS_IS_OK(result)) {
 227                 display_dfs_enumstruct(&str);
 228         }
 229 
 230         return werr;
 231 }
 232 
 233 /* Enumerate dfs shares */
 234 
 235 static WERROR cmd_dfs_enumex(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 236                              int argc, const char **argv)
 237 {
 238         struct dfs_EnumStruct str;
 239         struct dfs_EnumArray1 info1;
 240         struct dfs_EnumArray2 info2;
 241         struct dfs_EnumArray3 info3;
 242         struct dfs_EnumArray4 info4;
 243         struct dfs_EnumArray200 info200;
 244         struct dfs_EnumArray300 info300;
 245 
 246         NTSTATUS result;
 247         WERROR werr;
 248         uint32 total = 0;
 249 
 250         if (argc < 2 || argc > 3) {
 251                 printf("Usage: %s dfs_name [info_level]\n", argv[0]);
 252                 return WERR_OK;
 253         }
 254 
 255         str.level = 1;
 256 
 257         if (argc == 3)
 258                 str.level = atoi(argv[2]);
 259 
 260         switch (str.level) {
 261         case 1: str.e.info1 = &info1; ZERO_STRUCT(info1); break;
 262         case 2: str.e.info2 = &info2; ZERO_STRUCT(info2); break;
 263         case 3: str.e.info3 = &info3; ZERO_STRUCT(info3); break;
 264         case 4: str.e.info4 = &info4; ZERO_STRUCT(info4); break;
 265         case 200: str.e.info200 = &info200; ZERO_STRUCT(info200); break;
 266         case 300: str.e.info300 = &info300; ZERO_STRUCT(info300); break;
 267         default:
 268                   printf("Unknown info level %d\n", str.level);
 269                   break;
 270         }
 271 
 272         result = rpccli_dfs_EnumEx(cli, mem_ctx, argv[1], str.level,
 273                                    0xFFFFFFFF, &str, &total, &werr);
 274 
 275         if (NT_STATUS_IS_OK(result)) {
 276                 display_dfs_enumstruct(&str);
 277         }
 278 
 279         return werr;
 280 }
 281 
 282 
 283 static WERROR cmd_dfs_getinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 284                               int argc, const char **argv)
 285 {
 286         NTSTATUS result;
 287         WERROR werr;
 288         const char *path, *servername, *sharename;
 289         uint32 info_level = 1;
 290         union dfs_Info ctr;
 291 
 292         if (argc < 4 || argc > 5) {
 293                 printf("Usage: %s path servername sharename "
 294                        "[info_level]\n", argv[0]);
 295                 return WERR_OK;
 296         }
 297 
 298         path = argv[1];
 299         servername = argv[2];
 300         sharename = argv[3];
 301 
 302         if (argc == 5)
 303                 info_level = atoi(argv[4]);
 304 
 305         result = rpccli_dfs_GetInfo(cli, mem_ctx, path, servername,
 306                                     sharename, info_level, &ctr, &werr);
 307 
 308         if (NT_STATUS_IS_OK(result)) {
 309                 display_dfs_info(info_level, &ctr);
 310         }
 311 
 312         return werr;
 313 }
 314 
 315 /* List of commands exported by this module */
 316 
 317 struct cmd_set dfs_commands[] = {
 318 
 319         { "DFS" },
 320 
 321         { "dfsversion", RPC_RTYPE_WERROR, NULL, cmd_dfs_version, &ndr_table_netdfs.syntax_id, NULL, "Query DFS support",    "" },
 322         { "dfsadd",     RPC_RTYPE_WERROR, NULL, cmd_dfs_add,     &ndr_table_netdfs.syntax_id, NULL, "Add a DFS share",      "" },
 323         { "dfsremove",  RPC_RTYPE_WERROR, NULL, cmd_dfs_remove,  &ndr_table_netdfs.syntax_id, NULL, "Remove a DFS share",   "" },
 324         { "dfsgetinfo", RPC_RTYPE_WERROR, NULL, cmd_dfs_getinfo, &ndr_table_netdfs.syntax_id, NULL, "Query DFS share info", "" },
 325         { "dfsenum",    RPC_RTYPE_WERROR, NULL, cmd_dfs_enum,    &ndr_table_netdfs.syntax_id, NULL, "Enumerate dfs shares", "" },
 326         { "dfsenumex",  RPC_RTYPE_WERROR, NULL, cmd_dfs_enumex,  &ndr_table_netdfs.syntax_id, NULL, "Enumerate dfs shares", "" },
 327 
 328         { NULL }
 329 };

/* [<][>][^][v][top][bottom][index][help] */