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 | /** \class SuProcess suprocess.h KDESu/SuProcess |
20 | * Executes a command under elevated privileges, using su. |
21 | */ |
22 | |
23 | class KDESU_EXPORT SuProcess : public StubProcess |
24 | { |
25 | public: |
26 | enum Errors { |
27 | SuNotFound = 1, |
28 | SuNotAllowed, |
29 | SuIncorrectPassword, |
30 | }; |
31 | |
32 | /** |
33 | * Executes the command. This will wait for the command to finish. |
34 | */ |
35 | enum checkMode { |
36 | NoCheck = 0, |
37 | Install = 1, |
38 | NeedPassword = 2, |
39 | }; |
40 | |
41 | explicit SuProcess(const QByteArray &user = nullptr, const QByteArray &command = nullptr); |
42 | ~SuProcess() override; |
43 | |
44 | int exec(const char *password, int check = NoCheck); |
45 | |
46 | /** |
47 | * Checks if the stub is installed and the password is correct. |
48 | * @return Zero if everything is correct, nonzero otherwise. |
49 | */ |
50 | int checkInstall(const char *password); |
51 | |
52 | /** |
53 | * Checks if a password is needed. |
54 | */ |
55 | int checkNeedPassword(); |
56 | |
57 | /** |
58 | * Checks what the default super user command is, e.g. sudo, su, etc |
59 | * @return the default super user command |
60 | */ |
61 | QString superUserCommand(); |
62 | |
63 | /** |
64 | * Checks whether or not the user's password is being asked for or another |
65 | * user's password. Due to usage of systems such as sudo, even when attempting |
66 | * to switch to another user one may need to enter their own password. |
67 | */ |
68 | bool useUsersOwnPassword(); |
69 | |
70 | protected: |
71 | void virtual_hook(int id, void *data) override; |
72 | |
73 | private: |
74 | enum SuErrors { |
75 | error = -1, |
76 | ok = 0, |
77 | killme = 1, |
78 | notauthorized = 2, |
79 | }; |
80 | |
81 | KDESU_NO_EXPORT int converseSU(const char *password); |
82 | |
83 | private: |
84 | Q_DECLARE_PRIVATE(SuProcess) |
85 | }; |
86 | |
87 | } |
88 | |
89 | #endif // KDESUSUPROCESS_H |
90 | |