]> Pileus Git - ~andy/linux/blobdiff - fs/cifs/smb2pdu.c
Merge tag 'for_3.7-fixes-pm' of git://git.kernel.org/pub/scm/linux/kernel/git/khilman...
[~andy/linux] / fs / cifs / smb2pdu.c
index a7db95f4760cd39c4dd5130ea2b0b3ba174ae6f3..cf33622cdac841c7108d76043cf70ca7fab252e7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   fs/cifs/smb2pdu.c
  *
- *   Copyright (C) International Business Machines  Corp., 2009, 2011
+ *   Copyright (C) International Business Machines  Corp., 2009, 2012
  *                 Etersoft, 2012
  *   Author(s): Steve French (sfrench@us.ibm.com)
  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
@@ -304,24 +304,6 @@ free_rsp_buf(int resp_buftype, void *rsp)
                cifs_buf_release(rsp);
 }
 
-#define SMB2_NUM_PROT 2
-
-#define SMB2_PROT   0
-#define SMB21_PROT  1
-#define BAD_PROT 0xFFFF
-
-#define SMB2_PROT_ID  0x0202
-#define SMB21_PROT_ID 0x0210
-#define BAD_PROT_ID   0xFFFF
-
-static struct {
-       int index;
-       __le16 name;
-} smb2protocols[] = {
-       {SMB2_PROT,  cpu_to_le16(SMB2_PROT_ID)},
-       {SMB21_PROT, cpu_to_le16(SMB21_PROT_ID)},
-       {BAD_PROT,   cpu_to_le16(BAD_PROT_ID)}
-};
 
 /*
  *
@@ -348,7 +330,6 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
        int resp_buftype;
        struct TCP_Server_Info *server;
        unsigned int sec_flags;
-       u16 i;
        u16 temp = 0;
        int blob_offset, blob_length;
        char *security_blob;
@@ -377,11 +358,10 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
 
        req->hdr.SessionId = 0;
 
-       for (i = 0; i < SMB2_NUM_PROT; i++)
-               req->Dialects[i] = smb2protocols[i].name;
+       req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
 
-       req->DialectCount = cpu_to_le16(i);
-       inc_rfc1001_len(req, i * 2);
+       req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */
+       inc_rfc1001_len(req, 2);
 
        /* only one of SMB2 signing flags may be set in SMB2 request */
        if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN)
@@ -391,7 +371,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
 
        req->SecurityMode = cpu_to_le16(temp);
 
-       req->Capabilities = cpu_to_le32(SMB2_GLOBAL_CAP_DFS);
+       req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities);
 
        memcpy(req->ClientGUID, cifs_client_guid, SMB2_CLIENT_GUID_SIZE);
 
@@ -409,17 +389,16 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
        if (rc != 0)
                goto neg_exit;
 
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto neg_exit;
-       }
-
        cFYI(1, "mode 0x%x", rsp->SecurityMode);
 
-       if (rsp->DialectRevision == smb2protocols[SMB21_PROT].name)
+       /* BB we may eventually want to match the negotiated vs. requested
+          dialect, even though we are only requesting one at a time */
+       if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID))
+               cFYI(1, "negotiated smb2.0 dialect");
+       else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID))
                cFYI(1, "negotiated smb2.1 dialect");
-       else if (rsp->DialectRevision == smb2protocols[SMB2_PROT].name)
-               cFYI(1, "negotiated smb2 dialect");
+       else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID))
+               cFYI(1, "negotiated smb3.0 dialect");
        else {
                cERROR(1, "Illegal dialect returned by server %d",
                           le16_to_cpu(rsp->DialectRevision));
@@ -637,13 +616,14 @@ ssetup_ntlmssp_authenticate:
 
        kfree(security_blob);
        rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base;
-       if (rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) {
+       if (resp_buftype != CIFS_NO_BUFFER &&
+           rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) {
                if (phase != NtLmNegotiate) {
                        cERROR(1, "Unexpected more processing error");
                        goto ssetup_exit;
                }
                if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 !=
-                       le16_to_cpu(rsp->SecurityBufferOffset)) {
+                               le16_to_cpu(rsp->SecurityBufferOffset)) {
                        cERROR(1, "Invalid security buffer offset %d",
                                  le16_to_cpu(rsp->SecurityBufferOffset));
                        rc = -EIO;
@@ -669,11 +649,6 @@ ssetup_ntlmssp_authenticate:
        if (rc != 0)
                goto ssetup_exit;
 
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto ssetup_exit;
-       }
-
        ses->session_flags = le16_to_cpu(rsp->SessionFlags);
 ssetup_exit:
        free_rsp_buf(resp_buftype, rsp);
@@ -793,11 +768,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
                goto tcon_error_exit;
        }
 
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto tcon_exit;
-       }
-
        if (tcon == NULL) {
                ses->ipc_tid = rsp->hdr.TreeId;
                goto tcon_exit;
@@ -1046,10 +1016,6 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
                goto creat_exit;
        }
 
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto creat_exit;
-       }
        *persistent_fid = rsp->PersistentFileId;
        *volatile_fid = rsp->VolatileFileId;
 
@@ -1111,11 +1077,6 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
                goto close_exit;
        }
 
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto close_exit;
-       }
-
        /* BB FIXME - decode close response, update inode for caching */
 
 close_exit:
@@ -1950,12 +1911,6 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
                cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE);
                goto out;
        }
-
-       if (rsp == NULL) {
-               rc = -EIO;
-               goto out;
-       }
-
 out:
        free_rsp_buf(resp_buftype, rsp);
        kfree(iov);