fs/cifs: correctly to anonymous authentication for the NTLM(v2) authentication
[pandora-kernel.git] / fs / cifs / sess.c
index e8bc77d..8dbfa3e 100644 (file)
@@ -655,23 +655,25 @@ ssetup_ntlmssp_authenticate:
 
                pSMB->req.hdr.Flags2 &= ~SMBFLG2_UNICODE;
 
-               /* no capabilities flags in old lanman negotiation */
-
-               pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE);
-
-               /* Calculate hash with password and copy into bcc_ptr.
-                * Encryption Key (stored as in cryptkey) gets used if the
-                * security mode bit in Negottiate Protocol response states
-                * to use challenge/response method (i.e. Password bit is 1).
-                */
-
-               rc = calc_lanman_hash(ses->password, ses->server->cryptkey,
-                                ses->server->sec_mode & SECMODE_PW_ENCRYPT ?
-                                       true : false, lnm_session_key);
-
+               if (ses->user_name != NULL) {
+                       /* no capabilities flags in old lanman negotiation */
+                       pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE);
+
+                       /* Calculate hash with password and copy into bcc_ptr.
+                        * Encryption Key (stored as in cryptkey) gets used if the
+                        * security mode bit in Negottiate Protocol response states
+                        * to use challenge/response method (i.e. Password bit is 1).
+                        */
+                       rc = calc_lanman_hash(ses->password, ses->server->cryptkey,
+                                             ses->server->sec_mode & SECMODE_PW_ENCRYPT ?
+                                             true : false, lnm_session_key);
+
+                       memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_AUTH_RESP_SIZE);
+                       bcc_ptr += CIFS_AUTH_RESP_SIZE;
+               } else {
+                       pSMB->old_req.PasswordLength = 0;
+               }
                ses->flags |= CIFS_SES_LANMAN;
-               memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_AUTH_RESP_SIZE);
-               bcc_ptr += CIFS_AUTH_RESP_SIZE;
 
                /* can not sign if LANMAN negotiated so no need
                to calculate signing key? but what if server
@@ -684,26 +686,32 @@ ssetup_ntlmssp_authenticate:
 #endif
        } else if (type == NTLM) {
                pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities);
-               pSMB->req_no_secext.CaseInsensitivePasswordLength =
-                       cpu_to_le16(CIFS_AUTH_RESP_SIZE);
-               pSMB->req_no_secext.CaseSensitivePasswordLength =
-                       cpu_to_le16(CIFS_AUTH_RESP_SIZE);
+               if (ses->user_name != NULL) {
+                       pSMB->req_no_secext.CaseInsensitivePasswordLength =
+                                       cpu_to_le16(CIFS_AUTH_RESP_SIZE);
+                       pSMB->req_no_secext.CaseSensitivePasswordLength =
+                                       cpu_to_le16(CIFS_AUTH_RESP_SIZE);
+
+                       /* calculate ntlm response and session key */
+                       rc = setup_ntlm_response(ses, nls_cp);
+                       if (rc) {
+                               cERROR(1, "Error %d during NTLM authentication",
+                                                rc);
+                               goto ssetup_exit;
+                       }
 
-               /* calculate ntlm response and session key */
-               rc = setup_ntlm_response(ses, nls_cp);
-               if (rc) {
-                       cERROR(1, "Error %d during NTLM authentication", rc);
-                       goto ssetup_exit;
+                       /* copy ntlm response */
+                       memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
+                                       CIFS_AUTH_RESP_SIZE);
+                       bcc_ptr += CIFS_AUTH_RESP_SIZE;
+                       memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
+                                       CIFS_AUTH_RESP_SIZE);
+                       bcc_ptr += CIFS_AUTH_RESP_SIZE;
+               } else {
+                       pSMB->req_no_secext.CaseInsensitivePasswordLength = 0;
+                       pSMB->req_no_secext.CaseSensitivePasswordLength = 0;
                }
 
-               /* copy ntlm response */
-               memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
-                               CIFS_AUTH_RESP_SIZE);
-               bcc_ptr += CIFS_AUTH_RESP_SIZE;
-               memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
-                               CIFS_AUTH_RESP_SIZE);
-               bcc_ptr += CIFS_AUTH_RESP_SIZE;
-
                if (ses->capabilities & CAP_UNICODE) {
                        /* unicode strings must be word aligned */
                        if (iov[0].iov_len % 2) {
@@ -719,21 +727,26 @@ ssetup_ntlmssp_authenticate:
                /* LM2 password would be here if we supported it */
                pSMB->req_no_secext.CaseInsensitivePasswordLength = 0;
 
-               /* calculate nlmv2 response and session key */
-               rc = setup_ntlmv2_rsp(ses, nls_cp);
-               if (rc) {
-                       cERROR(1, "Error %d during NTLMv2 authentication", rc);
-                       goto ssetup_exit;
-               }
-               memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
-                               ses->auth_key.len - CIFS_SESS_KEY_SIZE);
-               bcc_ptr += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
+               if (ses->user_name != NULL) {
+                       /* calculate nlmv2 response and session key */
+                       rc = setup_ntlmv2_rsp(ses, nls_cp);
+                       if (rc) {
+                               cERROR(1, "Error %d during NTLMv2 authentication", rc);
+                               goto ssetup_exit;
+                       }
 
-               /* set case sensitive password length after tilen may get
-                * assigned, tilen is 0 otherwise.
-                */
-               pSMB->req_no_secext.CaseSensitivePasswordLength =
-                       cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+                       memcpy(bcc_ptr, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
+                                       ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+                       bcc_ptr += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
+
+                       /* set case sensitive password length after tilen may get
+                        * assigned, tilen is 0 otherwise.
+                        */
+                       pSMB->req_no_secext.CaseSensitivePasswordLength =
+                               cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+               } else {
+                       pSMB->req_no_secext.CaseSensitivePasswordLength = 0;
+               }
 
                if (ses->capabilities & CAP_UNICODE) {
                        if (iov[0].iov_len % 2) {