summaryrefslogtreecommitdiff
path: root/source3/client
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2020-08-18 16:58:19 +0200
committerAndrew Bartlett <abartlet@samba.org>2021-05-20 02:58:36 +0000
commite4474ac0a540c56548b4d15e38f2e234455e19b6 (patch)
tree0a2a6eebb7a205a9ef1574899267e1d6efbdfac9 /source3/client
parentc216e056b229a9e018c23b7c4500a31711bb30aa (diff)
downloadsamba-e4474ac0a540c56548b4d15e38f2e234455e19b6.tar.gz
s3:client: Migrate smbclient to new cmdline option parser
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source3/client')
-rw-r--r--source3/client/client.c190
1 files changed, 74 insertions, 116 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 7c0a3832a41..148a6036f3c 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -23,7 +23,6 @@
#include "includes.h"
#include "system/filesys.h"
-#include "popt_common_cmdline.h"
#include "rpc_client/cli_pipe.h"
#include "client/client_proto.h"
#include "client/clitar_proto.h"
@@ -41,6 +40,7 @@
#include "../libcli/smb/smbXcli_base.h"
#include "lib/util/time_basic.h"
#include "lib/util/string_wrappers.h"
+#include "lib/cmdline/cmdline.h"
#ifndef REGISTER
#define REGISTER 0
@@ -296,8 +296,7 @@ static int do_dskattr(void)
struct cli_state *targetcli = NULL;
char *targetpath = NULL;
TALLOC_CTX *ctx = talloc_tos();
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
status = cli_resolve_path(ctx,
@@ -393,8 +392,7 @@ static int do_cd(const char *new_dir)
uint32_t attributes;
int ret = 1;
TALLOC_CTX *ctx = talloc_stackframe();
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
newdir = talloc_strdup(ctx, new_dir);
@@ -589,6 +587,7 @@ static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *fin
char *targetpath = NULL;
char *afname = NULL;
uint16_t fnum;
+ struct cli_credentials *creds = samba_cmdline_get_creds();
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
@@ -611,8 +610,7 @@ static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *fin
status = cli_resolve_path(
ctx,
"",
- get_cmdline_auth_info_creds(
- popt_get_cmdline_auth_info()),
+ creds,
cli_state,
afname,
&targetcli,
@@ -827,8 +825,7 @@ NTSTATUS do_list(const char *mask,
struct do_list_helper_state state = { .cli = cli, };
static int in_do_list = 0;
TALLOC_CTX *ctx = talloc_tos();
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS ret_status = NT_STATUS_OK;
NTSTATUS status = NT_STATUS_OK;
@@ -1074,8 +1071,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
struct cli_state *targetcli = NULL;
char *targetname = NULL;
char *lname = NULL;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
lname = talloc_strdup(ctx, lname_in);
@@ -1448,8 +1444,7 @@ static bool do_mkdir(const char *name)
TALLOC_CTX *ctx = talloc_tos();
struct cli_state *targetcli;
char *targetname = NULL;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
status = cli_resolve_path(ctx, "",
@@ -1497,7 +1492,6 @@ 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;
@@ -1512,8 +1506,7 @@ static int cmd_mkdir(void)
TALLOC_CTX *ctx = talloc_tos();
char *mask = NULL;
char *buf = NULL;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
mask = talloc_strdup(ctx, client_get_cur_dir());
@@ -1865,8 +1858,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
struct cli_state *targetcli;
char *targetname = NULL;
struct push_state state;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
status = cli_resolve_path(ctx, "",
@@ -1969,7 +1961,6 @@ 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);
}
@@ -2645,8 +2636,7 @@ static int cmd_wdel(void)
uint32_t attribute;
struct cli_state *targetcli;
char *targetname = NULL;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -2699,8 +2689,7 @@ static int cmd_open(void)
char *targetname = NULL;
struct cli_state *targetcli;
uint16_t fnum = (uint16_t)-1;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -2788,8 +2777,7 @@ static int cmd_posix_encrypt(void)
} else {
bool auth_requested = false;
- creds = get_cmdline_auth_info_creds(
- popt_get_cmdline_auth_info());
+ creds = samba_cmdline_get_creds();
auth_requested = cli_credentials_authentication_requested(creds);
if (!auth_requested) {
@@ -2804,8 +2792,13 @@ static int cmd_posix_encrypt(void)
if (!NT_STATUS_IS_OK(status)) {
d_printf("posix_encrypt failed with error %s\n", nt_errstr(status));
} else {
+ bool ok;
+
d_printf("encryption on\n");
- set_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info());
+ ok = cli_credentials_set_smb_encryption(creds,
+ SMB_ENCRYPTION_REQUIRED,
+ CRED_SPECIFIED);
+ SMB_ASSERT(ok);
}
return 0;
@@ -2823,8 +2816,7 @@ static int cmd_posix_open(void)
struct cli_state *targetcli;
mode_t mode;
uint16_t fnum;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -2885,8 +2877,7 @@ static int cmd_posix_mkdir(void)
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -2936,8 +2927,7 @@ static int cmd_posix_unlink(void)
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -2982,8 +2972,7 @@ static int cmd_posix_rmdir(void)
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -3292,8 +3281,7 @@ static int cmd_rmdir(void)
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -3342,8 +3330,7 @@ static int cmd_link(void)
char *buf2 = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -3408,8 +3395,7 @@ static int cmd_readlink(void)
char *targetname = NULL;
char *linkname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
@@ -3468,8 +3454,7 @@ static int cmd_symlink(void)
char *buf = NULL;
char *buf2 = NULL;
struct cli_state *newcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -3529,8 +3514,7 @@ static int cmd_chmod(void)
char *targetname = NULL;
struct cli_state *targetcli;
mode_t mode;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -3697,8 +3681,7 @@ static int cmd_getfacl(void)
size_t num_dir_acls = 0;
size_t expected_buflen;
uint16_t i;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
@@ -3883,8 +3866,7 @@ static int cmd_geteas(void)
NTSTATUS status;
size_t i, num_eas;
struct ea_struct *eas;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
d_printf("geteas filename\n");
@@ -3942,8 +3924,7 @@ static int cmd_setea(void)
char *eavalue = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr, &name, NULL)
@@ -3999,8 +3980,7 @@ static int cmd_stat(void)
SMB_STRUCT_STAT sbuf;
struct tm *lt;
time_t tmp_time;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) {
@@ -4109,8 +4089,7 @@ static int cmd_chown(void)
char *buf, *buf2, *buf3;
struct cli_state *targetcli;
char *targetname = NULL;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -4169,8 +4148,7 @@ static int cmd_rename(void)
struct cli_state *targetcli;
char *targetsrc;
char *targetdest;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
bool replace = false;
@@ -4275,8 +4253,7 @@ static int cmd_scopy(void)
off_t written = 0;
struct scopy_timing st;
int rc = 0;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -4417,8 +4394,7 @@ static int cmd_hardlink(void)
char *buf, *buf2;
struct cli_state *targetcli;
char *targetname;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
@@ -5126,8 +5102,7 @@ static int cmd_show_connect( void )
TALLOC_CTX *ctx = talloc_tos();
struct cli_state *targetcli;
char *targetpath;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
status = cli_resolve_path(ctx, "",
@@ -5387,9 +5362,10 @@ int cmd_iosize(void)
TALLOC_CTX *ctx = talloc_tos();
char *buf;
int iosize;
+ struct cli_credentials *creds = samba_cmdline_get_creds();
bool smb_encrypt =
- get_cmdline_auth_info_smb_encrypt(
- popt_get_cmdline_auth_info());
+ (cli_credentials_get_smb_encryption(creds) ==
+ SMB_ENCRYPTION_REQUIRED);
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
@@ -5653,8 +5629,7 @@ static int process_command_string(const char *cmd_in)
TALLOC_CTX *ctx = talloc_tos();
char *cmd = talloc_strdup(ctx, cmd_in);
int rc = 0;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
if (!cmd) {
return 1;
@@ -5790,8 +5765,7 @@ static char **remote_completion(const char *text, int len)
struct cli_state *targetcli = NULL;
int i;
struct completion_remote info = { NULL, NULL, 1, 0, NULL, 0 };
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
NTSTATUS status;
/* can't have non-static initialisation on Sun CC, so do it
@@ -6109,8 +6083,7 @@ static int process(const char *base_directory)
{
int rc = 0;
NTSTATUS status;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
status = cli_cm_open(talloc_tos(), NULL,
desthost,
@@ -6149,8 +6122,7 @@ static int process(const char *base_directory)
static int do_host_query(const char *query_host)
{
NTSTATUS status;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
status = cli_cm_open(talloc_tos(), NULL,
query_host,
@@ -6226,8 +6198,7 @@ static int do_tar_op(const char *base_directory)
{
struct tar *tar_ctx = tar_get_ctx();
int ret = 0;
- struct cli_credentials *creds =
- get_cmdline_auth_info_creds(popt_get_cmdline_auth_info());
+ struct cli_credentials *creds = samba_cmdline_get_creds();
/* do we already have a connection? */
if (!cli) {
@@ -6267,7 +6238,7 @@ static int do_tar_op(const char *base_directory)
Handle a message operation.
****************************************************************************/
-static int do_message_op(struct user_auth_info *a_info)
+static int do_message_op(struct cli_credentials *creds)
{
NTSTATUS status;
@@ -6288,7 +6259,7 @@ static int do_message_op(struct user_auth_info *a_info)
}
cli_set_timeout(cli, io_timeout*1000);
- send_message(get_cmdline_auth_info_username(a_info));
+ send_message(cli_credentials_get_username(creds));
cli_shutdown(cli);
return 0;
@@ -6312,6 +6283,7 @@ int main(int argc,char *argv[])
bool tar_opt = false;
bool service_opt = false;
struct tar *tar_ctx = tar_get_ctx();
+ bool ok;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -6361,15 +6333,6 @@ int main(int argc,char *argv[])
.argDescrip = "HOST",
},
{
- .longName = "max-protocol",
- .shortName = 'm',
- .argInfo = POPT_ARG_STRING,
- .arg = NULL,
- .val = 'm',
- .descrip = "Set the max protocol level",
- .argDescrip = "LEVEL",
- },
- {
.longName = "tar",
.shortName = 'T',
.argInfo = POPT_ARG_STRING,
@@ -6449,27 +6412,33 @@ int main(int argc,char *argv[])
POPT_COMMON_SAMBA
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
+ POPT_LEGACY_S3
+ POPT_COMMON_VERSION
POPT_TABLEEND
};
TALLOC_CTX *frame = talloc_stackframe();
+ struct cli_credentials *creds = NULL;
if (!client_set_cur_dir("\\")) {
exit(ENOMEM);
}
- /* set default debug level to 1 regardless of what smb.conf sets */
- setup_logging( "smbclient", DEBUG_DEFAULT_STDERR );
smb_init_locale();
+ ok = samba_cmdline_init(frame,
+ SAMBA_CMDLINE_CONFIG_CLIENT,
+ false /* require_smbconf */);
+ if (!ok) {
+ DBG_ERR("Failed to init cmdline parser!\n");
+ exit(ENOMEM);
+ }
lp_set_cmdline("log level", "1");
- popt_common_credentials_set_ignore_missing_conf();
- popt_common_credentials_set_delay_post();
-
/* skip argv(0) */
pc = poptGetContext("smbclient", argc, const_argv, long_options, 0);
- poptSetOtherOptionHelp(pc, "service <password>");
+ poptSetOtherOptionHelp(pc, "[OPTIONS] service <password>");
+ creds = samba_cmdline_get_creds();
while ((opt = poptGetNextOpt(pc)) != -1) {
/*
@@ -6494,12 +6463,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(
- popt_get_cmdline_auth_info()))
- && poptPeekArg(pc)) {
- set_cmdline_auth_info_password(
- popt_get_cmdline_auth_info(), poptGetArg(pc));
+ if (service_opt &&
+ cli_credentials_get_password(creds) == NULL &&
+ poptPeekArg(pc)) {
+ cli_credentials_set_password(creds,
+ poptGetArg(pc),
+ CRED_SPECIFIED);
}
@@ -6527,20 +6496,12 @@ int main(int argc,char *argv[])
print_sockaddr(dest_ss_str, sizeof(dest_ss_str), &dest_ss);
}
break;
- case 'E':
- setup_logging("smbclient", DEBUG_STDERR );
- display_set_stderr();
- break;
-
case 'L':
query_host = talloc_strdup(frame, poptGetOptArg(pc));
if (!query_host) {
exit(ENOMEM);
}
break;
- case 'm':
- lp_set_cmdline("client max protocol", poptGetOptArg(pc));
- break;
case 'T':
/* We must use old option processing for this. Find the
* position of the -T option in the raw argv[]. */
@@ -6597,11 +6558,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(popt_get_cmdline_auth_info())
- && poptPeekArg(pc)) {
- set_cmdline_auth_info_password(popt_get_cmdline_auth_info(),
- poptGetArg(pc));
+ if (service_opt &&
+ cli_credentials_get_password(creds) == NULL &&
+ poptPeekArg(pc)) {
+ cli_credentials_set_password(creds,
+ poptGetArg(pc),
+ CRED_SPECIFIED);
}
if (service_opt && service) {
@@ -6631,13 +6593,10 @@ int main(int argc,char *argv[])
}
poptFreeContext(pc);
- popt_burn_cmdline_password(argc, argv);
+ samba_cmdline_burn(argc, argv);
DEBUG(3,("Client started (version %s).\n", samba_version_string()));
- /* Ensure we have a password (or equivalent). */
- popt_common_credentials_post();
-
if (tar_to_process(tar_ctx)) {
if (cmdstr)
process_command_string(cmdstr);
@@ -6662,12 +6621,11 @@ int main(int argc,char *argv[])
rc = do_host_query(qhost);
} else if (message) {
- rc = do_message_op(popt_get_cmdline_auth_info());
+ rc = do_message_op(creds);
} else if (process(base_directory)) {
rc = 1;
}
- popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return rc;
}