File indexing completed on 2024-04-21 03:53:58

0001 /*
0002     This file is part of the KDE project, module kdesu.
0003     SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only
0006 */
0007 
0008 #ifndef KDESUSSHPROCESS_H
0009 #define KDESUSSHPROCESS_H
0010 
0011 #include "stubprocess.h"
0012 
0013 #include <kdesu/kdesu_export.h>
0014 
0015 namespace KDESu
0016 {
0017 class SshProcessPrivate;
0018 
0019 /** \class SshProcess sshprocess.h KDESu/SshProcess
0020  * Executes a remote command, using ssh.
0021  */
0022 
0023 class KDESU_EXPORT SshProcess : public StubProcess
0024 {
0025 public:
0026     enum Errors {
0027         SshNotFound = 1,
0028         SshNeedsPassword,
0029         SshIncorrectPassword,
0030     };
0031 
0032     explicit SshProcess(const QByteArray &host = QByteArray(), const QByteArray &user = QByteArray(), const QByteArray &command = QByteArray());
0033     ~SshProcess() override;
0034 
0035     /**
0036      * Sets the target host.
0037      */
0038     void setHost(const QByteArray &host);
0039 
0040     /**
0041      * Sets the location of the remote stub.
0042      */
0043     void setStub(const QByteArray &stub);
0044 
0045     /**
0046      * Checks if the current user\@host needs a password.
0047      * @return The prompt for the password if a password is required. A null
0048      * string otherwise.
0049      *
0050      * @todo The return doc is so obviously wrong that the C code needs to be checked.
0051      */
0052     int checkNeedPassword();
0053 
0054     /**
0055      * Checks if the stub is installed and if the password is correct.
0056      * @return Zero if everything is correct, nonzero otherwise.
0057      */
0058     int checkInstall(const char *password);
0059 
0060     /**
0061      * Executes the command.
0062      */
0063     int exec(const char *password, int check = 0);
0064 
0065     QByteArray prompt() const;
0066     QByteArray error() const;
0067 
0068 protected:
0069     void virtual_hook(int id, void *data) override;
0070     QByteArray display() override;
0071     QByteArray displayAuth() override;
0072 
0073 private:
0074     KDESU_NO_EXPORT int converseSsh(const char *password, int check);
0075 
0076 private:
0077     Q_DECLARE_PRIVATE(SshProcess)
0078 };
0079 
0080 }
0081 
0082 #endif // KDESUSSHPROCESS_H