[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / utils / smbtree.c
index cbe1bd448f8b9ed2bb240590025d83a339b578df..7d62d65b05695e926242b8b9f36ca7536954cbc1 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,
@@ -16,8 +16,7 @@
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -51,7 +50,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;
@@ -127,6 +126,60 @@ 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;
+       ENUM_HND enum_hnd;
+       WERROR werr;
+       SRV_SHARE_INFO_CTR ctr;
+       int i;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               DEBUG(0, ("talloc_new failed\n"));
+               return False;
+       }
+
+       init_enum_hnd(&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;
+       }
+
+       werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr,
+                                           0xffffffff, &enum_hnd);
+
+       if (!W_ERROR_IS_OK(werr)) {
+               TALLOC_FREE(mem_ctx);
+               cli_rpc_pipe_close(pipe_hnd);
+               return False;
+       }
+
+       for (i=0; i<ctr.num_entries; i++) {
+               SRV_SHARE_INFO_1 *info = &ctr.share.info1[i];
+               char *name, *comment;
+               name = rpcstr_pull_unistr2_talloc(
+                       mem_ctx, &info->info_1_str.uni_netname);
+               comment = rpcstr_pull_unistr2_talloc(
+                       mem_ctx, &info->info_1_str.uni_remark);
+               fn(name, info->info_1.type, 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;
@@ -134,6 +187,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;
 
@@ -191,6 +247,7 @@ static BOOL print_tree(struct user_auth_info *user_info)
 ****************************************************************************/
  int main(int argc,char *argv[])
 {
+       TALLOC_CTX *frame = talloc_stackframe();
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" },
@@ -203,6 +260,7 @@ static BOOL print_tree(struct user_auth_info *user_info)
        poptContext pc;
        
        /* Initialise samba stuff */
+       load_case_tables();
 
        setlinebuf(stdout);
 
@@ -215,7 +273,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 */
@@ -230,8 +288,11 @@ static BOOL print_tree(struct user_auth_info *user_info)
 
        /* Now do our stuff */
 
-        if (!print_tree(&cmdline_auth_info))
+        if (!print_tree(&cmdline_auth_info)) {
+               TALLOC_FREE(frame);
                 return 1;
+       }
 
+       TALLOC_FREE(frame);
        return 0;
 }