31 #include <linux/utsname.h>
32 #include <linux/slab.h>
40 static bool is_first_ses_reconnect(
struct cifs_ses *ses)
71 int free_vc_found = 0;
83 for (i = ses->
server->srv_count - 1; i < max_vcs; i++) {
92 if (tmp_ses->
vcnum == i) {
105 else if (free_vc_found == 0)
117 static __u32 cifs_ssetup_hdr(
struct cifs_ses *ses, SESSION_SETUP_ANDX *pSMB)
126 pSMB->req.AndXCommand = 0xFF;
131 pSMB->req.VcNumber = get_next_vcnum(ses);
141 if (ses->
server->sec_mode &
164 unicode_oslm_strings(
char **pbcc_area,
const struct nls_table *nls_cp)
166 char *bcc_ptr = *pbcc_area;
172 bcc_ptr += 2 * bytes_ret;
175 bcc_ptr += 2 * bytes_ret;
180 bcc_ptr += 2 * bytes_ret;
183 *pbcc_area = bcc_ptr;
186 static void unicode_domain_string(
char **pbcc_area,
struct cifs_ses *ses,
189 char *bcc_ptr = *pbcc_area;
202 bcc_ptr += 2 * bytes_ret;
205 *pbcc_area = bcc_ptr;
209 static void unicode_ssetup_strings(
char **pbcc_area,
struct cifs_ses *ses,
212 char *bcc_ptr = *pbcc_area;
232 bcc_ptr += 2 * bytes_ret;
235 unicode_domain_string(&bcc_ptr, ses, nls_cp);
236 unicode_oslm_strings(&bcc_ptr, nls_cp);
238 *pbcc_area = bcc_ptr;
241 static void ascii_ssetup_strings(
char **pbcc_area,
struct cifs_ses *ses,
244 char *bcc_ptr = *pbcc_area;
268 strcpy(bcc_ptr,
"Linux version ");
269 bcc_ptr +=
strlen(
"Linux version ");
276 *pbcc_area = bcc_ptr;
280 decode_unicode_ssetup(
char **pbcc_area,
int bleft,
struct cifs_ses *ses,
284 char *
data = *pbcc_area;
286 cFYI(1,
"bleft %d", bleft);
291 len = (UniStrnlen((
wchar_t *) data, bleft / 2) * 2) + 2;
300 len = (UniStrnlen((
wchar_t *) data, bleft / 2) * 2) + 2;
313 static int decode_ascii_ssetup(
char **pbcc_area,
__u16 bleft,
319 char *bcc_ptr = *pbcc_area;
321 cFYI(1,
"decode sessetup ascii. bleft %d", bleft);
333 cFYI(1,
"OS/2 server");
362 cFYI(1,
"ascii: bytes left %d", bleft);
370 unsigned int tioffset;
373 CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr;
375 if (blob_len <
sizeof(CHALLENGE_MESSAGE)) {
376 cERROR(1,
"challenge blob len %d too small", blob_len);
380 if (
memcmp(pblob->Signature,
"NTLMSSP", 8)) {
381 cERROR(1,
"blob signature incorrect %s", pblob->Signature);
385 cERROR(1,
"Incorrect message type %d", pblob->MessageType);
395 tioffset =
le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
396 tilen =
le16_to_cpu(pblob->TargetInfoArray.Length);
397 if (tioffset > blob_len || tioffset + tilen > blob_len) {
398 cERROR(1,
"tioffset + tilen too high %u + %u", tioffset, tilen);
404 cERROR(1,
"Challenge target info allocation failure");
421 NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer;
424 memset(pbuffer, 0,
sizeof(NEGOTIATE_MESSAGE));
432 if (ses->
server->sec_mode &
435 if (!ses->
server->session_estab)
441 sec_blob->WorkstationName.BufferOffset = 0;
442 sec_blob->WorkstationName.Length = 0;
443 sec_blob->WorkstationName.MaximumLength = 0;
446 sec_blob->DomainName.BufferOffset = 0;
447 sec_blob->DomainName.Length = 0;
448 sec_blob->DomainName.MaximumLength = 0;
460 AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer;
471 if (ses->
server->sec_mode &
474 if (!ses->
server->session_estab)
478 tmp = pbuffer +
sizeof(AUTHENTICATE_MESSAGE);
481 sec_blob->LmChallengeResponse.BufferOffset =
483 sec_blob->LmChallengeResponse.Length = 0;
484 sec_blob->LmChallengeResponse.MaximumLength = 0;
486 sec_blob->NtChallengeResponse.BufferOffset =
cpu_to_le32(tmp - pbuffer);
489 cERROR(1,
"Error %d during NTLMSSP authentication", rc);
490 goto setup_ntlmv2_ret;
496 sec_blob->NtChallengeResponse.Length =
498 sec_blob->NtChallengeResponse.MaximumLength =
502 sec_blob->DomainName.BufferOffset =
cpu_to_le32(tmp - pbuffer);
503 sec_blob->DomainName.Length = 0;
504 sec_blob->DomainName.MaximumLength = 0;
511 sec_blob->DomainName.BufferOffset =
cpu_to_le32(tmp - pbuffer);
513 sec_blob->DomainName.MaximumLength =
cpu_to_le16(len);
518 sec_blob->UserName.BufferOffset =
cpu_to_le32(tmp - pbuffer);
519 sec_blob->UserName.Length = 0;
520 sec_blob->UserName.MaximumLength = 0;
527 sec_blob->UserName.BufferOffset =
cpu_to_le32(tmp - pbuffer);
529 sec_blob->UserName.MaximumLength =
cpu_to_le16(len);
533 sec_blob->WorkstationName.BufferOffset =
cpu_to_le32(tmp - pbuffer);
534 sec_blob->WorkstationName.Length = 0;
535 sec_blob->WorkstationName.MaximumLength = 0;
542 sec_blob->SessionKey.BufferOffset =
cpu_to_le32(tmp - pbuffer);
544 sec_blob->SessionKey.MaximumLength =
548 sec_blob->SessionKey.BufferOffset =
cpu_to_le32(tmp - pbuffer);
549 sec_blob->SessionKey.Length = 0;
550 sec_blob->SessionKey.MaximumLength = 0;
554 *buflen = tmp - pbuffer;
567 SESSION_SETUP_ANDX *pSMB;
577 char *ntlmsspblob =
NULL;
582 type = ses->
server->secType;
583 cFYI(1,
"sess setup type %d", type);
593 ssetup_ntlmssp_authenticate:
598 #ifndef CONFIG_CIFS_WEAK_PW_HASH
607 }
else if ((type ==
NTLM) || (type ==
NTLMv2)) {
618 pSMB = (SESSION_SETUP_ANDX *)smb_buf;
620 capabilities = cifs_ssetup_hdr(ses, pSMB);
637 if (str_area ==
NULL) {
649 #ifdef CONFIG_CIFS_WEAK_PW_HASH
666 true :
false, lnm_session_key);
677 cFYI(1,
"Negotiating LANMAN setting up strings");
679 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
681 }
else if (type ==
NTLM) {
682 pSMB->req_no_secext.Capabilities =
cpu_to_le32(capabilities);
683 pSMB->req_no_secext.CaseInsensitivePasswordLength =
685 pSMB->req_no_secext.CaseSensitivePasswordLength =
691 cERROR(1,
"Error %d during NTLM authentication", rc);
705 if (iov[0].iov_len % 2) {
709 unicode_ssetup_strings(&bcc_ptr, ses, nls_cp);
711 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
712 }
else if (type ==
NTLMv2) {
713 pSMB->req_no_secext.Capabilities =
cpu_to_le32(capabilities);
716 pSMB->req_no_secext.CaseInsensitivePasswordLength = 0;
721 cERROR(1,
"Error %d during NTLMv2 authentication", rc);
731 pSMB->req_no_secext.CaseSensitivePasswordLength =
735 if (iov[0].iov_len % 2) {
739 unicode_ssetup_strings(&bcc_ptr, ses, nls_cp);
741 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
743 #ifdef CONFIG_CIFS_UPCALL
747 if (IS_ERR(spnego_key)) {
748 rc = PTR_ERR(spnego_key);
753 msg = spnego_key->payload.
data;
757 cERROR(1,
"incorrect version of cifs.upcall (expected"
766 cERROR(1,
"Kerberos can't allocate (%u bytes) memory",
776 pSMB->req.Capabilities =
cpu_to_le32(capabilities);
779 pSMB->req.SecurityBlobLength =
cpu_to_le16(iov[1].iov_len);
783 if ((iov[0].iov_len + iov[1].iov_len) % 2) {
787 unicode_oslm_strings(&bcc_ptr, nls_cp);
788 unicode_domain_string(&bcc_ptr, ses, nls_cp);
791 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
793 cERROR(1,
"Kerberos negotiated but upcall support disabled!");
799 cERROR(1,
"NTLMSSP requires Unicode support");
804 cFYI(1,
"ntlmssp session setup phase %d", phase);
807 pSMB->req.Capabilities |=
cpu_to_le32(capabilities);
811 pSMB->req.SecurityBlob, ses);
812 iov[1].
iov_len =
sizeof(NEGOTIATE_MESSAGE);
813 iov[1].
iov_base = pSMB->req.SecurityBlob;
814 pSMB->req.SecurityBlobLength =
823 ntlmsspblob = kzalloc(
827 cERROR(1,
"Can't allocate NTLMSSP blob");
833 &blob_len, ses, nls_cp);
838 pSMB->req.SecurityBlobLength =
cpu_to_le16(blob_len);
847 cERROR(1,
"invalid phase %d", phase);
852 if ((iov[0].iov_len + iov[1].iov_len) % 2) {
856 unicode_oslm_strings(&bcc_ptr, nls_cp);
858 cERROR(1,
"secType %d not supported!", type);
870 put_bcc(count, smb_buf);
876 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base;
877 smb_buf = (
struct smb_hdr *)iov[0].iov_base;
883 cERROR(1,
"Unexpected more processing error");
900 cFYI(1,
"Guest login");
905 bytes_remaining = get_bcc(smb_buf);
909 blob_len =
le16_to_cpu(pSMB->resp.SecurityBlobLength);
910 if (blob_len > bytes_remaining) {
911 cERROR(1,
"bad security blob length %d", blob_len);
926 if (bytes_remaining == 0) {
930 if (((
unsigned long) bcc_ptr - (
unsigned long) smb_buf) % 2) {
934 decode_unicode_ssetup(&bcc_ptr, bytes_remaining, ses, nls_cp);
936 rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining,
949 cFYI(1,
"ssetup freeing small buf %p", iov[0].iov_base);
956 goto ssetup_ntlmssp_authenticate;