Commit 83d439f1 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

iscsi: Move spdk_iscsi_chap_get_authinfo() from iscsi.c to iscsi_subsystem.c



This patch series will refactor/improve CHAP authentication and consolidate
it into iscsi_subsystem.c.

To get better reviews, this patch just moves spdk_iscsi_chap_get_authinfo()
from iscsi.c to iscsi_subsystem.c.

Change-Id: I953f5c851bfe67dc02f6f82966132b4216e79228
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/422764


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 844735c9
Loading
Loading
Loading
Loading
+0 −86
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@
#include "spdk/trace.h"
#include "spdk/string.h"
#include "spdk/queue.h"
#include "spdk/conf.h"
#include "spdk/net.h"

#include "iscsi/md5.h"
@@ -677,91 +676,6 @@ spdk_iscsi_append_param(struct spdk_iscsi_conn *conn, const char *key,
	return rc;
}

static int
spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile,
			     const char *authuser, int ag_tag)
{
	struct spdk_conf *config = NULL;
	struct spdk_conf_section *sp;
	const char *val;
	const char *user, *muser;
	const char *secret, *msecret;
	int rc;
	int i;

	if (auth->user != NULL) {
		free(auth->user);
		free(auth->secret);
		free(auth->muser);
		free(auth->msecret);
		auth->user = auth->secret = NULL;
		auth->muser = auth->msecret = NULL;
	}

	/* read config files */
	config = spdk_conf_allocate();
	if (config == NULL) {
		SPDK_ERRLOG("allocate config fail\n");
		return -1;
	}
	rc = spdk_conf_read(config, authfile);
	if (rc < 0) {
		SPDK_ERRLOG("auth conf error\n");
		spdk_conf_free(config);
		return -1;
	}
	//spdk_conf_print(config);

	sp = spdk_conf_first_section(config);
	while (sp != NULL) {
		if (spdk_conf_section_match_prefix(sp, "AuthGroup")) {
			int group = spdk_conf_section_get_num(sp);
			if (group == 0) {
				SPDK_ERRLOG("Group 0 is invalid\n");
				spdk_conf_free(config);
				return -1;
			}
			if (ag_tag != group) {
				goto skip_ag_tag;
			}

			val = spdk_conf_section_get_val(sp, "Comment");
			if (val != NULL) {
				SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Comment %s\n", val);
			}
			for (i = 0; ; i++) {
				val = spdk_conf_section_get_nval(sp, "Auth", i);
				if (val == NULL) {
					break;
				}
				user = spdk_conf_section_get_nmval(sp, "Auth", i, 0);
				secret = spdk_conf_section_get_nmval(sp, "Auth", i, 1);
				muser = spdk_conf_section_get_nmval(sp, "Auth", i, 2);
				msecret = spdk_conf_section_get_nmval(sp, "Auth", i, 3);
				if (user != NULL) {
					if (strcasecmp(authuser, user) == 0) {
						/* match user */
						auth->user = xstrdup(user);
						auth->secret = xstrdup(secret);
						auth->muser = xstrdup(muser);
						auth->msecret = xstrdup(msecret);
						spdk_conf_free(config);
						return 0;
					}
				} else {
					SPDK_ERRLOG("Invalid Auth format, skip this line\n");
					continue;
				}
			}
		}
skip_ag_tag:
		sp = spdk_conf_next_section(sp);
	}

	spdk_conf_free(config);
	return 0;
}

static int
spdk_iscsi_get_authinfo(struct spdk_iscsi_conn *conn, const char *authuser)
{
+2 −0
Original line number Diff line number Diff line
@@ -366,6 +366,8 @@ struct spdk_iscsi_opts *spdk_iscsi_opts_copy(struct spdk_iscsi_opts *src);
void spdk_iscsi_opts_info_json(struct spdk_json_write_ctx *w);
int spdk_iscsi_set_discovery_auth(bool disable_chap, bool require_chap,
				  bool mutual_chap, int32_t chap_group);
int spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile,
				 const char *authuser, int ag_tag);

void spdk_iscsi_send_nopin(struct spdk_iscsi_conn *conn);
void spdk_iscsi_task_response(struct spdk_iscsi_conn *conn,
+86 −0
Original line number Diff line number Diff line
@@ -774,6 +774,92 @@ spdk_iscsi_set_discovery_auth(bool disable_chap, bool require_chap, bool mutual_
	return 0;
}

int
spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile,
			     const char *authuser, int ag_tag)
{
	struct spdk_conf *config = NULL;
	struct spdk_conf_section *sp;
	const char *val;
	const char *user, *muser;
	const char *secret, *msecret;
	int rc;
	int i;

	if (auth->user != NULL) {
		free(auth->user);
		free(auth->secret);
		free(auth->muser);
		free(auth->msecret);
		auth->user = auth->secret = NULL;
		auth->muser = auth->msecret = NULL;
	}

	/* read config files */
	config = spdk_conf_allocate();
	if (config == NULL) {
		SPDK_ERRLOG("allocate config fail\n");
		return -1;
	}

	rc = spdk_conf_read(config, authfile);
	if (rc < 0) {
		SPDK_ERRLOG("auth conf error\n");
		spdk_conf_free(config);
		return -1;
	}
	//spdk_conf_print(config);

	sp = spdk_conf_first_section(config);
	while (sp != NULL) {
		if (spdk_conf_section_match_prefix(sp, "AuthGroup")) {
			int group = spdk_conf_section_get_num(sp);
			if (group == 0) {
				SPDK_ERRLOG("Group 0 is invalid\n");
				spdk_conf_free(config);
				return -1;
			}
			if (ag_tag != group) {
				goto skip_ag_tag;
			}

			val = spdk_conf_section_get_val(sp, "Comment");
			if (val != NULL) {
				SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Comment %s\n", val);
			}
			for (i = 0; ; i++) {
				val = spdk_conf_section_get_nval(sp, "Auth", i);
				if (val == NULL) {
					break;
				}
				user = spdk_conf_section_get_nmval(sp, "Auth", i, 0);
				secret = spdk_conf_section_get_nmval(sp, "Auth", i, 1);
				muser = spdk_conf_section_get_nmval(sp, "Auth", i, 2);
				msecret = spdk_conf_section_get_nmval(sp, "Auth", i, 3);
				if (user != NULL) {
					if (strcasecmp(authuser, user) == 0) {
						/* match user */
						auth->user = xstrdup(user);
						auth->secret = xstrdup(secret);
						auth->muser = xstrdup(muser);
						auth->msecret = xstrdup(msecret);
						spdk_conf_free(config);
						return 0;
					}
				} else {
					SPDK_ERRLOG("Invalid Auth format, skip this line\n");
					continue;
				}
			}
		}
skip_ag_tag:
		sp = spdk_conf_next_section(sp);
	}

	spdk_conf_free(config);
	return 0;
}

static int
spdk_iscsi_initialize_global_params(void)
{
+7 −0
Original line number Diff line number Diff line
@@ -96,6 +96,13 @@ spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pd
{
}

int
spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile,
			     const char *authuser, int ag_tag)
{
	return 0;
}

int
spdk_scsi_lun_get_id(const struct spdk_scsi_lun *lun)
{