File indexing completed on 2024-04-21 03:53:59

0001 /*
0002     This file is part of the KDE project, module kdesu.
0003     SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <jansen@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only
0006 */
0007 
0008 #ifndef KDESUSTUBPROCESS_H
0009 #define KDESUSTUBPROCESS_H
0010 
0011 #include "ptyprocess.h"
0012 
0013 #include <kdesu/kdesu_export.h>
0014 
0015 #include <QByteArray>
0016 #include <QList>
0017 
0018 namespace KDESu
0019 {
0020 namespace KDESuPrivate
0021 {
0022 class KCookie;
0023 }
0024 class StubProcessPrivate;
0025 
0026 /** \class StubProcess stubprocess.h KDESu/StubProcess
0027  * Chat with kdesu_stub.
0028  *
0029  * StubProcess extends PtyProcess with functionality to chat with kdesu_stub.
0030  */
0031 
0032 class KDESU_EXPORT StubProcess : public PtyProcess
0033 {
0034 public:
0035     /**
0036      * Different schedulers. SchedNormal is the normal Unix timesharing
0037      * scheduler, while SchedRealtime is a POSIX.1b realtime scheduler.
0038      */
0039     enum Scheduler {
0040         SchedNormal,
0041         SchedRealtime,
0042     };
0043 
0044     StubProcess();
0045     ~StubProcess() override;
0046 
0047     /**
0048      * Set the command.
0049      */
0050     void setCommand(const QByteArray &command);
0051 
0052     /**
0053      * Set the target user.
0054      */
0055     void setUser(const QByteArray &user);
0056 
0057     /**
0058      * Set to "X only mode": Sycoca is not built and kdeinit is not launched.
0059      */
0060     void setXOnly(bool xonly);
0061 
0062     /**
0063      * Set the priority of the process. The priority value must be between 0
0064      * and 100, 0 being the lowest priority. This value is mapped to the
0065      * scheduler and system dependent priority range of the OS.
0066      */
0067     void setPriority(int prio);
0068 
0069     /**
0070      * Set the scheduler type.
0071      */
0072     void setScheduler(int sched);
0073 
0074 protected:
0075     void virtual_hook(int id, void *data) override;
0076 
0077     /**
0078      * Exchange all parameters with kdesu_stub.
0079      */
0080     int converseStub(int check);
0081 
0082     /**
0083      * This virtual function can be overloaded when special behavior is
0084      * desired. By default, it returns the value returned by KCookie.
0085      */
0086     virtual QByteArray display();
0087 
0088     /**
0089      * See display.
0090      */
0091     virtual QByteArray displayAuth();
0092 
0093     // KF6 TODO: move to StubProcessPrivate
0094     bool m_XOnly;
0095     int m_priority;
0096     int m_scheduler;
0097     QByteArray m_command;
0098     QByteArray m_user;
0099     KDESuPrivate::KCookie *m_cookie;
0100 
0101 private:
0102     KDESU_NO_EXPORT void writeString(const QByteArray &str);
0103 
0104 protected:
0105     KDESU_NO_EXPORT explicit StubProcess(StubProcessPrivate &dd);
0106 
0107 private:
0108     Q_DECLARE_PRIVATE(StubProcess)
0109 };
0110 
0111 }
0112 
0113 #endif // KDESUSTUBPROCESS_H