1 | /*␊ |
2 | * property_list.h␊ |
3 | *␊ |
4 | * Created by Rekursor on 1/17/10.␊ |
5 | *␊ |
6 | */␊ |
7 | #ifndef __CHPROPERTYLIST_LIST_H␊ |
8 | #define __CHPROPERTYLIST_LIST_H␊ |
9 | ␊ |
10 | #include <CoreFoundation/CFPropertyList.h>␊ |
11 | #include <CoreFoundation/CFURLAccess.h>␊ |
12 | #include <Security/Authorization.h>␊ |
13 | #include <string>␊ |
14 | ␊ |
15 | /****************************************************************/␊ |
16 | ␊ |
17 | /**␊ |
18 | * priviledged command run for cmds like property chmods and restard command␊ |
19 | */␊ |
20 | bool executePrivilegedCmd(AuthorizationRef auth, ␊ |
21 | ␉␉␉␉␉␉ const char* pathToTool, ␊ |
22 | ␉␉␉␉␉␉ const char* args=NULL, ␊ |
23 | ␉␉␉␉␉␉ AuthorizationFlags flags=kAuthorizationFlagDefaults);␊ |
24 | ␊ |
25 | /****************************************************************/␊ |
26 | ␊ |
27 | /**␊ |
28 | * Simple PropertyList Abstraction␊ |
29 | */␊ |
30 | class PropertyList␊ |
31 | {␊ |
32 | ␉␊ |
33 | public:␊ |
34 | ␉PropertyList() : _proplistRef(0), _CFURLRef(0) {␉}␊ |
35 | ␉virtual ~PropertyList();␊ |
36 | ␉␊ |
37 | ␉bool isValid() const { return _proplistRef!=NULL;}␊ |
38 | ␊ |
39 | ␉bool open(const char *propListPath, CFStringRef* errString,␊ |
40 | ␉␉␉ AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults);␊ |
41 | ␉bool save(AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults);␊ |
42 | ␉␊ |
43 | ␉const char * getStringForKey(const char *key);␊ |
44 | ␉const char * getStringForKey(const std::string& key)␊ |
45 | ␉{␊ |
46 | ␉␉std::string str= key;␊ |
47 | ␉␉return getStringForKey(str.c_str());␊ |
48 | ␉}␊ |
49 | ␉bool setStringForKey(const char* key, const char* value);␊ |
50 | ␉bool setStringForKey(const std::string& key, const std::string& value)␊ |
51 | ␉{␊ |
52 | ␉␉return setStringForKey(key.c_str(), value.c_str());␊ |
53 | ␉}␊ |
54 | ␉bool removeKeyAndValue(const char *key);␊ |
55 | ␊ |
56 | ␉const char * propFilePath() const {␉return _propFilePath.c_str(); }␊ |
57 | ␊ |
58 | ␉static bool chmodFile(const char * path, const char * chmodMask,␊ |
59 | ␉␉␉␉␉␉ AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults);␊ |
60 | protected:␊ |
61 | ␉CFPropertyListRef _proplistRef;␊ |
62 | ␉CFURLRef _CFURLRef;␊ |
63 | ␉std::string _propFilePath; // keep a track of the proplist filename␊ |
64 | };␊ |
65 | ␊ |
66 | #endif␊ |
67 | |