s3: client tools: Call popt_free_cmdline_auth_info() on all normal exits.
[bbaumbach/samba-autobuild/.git] / source3 / client / client.c
index 82521288be985e333f0cdc850b2d9b727ad40d7f..64647365dc4709b3c71cf73c89b334b0120f4c60 100644 (file)
@@ -108,9 +108,6 @@ struct cli_state *cli;
 static char CLI_DIRSEP_CHAR = '\\';
 static char CLI_DIRSEP_STR[] = { '\\', '\0' };
 
-/* Authentication for client connections. */
-struct user_auth_info *auth_info;
-
 /* Accessor functions for directory paths. */
 static char *fileselection;
 static const char *client_get_fileselection(void)
@@ -304,7 +301,7 @@ static int do_dskattr(void)
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status;
 
-       status = cli_resolve_path(ctx, "", auth_info, cli,
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(), cli,
                                  client_get_cur_dir(), &targetcli,
                                  &targetpath);
        if (!NT_STATUS_IS_OK(status)) {
@@ -405,8 +402,8 @@ static int do_cd(const char *new_dir)
        new_cd = clean_name(ctx, new_cd);
        client_set_cur_dir(new_cd);
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, new_cd,
-                                 &targetcli, &targetpath);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, new_cd, &targetcli, &targetpath);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("cd %s: %s\n", new_cd, nt_errstr(status));
                client_set_cur_dir(saved_dir);
