lib: Remove global xfile.h includes
[samba.git] / source3 / client / client.c
index 5d708970ad56238ab9f3142e568c4d345fa8ff24..65696f9704a29cebf2aad11e4a60bd612f7726f5 100644 (file)
@@ -39,6 +39,7 @@
 #include "libsmb/nmblib.h"
 #include "include/ntioctl.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "lib/util/xfile.h"
 
 #ifndef REGISTER
 #define REGISTER 0
@@ -312,7 +313,7 @@ static int do_dskattr(void)
                return 1;
        }
 
-       status = cli_disk_size(targetcli, &bsize, &total, &avail);
+       status = cli_disk_size(targetcli, targetpath, &bsize, &total, &avail);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Error in dskattr: %s\n", nt_errstr(status));
                return 1;
@@ -360,7 +361,7 @@ static int do_cd(const char *new_dir)
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        SMB_STRUCT_STAT sbuf;
-       uint32 attributes;
+       uint32_t attributes;
        int ret = 1;
        TALLOC_CTX *ctx = talloc_stackframe();
        NTSTATUS status;
@@ -813,7 +814,7 @@ static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
 ****************************************************************************/
 
 NTSTATUS do_list(const char *mask,
-                       uint16 attribute,
+                       uint16_t attribute,
                        NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
                                   const char *dir),
                        bool rec,
@@ -929,7 +930,7 @@ NTSTATUS do_list(const char *mask,
 static int cmd_dir(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+       uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mask = NULL;
        char *buf = NULL;
        int rc = 1;
@@ -979,7 +980,7 @@ static int cmd_dir(void)
 static int cmd_du(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+       uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mask = NULL;
        char *buf = NULL;
        NTSTATUS status;
@@ -1063,7 +1064,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        uint16_t fnum;
        bool newhandle = false;
        struct timespec tp_start;
-       uint16 attr;
+       uint16_t attr;
        off_t size;
        off_t start = 0;
        off_t nread = 0;
@@ -1158,7 +1159,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        }
 
        if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
-               cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
+               cli_setatr(cli, rname, attr & ~(uint16_t)FILE_ATTRIBUTE_ARCHIVE, 0);
        }
 
        {
@@ -1419,7 +1420,7 @@ static int cmd_more(void)
 static int cmd_mget(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+       uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
        char *mget_mask = NULL;
        char *buf = NULL;
        NTSTATUS status = NT_STATUS_OK;
@@ -1696,7 +1697,7 @@ static int do_allinfo(const char *name)
        unsigned int num_streams;
        struct stream_struct *streams;
        int num_snapshots;
-       char **snapshots;
+       char **snapshots = NULL;
        unsigned int i;
        NTSTATUS status;
 
@@ -1782,6 +1783,20 @@ static int do_allinfo(const char *name)
                 */
                return 0;
        }
+       /*
+        * In order to get shadow copy data over SMB1 we
+        * must call twice, once with 'get_names = false'
+        * to get the size, then again with 'get_names = true'
+        * to get the data or a Windows server fails to return
+        * valid info. Samba doesn't have this bug. JRA.
+        */
+
+       status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
+                                     false, &snapshots, &num_snapshots);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_close(cli, fnum);
+               return 0;
+       }
        status = cli_shadow_copy_data(talloc_tos(), cli, fnum,
                                      true, &snapshots, &num_snapshots);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1816,6 +1831,7 @@ static int do_allinfo(const char *name)
        }
 
        TALLOC_FREE(snapshots);
+       cli_close(cli, fnum);
 
        return 0;
 }
@@ -2389,7 +2405,7 @@ static int cmd_del(void)
        char *mask = NULL;
        char *buf = NULL;
        NTSTATUS status = NT_STATUS_OK;
-       uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+       uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
 
        if (recurse) {
                attribute |= FILE_ATTRIBUTE_DIRECTORY;
@@ -2424,7 +2440,7 @@ static int cmd_wdel(void)
        TALLOC_CTX *ctx = talloc_tos();
        char *mask = NULL;
        char *buf = NULL;
-       uint16 attribute;
+       uint16_t attribute;
        struct cli_state *targetcli;
        char *targetname = NULL;
        NTSTATUS status;
@@ -2434,7 +2450,7 @@ static int cmd_wdel(void)
                return 1;
        }
 
-       attribute = (uint16)strtol(buf, (char **)NULL, 16);
+       attribute = (uint16_t)strtol(buf, (char **)NULL, 16);
 
        if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
                d_printf("wdel 0x<attrib> <wcard>\n");
