r23779: Change from v2 or later to v3 or later.
[ira/wip.git] / source3 / utils / smbtree.c
index bc669b4aa165dfccceb85eb8933c2905dbdd3db1..5deb29a149b3a03b5b3f66feea464e9376d03695 100644 (file)
@@ -7,7 +7,7 @@
    
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -22,8 +22,6 @@
 
 #include "includes.h"
 
-#include "module_dummy.h"
-
 static BOOL use_bcast;
 
 /* How low can we go? */
@@ -53,7 +51,7 @@ static void add_name(const char *machine_name, uint32 server_type,
         struct name_list **name_list = (struct name_list **)state;
         struct name_list *new_name;
 
-        new_name = (struct name_list *)malloc(sizeof(struct name_list));
+        new_name = SMB_MALLOC_P(struct name_list);
 
         if (!new_name)
                 return;
@@ -129,6 +127,62 @@ static BOOL get_servers(char *workgroup, struct user_auth_info *user_info)
         return True;
 }
 
+static BOOL get_rpc_shares(struct cli_state *cli, 
+                          void (*fn)(const char *, uint32, const char *, void *),
+                          void *state)
+{
+       NTSTATUS status;
+       struct rpc_pipe_client *pipe_hnd;
+       TALLOC_CTX *mem_ctx;
+       uint32 enum_hnd;
+       struct srvsvc_NetShareCtr1 ctr1;
+       union srvsvc_NetShareCtr ctr;
+       uint32 numentries;
+       int i;
+       uint32 info_level = 1;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               DEBUG(0, ("talloc_new failed\n"));
+               return False;
+       }
+
+       enum_hnd = 0;
+       pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
+
+       if (pipe_hnd == NULL) {
+               DEBUG(10, ("Could not connect to srvsvc pipe: %s\n",
+                          nt_errstr(status)));
+               TALLOC_FREE(mem_ctx);
+               return False;
+       }
+
+       ZERO_STRUCT(ctr1);
+       level = 1;
+       ctr.ctr1 = &ctr1;
+
+       status = rpccli_srvsvc_NetShareEnum(pipe_hnd, mem_ctx, NULL,
+                                           &info_level, &ctr,
+                                           0xffffffff, &numentries,
+                                           &enum_hnd);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(mem_ctx);
+               cli_rpc_pipe_close(pipe_hnd);
+               return False;
+       }
+
+       for (i=0; i<numentries; i++) {
+               fn(ctr.ctr1->array[i].name, ctr.ctr1->array[i].type, 
+                  ctr.ctr1->array[i].comment, state);
+       }
+
+       TALLOC_FREE(mem_ctx);
+       cli_rpc_pipe_close(pipe_hnd);
+       return True;
+}
+
+
 static BOOL get_shares(char *server_name, struct user_auth_info *user_info)
 {
         struct cli_state *cli;
@@ -136,6 +190,9 @@ static BOOL get_shares(char *server_name, struct user_auth_info *user_info)
         if (!(cli = get_ipc_connect(server_name, NULL, user_info)))
                 return False;
 
+       if (get_rpc_shares(cli, add_name, &shares))
+               return True;
+       
         if (!cli_RNetShareEnum(cli, add_name, &shares))
                 return False;
 
@@ -205,6 +262,7 @@ static BOOL print_tree(struct user_auth_info *user_info)
        poptContext pc;
        
        /* Initialise samba stuff */
+       load_case_tables();
 
        setlinebuf(stdout);
 
@@ -217,7 +275,7 @@ static BOOL print_tree(struct user_auth_info *user_info)
        while(poptGetNextOpt(pc) != -1);
        poptFreeContext(pc);
 
-       lp_load(dyn_CONFIGFILE,True,False,False);
+       lp_load(dyn_CONFIGFILE,True,False,False,True);
        load_interfaces();
 
        /* Parse command line args */