KDECore
kauth-policy-gen-mac.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 2.1 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . 00018 */ 00019 00020 #include <auth/policy-gen/policy-gen.h> 00021 00022 #include <iostream> 00023 #include <Security/Security.h> 00024 00025 using namespace std; 00026 00027 void output(QList<Action> actions, QHash<QString, QString> domain) 00028 { 00029 AuthorizationRef auth; 00030 AuthorizationCreate(NULL, NULL, kAuthorizationFlagDefaults, &auth); 00031 00032 OSStatus err; 00033 00034 foreach(const Action &action, actions) { 00035 00036 err = AuthorizationRightGet(action.name.toAscii(), NULL); 00037 00038 if (err == errAuthorizationDenied) { 00039 00040 QString rule; 00041 00042 if (action.policy == QLatin1String("yes")) 00043 rule = QString::fromLatin1(kAuthorizationRuleClassAllow); 00044 else if (action.policy == QLatin1String("no")) 00045 rule = QString::fromLatin1(kAuthorizationRuleClassDeny); 00046 else if (action.policy == QLatin1String("auth_self")) 00047 rule = QString::fromLatin1(kAuthorizationRuleAuthenticateAsSessionUser); 00048 else if (action.policy == QLatin1String("auth_admin")) 00049 rule = QString::fromLatin1(kAuthorizationRuleAuthenticateAsAdmin); 00050 00051 CFStringRef cfRule = CFStringCreateWithCString(NULL, rule.toAscii(), kCFStringEncodingASCII); 00052 CFStringRef cfPrompt = CFStringCreateWithCString(NULL, action.descriptions.value(QLatin1String("en")).toAscii(), kCFStringEncodingASCII); 00053 00054 err = AuthorizationRightSet(auth, action.name.toAscii(), cfRule, cfPrompt, NULL, NULL); 00055 if (err != noErr) { 00056 cerr << "You don't have the right to edit the security database (try to run cmake with sudo): " << err << endl; 00057 exit(1); 00058 } 00059 } 00060 } 00061 }
KDE 4.6 API Reference