[iscsi] Use generic base16 functions for iSCSI reverse CHAP

Yes, I forgot to convert this function before pushing.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/1/head
Michael Brown 2010-05-28 19:27:59 +01:00
parent d6f79d6b6e
commit b3d8238fd4
1 changed files with 17 additions and 24 deletions

View File

@ -812,10 +812,8 @@ static int iscsi_handle_chap_n_value ( struct iscsi_session *iscsi,
*/ */
static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi, static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
const char *value ) { const char *value ) {
char buf[3]; uint8_t buf[ strlen ( value ) ]; /* Decoding never expands data */
char *endp; size_t len;
uint8_t byte;
unsigned int i;
int rc; int rc;
/* Generate CHAP response for verification */ /* Generate CHAP response for verification */
@ -840,32 +838,27 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
iscsi, value ); iscsi, value );
return -EPROTO_INVALID_CHAP_RESPONSE; return -EPROTO_INVALID_CHAP_RESPONSE;
} }
value += 2;
/* Check CHAP response length */ /* Process response */
if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) { rc = base16_decode ( ( value + 2 ), buf );
if ( rc < 0 ) {
DBGC ( iscsi, "iSCSI %p invalid CHAP response \"%s\": %s\n",
iscsi, value, strerror ( rc ) );
return rc;
}
len = rc;
/* Check CHAP response */
if ( len != iscsi->chap.response_len ) {
DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n", DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
iscsi ); iscsi );
return -EPROTO_INVALID_CHAP_RESPONSE; return -EPROTO_INVALID_CHAP_RESPONSE;
} }
if ( memcmp ( buf, iscsi->chap.response, len ) != 0 ) {
/* Process response an octet at a time */ DBGC ( iscsi, "iSCSI %p incorrect CHAP response \"%s\"\n",
for ( i = 0 ; ( value[0] && value[1] ) ; value += 2, i++ ) { iscsi, value );
memcpy ( buf, value, 2 ); return -EACCES_INCORRECT_TARGET_PASSWORD;
buf[2] = 0;
byte = strtoul ( buf, &endp, 16 );
if ( *endp != '\0' ) {
DBGC ( iscsi, "iSCSI %p saw invalid CHAP response "
"byte \"%s\"\n", iscsi, buf );
return -EPROTO_INVALID_CHAP_RESPONSE;
}
if ( byte != iscsi->chap.response[i] ) {
DBGC ( iscsi, "iSCSI %p saw incorrect CHAP "
"response\n", iscsi );
return -EACCES_INCORRECT_TARGET_PASSWORD;
}
} }
assert ( i == iscsi->chap.response_len );
/* Mark session as authenticated */ /* Mark session as authenticated */
iscsi->status |= ISCSI_STATUS_AUTH_REVERSE_OK; iscsi->status |= ISCSI_STATUS_AUTH_REVERSE_OK;