diff options
Diffstat (limited to 'tdeioslave/sftp/tdeio_sftp.h')
-rw-r--r-- | tdeioslave/sftp/tdeio_sftp.h | 77 |
1 files changed, 70 insertions, 7 deletions
diff --git a/tdeioslave/sftp/tdeio_sftp.h b/tdeioslave/sftp/tdeio_sftp.h index 8e46d815c..75b295cfd 100644 --- a/tdeioslave/sftp/tdeio_sftp.h +++ b/tdeioslave/sftp/tdeio_sftp.h @@ -31,6 +31,7 @@ #include <tdeio/slavebase.h> #include <kdebug.h> #include <stdint.h> +#include <memory> #include <libssh/libssh.h> #include <libssh/sftp.h> @@ -95,10 +96,18 @@ public: void log_callback(ssh_session session, int priority, const char *message, void *userdata); + // Callbacks for SSHAuthMethod-derived strategies + int authenticatePublicKey(); + int authenticateKeyboardInteractive(bool noPaswordQuery = false); + int authenticatePassword(bool noPaswordQuery = false); + + /** Some extra authentication failure reasons intended to use alongside was declared in libssh */ + enum extra_ssh_auth_e { + SSH_AUTH_CANCELED=128, //< user canceled password entry dialog + SSH_AUTH_NEED_RECONNECT //< it is required to reinitialize connection from scratch + }; private: // Private variables - void statMime(const KURL &url); - void closeFile(); /** True if ioslave is connected to sftp server. */ bool mConnected; @@ -114,10 +123,16 @@ private: // Private variables /** The sftp session for the connection */ sftp_session mSftp; - /** Username to use when connecting */ + /** Username to use when connecting, Note: it's the one passed in the URL */ TQString mUsername; - /** User's password */ + /** Username to use with the next connection attempt: it's either from the cached data or from + * the password dialog that was prompted to the user. */ + TQString mCachedUsername; + + /** User's password. Note: the password would be set only if it was somehow cached: passed to + * setHost(), received from passwdserver's cache or was entered by user before reconnection + */ TQString mPassword; /** The open file */ @@ -138,12 +153,39 @@ private: // Private variables // TQString text; //}; - TDEIO::AuthInfo *pubKeyInfo; + /** Some data needed to interact with auth_callback() */ + struct { + /** List of keys user was already prompted to enter the passphrase for. + * Note: Under most sane circumstances the list shouldn't go beyond size=2, + * so no fancy containers here + */ + TQStringList attemptedKeys; + /** A backup for SlaveBase::s_seqNr to pass the same value to prompts for different keys */ + long current_seqNr; + /** true if callback was called */ + bool wasCalled; + /** true if user canceled all passphrase entry dialogues */ + bool wasCanceled; + } mPubKeyAuthData; + + /** true if the password dialog was prompted to the user at leas once */ + bool mPasswordWasPrompted = false; private: // private methods + void statMime(const KURL &url); + void closeFile(); - int authenticateKeyboardInteractive(TDEIO::AuthInfo &info); - void clearPubKeyAuthInfo(); + /** @returns username used by libssh during the connection */ + TQString sshUsername(); + + /** Adds ssh error (if any) to the given message string */ + TQString sshError(TQString errMsg=TQString()); + + /** A small helper function to construct auth info skeleton for the protocol */ + TDEIO::AuthInfo authInfo(); + + /** A helper function encapsulating creation of an ssh connection before authentication */ + int initializeConnection(); void reportError(const KURL &url, const int err); @@ -153,4 +195,25 @@ private: // private methods TQString canonicalizePath(const TQString &path); }; +/** A base class for ssh authentication methods. */ +class SSHAuthMethod { +public: + /** libssh's flag for he method */ + virtual unsigned flag() = 0; + /** The user-friendly (probably translated) name of the method */ + virtual TQString name() {return flagToStr(flag());} + /** Actually do perform the auth process */ + virtual int authenticate(sftpProtocol *ioslave) const = 0; + /** Creates a copy of derived class */ + virtual SSHAuthMethod* clone() = 0; + + virtual ~SSHAuthMethod() {}; + + /** Returns a name for the given libssh auth method flag */ + static TQString flagToStr(unsigned method); + + /** Returns a list of names for all the methods set in the given libssh auth method bitset */ + static TQStringList bitsetToStr(unsigned method); +}; + #endif |