diff --git a/kfirewall/CMakeLists.txt b/kfirewall/CMakeLists.txt index 4aceefc2..2f1d34a5 100644 --- a/kfirewall/CMakeLists.txt +++ b/kfirewall/CMakeLists.txt @@ -1,5 +1,14 @@ project(kfirewall) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + include(FeatureSummary) + + find_package(KDE4 4.21.0 REQUIRED) + include(KDE4Defaults) + include_directories(${KDE4_INCLUDES}) + add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) +endif() + find_program(IPTABLES_EXECUTABLE iptables-restore) add_feature_info(iptables IPTABLES_EXECUTABLE diff --git a/kfirewall/kcm/kfirewallconfig.cpp b/kfirewall/kcm/kfirewallconfig.cpp index 7eb79271..9074d954 100644 --- a/kfirewall/kcm/kfirewallconfig.cpp +++ b/kfirewall/kcm/kfirewallconfig.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -69,7 +69,8 @@ KCMFirewall::KCMFirewall(QWidget* parent, const QVariantList& args) about->addAuthor(ki18n("Ivailo Monev"), KLocalizedString(), "xakepa10@gmail.com"); setAboutData(about); - setNeedsAuthorization(true); + // TODO: + // setNeedsAuthorization(true); load(); diff --git a/kfirewall/kcm/kfirewallconfig.ui b/kfirewall/kcm/kfirewallconfig.ui index 89a8b6fc..733819cb 100644 --- a/kfirewall/kcm/kfirewallconfig.ui +++ b/kfirewall/kcm/kfirewallconfig.ui @@ -116,6 +116,5 @@ 1 - diff --git a/kfirewall/kcm/kfirewallhelper.cpp b/kfirewall/kcm/kfirewallhelper.cpp index bd8f1bb7..73ca38a5 100644 --- a/kfirewall/kcm/kfirewallhelper.cpp +++ b/kfirewall/kcm/kfirewallhelper.cpp @@ -20,7 +20,6 @@ #include #include -#include #include static QByteArray ruleForSettings(const QByteArray &uservalue, const QByteArray &trafficvalue, @@ -102,22 +101,18 @@ static QByteArray rulesForParameters(const QVariantMap ¶meters, const bool a return iptablesruledata; } -static ActionReply applyRules(KFirewallHelper *helper, const QString &iptablesexe, +static int applyRules(KFirewallHelper *helper, const QString &iptablesexe, const QByteArray &iptablesruledata) { QProcess iptablesproc(helper); iptablesproc.start(iptablesexe); if (!iptablesproc.waitForStarted()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Could not start iptables-restore"); - errorreply.setErrorCode(3); - return errorreply; + kWarning() << "Could not start iptables-restore"; + return KAuthorization::HelperError; } if (iptablesproc.write(iptablesruledata) != iptablesruledata.size()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Could not write rules"); - errorreply.setErrorCode(4); - return errorreply; + kWarning() << "Could not write rules"; + return KAuthorization::HelperError; } iptablesproc.closeWriteChannel(); iptablesproc.waitForFinished(); @@ -126,55 +121,45 @@ static ActionReply applyRules(KFirewallHelper *helper, const QString &iptablesex if (errorstring.isEmpty()) { errorstring = QString::fromLatin1("Could not apply rules"); } - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription(errorstring); - errorreply.setErrorCode(5); - return errorreply; + kWarning() << errorstring; + return KAuthorization::HelperError; } - return KAuth::ActionReply::SuccessReply; + return KAuthorization::NoError; } -ActionReply KFirewallHelper::apply(const QVariantMap ¶meters) +int KFirewallHelper::apply(const QVariantMap ¶meters) { if (parameters.isEmpty()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Empty rules"); - errorreply.setErrorCode(1); - return errorreply; + kWarning() << "Empty rules"; + return KAuthorization::HelperError; } const QString iptablesexe = KStandardDirs::findRootExe("iptables-restore"); if (iptablesexe.isEmpty()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Could not find iptables-restore"); - errorreply.setErrorCode(2); - return errorreply; + kWarning() << "Could not find iptables-restore"; + return KAuthorization::HelperError; } return applyRules(this, iptablesexe, rulesForParameters(parameters, true)); } -ActionReply KFirewallHelper::revert(const QVariantMap ¶meters) +int KFirewallHelper::revert(const QVariantMap ¶meters) { //qDebug() << Q_FUNC_INFO << parameters; if (parameters.isEmpty()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Empty rules"); - errorreply.setErrorCode(1); - return errorreply; + kWarning() << "Empty rules"; + return KAuthorization::HelperError; } const QString iptablesexe = KStandardDirs::findRootExe("iptables-restore"); if (iptablesexe.isEmpty()) { - KAuth::ActionReply errorreply(KAuth::ActionReply::HelperError); - errorreply.setErrorDescription("Could not find iptables-restore"); - errorreply.setErrorCode(2); - return errorreply; + kWarning() << "Could not find iptables-restore"; + return KAuthorization::HelperError; } return applyRules(this, iptablesexe, rulesForParameters(parameters, false)); } -KDE4_AUTH_HELPER_MAIN("org.kde.kcontrol.kcmkfirewall", KFirewallHelper) +K_AUTH_MAIN("org.kde.kcontrol.kcmkfirewall", KFirewallHelper) diff --git a/kfirewall/kcm/kfirewallhelper.h b/kfirewall/kcm/kfirewallhelper.h index 72fa710b..468298e5 100644 --- a/kfirewall/kcm/kfirewallhelper.h +++ b/kfirewall/kcm/kfirewallhelper.h @@ -19,17 +19,14 @@ #ifndef KFIREWALLHELPER_H #define KFIREWALLHELPER_H -#include +#include -// methods return type must be ActionReply otherwise QMetaObject::invokeMethod() fails -using namespace KAuth; - -class KFirewallHelper : public QObject +class KFirewallHelper : public KAuthorization { Q_OBJECT public slots: - ActionReply apply(const QVariantMap ¶meters); - ActionReply revert(const QVariantMap ¶meters); + int apply(const QVariantMap ¶meters); + int revert(const QVariantMap ¶meters); }; #endif // KFIREWALLHELPER_H diff --git a/kfirewall/kded/kded_kfirewall.cpp b/kfirewall/kded/kded_kfirewall.cpp index e476b212..078c0f99 100644 --- a/kfirewall/kded/kded_kfirewall.cpp +++ b/kfirewall/kded/kded_kfirewall.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -69,14 +69,13 @@ bool KFirewallModule::enable() return true; } - KAuth::Action kfirewallaction("org.kde.kcontrol.kcmkfirewall.apply"); - kfirewallaction.setHelperID("org.kde.kcontrol.kcmkfirewall"); - kfirewallaction.setArguments(m_kfirewallsettingsmap); - KAuth::ActionReply kfirewallreply = kfirewallaction.execute(); - // qDebug() << Q_FUNC_INFO << kfirewallreply.errorCode() << kfirewallreply.errorDescription(); - - if (kfirewallreply != KAuth::ActionReply::SuccessReply) { - kWarning() << kfirewallreply.errorCode() << kfirewallreply.errorDescription(); + const int kfirewallreply = KAuthorization::execute( + "org.kde.kcontrol.kcmkfirewall", + "apply", + m_kfirewallsettingsmap + ); + if (kfirewallreply != KAuthorization::NoError) { + kWarning() << kfirewallreply; return false; } @@ -90,14 +89,13 @@ bool KFirewallModule::disable() return true; } - KAuth::Action kfirewallaction("org.kde.kcontrol.kcmkfirewall.revert"); - kfirewallaction.setHelperID("org.kde.kcontrol.kcmkfirewall"); - kfirewallaction.setArguments(m_kfirewallsettingsmap); - KAuth::ActionReply kfirewallreply = kfirewallaction.execute(); - // qDebug() << Q_FUNC_INFO << kfirewallreply.errorCode() << kfirewallreply.errorDescription(); - - if (kfirewallreply != KAuth::ActionReply::SuccessReply) { - kWarning() << kfirewallreply.errorCode() << kfirewallreply.errorDescription(); + const int kfirewallreply = KAuthorization::execute( + "org.kde.kcontrol.kcmkfirewall", + "revert", + m_kfirewallsettingsmap + ); + if (kfirewallreply != KAuthorization::NoError) { + kWarning() << kfirewallreply; return false; }