Update login functions to use asprint to build the key=value pairs
instead of calling iscsi_pdu_add_data twice, once for key= and once for value
This commit is contained in:
+24
-38
@@ -30,59 +30,52 @@
|
|||||||
static int
|
static int
|
||||||
iscsi_login_add_initiatorname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
iscsi_login_add_initiatorname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||||
{
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
/* We only send InitiatorName during opneg or the first leg of secneg */
|
/* We only send InitiatorName during opneg or the first leg of secneg */
|
||||||
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
||||||
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
asprintf(&str, "InitiatorName=%s", iscsi->initiator_name);
|
||||||
(unsigned char *)"InitiatorName=",
|
if (iscsi_pdu_add_data(iscsi, pdu, (unsigned char *)str, strlen(str)+1)
|
||||||
14) != 0) {
|
!= 0) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
iscsi_set_error(iscsi, "Out-of-memory: pdu add data failed.");
|
||||||
"failed for InitiatorName.");
|
free(str);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
|
||||||
(unsigned char *)iscsi->initiator_name,
|
|
||||||
strlen(iscsi->initiator_name) +1) != 0) {
|
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
|
||||||
"failed for InitiatorName.");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
free(str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
iscsi_login_add_alias(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
iscsi_login_add_alias(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||||
{
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
/* We only send InitiatorAlias during opneg or the first leg of secneg */
|
/* We only send InitiatorAlias during opneg or the first leg of secneg */
|
||||||
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
||||||
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
asprintf(&str, "InitiatorAlias=%s", iscsi->alias);
|
||||||
(unsigned char *)"InitiatorAlias=",
|
if (iscsi_pdu_add_data(iscsi, pdu, (unsigned char *)str, strlen(str)+1)
|
||||||
15) != 0) {
|
!= 0) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
iscsi_set_error(iscsi, "Out-of-memory: pdu add data failed.");
|
||||||
"failed.");
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
free(str);
|
||||||
(unsigned char *)iscsi->alias,
|
|
||||||
strlen(iscsi->alias) +1) != 0) {
|
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
|
||||||
"failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||||
{
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
/* We only send TargetName during opneg or the first leg of secneg */
|
/* We only send TargetName during opneg or the first leg of secneg */
|
||||||
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
if (iscsi->current_phase != ISCSI_PDU_LOGIN_CSG_OPNEG
|
||||||
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
&& iscsi->secneg_phase != ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP) {
|
||||||
@@ -95,21 +88,14 @@ iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
asprintf(&str, "TargetName=%s", iscsi->target_name);
|
||||||
(unsigned char *)"TargetName=",
|
if (iscsi_pdu_add_data(iscsi, pdu, (unsigned char *)str, strlen(str)+1)
|
||||||
11) != 0) {
|
!= 0) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
iscsi_set_error(iscsi, "Out-of-memory: pdu add data failed.");
|
||||||
"failed.");
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (iscsi_pdu_add_data(iscsi, pdu,
|
free(str);
|
||||||
(unsigned char *)iscsi->target_name,
|
|
||||||
strlen(iscsi->target_name) +1) != 0) {
|
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data "
|
|
||||||
"failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user