| 
				
			 | 
			
			
				
				@@ -812,10 +812,8 @@ static int iscsi_handle_chap_n_value ( struct iscsi_session *iscsi, 
			 | 
		
		
	
		
			
			| 
				812
			 | 
			
				812
			 | 
			
			
				
				  */ 
			 | 
		
		
	
		
			
			| 
				813
			 | 
			
				813
			 | 
			
			
				
				 static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi, 
			 | 
		
		
	
		
			
			| 
				814
			 | 
			
				814
			 | 
			
			
				
				 				       const char *value ) { 
			 | 
		
		
	
		
			
			| 
				815
			 | 
			
				
			 | 
			
			
				
				-	char buf[3]; 
			 | 
		
		
	
		
			
			| 
				816
			 | 
			
				
			 | 
			
			
				
				-	char *endp; 
			 | 
		
		
	
		
			
			| 
				817
			 | 
			
				
			 | 
			
			
				
				-	uint8_t byte; 
			 | 
		
		
	
		
			
			| 
				818
			 | 
			
				
			 | 
			
			
				
				-	unsigned int i; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				815
			 | 
			
			
				
				+	uint8_t buf[ strlen ( value ) ]; /* Decoding never expands data */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				816
			 | 
			
			
				
				+	size_t len; 
			 | 
		
		
	
		
			
			| 
				819
			 | 
			
				817
			 | 
			
			
				
				 	int rc; 
			 | 
		
		
	
		
			
			| 
				820
			 | 
			
				818
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				821
			 | 
			
				819
			 | 
			
			
				
				 	/* Generate CHAP response for verification */ 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -840,32 +838,27 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi, 
			 | 
		
		
	
		
			
			| 
				840
			 | 
			
				838
			 | 
			
			
				
				 		       iscsi, value ); 
			 | 
		
		
	
		
			
			| 
				841
			 | 
			
				839
			 | 
			
			
				
				 		return -EPROTO_INVALID_CHAP_RESPONSE; 
			 | 
		
		
	
		
			
			| 
				842
			 | 
			
				840
			 | 
			
			
				
				 	} 
			 | 
		
		
	
		
			
			| 
				843
			 | 
			
				
			 | 
			
			
				
				-	value += 2; 
			 | 
		
		
	
		
			
			| 
				844
			 | 
			
				841
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				845
			 | 
			
				
			 | 
			
			
				
				-	/* Check CHAP response length */ 
			 | 
		
		
	
		
			
			| 
				846
			 | 
			
				
			 | 
			
			
				
				-	if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				842
			 | 
			
			
				
				+	/* Process response */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				843
			 | 
			
			
				
				+	rc = base16_decode ( ( value + 2 ), buf ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				844
			 | 
			
			
				
				+	if ( rc < 0 ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				845
			 | 
			
			
				
				+		DBGC ( iscsi, "iSCSI %p invalid CHAP response \"%s\": %s\n", 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				846
			 | 
			
			
				
				+		       iscsi, value, strerror ( rc ) ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				847
			 | 
			
			
				
				+		return rc; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				848
			 | 
			
			
				
				+	} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				849
			 | 
			
			
				
				+	len = rc; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				850
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				851
			 | 
			
			
				
				+	/* Check CHAP response */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				852
			 | 
			
			
				
				+	if ( len != iscsi->chap.response_len ) { 
			 | 
		
		
	
		
			
			| 
				847
			 | 
			
				853
			 | 
			
			
				
				 		DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n", 
			 | 
		
		
	
		
			
			| 
				848
			 | 
			
				854
			 | 
			
			
				
				 		       iscsi ); 
			 | 
		
		
	
		
			
			| 
				849
			 | 
			
				855
			 | 
			
			
				
				 		return -EPROTO_INVALID_CHAP_RESPONSE; 
			 | 
		
		
	
		
			
			| 
				850
			 | 
			
				856
			 | 
			
			
				
				 	} 
			 | 
		
		
	
		
			
			| 
				851
			 | 
			
				
			 | 
			
			
				
				- 
			 | 
		
		
	
		
			
			| 
				852
			 | 
			
				
			 | 
			
			
				
				-	/* Process response an octet at a time */ 
			 | 
		
		
	
		
			
			| 
				853
			 | 
			
				
			 | 
			
			
				
				-	for ( i = 0 ; ( value[0] && value[1] ) ; value += 2, i++ ) { 
			 | 
		
		
	
		
			
			| 
				854
			 | 
			
				
			 | 
			
			
				
				-		memcpy ( buf, value, 2 ); 
			 | 
		
		
	
		
			
			| 
				855
			 | 
			
				
			 | 
			
			
				
				-		buf[2] = 0; 
			 | 
		
		
	
		
			
			| 
				856
			 | 
			
				
			 | 
			
			
				
				-		byte = strtoul ( buf, &endp, 16 ); 
			 | 
		
		
	
		
			
			| 
				857
			 | 
			
				
			 | 
			
			
				
				-		if ( *endp != '\0' ) { 
			 | 
		
		
	
		
			
			| 
				858
			 | 
			
				
			 | 
			
			
				
				-			DBGC ( iscsi, "iSCSI %p saw invalid CHAP response " 
			 | 
		
		
	
		
			
			| 
				859
			 | 
			
				
			 | 
			
			
				
				-			       "byte \"%s\"\n", iscsi, buf ); 
			 | 
		
		
	
		
			
			| 
				860
			 | 
			
				
			 | 
			
			
				
				-			return -EPROTO_INVALID_CHAP_RESPONSE; 
			 | 
		
		
	
		
			
			| 
				861
			 | 
			
				
			 | 
			
			
				
				-		} 
			 | 
		
		
	
		
			
			| 
				862
			 | 
			
				
			 | 
			
			
				
				-		if ( byte != iscsi->chap.response[i] ) { 
			 | 
		
		
	
		
			
			| 
				863
			 | 
			
				
			 | 
			
			
				
				-			DBGC ( iscsi, "iSCSI %p saw incorrect CHAP " 
			 | 
		
		
	
		
			
			| 
				864
			 | 
			
				
			 | 
			
			
				
				-			       "response\n", iscsi ); 
			 | 
		
		
	
		
			
			| 
				865
			 | 
			
				
			 | 
			
			
				
				-			return -EACCES_INCORRECT_TARGET_PASSWORD; 
			 | 
		
		
	
		
			
			| 
				866
			 | 
			
				
			 | 
			
			
				
				-		} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				857
			 | 
			
			
				
				+	if ( memcmp ( buf, iscsi->chap.response, len ) != 0 ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				858
			 | 
			
			
				
				+		DBGC ( iscsi, "iSCSI %p incorrect CHAP response \"%s\"\n", 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				859
			 | 
			
			
				
				+		       iscsi, value ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				860
			 | 
			
			
				
				+		return -EACCES_INCORRECT_TARGET_PASSWORD; 
			 | 
		
		
	
		
			
			| 
				867
			 | 
			
				861
			 | 
			
			
				
				 	} 
			 | 
		
		
	
		
			
			| 
				868
			 | 
			
				
			 | 
			
			
				
				-	assert ( i == iscsi->chap.response_len ); 
			 | 
		
		
	
		
			
			| 
				869
			 | 
			
				862
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				870
			 | 
			
				863
			 | 
			
			
				
				 	/* Mark session as authenticated */ 
			 | 
		
		
	
		
			
			| 
				871
			 | 
			
				864
			 | 
			
			
				
				 	iscsi->status |= ISCSI_STATUS_AUTH_REVERSE_OK; 
			 |