diff --git a/CMakeLists.txt b/CMakeLists.txt index c1e4bd4d..7f25dfef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ option(KIOCORE_ONLY "Only compile KIOCore, not KIOWidgets or anything that depen option(KIO_FORK_SLAVES "If set we start the slaves via QProcess. It's also possible to change this by setting the environment variable KDE_FORK_SLAVES." OFF) find_package(KF5Archive ${KF5_DEP_VERSION} REQUIRED) +find_package(KF5Auth ${KF5_DEP_VERSION} REQUIRED) find_package(KF5Config ${KF5_DEP_VERSION} REQUIRED) find_package(KF5CoreAddons ${KF5_DEP_VERSION} REQUIRED) find_package(KF5DBusAddons ${KF5_DEP_VERSION} REQUIRED) diff --git a/src/ioslaves/file/CMakeLists.txt b/src/ioslaves/file/CMakeLists.txt index b9132ced..320b27c6 100644 --- a/src/ioslaves/file/CMakeLists.txt +++ b/src/ioslaves/file/CMakeLists.txt @@ -21,7 +21,7 @@ set_package_properties(ACL PROPERTIES DESCRIPTION "LibACL" URL "ftp://oss.sgi.co configure_file(config-kioslave-file.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kioslave-file.h ) add_library(kio_file MODULE ${kio_file_PART_SRCS}) -target_link_libraries(kio_file KF5::KIOCore KF5::I18n) +target_link_libraries(kio_file KF5::Auth KF5::KIOCore KF5::I18n) if (HAVE_VOLMGT AND CMAKE_SYSTEM_NAME MATCHES SunOS) target_link_libraries(kio_file -lvolmgt) @@ -33,3 +33,5 @@ endif() set_target_properties(kio_file PROPERTIES OUTPUT_NAME "file") install(TARGETS kio_file DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio) + +add_subdirectory(kauth) diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp index c6fcf228..dd29bec2 100644 --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -510,13 +511,23 @@ void FileProtocol::del(const QUrl &url, bool isfile) if (unlink(_path.data()) == -1) { if ((errno == EACCES) || (errno == EPERM)) { - error(KIO::ERR_ACCESS_DENIED, path); + + QVariantMap args; + args["path"] = _path; + KAuth::Action delAction(QStringLiteral("org.kde.kio.file.del")); + delAction.setHelperId("org.kde.kio.file"); + delAction.setArguments(args); + auto reply = delAction.execute(); + if (!reply->exec()) { + error(ERR_SLAVE_DEFINED, i18n("KAuth helper failed to remove %1, error: %2", path, reply->error())); + } } else if (errno == EISDIR) { error(KIO::ERR_IS_DIRECTORY, path); + return; } else { error(KIO::ERR_CANNOT_DELETE, path); + return; } - return; } } else { diff --git a/src/ioslaves/file/kauth/CMakeLists.txt b/src/ioslaves/file/kauth/CMakeLists.txt new file mode 100644 index 00000000..1fda4bd0 --- /dev/null +++ b/src/ioslaves/file/kauth/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(file_helper helper.cpp) +target_link_libraries(file_helper KF5::Auth KF5::I18n) + +install(TARGETS file_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) +kauth_install_helper_files(file_helper org.kde.kio.file root) +kauth_install_actions(org.kde.kio.file file.actions) diff --git a/src/ioslaves/file/kauth/file.actions b/src/ioslaves/file/kauth/file.actions new file mode 100644 index 00000000..89efcccc --- /dev/null +++ b/src/ioslaves/file/kauth/file.actions @@ -0,0 +1,6 @@ +[org.kde.kio.file.del] +Name=Delete files +Description=Delete files from filesystem +Policy=auth_admin +Persistence=session + diff --git a/src/ioslaves/file/kauth/helper.cpp b/src/ioslaves/file/kauth/helper.cpp new file mode 100644 index 00000000..8c8e56c2 --- /dev/null +++ b/src/ioslaves/file/kauth/helper.cpp @@ -0,0 +1,27 @@ +#include "helper.h" + +#include + +#include + +#include +#include + +ActionReply Helper::del(const QVariantMap& args) +{ + QByteArray path = args["path"].toByteArray(); + + if (unlink(path.data()) == -1) { + ActionReply reply = ActionReply::HelperErrorReply(); + if ((errno == EACCES) || (errno == EPERM)) { + reply.setErrorDescription(i18n("Helper did not have karma. Weird.")); + } else if (errno == EISDIR) { + reply.setErrorDescription(i18n("Cannot remove directories.")); + } + return reply; + } + + return ActionReply::SuccessReply(); +} + +KAUTH_HELPER_MAIN("org.kde.kio.file", Helper) diff --git a/src/ioslaves/file/kauth/helper.h b/src/ioslaves/file/kauth/helper.h new file mode 100644 index 00000000..9656b2d1 --- /dev/null +++ b/src/ioslaves/file/kauth/helper.h @@ -0,0 +1,16 @@ +#ifndef HELPER_H +#define HELPER_H + +#include + +using namespace KAuth; + +class Helper : public QObject +{ + Q_OBJECT + + public Q_SLOTS: + ActionReply del(const QVariantMap& args); +}; + +#endif