summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorRyan Chu <ryan.chu@qt.io>2017-12-12 15:06:43 +0100
committerRyan Chu <ryan.chu@qt.io>2018-01-09 13:31:55 +0000
commita5ad605dfec2ab4e921d5c5843b23916ed5ae3bf (patch)
treed1ca33421f00f9d92c9e6f7c15c6acadbd79bc87 /src/network
parent6ff8d8173d3056d8bd232e6c11da328a300915d5 (diff)
QFtp: only use fall-back password for anonymous access
The code used to fall back to anonymous login independently for username and password; however, it should only use a fall-back password if the username is missing or (case-insensitive) "anonymous". When a non-anonymous username is given without password, we should simply skip he PASS message to FTP. If the FTP server requests a password, in the latter case, QFtp will signal authenticationRequired; in all cases, if the server rejects the given credentials, QFtp signals authenticationFailed. Either way, the client code can then query the user for credentials as usual. Task-number: QTBUG-25033 Change-Id: I2a4a3b2725819ab19c8a7e4baa431af539edcd8d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qftp.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 762ef00225..719e3536b4 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -1702,8 +1702,16 @@ int QFtp::connectToHost(const QString &host, quint16 port)
int QFtp::login(const QString &user, const QString &password)
{
QStringList cmds;
- cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n"));
- cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n"));
+
+ if (user.isNull() || user.compare(QLatin1String("anonymous"), Qt::CaseInsensitive) == 0) {
+ cmds << (QLatin1String("USER ") + (user.isNull() ? QLatin1String("anonymous") : user) + QLatin1String("\r\n"));
+ cmds << (QLatin1String("PASS ") + (password.isNull() ? QLatin1String("anonymous@") : password) + QLatin1String("\r\n"));
+ } else {
+ cmds << (QLatin1String("USER ") + user + QLatin1String("\r\n"));
+ if (!password.isNull())
+ cmds << (QLatin1String("PASS ") + password + QLatin1String("\r\n"));
+ }
+
return d_func()->addCommand(new QFtpCommand(Login, cmds));
}