kdecore: remove unused KAuth backend methods

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-09-25 09:54:03 +03:00
parent 6287f9c468
commit 9df491ec50
8 changed files with 43 additions and 205 deletions

View file

@ -23,47 +23,14 @@
namespace KAuth namespace KAuth
{ {
class AuthBackend::Private
{
public:
Private() {}
virtual ~Private() {}
Capabilities capabilities;
};
AuthBackend::AuthBackend() AuthBackend::AuthBackend()
: QObject(0) : QObject(0)
, d(new Private)
{ {
} }
AuthBackend::~AuthBackend() AuthBackend::~AuthBackend()
{ {
delete d;
}
AuthBackend::Capabilities AuthBackend::capabilities() const
{
return d->capabilities;
}
void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
{
d->capabilities = capabilities;
}
bool AuthBackend::actionExists(const QString& action)
{
Q_UNUSED(action);
return false;
}
void AuthBackend::preAuthAction(const QString& action, QWidget* parent)
{
Q_UNUSED(action)
Q_UNUSED(parent)
} }
} //namespace KAuth } //namespace KAuth

View file

@ -34,41 +34,19 @@ class AuthBackend : public QObject
Q_DISABLE_COPY(AuthBackend) Q_DISABLE_COPY(AuthBackend)
public: public:
enum Capability {
NoCapability = 0,
AuthorizeFromClientCapability = 1,
AuthorizeFromHelperCapability = 2,
CheckActionExistenceCapability = 4,
PreAuthActionCapability = 8
};
Q_DECLARE_FLAGS(Capabilities, Capability)
AuthBackend(); AuthBackend();
virtual ~AuthBackend(); virtual ~AuthBackend();
virtual void setupAction(const QString &action) = 0;
virtual void preAuthAction(const QString &action, QWidget *parent);
virtual Action::AuthStatus authorizeAction(const QString &action) = 0; virtual Action::AuthStatus authorizeAction(const QString &action) = 0;
virtual Action::AuthStatus actionStatus(const QString &action) = 0; virtual Action::AuthStatus actionStatus(const QString &action) = 0;
virtual QByteArray callerID() const = 0; virtual bool isCallerAuthorized(const QString &action) = 0;
virtual bool isCallerAuthorized(const QString &action, QByteArray callerID) = 0;
virtual bool actionExists(const QString &action);
Capabilities capabilities() const;
protected:
void setCapabilities(Capabilities capabilities);
Q_SIGNALS: Q_SIGNALS:
void actionStatusChanged(const QString &action, Action::AuthStatus status); void actionStatusChanged(const QString &action, Action::AuthStatus status);
private:
class Private;
Private * const d;
}; };
} // namespace Auth } // namespace Auth
Q_DECLARE_INTERFACE(KAuth::AuthBackend, "org.kde.auth.AuthBackend/0.1") Q_DECLARE_INTERFACE(KAuth::AuthBackend, "org.kde.auth.AuthBackend/0.1")
Q_DECLARE_OPERATORS_FOR_FLAGS(KAuth::AuthBackend::Capabilities)
#endif #endif

View file

@ -33,7 +33,6 @@ namespace KAuth
DBusBackend::DBusBackend() DBusBackend::DBusBackend()
: AuthBackend() : AuthBackend()
{ {
setCapabilities(AuthorizeFromClientCapability | AuthorizeFromHelperCapability);
} }
Action::AuthStatus DBusBackend::authorizeAction(const QString &action) Action::AuthStatus DBusBackend::authorizeAction(const QString &action)
@ -41,32 +40,17 @@ Action::AuthStatus DBusBackend::authorizeAction(const QString &action)
return actionStatus(action); return actionStatus(action);
} }
void DBusBackend::setupAction(const QString &action)
{
Q_UNUSED(action)
}
Action::AuthStatus DBusBackend::actionStatus(const QString &action) Action::AuthStatus DBusBackend::actionStatus(const QString &action)
{ {
if (isCallerAuthorized(action, callerID())) { if (isCallerAuthorized(action)) {
return Action::Authorized; return Action::Authorized;
} else { } else {
return Action::Denied; return Action::Denied;
} }
} }
QByteArray DBusBackend::callerID() const bool DBusBackend::isCallerAuthorized(const QString &action)
{ {
QByteArray a;
QDataStream s(&a, QIODevice::WriteOnly);
s << QCoreApplication::applicationPid();
return a;
}
bool DBusBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
Q_UNUSED(callerID)
QDBusMessage message; QDBusMessage message;
QRegExp rx(QLatin1String("(\\S+\\.\\S+\\.\\S+\\.\\S+)\\.")); QRegExp rx(QLatin1String("(\\S+\\.\\S+\\.\\S+\\.\\S+)\\."));

View file

@ -34,11 +34,10 @@ class DBusBackend : public AuthBackend
public: public:
DBusBackend(); DBusBackend();
virtual void setupAction(const QString&);
virtual Action::AuthStatus authorizeAction(const QString&); Action::AuthStatus authorizeAction(const QString&) final;
virtual Action::AuthStatus actionStatus(const QString&); Action::AuthStatus actionStatus(const QString&) final;
virtual QByteArray callerID() const; bool isCallerAuthorized(const QString &action) final;
virtual bool isCallerAuthorized(const QString &action, QByteArray callerID);
}; };
} // namespace Auth } // namespace Auth

