1 | /* |
2 | This file is part of the KDE project, module kdesu. |
3 | SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <jansen@kde.org> |
4 | |
5 | SPDX-License-Identifier: GPL-2.0-only |
6 | */ |
7 | |
8 | #ifndef KDESUSUPROCESS_H |
9 | #define KDESUSUPROCESS_H |
10 | |
11 | #include <kdesu/kdesu_export.h> |
12 | |
13 | #include "stubprocess.h" |
14 | |
15 | namespace KDESu |
16 | { |
17 | class SuProcessPrivate; |
18 | |
19 | /*! |
20 | * \class KDESu::SuProcess |
21 | * \inmodule KDESu |
22 | * \inheaderfile KDESu/SuProcess |
23 | * |
24 | * \brief Executes a command under elevated privileges, using su. |
25 | */ |
26 | |
27 | class KDESU_EXPORT SuProcess : public StubProcess |
28 | { |
29 | public: |
30 | /*! |
31 | * \value SuNotFound |
32 | * \value SuNotAllowed |
33 | * \value SuIncorrectPassword |
34 | */ |
35 | enum Errors { |
36 | SuNotFound = 1, |
37 | SuNotAllowed, |
38 | SuIncorrectPassword, |
39 | }; |
40 | |
41 | /*! |
42 | * Executes the command. This will wait for the command to finish. |
43 | * |
44 | * \value NoCheck |
45 | * \value Install |
46 | * \value NeedPassword |
47 | */ |
48 | enum checkMode { |
49 | NoCheck = 0, |
50 | Install = 1, |
51 | NeedPassword = 2, |
52 | }; |
53 | |
54 | /*! |
55 | * |
56 | */ |
57 | explicit SuProcess(const QByteArray &user = nullptr, const QByteArray &command = nullptr); |
58 | ~SuProcess() override; |
59 | |
60 | /*! |
61 | * |
62 | */ |
63 | int exec(const char *password, int check = NoCheck); |
64 | |
65 | /*! |
66 | * Checks if the stub is installed and the password is correct. |
67 | * |
68 | * Returns zero if everything is correct, nonzero otherwise. |
69 | */ |
70 | int checkInstall(const char *password); |
71 | |
72 | /*! |
73 | * Checks if a password is needed. |
74 | */ |
75 | int checkNeedPassword(); |
76 | |
77 | /*! |
78 | * Checks what the default super user command is, e.g. sudo, su, etc |
79 | * |
80 | * Returns the default super user command |
81 | */ |
82 | QString superUserCommand(); |
83 | |
84 | /*! |
85 | * Checks whether or not the user's password is being asked for or another |
86 | * user's password. Due to usage of systems such as sudo, even when attempting |
87 | * to switch to another user one may need to enter their own password. |
88 | */ |
89 | bool useUsersOwnPassword(); |
90 | |
91 | protected: |
92 | void virtual_hook(int id, void *data) override; |
93 | |
94 | private: |
95 | enum SuErrors { |
96 | error = -1, |
97 | ok = 0, |
98 | killme = 1, |
99 | notauthorized = 2, |
100 | }; |
101 | |
102 | KDESU_NO_EXPORT int converseSU(const char *password); |
103 | |
104 | private: |
105 | Q_DECLARE_PRIVATE(SuProcess) |
106 | }; |
107 | |
108 | } |
109 | |
110 | #endif // KDESUSUPROCESS_H |
111 | |