@@ -857,9 +854,9 @@ NTSTATUS do_list(const char *mask,
 
                        /* check for dfs */
 
-                       status = cli_resolve_path(ctx, "", auth_info, cli,
-                                                 head, &targetcli,
-                                                 &targetpath);
+                       status = cli_resolve_path(ctx, "",
+                                       popt_get_cmdline_auth_info(),
+                                       cli, head, &targetcli, &targetpath);
                        if (!NT_STATUS_IS_OK(status)) {
                                d_printf("do_list: [%s] %s\n", head,
                                         nt_errstr(status));
@@ -900,8 +897,9 @@ NTSTATUS do_list(const char *mask,
                }
        } else {
                /* check for dfs */
-               status = cli_resolve_path(ctx, "", auth_info, cli, mask,
-                                         &targetcli, &targetpath);
+               status = cli_resolve_path(ctx, "",
+                               popt_get_cmdline_auth_info(), cli, mask,
+                                 &targetcli, &targetpath);
                if (NT_STATUS_IS_OK(status)) {
                        status = cli_list(targetcli, targetpath, attribute,
                                          do_list_helper, targetcli);
@@ -1085,8 +1083,8 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
                }
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, rname, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
                return 1;
@@ -1483,8 +1481,8 @@ static bool do_mkdir(const char *name)
        char *targetname = NULL;
        NTSTATUS status;
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, name, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("mkdir %s: %s\n", name, nt_errstr(status));
                return false;
@@ -1527,6 +1525,7 @@ static bool do_altname(const char *name)
 static int cmd_quit(void)
 {
        cli_shutdown(cli);
+       popt_free_cmdline_auth_info();
        exit(0);
        /* NOTREACHED */
        return 0;
@@ -1572,8 +1571,9 @@ static int cmd_mkdir(void)
                        return 1;
                }
 
-               status = cli_resolve_path(ctx, "", auth_info, cli, mask,
-                                         &targetcli, &targetname);
+               status = cli_resolve_path(ctx, "",
+                               popt_get_cmdline_auth_info(), cli, mask,
+                               &targetcli, &targetname);
                if (!NT_STATUS_IS_OK(status)) {
                        return 1;
                }
@@ -1881,8 +1881,8 @@ static int do_put(const char *rname, const char *lname, bool reput)
        struct push_state state;
        NTSTATUS status;
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, rname,
-                                 &targetcli, &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, rname, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Failed to open %s: %s\n", rname, nt_errstr(status));
                return 1;
@@ -1984,6 +1984,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
 
        if (f == stdin) {
                cli_shutdown(cli);
+               popt_free_cmdline_auth_info();
                exit(rc);
        }
 
@@ -2463,8 +2464,8 @@ static int cmd_wdel(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("cmd_wdel %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -2503,8 +2504,8 @@ static int cmd_open(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("open %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -2535,35 +2536,54 @@ static int cmd_posix_encrypt(void)
 {
        TALLOC_CTX *ctx = talloc_tos();
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+       char *domain = NULL;
+       char *user = NULL;
+       char *password = NULL;
+       struct cli_credentials *creds = NULL;
+       struct cli_credentials *lcreds = NULL;
 
-       if (cli->use_kerberos) {
-               status = cli_gss_smb_encryption_start(cli);
-       } else {
-               char *domain = NULL;
-               char *user = NULL;
-               char *password = NULL;
+       if (next_token_talloc(ctx, &cmd_ptr, &domain, NULL)) {
 
-               if (!next_token_talloc(ctx, &cmd_ptr,&domain,NULL)) {
+               if (!next_token_talloc(ctx, &cmd_ptr, &user, NULL)) {
                        d_printf("posix_encrypt domain user password\n");
                        return 1;
                }
 
-               if (!next_token_talloc(ctx, &cmd_ptr,&user,NULL)) {
+               if (!next_token_talloc(ctx, &cmd_ptr, &password, NULL)) {
                        d_printf("posix_encrypt domain user password\n");
                        return 1;
                }
 
-               if (!next_token_talloc(ctx, &cmd_ptr,&password,NULL)) {
+               lcreds = cli_session_creds_init(ctx,
+                                               user,
+                                               domain,
+                                               NULL, /* realm */
+                                               password,
+                                               false, /* use_kerberos */
+                                               false, /* fallback_after_kerberos */
+                                               false, /* use_ccache */
+                                               false); /* password_is_nt_hash */
+               if (lcreds == NULL) {
+                       d_printf("cli_session_creds_init() failed.\n");
+                       return -1;
+               }
+               creds = lcreds;
+       } else {
+               bool auth_requested = false;
+
+               creds = get_cmdline_auth_info_creds(
+                               popt_get_cmdline_auth_info());
+
+               auth_requested = cli_credentials_authentication_requested(creds);
+               if (!auth_requested) {
                        d_printf("posix_encrypt domain user password\n");
                        return 1;
                }
-
-               status = cli_raw_ntlm_smb_encryption_start(cli,
-                                                       user,
-                                                       password,
-                                                       domain);
        }
 
+       status = cli_smb1_setup_encryption(cli, creds);
+       /* gensec currently references the creds so we can't free them here */
+       talloc_unlink(ctx, lcreds);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("posix_encrypt failed with error %s\n", nt_errstr(status));
        } else {
@@ -2606,8 +2626,8 @@ static int cmd_posix_open(void)
        }
        mode = (mode_t)strtol(buf, (char **)NULL, 8);
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("posix_open %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -2661,8 +2681,8 @@ static int cmd_posix_mkdir(void)
        }
        mode = (mode_t)strtol(buf, (char **)NULL, 8);
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("posix_mkdir %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -2699,8 +2719,8 @@ static int cmd_posix_unlink(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("posix_unlink %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -2738,8 +2758,8 @@ static int cmd_posix_rmdir(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("posix_rmdir %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -3040,8 +3060,8 @@ static int cmd_rmdir(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, mask, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("rmdir %s: %s\n", mask, nt_errstr(status));
                return 1;
@@ -3091,8 +3111,8 @@ static int cmd_link(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, oldname, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("link %s: %s\n", oldname, nt_errstr(status));
                return 1;
@@ -3138,8 +3158,8 @@ static int cmd_readlink(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, name, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("readlink %s: %s\n", name, nt_errstr(status));
                return 1;
@@ -3192,8 +3212,9 @@ static int cmd_symlink(void)
                        return 1;
                }
                /* New name must be present in share namespace. */
-               status = cli_resolve_path(ctx, "", auth_info, cli, newname,
-                                         &newcli, &newname);
+               status = cli_resolve_path(ctx, "",
+                               popt_get_cmdline_auth_info(), cli, newname,
+                               &newcli, &newname);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("link %s: %s\n", oldname, nt_errstr(status));
                        return 1;
@@ -3244,8 +3265,8 @@ static int cmd_chmod(void)
 
        mode = (mode_t)strtol(buf, NULL, 8);
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("chmod %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3401,8 +3422,8 @@ static int cmd_getfacl(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("stat %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3569,8 +3590,8 @@ static int cmd_geteas(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("stat %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3626,8 +3647,8 @@ static int cmd_setea(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("stat %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3672,8 +3693,8 @@ static int cmd_stat(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("stat %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3780,8 +3801,8 @@ static int cmd_chown(void)
        if (!src) {
                return 1;
        }
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("chown %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -3815,10 +3836,11 @@ static int cmd_rename(void)
        char *targetsrc;
        char *targetdest;
         NTSTATUS status;
+       bool replace = false;
 
        if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
            !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
-               d_printf("rename <src> <dest>\n");
+               d_printf("rename <src> <dest> [-f]\n");
                return 1;
        }
 
@@ -3838,21 +3860,26 @@ static int cmd_rename(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetsrc);
+       if (next_token_talloc(ctx, &cmd_ptr, &buf, NULL) &&
+           strcsequal(buf, "-f")) {
+               replace = true;
+       }
+
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, src, &targetcli, &targetsrc);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("rename %s: %s\n", src, nt_errstr(status));
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli,
-                                 &targetdest);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, dest, &targetcli, &targetdest);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("rename %s: %s\n", dest, nt_errstr(status));
                return 1;
        }
 
-       status = cli_rename(targetcli, targetsrc, targetdest);
+       status = cli_rename(targetcli, targetsrc, targetdest, replace);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("%s renaming files %s -> %s \n",
                        nt_errstr(status),
@@ -3926,15 +3953,15 @@ static int cmd_scopy(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                       &targetsrc);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_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);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                       cli, dest, &targetcli, &targetdest);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("scopy %s: %s\n", dest, nt_errstr(status));
                return 1;
@@ -4056,8 +4083,8 @@ static int cmd_hardlink(void)
                return 1;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli,
-                                 &targetname);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, src, &targetcli, &targetname);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("hardlink %s: %s\n", src, nt_errstr(status));
                return 1;
@@ -4714,7 +4741,7 @@ static int cmd_show_connect( void )
        char *targetpath;
        NTSTATUS status;
 
-       status = cli_resolve_path(ctx, "", auth_info, cli,
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(), cli,
                                  client_get_cur_dir(), &targetcli,
                                  &targetpath);
        if (!NT_STATUS_IS_OK(status)) {
@@ -5124,7 +5151,7 @@ static int process_command_string(const char *cmd_in)
 
                status = cli_cm_open(talloc_tos(), NULL,
                                     have_ip ? dest_ss_str : desthost,
-                                    service, auth_info,
+                                    service, popt_get_cmdline_auth_info(),
                                     true, smb_encrypt,
                                     max_protocol, port, name_type,
                                     &cli);
@@ -5304,8 +5331,8 @@ static char **remote_completion(const char *text, int len)
                goto cleanup;
        }
 
-       status = cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli,
-                                 &targetpath);
+       status = cli_resolve_path(ctx, "", popt_get_cmdline_auth_info(),
+                               cli, dirmask, &targetcli, &targetpath);
        if (!NT_STATUS_IS_OK(status)) {
                goto cleanup;
        }
@@ -5553,8 +5580,9 @@ static int process(const char *base_directory)
 
        status = cli_cm_open(talloc_tos(), NULL,
                             have_ip ? dest_ss_str : desthost,
-                            service, auth_info, true, smb_encrypt,
-                            max_protocol, port, name_type, &cli);
+                            service, popt_get_cmdline_auth_info(),
+                            true, smb_encrypt, max_protocol, port,
+                            name_type, &cli);
        if (!NT_STATUS_IS_OK(status)) {
                return 1;
        }
@@ -5589,8 +5617,9 @@ static int do_host_query(const char *query_host)
 
        status = cli_cm_open(talloc_tos(), NULL,
                             have_ip ? dest_ss_str : query_host,
-                            "IPC$", auth_info, true, smb_encrypt,
-                            max_protocol, port, name_type, &cli);
+                            "IPC$", popt_get_cmdline_auth_info(),
+                            true, smb_encrypt, max_protocol, port,
+                            name_type, &cli);
        if (!NT_STATUS_IS_OK(status)) {
                return 1;
        }
@@ -5622,9 +5651,9 @@ static int do_host_query(const char *query_host)
                cli_shutdown(cli);
                status = cli_cm_open(talloc_tos(), NULL,
                                     have_ip ? dest_ss_str : query_host,
-                                    "IPC$", auth_info, true, smb_encrypt,
-                                    max_protocol, NBT_SMB_PORT, name_type,
-                                    &cli);
+                                    "IPC$", popt_get_cmdline_auth_info(),
+                                    true, smb_encrypt, max_protocol,
+                                    NBT_SMB_PORT, name_type, &cli);
                if (!NT_STATUS_IS_OK(status)) {
                        cli = NULL;
                }
@@ -5658,8 +5687,9 @@ static int do_tar_op(const char *base_directory)
 
                status = cli_cm_open(talloc_tos(), NULL,
                                     have_ip ? dest_ss_str : desthost,
-                                    service, auth_info, true, smb_encrypt,
-                                    max_protocol, port, name_type, &cli);
+                                    service, popt_get_cmdline_auth_info(),
+                                    true, smb_encrypt, max_protocol,
+                                    port, name_type, &cli);
                if (!NT_STATUS_IS_OK(status)) {
             ret = 1;
             goto out;
@@ -5765,6 +5795,7 @@ int main(int argc,char *argv[])
 
        lp_set_cmdline("log level", "1");
 
+       popt_common_credentials_set_ignore_missing_conf();
        popt_common_credentials_set_delay_post();
 
        /* skip argv(0) */
@@ -5793,10 +5824,11 @@ 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(cmdline_auth_info))
+                   && (!get_cmdline_auth_info_got_pass(
+                               popt_get_cmdline_auth_info()))
                    && poptPeekArg(pc)) {
-                       set_cmdline_auth_info_password(cmdline_auth_info,
-                                                      poptGetArg(pc));
+                       set_cmdline_auth_info_password(
+                               popt_get_cmdline_auth_info(), poptGetArg(pc));
                }
 
 
@@ -5895,22 +5927,12 @@ 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(cmdline_auth_info)
+           && !get_cmdline_auth_info_got_pass(popt_get_cmdline_auth_info())
            && poptPeekArg(pc)) {
-               set_cmdline_auth_info_password(cmdline_auth_info,
+               set_cmdline_auth_info_password(popt_get_cmdline_auth_info(),
                                               poptGetArg(pc));
        }
 
-       if ( override_logfile )
-               setup_logging( lp_logfile(talloc_tos()), DEBUG_FILE );
-
-       if (!lp_load_client(get_dyn_CONFIGFILE())) {
-               fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
-                       argv[0], get_dyn_CONFIGFILE());
-       }
-
-       load_interfaces();
-
        if (service_opt && service) {
                size_t len;
 
@@ -5949,8 +5971,8 @@ int main(int argc,char *argv[])
 
        /* Ensure we have a password (or equivalent). */
        popt_common_credentials_post();
-       auth_info = cmdline_auth_info;
-       smb_encrypt = get_cmdline_auth_info_smb_encrypt(auth_info);
+       smb_encrypt = get_cmdline_auth_info_smb_encrypt(
+                       popt_get_cmdline_auth_info());
 
        max_protocol = lp_client_max_protocol();
 
@@ -5978,11 +6000,12 @@ int main(int argc,char *argv[])
 
                rc = do_host_query(qhost);
        } else if (message) {
-               rc = do_message_op(auth_info);
+               rc = do_message_op(popt_get_cmdline_auth_info());
        } else if (process(base_directory)) {
                rc = 1;
        }
 
+       popt_free_cmdline_auth_info();
        TALLOC_FREE(frame);
        return rc;
 }