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)
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)) {
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);
/* 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));
}
} 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);
}
}
- 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;
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;
static int cmd_quit(void)
{
cli_shutdown(cli);
+ popt_free_cmdline_auth_info();
exit(0);
/* NOTREACHED */
return 0;
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;
}
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;
if (f == stdin) {
cli_shutdown(cli);
+ popt_free_cmdline_auth_info();
exit(rc);
}
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;
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;
{
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 {
}
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;
}
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
}
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),
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;
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;
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)) {
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);
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;
}
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;
}
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;
}
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;
}
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;
lp_set_cmdline("log level", "1");
+ popt_common_credentials_set_ignore_missing_conf();
popt_common_credentials_set_delay_post();
/* skip argv(0) */
/* 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));
}
/* 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;
/* 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();
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;
}