I'm trying to ask polkit for authorization but I can't seem to find out how to provide a struct as an argument.
QDBusArgument subject;
subject.beginStructure();
subject << "unix-process";
subject << QMap<QString, QVariant>{
{"pid", static_cast<uint32_t>(QCoreApplication::applicationPid())},
{"start-time", static_cast<uint64_t>(0)},
};
subject.endStructure();
QDBusInterface polkit("org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", "org.freedesktop.PolicyKit1.Authority");
auto result = polkit.callWithArgumentList(
QDBus::CallMode::AutoDetect,
"CheckAuthorization",
{
// how to provide the subject here?
}
);
The QDBusArgument shows what the argument should look like and I somehow need to translate this to a format that can be used in callWithArgumentList
.
FreeDesktop specifies the struct as such:
{
String subject_kind,
Dict<String,Variant> subject_details
}
More specifically, I'm trying to replace this with a dbus call:
// checkProcess is *QProcess
checkProcess->start("pkcheck", {
"--process",
QString::number(QCoreApplication::applicationPid()),
"--action-id",
"my-custom-action-id",
"--allow-user-interaction"
});
I'm not too familiar with D-Bus or its Qt interface, but I do happen to have a linux system I could test this on. It seems that you were already well on your way, I was able to get a response from the polkit service after some small adjustments:
This resulted in the following output:
Some further remarks:
Once these requirements are met, you should be able to get meaningful output from D-Bus, even if you pass the wrong arguments. For example, leaving out the last string argument to CheckAuthorization leads to an InvalidArgs error response with the message
The string encodes the expected types