@@ -2766,8 +2782,8 @@ static int cmd_close(void)
 static int cmd_posix(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
-       uint16 major, minor;
-       uint32 caplow, caphigh;
+       uint16_t major, minor;
+       uint32_t caplow, caphigh;
        char *caps;
        NTSTATUS status;
 
@@ -2955,6 +2971,50 @@ static int cmd_unlock(void)
        return 0;
 }
 
+static int cmd_posix_whoami(void)
+{
+       TALLOC_CTX *ctx = talloc_tos();
+       NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       uint64_t uid = 0;
+       uint64_t gid = 0;
+       uint32_t num_gids = 0;
+       uint32_t num_sids = 0;
+       uint64_t *gids = NULL;
+       struct dom_sid *sids = NULL;
+       bool guest = false;
+       uint32_t i;
+
+       status = cli_posix_whoami(cli,
+                       ctx,
+                       &uid,
+                       &gid,
+                       &num_gids,
+                       &gids,
+                       &num_sids,
+                       &sids,
+                       &guest);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("posix_whoami failed with error %s\n", nt_errstr(status));
+               return 1;
+       }
+
+       d_printf("GUEST:%s\n", guest ? "True" : "False");
+       d_printf("UID:%" PRIu64 "\n", uid);
+       d_printf("GID:%" PRIu64 "\n", gid);
+       d_printf("NUM_GIDS:%" PRIu32 "\n", num_gids);
+       for (i = 0; i < num_gids; i++) {
+               d_printf("GIDS[%" PRIu32 "]:%" PRIu64 "\n", i, gids[i]);
+       }
+       d_printf("NUM_SIDS:%" PRIu32 "\n", num_sids);
+       for (i = 0; i < num_sids; i++) {
+               char *sid_str = dom_sid_string(ctx, &sids[i]);
+               d_printf("SIDS[%" PRIu32 "]:%s\n", i, sid_str);
+               TALLOC_FREE(sid_str);
+       }
+       return 0;
+}
+
 
 /****************************************************************************
  Remove a directory.
@@ -3320,14 +3380,14 @@ static int cmd_getfacl(void)
        char *name = NULL;
        char *targetname = NULL;
        struct cli_state *targetcli;
-       uint16 major, minor;
-       uint32 caplow, caphigh;
+       uint16_t major, minor;
+       uint32_t caplow, caphigh;
        char *retbuf = NULL;
        size_t rb_size = 0;
        SMB_STRUCT_STAT sbuf;
-       uint16 num_file_acls = 0;
-       uint16 num_dir_acls = 0;
-       uint16 i;
+       uint16_t num_file_acls = 0;
+       uint16_t num_dir_acls = 0;
+       uint16_t i;
        NTSTATUS status;
 
        if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
@@ -3375,7 +3435,7 @@ static int cmd_getfacl(void)
                return 1;
        }
 
-       status = cli_posix_getfacl(targetcli, targetname, ctx, &rb_size, &retbuf);
+       status = cli_posix_getacl(targetcli, targetname, ctx, &rb_size, &retbuf);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("%s getfacl file %s\n",
                         nt_errstr(status), src);
@@ -3407,7 +3467,7 @@ static int cmd_getfacl(void)
        }
 
        for (i = 0; i < num_file_acls; i++) {
-               uint32 uorg;
+               uint32_t uorg;
                fstring permstring;
                unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE));
                unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+1);
@@ -3444,7 +3504,7 @@ static int cmd_getfacl(void)
        }
 
        for (i = 0; i < num_dir_acls; i++) {
-               uint32 uorg;
+               uint32_t uorg;
                fstring permstring;
                unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE));
                unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+1);
@@ -3805,6 +3865,139 @@ static int cmd_rename(void)
        return 0;
 }
 
+struct scopy_timing {
+       struct timespec tp_start;
+};
+
+static int scopy_status(off_t written, void *priv)
+{
+       struct timespec tp_end;
+       unsigned int scopy_total_time_ms;
+       struct scopy_timing *st = priv;
+
+       clock_gettime_mono(&tp_end);
+       scopy_total_time_ms = nsec_time_diff(&tp_end,&st->tp_start)/1000000;
+
+       DEBUG(5,("Copied %jd bytes at an average %3.1f kb/s\n",
+                (intmax_t)written, written / (1.024*scopy_total_time_ms)));
+
+       return true;
+}
+
+/****************************************************************************
+ Server-Side copy some file.
+****************************************************************************/
+
+static int cmd_scopy(void)
+{
+       TALLOC_CTX *ctx = talloc_tos();
+       char *src, *dest;
+       char *buf, *buf2;
+       struct cli_state *targetcli;
+       char *targetsrc;
+       char *targetdest;
+       uint32_t DesiredAccess, ShareAccess, CreateDisposition, CreateOptions;
+       struct smb_create_returns cr;
+       uint16_t destfnum = (uint16_t)-1;
+       uint16_t srcfnum = (uint16_t)-1;
+       off_t written = 0;
+       struct scopy_timing st;
+       int rc = 0;
+       NTSTATUS status;
+
+       if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
+                       !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
+               d_printf("scopy <src> <dest>\n");
+               return 1;
+       }
+
+       src = talloc_asprintf(ctx,
+                       "%s%s",
+                       client_get_cur_dir(),
+                       buf);
+       if (!src) {
+               return 1;
+       }
+
+       dest = talloc_asprintf(ctx,
+                       "%s%s",
+                       client_get_cur_dir(),
+                       buf2);
+       if (!dest) {
+               return 1;
+       }
+
+       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
+                       &targetsrc);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("scopy %s: %s\n", src, nt_errstr(status));
+               return 1;
+       }
+
+       status = cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli,
+                       &targetdest);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("scopy %s: %s\n", dest, nt_errstr(status));
+               return 1;
+       }
+
+
+       DesiredAccess = (FILE_READ_DATA|FILE_READ_EA|FILE_READ_ATTRIBUTES|
+                       READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS);
+       ShareAccess = FILE_SHARE_READ|FILE_SHARE_DELETE;
+       CreateDisposition = FILE_OPEN;
+       CreateOptions = (FILE_SEQUENTIAL_ONLY|FILE_NON_DIRECTORY_FILE|
+                       FILE_OPEN_REPARSE_POINT);
+       status = cli_ntcreate(targetcli, targetsrc, 0, DesiredAccess, 0,
+                       ShareAccess, CreateDisposition, CreateOptions, 0x0,
+                       &srcfnum, &cr);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Failed to open file %s. %s\n",
+                               targetsrc, nt_errstr(status));
+               return 1;
+       }
+
+       DesiredAccess = (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|FILE_READ_EA|
+                       FILE_WRITE_EA|FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|
+                       DELETE_ACCESS|READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|SYNCHRONIZE_ACCESS);
+       ShareAccess = FILE_SHARE_NONE;
+       CreateDisposition = FILE_CREATE;
+       CreateOptions = FILE_SEQUENTIAL_ONLY|FILE_NON_DIRECTORY_FILE;
+       status = cli_ntcreate(targetcli, targetdest, 0, DesiredAccess,
+                       FILE_ATTRIBUTE_ARCHIVE, ShareAccess, CreateDisposition,
+                       CreateOptions, 0x0, &destfnum, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Failed to create file %s. %s\n",
+                               targetdest, nt_errstr(status));
+               cli_close(targetcli, srcfnum);
+               return 1;
+       }
+
+       clock_gettime_mono(&st.tp_start);
+       status = cli_splice(targetcli, targetcli, srcfnum, destfnum,
+                       cr.end_of_file, 0, 0, &written, scopy_status, &st);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("%s copying file %s -> %s \n",
+                               nt_errstr(status),
+                               targetsrc,
+                               targetdest);
+               rc = 1;
+       }
+
+       status = cli_close(targetcli, srcfnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Error %s closing remote source file\n", nt_errstr(status));
+               rc = 1;
+       }
+       status = cli_close(targetcli, destfnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Error %s closing remote dest file\n", nt_errstr(status));
+               rc = 1;
+       }
+
+       return rc;
+}
+
 /****************************************************************************
  Print the volume name.
 ****************************************************************************/
