| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/ftp/ftp_network_transaction.h" | 5 #include "net/ftp/ftp_network_transaction.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 const std::string command = "EPSV"; | 958 const std::string command = "EPSV"; |
| 959 next_state_ = STATE_CTRL_READ; | 959 next_state_ = STATE_CTRL_READ; |
| 960 return SendFtpCommand(command, command, COMMAND_EPSV); | 960 return SendFtpCommand(command, command, COMMAND_EPSV); |
| 961 } | 961 } |
| 962 | 962 |
| 963 int FtpNetworkTransaction::ProcessResponseEPSV( | 963 int FtpNetworkTransaction::ProcessResponseEPSV( |
| 964 const FtpCtrlResponse& response) { | 964 const FtpCtrlResponse& response) { |
| 965 switch (GetErrorClass(response.status_code)) { | 965 switch (GetErrorClass(response.status_code)) { |
| 966 case ERROR_CLASS_INITIATED: | 966 case ERROR_CLASS_INITIATED: |
| 967 return Stop(ERR_INVALID_RESPONSE); | 967 return Stop(ERR_INVALID_RESPONSE); |
| 968 case ERROR_CLASS_OK: | 968 case ERROR_CLASS_OK: { |
| 969 if (!ExtractPortFromEPSVResponse( response, &data_connection_port_)) | 969 int port; |
| 970 if (!ExtractPortFromEPSVResponse(response, &port)) |
| 970 return Stop(ERR_INVALID_RESPONSE); | 971 return Stop(ERR_INVALID_RESPONSE); |
| 971 if (data_connection_port_ < 1024 || | 972 if (port < 1024 || !IsPortAllowedByFtp(port)) |
| 972 !IsPortAllowedByFtp(data_connection_port_)) | |
| 973 return Stop(ERR_UNSAFE_PORT); | 973 return Stop(ERR_UNSAFE_PORT); |
| 974 data_connection_port_ = static_cast<uint16>(port); |
| 974 next_state_ = STATE_DATA_CONNECT; | 975 next_state_ = STATE_DATA_CONNECT; |
| 975 break; | 976 break; |
| 977 } |
| 976 case ERROR_CLASS_INFO_NEEDED: | 978 case ERROR_CLASS_INFO_NEEDED: |
| 977 return Stop(ERR_INVALID_RESPONSE); | 979 return Stop(ERR_INVALID_RESPONSE); |
| 978 case ERROR_CLASS_TRANSIENT_ERROR: | 980 case ERROR_CLASS_TRANSIENT_ERROR: |
| 979 case ERROR_CLASS_PERMANENT_ERROR: | 981 case ERROR_CLASS_PERMANENT_ERROR: |
| 980 use_epsv_ = false; | 982 use_epsv_ = false; |
| 981 next_state_ = STATE_CTRL_WRITE_PASV; | 983 next_state_ = STATE_CTRL_WRITE_PASV; |
| 982 return OK; | 984 return OK; |
| 983 default: | 985 default: |
| 984 NOTREACHED(); | 986 NOTREACHED(); |
| 985 return Stop(ERR_UNEXPECTED); | 987 return Stop(ERR_UNEXPECTED); |
| 986 } | 988 } |
| 987 return OK; | 989 return OK; |
| 988 } | 990 } |
| 989 | 991 |
| 990 // PASV command | 992 // PASV command |
| 991 int FtpNetworkTransaction::DoCtrlWritePASV() { | 993 int FtpNetworkTransaction::DoCtrlWritePASV() { |
| 992 std::string command = "PASV"; | 994 std::string command = "PASV"; |
| 993 next_state_ = STATE_CTRL_READ; | 995 next_state_ = STATE_CTRL_READ; |
| 994 return SendFtpCommand(command, command, COMMAND_PASV); | 996 return SendFtpCommand(command, command, COMMAND_PASV); |
| 995 } | 997 } |
| 996 | 998 |
| 997 int FtpNetworkTransaction::ProcessResponsePASV( | 999 int FtpNetworkTransaction::ProcessResponsePASV( |
| 998 const FtpCtrlResponse& response) { | 1000 const FtpCtrlResponse& response) { |
| 999 switch (GetErrorClass(response.status_code)) { | 1001 switch (GetErrorClass(response.status_code)) { |
| 1000 case ERROR_CLASS_INITIATED: | 1002 case ERROR_CLASS_INITIATED: |
| 1001 return Stop(ERR_INVALID_RESPONSE); | 1003 return Stop(ERR_INVALID_RESPONSE); |
| 1002 case ERROR_CLASS_OK: | 1004 case ERROR_CLASS_OK: { |
| 1003 if (!ExtractPortFromPASVResponse(response, &data_connection_port_)) | 1005 int port; |
| 1006 if (!ExtractPortFromPASVResponse(response, &port)) |
| 1004 return Stop(ERR_INVALID_RESPONSE); | 1007 return Stop(ERR_INVALID_RESPONSE); |
| 1005 if (data_connection_port_ < 1024 || | 1008 if (port < 1024 || !IsPortAllowedByFtp(port)) |
| 1006 !IsPortAllowedByFtp(data_connection_port_)) | |
| 1007 return Stop(ERR_UNSAFE_PORT); | 1009 return Stop(ERR_UNSAFE_PORT); |
| 1010 data_connection_port_ = static_cast<uint16>(port); |
| 1008 next_state_ = STATE_DATA_CONNECT; | 1011 next_state_ = STATE_DATA_CONNECT; |
| 1009 break; | 1012 break; |
| 1013 } |
| 1010 case ERROR_CLASS_INFO_NEEDED: | 1014 case ERROR_CLASS_INFO_NEEDED: |
| 1011 return Stop(ERR_INVALID_RESPONSE); | 1015 return Stop(ERR_INVALID_RESPONSE); |
| 1012 case ERROR_CLASS_TRANSIENT_ERROR: | 1016 case ERROR_CLASS_TRANSIENT_ERROR: |
| 1013 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); | 1017 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); |
| 1014 case ERROR_CLASS_PERMANENT_ERROR: | 1018 case ERROR_CLASS_PERMANENT_ERROR: |
| 1015 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); | 1019 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); |
| 1016 default: | 1020 default: |
| 1017 NOTREACHED(); | 1021 NOTREACHED(); |
| 1018 return Stop(ERR_UNEXPECTED); | 1022 return Stop(ERR_UNEXPECTED); |
| 1019 } | 1023 } |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 if (!had_error_type[type]) { | 1397 if (!had_error_type[type]) { |
| 1394 had_error_type[type] = true; | 1398 had_error_type[type] = true; |
| 1395 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1399 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
| 1396 type, NUM_OF_NET_ERROR_TYPES); | 1400 type, NUM_OF_NET_ERROR_TYPES); |
| 1397 } | 1401 } |
| 1398 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1402 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
| 1399 type, NUM_OF_NET_ERROR_TYPES); | 1403 type, NUM_OF_NET_ERROR_TYPES); |
| 1400 } | 1404 } |
| 1401 | 1405 |
| 1402 } // namespace net | 1406 } // namespace net |
| OLD | NEW |