Browse Source

[iscsi] Disambiguate some common authentication errors

Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v1.20.1
Michael Brown 15 years ago
parent
commit
73c71f6492
1 changed files with 27 additions and 14 deletions
  1. 27
    14
      src/net/tcp/iscsi.c

+ 27
- 14
src/net/tcp/iscsi.c View File

45
 
45
 
46
 FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
46
 FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
47
 
47
 
48
+/* Disambiguate the various error causes */
49
+#define EACCES_INCORRECT_TARGET_USERNAME ( EACCES | EUNIQ_01 )
50
+#define EACCES_INCORRECT_TARGET_PASSWORD ( EACCES | EUNIQ_02 )
51
+#define ENOTSUP_INITIATOR_STATUS ( ENOTSUP | EUNIQ_01 )
52
+#define ENOTSUP_OPCODE ( ENOTSUP | EUNIQ_02 )
53
+#define ENOTSUP_DISCOVERY ( ENOTSUP | EUNIQ_03 )
54
+#define EPERM_INITIATOR_AUTHENTICATION ( EPERM | EUNIQ_01 )
55
+#define EPERM_INITIATOR_AUTHORISATION ( EPERM | EUNIQ_02 )
56
+#define EPROTO_INVALID_CHAP_ALGORITHM ( EPROTO | EUNIQ_01 )
57
+#define EPROTO_INVALID_CHAP_IDENTIFIER ( EPROTO | EUNIQ_02 )
58
+#define EPROTO_INVALID_CHAP_CHALLENGE ( EPROTO | EUNIQ_03 )
59
+#define EPROTO_INVALID_CHAP_RESPONSE ( EPROTO | EUNIQ_04 )
60
+
48
 /** iSCSI initiator name (explicitly specified) */
61
 /** iSCSI initiator name (explicitly specified) */
49
 static char *iscsi_explicit_initiator_iqn;
62
 static char *iscsi_explicit_initiator_iqn;
50
 
63
 
671
 	if ( strcmp ( value, "5" ) != 0 ) {
684
 	if ( strcmp ( value, "5" ) != 0 ) {
672
 		DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
685
 		DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
673
 		       iscsi, value );
686
 		       iscsi, value );
674
-		return -EPROTO;
687
+		return -EPROTO_INVALID_CHAP_ALGORITHM;
675
 	}
688
 	}
676
 
689
 
677
 	return 0;
690
 	return 0;
695
 	if ( *endp != '\0' ) {
708
 	if ( *endp != '\0' ) {
696
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
709
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
697
 		       iscsi, value );
710
 		       iscsi, value );
698
-		return -EPROTO;
711
+		return -EPROTO_INVALID_CHAP_IDENTIFIER;
699
 	}
712
 	}
700
 
713
 
701
 	/* Prepare for CHAP with MD5 */
714
 	/* Prepare for CHAP with MD5 */
736
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
749
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
737
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
750
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
738
 		       iscsi, value );
751
 		       iscsi, value );
739
-		return -EPROTO;
752
+		return -EPROTO_INVALID_CHAP_CHALLENGE;
740
 	}
753
 	}
741
 	value += 2;
754
 	value += 2;
742
 
755
 
748
 		if ( *endp != '\0' ) {
761
 		if ( *endp != '\0' ) {
749
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
762
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
750
 			       "byte \"%s\"\n", iscsi, buf );
763
 			       "byte \"%s\"\n", iscsi, buf );
751
-			return -EPROTO;
764
+			return -EPROTO_INVALID_CHAP_CHALLENGE;
752
 		}
765
 		}
753
 		chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
766
 		chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
754
 	}
767
 	}
793
 		DBGC ( iscsi, "iSCSI %p target username \"%s\" incorrect "
806
 		DBGC ( iscsi, "iSCSI %p target username \"%s\" incorrect "
794
 		       "(wanted \"%s\")\n",
807
 		       "(wanted \"%s\")\n",
795
 		       iscsi, value, iscsi->target_username );
808
 		       iscsi, value, iscsi->target_username );
