File indexing completed on 2024-05-05 03:54:29
0001 /* vi: ts=8 sts=4 sw=4 0002 0003 This file is part of the KDE project, module kdesu. 0004 SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <jansen@kde.org> 0005 */ 0006 0007 #ifndef __Handler_h_included__ 0008 #define __Handler_h_included__ 0009 0010 #include <sys/types.h> 0011 0012 #include "secure.h" 0013 #include <QByteArray> 0014 0015 /** 0016 * A ConnectionHandler handles a client. It is called from the main program 0017 * loop whenever there is data to read from a corresponding socket. 0018 * It keeps reading data until a newline is read. Then, a command is parsed 0019 * and executed. 0020 */ 0021 0022 class ConnectionHandler : public SocketSecurity 0023 { 0024 public: 0025 ConnectionHandler(int fd); 0026 ~ConnectionHandler(); 0027 0028 ConnectionHandler(const ConnectionHandler &) = delete; 0029 ConnectionHandler &operator=(const ConnectionHandler &) = delete; 0030 0031 /** Handle incoming data. */ 0032 int handle(); 0033 0034 /* Send back exit code. */ 0035 void sendExitCode(); 0036 0037 private: 0038 enum Results { 0039 Res_OK, 0040 Res_NO, 0041 }; 0042 0043 int doCommand(QByteArray buf); 0044 void respond(int ok, const QByteArray &s = QByteArray()); 0045 QByteArray makeKey(int namspace, const QByteArray &s1, const QByteArray &s2 = QByteArray(), const QByteArray &s3 = QByteArray()) const; 0046 0047 int m_Fd, m_Timeout; 0048 int m_Priority, m_Scheduler; 0049 QByteArray m_Buf, m_Pass, m_Host; 0050 0051 public: 0052 int m_exitCode; 0053 bool m_hasExitCode; 0054 bool m_needExitCode; 0055 pid_t m_pid; 0056 }; 0057 0058 #endif