[PATCH] cifs: cleanup of ifdefs usage so it is more consistent
[sfrench/cifs-2.6.git] / fs / cifs / connect.c
index 40470b9d5477a144331f10f12bd5bd7c2c7065be..383e55fa7d260687930daeb43b1309f58175de33 100644 (file)
@@ -72,6 +72,7 @@ struct smb_vol {
        unsigned no_xattr:1;   /* set if xattr (EA) support should be disabled*/
        unsigned server_ino:1; /* use inode numbers from server ie UniqueId */
        unsigned direct_io:1;
+       unsigned remap:1;   /* set to remap seven reserved chars in filenames */
        unsigned int rsize;
        unsigned int wsize;
        unsigned int sockopt;
@@ -182,7 +183,8 @@ cifs_reconnect(struct TCP_Server_Info *server)
                        spin_lock(&GlobalMid_Lock);
                        if(server->tcpStatus != CifsExiting)
                                server->tcpStatus = CifsGood;
-                       spin_unlock(&GlobalMid_Lock);
+                       server->sequence_number = 0;
+                       spin_unlock(&GlobalMid_Lock);                   
        /*              atomic_set(&server->inFlight,0);*/
                        wake_up(&server->response_q);
                }
@@ -359,9 +361,13 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                                                               mid_q_entry,
                                                               qhead);
 
-                                       if ((mid_entry->mid == smb_buffer->Mid) && (mid_entry->midState == MID_REQUEST_SUBMITTED)) {
-                                               cFYI(1,
-                                                    (" Mid 0x%x matched - waking up ",mid_entry->mid));
+                                       if ((mid_entry->mid == smb_buffer->Mid)
+                                               && (mid_entry->midState == 
+                                                       MID_REQUEST_SUBMITTED) 
+                                               && (mid_entry->command == 
+                                                       smb_buffer->Command)) {
+                                               cFYI(1,("Found Mid 0x%x wake up"
+                                                       ,mid_entry->mid));
                                                task_to_wake = mid_entry->tsk;
                                                mid_entry->resp_buf =
                                                    smb_buffer;
@@ -770,6 +776,10 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
                        vol->noperm = 0;
                } else if (strnicmp(data, "noperm", 6) == 0) {
                        vol->noperm = 1;
+               } else if (strnicmp(data, "mapchars", 8) == 0) {
+                       vol->remap = 1;
+               } else if (strnicmp(data, "nomapchars", 10) == 0) {
+                       vol->remap = 0;
                } else if (strnicmp(data, "setuids", 7) == 0) {
                        vol->setuids = 1;
                } else if (strnicmp(data, "nosetuids", 9) == 0) {
@@ -918,14 +928,15 @@ find_unc(__be32 new_target_ip_addr, char *uncName, char *userName)
 
 int
 connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
-                   const char *old_path, const struct nls_table *nls_codepage)
+                   const char *old_path, const struct nls_table *nls_codepage,
+                   int remap)
 {
        unsigned char *referrals = NULL;
        unsigned int num_referrals;
        int rc = 0;
 
        rc = get_dfs_path(xid, pSesInfo,old_path, nls_codepage, 
-                       &num_referrals, &referrals);
+                       &num_referrals, &referrals, remap);
 
        /* BB Add in code to: if valid refrl, if not ip address contact
                the helper that resolves tcp names, mount to it, try to 
@@ -940,7 +951,8 @@ connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
 int
 get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
                        const char *old_path, const struct nls_table *nls_codepage, 
-                       unsigned int *pnum_referrals, unsigned char ** preferrals)
+                       unsigned int *pnum_referrals, 
+                       unsigned char ** preferrals, int remap)
 {
        char *temp_unc;
        int rc = 0;
@@ -965,7 +977,7 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
        }
        if (rc == 0)
                rc = CIFSGetDFSRefer(xid, pSesInfo, old_path, preferrals,
-                                    pnum_referrals, nls_codepage);
+                                    pnum_referrals, nls_codepage, remap);
 
        return rc;
 }
@@ -1352,6 +1364,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                        } else
                                rc = 0;
                        memcpy(srvTcp->workstation_RFC1001_name, volume_info.source_rfc1001_name,16);
+                       srvTcp->sequence_number = 0;
                }
        }
 
@@ -1419,6 +1432,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                        cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
                if(volume_info.server_ino)
                        cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM;
+               if(volume_info.remap)
+                       cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR;
                if(volume_info.no_xattr)
                        cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR;
                if(volume_info.direct_io) {
@@ -1447,11 +1462,10 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                                if ((strchr(volume_info.UNC + 3, '\\') == NULL)
                                    && (strchr(volume_info.UNC + 3, '/') ==
                                        NULL)) {
-                                       rc = connect_to_dfs_path(xid,
-                                                                pSesInfo,
-                                                                "",
-                                                                cifs_sb->
-                                                                local_nls);
+                                       rc = connect_to_dfs_path(xid, pSesInfo,
+                                                       "", cifs_sb->local_nls,
+                                                       cifs_sb->mnt_cifs_flags & 
+                                                         CIFS_MOUNT_MAP_SPECIAL_CHR);
                                        if(volume_info.UNC)
                                                kfree(volume_info.UNC);
                                        FreeXid(xid);
@@ -1514,10 +1528,10 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                tcon->ses = pSesInfo;
 
                /* do not care if following two calls succeed - informational only */
-               CIFSSMBQFSDeviceInfo(xid, tcon, cifs_sb->local_nls);
-               CIFSSMBQFSAttributeInfo(xid, tcon, cifs_sb->local_nls);
+               CIFSSMBQFSDeviceInfo(xid, tcon);
+               CIFSSMBQFSAttributeInfo(xid, tcon);
                if (tcon->ses->capabilities & CAP_UNIX) {
-                       if(!CIFSSMBQFSUnixInfo(xid, tcon, cifs_sb->local_nls)) {
+                       if(!CIFSSMBQFSUnixInfo(xid, tcon)) {
                                if(!volume_info.no_psx_acl) {
                                        if(CIFS_UNIX_POSIX_ACL_CAP & 
                                           le64_to_cpu(tcon->fsUnixInfo.Capability))
@@ -2959,6 +2973,7 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
        int rc = 0;
        char ntlm_session_key[CIFS_SESSION_KEY_SIZE];
        int ntlmv2_flag = FALSE;
+       int first_time = 0;
 
        /* what if server changes its buffer size after dropping the session? */
        if(pSesInfo->server->maxBuf == 0) /* no need to send on reconnect */ {
@@ -2977,12 +2992,13 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
                        spin_unlock(&GlobalMid_Lock);
 
                }
+               first_time = 1;
        }
        if (!rc) {
                pSesInfo->capabilities = pSesInfo->server->capabilities;
                if(linuxExtEnabled == 0)
                        pSesInfo->capabilities &= (~CAP_UNIX);
-               pSesInfo->sequence_number = 0;
+       /*      pSesInfo->sequence_number = 0;*/
                cFYI(1,("Security Mode: 0x%x Capabilities: 0x%x Time Zone: %d",
                        pSesInfo->server->secMode,
                        pSesInfo->server->capabilities,
@@ -3015,7 +3031,10 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
                                                v2_response = kmalloc(16 + 64 /* blob */, GFP_KERNEL);
                                        if(v2_response) {
                                                CalcNTLMv2_response(pSesInfo,v2_response);
-/*                                             cifs_calculate_ntlmv2_mac_key(pSesInfo->mac_signing_key, response, ntlm_session_key, */
+                               /*              if(first_time)
+                                                       cifs_calculate_ntlmv2_mac_key(
+                                                         pSesInfo->server->mac_signing_key, 
+                                                         response, ntlm_session_key, */
                                                kfree(v2_response);
                                        /* BB Put dummy sig in SessSetup PDU? */
                                        } else {
@@ -3028,9 +3047,11 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
                                                pSesInfo->server->cryptKey,
                                                ntlm_session_key);
 
-                                       cifs_calculate_mac_key(pSesInfo->mac_signing_key,
-                                               ntlm_session_key,
-                                               pSesInfo->password);
+                                       if(first_time)
+                                               cifs_calculate_mac_key(
+                                                       pSesInfo->server->mac_signing_key,
+                                                       ntlm_session_key,
+                                                       pSesInfo->password);
                                }
                        /* for better security the weaker lanman hash not sent
                           in AuthSessSetup so we no longer calculate it */
@@ -3046,8 +3067,11 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
                                pSesInfo->server->cryptKey,
                                ntlm_session_key);
 
-                       cifs_calculate_mac_key(pSesInfo->mac_signing_key, 
-                               ntlm_session_key, pSesInfo->password);
+                       if(first_time)          
+                               cifs_calculate_mac_key(
+                                       pSesInfo->server->mac_signing_key,
+                                       ntlm_session_key, pSesInfo->password);
+
                        rc = CIFSSessSetup(xid, pSesInfo,
                                ntlm_session_key, nls_info);
                }