cifs: add separate cred_uid field to sesInfo
[deliverable/linux.git] / fs / cifs / connect.c
index b24e4cea4e3c808288d3332a09e53efa18645f9f..52a7646cc7af5419f8e95dd1e16e41ae2904b3bb 100644 (file)
@@ -67,6 +67,7 @@ struct smb_vol {
        char *iocharset;  /* local code page for mapping to and from Unicode */
        char source_rfc1001_name[16]; /* netbios name of client */
        char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */
+       uid_t cred_uid;
        uid_t linux_uid;
        gid_t linux_gid;
        mode_t file_mode;
@@ -98,6 +99,7 @@ struct smb_vol {
        bool noblocksnd:1;
        bool noautotune:1;
        bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
+       bool fsc:1;     /* enable fscache */
        unsigned int rsize;
        unsigned int wsize;
        bool sockopt_tcp_nodelay:1;
@@ -831,7 +833,8 @@ cifs_parse_mount_options(char *options, const char *devname,
        /* null target name indicates to use *SMBSERVR default called name
           if we end up sending RFC1001 session initialize */
        vol->target_rfc1001_name[0] = 0;
-       vol->linux_uid = current_uid();  /* use current_euid() instead? */
+       vol->cred_uid = current_uid();
+       vol->linux_uid = current_uid();
        vol->linux_gid = current_gid();
 
        /* default to only allowing write access to owner of the mount */
@@ -843,6 +846,9 @@ cifs_parse_mount_options(char *options, const char *devname,
        /* default to using server inode numbers where available */
        vol->server_ino = 1;
 
+       /* XXX: default to fsc for testing until mount.cifs pieces are done */
+       vol->fsc = 1;
+
        if (!options)
                return 1;
 
@@ -1332,6 +1338,8 @@ cifs_parse_mount_options(char *options, const char *devname,
                        printk(KERN_WARNING "CIFS: Mount option noac not "
                                "supported. Instead set "
                                "/proc/fs/cifs/LookupCacheEnabled to 0\n");
+               } else if (strnicmp(data, "fsc", 3) == 0) {
+                       vol->fsc = true;
                } else
                        printk(KERN_WARNING "CIFS: Unknown mount option %s\n",
                                                data);
@@ -1644,17 +1652,27 @@ out_err:
 }
 
 static struct cifsSesInfo *
-cifs_find_smb_ses(struct TCP_Server_Info *server, char *username)
+cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 {
-       struct list_head *tmp;
        struct cifsSesInfo *ses;
 
        write_lock(&cifs_tcp_ses_lock);
-       list_for_each(tmp, &server->smb_ses_list) {
-               ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
-               if (strncmp(ses->userName, username, MAX_USERNAME_SIZE))
-                       continue;
-
+       list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               switch (server->secType) {
+               case Kerberos:
+                       if (vol->cred_uid != ses->cred_uid)
+                               continue;
+                       break;
+               default:
+                       /* anything else takes username/password */
+                       if (strncmp(ses->userName, vol->username,
+                                   MAX_USERNAME_SIZE))
+                               continue;
+                       if (strlen(vol->username) != 0 &&
+                           strncmp(ses->password, vol->password,
+                                   MAX_PASSWORD_SIZE))
+                               continue;
+               }
                ++ses->ses_count;
                write_unlock(&cifs_tcp_ses_lock);
                return ses;
@@ -1696,7 +1714,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
 
        xid = GetXid();
 
-       ses = cifs_find_smb_ses(server, volume_info->username);
+       ses = cifs_find_smb_ses(server, volume_info);
        if (ses) {
                cFYI(1, "Existing smb sess found (status=%d)", ses->status);
 
@@ -1759,6 +1777,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
                if (ses->domainName)
                        strcpy(ses->domainName, volume_info->domainname);
        }
+       ses->cred_uid = volume_info->cred_uid;
        ses->linux_uid = volume_info->linux_uid;
        ses->overrideSecFlg = volume_info->secFlg;
 
@@ -1827,6 +1846,7 @@ cifs_put_tcon(struct cifsTconInfo *tcon)
        _FreeXid(xid);
 
        tconInfoFree(tcon);
+       cifs_fscache_release_super_cookie(tcon);
        cifs_put_smb_ses(ses);
 }
 
@@ -1896,6 +1916,8 @@ cifs_get_tcon(struct cifsSesInfo *ses, struct smb_vol *volume_info)
        list_add(&tcon->tcon_list, &ses->tcon_list);
        write_unlock(&cifs_tcp_ses_lock);
 
+       cifs_fscache_get_super_cookie(tcon);
+
        return tcon;
 
 out_fail:
@@ -2450,6 +2472,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
        if (pvolume_info->dynperm)
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
+       if (pvolume_info->fsc)
+               cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
        if (pvolume_info->direct_io) {
                cFYI(1, "mounting share using direct i/o");
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
This page took 0.029998 seconds and 5 git commands to generate.