public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-x86 commit in kde-base/kdebase-kioslaves/files: kdebase-kioslaves-4.7.0-sftp.patch
@ 2011-08-27 22:07 Andreas HAttel (dilfridge)
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas HAttel (dilfridge) @ 2011-08-27 22:07 UTC (permalink / raw
  To: gentoo-commits

dilfridge    11/08/27 22:07:04

  Added:                kdebase-kioslaves-4.7.0-sftp.patch
  Log:
  Add upstream patch to fix sftp authentication, bug 380707
  
  (Portage version: 2.1.10.11/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  kde-base/kdebase-kioslaves/files/kdebase-kioslaves-4.7.0-sftp.patch

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/kde-base/kdebase-kioslaves/files/kdebase-kioslaves-4.7.0-sftp.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/kde-base/kdebase-kioslaves/files/kdebase-kioslaves-4.7.0-sftp.patch?rev=1.1&content-type=text/plain

Index: kdebase-kioslaves-4.7.0-sftp.patch
===================================================================
commit 23e4ab03091e9d824e78171ea92a2da2326256d8
Author: Dawit Alemayehu <adawit@kde.org>
Date:   Thu Aug 25 00:29:14 2011 -0400

    Fix the logic for user name change redirection so it won't break normal
    login into sftp servers.

diff --git a/kioslave/sftp/kio_sftp.cpp b/kioslave/sftp/kio_sftp.cpp
index eb5c8a8..2a55ff9 100644
--- a/kioslave/sftp/kio_sftp.cpp
+++ b/kioslave/sftp/kio_sftp.cpp
@@ -429,12 +429,11 @@ sftpProtocol::~sftpProtocol() {
 }
 
 void sftpProtocol::setHost(const QString& host, quint16 port, const QString& user, const QString& pass) {
-  kDebug(KIO_SFTP_DB) << "setHost(): " << user << "@" << host << ":" << port;
+  kDebug(KIO_SFTP_DB) << user << "@" << host << ":" << port;
 
   // Close connection if the request is to another server...
-  if (mConnected &&
-      (host != mHost || port != mPort ||
-       user != mUsername || pass != mPassword)) {
+  if (host != mHost || port != mPort ||
+      user != mUsername || pass != mPassword) {
     closeConnection();
   }
 
@@ -451,9 +450,7 @@ void sftpProtocol::setHost(const QString& host, quint16 port, const QString& use
     }
   }
 
-  kDebug(KIO_SFTP_DB) << "setHost(): mPort=" << mPort;
-
-  mUsername = mOrigUsername = user;
+  mUsername = user;
   mPassword = pass;
 }
 
@@ -479,6 +476,7 @@ void sftpProtocol::openConnection() {
   info.url.setPort(mPort);
   info.url.setUser(mUsername);
   info.username = mUsername;
+  const QString origPasswd (mPassword);
 
   // Check for cached authentication info if no password is specified...
   if (mPassword.isEmpty()) {
@@ -497,6 +495,7 @@ void sftpProtocol::openConnection() {
   int rc, state, hlen;
   int timeout_sec = 30, timeout_usec = 0;
 
+login_start:
   mSession = ssh_new();
   if (mSession == NULL) {
     error(KIO::ERR_INTERNAL, i18n("Could not create a new SSH session."));
@@ -722,8 +721,12 @@ void sftpProtocol::openConnection() {
       firstTime = false;
 
       if (!mUsername.isEmpty() && mUsername != info.username) {
-        info.url.setUser(info.username); // update the AuthInfo URL's username
         kDebug(KIO_SFTP_DB) << "Username changed from" << mUsername << "to" << info.username;
+        info.url.setUser(info.username);
+        mUsername = info.username;
+        mPassword = info.password;
+        closeConnection();
+        goto login_start;
       }
     }
 
@@ -770,6 +773,7 @@ void sftpProtocol::openConnection() {
   setTimeoutSpecialCommand(KIO_SFTP_SPECIAL_TIMEOUT);
 
   mConnected = true;
+  mPassword = origPasswd;
   connected();
 
   info.password.fill('x');
@@ -777,13 +781,17 @@ void sftpProtocol::openConnection() {
 }
 
 void sftpProtocol::closeConnection() {
-  kDebug(KIO_SFTP_DB) << "closeConnection()";
+  kDebug(KIO_SFTP_DB);
 
-  sftp_free(mSftp);
-  mSftp = NULL;
+  if (mSftp) {
+    sftp_free(mSftp);
+    mSftp = NULL;
+  }
 
-  ssh_disconnect(mSession);
-  mSession = NULL;
+  if (mSession) {
+    ssh_disconnect(mSession);
+    mSession = NULL;
+  }
 
   mConnected = false;
 }
@@ -1824,28 +1832,28 @@ sftpProtocol::GetRequest::~GetRequest() {
   sftp_attributes_free(mSb);
 }
 
-bool sftpProtocol::requiresUserNameRedirection()
+void sftpProtocol::requiresUserNameRedirection()
 {
-    kDebug(KIO_SFTP_DB) << "Connected ?" << mConnected << "Original:" << mOrigUsername << "Current:" << mUsername;
-    if (!mConnected || mOrigUsername.isEmpty() || mOrigUsername == mUsername)
-        return false;
-
-    KUrl realURL;
-    realURL.setProtocol( QLatin1String("sftp") );
-    realURL.setUser( mUsername );
-    realURL.setPass( mPassword );
-    realURL.setHost( mHost );
-    if ( mPort > 0)
-      realURL.setPort( mPort );
-    kDebug(KIO_SFTP_DB) << "User name changed! Redirecting to" << realURL.prettyUrl();
-    redirection( realURL );
-    finished();
-    mOrigUsername = mUsername;
-    return true;
+    KUrl redirectUrl;
+    redirectUrl.setProtocol( QLatin1String("sftp") );
+    redirectUrl.setUser( mUsername );
+    redirectUrl.setPass( mPassword );
+    redirectUrl.setHost( mHost );
+    if (mPort > 0)
+      redirectUrl.setPort( mPort );
+    kDebug(KIO_SFTP_DB) << "redirecting to" << redirectUrl;
+    redirection( redirectUrl );
 }
 
 bool sftpProtocol::sftpConnect()
 {
+    const QString origUsername = mUsername;
     openConnection();
-    return !requiresUserNameRedirection();
+    kDebug(KIO_SFTP_DB) << "connected ?" << mConnected << "username: old=" << origUsername << "new=" << mUsername;
+    if (!origUsername.isEmpty() && origUsername != mUsername) {
+        requiresUserNameRedirection();
+        finished();
+        return false;
+    }
+    return true;
 }
diff --git a/kioslave/sftp/kio_sftp.h b/kioslave/sftp/kio_sftp.h
index 7cd16d1..c937e2e 100644
--- a/kioslave/sftp/kio_sftp.h
+++ b/kioslave/sftp/kio_sftp.h
@@ -101,9 +101,6 @@ private: // Private variables
   /** The sftp session for the connection */
   sftp_session mSftp;
 
-  /** Username originally set when setHost was called. */
-  QString mOrigUsername;
-
   /** Username to use when connecting */
   QString mUsername;
 
@@ -194,7 +191,7 @@ private: // private methods
                       KIO::UDSEntry &entry, short int details);
 
   QString canonicalizePath(const QString &path);
-  bool requiresUserNameRedirection();
+  void requiresUserNameRedirection();
   bool sftpConnect();
 };
 






^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] gentoo-x86 commit in kde-base/kdebase-kioslaves/files: kdebase-kioslaves-4.7.0-sftp.patch
@ 2011-12-12  0:49 Jonathan Callen (abcd)
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Callen (abcd) @ 2011-12-12  0:49 UTC (permalink / raw
  To: gentoo-commits

abcd        11/12/12 00:49:48

  Removed:              kdebase-kioslaves-4.7.0-sftp.patch
  Log:
  rm old files
  
  (Portage version: 2.2.0_alpha80/cvs/Linux x86_64)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-12  0:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12  0:49 [gentoo-commits] gentoo-x86 commit in kde-base/kdebase-kioslaves/files: kdebase-kioslaves-4.7.0-sftp.patch Jonathan Callen (abcd)
  -- strict thread matches above, loose matches on Subject: below --
2011-08-27 22:07 Andreas HAttel (dilfridge)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox