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 KDESUSTUBPROCESS_H |
9 | #define KDESUSTUBPROCESS_H |
10 | |
11 | #include "ptyprocess.h" |
12 | |
13 | #include <kdesu/kdesu_export.h> |
14 | |
15 | #include <QByteArray> |
16 | #include <QList> |
17 | |
18 | namespace KDESu |
19 | { |
20 | namespace KDESuPrivate |
21 | { |
22 | class KCookie; |
23 | } |
24 | class StubProcessPrivate; |
25 | |
26 | /*! |
27 | * \class KDESu::StubProcess |
28 | * \inmodule KDESu |
29 | * \inheaderfile KDESu/StubProcess |
30 | * |
31 | * \brief Chat with kdesu_stub. |
32 | * |
33 | * StubProcess extends PtyProcess with functionality to chat with kdesu_stub. |
34 | */ |
35 | class KDESU_EXPORT StubProcess : public PtyProcess |
36 | { |
37 | public: |
38 | /*! |
39 | * Different schedulers. SchedNormal is the normal Unix timesharing |
40 | * scheduler, while SchedRealtime is a POSIX.1b realtime scheduler. |
41 | * |
42 | * \value SchedNormal |
43 | * \value SchedRealtime |
44 | */ |
45 | enum Scheduler { |
46 | SchedNormal, |
47 | SchedRealtime, |
48 | }; |
49 | |
50 | /*! |
51 | * |
52 | */ |
53 | StubProcess(); |
54 | ~StubProcess() override; |
55 | |
56 | /*! |
57 | * Set the command. |
58 | */ |
59 | void setCommand(const QByteArray &command); |
60 | |
61 | /*! |
62 | * Set the target user. |
63 | */ |
64 | void setUser(const QByteArray &user); |
65 | |
66 | /*! |
67 | * Set to "X only mode": Sycoca is not built and kdeinit is not launched. |
68 | */ |
69 | void setXOnly(bool xonly); |
70 | |
71 | /*! |
72 | * Set the priority of the process. The priority value must be between 0 |
73 | * and 100, 0 being the lowest priority. This value is mapped to the |
74 | * scheduler and system dependent priority range of the OS. |
75 | */ |
76 | void setPriority(int prio); |
77 | |
78 | /*! |
79 | * Set the scheduler type. |
80 | */ |
81 | void setScheduler(int sched); |
82 | |
83 | protected: |
84 | void virtual_hook(int id, void *data) override; |
85 | |
86 | /*! |
87 | * Exchange all parameters with kdesu_stub. |
88 | */ |
89 | int converseStub(int check); |
90 | |
91 | /*! |
92 | * This virtual function can be overloaded when special behavior is |
93 | * desired. By default, it returns the value returned by KCookie. |
94 | */ |
95 | virtual QByteArray display(); |
96 | |
97 | /*! |
98 | * See display. |
99 | */ |
100 | virtual QByteArray displayAuth(); |
101 | |
102 | // KF6 TODO: move to StubProcessPrivate |
103 | bool m_XOnly; |
104 | int m_priority; |
105 | int m_scheduler; |
106 | QByteArray m_command; |
107 | QByteArray m_user; |
108 | KDESuPrivate::KCookie *m_cookie; |
109 | |
110 | private: |
111 | KDESU_NO_EXPORT void writeString(const QByteArray &str); |
112 | |
113 | protected: |
114 | KDESU_NO_EXPORT explicit StubProcess(StubProcessPrivate &dd); |
115 | |
116 | private: |
117 | Q_DECLARE_PRIVATE(StubProcess) |
118 | }; |
119 | |
120 | } |
121 | |
122 | #endif // KDESUSTUBPROCESS_H |
123 | |