796
-		return -EACCES;
809
+		return -EACCES_INCORRECT_TARGET_USERNAME;
797
 	}
810
 	}
798
 
811
 
799
 	return 0;
812
 	return 0;
834
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
847
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
835
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP response \"%s\"\n",
848
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP response \"%s\"\n",
836
 		       iscsi, value );
849
 		       iscsi, value );
837
-		return -EPROTO;
850
+		return -EPROTO_INVALID_CHAP_RESPONSE;
838
 	}
851
 	}
839
 	value += 2;
852
 	value += 2;
840
 
853
 
842
 	if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) {
855
 	if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) {
843
 		DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
856
 		DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
844
 		       iscsi );
857
 		       iscsi );
845
-		return -EPROTO;
858
+		return -EPROTO_INVALID_CHAP_RESPONSE;
846
 	}
859
 	}
847
 
860
 
848
 	/* Process response an octet at a time */
861
 	/* Process response an octet at a time */
853
 		if ( *endp != '\0' ) {
866
 		if ( *endp != '\0' ) {
854
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP response "
867
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP response "
855
 			       "byte \"%s\"\n", iscsi, buf );
868
 			       "byte \"%s\"\n", iscsi, buf );
856
-			return -EPROTO;
869
+			return -EPROTO_INVALID_CHAP_RESPONSE;
857
 		}
870
 		}
858
 		if ( byte != iscsi->chap.response[i] ) {
871
 		if ( byte != iscsi->chap.response[i] ) {
859
 			DBGC ( iscsi, "iSCSI %p saw incorrect CHAP "
872
 			DBGC ( iscsi, "iSCSI %p saw incorrect CHAP "
860
 			       "response\n", iscsi );
873
 			       "response\n", iscsi );
861
-			return -EACCES;
874
+			return -EACCES_INCORRECT_TARGET_PASSWORD;
862
 		}
875
 		}
863
 	}
876
 	}
864
 	assert ( i == iscsi->chap.response_len );
877
 	assert ( i == iscsi->chap.response_len );
999
 	case ISCSI_STATUS_INITIATOR_ERROR :
1012
 	case ISCSI_STATUS_INITIATOR_ERROR :
1000
 		switch ( status_detail ) {
1013
 		switch ( status_detail ) {
1001
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION :
1014
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION :
1002
-			return -EACCES;
1015
+			return -EPERM_INITIATOR_AUTHENTICATION;
1003
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION :
1016
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION :
1004
-			return -EPERM;
1017
+			return -EPERM_INITIATOR_AUTHORISATION;
1005
 		case ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND :
1018
 		case ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND :
1006
 		case ISCSI_STATUS_INITIATOR_ERROR_REMOVED :
1019
 		case ISCSI_STATUS_INITIATOR_ERROR_REMOVED :
1007
 			return -ENODEV;
1020
 			return -ENODEV;
1008
 		default :
1021
 		default :
1009
-			return -ENOTSUP;
1022
+			return -ENOTSUP_INITIATOR_STATUS;
1010
 		}
1023
 		}
1011
 	case ISCSI_STATUS_TARGET_ERROR :
1024
 	case ISCSI_STATUS_TARGET_ERROR :
1012
 		return -EIO;
1025
 		return -EIO;
1374
 			return 0;
1387
 			return 0;
1375
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1388
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1376
 		       response->opcode );
1389
 		       response->opcode );
1377
-		return -ENOTSUP;
1390
+		return -ENOTSUP_OPCODE;
1378
 	}
1391
 	}
1379
 }
1392
 }
1380
 
1393
 
1757
 	if ( ! iscsi->target_address ) {
1770
 	if ( ! iscsi->target_address ) {
1758
 		DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
1771
 		DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
1759
 		       iscsi );
1772
 		       iscsi );
1760
-		rc = -ENOTSUP;
1773
+		rc = -ENOTSUP_DISCOVERY;
1761
 		goto err;
1774
 		goto err;
1762
 	}
1775
 	}
1763
 	if ( ! iscsi->target_iqn ) {
1776
 	if ( ! iscsi->target_iqn ) {

Loading…
Cancel
Save