diff --git a/src/core/simplejob.cpp b/src/core/simplejob.cpp --- a/src/core/simplejob.cpp +++ b/src/core/simplejob.cpp @@ -338,7 +338,10 @@ void SimpleJobPrivate::slotPrivilegeOperationRequested() { - m_slave->send(MSG_PRIVILEGE_EXEC, QByteArray::number(tryAskPrivilegeOpConfirmation())); + const pid_t appPID = getpid(); + const PrivilegeOperationStatus status = tryAskPrivilegeOpConfirmation(); + const QByteArray slaveData = QStringLiteral("%1,%2").arg(appPID).arg(status).toLocal8Bit(); + m_slave->send(MSG_PRIVILEGE_EXEC, slaveData); } ////////// diff --git a/src/core/slavebase.h b/src/core/slavebase.h --- a/src/core/slavebase.h +++ b/src/core/slavebase.h @@ -951,6 +951,10 @@ //Often used by TcpSlaveBase and unlikely to change MetaData mOutgoingMetaData; MetaData mIncomingMetaData; + /** + * Tells if a different application picked up the slave + */ + bool mAppChanged; enum VirtualFunctionId { AppConnectionMade = 0, diff --git a/src/core/slavebase.cpp b/src/core/slavebase.cpp --- a/src/core/slavebase.cpp +++ b/src/core/slavebase.cpp @@ -80,7 +80,7 @@ { public: SlaveBase *q; - SlaveBasePrivate(SlaveBase *owner): q(owner), nextTimeoutMsecs(0), m_passwdServerClient(nullptr) + SlaveBasePrivate(SlaveBase *owner): q(owner), nextTimeoutMsecs(0), m_passwdServerClient(nullptr), appPID(-1) { if (!qEnvironmentVariableIsEmpty("KIOSLAVE_ENABLE_TESTMODE")) { QStandardPaths::enableTestMode(true); @@ -121,6 +121,8 @@ KPasswdServerClient *m_passwdServerClient; bool m_rootEntryListed = false; + pid_t appPID; + // Reconstructs configGroup from configData and mIncomingMetaData void rebuildConfig() { @@ -196,6 +198,7 @@ const QByteArray &pool_socket, const QByteArray &app_socket) : mProtocol(protocol), + mAppChanged(false), d(new SlaveBasePrivate(this)) { @@ -1464,5 +1467,13 @@ QByteArray buffer; send(MSG_PRIVILEGE_EXEC); waitForAnswer(MSG_PRIVILEGE_EXEC, 0, buffer); - return KIO::PrivilegeOperationStatus(buffer.toInt()); + const QList data = buffer.split(','); + if (d->appPID != data[0].toLong()) { + if (d->appPID == -1) { + d->appPID = data[0].toLong(); + } else { + mAppChanged = true; + } + } + return KIO::PrivilegeOperationStatus(data[1].toInt()); } diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -804,6 +804,12 @@ KAuth::Action execAction(QStringLiteral("org.kde.kio.file.exec")); execAction.setHelperId(QStringLiteral("org.kde.kio.file")); + if (execAction.status() == KAuth::Action::AuthorizedStatus && mAppChanged) { + return PrivilegeOperationReturnValue::failure(errcode); + } else { + mAppChanged = false; + } + QVariantMap argv; argv.insert(QStringLiteral("arguments"), helperArgs); execAction.setArguments(argv);