]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_mds/lib/MDSAttrParser.h
Security-59754.41.1.tar.gz
[apple/security.git] / OSX / libsecurity_mds / lib / MDSAttrParser.h
1 /*
2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 File: MDSAttrParser.h
21
22 Contains: Classes to parse XML plists and fill in MDS DBs with the
23 attributes found there.
24
25 Copyright (c) 2001,2011,2014 Apple Inc. All Rights Reserved.
26 */
27
28 #ifndef _MDS_ATTR_PARSER_H_
29 #define _MDS_ATTR_PARSER_H_ 1
30
31 #include <Security/cssmtype.h>
32 #include "MDSSession.h"
33 #include "MDSDictionary.h"
34 #include "MDSAttrStrings.h"
35 #include <CoreFoundation/CoreFoundation.h>
36
37 /*
38 * Hard-coded strings, which we attempt to keep to a minimum
39 */
40
41 /* extension of a bundle's MDS files */
42 #define MDS_INFO_TYPE "mdsinfo"
43
44 /* key in an MDS info file determining whether it's for CSSM, plugin, or
45 * Plugin-specific MDS record type */
46 #define MDS_INFO_FILE_TYPE "MdsFileType"
47
48 /* Values for MDS_INFO_FILE_TYPE */
49 #define MDS_INFO_FILE_TYPE_CSSM "CSSM"
50 #define MDS_INFO_FILE_TYPE_PLUGIN "PluginCommon"
51 #define MDS_INFO_FILE_TYPE_RECORD "PluginSpecific"
52
53 /* For MDS_INFO_FILE_TYPE_RECORD files, this key is used to find the
54 * CSSM_DB_RECORDTYPE associated with the file's info. */
55 #define MDS_INFO_FILE_RECORD_TYPE "MdsRecordType"
56
57 /* key for file description string, for debugging and documentation (since
58 * PropertyListEditor does not support comments) */
59 #define MDS_INFO_FILE_DESC "MdsFileDescription"
60
61
62 namespace Security
63 {
64
65 /*
66 * The purpose of the MDSAttrParser class is to process a set of plist files
67 * in a specified bundle or framework, parsing them to create data which
68 * is written to a pair of open DBs. Each plist file represents the bundle's
69 * entries for one or more MDS relations. Typically a bundle will have
70 * multiple plist files.
71 */
72
73 /* base class for all parsers */
74 class MDSAttrParser
75 {
76 public:
77 MDSAttrParser(
78 const char *bundlePath,
79 MDSSession &dl,
80 CSSM_DB_HANDLE objectHand,
81 CSSM_DB_HANDLE cdsaDirHand);
82 virtual ~MDSAttrParser();
83
84 /* the bulk of the work */
85 void parseAttrs(CFStringRef subdir = NULL);
86
87 /* parse a single file, by path URL -- throws on parse error */
88 void parseFile(CFURLRef theFileUrl, CFStringRef subdir = NULL);
89
90 void setDefaults(const MDS_InstallDefaults *defaults) { mDefaults = defaults; }
91
92 const char *guid() { return mGuid; }
93
94 private:
95 void logFileError(
96 const char *op,
97 CFURLRef file,
98 CFStringRef errStr, // optional if you have it
99 SInt32 *errNo); // optional if you have it
100
101 /*
102 * Parse a CSSM info file.
103 */
104 void parseCssmInfo(
105 MDSDictionary *theDict);
106
107 /*
108 * Parse a Plugin Common info file.
109 */
110 void parsePluginCommon(
111 MDSDictionary *theDict);
112
113 /*
114 * Parse a Plugin-specific file.
115 */
116 void parsePluginSpecific(
117 MDSDictionary *theDict);
118
119 /*
120 * Given an open dictionary (representing a parsed XML file), create
121 * an MDS_OBJECT_RECORDTYPE record and add it to mObjectHand. This is
122 * used by both parseCssmInfo and parsePluginCommon.
123 */
124 void parseObjectRecord(
125 MDSDictionary *dict);
126
127 /*
128 * Given an open dictionary and a RelationInfo defining a schema, fetch all
129 * attributes associated with the specified schema from the dictionary
130 * and write them to specified DB.
131 */
132 void parseMdsRecord(
133 MDSDictionary *mdsDict,
134 const RelationInfo *relInfo,
135 CSSM_DB_HANDLE dbHand);
136
137 /*
138 * Special case handlers for MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE and
139 * MDS_CDSADIR_TP_OIDS_RECORDTYPE.
140 */
141 void parseCspCapabilitiesRecord(
142 MDSDictionary *mdsDict);
143 void parseTpPolicyOidsRecord(
144 MDSDictionary *mdsDict);
145
146 private:
147 /* could be Security.framework or a loadable bundle anywhere */
148 CFBundleRef mBundle;
149 char *mPath;
150
151 /* a DL session and two open DBs - one for object directory, one for
152 * CDSA directory */
153 MDSSession &mDl;
154 CSSM_DB_HANDLE mObjectHand;
155 CSSM_DB_HANDLE mCdsaDirHand;
156
157 char *mGuid; // should this be a CFStringRef instead?
158
159 // Guid/SSID defaults
160 const MDS_InstallDefaults *mDefaults;
161 };
162
163
164 } // end namespace Security
165
166 #endif /* _MDS_ATTR_PARSER_H_ */