diff mbox

[10/11] cifs: clean up cifs_find_smb_ses

Message ID 1271469958-4894-11-git-send-email-jlayton@redhat.com
State New
Headers show

Commit Message

Jeff Layton April 17, 2010, 2:05 a.m. UTC
Do a better job of matching sessions by authtype. Matching by username
for an anonymous or Kerberos session is incorrect. We need different
criteria for different security types. Also, in the case where we do
match by username, we also need to match by password. That ensures
that someone else doesn't "borrow" an existing session without needing
to know the password.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/cifs/cifsglob.h |    2 +-
 fs/cifs/connect.c  |   27 +++++++++++++++++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 1ececf4..eae6033 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -34,7 +34,7 @@ 
 #define MAX_SHARE_SIZE  64	/* used to be 20, this should still be enough */
 #define MAX_USERNAME_SIZE 32	/* 32 is to allow for 15 char names + null
 				   termination then *2 for unicode versions */
-#define MAX_PASSWORD_SIZE 16
+#define MAX_PASSWORD_SIZE 128
 
 #define CIFS_MIN_RCV_POOL 4
 
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 2e70071..74a7663 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1733,7 +1733,7 @@  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;
@@ -1741,9 +1741,28 @@  cifs_find_smb_ses(struct TCP_Server_Info *server, char *username)
 	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;
 
+		switch(vol->sectype) {
+		case Anonymous:
+			/* match any other anonymous session */
+			if (ses->secType != Anonymous)
+				continue;
+			break;
+		case Kerberos:
+			if (ses->secType != Kerberos)
+				continue;
+			if (vol->linux_uid != ses->linux_uid)
+				continue;
+			break;
+		default:
+			/* anything else takes username/password */
+			if (strncmp(ses->userName, vol->username,
+				    MAX_USERNAME_SIZE))
+				continue;
+			if (strncmp(ses->password, vol->password,
+				    MAX_PASSWORD_SIZE));
+				continue;
+		}
 		++ses->ses_count;
 		write_unlock(&cifs_tcp_ses_lock);
 		return ses;
@@ -1785,7 +1804,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));