Actually check if the caller is authorized.
This commit is contained in:
parent
dac3372a78
commit
39d3592c23
|
@ -65,8 +65,6 @@ QVector<KPluginMetaData> CoreBackendManager::list() const
|
|||
|
||||
void CoreBackendManager::startExternalCommandHelper()
|
||||
{
|
||||
stopExternalCommandHelper();
|
||||
|
||||
KAuth::Action action = KAuth::Action(QStringLiteral("org.kde.kpmcore.externalcommand.init"));
|
||||
action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand"));
|
||||
action.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||
|
|
|
@ -139,28 +139,14 @@ void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMod
|
|||
// connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);
|
||||
}
|
||||
|
||||
/** Starts the external command.
|
||||
/** Executes the external command.
|
||||
@param timeout timeout to wait for the process to start
|
||||
@return true on success
|
||||
*/
|
||||
|
||||
bool ExternalCommand::start(int timeout)
|
||||
{
|
||||
// this->moveToThread(CoreBackendManager::self()->kauthThread());
|
||||
// QTimer::singleShot(0, this, &ExternalCommand::execute);
|
||||
// QEventLoop loop;
|
||||
// connect(this, &ExternalCommand::finished, &loop, &QEventLoop::quit);
|
||||
// loop.exec();
|
||||
// return true;
|
||||
Q_UNUSED(timeout)
|
||||
execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Executes the external command in kauthThread() thread.
|
||||
*/
|
||||
void ExternalCommand::execute()
|
||||
{
|
||||
if (report()) {
|
||||
report()->setCommand(xi18nc("@info:status", "Command: %1 %2", command(), args().join(QStringLiteral(" "))));
|
||||
}
|
||||
|
@ -171,7 +157,7 @@ void ExternalCommand::execute()
|
|||
|
||||
if (!QDBusConnection::systemBus().isConnected()) {
|
||||
qWarning() << "Could not connect to DBus system bus";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
QDBusInterface iface(QStringLiteral("org.kde.kpmcore.helperinterface"),
|
||||
|
@ -181,6 +167,7 @@ void ExternalCommand::execute()
|
|||
|
||||
iface.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||
|
||||
bool rval = false;
|
||||
if (iface.isValid()) {
|
||||
QDBusPendingCall pcall = iface.asyncCall(QStringLiteral("start"),
|
||||
CoreBackendManager::self()->Uuid(),
|
||||
|
@ -206,11 +193,13 @@ void ExternalCommand::execute()
|
|||
}
|
||||
|
||||
emit finished();
|
||||
rval = true;
|
||||
};
|
||||
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, exitLoop);
|
||||
loop.exec();
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool ExternalCommand::write(const QByteArray& input)
|
||||
|
|
|
@ -93,8 +93,6 @@ public Q_SLOTS:
|
|||
void emitProgress(KJob*, unsigned long percent) { emit progress(percent); };
|
||||
|
||||
protected:
|
||||
void execute();
|
||||
|
||||
void setExitCode(int i) {
|
||||
m_ExitCode = i;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2017 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* Copyright (C) 2017-2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
|
@ -111,7 +111,8 @@ bool ExternalCommandHelper::writeData(const QString &targetDevice, const QByteAr
|
|||
|
||||
bool ExternalCommandHelper::copyblocks(const QString& Uuid, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize)
|
||||
{
|
||||
isCallerAuthorized(Uuid);
|
||||
if (!isCallerAuthorized(Uuid))
|
||||
return false;
|
||||
|
||||
const qint64 blocksToCopy = sourceLength / blockSize;
|
||||
qint64 readOffset = sourceFirstByte;
|
||||
|
@ -194,8 +195,11 @@ bool ExternalCommandHelper::copyblocks(const QString& Uuid, const QString& sourc
|
|||
|
||||
QVariantMap ExternalCommandHelper::start(const QString& Uuid, const QString& command, const QStringList& arguments, const QByteArray& input, const QStringList& environment)
|
||||
{
|
||||
isCallerAuthorized(Uuid);
|
||||
QVariantMap reply;
|
||||
if (!isCallerAuthorized(Uuid)) {
|
||||
reply[QStringLiteral("success")] = false;
|
||||
return reply;
|
||||
}
|
||||
|
||||
// connect(&cmd, &QProcess::readyReadStandardOutput, this, &ExternalCommandHelper::onReadOutput);
|
||||
|
||||
|
@ -223,7 +227,8 @@ bool ExternalCommandHelper::isCallerAuthorized(const QString& Uuid)
|
|||
|
||||
void ExternalCommandHelper::exit(const QString& Uuid)
|
||||
{
|
||||
isCallerAuthorized(Uuid);
|
||||
if (!isCallerAuthorized(Uuid))
|
||||
return;
|
||||
m_loop.exit();
|
||||
|
||||
if (QDBusConnection::systemBus().unregisterService(QStringLiteral("org.kde.kpmcore.helperinterface")))
|
||||
|
|
Loading…
Reference in New Issue