man page claims that you can use auth type = none, but in reality this

didn't work (insisted on a username being given and then used, plus always
advertised CHAP to the target). Make initiator work as advertised (i.e.
defaults to auth type none and so don't require a username).

To use CHAP you should explicitly request CHAP:
iscsi-initiator -a chap -u user -h targetname /mountpoint

For backwards compatibility, if a username is given (-u) and no auth type
is specified (-a), it will default to CHAP, i.e. to use none, just give no
username:
iscsi-initiator -h targetname /mountpoint
This commit is contained in:
sborrill 2011-02-21 17:48:43 +00:00
parent 4fd58d7036
commit ff607cd15b
3 changed files with 30 additions and 9 deletions

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)
AC_INIT([netbsd-iscsi],[20100416],[Alistair Crooks <agc@NetBSD.org>])
AC_INIT([netbsd-iscsi],[20110221],[Alistair Crooks <agc@NetBSD.org>])
AC_CONFIG_SRCDIR([src/lib/protocol.c])
AC_CONFIG_AUX_DIR([buildaux])

View File

@ -618,11 +618,22 @@ main(int argc, char **argv)
*argv, i);
}
}
if (iscsi_initiator_getvar(&ini, "user") == NULL) {
iscsi_err(__FILE__, __LINE__, "user must be specified with -u\n");
if (!strcmp(iscsi_initiator_getvar(&ini, "auth type"), "chap") &&
iscsi_initiator_getvar(&ini, "user") == NULL) {
iscsi_err(__FILE__, __LINE__, "user must be specified with "
"-u if using CHAP authentication\n");
exit(EXIT_FAILURE);
}
if (strcmp(iscsi_initiator_getvar(&ini, "auth type"), "none") &&
iscsi_initiator_getvar(&ini, "user") != NULL) {
/*
* For backwards compatibility, default to using CHAP
* if username given
*/
iscsi_initiator_setvar(&ini, "auth type", "chap");
}
if (iscsi_initiator_start(&ini) == -1) {
iscsi_err(__FILE__, __LINE__, "initiator_init() failed\n");
exit(EXIT_FAILURE);

View File

@ -211,10 +211,10 @@ session_init_i(initiator_session_t ** sess, uint64_t isid)
}
s = *sess;
user = NULL;
if (s->sess_params.cred.user) {
auth_type = s->sess_params.auth_type;
if (s->sess_params.cred.user && auth_type != AuthNone) {
user = s->sess_params.cred.user;
}
auth_type = s->sess_params.auth_type;
mutual_auth = s->sess_params.mutual_auth;
(void) memset(s, 0x0, sizeof(*s));
s->state = INITIATOR_SESSION_STATE_INITIALIZING;
@ -468,7 +468,11 @@ params_out(initiator_session_t * sess, char *text, int *len, int textsize, int s
if (security == IS_SECURITY) {
PARAM_TEXT_ADD(sess->params, "InitiatorName", "iqn.1994-04.org.NetBSD.iscsi-initiator:agc", text, len, textsize, 1, return -1);
PARAM_TEXT_ADD(sess->params, "InitiatorAlias", "NetBSD", text, len, textsize, 1, return -1);
PARAM_TEXT_ADD(sess->params, "AuthMethod", "CHAP,None", text, len, textsize, 1, return -1);
if (sess->sess_params.auth_type != AuthNone) {
PARAM_TEXT_ADD(sess->params, "AuthMethod", "CHAP,None", text, len, textsize, 1, return -1);
} else {
PARAM_TEXT_ADD(sess->params, "AuthMethod", "None", text, len, textsize, 1, return -1);
}
} else {
PARAM_TEXT_ADD(sess->params, "HeaderDigest", "None", text, len, textsize, 1, return -1);
PARAM_TEXT_ADD(sess->params, "DataDigest", "None", text, len, textsize, 1, return -1);
@ -890,11 +894,13 @@ iscsi_initiator_start(iscsi_initiator_t *ini)
INIT_CLEANUP;
return -1;
}
sess->sess_params.cred.user =
strdup(iscsi_initiator_getvar(ini, "user"));
cp = iscsi_initiator_getvar(ini, "auth type");
if (strcmp(cp, "none") == 0) {
sess->sess_params.auth_type = AuthNone;
sess->sess_params.cred.user = NULL;
} else {
sess->sess_params.cred.user =
strdup(iscsi_initiator_getvar(ini, "user"));
}
cp = iscsi_initiator_getvar(ini, "mutual auth");
if (strcmp(cp, "none") == 0) {
@ -3678,7 +3684,11 @@ ii_initiator_init(const char *hostname, int port, int address_family, const char
INIT_CLEANUP;
return -1;
}
sess->sess_params.cred.user = strdup(user);
if (user)
sess->sess_params.cred.user = strdup(user);
else
sess->sess_params.cred.user = NULL;
sess->sess_params.auth_type = auth_type;
sess->sess_params.mutual_auth = mutual_auth;
sess->sess_params.digest_wanted = digest_type;