[PATCH] s3 popt - remove global variables/talloc_autofree_context().
Jeremy Allison
jra at samba.org
Mon May 8 18:24:07 UTC 2017
Cleanup patch that removes use of global cmdline_auth_info
via helper functions, and (in the last patch) removes use
of one more talloc_autofree_context().
Tested by all exising s3 client utility tests :-).
Please review and push if happy !
Jeremy.
-------------- next part --------------
From 3a8b03bbcd44350b2867fc370063ee242e41babe Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 25 Apr 2017 16:32:05 -0700
Subject: [PATCH 1/5] s3: popt: When using a global variable, don't hide it by
helper locals.
That makes it very unclear when you're using a global.
Signed-off-by: Jeremy Allison <jra at samba.org>
---
source3/lib/popt_common.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 3589a4fbd2b..538c848d235 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -237,17 +237,15 @@ void popt_common_credentials_set_delay_post(void)
void popt_common_credentials_post(void)
{
- struct user_auth_info *auth_info = cmdline_auth_info;
-
- if (get_cmdline_auth_info_use_machine_account(auth_info) &&
- !set_cmdline_auth_info_machine_account_creds(auth_info))
+ if (get_cmdline_auth_info_use_machine_account(cmdline_auth_info) &&
+ !set_cmdline_auth_info_machine_account_creds(cmdline_auth_info))
{
fprintf(stderr,
"Failed to use machine account credentials\n");
exit(1);
}
- set_cmdline_auth_info_getpass(auth_info);
+ set_cmdline_auth_info_getpass(cmdline_auth_info);
}
static void popt_common_credentials_callback(poptContext con,
@@ -255,10 +253,9 @@ static void popt_common_credentials_callback(poptContext con,
const struct poptOption *opt,
const char *arg, const void *data)
{
- struct user_auth_info *auth_info = cmdline_auth_info;
-
if (reason == POPT_CALLBACK_REASON_PRE) {
- auth_info = user_auth_info_init(talloc_autofree_context());
+ struct user_auth_info *auth_info =
+ user_auth_info_init(talloc_autofree_context());
if (auth_info == NULL) {
fprintf(stderr, "user_auth_info_init() failed\n");
exit(1);
@@ -287,7 +284,7 @@ static void popt_common_credentials_callback(poptContext con,
load_interfaces();
- set_cmdline_auth_info_guess(auth_info);
+ set_cmdline_auth_info_guess(cmdline_auth_info);
if (popt_common_credentials_delay_post) {
return;
@@ -299,11 +296,11 @@ static void popt_common_credentials_callback(poptContext con,
switch(opt->val) {
case 'U':
- set_cmdline_auth_info_username(auth_info, arg);
+ set_cmdline_auth_info_username(cmdline_auth_info, arg);
break;
case 'A':
- set_cmdline_auth_info_from_file(auth_info, arg);
+ set_cmdline_auth_info_from_file(cmdline_auth_info, arg);
break;
case 'k':
@@ -311,30 +308,31 @@ static void popt_common_credentials_callback(poptContext con,
d_printf("No kerberos support compiled in\n");
exit(1);
#else
- set_cmdline_auth_info_use_krb5_ticket(auth_info);
+ set_cmdline_auth_info_use_krb5_ticket(cmdline_auth_info);
#endif
break;
case 'S':
- if (!set_cmdline_auth_info_signing_state(auth_info, arg)) {
+ if (!set_cmdline_auth_info_signing_state(cmdline_auth_info,
+ arg)) {
fprintf(stderr, "Unknown signing option %s\n", arg );
exit(1);
}
break;
case 'P':
- set_cmdline_auth_info_use_machine_account(auth_info);
+ set_cmdline_auth_info_use_machine_account(cmdline_auth_info);
break;
case 'N':
- set_cmdline_auth_info_password(auth_info, "");
+ set_cmdline_auth_info_password(cmdline_auth_info, "");
break;
case 'e':
- set_cmdline_auth_info_smb_encrypt(auth_info);
+ set_cmdline_auth_info_smb_encrypt(cmdline_auth_info);
break;
case 'C':
- set_cmdline_auth_info_use_ccache(auth_info, true);
+ set_cmdline_auth_info_use_ccache(cmdline_auth_info, true);
break;
case 'H':
- set_cmdline_auth_info_use_pw_nt_hash(auth_info, true);
+ set_cmdline_auth_info_use_pw_nt_hash(cmdline_auth_info, true);
break;
}
}
--
2.13.0.rc0.306.g87b477812d-goog
From 1b0fcbf715287e0017d71a5dae48ff27fce664f8 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 25 Apr 2017 17:01:25 -0700
Subject: [PATCH 2/5] s3: popt: Add utility functions
popt_get_cmdline_auth_info(), popt_free_cmdline_auth_info().
Leave the global cmdline_auth_info still exposed, we will make it static
once the users have been converted to the utility functions.
Signed-off-by: Jeremy Allison <jra at samba.org>
---
source3/include/popt_common.h | 2 ++
source3/lib/popt_common.c | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/source3/include/popt_common.h b/source3/include/popt_common.h
index 2abfa04095c..f859db40449 100644
--- a/source3/include/popt_common.h
+++ b/source3/include/popt_common.h
@@ -49,6 +49,8 @@ extern const struct poptOption popt_common_dynconfig[];
#define POPT_COMMON_OPTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_option, 0, "Common samba commandline config:", NULL },
extern struct user_auth_info *cmdline_auth_info;
+struct user_auth_info *popt_get_cmdline_auth_info(void);
+void popt_free_cmdline_auth_info(void);
void popt_common_credentials_set_ignore_missing_conf(void);
void popt_common_credentials_set_delay_post(void);
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 538c848d235..56da91c0600 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -222,6 +222,16 @@ struct poptOption popt_common_option[] = {
*/
struct user_auth_info *cmdline_auth_info;
+
+struct user_auth_info *popt_get_cmdline_auth_info(void)
+{
+ return cmdline_auth_info;
+}
+void popt_free_cmdline_auth_info(void)
+{
+ TALLOC_FREE(cmdline_auth_info);
+}
+
static bool popt_common_credentials_ignore_missing_conf;
static bool popt_common_credentials_delay_post;
--
2.13.0.rc0.306.g87b477812d-goog
From 95fcc1f3c5eacc3fb44aa8627053e95034ec1c5e Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 25 Apr 2017 17:03:10 -0700
Subject: [PATCH 3/5] s3: client tools. Remove direct access to struct
user_auth_info *cmdline_auth_info.
Only access through utility functions. Remove all the local pointer aliases
that were just being set to cmdline_auth_info in the client tools.
Signed-off-by: Jeremy Allison <jra at samba.org>
---
examples/fuse/smb2mount.c | 2 +-
source3/client/client.c | 171 +++++++++++++++++++++-------------------
source3/include/popt_common.h | 1 -
source3/lib/popt_common.c | 2 +-
source3/rpcclient/cmd_spoolss.c | 22 +++---
source3/rpcclient/rpcclient.c | 43 ++++++----
source3/utils/smbcacls.c | 2 +-
source3/utils/smbcquotas.c | 24 +++---
source3/utils/smbtree.c | 2 +-
9 files changed, 145 insertions(+), 124 deletions(-)
diff --git a/examples/fuse/smb2mount.c b/examples/fuse/smb2mount.c
index 4ed985f53c4..67667bea6d0 100644
--- a/examples/fuse/smb2mount.c
+++ b/examples/fuse/smb2mount.c
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
*share = 0;
share++;
- cli = connect_one(cmdline_auth_info, server, port, share);
+ cli = connect_one(popt_get_cmdline_auth_info(), server, port, share);
if (cli == NULL) {
return -1;
}
diff --git a/source3/client/client.c b/source3/client/client.c
index d2ebea0ad39..532e2884426 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -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;
@@ -1572,8 +1570,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 +1880,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;
@@ -2463,8 +2462,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 +2502,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;
@@ -2570,7 +2569,8 @@ static int cmd_posix_encrypt(void)
} else {
bool auth_requested = false;
- creds = get_cmdline_auth_info_creds(auth_info);
+ creds = get_cmdline_auth_info_creds(
+ popt_get_cmdline_auth_info());
auth_requested = cli_credentials_authentication_requested(creds);
if (!auth_requested) {
@@ -2624,8 +2624,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;
@@ -2679,8 +2679,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;
@@ -2717,8 +2717,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;
@@ -2756,8 +2756,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;
@@ -3058,8 +3058,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;
@@ -3109,8 +3109,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;
@@ -3156,8 +3156,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;
@@ -3210,8 +3210,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;
@@ -3262,8 +3263,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;
@@ -3419,8 +3420,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;
@@ -3587,8 +3588,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;
@@ -3644,8 +3645,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;
@@ -3690,8 +3691,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;
@@ -3798,8 +3799,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;
@@ -3862,15 +3863,15 @@ static int cmd_rename(void)
replace = true;
}
- 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("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;
@@ -3950,15 +3951,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;
@@ -4080,8 +4081,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;
@@ -4738,7 +4739,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)) {
@@ -5148,7 +5149,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);
@@ -5328,8 +5329,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;
}
@@ -5577,8 +5578,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;
}
@@ -5613,8 +5615,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;
}
@@ -5646,9 +5649,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;
}
@@ -5682,8 +5685,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;
@@ -5818,10 +5822,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));
}
@@ -5920,9 +5925,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(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));
}
@@ -5964,8 +5969,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();
@@ -5993,7 +5998,7 @@ 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;
}
diff --git a/source3/include/popt_common.h b/source3/include/popt_common.h
index f859db40449..a8c778473e9 100644
--- a/source3/include/popt_common.h
+++ b/source3/include/popt_common.h
@@ -48,7 +48,6 @@ extern const struct poptOption popt_common_dynconfig[];
#define POPT_COMMON_DEBUGLEVEL { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debuglevel, 0, "Common samba debugging:", NULL },
#define POPT_COMMON_OPTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_option, 0, "Common samba commandline config:", NULL },
-extern struct user_auth_info *cmdline_auth_info;
struct user_auth_info *popt_get_cmdline_auth_info(void);
void popt_free_cmdline_auth_info(void);
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 56da91c0600..004296801b9 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -221,7 +221,7 @@ struct poptOption popt_common_option[] = {
* -C --use-ccache
*/
-struct user_auth_info *cmdline_auth_info;
+static struct user_auth_info *cmdline_auth_info;
struct user_auth_info *popt_get_cmdline_auth_info(void)
{
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 00dc2e0e817..73af42fa0c3 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -33,6 +33,7 @@
#include "../libcli/security/security_descriptor.h"
#include "../libcli/registry/util_reg.h"
#include "libsmb/libsmb.h"
+#include "popt_common.h"
#define RPCCLIENT_PRINTERNAME(_printername, _cli, _arg) \
{ \
@@ -3495,8 +3496,6 @@ done:
/****************************************************************************
****************************************************************************/
-extern struct user_auth_info *rpcclient_auth_info;
-
static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx, int argc,
const char **argv)
@@ -3519,13 +3518,18 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
/* first get the connection to the remote server */
nt_status = cli_full_connection(&cli_server2, lp_netbios_name(), argv[2],
- NULL, 0,
- "IPC$", "IPC",
- get_cmdline_auth_info_username(rpcclient_auth_info),
- lp_workgroup(),
- get_cmdline_auth_info_password(rpcclient_auth_info),
- get_cmdline_auth_info_use_kerberos(rpcclient_auth_info) ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
- get_cmdline_auth_info_signing_state(rpcclient_auth_info));
+ NULL, 0,
+ "IPC$", "IPC",
+ get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()),
+ lp_workgroup(),
+ get_cmdline_auth_info_password(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_use_kerberos(
+ popt_get_cmdline_auth_info()) ?
+ CLI_FULL_CONNECTION_USE_KERBEROS : 0,
+ get_cmdline_auth_info_signing_state(
+ popt_get_cmdline_auth_info()));
if ( !NT_STATUS_IS_OK(nt_status) )
return WERR_GEN_FAILURE;
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 6c851653a0e..1d352033479 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -50,7 +50,6 @@ static unsigned int timeout = 0;
static enum dcerpc_transport_t default_transport = NCACN_NP;
struct messaging_context *rpcclient_msg_ctx;
-struct user_auth_info *rpcclient_auth_info;
struct cli_state *rpcclient_cli_state;
struct netlogon_creds_cli_context *rpcclient_netlogon_creds;
static const char *rpcclient_netlogon_domain;
@@ -1013,7 +1012,6 @@ out_free:
poptFreeContext(pc);
popt_burn_cmdline_password(argc, argv);
- rpcclient_auth_info = cmdline_auth_info;
nt_status = messaging_init_client(talloc_autofree_context(),
samba_tevent_context_init(talloc_autofree_context()),
@@ -1120,7 +1118,8 @@ out_free:
}
}
- signing_state = get_cmdline_auth_info_signing_state(rpcclient_auth_info);
+ signing_state = get_cmdline_auth_info_signing_state(
+ popt_get_cmdline_auth_info());
switch (signing_state) {
case SMB_SIGNING_OFF:
lp_set_cmdline("client ipc signing", "no");
@@ -1130,18 +1129,20 @@ out_free:
break;
}
- if (get_cmdline_auth_info_use_kerberos(rpcclient_auth_info)) {
+ if (get_cmdline_auth_info_use_kerberos(popt_get_cmdline_auth_info())) {
flags |= CLI_FULL_CONNECTION_USE_KERBEROS |
CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
}
- if (get_cmdline_auth_info_use_ccache(rpcclient_auth_info)) {
+ if (get_cmdline_auth_info_use_ccache(popt_get_cmdline_auth_info())) {
flags |= CLI_FULL_CONNECTION_USE_CCACHE;
}
- if (get_cmdline_auth_info_use_pw_nt_hash(rpcclient_auth_info)) {
+ if (get_cmdline_auth_info_use_pw_nt_hash(
+ popt_get_cmdline_auth_info())) {
flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
}
- rpcclient_netlogon_domain = get_cmdline_auth_info_domain(rpcclient_auth_info);
+ rpcclient_netlogon_domain = get_cmdline_auth_info_domain(
+ popt_get_cmdline_auth_info());
if (rpcclient_netlogon_domain == NULL ||
rpcclient_netlogon_domain[0] == '\0')
{
@@ -1151,9 +1152,12 @@ out_free:
nt_status = cli_full_connection(&cli, lp_netbios_name(), host,
opt_ipaddr ? &server_ss : NULL, opt_port,
"IPC$", "IPC",
- get_cmdline_auth_info_username(rpcclient_auth_info),
- get_cmdline_auth_info_domain(rpcclient_auth_info),
- get_cmdline_auth_info_password(rpcclient_auth_info),
+ get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_domain(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_password(
+ popt_get_cmdline_auth_info()),
flags,
SMB_SIGNING_IPC_DEFAULT);
@@ -1163,11 +1167,14 @@ out_free:
goto done;
}
- if (get_cmdline_auth_info_smb_encrypt(rpcclient_auth_info)) {
+ if (get_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info())) {
nt_status = cli_cm_force_encryption(cli,
- get_cmdline_auth_info_username(rpcclient_auth_info),
- get_cmdline_auth_info_password(rpcclient_auth_info),
- get_cmdline_auth_info_domain(rpcclient_auth_info),
+ get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_password(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_domain(
+ popt_get_cmdline_auth_info()),
"IPC$");
if (!NT_STATUS_IS_OK(nt_status)) {
result = 1;
@@ -1205,8 +1212,9 @@ out_free:
result = 0;
while((cmd=next_command(&p)) != NULL) {
- NTSTATUS cmd_result = process_cmd(rpcclient_auth_info, cli,
- binding, cmd);
+ NTSTATUS cmd_result = process_cmd(
+ popt_get_cmdline_auth_info(),
+ cli, binding, cmd);
SAFE_FREE(cmd);
result = NT_STATUS_IS_ERR(cmd_result);
}
@@ -1227,7 +1235,8 @@ out_free:
}
if (line[0] != '\n')
- process_cmd(rpcclient_auth_info, cli, binding, line);
+ process_cmd(popt_get_cmdline_auth_info(), cli,
+ binding, line);
SAFE_FREE(line);
}
diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index 255ff9729b7..48a6229fe98 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -920,7 +920,7 @@ int main(int argc, char *argv[])
share++;
if (!test_args) {
- cli = connect_one(cmdline_auth_info, server, share);
+ cli = connect_one(popt_get_cmdline_auth_info(), server, share);
if (!cli) {
exit(EXIT_FAILED);
}
diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
index a1cf70a1935..8c888b34e36 100644
--- a/source3/utils/smbcquotas.c
+++ b/source3/utils/smbcquotas.c
@@ -44,7 +44,6 @@ static struct cli_state *cli_ipc;
static struct rpc_pipe_client *global_pipe_hnd;
static struct policy_handle pol;
static bool got_policy_hnd;
-static struct user_auth_info *smbcquotas_auth_info;
static struct cli_state *connect_one(const char *share);
@@ -523,7 +522,7 @@ static struct cli_state *connect_one(const char *share)
NTSTATUS nt_status;
uint32_t flags = 0;
- if (get_cmdline_auth_info_use_kerberos(smbcquotas_auth_info)) {
+ if (get_cmdline_auth_info_use_kerberos(popt_get_cmdline_auth_info())) {
flags |= CLI_FULL_CONNECTION_USE_KERBEROS |
CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS;
@@ -532,20 +531,25 @@ static struct cli_state *connect_one(const char *share)
nt_status = cli_full_connection(&c, lp_netbios_name(), server,
NULL, 0,
share, "?????",
- get_cmdline_auth_info_username(smbcquotas_auth_info),
+ get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()),
lp_workgroup(),
- get_cmdline_auth_info_password(smbcquotas_auth_info),
+ get_cmdline_auth_info_password(
+ popt_get_cmdline_auth_info()),
flags,
- get_cmdline_auth_info_signing_state(smbcquotas_auth_info));
+ get_cmdline_auth_info_signing_state(
+ popt_get_cmdline_auth_info()));
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
return NULL;
}
- if (get_cmdline_auth_info_smb_encrypt(smbcquotas_auth_info)) {
+ if (get_cmdline_auth_info_smb_encrypt(popt_get_cmdline_auth_info())) {
nt_status = cli_cm_force_encryption(c,
- get_cmdline_auth_info_username(smbcquotas_auth_info),
- get_cmdline_auth_info_password(smbcquotas_auth_info),
+ get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()),
+ get_cmdline_auth_info_password(
+ popt_get_cmdline_auth_info()),
lp_workgroup(),
share);
if (!NT_STATUS_IS_OK(nt_status)) {
@@ -675,10 +679,10 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
if (todo == 0)
todo = USER_QUOTA;
- smbcquotas_auth_info = cmdline_auth_info;
if (!fix_user) {
username_str = talloc_strdup(
- frame, get_cmdline_auth_info_username(smbcquotas_auth_info));
+ frame, get_cmdline_auth_info_username(
+ popt_get_cmdline_auth_info()));
if (!username_str) {
exit(EXIT_PARSE_ERROR);
}
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index ba7b3182b64..f1890edcfad 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -317,7 +317,7 @@ int main(int argc, char *argv[])
/* Now do our stuff */
- if (!print_tree(cmdline_auth_info)) {
+ if (!print_tree(popt_get_cmdline_auth_info())) {
TALLOC_FREE(frame);
return 1;
}
--
2.13.0.rc0.306.g87b477812d-goog
From fc6a652fa2bf3380922022e440080fee1804c1a0 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 25 Apr 2017 17:08:30 -0700
Subject: [PATCH 4/5] s3: client tools: Call popt_free_cmdline_auth_info() on
all normal exits.
Signed-off-by: Jeremy Allison <jra at samba.org>
---
examples/fuse/smb2mount.c | 1 +
source3/client/client.c | 3 +++
source3/rpcclient/rpcclient.c | 1 +
source3/utils/smbcacls.c | 2 ++
source3/utils/smbcquotas.c | 2 ++
source3/utils/smbtree.c | 1 +
6 files changed, 10 insertions(+)
diff --git a/examples/fuse/smb2mount.c b/examples/fuse/smb2mount.c
index 67667bea6d0..816b0b597ad 100644
--- a/examples/fuse/smb2mount.c
+++ b/examples/fuse/smb2mount.c
@@ -154,6 +154,7 @@ int main(int argc, char *argv[])
return -1;
}
+ popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return 0;
}
diff --git a/source3/client/client.c b/source3/client/client.c
index 532e2884426..64647365dc4 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -1525,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;
@@ -1983,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);
}
@@ -6003,6 +6005,7 @@ int main(int argc,char *argv[])
rc = 1;
}
+ popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return rc;
}
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 1d352033479..be7769672c0 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -1245,6 +1245,7 @@ done:
if (cli != NULL) {
cli_shutdown(cli);
}
+ popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return result;
}
diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index 48a6229fe98..914603d8564 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -925,6 +925,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILED);
}
} else {
+ popt_free_cmdline_auth_info();
exit(0);
}
@@ -950,6 +951,7 @@ int main(int argc, char *argv[])
result = cacl_dump(cli, filename, numeric);
}
+ popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return result;
diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
index 8c888b34e36..031862f52a1 100644
--- a/source3/utils/smbcquotas.c
+++ b/source3/utils/smbcquotas.c
@@ -732,6 +732,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
exit(EXIT_FAILED);
}
} else {
+ popt_free_cmdline_auth_info();
exit(EXIT_OK);
}
@@ -756,6 +757,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
break;
}
+ popt_free_cmdline_auth_info();
talloc_free(frame);
return result;
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index f1890edcfad..fb0c130d350 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -322,6 +322,7 @@ int main(int argc, char *argv[])
return 1;
}
+ popt_free_cmdline_auth_info();
TALLOC_FREE(frame);
return 0;
}
--
2.13.0.rc0.306.g87b477812d-goog
From 034d433f91ef57cfea234377a62f76d55497459f Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 25 Apr 2017 17:09:18 -0700
Subject: [PATCH 5/5] s3: popt: Change to NULL from talloc_autofree_context()
now we correctly free on exit.
Signed-off-by: Jeremy Allison <jra at samba.org>
---
source3/lib/popt_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c
index 004296801b9..1c1e3d7c9d4 100644
--- a/source3/lib/popt_common.c
+++ b/source3/lib/popt_common.c
@@ -265,7 +265,7 @@ static void popt_common_credentials_callback(poptContext con,
{
if (reason == POPT_CALLBACK_REASON_PRE) {
struct user_auth_info *auth_info =
- user_auth_info_init(talloc_autofree_context());
+ user_auth_info_init(NULL);
if (auth_info == NULL) {
fprintf(stderr, "user_auth_info_init() failed\n");
exit(1);
--
2.13.0.rc0.306.g87b477812d-goog
More information about the samba-technical
mailing list