File indexing completed on 2024-04-21 04:43:23

0001 /*
0002     This file is part of the PolKit1-qt project
0003     SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef POLKITQT1_SUBJECT_H
0009 #define POLKITQT1_SUBJECT_H
0010 
0011 #include "polkitqt1-core-export.h"
0012 
0013 #include <QObject>
0014 #include <QSharedData>
0015 
0016 typedef struct _PolkitSubject PolkitSubject;
0017 typedef struct _PolkitUnixProcess PolkitUnixProcess;
0018 typedef struct _PolkitSystemBusName PolkitSystemBusName;
0019 
0020 /**
0021  * \namespace PolkitQt1 PolkitQt
0022  *
0023  * \brief Namespace wrapping PolicyKit-Qt classes
0024  *
0025  * This namespace wraps all PolicyKit-Qt classes.
0026  */
0027 namespace PolkitQt1
0028 {
0029 
0030 class UnixUserIdentity;
0031 
0032 /**
0033  * \class Subject polkitqt1-subject.h Subject
0034  * \author Jaroslav Reznik <jreznik@redhat.com>
0035  *
0036  * \brief This class represents PolicyKit subjects
0037  *
0038  * This class encapsulates the PolkitSubject interface.
0039  *
0040  * \see UnixProcess
0041  * \see SystemBusName
0042  * \see UnixSession
0043  */
0044 class POLKITQT1_CORE_EXPORT Subject
0045 {
0046 public:
0047     Subject();
0048     Subject(const Subject &other);
0049     ~Subject();
0050 
0051     Subject &operator=(const Subject &other);
0052 
0053     bool isValid() const;
0054 
0055     /**
0056      * Serialization of object to the string
0057      *
0058      * \return Serialized Subject object
0059      */
0060     QString toString() const;
0061 
0062     /**
0063      * Creates the Subject object from string reprezentation
0064      *
0065      * \param string string reprezentation of the object
0066      *
0067      * \return Pointer to new Subject instance
0068      */
0069     static Subject fromString(const QString &string);
0070 
0071     /**
0072      * Gets PolkitSubject object.
0073      *
0074      * \warning It shouldn't be used directly unless you are completely aware of what are you doing
0075      *
0076      * \return Pointer to PolkitSubject instance
0077      */
0078     PolkitSubject *subject() const;
0079 
0080 protected:
0081     Subject(PolkitSubject *subject);
0082 
0083     void setSubject(PolkitSubject *subject);
0084 
0085 private:
0086     class Data;
0087     QExplicitlySharedDataPointer< Data > d;
0088 };
0089 
0090 /**
0091  * \class UnixProcessSubject polkitqt1-subject.h Subject
0092  * \author Jaroslav Reznik <jreznik@redhat.com>
0093  *
0094  * \brief A class for representing a UNIX process.
0095  *
0096  * To uniquely identify processes, both the process
0097  * id and the start time of the process (a monotonic
0098  * increasing value representing the time since the
0099  * kernel was started) is used.
0100  *
0101  * \sa Subject
0102  */
0103 class POLKITQT1_CORE_EXPORT UnixProcessSubject : public Subject
0104 {
0105 public:
0106     /**
0107     * Subject constructor, takes one parameter - PID. The start time
0108     * of process will be looked automatically.
0109     *
0110     * \param pid An Unix process PID.
0111     */
0112     explicit UnixProcessSubject(qint64 pid);
0113 
0114     /**
0115     * Subject constructor, takes two parameters - PID and start time.
0116     *
0117     * \param pid An Unix process PID.
0118     * \param startTime An Unix process start time.
0119     */
0120     UnixProcessSubject(qint64 pid, quint64 startTime);
0121 
0122     /**
0123      * Subject constructor, it creates UnixProcess object from PolkitUnixProcess object
0124      *
0125      * \warning Use this only if you are completely aware of what are you doing!
0126      *
0127      * \param process PolkitUnixProcess object
0128      */
0129     explicit UnixProcessSubject(PolkitUnixProcess *process);
0130 
0131     /**
0132     * Returns Unix process PID.
0133     *
0134     * \return A PID of associated Unix process.
0135     */
0136     qint64 pid() const;
0137 
0138     /**
0139     * Returns Unix process start time.
0140     *
0141     * \return A start time of associated Unix process.
0142     */
0143     qint64 startTime() const;
0144 
0145     /**
0146     * Returns Unix process UID.
0147     *
0148     * \return A UID of associated Unix process.
0149     */
0150     qint64 uid() const;
0151 
0152     /**
0153     * Sets Unix process PID.
0154     *
0155     * \param pid An Unix process PID.
0156     */
0157     void setPid(qint64 pid);
0158 };
0159 
0160 /**
0161  * \class SystemBusNameSubject polkitqt1-subject.h Subject
0162  * \author Jaroslav Reznik <jreznik@redhat.com>
0163  *
0164  * \brief A class for representing a process owning a unique name on the system bus.
0165  *
0166  * \sa Subject
0167  */
0168 class POLKITQT1_CORE_EXPORT SystemBusNameSubject : public Subject
0169 {
0170 public:
0171     /**
0172     * Subject constructor, takes one parameter - system bus name.
0173     *
0174     * \param name A unique system bus name.
0175     */
0176     explicit SystemBusNameSubject(const QString &name);
0177 
0178     /**
0179      * Subject constructor, it creates SystemBusName object from PolkitSystemBusName object
0180      *
0181      * \warning Use this only if you are completely aware of what are you doing!
0182      *
0183      * \param pkSystemBusName PolkitSystemBusName object
0184      */
0185     explicit SystemBusNameSubject(PolkitSystemBusName *pkSystemBusName);
0186 
0187     /**
0188     * Returns system bus name.
0189     *
0190     * \return A unique system bus name.
0191     */
0192     QString name() const;
0193 
0194     /**
0195     * Sets system bus name.
0196     *
0197     * \param name System bus name.
0198     */
0199     void setName(const QString &name);
0200 
0201     /**
0202      * Returns the UnixUserIdentity for this subject.
0203      *
0204      * \note This can be an invalid UnixUserIdentity so be sure to check before using it
0205      *
0206      * \since 0.113
0207      **/
0208     UnixUserIdentity user();
0209 };
0210 
0211 /**
0212  * \class UnixSessionSubject polkitqt1-subject.h Subject
0213  * \author Jaroslav Reznik <jreznik@redhat.com>
0214  *
0215  * \brief A class for representing unix session.
0216  *
0217  * The session id is an opaque string obtained from
0218  * ConsoleKit.
0219  *
0220  * \sa Subject
0221  */
0222 class POLKITQT1_CORE_EXPORT UnixSessionSubject : public Subject
0223 {
0224 public:
0225     /**
0226     * Subject constructor, takes one parameter - session id.
0227     *
0228     * \param sessionId The session id.
0229     */
0230     explicit UnixSessionSubject(const QString &sessionId);
0231 
0232     /**
0233     * Subject constructor, takes one parameter - pid of process.
0234     *
0235     * Synchronous!
0236     *
0237     * \param pid The session's process pid.
0238     */
0239     explicit UnixSessionSubject(qint64 pid);
0240 
0241     /**
0242      * Subject constructor, it creates UnixSession object from PolkitUnixSession object
0243      *
0244      * \warning Use this only if you are completely aware of what are you doing!
0245      *
0246      * \param pkUnixSession PolkitUnixSession object
0247      */
0248     explicit UnixSessionSubject(PolkitSystemBusName *pkUnixSession);
0249 
0250     /**
0251     * Returns session id.
0252     *
0253     * \return A session id.
0254     */
0255     QString sessionId() const;
0256 
0257     /**
0258     * Sets session id.
0259     *
0260     * \param sessionId A session id.
0261     */
0262     void setSessionId(const QString &sessionId);
0263 };
0264 
0265 }
0266 
0267 #endif