KDESu

suprocess.h
1 /*
2  This file is part of the KDE project, module kdesu.
3  SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <[email protected]>
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_D(PtyProcess::d, SuProcess)
85 #if KDESU_BUILD_DEPRECATED_SINCE(5, 79)
86  // Unused, kept for ABI compatibility
87  const void *__kdesu_d_do_not_use;
88 #endif
89 };
90 
91 }
92 
93 #endif // KDESUSUPROCESS_H
checkMode
Executes the command.
Definition: suprocess.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 30 2023 03:48:44 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.