1 | /* vi: ts=8 sts=4 sw=4 |
2 | |
3 | This file is part of the KDE project, module kdesu. |
4 | SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <jansen@kde.org> |
5 | */ |
6 | |
7 | #ifndef __Handler_h_included__ |
8 | #define __Handler_h_included__ |
9 | |
10 | #include <sys/types.h> |
11 | |
12 | #include "secure.h" |
13 | #include <QByteArray> |
14 | |
15 | /** |
16 | * A ConnectionHandler handles a client. It is called from the main program |
17 | * loop whenever there is data to read from a corresponding socket. |
18 | * It keeps reading data until a newline is read. Then, a command is parsed |
19 | * and executed. |
20 | */ |
21 | |
22 | class ConnectionHandler : public SocketSecurity |
23 | { |
24 | public: |
25 | ConnectionHandler(int fd); |
26 | ~ConnectionHandler(); |
27 | |
28 | ConnectionHandler(const ConnectionHandler &) = delete; |
29 | ConnectionHandler &operator=(const ConnectionHandler &) = delete; |
30 | |
31 | /** Handle incoming data. */ |
32 | int handle(); |
33 | |
34 | /* Send back exit code. */ |
35 | void sendExitCode(); |
36 | |
37 | private: |
38 | enum Results { |
39 | Res_OK, |
40 | Res_NO, |
41 | }; |
42 | |
43 | int doCommand(QByteArray buf); |
44 | void respond(int ok, const QByteArray &s = QByteArray()); |
45 | QByteArray makeKey(int namspace, const QByteArray &s1, const QByteArray &s2 = QByteArray(), const QByteArray &s3 = QByteArray()) const; |
46 | |
47 | int m_Fd, m_Timeout; |
48 | int m_Priority, m_Scheduler; |
49 | QByteArray m_Buf, m_Pass, m_Host; |
50 | |
51 | public: |
52 | int m_exitCode; |
53 | bool m_hasExitCode; |
54 | bool m_needExitCode; |
55 | pid_t m_pid; |
56 | }; |
57 | |
58 | #endif |
59 | |