diff --git a/src/backends/fake/kauth-policy-gen-polkit.cpp b/src/backends/fake/kauth-policy-gen-polkit.cpp index 45b9ce0..728ae0f 100644 --- a/src/backends/fake/kauth-policy-gen-polkit.cpp +++ b/src/backends/fake/kauth-policy-gen-polkit.cpp @@ -1,82 +1,82 @@ /* * Copyright (C) 2008 Nicola Gigante * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program 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 Lesser General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . */ #include #include #include #include const char header[] = "" "\n" "\n" "\n"; const char policy_tag[] = "" " \n" " no\n" " %1\n" " \n"; const char dent[] = " "; -void output(QList actions, const QMap &domain) +void output(const QList &actions, const QMap &domain) { Q_UNUSED(domain) QTextStream out(stdout); out.setCodec("UTF-8"); out << header; for (const Action &action : qAsConst(actions)) { out << dent << "\n"; const auto lstKeys = action.descriptions.keys(); for (const QString &lang : lstKeys) { out << dent << dent << "' << action.messages.value(lang) << "\n"; } const auto lstMessagesKeys = action.messages.keys(); for (const QString &lang : lstMessagesKeys) { out << dent << dent << "' << action.descriptions.value(lang) << "\n"; } QString policy = action.policy; if (!action.persistence.isEmpty()) { policy += "_keep_" + action.persistence; } out << QString(policy_tag).arg(policy); out << dent << "\n"; } out << "\n"; } diff --git a/src/backends/mac/kauth-policy-gen-mac.cpp b/src/backends/mac/kauth-policy-gen-mac.cpp index fdd22cd..213d96b 100644 --- a/src/backends/mac/kauth-policy-gen-mac.cpp +++ b/src/backends/mac/kauth-policy-gen-mac.cpp @@ -1,66 +1,66 @@ /* * Copyright (C) 2008 Nicola Gigante * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program 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 Lesser General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . */ #include "../../policy-gen/policy-gen.h" #include #include #include using namespace std; -void output(QList actions, const QMap &domain) +void output(const QList &actions, const QMap &domain) { AuthorizationRef auth; AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth); OSStatus err; for (const Action &action : qAsConst(actions)) { err = AuthorizationRightGet(action.name.toLatin1().constData(), NULL); if (err != errAuthorizationSuccess) { QString rule; if (action.policy == QLatin1String("yes")) { rule = QString::fromLatin1(kAuthorizationRuleClassAllow); } else if (action.policy == QLatin1String("no")) { rule = QString::fromLatin1(kAuthorizationRuleClassDeny); } else if (action.policy == QLatin1String("auth_self")) { rule = QString::fromLatin1(kAuthorizationRuleAuthenticateAsSessionUser); } else if (action.policy == QLatin1String("auth_admin")) { rule = QString::fromLatin1(kAuthorizationRuleAuthenticateAsAdmin); } CFStringRef cfRule = CFStringCreateWithCString(NULL, rule.toLatin1().constData(), kCFStringEncodingASCII); CFStringRef cfPrompt = CFStringCreateWithCString(NULL, action.descriptions.value(QLatin1String("en")).toLatin1().constData(), kCFStringEncodingASCII); err = AuthorizationRightSet(auth, action.name.toLatin1().constData(), cfRule, cfPrompt, NULL, NULL); if (err != noErr) { cerr << "You don't have the right to edit the security database (try to run cmake with sudo): " << err << endl; exit(1); } else { qInfo() << "Created or updated rule" << rule << "for right entry" << action.name << "policy" << action.policy << "; domain=" << domain; } } } } diff --git a/src/backends/policykit/kauth-policy-gen-polkit.cpp b/src/backends/policykit/kauth-policy-gen-polkit.cpp index 995d53d..84ee427 100644 --- a/src/backends/policykit/kauth-policy-gen-polkit.cpp +++ b/src/backends/policykit/kauth-policy-gen-polkit.cpp @@ -1,119 +1,119 @@ /* * Copyright (C) 2008 Nicola Gigante * Copyright (C) 2009-2010 Dario Freddi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program 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 Lesser General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . */ #include #include #include #include const char header[] = "" "\n" "\n" "\n"; const char policy_tag[] = "" " \n" " %1\n" " %2\n" " \n"; const char dent[] = " "; -void output(QList actions, const QMap &domain) +void output(const QList &actions, const QMap &domain) { QTextStream out(stdout); out.setCodec("UTF-8"); out << header; // Blacklisted characters + replacements QHash< QChar, QString > blacklist; blacklist.insert(QChar::fromLatin1('&'), QString::fromLatin1("&")); if (domain.contains(QLatin1String("vendor"))) { QHash< QChar, QString >::const_iterator blI; QString vendor = domain[QLatin1String("vendor")]; for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) { vendor.replace(blI.key(), blI.value()); } out << "" << vendor << "\n"; } if (domain.contains(QLatin1String("vendorurl"))) { out << "" << domain[QLatin1String("vendorurl")] << "\n"; } if (domain.contains(QLatin1String("icon"))) { out << "" << domain[QLatin1String("icon")] << "\n"; } for (const Action &action : qAsConst(actions)) { out << dent << "\n"; for (QHash< QString, QString >::const_iterator i = action.messages.constBegin(); i != action.messages.constEnd(); ++i) { out << dent << dent << "::const_iterator blI; QString description = i.value(); for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) { description.replace(blI.key(), blI.value()); } out << '>' << description << "\n"; } for (QHash< QString, QString>::const_iterator i = action.descriptions.constBegin(); i != action.descriptions.constEnd(); ++i) { out << dent << dent << "::const_iterator blI; QString message = i.value(); for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) { message.replace(blI.key(), blI.value()); } out << '>' << message << "\n"; } QString policy = action.policy; QString policyInactive = action.policyInactive.isEmpty() ? QLatin1String("no") : action.policyInactive; if (!action.persistence.isEmpty() && policy != QLatin1String("yes") && policy != QLatin1String("no")) { policy += QLatin1String("_keep_") + action.persistence; } if (!action.persistence.isEmpty() && policyInactive != QLatin1String("yes") && policyInactive != QLatin1String("no")) { policyInactive += QLatin1String("_keep_") + action.persistence; } out << QString(QLatin1String(policy_tag)).arg(policyInactive).arg(policy); out << dent << "\n"; } out << "\n"; }