|
@@ -15,14 +15,19 @@
|
15
|
15
|
* along with this program; if not, write to the Free Software
|
16
|
16
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
17
|
17
|
* 02110-1301, USA.
|
|
18
|
+ *
|
|
19
|
+ * You can also choose to distribute this program under the terms of
|
|
20
|
+ * the Unmodified Binary Distribution Licence (as given in the file
|
|
21
|
+ * COPYING.UBDL), provided that you have satisfied its requirements.
|
18
|
22
|
*/
|
19
|
23
|
|
20
|
|
-FILE_LICENCE ( GPL2_OR_LATER );
|
|
24
|
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
21
|
25
|
|
22
|
26
|
#include <stddef.h>
|
23
|
27
|
#include <string.h>
|
24
|
28
|
#include <stdlib.h>
|
25
|
29
|
#include <stdio.h>
|
|
30
|
+#include <ctype.h>
|
26
|
31
|
#include <errno.h>
|
27
|
32
|
#include <assert.h>
|
28
|
33
|
#include <byteswap.h>
|
|
@@ -127,7 +132,7 @@ FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
|
127
|
132
|
#define EPROTO_INVALID_LARGE_BINARY \
|
128
|
133
|
__einfo_error ( EINFO_EPROTO_INVALID_LARGE_BINARY )
|
129
|
134
|
#define EINFO_EPROTO_INVALID_LARGE_BINARY \
|
130
|
|
- __einfo_uniqify ( EINFO_EPROTO, 0x03, "Invalid large binary" )
|
|
135
|
+ __einfo_uniqify ( EINFO_EPROTO, 0x03, "Invalid large binary value" )
|
131
|
136
|
#define EPROTO_INVALID_CHAP_RESPONSE \
|
132
|
137
|
__einfo_error ( EINFO_EPROTO_INVALID_CHAP_RESPONSE )
|
133
|
138
|
#define EINFO_EPROTO_INVALID_CHAP_RESPONSE \
|
|
@@ -823,17 +828,6 @@ static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
|
823
|
828
|
return xfer_deliver_iob ( &iscsi->socket, iobuf );
|
824
|
829
|
}
|
825
|
830
|
|
826
|
|
-/**
|
827
|
|
- * Calculate maximum length of decoded large binary value
|
828
|
|
- *
|
829
|
|
- * @v encoded Encoded large binary value
|
830
|
|
- * @v max_raw_len Maximum length of raw data
|
831
|
|
- */
|
832
|
|
-static inline size_t
|
833
|
|
-iscsi_large_binary_decoded_max_len ( const char *encoded ) {
|
834
|
|
- return ( strlen ( encoded ) ); /* Decoding never expands data */
|
835
|
|
-}
|
836
|
|
-
|
837
|
831
|
/**
|
838
|
832
|
* Decode large binary value
|
839
|
833
|
*
|
|
@@ -843,19 +837,17 @@ iscsi_large_binary_decoded_max_len ( const char *encoded ) {
|
843
|
837
|
*/
|
844
|
838
|
static int iscsi_large_binary_decode ( const char *encoded, uint8_t *raw ) {
|
845
|
839
|
|
846
|
|
- if ( encoded[0] != '0' )
|
847
|
|
- return -EPROTO_INVALID_LARGE_BINARY;
|
848
|
|
-
|
849
|
|
- switch ( encoded[1] ) {
|
850
|
|
- case 'x' :
|
851
|
|
- case 'X' :
|
852
|
|
- return base16_decode ( ( encoded + 2 ), raw );
|
853
|
|
- case 'b' :
|
854
|
|
- case 'B' :
|
855
|
|
- return base64_decode ( ( encoded + 2 ), raw );
|
856
|
|
- default:
|
857
|
|
- return -EPROTO_INVALID_LARGE_BINARY;
|
|
840
|
+ /* Check for initial '0x' or '0b' and decode as appropriate */
|
|
841
|
+ if ( *(encoded++) == '0' ) {
|
|
842
|
+ switch ( tolower ( *(encoded++) ) ) {
|
|
843
|
+ case 'x' :
|
|
844
|
+ return base16_decode ( encoded, raw );
|
|
845
|
+ case 'b' :
|
|
846
|
+ return base64_decode ( encoded, raw );
|
|
847
|
+ }
|
858
|
848
|
}
|
|
849
|
+
|
|
850
|
+ return -EPROTO_INVALID_LARGE_BINARY;
|
859
|
851
|
}
|
860
|
852
|
|
861
|
853
|
/**
|
|
@@ -982,19 +974,19 @@ static int iscsi_handle_chap_i_value ( struct iscsi_session *iscsi,
|
982
|
974
|
*/
|
983
|
975
|
static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
|
984
|
976
|
const char *value ) {
|
985
|
|
- uint8_t buf[ iscsi_large_binary_decoded_max_len ( value ) ];
|
|
977
|
+ uint8_t buf[ strlen ( value ) ]; /* Decoding never expands data */
|
986
|
978
|
unsigned int i;
|
987
|
|
- size_t len;
|
|
979
|
+ int len;
|
988
|
980
|
int rc;
|
989
|
981
|
|
990
|
982
|
/* Process challenge */
|
991
|
|
- rc = iscsi_large_binary_decode ( value, buf );
|
992
|
|
- if ( rc < 0 ) {
|
|
983
|
+ len = iscsi_large_binary_decode ( value, buf );
|
|
984
|
+ if ( len < 0 ) {
|
|
985
|
+ rc = len;
|
993
|
986
|
DBGC ( iscsi, "iSCSI %p invalid CHAP challenge \"%s\": %s\n",
|
994
|
987
|
iscsi, value, strerror ( rc ) );
|
995
|
988
|
return rc;
|
996
|
989
|
}
|
997
|
|
- len = rc;
|
998
|
990
|
chap_update ( &iscsi->chap, buf, len );
|
999
|
991
|
|
1000
|
992
|
/* Build CHAP response */
|
|
@@ -1052,8 +1044,8 @@ static int iscsi_handle_chap_n_value ( struct iscsi_session *iscsi,
|
1052
|
1044
|
*/
|
1053
|
1045
|
static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
|
1054
|
1046
|
const char *value ) {
|
1055
|
|
- uint8_t buf[ iscsi_large_binary_decoded_max_len ( value ) ];
|
1056
|
|
- size_t len;
|
|
1047
|
+ uint8_t buf[ strlen ( value ) ]; /* Decoding never expands data */
|
|
1048
|
+ int len;
|
1057
|
1049
|
int rc;
|
1058
|
1050
|
|
1059
|
1051
|
/* Generate CHAP response for verification */
|
|
@@ -1073,16 +1065,16 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
|
1073
|
1065
|
chap_respond ( &iscsi->chap );
|
1074
|
1066
|
|
1075
|
1067
|
/* Process response */
|
1076
|
|
- rc = iscsi_large_binary_decode ( value, buf );
|
1077
|
|
- if ( rc < 0 ) {
|
|
1068
|
+ len = iscsi_large_binary_decode ( value, buf );
|
|
1069
|
+ if ( len < 0 ) {
|
|
1070
|
+ rc = len;
|
1078
|
1071
|
DBGC ( iscsi, "iSCSI %p invalid CHAP response \"%s\": %s\n",
|
1079
|
1072
|
iscsi, value, strerror ( rc ) );
|
1080
|
1073
|
return rc;
|
1081
|
1074
|
}
|
1082
|
|
- len = rc;
|
1083
|
1075
|
|
1084
|
1076
|
/* Check CHAP response */
|
1085
|
|
- if ( len != iscsi->chap.response_len ) {
|
|
1077
|
+ if ( len != ( int ) iscsi->chap.response_len ) {
|
1086
|
1078
|
DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
|
1087
|
1079
|
iscsi );
|
1088
|
1080
|
return -EPROTO_INVALID_CHAP_RESPONSE;
|