8#include "polkitqt1-subject.h"
9#include "polkitqt1-identity.h"
10#include "polkitqt1-config.h"
13#include <polkit/polkit.h>
18class Q_DECL_HIDDEN
Subject::Data :
public QSharedData
25 Data(
const Data& other)
27 , subject(other.subject)
29 g_object_ref(subject);
33 g_object_unref(subject);
36 PolkitSubject *subject;
44Subject::Subject(PolkitSubject *subject)
49 if (d->subject !=
nullptr) {
50 g_object_ref(d->subject);
70bool Subject::isValid()
const
72 return d->subject !=
nullptr;
80void Subject::setSubject(PolkitSubject *subject)
82 if (d->subject !=
nullptr) {
83 g_object_unref(d->subject);
97 GError *error =
nullptr;
98 subject.d->subject = polkit_subject_from_string(
string.toUtf8().data(), &error);
99 if (error !=
nullptr) {
100 qWarning() <<
QString(
"Cannot create Subject from string: %1").
arg(error->message);
109 setSubject(polkit_unix_process_new_for_owner(
pid, 0, -1));
115 setSubject(polkit_unix_process_new_for_owner(
pid,
startTime, -1));
119 : Subject((PolkitSubject *) pkUnixProcess)
126 return polkit_unix_process_get_pid((PolkitUnixProcess *)
subject());
131 return polkit_unix_process_get_start_time((PolkitUnixProcess *)
subject());
136 return polkit_unix_process_get_uid((PolkitUnixProcess *)
subject());
141 polkit_unix_process_set_pid((PolkitUnixProcess *)
subject(),
pid);
148 setSubject(polkit_system_bus_name_new(
name.toUtf8().data()));
152 : Subject((PolkitSubject *) pkSystemBusName)
164 polkit_system_bus_name_set_name((PolkitSystemBusName *)
subject(),
name.toUtf8().data());
169#if HAVE_POLKIT_SYSTEM_BUS_NAME_GET_USER_SYNC
170 return UnixUserIdentity(polkit_system_bus_name_get_user_sync((PolkitSystemBusName *)
subject(),
nullptr,
nullptr));
172 qWarning(
"Polkit is too old, returning invalid user from SystemBusNameSubject::user()!");
181 setSubject(polkit_unix_session_new(
sessionId.toUtf8().data()));
187 GError *error =
nullptr;
188 setSubject(polkit_unix_session_new_for_process_sync(pid,
nullptr, &error));
189 if (error !=
nullptr) {
190 qWarning() <<
QString(
"Cannot create unix session: %1").
arg(error->message);
196 : Subject((PolkitSubject *) pkUnixSession)
208 polkit_unix_session_set_session_id((PolkitUnixSession *)
subject(),
sessionId.toUtf8().data());
This class represents PolicyKit subjects.
QString toString() const
Serialization of object to the string.
static Subject fromString(const QString &string)
Creates the Subject object from string reprezentation.
PolkitSubject * subject() const
Gets PolkitSubject object.
void setName(const QString &name)
Sets system bus name.
UnixUserIdentity user()
Returns the UnixUserIdentity for this subject.
SystemBusNameSubject(const QString &name)
Subject constructor, takes one parameter - system bus name.
QString name() const
Returns system bus name.
void setPid(qint64 pid)
Sets Unix process PID.
qint64 uid() const
Returns Unix process UID.
UnixProcessSubject(qint64 pid)
Subject constructor, takes one parameter - PID.
qint64 startTime() const
Returns Unix process start time.
qint64 pid() const
Returns Unix process PID.
void setSessionId(const QString &sessionId)
Sets session id.
QString sessionId() const
Returns session id.
UnixSessionSubject(const QString &sessionId)
Subject constructor, takes one parameter - session id.
An object representing a user identity on a UNIX system.
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)