Commit 50effd71 authored by Corbin Schwimmbeck's avatar Corbin Schwimmbeck Committed by Laurent Montel
Browse files

Add helper files for KAuth.

This creates a little executable, which can run with elevated privileges, and handles saving the files. This way the main application does not require root permissions.
parent 442d59e4
add_executable(kcron_helper kcronhelper.cpp)
target_link_libraries(kcron_helper PRIVATE KF5::AuthCore Qt5::Core KF5::Auth)
ecm_qt_declare_logging_category(kcron_helper
HEADER kcm_cron_helper_debug.h
IDENTIFIER KCM_CRON_HELPER_LOG
CATEGORY_NAME org.kde.kcm.cron_helper
DESCRIPTION "kcm cron helper"
EXPORT KCRON_HELPER
)
# The following need to be disabled in debug builds, if lacking root permissions.
# Build the project to generate the files, then install them manually:
# /usr/share/dbus-1/system-services/ <- local.kcron.crontab.service
# /usr/share/polkit-1/actions/ <- local.kcron.crontab.policy
# /usr/share/dbus-1/system.d/ <- local.kcron.crontab.conf
install(TARGETS kcron_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
kauth_install_helper_files(kcron_helper local.kcron.crontab root)
kauth_install_actions(local.kcron.crontab local.kcron.crontab.actions)
The contents of this folder, as well as a few tweaks
regarding KAuth and polkit permissions were sourced
and modified from the GPL-licensed project Zeit by lolmu.
The original project can be found here https://github.com/loimu/zeit.
/* ========================================================================
* Copyright (C) 2015-2021 Blaze <blaze@vivaldi.net>
*
* This file is part of Zeit.
*
* Zeit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zeit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Zeit. If not, see <http://www.gnu.org/licenses/>.
* ======================================================================== *
*
* This file was modified to fit into the project Kcron.
* The same license terms apply.
*
* ======================================================================== */
#include <QFile>
#include "kcm_cron_helper_debug.h"
#include "kcronhelper.h"
ActionReply KcronHelper::save(const QVariantMap &args)
{
qCDebug(KCM_CRON_HELPER_LOG) << "running actions";
QString source = args[QLatin1String("source")].toString();
QString destination = args[QLatin1String("target")].toString();
if (!QFile::remove(destination))
qCWarning(KCM_CRON_HELPER_LOG) << "can't remove file, it doesn't exist";
if (!QFile::copy(source, destination))
qCWarning(KCM_CRON_HELPER_LOG) << "can't write into the system file, something went wrong";
return ActionReply::SuccessReply();
}
KAUTH_HELPER_MAIN("local.kcron.crontab", KcronHelper)
/* ========================================================================
* Copyright (C) 2015-2021 Blaze <blaze@vivaldi.net>
*
* This file is part of Zeit.
*
* Zeit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zeit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Zeit. If not, see <http://www.gnu.org/licenses/>.
* ======================================================================== *
*
* This file was modified to fit into the project Kcron.
* The same license terms apply.
*
* ======================================================================== */
#pragma once
#include <KAuth>
using namespace KAuth;
// usage of fully qualified type here renders the helper app fully ;) unusable
// clazy:excludeall=fully-qualified-moc-types
class KcronHelper : public QObject
{
Q_OBJECT
public Q_SLOTS:
ActionReply save(const QVariantMap &args);
};
[Domain]
Name=Crontab Actions
Policy=auth_admin
Persistence=session
[local.kcron.crontab.save]
Name=Write Crontab
Description=Write into the system crontab file
Policy=auth_admin
Persistence=session
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment