Use the given name, not the absolute pathname, when printing out ACL info.
[tprouty/samba.git] / source / client / client.c
index 79b7dfe8389ecca0ec6981a84dbafe12f5791784..9446c27068fea9f41e1bb9f4dde46e2cb12ae5ad 100644 (file)
@@ -33,7 +33,6 @@ extern int do_smb_browse(void); /* mDNS browsing */
 extern bool AllowDebugChange;
 extern bool override_logfile;
 extern char tar_type;
-extern bool in_client;
 
 static int port = 0;
 static char *service;
@@ -41,7 +40,7 @@ static char *desthost;
 static char *calling_name;
 static bool grepable = false;
 static char *cmdstr = NULL;
-static const char *cmd_ptr = NULL;
+const char *cmd_ptr = NULL;
 
 static int io_bufsize = 524288;
 
@@ -522,14 +521,14 @@ static void display_finfo(file_info *finfo, const char *dir)
                /* create absolute filename for cli_nt_create() FIXME */
                afname = talloc_asprintf(ctx,
                                        "%s%s%s",
-                                       client_get_cwd(),
+                                       dir,
                                        CLI_DIRSEP_STR,
                                        finfo->name);
                if (!afname) {
                        return;
                }
                /* print file meta date header */
-               d_printf( "FILENAME:%s\n", afname);
+               d_printf( "FILENAME:%s\n", finfo->name);
                d_printf( "MODE:%s\n", attrib_string(finfo->mode));
                d_printf( "SIZE:%.0f\n", (double)finfo->size);
                d_printf( "MTIME:%s", time_to_asc(t));
@@ -982,7 +981,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        uint16 attr;
        SMB_OFF_T size;
        off_t start = 0;
-       ssize_t nread = 0;
+       SMB_OFF_T nread = 0;
        int rc = 0;
        struct cli_state *targetcli = NULL;
        char *targetname = NULL;
@@ -3628,13 +3627,13 @@ static bool browse_host_rpc(bool sort)
        NTSTATUS status;
        struct rpc_pipe_client *pipe_hnd;
        TALLOC_CTX *frame = talloc_stackframe();
-       ENUM_HND enum_hnd;
        WERROR werr;
-       SRV_SHARE_INFO_CTR ctr;
+       struct srvsvc_NetShareInfoCtr info_ctr;
+       struct srvsvc_NetShareCtr1 ctr1;
+       uint32_t resume_handle = 0;
+       uint32_t total_entries = 0;
        int i;
 
-       init_enum_hnd(&enum_hnd, 0);
-
        pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
 
        if (pipe_hnd == NULL) {
@@ -3644,23 +3643,29 @@ static bool browse_host_rpc(bool sort)
                return false;
        }
 
-       werr = rpccli_srvsvc_net_share_enum(pipe_hnd, frame, 1, &ctr,
-                                           0xffffffff, &enum_hnd);
+       ZERO_STRUCT(info_ctr);
+       ZERO_STRUCT(ctr1);
+
+       info_ctr.level = 1;
+       info_ctr.ctr.ctr1 = &ctr1;
 
-       if (!W_ERROR_IS_OK(werr)) {
+       status = rpccli_srvsvc_NetShareEnumAll(pipe_hnd, frame,
+                                             pipe_hnd->cli->desthost,
+                                             &info_ctr,
+                                             0xffffffff,
+                                             &total_entries,
+                                             &resume_handle,
+                                             &werr);
+
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
                cli_rpc_pipe_close(pipe_hnd);
                TALLOC_FREE(frame);
                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(
-                       frame, &info->info_1_str.uni_netname);
-               comment = rpcstr_pull_unistr2_talloc(
-                       frame, &info->info_1_str.uni_remark);
-               browse_fn(name, info->info_1.type, comment, NULL);
+       for (i=0; i < info_ctr.ctr.ctr1->count; i++) {
+               struct srvsvc_NetShareInfo1 info = info_ctr.ctr.ctr1->array[i];
+               browse_fn(info.name, info.type, info.comment, NULL);
        }
 
        cli_rpc_pipe_close(pipe_hnd);
@@ -4097,11 +4102,7 @@ static void completion_remote_filter(const char *mnt,
                        TALLOC_CTX *ctx = talloc_stackframe();
                        char *tmp;
 
-                       if (info->dirmask && info->dirmask[0] != 0) {
-                               tmp = talloc_strdup(ctx,info->dirmask);
-                       } else {
-                               tmp = talloc_strdup(ctx,"");
-                       }
+                       tmp = talloc_strdup(ctx,info->dirmask);
                        if (!tmp) {
                                TALLOC_FREE(ctx);
                                return;
@@ -4381,7 +4382,7 @@ static void readline_callback(void)
 
                set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
 
-               status = receive_smb_raw(cli->fd, cli->inbuf, 0, 0, &len);
+               status = receive_smb_raw(cli->fd, cli->inbuf, cli->bufsize, 0, 0, &len);
 
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("Read from server failed, maybe it closed "
@@ -4513,6 +4514,8 @@ static int process(const char *base_directory)
 
 static int do_host_query(const char *query_host)
 {
+       struct sockaddr_storage ss;
+
        cli = cli_cm_open(talloc_tos(), NULL,
                        query_host, "IPC$", true, smb_encrypt);
        if (!cli)
@@ -4520,6 +4523,12 @@ static int do_host_query(const char *query_host)
 
        browse_host(true);
 
+       if (interpret_string_addr(&ss, query_host, 0) && (ss.ss_family != AF_INET)) {
+               d_printf("%s is an IPv6 address -- no workgroup available\n",
+                       query_host);
+               return 1;
+       }
+
        if (port != 139) {
 
                /* Workgroups simply don't make sense over anything
@@ -4701,7 +4710,7 @@ static int do_message_op(void)
        pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
        poptSetOtherOptionHelp(pc, "service <password>");
 
-       in_client = true;   /* Make sure that we tell lp_load we are */
+        lp_set_in_client(true); /* Make sure that we tell lp_load we are */
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
 
@@ -4866,6 +4875,11 @@ static int do_message_op(void)
                        argv[0], get_dyn_CONFIGFILE());
        }
 
+       if (get_cmdline_auth_info_use_machine_account() &&
+           !set_cmdline_auth_info_machine_account_creds()) {
+               exit(-1);
+       }
+
        load_interfaces();
 
        if (service_opt && service) {
@@ -4898,7 +4912,10 @@ static int do_message_op(void)
        }
 
        smb_encrypt = get_cmdline_auth_info_smb_encrypt();
-       init_names();
+       if (!init_names()) {
+               fprintf(stderr, "init_names() failed\n");
+               exit(1);
+       }
 
        if(new_name_resolve_order)
                lp_set_name_resolve_order(new_name_resolve_order);