summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-01-27 22:09:30 +0300
committerTDE Gitea <gitea@mirror.git.trinitydesktop.org>2024-03-04 11:04:11 +0000
commit009382772da4cb5a56749ea67ed29c09658a4f69 (patch)
tree96902c5aa59a3eacd89367f51aa8a34b7c7f1014
parent581d266ae6f085317b4247b2d1ddbc12c8fa09fb (diff)
downloadtdebase-009382772da4cb5a56749ea67ed29c09658a4f69.tar.gz
tdebase-009382772da4cb5a56749ea67ed29c09658a4f69.zip
tdeioslave/sftp: enable changing user during kb-interactive auth
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
-rw-r--r--tdeioslave/sftp/tdeio_sftp.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/tdeioslave/sftp/tdeio_sftp.cpp b/tdeioslave/sftp/tdeio_sftp.cpp
index 1664725a5..dcefc45f1 100644
--- a/tdeioslave/sftp/tdeio_sftp.cpp
+++ b/tdeioslave/sftp/tdeio_sftp.cpp
@@ -365,6 +365,7 @@ int sftpProtocol::authenticateKeyboardInteractive(bool noPaswordQuery) {
for (i = 0; i < n; ++i) {
char echo;
+ bool isPassword=false;
TQString answer;
TQString errMsg;
@@ -390,6 +391,7 @@ int sftpProtocol::authenticateKeyboardInteractive(bool noPaswordQuery) {
if (prompt.lower().startsWith("password")) {
// We can assume that the ssh server asks for a password and we will handle that case
// with more care since it's what most users will see
+ isPassword = true;
if (noPaswordQuery) { // if we have a cached password we might use it
kdDebug(TDEIO_SFTP_DB) << "Using cached password" << endl;
answer = mPassword;
@@ -412,15 +414,25 @@ int sftpProtocol::authenticateKeyboardInteractive(bool noPaswordQuery) {
infoKbdInt.prompt.append("\n\n").append(instruction);
}
infoKbdInt.prompt.append("\n\n").append(prompt);
+ infoKbdInt.readOnly = true; // set username readonly (enable changing it only with password)
}
- infoKbdInt.readOnly = true; // set username readonly
- /* FIXME: We can query a new user name but we will have to reinitialize the connection if
- * it changes <2024-01-10 Fat-Zer> */
if (answer.isNull()) {
if (openPassDlg(infoKbdInt, errMsg)) {
answer = infoKbdInt.password;
kdDebug(TDEIO_SFTP_DB) << "Got the answer from the password dialog" << endl;
+
+ if (isPassword) {
+ TQString sshUser=sshUsername();
+ if (infoKbdInt.username != sshUser) {
+ kdDebug(TDEIO_SFTP_DB) << "Username changed from " << sshUser
+ << " to " << infoKbdInt.username << endl;
+ mCachedUsername = infoKbdInt.username;
+ mPassword = infoKbdInt.password;
+
+ return sftpProtocol::SSH_AUTH_NEED_RECONNECT;
+ }
+ }
} else {
return sftpProtocol::SSH_AUTH_CANCELED;
}