Guest User

Untitled

a guest
Apr 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.48 KB | None | 0 0
  1. diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c
  2. index 8beeb87..fa1bb39 100644
  3. --- a/src/net/tcp/iscsi.c
  4. +++ b/src/net/tcp/iscsi.c
  5. @@ -131,6 +131,14 @@ FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
  6.     __einfo_error ( EINFO_EPROTO_INVALID_CHAP_RESPONSE )
  7.  #define EINFO_EPROTO_INVALID_CHAP_RESPONSE \
  8.     __einfo_uniqify ( EINFO_EPROTO, 0x04, "Invalid CHAP response" )
  9. +#define EPROTO_INVALID_KEY_VALUE_PAIR \
  10. +   __einfo_error ( EINFO_EPROTO_INVALID_KEY_VALUE_PAIR )
  11. +#define EINFO_EPROTO_INVALID_KEY_VALUE_PAIR \
  12. +   __einfo_uniqify ( EINFO_EPROTO, 0x05, "Invalid key/value pair" )
  13. +#define EPROTO_VALUE_REJECTED \
  14. +   __einfo_error ( EINFO_EPROTO_VALUE_REJECTED )
  15. +#define EINFO_EPROTO_VALUE_REJECTED                    \
  16. +   __einfo_uniqify ( EINFO_EPROTO, 0x06, "Parameter rejected" )
  17.  
  18.  static void iscsi_start_tx ( struct iscsi_session *iscsi );
  19.  static void iscsi_start_login ( struct iscsi_session *iscsi );
  20. @@ -1083,8 +1091,8 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
  21.  struct iscsi_string_type {
  22.     /** String key
  23.      *
  24. -    * This is the portion up to and including the "=" sign,
  25. -    * e.g. "InitiatorName=", "CHAP_A=", etc.
  26. +    * This is the portion preceding the "=" sign,
  27. +    * e.g. "InitiatorName", "CHAP_A", etc.
  28.      */
  29.     const char *key;
  30.     /** Handle iSCSI string value
  31. @@ -1098,13 +1106,13 @@ struct iscsi_string_type {
  32.  
  33.  /** iSCSI text strings that we want to handle */
  34.  static struct iscsi_string_type iscsi_string_types[] = {
  35. -   { "TargetAddress=", iscsi_handle_targetaddress_value },
  36. -   { "AuthMethod=", iscsi_handle_authmethod_value },
  37. -   { "CHAP_A=", iscsi_handle_chap_a_value },
  38. -   { "CHAP_I=", iscsi_handle_chap_i_value },
  39. -   { "CHAP_C=", iscsi_handle_chap_c_value },
  40. -   { "CHAP_N=", iscsi_handle_chap_n_value },
  41. -   { "CHAP_R=", iscsi_handle_chap_r_value },
  42. +   { "TargetAddress", iscsi_handle_targetaddress_value },
  43. +   { "AuthMethod", iscsi_handle_authmethod_value },
  44. +   { "CHAP_A", iscsi_handle_chap_a_value },
  45. +   { "CHAP_I", iscsi_handle_chap_i_value },
  46. +   { "CHAP_C", iscsi_handle_chap_c_value },
  47. +   { "CHAP_N", iscsi_handle_chap_n_value },
  48. +   { "CHAP_R", iscsi_handle_chap_r_value },
  49.     { NULL, NULL }
  50.  };
  51.  
  52. @@ -1118,16 +1126,35 @@ static struct iscsi_string_type iscsi_string_types[] = {
  53.  static int iscsi_handle_string ( struct iscsi_session *iscsi,
  54.                  const char *string ) {
  55.     struct iscsi_string_type *type;
  56. +   const char *separator;
  57. +   const char *value;
  58.     size_t key_len;
  59.     int rc;
  60.  
  61. +   /* Find separator */
  62. +   separator = strchr ( string, '=' );
  63. +   if ( ! separator ) {
  64. +       DBGC ( iscsi, "iSCSI %p malformed string %s\n",
  65. +              iscsi, string );
  66. +       return -EPROTO_INVALID_KEY_VALUE_PAIR;
  67. +   }
  68. +   key_len = ( separator - string );
  69. +   value = ( separator + 1 );
  70. +
  71. +   /* Check for rejections.  Since we send only non-rejectable
  72. +    * values, any rejection is a fatal protocol error.
  73. +    */
  74. +   if ( strcmp ( value, "Reject" ) == 0 ) {
  75. +       DBGC ( iscsi, "iSCSI %p rejection: %s\n", iscsi, string );
  76. +       return -EPROTO_VALUE_REJECTED;
  77. +   }
  78. +
  79. +   /* Handle key/value pair */
  80.     for ( type = iscsi_string_types ; type->key ; type++ ) {
  81. -       key_len = strlen ( type->key );
  82.         if ( strncmp ( string, type->key, key_len ) != 0 )
  83.             continue;
  84.         DBGC ( iscsi, "iSCSI %p handling %s\n", iscsi, string );
  85. -       if ( ( rc = type->handle ( iscsi,
  86. -                      ( string + key_len ) ) ) != 0 ) {
  87. +       if ( ( rc = type->handle ( iscsi, value ) ) != 0 ) {
  88.             DBGC ( iscsi, "iSCSI %p could not handle %s: %s\n",
  89.                    iscsi, string, strerror ( rc ) );
  90.             return rc;
Add Comment
Please, Sign In to add comment