View file

@ -72,7 +72,7 @@ bool DBusHelperProxy::executeActions(const QList<QPair<QString, QVariantMap> > &
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performActions")); message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performActions"));
QList<QVariant> args; QList<QVariant> args;
args << blob << BackendsManager::authBackend()->callerID(); args << blob;
message.setArguments(args); message.setArguments(args);
QDBusPendingCall reply = QDBusConnection::systemBus().asyncCall(message); // This is a NO_REPLY method QDBusPendingCall reply = QDBusConnection::systemBus().asyncCall(message); // This is a NO_REPLY method
@ -107,7 +107,7 @@ ActionReply DBusHelperProxy::executeAction(const QString &action, const QString
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performAction")); message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performAction"));
QList<QVariant> args; QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID() << blob; args << action << blob;
message.setArguments(args); message.setArguments(args);
m_actionsInProgress.push_back(action); m_actionsInProgress.push_back(action);
@ -159,7 +159,7 @@ Action::AuthStatus DBusHelperProxy::authorizeAction(const QString& action, const
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("authorizeAction")); message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("authorizeAction"));
QList<QVariant> args; QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID(); args << action;
message.setArguments(args); message.setArguments(args);
m_actionsInProgress.push_back(action); m_actionsInProgress.push_back(action);
@ -250,7 +250,7 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest; return m_stopRequest;
} }
void DBusHelperProxy::performActions(QByteArray blob, const QByteArray &callerID) void DBusHelperProxy::performActions(QByteArray blob)
{ {
QDataStream stream(&blob, QIODevice::ReadOnly); QDataStream stream(&blob, QIODevice::ReadOnly);
QList< QPair< QString, QVariantMap > > actions; QList< QPair< QString, QVariantMap > > actions;
@ -264,13 +264,13 @@ void DBusHelperProxy::performActions(QByteArray blob, const QByteArray &callerID
stream << i->second; stream << i->second;
performAction(i->first, callerID, blob); performAction(i->first, blob);
++i; ++i;
} }
} }
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments) QByteArray DBusHelperProxy::performAction(const QString &action, QByteArray arguments)
{ {
if (!responder) { if (!responder) {
return ActionReply::NoResponderReply.serialized(); return ActionReply::NoResponderReply.serialized();
@ -294,7 +294,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>(); QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop(); timer->stop();
if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) { if (BackendsManager::authBackend()->isCallerAuthorized(action)) {
QString slotname = action; QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) { if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1); slotname = slotname.right(slotname.length() - m_name.length() - 1);
@ -324,7 +324,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
} }
uint DBusHelperProxy::authorizeAction(const QString& action, const QByteArray& callerID) uint DBusHelperProxy::authorizeAction(const QString& action)
{ {
if (!m_currentAction.isEmpty()) { if (!m_currentAction.isEmpty()) {
return static_cast<uint>(Action::Error); return static_cast<uint>(Action::Error);
@ -337,7 +337,7 @@ uint DBusHelperProxy::authorizeAction(const QString& action, const QByteArray& c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>(); QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop(); timer->stop();
if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) { if (BackendsManager::authBackend()->isCallerAuthorized(action)) {
retVal = static_cast<uint>(Action::Authorized); retVal = static_cast<uint>(Action::Authorized);
} else { } else {
retVal = static_cast<uint>(Action::Denied); retVal = static_cast<uint>(Action::Denied);

View file

@ -49,23 +49,23 @@ class DBusHelperProxy : public HelperProxy
public: public:
DBusHelperProxy() : responder(0), m_stopRequest(false) {} DBusHelperProxy() : responder(0), m_stopRequest(false) {}
virtual bool executeActions(const QList<QPair<QString, QVariantMap> > &list, const QString &helperID); bool executeActions(const QList<QPair<QString, QVariantMap> > &list, const QString &helperID) final;
virtual ActionReply executeAction(const QString &action, const QString &helperID, const QVariantMap &arguments); ActionReply executeAction(const QString &action, const QString &helperID, const QVariantMap &arguments) final;
virtual Action::AuthStatus authorizeAction(const QString& action, const QString& helperID); Action::AuthStatus authorizeAction(const QString& action, const QString& helperID) final;
virtual void stopAction(const QString &action, const QString &helperID); void stopAction(const QString &action, const QString &helperID) final;
virtual bool initHelper(const QString &name); bool initHelper(const QString &name) final;
virtual void setHelperResponder(QObject *o); void setHelperResponder(QObject *o) final;
virtual bool hasToStopAction(); bool hasToStopAction() final;
virtual void sendDebugMessage(int level, const char *msg); void sendDebugMessage(int level, const char *msg) final;
virtual void sendProgressStep(int step); void sendProgressStep(int step) final;
virtual void sendProgressStep(const QVariantMap &data); void sendProgressStep(const QVariantMap &data) final;
public slots: public slots:
void stopAction(const QString &action); void stopAction(const QString &action);
void performActions(QByteArray blob, const QByteArray &callerID); void performActions(QByteArray blob);
QByteArray performAction(const QString &action, const QByteArray &callerID, QByteArray arguments); QByteArray performAction(const QString &action, QByteArray arguments);
uint authorizeAction(const QString &action, const QByteArray &callerID); uint authorizeAction(const QString &action);
signals: signals:
void remoteSignal(int type, const QString &action, const QByteArray &blob); // This signal is sent from the helper to the app void remoteSignal(int type, const QString &action, const QByteArray &blob); // This signal is sent from the helper to the app

View file

@ -3,18 +3,15 @@
<interface name="org.kde.auth"> <interface name="org.kde.auth">
<method name="performAction" > <method name="performAction" >
<arg name="action" type="s" direction="in" /> <arg name="action" type="s" direction="in" />
<arg name="callerID" type="ay" direction="in" />
<arg name="arguments" type="ay" direction="in" /> <arg name="arguments" type="ay" direction="in" />
<arg name="r" type="ay" direction="out" /> <arg name="r" type="ay" direction="out" />
</method> </method>
<method name="authorizeAction" > <method name="authorizeAction" >
<arg name="action" type="s" direction="in" /> <arg name="action" type="s" direction="in" />
<arg name="callerID" type="ay" direction="in" />
<arg name="r" type="u" direction="out" /> <arg name="r" type="u" direction="out" />
</method> </method>
<method name="performActions" > <method name="performActions" >
<arg name="blob" type="ay" direction="in" /> <arg name="blob" type="ay" direction="in" />
<arg name="callerID" type="ay" direction="in" />
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/> <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method> </method>
<method name="stopAction" > <method name="stopAction" >

View file

@ -59,7 +59,6 @@ Action::Action(const QString &name)
: d(new Private()) : d(new Private())
{ {
setName(name); setName(name);
BackendsManager::authBackend()->setupAction(d->name);
} }
Action::Action(const QString &name, const QString &details) Action::Action(const QString &name, const QString &details)
@ -67,7 +66,6 @@ Action::Action(const QString &name, const QString &details)
{ {
setName(name); setName(name);
setDetails(details); setDetails(details);
BackendsManager::authBackend()->setupAction(d->name);
} }
Action::~Action() Action::~Action()
@ -104,16 +102,10 @@ void Action::setName(const QString &name)
{ {
d->name = name; d->name = name;
// Does the backend support checking for known actions? // Check through a regexp
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::CheckActionExistenceCapability) {
// In this case, just ask the backend
d->valid = BackendsManager::authBackend()->actionExists(name);
} else {
// Otherwise, check through a regexp
QRegExp exp(QLatin1String("[0-z]+(\\.[0-z]+)*")); QRegExp exp(QLatin1String("[0-z]+(\\.[0-z]+)*"));
d->valid = exp.exactMatch(name); d->valid = exp.exactMatch(name);
} }
}
QString Action::details() const QString Action::details() const
{ {
@ -179,32 +171,7 @@ Action::AuthStatus Action::authorize() const
return Action::Invalid; return Action::Invalid;
} }
// If there is any pre auth action, let's perform it
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {
BackendsManager::authBackend()->preAuthAction(d->name, d->parent);
}
// Let's check capabilities
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromClientCapability) {
// That's easy then
return BackendsManager::authBackend()->authorizeAction(d->name); return BackendsManager::authBackend()->authorizeAction(d->name);
} else if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromHelperCapability) {
// We need to check if we have an helper in this case
if (hasHelper()) {
// Ok, we need to use "helper authorization".
return BackendsManager::helperProxy()->authorizeAction(d->name, d->helperId);
} else {
// Ok, in this case we have to fake and just pretend we are an helper
if (BackendsManager::authBackend()->isCallerAuthorized(d->name, BackendsManager::authBackend()->callerID())) {
return Authorized;
} else {
return Denied;
}
}
} else {
// This should never, never happen
return Invalid;
}
} }
@ -213,21 +180,7 @@ Action::AuthStatus Action::earlyAuthorize() const
// Check the status first // Check the status first
AuthStatus s = status(); AuthStatus s = status();
if (s == AuthRequired) { if (s == AuthRequired) {
// Let's check what to do
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromClientCapability) {
// In this case we can actually try an authorization
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {
BackendsManager::authBackend()->preAuthAction(d->name, d->parent);
}
return BackendsManager::authBackend()->authorizeAction(d->name); return BackendsManager::authBackend()->authorizeAction(d->name);
} else if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromHelperCapability) {
// In this case, just throw out Authorized, as the auth will take place later
return Authorized;
} else {
// This should never, never happen
return Invalid;
}
} else { } else {
// It's fine, return the status // It's fine, return the status
return s; return s;
@ -256,11 +209,6 @@ bool Action::executeActions(const QList< Action >& actions, QList< Action >* den
foreach(const Action &a, actions) { foreach(const Action &a, actions) {
// Save us an additional step // Save us an additional step
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromClientCapability) {
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {
BackendsManager::authBackend()->preAuthAction(a.name(), parent);
}
AuthStatus s = BackendsManager::authBackend()->authorizeAction(a.name()); AuthStatus s = BackendsManager::authBackend()->authorizeAction(a.name());
if (s == Authorized) { if (s == Authorized) {
@ -268,12 +216,6 @@ bool Action::executeActions(const QList< Action >& actions, QList< Action >* den
} else if ((s == Denied || s == Invalid) && deniedActions) { } else if ((s == Denied || s == Invalid) && deniedActions) {
*deniedActions << a; *deniedActions << a;
} }
} else if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromHelperCapability) {
list.push_back(QPair<QString, QVariantMap>(a.name(), a.arguments()));
} else {
// There's something totally wrong here
return false;
}
} }
if (list.isEmpty()) { if (list.isEmpty()) {
@ -308,11 +250,6 @@ ActionReply Action::execute(const QString &helperID) const
return ActionReply::InvalidActionReply; return ActionReply::InvalidActionReply;
} }
// What to do?
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromClientCapability) {
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {
BackendsManager::authBackend()->preAuthAction(d->name, d->parent);
}
// Authorize from here // Authorize from here
AuthStatus s = BackendsManager::authBackend()->authorizeAction(d->name); AuthStatus s = BackendsManager::authBackend()->authorizeAction(d->name);
@ -327,25 +264,6 @@ ActionReply Action::execute(const QString &helperID) const
default: default:
break; break;
} }
} else if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::AuthorizeFromHelperCapability) {
// In this case we care only if the action is not async and does not have an helper
if (!d->async && !hasHelper()) {
// Authorize!
switch (authorize()) {
case Denied:
return ActionReply::AuthorizationDeniedReply;
case Invalid:
return ActionReply::InvalidActionReply;
case UserCancelled:
return ActionReply::UserCancelledReply;
default:
break;
}
}
} else {
// What?
return ActionReply::InvalidActionReply;
}
if (d->async) { if (d->async) {
if (!hasHelper()) { if (!hasHelper()) {
@ -357,11 +275,6 @@ ActionReply Action::execute(const QString &helperID) const
ActionReply::SuccessReply : ActionReply::AuthorizationDeniedReply; ActionReply::SuccessReply : ActionReply::AuthorizationDeniedReply;
} else { } else {
if (hasHelper()) { if (hasHelper()) {
// Perform the pre auth here
if (BackendsManager::authBackend()->capabilities() & KAuth::AuthBackend::PreAuthActionCapability) {
BackendsManager::authBackend()->preAuthAction(d->name, d->parent);
}
return BackendsManager::helperProxy()->executeAction(d->name, helperID, d->args); return BackendsManager::helperProxy()->executeAction(d->name, helperID, d->args);
} else { } else {
return ActionReply::SuccessReply; return ActionReply::SuccessReply;