[PATCH] smbclient: Fix connecting to a Windows share with cached credentials.
Andreas Schneider
asn at samba.org
Thu Nov 13 07:55:11 MST 2014
BUG: https://bugzilla.samba.org/show_bug.cgi?id=10279
The first thing it does is not requiring a password if --use-ccahe is
specified. The second part is correctly setting up the netbios domain
name. Else the connection will be aborted with ENOMEM.
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source3/lib/util_cmdline.c | 3 ++-
source3/libsmb/ntlmssp.c | 26 +++++++++++++++++++++++---
source3/script/tests/test_smbclient_s3.sh | 4 ++--
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/source3/lib/util_cmdline.c b/source3/lib/util_cmdline.c
index d15f325..80c3ecd 100644
--- a/source3/lib/util_cmdline.c
+++ b/source3/lib/util_cmdline.c
@@ -251,7 +251,8 @@ void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
TALLOC_CTX *frame;
if (get_cmdline_auth_info_got_pass(auth_info) ||
- get_cmdline_auth_info_use_kerberos(auth_info)) {
+ get_cmdline_auth_info_use_ccache(auth_info) ||
+ get_cmdline_auth_info_use_kerberos(auth_info)) {
/* Already got one... */
return;
}
diff --git a/source3/libsmb/ntlmssp.c b/source3/libsmb/ntlmssp.c
index e8c9ebf..218e1b3 100644
--- a/source3/libsmb/ntlmssp.c
+++ b/source3/libsmb/ntlmssp.c
@@ -374,6 +374,7 @@ static NTSTATUS ntlmssp3_client_challenge(struct ntlmssp_state *ntlmssp_state,
bool anon = ntlmssp_is_anonymous(ntlmssp_state);
if (!anon && ntlmssp_state->use_ccache) {
+ struct wbcDomainControllerInfo *dc_info = NULL;
struct wbcCredentialCacheParams params;
struct wbcCredentialCacheInfo *info = NULL;
struct wbcAuthErrorInfo *error = NULL;
@@ -383,6 +384,22 @@ static NTSTATUS ntlmssp3_client_challenge(struct ntlmssp_state *ntlmssp_state,
wbcErr wbc_status;
int i;
+ if (ntlmssp_state->server.netbios_domain == NULL ||
+ ntlmssp_state->server.netbios_domain[0] == '\0') {
+ ntlmssp_state->server.netbios_domain = ntlmssp_state->domain;
+
+ wbc_status = wbcLookupDomainController(ntlmssp_state->domain, 0, &dc_info);
+ if (WBC_ERROR_IS_OK(wbc_status)) {
+ ntlmssp_state->server.netbios_domain =
+ talloc_strdup(ntlmssp_state,
+ dc_info->dc_name);
+ wbcFreeMemory(dc_info);
+ }
+ if (ntlmssp_state->server.netbios_domain == NULL) {
+ goto noccache;
+ }
+ }
+
params.account_name = ntlmssp_state->user;
params.domain_name = ntlmssp_state->domain;
params.level = WBC_CREDENTIAL_CACHE_LEVEL_NTLMSSP;
@@ -413,9 +430,12 @@ static NTSTATUS ntlmssp3_client_challenge(struct ntlmssp_state *ntlmssp_state,
goto noccache;
}
- *next_request = data_blob(wbc_next->data, wbc_next->length);
- ntlmssp_state->session_key = data_blob(
- wbc_session_key->data, wbc_session_key->length);
+ *next_request = data_blob_talloc(ntlmssp_state,
+ wbc_next->data,
+ wbc_next->length);
+ ntlmssp_state->session_key = data_blob_talloc(ntlmssp_state,
+ wbc_session_key->data,
+ wbc_session_key->length);
wbcFreeMemory(info);
goto done;
diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh
index 67ac94a..f6f3705 100755
--- a/source3/script/tests/test_smbclient_s3.sh
+++ b/source3/script/tests/test_smbclient_s3.sh
@@ -602,7 +602,7 @@ test_ccache_access()
return
fi
- $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
+ $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
-c quit 2>&1
ret=$?
@@ -621,7 +621,7 @@ test_ccache_access()
return
fi
- $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
+ $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
-c quit 2>&1
ret=$?
--
2.1.2
More information about the samba-technical
mailing list