[PATCH] : Unable to handle CHAP_A in List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Initially the LIO target was not able to handle CHAP_A in list correctly.This patch handles it correctly.
Let me know if any changes are required.

--
Thanks and regards.
Tejas Vaykole
Development Engineer.
Calsoft Inc.

>From 5237e56fd095175ca0419156477c327546a8d7e9 Mon Sep 17 00:00:00 2001
From: Tejas Vaykole <tejas.vaykole@xxxxxxxxxxxxxx>
Date: Tue, 27 May 2014 12:18:45 +0530
Subject: [PATCH] Initially LIO was not able to handle CHAP_A in list
 correctly. This patch handles it correctly.

---
 drivers/target/iscsi/iscsi_target_auth.c | 100 +++++++++++++++++++++----------
 drivers/target/iscsi/iscsi_target_auth.h |   3 +-
 2 files changed, 69 insertions(+), 34 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c
index de77d9a..97da79e 100644
--- a/drivers/target/iscsi/iscsi_target_auth.c
+++ b/drivers/target/iscsi/iscsi_target_auth.c
@@ -72,17 +72,50 @@ static void chap_gen_challenge(
 }
 
 
+
+/*
+ * check_algorithm -	Verifies CHAP_A string contains correct
+ *			algorithm value. Presently only MD5 is
+ *			supported.
+ *
+ * return values -	CHAP_DIGEST_UNKNOWN for unknown value and
+ *			CHAP_DIGEST_MD5 for MD5.
+ *
+ */
+static int check_algorithm(const char *a_str)
+{
+	char *tmp = NULL;
+	char *token = NULL;
+	tmp = kmalloc(strlen(a_str)+1, GFP_KERNEL);
+	if (tmp == NULL) {
+		pr_err("Memory allocation Failed\n");
+		return CHAP_DIGEST_UNKNOWN;
+	}
+	strcpy(tmp, a_str);
+	token = strsep(&tmp , "=");
+	while (token != NULL) {
+		token = strsep(&tmp , ",");
+		if (token == NULL)
+			return CHAP_DIGEST_UNKNOWN;
+		if (!strcmp(token, "5")) {
+			pr_err("MD5 Algorithm\n");
+			return CHAP_DIGEST_MD5;
+		}
+	}
+	return CHAP_DIGEST_UNKNOWN;
+}
+
 static struct iscsi_chap *chap_server_open(
-	struct iscsi_conn *conn,
-	struct iscsi_node_auth *auth,
-	const char *a_str,
-	char *aic_str,
-	unsigned int *aic_len)
+		struct iscsi_conn *conn,
+		struct iscsi_node_auth *auth,
+		const char *a_str,
+		char *aic_str,
+		unsigned int *aic_len)
 {
+	int ret;
 	struct iscsi_chap *chap;
-
 	if (!(auth->naf_flags & NAF_USERID_SET) ||
-	    !(auth->naf_flags & NAF_PASSWORD_SET)) {
+			!(auth->naf_flags & NAF_PASSWORD_SET)) {
 		pr_err("CHAP user or password not set for"
 				" Initiator ACL\n");
 		return NULL;
@@ -93,34 +126,35 @@ static struct iscsi_chap *chap_server_open(
 		return NULL;
 
 	chap = conn->auth_protocol;
-	/*
-	 * We only support MD5 MDA presently.
-	 */
-	if (strncmp(a_str, "CHAP_A=5", 8)) {
-		pr_err("CHAP_A is not MD5.\n");
+	ret = check_algorithm(a_str);
+	switch (ret) {
+	case CHAP_DIGEST_MD5:
+		pr_debug("[server] Got CHAP_A=5\n");
+		/*
+		 * Send back CHAP_A set to MD5.
+		 */
+		*aic_len = sprintf(aic_str, "CHAP_A=5");
+		*aic_len += 1;
+		chap->digest_type = CHAP_DIGEST_MD5;
+		pr_debug("[server] Sending CHAP_A=%d\n", chap->digest_type);
+		/*
+		 * Set Identifier.
+		 */
+		chap->id = conn->tpg->tpg_chap_id++;
+		*aic_len += sprintf(aic_str + *aic_len, "CHAP_I=%d", chap->id);
+		*aic_len += 1;
+		pr_debug("[server] Sending CHAP_I=%d\n", chap->id);
+		/*
+		 * Generate Challenge.
+		 */
+		chap_gen_challenge(conn, 1, aic_str, aic_len);
+		return chap;
+		break;
+	case CHAP_DIGEST_UNKNOWN:
+	default:
+		pr_err("Unknown CHAP_A.\n");
 		return NULL;
 	}
-	pr_debug("[server] Got CHAP_A=5\n");
-	/*
-	 * Send back CHAP_A set to MD5.
-	 */
-	*aic_len = sprintf(aic_str, "CHAP_A=5");
-	*aic_len += 1;
-	chap->digest_type = CHAP_DIGEST_MD5;
-	pr_debug("[server] Sending CHAP_A=%d\n", chap->digest_type);
-	/*
-	 * Set Identifier.
-	 */
-	chap->id = conn->tpg->tpg_chap_id++;
-	*aic_len += sprintf(aic_str + *aic_len, "CHAP_I=%d", chap->id);
-	*aic_len += 1;
-	pr_debug("[server] Sending CHAP_I=%d\n", chap->id);
-	/*
-	 * Generate Challenge.
-	 */
-	chap_gen_challenge(conn, 1, aic_str, aic_len);
-
-	return chap;
 }
 
 static void chap_close(struct iscsi_conn *conn)
diff --git a/drivers/target/iscsi/iscsi_target_auth.h b/drivers/target/iscsi/iscsi_target_auth.h
index 2f463c0..97b4527 100644
--- a/drivers/target/iscsi/iscsi_target_auth.h
+++ b/drivers/target/iscsi/iscsi_target_auth.h
@@ -1,10 +1,11 @@
 #ifndef _ISCSI_CHAP_H_
 #define _ISCSI_CHAP_H_
 
+#define CHAP_DIGEST_UNKNOWN	0
 #define CHAP_DIGEST_MD5		5
 #define CHAP_DIGEST_SHA		6
 
-#define CHAP_CHALLENGE_LENGTH	16
+#define CHAP_CHALLENGE_LENGTH   16 
 #define CHAP_CHALLENGE_STR_LEN	4096
 #define MAX_RESPONSE_LENGTH	64	/* sufficient for MD5 */
 #define	MAX_CHAP_N_SIZE		512
-- 
1.7.11.7


[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux