s3/smbclient: fix incorrect command tab completions
[mat/samba.git] / source3 / client / client.c
index 821bd0a32e10a1772d107f09e4e462db61c4c5a0..d03d1a40aed264dc3c80980c203a326a7bbdf328 100644 (file)
@@ -65,10 +65,6 @@ static int cmd_help(void);
 
 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
 
-/* 30 second timeout on most commands */
-#define CLIENT_TIMEOUT (30*1000)
-#define SHORT_TIMEOUT (5*1000)
-
 /* value for unused fid field in trans2 secondary request */
 #define FID_UNUSED (0xFFFF)
 
@@ -1086,7 +1082,10 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        }
 
        if (lowercase) {
-               strlower_m(lname);
+               if (!strlower_m(lname)) {
+                       d_printf("strlower_m %s failed\n", lname);
+                       return 1;
+               }
        }
 
        status = cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli,
@@ -1296,7 +1295,9 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
 
        string_replace(finfo->name,'\\','/');
        if (lowercase) {
-               strlower_m(finfo->name);
+               if (!strlower_m(finfo->name)) {
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
        }
 
        if (!directory_exist(finfo->name) &&
@@ -1320,8 +1321,17 @@ static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = do_list(mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
-       if (!NT_STATUS_IS_OK(status)) {
+       status = do_list(mget_mask,
+                        (FILE_ATTRIBUTE_SYSTEM
+                         | FILE_ATTRIBUTE_HIDDEN
+                         | FILE_ATTRIBUTE_DIRECTORY),
+                        do_mget, false, true);
+       if (!NT_STATUS_IS_OK(status)
+        && !NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+               /*
+                * Ignore access denied errors to ensure all permitted files are
+                * pulled down.
+                */
                return status;
        }
 
@@ -1351,6 +1361,7 @@ static int cmd_more(void)
        const char *pager;
        int fd;
        int rc = 0;
+       mode_t mask;
 
        rname = talloc_strdup(ctx, client_get_cur_dir());
        if (!rname) {
@@ -1361,7 +1372,9 @@ static int cmd_more(void)
        if (!lname) {
                return 1;
        }
+       mask = umask(S_IRWXO | S_IRWXG);
        fd = mkstemp(lname);
+       umask(mask);
        if (fd == -1) {
                d_printf("failed to create temporary file for more\n");
                return 1;
@@ -1752,7 +1765,8 @@ static int do_allinfo(const char *name)
        }
 
        status = cli_ntcreate(cli, name, 0,
-                             CREATE_ACCESS_READ, 0,
+                             SEC_FILE_READ_DATA | SEC_FILE_READ_ATTRIBUTE |
+                             SEC_STD_SYNCHRONIZE, 0,
                              FILE_SHARE_READ|FILE_SHARE_WRITE
                              |FILE_SHARE_DELETE,
                              FILE_OPEN, 0x0, 0x0, &fnum);
@@ -4351,9 +4365,12 @@ static int cmd_logon(void)
        }
 
        if (!next_token_talloc(ctx, &cmd_ptr,&l_password,NULL)) {
-               char *pass = getpass("Password: ");
-               if (pass) {
-                       l_password = talloc_strdup(ctx,pass);
+               char pwd[256] = {0};
+               int rc;
+
+               rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false);
+               if (rc == 0) {
+                       l_password = talloc_strdup(ctx, pwd);
                }
        }
        if (!l_password) {
@@ -4589,18 +4606,18 @@ static struct {
   {"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
   {"case_sensitive",cmd_setcase,"toggle the case sensitive flag to server",{COMPL_NONE,COMPL_NONE}},
   {"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
-  {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
-  {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
-  {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_REMOTE}},
+  {"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_NONE}},
+  {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_NONE}},
+  {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_NONE}},
   {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
   {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
   {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
   {"echo",cmd_echo,"ping the server",{COMPL_NONE,COMPL_NONE}},
   {"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
   {"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
-  {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_LOCAL}},
+  {"getfacl",cmd_getfacl,"<file name> get the POSIX ACL on a file (UNIX extensions only)",{COMPL_REMOTE,COMPL_NONE}},
   {"geteas", cmd_geteas, "<file name> get the EA list of a file",
-   {COMPL_REMOTE, COMPL_LOCAL}},
+   {COMPL_REMOTE, COMPL_NONE}},
   {"hardlink",cmd_hardlink,"<src> <dest> create a Windows hard link",{COMPL_REMOTE,COMPL_REMOTE}},
   {"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
   {"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
@@ -4640,12 +4657,12 @@ static struct {
   {"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
   {"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
   {"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
-  {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
+  {"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_REMOTE,COMPL_NONE}},
   {"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}},  
   {"setea", cmd_setea, "<file name> <eaname> <eaval> Set an EA of a file",
    {COMPL_REMOTE, COMPL_LOCAL}},
-  {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
-  {"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
+  {"setmode",cmd_setmode,"<file name> <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
+  {"stat",cmd_stat,"<file name> Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_NONE}},
   {"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
   {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
   {"tarmode",cmd_tarmode,"<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
@@ -4964,6 +4981,7 @@ static char **remote_completion(const char *text, int len)
 
        info.matches[0] = SMB_STRNDUP(info.matches[1], info.samelen);
        info.matches[info.count] = NULL;
+       TALLOC_FREE(ctx);
        return info.matches;
 
 cleanup:
@@ -5401,6 +5419,7 @@ static int do_message_op(struct user_auth_info *a_info)
                                                       poptGetArg(pc));
                }
 
+
                switch (opt) {
                case 'M':
                        /* Messages are sent to NetBIOS name type 0x3
@@ -5540,7 +5559,7 @@ static int do_message_op(struct user_auth_info *a_info)
        }
 
        if(new_name_resolve_order)
-               lp_set_name_resolve_order(new_name_resolve_order);
+               lp_set_cmdline("name resolve order", new_name_resolve_order);
 
        if (!tar_type && !query_host && !service && !message) {
                poptPrintUsage(pc, stderr, 0);
@@ -5548,6 +5567,7 @@ static int do_message_op(struct user_auth_info *a_info)
        }
 
        poptFreeContext(pc);
+       popt_burn_cmdline_password(argc, argv);
 
        DEBUG(3,("Client started (version %s).\n", samba_version_string()));