From 2674df4cc0e124d74eb9d764c29a07c9c84b94d6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 14 Apr 2022 15:36:51 +0200 Subject: [PATCH] s3:libsmb: let cli_tree_connect_creds() only call cli_credentials_get_password() if needed Only legacy protocols need a password for share level authentication, so avoid triggering the password prompt for the common case. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15018 Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider Autobuild-User(master): Stefan Metzmacher Autobuild-Date(master): Tue Apr 23 15:21:38 UTC 2024 on atb-devel-224 --- source3/libsmb/cliconnect.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index d42f08fbb1a..169960282a4 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2424,9 +2424,25 @@ NTSTATUS cli_tree_connect_creds(struct cli_state *cli, const char *share, const char *dev, struct cli_credentials *creds) { + bool need_pass = false; const char *pw = NULL; - if (creds != NULL) { + /* + * We should work out if the protocol + * will make use of a password for share level + * authentication before we may cause + * the password prompt to be called. + */ + if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) { + uint16_t sec_mode = smb1cli_conn_server_security_mode(cli->conn); + + /* in user level security don't send a password now */ + if (!(sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) { + need_pass = true; + } + } + + if (need_pass && creds != NULL) { pw = cli_credentials_get_password(creds); } -- 2.34.1