r15098: Make smbclient -L use RPC to list shares, fall back to RAP. This should list
authorVolker Lendecke <vlendec@samba.org>
Sun, 16 Apr 2006 11:47:26 +0000 (11:47 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:16:23 +0000 (11:16 -0500)
long share names.

Volker

source/Makefile.in
source/client/client.c

index 1b2fc922279f09486613875e06e242383cd9f58b..27753dd072123e016e719a73cbb2fd5a74045930 100644 (file)
@@ -555,7 +555,9 @@ LIBBIGBALLOFMUD_OBJ = $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ) \
 
 LIBBIGBALLOFMUD_PICOBJS = $(LIBBIGBALLOFMUD_OBJ:.o=.@PICSUFFIX@)
 
-CLIENT_OBJ1 = client/client.o client/clitar.o 
+CLIENT_OBJ1 = client/client.o client/clitar.o rpc_client/cli_srvsvc.o \
+       rpc_parse/parse_srv.o rpc_client/cli_pipe.o rpc_parse/parse_rpc.o \
+       rpc_client/cli_netlogon.o rpc_parse/parse_net.o
 
 CLIENT_OBJ = $(CLIENT_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \
             $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) \
index 886af863e470a66ff0da2870acd45ee25e9ea94a..1fbee70645c9ecb1f34af586f5f1ac4f06b09d57 100644 (file)
@@ -2510,7 +2510,7 @@ static void browse_fn(const char *name, uint32 m,
 
         *typestr=0;
 
-        switch (m)
+        switch (m & 7)
         {
           case STYPE_DISKTREE:
             fstrcpy(typestr,"Disk"); break;
@@ -2532,6 +2532,57 @@ static void browse_fn(const char *name, uint32 m,
        }
 }
 
+static BOOL browse_host_rpc(BOOL sort)
+{
+       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);
+               browse_fn(name, info->info_1.type, comment, NULL);
+       }
+
+       TALLOC_FREE(mem_ctx);
+       cli_rpc_pipe_close(pipe_hnd);
+       return True;
+}
+
 /****************************************************************************
  Try and browse available connections on a host.
 ****************************************************************************/
@@ -2544,6 +2595,10 @@ static BOOL browse_host(BOOL sort)
                d_printf("\t---------       ----      -------\n");
        }
 
+       if (browse_host_rpc(sort)) {
+               return True;
+       }
+
        if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
                d_printf("Error returning browse list: %s\n", cli_errstr(cli));