Can smbclient or libsmbclient do NetrShareEnum ?

David Wuertele dave-gnus at bfnet.com
Thu Sep 9 20:59:30 GMT 2004


Rafal> Does that mean you have the function ie. what you needed ?

Well, my program works, but my data (Japanese share names) are getting
truncated.

I have written a tiny app that links with samba-3.0.6 code for the
purpose of listing the shares on a remote Japanese windows host.  My
app uses the cli_srvsvc_net_share_enum() function to do the
NetrShareEnum RPC call, then it uses rpcstr_pull_unistr2_fstring() to
extract the share names from the result.  But the share names are
getting truncated.

When I look at the response packet on the wire, the share name is
complete.  In fact, when I use "net rpc share -S myserver", I see a
list of all the share names.  My program is trying to do the exact
same thing as "net rpc share -S myserver", but the printed result does
not match exactly.  Here is the difference:

"net rpc share -S myserver"
---------------------------
# net rpc share -S myserver
Password:
IPC$
share
¿·¤·¤¤¥Õ¥©¥ë¥À(2)
ADMIN$
C$
DVD-ROM
¿·¤·¤¤¥Õ¥©¥ë¥À
# net --version

my own app
----------
# ./doit
IPC$
share
0WDU)k@ (2)
ADMIN$
C$
DVD-ROM
0WDU)k@

As you can see (if you can display Japanese fonts), my app is not only
truncating the strings, but it is also munging the character
conversion.

I used gdb to find out why the conversion was getting munged.  It
turns out that the string being returned by
cli_srvsvc_net_share_enum() is different.  In "net rpc share" the
string is the correct japanese string in UTF16, and in my own app, the
string starts with a zero.

Here is my code.  See any obvious errors?

#include "includes.h"

const char *share_type[] = {
  "Disk",
  "Print",
  "Dev",
  "IPC"
};

int
main ()
{
  struct in_addr server_ip;
  char *server_name = "myserver";
  NTSTATUS nt_status;
  struct cli_state *cli = NULL;
  TALLOC_CTX *mem_ctx;
  POLICY_HND pol;
  DOM_SID *domain_sid;
  uint32 info_class = 5;
  fstring netname = "", remark = "";
  char *domain_name;
  ENUM_HND hnd;
  SRV_SHARE_INFO_CTR ctr;
  uint32 preferred_len = 0xffffffff, i;
  WERROR result;

  load_interfaces();
  lp_set_name_resolve_order ("lmhosts wins host bcast");
  resolve_name (server_name, &server_ip, 0x20);
  nt_status = cli_full_connection (&cli, NULL, server_name, &server_ip, 0, 
                                   "IPC$", "IPC", "dave", "WORKGROUP", "", 0, Undefined, NULL);
  mem_ctx = talloc_init ("run_rpc_command");
  cli_nt_session_open (cli, PI_LSARPC);
  nt_status = cli_lsa_open_policy (cli, mem_ctx, False, SEC_RIGHTS_MAXIMUM_ALLOWED, &pol);
  nt_status = cli_lsa_query_info_policy (cli, mem_ctx, &pol, info_class, &domain_name, &domain_sid);
  cli_lsa_close (cli, mem_ctx, &pol);
  cli_nt_session_close (cli);
  cli_nt_session_open (cli, PI_SRVSVC);
  init_enum_hnd (&hnd, 0);
  result = cli_srvsvc_net_share_enum (cli, mem_ctx, 1, &ctr, preferred_len, &hnd);

  for (i = 0; i < ctr.num_entries; i++) {
	SRV_SHARE_INFO_1 *info1 = &ctr.share.info1[i];
	rpcstr_pull_unistr2_fstring (netname, &info1->info_1_str.uni_netname);
	rpcstr_pull_unistr2_fstring (remark, &info1->info_1_str.uni_remark);

	fprintf (stderr, "%-20.20s %-20.20s %-50.50s\n", netname, share_type[info1->info_1.type], remark);
  }

  if (cli->nt_pipe_fnum) cli_nt_session_close (cli);
  cli_shutdown (cli);
  talloc_destroy (mem_ctx);

  return 0;
}



More information about the samba-technical mailing list