diff --git a/src/core/jobuidelegateextension.h b/src/core/jobuidelegateextension.h --- a/src/core/jobuidelegateextension.h +++ b/src/core/jobuidelegateextension.h @@ -191,7 +191,7 @@ * or emptying the trash * Used by askDeleteConfirmation. */ - enum DeletionType { Delete, Trash, EmptyTrash }; + enum DeletionType { Delete, DeletePrivileged, Trash, EmptyTrash }; /** * ForceConfirmation: always ask the user for confirmation * DefaultConfirmation: don't ask the user if he/she said "don't ask again". diff --git a/src/ioslaves/file/file.cpp b/src/ioslaves/file/file.cpp --- a/src/ioslaves/file/file.cpp +++ b/src/ioslaves/file/file.cpp @@ -1331,8 +1331,15 @@ } else { //qDebug() << "QFile::remove" << itemPath; if (!QFile::remove(itemPath)) { - error(KIO::ERR_CANNOT_DELETE, itemPath); - return false; + if (errno == EACCES || errno == EPERM) { + if (!execWithRoot(QStringLiteral("del"), QStringLiteral("delete_file"), itemPath, WARN_PRIVILEDGE_DEL)) { + error(KIO::ERR_ACCESS_DENIED, itemPath); + return false; + } + } else { + error(KIO::ERR_CANNOT_DELETE, itemPath); + return false; + } } } } @@ -1340,8 +1347,15 @@ Q_FOREACH (const QString &itemPath, dirsToDelete) { //qDebug() << "QDir::rmdir" << itemPath; if (!dir.rmdir(itemPath)) { - error(KIO::ERR_CANNOT_DELETE, itemPath); - return false; + if (errno == EACCES || errno == EPERM) { + if (!execWithRoot(QStringLiteral("del"), QStringLiteral("delete_dir"), itemPath, WARN_PRIVILEDGE_RMDIR)) { + error(KIO::ERR_ACCESS_DENIED, itemPath); + return false; + } + } else { + error(KIO::ERR_CANNOT_DELETE, itemPath); + return false; + } } } return true; @@ -1394,7 +1408,9 @@ } bool proceed = true; - if (kauthStatus == KAuth::Action::AuthorizedStatus && !mPriviledgeOpStarted) { + if (kauthStatus == KAuth::Action::AuthorizedStatus + && !mPriviledgeOpStarted + && metaData(QLatin1String("ShowInternalWarning")) == QStringLiteral("true")) { mPriviledgeOpStarted = true; proceed = showWarning(warning); } 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 @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -526,13 +527,17 @@ if (unlink(_path.data()) == -1) { if ((errno == EACCES) || (errno == EPERM)) { - error(KIO::ERR_ACCESS_DENIED, path); + if (!execWithRoot(QStringLiteral("del"), QStringLiteral("delete_file"), _path, WARN_PRIVILEDGE_DEL)) { + error(KIO::ERR_ACCESS_DENIED, path); + return; + } } else if (errno == EISDIR) { error(KIO::ERR_IS_DIRECTORY, path); + return; } else { error(KIO::ERR_CANNOT_DELETE, path); + return; } - return; } } else { @@ -548,8 +553,10 @@ } if (QT_RMDIR(_path.data()) == -1) { if ((errno == EACCES) || (errno == EPERM)) { - error(KIO::ERR_ACCESS_DENIED, path); - return; + if (!execWithRoot(QStringLiteral("del"), QStringLiteral("delete_dir"), path, WARN_PRIVILEDGE_RMDIR)) { + error(KIO::ERR_ACCESS_DENIED, path); + return; + } } else { // qDebug() << "could not rmdir " << perror; error(KIO::ERR_CANNOT_RMDIR, path); @@ -558,6 +565,7 @@ } } + endPriviledgeOp(); finished(); } diff --git a/src/ioslaves/file/kauth/file.actions b/src/ioslaves/file/kauth/file.actions --- a/src/ioslaves/file/kauth/file.actions +++ b/src/ioslaves/file/kauth/file.actions @@ -0,0 +1,5 @@ +[org.kde.kio.file.del] +Name=Remove items as a privileged user. +Description=Remove items as a privileged user. +Policy=auth_admin +Persistence=session diff --git a/src/ioslaves/file/kauth/helper.h b/src/ioslaves/file/kauth/helper.h --- a/src/ioslaves/file/kauth/helper.h +++ b/src/ioslaves/file/kauth/helper.h @@ -29,6 +29,9 @@ class Helper : public QObject { Q_OBJECT + +public Q_SLOTS: + ActionReply del(const QVariantMap& args); }; #endif diff --git a/src/ioslaves/file/kauth/helper.cpp b/src/ioslaves/file/kauth/helper.cpp --- a/src/ioslaves/file/kauth/helper.cpp +++ b/src/ioslaves/file/kauth/helper.cpp @@ -19,5 +19,40 @@ ***/ #include "helper.h" +#include +#include + +#include +#include +#include +#include +#include + + +ActionReply Helper::del(const QVariantMap &args) +{ + ActionReply reply = ActionReply::SuccessReply(); + const QByteArray path = args["arguments"].toByteArray(); + const QString subAction = args["subaction"].toString(); + + if (subAction == "delete_file") { + qDebug()<<"Deleting file "<