1/*
2 This file is part of the KDE project, module kdesu.
3 SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-only
6*/
7
8#ifndef KDESUSSHPROCESS_H
9#define KDESUSSHPROCESS_H
10
11#include "stubprocess.h"
12
13#include <kdesu/kdesu_export.h>
14
15namespace KDESu
16{
17class SshProcessPrivate;
18
19/*!
20 * \class KDESu::SshProcess
21 * \inmodule KDESu
22 * \inheaderfile KDESu/SshProcess
23 *
24 * \brief Executes a remote command, using ssh.
25 */
26class KDESU_EXPORT SshProcess : public StubProcess
27{
28public:
29 /*!
30 * \value SshNotFound
31 * \value SshNeedsPassword
32 * \value SshIncorrectPassword
33 */
34 enum Errors {
35 SshNotFound = 1,
36 SshNeedsPassword,
37 SshIncorrectPassword,
38 };
39
40 /*!
41 *
42 */
43 explicit SshProcess(const QByteArray &host = QByteArray(), const QByteArray &user = QByteArray(), const QByteArray &command = QByteArray());
44 ~SshProcess() override;
45
46 /*!
47 * Sets the target host.
48 */
49 void setHost(const QByteArray &host);
50
51 /*!
52 * Sets the location of the remote stub.
53 */
54 void setStub(const QByteArray &stub);
55
56 // TODO The return doc is so obviously wrong that the C code needs to be checked.
57 /*!
58 * Checks if the current user\@host needs a password.
59 *
60 * Returns the prompt for the password if a password is required. A null
61 * string otherwise.
62 */
63 int checkNeedPassword();
64
65 /*!
66 * Checks if the stub is installed and if the password is correct.
67 *
68 * Returns zero if everything is correct, nonzero otherwise.
69 */
70 int checkInstall(const char *password);
71
72 /*!
73 * Executes the command.
74 */
75 int exec(const char *password, int check = 0);
76
77 /*!
78 *
79 */
80 QByteArray prompt() const;
81
82 /*!
83 *
84 */
85 QByteArray error() const;
86
87protected:
88 void virtual_hook(int id, void *data) override;
89 QByteArray display() override;
90 QByteArray displayAuth() override;
91
92private:
93 KDESU_NO_EXPORT int converseSsh(const char *password, int check);
94
95private:
96 Q_DECLARE_PRIVATE(SshProcess)
97};
98
99}
100
101#endif // KDESUSSHPROCESS_H
102

source code of kdesu/src/sshprocess.h