@@ -3970,7 +4163,7 @@ static int cmd_notify(void)
                TALLOC_FREE(changes);
        }
 usage:
-       d_printf("notify <file>\n");
+       d_printf("notify <dir name>\n");
 fail:
        TALLOC_FREE(frame);
        return 1;
@@ -4180,7 +4373,7 @@ static int cmd_reput(void)
  List a share name.
  ****************************************************************************/
 
-static void browse_fn(const char *name, uint32 m,
+static void browse_fn(const char *name, uint32_t m,
                       const char *comment, void *state)
 {
        const char *typestr = "";
@@ -4294,7 +4487,7 @@ static bool browse_host(bool sort)
  List a server name.
 ****************************************************************************/
 
-static void server_fn(const char *name, uint32 m,
+static void server_fn(const char *name, uint32_t m,
                       const char *comment, void *state)
 {
 
@@ -4362,6 +4555,7 @@ static int cmd_logon(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
        char *l_username, *l_password;
+       struct cli_credentials *creds = NULL;
        NTSTATUS nt_status;
 
        if (!next_token_talloc(ctx, &cmd_ptr,&l_username,NULL)) {
@@ -4382,10 +4576,21 @@ static int cmd_logon(void)
                return 1;
        }
 
-       nt_status = cli_session_setup(cli, l_username,
-                                     l_password, strlen(l_password),
-                                     l_password, strlen(l_password),
-                                     lp_workgroup());
+       creds = cli_session_creds_init(ctx,
+                                      l_username,
+                                      lp_workgroup(),
+                                      NULL, /* realm */
+                                      l_password,
+                                      false, /* use_kerberos */
+                                      false, /* fallback_after_kerberos */
+                                      false, /* use_ccache */
+                                      false); /* password_is_nt_hash */
+       if (creds == NULL) {
+               d_printf("cli_session_creds_init() failed.\n");
+               return -1;
+       }
+       nt_status = cli_session_setup_creds(cli, creds);
+       TALLOC_FREE(creds);
        if (!NT_STATUS_IS_OK(nt_status)) {
                d_printf("session setup failed: %s\n", nt_errstr(nt_status));
                return -1;
@@ -4522,6 +4727,124 @@ static int cmd_show_connect( void )
        return 0;
 }
 
+/**
+ * set_remote_attr - set DOS attributes of a remote file
+ * @filename: path to the file name
+ * @new_attr: attribute bit mask to use
+ * @mode: one of ATTR_SET or ATTR_UNSET
+ *
+ * Update the file attributes with the one provided.
+ */
+int set_remote_attr(const char *filename, uint16_t new_attr, int mode)
+{
+       extern struct cli_state *cli;
+       uint16_t old_attr;
+       NTSTATUS status;
+
+       status = cli_getatr(cli, filename, &old_attr, NULL, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_getatr failed: %s\n", nt_errstr(status));
+               return 1;
+       }
+
+       if (mode == ATTR_SET) {
+               new_attr |= old_attr;
+       } else {
+               new_attr = old_attr & ~new_attr;
+       }
+
+       status = cli_setatr(cli, filename, new_attr, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_setatr failed: %s\n", nt_errstr(status));
+               return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * cmd_setmode - interactive command to set DOS attributes
+ *
+ * Read a filename and mode from the client command line and update
+ * the file DOS attributes.
+ */
+int cmd_setmode(void)
+{
+       const extern char *cmd_ptr;
+       char *buf;
+       char *fname = NULL;
+       uint16_t attr[2] = {0};
+       int mode = ATTR_SET;
+       int err = 0;
+       bool ok;
+       TALLOC_CTX *ctx = talloc_new(NULL);
+       if (ctx == NULL) {
+               return 1;
+       }
+
+       ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL);
+       if (!ok) {
+               d_printf("setmode <filename> <[+|-]rsha>\n");
+               err = 1;
+               goto out;
+       }
+
+       fname = talloc_asprintf(ctx,
+                               "%s%s",
+                               client_get_cur_dir(),
+                               buf);
+       if (fname == NULL) {
+               err = 1;
+               goto out;
+       }
+
+       while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) {
+               const char *s = buf;
+
+               while (*s) {
+                       switch (*s++) {
+                       case '+':
+                               mode = ATTR_SET;
+                               break;
+                       case '-':
+                               mode = ATTR_UNSET;
+                               break;
+                       case 'r':
+                               attr[mode] |= FILE_ATTRIBUTE_READONLY;
+                               break;
+                       case 'h':
+                               attr[mode] |= FILE_ATTRIBUTE_HIDDEN;
+                               break;
+                       case 's':
+                               attr[mode] |= FILE_ATTRIBUTE_SYSTEM;
+                               break;
+                       case 'a':
+                               attr[mode] |= FILE_ATTRIBUTE_ARCHIVE;
+                               break;
+                       default:
+                               d_printf("setmode <filename> <perm=[+|-]rsha>\n");
+                               err = 1;
+                               goto out;
+                       }
+               }
+       }
+
+       if (attr[ATTR_SET] == 0 && attr[ATTR_UNSET] == 0) {
+               d_printf("setmode <filename> <[+|-]rsha>\n");
+               err = 1;
+               goto out;
+       }
+
+       DEBUG(2, ("perm set %d %d\n", attr[ATTR_SET], attr[ATTR_UNSET]));
+
+       /* ignore return value: server might not store DOS attributes */
+       set_remote_attr(fname, attr[ATTR_SET], ATTR_SET);
+       set_remote_attr(fname, attr[ATTR_UNSET], ATTR_UNSET);
+out:
+       talloc_free(ctx);
+       return err;
+}
+
 /****************************************************************************
  iosize command
 ***************************************************************************/
@@ -4679,6 +5002,8 @@ static struct {
   {"posix_mkdir",cmd_posix_mkdir,"<name> 0<mode> creates a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"posix_rmdir",cmd_posix_rmdir,"<name> removes a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"posix_unlink",cmd_posix_unlink,"<name> removes a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
+  {"posix_whoami",cmd_posix_whoami,"retun logged on user information "
+                       "using POSIX interface",{COMPL_REMOTE,COMPL_NONE}},
   {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
   {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
   {"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
@@ -4698,6 +5023,7 @@ static struct {
   {"setea", cmd_setea, "<file name> <eaname> <eaval> Set an EA of a file",
    {COMPL_REMOTE, COMPL_LOCAL}},
   {"setmode",cmd_setmode,"<file name> <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
+  {"scopy",cmd_scopy,"<src> <dest> server-side copy file",{COMPL_REMOTE,COMPL_REMOTE}},
   {"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}},
@@ -5285,6 +5611,10 @@ static int do_host_query(const char *query_host)
                }
        }
 
+       if (lp_disable_netbios()) {
+               goto out;
+       }
+
        if (port != NBT_SMB_PORT) {
 
                /* Workgroups simply don't make sense over anything
@@ -5308,7 +5638,7 @@ static int do_host_query(const char *query_host)
 
        cli_set_timeout(cli, io_timeout*1000);
        list_servers(lp_workgroup());
-
+out:
        cli_shutdown(cli);
 
        return(0);
@@ -5363,6 +5693,11 @@ static int do_message_op(struct user_auth_info *a_info)
 {
        NTSTATUS status;
 
+       if (lp_disable_netbios()) {
+               d_printf("NetBIOS over TCP disabled.\n");
+               return 1;
+       }
+
        status = cli_connect_nb(desthost, have_ip ? &dest_ss : NULL,
                                port ? port : NBT_SMB_PORT, name_type,
                                lp_netbios_name(), SMB_SIGNING_DEFAULT, 0, &cli);
@@ -5427,15 +5762,11 @@ int main(int argc,char *argv[])
 
         /* set default debug level to 1 regardless of what smb.conf sets */
        setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
-       load_case_tables();
+       smb_init_locale();
 
        lp_set_cmdline("log level", "1");
 
-       auth_info = user_auth_info_init(frame);
-       if (auth_info == NULL) {
-               exit(1);
-       }
-       popt_common_set_auth_info(auth_info);
+       popt_common_credentials_set_delay_post();
 
        /* skip argv(0) */
        pc = poptGetContext("smbclient", argc, const_argv, long_options, 0);
@@ -5463,9 +5794,9 @@ int main(int argc,char *argv[])
 
                /* if the service has already been retrieved then check if we have also a password */
                if (service_opt
-                   && (!get_cmdline_auth_info_got_pass(auth_info))
+                   && (!get_cmdline_auth_info_got_pass(cmdline_auth_info))
                    && poptPeekArg(pc)) {
-                       set_cmdline_auth_info_password(auth_info,
+                       set_cmdline_auth_info_password(cmdline_auth_info,
                                                       poptGetArg(pc));
                }
 
@@ -5565,9 +5896,9 @@ int main(int argc,char *argv[])
 
        /* if the service has already been retrieved then check if we have also a password */
        if (service_opt
-           && !get_cmdline_auth_info_got_pass(auth_info)
+           && !get_cmdline_auth_info_got_pass(cmdline_auth_info)
            && poptPeekArg(pc)) {
-               set_cmdline_auth_info_password(auth_info,
+               set_cmdline_auth_info_password(cmdline_auth_info,
                                               poptGetArg(pc));
        }
 
@@ -5579,11 +5910,6 @@ int main(int argc,char *argv[])
                        argv[0], get_dyn_CONFIGFILE());
        }
 
-       if (get_cmdline_auth_info_use_machine_account(auth_info) &&
-           !set_cmdline_auth_info_machine_account_creds(auth_info)) {
-               exit(-1);
-       }
-
        load_interfaces();
 
        if (service_opt && service) {
@@ -5604,7 +5930,6 @@ int main(int argc,char *argv[])
                }
        }
 
-       smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
        if (!init_names()) {
                fprintf(stderr, "init_names() failed\n");
                exit(1);
@@ -5624,7 +5949,9 @@ int main(int argc,char *argv[])
        DEBUG(3,("Client started (version %s).\n", samba_version_string()));
 
        /* Ensure we have a password (or equivalent). */
-       set_cmdline_auth_info_getpass(auth_info);
+       popt_common_credentials_post();
+       auth_info = cmdline_auth_info;
+       smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
 
        max_protocol = lp_client_max_protocol();