]> git.saurik.com Git - apple/securityd.git/blob - src/AuthorizationDBPlist.h
4cbd6a50707682011cd192846abf6eda8b3bf9f0
[apple/securityd.git] / src / AuthorizationDBPlist.h
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 *
25 * AuthorizationDBPlist.h
26 * Security
27 *
28 */
29 #ifndef _H_AUTHORIZATIONDBPLIST
30 #define _H_AUTHORIZATIONDBPLIST 1
31
32 #include <CoreFoundation/CoreFoundation.h>
33 #include <security_utilities/cfutilities.h>
34
35 #include <security_cdsa_utilities/AuthorizationData.h>
36 #include "AuthorizationRule.h"
37
38 class AuthorizationDBPlist; // @@@ the ordering sucks here, maybe engine should include all these and other should only include it
39
40 namespace Authorization
41 {
42
43 class AuthorizationDBPlist /* : public AuthorizationDB */
44 {
45 public:
46 AuthorizationDBPlist(const char *configFile = "/etc/authorization");
47
48 void sync(CFAbsoluteTime now);
49 bool validateRule(string inRightName, CFDictionaryRef inRightDefinition) const;
50 CFDictionaryRef getRuleDefinition(string &key);
51
52 bool existRule(string &ruleName) const;
53 Rule getRule(const AuthItemRef &inRight) const;
54
55 void setRule(const char *inRightName, CFDictionaryRef inRuleDefinition);
56 void removeRule(const char *inRightName);
57
58 protected:
59 void load(CFTimeInterval now);
60 void save() const;
61
62 private:
63 string mFileName;
64
65 private:
66 enum { kTypeRight, kTypeRule };
67 void parseConfig(CFDictionaryRef config);
68 static void parseRule(const void *key, const void *value, void *context);
69 void addRight(CFStringRef key, CFDictionaryRef definition);
70
71 CFAbsoluteTime mLastChecked;
72 struct timespec mRulesFileMtimespec;
73
74 map<string,Rule> mRules;
75 CFRef<CFDictionaryRef> mConfig;
76 CFRef<CFMutableDictionaryRef> mConfigRights;
77 CFRef<CFMutableDictionaryRef> mConfigRules;
78
79 mutable Mutex mLock; // rule map lock
80 mutable Mutex mReadWriteLock; // file operation lock
81 };
82
83 }; /* namespace Authorization */
84
85 #endif /* ! _H_AUTHORIZATIONDBPLIST */