1 | /* vi: ts=8 sts=4 sw=4 |
2 | * |
3 | * This file is part of the KDE project, module kdesu. |
4 | * Copyright (C) 2000 Geert Jansen <jansen@kde.org> |
5 | * |
6 | * This is free software; you can use this library under the GNU Library |
7 | * General Public License, version 2. See the file "COPYING.LIB" for the |
8 | * exact licensing terms. |
9 | */ |
10 | |
11 | #ifndef __SSH_h_Included__ |
12 | #define __SSH_h_Included__ |
13 | |
14 | #include "stub.h" |
15 | |
16 | #include <kdesu/kdesu_export.h> |
17 | |
18 | namespace KDESu { |
19 | |
20 | /** \class SshProcess ssh.h kdesu/ssh.h |
21 | * Executes a remote command, using ssh. |
22 | */ |
23 | |
24 | class KDESU_EXPORT SshProcess: public StubProcess |
25 | { |
26 | public: |
27 | explicit SshProcess(const QByteArray &host = QByteArray(), |
28 | const QByteArray &user = QByteArray(), |
29 | const QByteArray &command = QByteArray()); |
30 | ~SshProcess(); |
31 | |
32 | enum Errors { SshNotFound=1, SshNeedsPassword, SshIncorrectPassword }; |
33 | |
34 | /** |
35 | * Sets the target host. |
36 | */ |
37 | void setHost(const QByteArray &host); |
38 | |
39 | /** |
40 | * Sets the localtion of the remote stub. |
41 | */ |
42 | void setStub(const QByteArray &stub); |
43 | |
44 | /** |
45 | * Checks if the current user\@host needs a password. |
46 | * @return The prompt for the password if a password is required. A null |
47 | * string otherwise. |
48 | * |
49 | * @todo The return doc is so obviously wrong that the C code needs to be checked. |
50 | */ |
51 | int checkNeedPassword(); |
52 | |
53 | /** |
54 | * Checks if the stub is installed and if the password is correct. |
55 | * @return Zero if everything is correct, nonzero otherwise. |
56 | */ |
57 | int checkInstall(const char *password); |
58 | |
59 | /** |
60 | * Executes the command. |
61 | */ |
62 | int exec(const char *password, int check=0); |
63 | |
64 | QByteArray prompt() const; |
65 | QByteArray error() const; |
66 | |
67 | protected: |
68 | virtual QByteArray display(); |
69 | virtual QByteArray displayAuth(); |
70 | |
71 | private: |
72 | int ConverseSsh(const char *password, int check); |
73 | |
74 | protected: |
75 | virtual void virtual_hook( int id, void* data ); |
76 | private: |
77 | class SshProcessPrivate; |
78 | SshProcessPrivate * const d; |
79 | }; |
80 | |
81 | } |
82 | |
83 | #endif |
84 | |