]> git.saurik.com Git - apple/security.git/blob - cdsa/mds/MDSSchema.cpp
Security-54.tar.gz
[apple/security.git] / cdsa / mds / MDSSchema.cpp
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, 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 // MDSSchema.cpp
21 //
22 // Definitions of structures which define the schema, including attributes
23 // and indexes, for the standard tables that are part of the MDS database.
24 //
25
26 #include "MDSSchema.h"
27 #include <Security/mds_schema.h>
28 #include <cstring>
29
30 namespace Security
31 {
32
33 /*
34 * There appears to be a bug in AppleDatabase which prevents our assigning
35 * schema to the meta-tables.
36 */
37 #define DEFINE_META_TABLES 0
38
39 /* indicates "no MDSNameValuePair table" in a RELATION_INFO declaration. */
40 #define NO_NVP NULL
41
42 //
43 // Schema for the lone table in the Object Directory Database.
44 //
45 static const CSSM_DB_ATTRIBUTE_INFO objectAttrs[] = {
46 DB_ATTRIBUTE(ModuleID, STRING),
47 DB_ATTRIBUTE(Manifest, BLOB),
48 DB_ATTRIBUTE(ModuleName, STRING),
49 DB_ATTRIBUTE(Path, STRING),
50 DB_ATTRIBUTE(ProductVersion, STRING),
51
52 /* not in the CDSA spec; denotes a plugin which is statically linked to CSSM */
53 DB_ATTRIBUTE(BuiltIn, UINT32),
54 };
55
56 static const CSSM_DB_INDEX_INFO objectIndex[] = {
57 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING)
58 };
59
60 const RelationInfo kObjectRelation =
61 RELATION_INFO(MDS_OBJECT_RECORDTYPE,
62 objectAttrs,
63 NO_NVP, // no symbolic names
64 objectIndex);
65
66 //
67 // Schema for the various tables in the CDSA Directory Database.
68 //
69
70 // CSSM Relation.
71 static const CSSM_DB_ATTRIBUTE_INFO cssmAttrs[] =
72 {
73 DB_ATTRIBUTE(ModuleID, STRING),
74 DB_ATTRIBUTE(CDSAVersion, STRING),
75 DB_ATTRIBUTE(Vendor, STRING),
76 DB_ATTRIBUTE(Desc, STRING),
77 DB_ATTRIBUTE(NativeServices, UINT32),
78 };
79
80 static const MDSNameValuePair *cssmNvp[] = {
81 NULL, NULL, NULL, NULL,
82 MDSServiceNames
83 };
84
85 static const CSSM_DB_INDEX_INFO cssmIndex[] =
86 {
87 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING)
88 };
89
90 // KRMM Relation.
91 static const CSSM_DB_ATTRIBUTE_INFO krmmAttrs[] =
92 {
93 DB_ATTRIBUTE(CSSMGuid, STRING),
94 DB_ATTRIBUTE(PolicyType, UINT32),
95 DB_ATTRIBUTE(PolicyName, STRING),
96 DB_ATTRIBUTE(PolicyPath, STRING),
97 DB_ATTRIBUTE(PolicyInfo, BLOB),
98 DB_ATTRIBUTE(PolicyManifest, BLOB),
99 /*
100 * This attribute is not defined in the CDSA spec. It's only here, in the schema,
101 * to avoid throwing exceptions when searching a DB for any records associated
102 * with a specified GUID - in all other schemas, a guid is specified as a
103 * ModuleID.
104 */
105 DB_ATTRIBUTE(ModuleID, STRING),
106 };
107
108 static const MDSNameValuePair *krmmNvp[] = {
109 NULL, MDSKrPolicyTypeNames, NULL, NULL,
110 NULL, NULL,
111 };
112
113 static const CSSM_DB_INDEX_INFO krmmIndex[] =
114 {
115 UNIQUE_INDEX_ATTRIBUTE(CSSMGuid, STRING),
116 UNIQUE_INDEX_ATTRIBUTE(PolicyType, UINT32)
117 };
118
119 // EMM Relation.
120 static const CSSM_DB_ATTRIBUTE_INFO emmAttrs[] =
121 {
122 DB_ATTRIBUTE(ModuleID, STRING),
123 DB_ATTRIBUTE(Manifest, BLOB),
124 DB_ATTRIBUTE(ModuleName, STRING),
125 DB_ATTRIBUTE(Path, STRING),
126 DB_ATTRIBUTE(CDSAVersion, STRING),
127 DB_ATTRIBUTE(EMMSpecVersion, STRING),
128 DB_ATTRIBUTE(Desc, STRING),
129 DB_ATTRIBUTE(PolicyStmt, BLOB),
130 DB_ATTRIBUTE(EmmVersion, STRING),
131 DB_ATTRIBUTE(EmmVendor, STRING),
132 DB_ATTRIBUTE(EmmType, UINT32), // does this need a name/value table?
133 };
134
135 static const CSSM_DB_INDEX_INFO emmIndex[] =
136 {
137 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING)
138 };
139
140 // Primary EMM Service Provider Relation.
141 static const CSSM_DB_ATTRIBUTE_INFO emmPrimaryAttrs[] =
142 {
143 DB_ATTRIBUTE(ModuleID, STRING),
144 DB_ATTRIBUTE(SSID, UINT32),
145 DB_ATTRIBUTE(ServiceType, UINT32),
146 DB_ATTRIBUTE(Manifest, BLOB),
147 DB_ATTRIBUTE(ModuleName, STRING),
148 DB_ATTRIBUTE(ProductVersion, STRING),
149 DB_ATTRIBUTE(Vendor, STRING),
150 DB_ATTRIBUTE(SampleTypes, MULTI_UINT32),
151 DB_ATTRIBUTE(AclSubjectTypes, MULTI_UINT32),
152 DB_ATTRIBUTE(AuthTags, MULTI_UINT32),
153 DB_ATTRIBUTE(EmmSpecVersion, STRING),
154 };
155
156 static const MDSNameValuePair *emmPrimaryNvp[] = {
157 NULL, NULL, NULL, NULL,
158 NULL, NULL, NULL, MDSSampleTypeNames,
159 MDSAclSubjectTypeNames,
160 MDSAclAuthTagNames,
161 NULL
162 };
163
164 static const CSSM_DB_INDEX_INFO emmPrimaryIndex[] =
165 {
166 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
167 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32),
168 UNIQUE_INDEX_ATTRIBUTE(ServiceType, UINT32)
169 };
170
171 // Common Relation.
172 static const CSSM_DB_ATTRIBUTE_INFO commonAttrs[] =
173 {
174 DB_ATTRIBUTE(ModuleID, STRING),
175 DB_ATTRIBUTE(Manifest, BLOB),
176 DB_ATTRIBUTE(ModuleName, STRING),
177 DB_ATTRIBUTE(Path, STRING),
178 DB_ATTRIBUTE(CDSAVersion, STRING),
179 DB_ATTRIBUTE(Desc, STRING),
180 DB_ATTRIBUTE(DynamicFlag, UINT32),
181 DB_ATTRIBUTE(MultiThreadFlag, UINT32),
182 DB_ATTRIBUTE(ServiceMask, UINT32),
183 };
184
185 static const MDSNameValuePair *commonNvp[] = {
186 NULL, NULL, NULL, NULL,
187 NULL, NULL, NULL, NULL,
188 MDSServiceNames
189 };
190
191 static const CSSM_DB_INDEX_INFO commonIndex[] =
192 {
193 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING)
194 };
195
196 // CSP Primary Relation.
197 static const CSSM_DB_ATTRIBUTE_INFO cspPrimaryAttrs[] =
198 {
199 DB_ATTRIBUTE(ModuleID, STRING),
200 DB_ATTRIBUTE(SSID, UINT32),
201 DB_ATTRIBUTE(Manifest, BLOB),
202 DB_ATTRIBUTE(ModuleName, STRING),
203 DB_ATTRIBUTE(ProductVersion, STRING),
204 DB_ATTRIBUTE(Vendor, STRING),
205 DB_ATTRIBUTE(CspType, UINT32),
206 DB_ATTRIBUTE(CspFlags, UINT32),
207 DB_ATTRIBUTE(CspCustomFlags, UINT32),
208 DB_ATTRIBUTE(UseeTags, MULTI_UINT32),
209 DB_ATTRIBUTE(SampleTypes, MULTI_UINT32),
210 DB_ATTRIBUTE(AclSubjectTypes, MULTI_UINT32),
211 DB_ATTRIBUTE(AuthTags, MULTI_UINT32),
212 };
213
214 static const MDSNameValuePair *cspPrimaryNvp[] = {
215 NULL, NULL, NULL, NULL,
216 NULL, NULL,
217 MDSCspTypeNames,
218 MDSCspFlagsNames,
219 NULL,
220 MDSUseeTagsNames,
221 MDSSampleTypeNames,
222 MDSAclSubjectTypeNames,
223 MDSAclAuthTagNames
224 };
225
226 static const CSSM_DB_INDEX_INFO cspPrimaryIndex[] =
227 {
228 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
229 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
230 };
231
232 // CSP Capabilities Relation.
233 static const CSSM_DB_ATTRIBUTE_INFO cspCapabilitiesAttrs[] =
234 {
235 DB_ATTRIBUTE(ModuleID, STRING),
236 DB_ATTRIBUTE(SSID, UINT32),
237 DB_ATTRIBUTE(UseeTag, UINT32),
238 DB_ATTRIBUTE(ContextType, UINT32),
239 DB_ATTRIBUTE(AlgType, UINT32),
240 DB_ATTRIBUTE(GroupId, UINT32),
241 DB_ATTRIBUTE(AttributeType, UINT32),
242 DB_ATTRIBUTE(AttributeValue, MULTI_UINT32),
243 DB_ATTRIBUTE(Description, STRING),
244 };
245 static const MDSNameValuePair *cspCapabilitiesNvp[] = {
246 NULL,
247 NULL,
248 MDSUseeTagsNames,
249 MDSContextTypeNames,
250 MDSAlgorithmNames,
251 NULL,
252 MDSAttributeTypeNames,
253 NULL,
254 NULL
255 };
256
257 static const CSSM_DB_INDEX_INFO cspCapabilitiesIndex[] =
258 {
259 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
260 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32),
261 UNIQUE_INDEX_ATTRIBUTE(UseeTag, UINT32),
262 UNIQUE_INDEX_ATTRIBUTE(ContextType, UINT32),
263 UNIQUE_INDEX_ATTRIBUTE(AlgType, UINT32),
264 UNIQUE_INDEX_ATTRIBUTE(GroupId, UINT32),
265 UNIQUE_INDEX_ATTRIBUTE(AttributeType, STRING)
266 };
267
268 // special case "subschema" for parsing CSPCapabilities. These arrays correspond
269 // dictionaries within a CSPCapabilities info file; they are not part of
270 // our DB's schema. They are declared only to streamline the
271 // MDSAttrParser::parseCspCapabilitiesRecord function. No index info is needed.
272
273 // top-level info, applied to the dictionary for the whole file.
274 static const CSSM_DB_ATTRIBUTE_INFO kAttributesCSPCapabilitiesDict1[] =
275 {
276 DB_ATTRIBUTE(ModuleID, STRING),
277 DB_ATTRIBUTE(SSID, UINT32),
278 };
279 const RelationInfo CSPCapabilitiesDict1RelInfo =
280 RELATION_INFO(
281 MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE, // actually a don't care
282 kAttributesCSPCapabilitiesDict1,
283 NULL, // no NVP needed
284 NULL); // no index
285
286 // "Capabilities" is an array of dictionaries of these
287 static const CSSM_DB_ATTRIBUTE_INFO kAttributesCSPCapabilitiesDict2[] =
288 {
289 DB_ATTRIBUTE(AlgType, UINT32),
290 DB_ATTRIBUTE(ContextType, UINT32),
291 DB_ATTRIBUTE(UseeTag, UINT32),
292 DB_ATTRIBUTE(Description, STRING),
293 };
294 static const MDSNameValuePair *CSPCapabilitiesDict2Nvp[] = {
295 MDSAlgorithmNames,
296 MDSContextTypeNames,
297 MDSUseeTagsNames,
298 NULL
299 };
300 const RelationInfo CSPCapabilitiesDict2RelInfo =
301 RELATION_INFO(
302 MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE, // actually a don't care
303 kAttributesCSPCapabilitiesDict2,
304 CSPCapabilitiesDict2Nvp,
305 NULL); // no index
306
307 // Within a Capabilities array, the Attributes array is an array of
308 // Dictionaries of these.
309 static const CSSM_DB_ATTRIBUTE_INFO kAttributesCSPCapabilitiesDict3[] =
310 {
311 DB_ATTRIBUTE(AttributeType, UINT32),
312 DB_ATTRIBUTE(AttributeValue, MULTI_UINT32),
313 };
314 static const MDSNameValuePair *CSPCapabilitiesDict3Nvp[] = {
315 MDSAttributeTypeNames,
316 NULL
317 };
318 const RelationInfo CSPCapabilitiesDict3RelInfo =
319 RELATION_INFO(
320 MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE, // actually a don't care
321 kAttributesCSPCapabilitiesDict3,
322 CSPCapabilitiesDict3Nvp,
323 NULL);
324
325
326
327 // CSP Encapsulated Products Relation.
328 static const CSSM_DB_ATTRIBUTE_INFO cspEncapsulatedAttrs[] =
329 {
330 DB_ATTRIBUTE(ModuleID, STRING),
331 DB_ATTRIBUTE(SSID, UINT32),
332 DB_ATTRIBUTE(ProductDesc, STRING),
333 DB_ATTRIBUTE(ProductVendor, STRING),
334 DB_ATTRIBUTE(ProductVersion, STRING),
335 DB_ATTRIBUTE(ProductFlags, UINT32),
336 DB_ATTRIBUTE(CustomFlags, UINT32),
337 DB_ATTRIBUTE(StandardDesc, STRING),
338 DB_ATTRIBUTE(StandardVersion, STRING),
339 DB_ATTRIBUTE(ReaderDesc, STRING),
340 DB_ATTRIBUTE(ReaderVendor, STRING),
341 DB_ATTRIBUTE(ReaderVersion, STRING),
342 DB_ATTRIBUTE(ReaderFirmwareVersion, STRING),
343 DB_ATTRIBUTE(ReaderFlags, UINT32),
344 DB_ATTRIBUTE(ReaderCustomFlags, UINT32),
345 DB_ATTRIBUTE(ReaderSerialNumber, STRING),
346 };
347
348 static const MDSNameValuePair *cspEncapsulatedNvp[] = {
349 NULL, NULL, NULL, NULL,
350 NULL, NULL, NULL, NULL,
351 NULL, NULL, NULL, NULL,
352 NULL, MDSCspReaderFlagsNames, NULL, NULL
353 };
354
355 static const CSSM_DB_INDEX_INFO cspEncapsulatedIndex[] =
356 {
357 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
358 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
359 };
360
361 // CSP Smartcardinfo Relation.
362 static const CSSM_DB_ATTRIBUTE_INFO cspSmartCardAttrs[] =
363 {
364 DB_ATTRIBUTE(ModuleID, STRING),
365 DB_ATTRIBUTE(SSID, UINT32),
366 DB_ATTRIBUTE(ScDesc, STRING),
367 DB_ATTRIBUTE(ScVendor, STRING),
368 DB_ATTRIBUTE(ScVersion, STRING),
369 DB_ATTRIBUTE(ScFirmwareVersion, STRING),
370 DB_ATTRIBUTE(ScFlags, UINT32),
371 DB_ATTRIBUTE(ScCustomFlags, UINT32),
372 DB_ATTRIBUTE(ScSerialNumber, STRING),
373 };
374 static const MDSNameValuePair *cspSmartCardNvp[] = {
375 NULL, NULL, NULL, NULL,
376 NULL, NULL, MDSCspScFlagsNames, NULL,
377 NULL,
378 };
379
380 static const CSSM_DB_INDEX_INFO cspSmartCardIndex[] =
381 {
382 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
383 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32),
384 UNIQUE_INDEX_ATTRIBUTE(ScDesc, STRING),
385 UNIQUE_INDEX_ATTRIBUTE(ScVendor, STRING),
386 UNIQUE_INDEX_ATTRIBUTE(ScVersion, STRING),
387 UNIQUE_INDEX_ATTRIBUTE(ScFirmwareVersion, STRING),
388 UNIQUE_INDEX_ATTRIBUTE(ScFlags, UINT32)
389 };
390
391 // DL Primary Relation.
392 static const CSSM_DB_ATTRIBUTE_INFO dlPrimaryAttrs[] =
393 {
394 DB_ATTRIBUTE(ModuleID, STRING),
395 DB_ATTRIBUTE(SSID, UINT32),
396 DB_ATTRIBUTE(Manifest, BLOB),
397 DB_ATTRIBUTE(ModuleName, STRING),
398 DB_ATTRIBUTE(ProductVersion, STRING),
399 DB_ATTRIBUTE(Vendor, STRING),
400 DB_ATTRIBUTE(DLType, UINT32),
401 DB_ATTRIBUTE(QueryLimitsFlag, UINT32), // a completely bogus attr; see spec
402 DB_ATTRIBUTE(SampleTypes, MULTI_UINT32),
403 DB_ATTRIBUTE(AclSubjectTypes, MULTI_UINT32),
404 DB_ATTRIBUTE(AuthTags, MULTI_UINT32),
405 DB_ATTRIBUTE(ConjunctiveOps, MULTI_UINT32),
406 DB_ATTRIBUTE(RelationalOps, MULTI_UINT32),
407 };
408 static const MDSNameValuePair *dlPrimaryNvp[] = {
409 NULL, NULL, NULL, NULL,
410 NULL, NULL, MDSDlTypeNames, NULL,
411 MDSSampleTypeNames,
412 MDSAclSubjectTypeNames,
413 MDSAclAuthTagNames,
414 MDSDbConjunctiveNames,
415 MDSDbOperatorNames
416 };
417 static const CSSM_DB_INDEX_INFO dlPrimaryIndex[] =
418 {
419 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
420 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
421 };
422
423 // DL Encapsulated Products Relation.
424 static const CSSM_DB_ATTRIBUTE_INFO dlEncapsulatedAttrs[] =
425 {
426 DB_ATTRIBUTE(ModuleID, STRING),
427 DB_ATTRIBUTE(SSID, UINT32),
428 DB_ATTRIBUTE(ProductDesc, STRING),
429 DB_ATTRIBUTE(ProductVendor, STRING),
430 DB_ATTRIBUTE(ProductVersion, STRING),
431 DB_ATTRIBUTE(ProductFlags, UINT32),
432 DB_ATTRIBUTE(StandardDesc, STRING),
433 DB_ATTRIBUTE(StandardVersion, STRING),
434 DB_ATTRIBUTE(Protocol, UINT32),
435 DB_ATTRIBUTE(RetrievalMode, UINT32),
436 };
437
438 static const MDSNameValuePair *dlEncapsulatedNvp[] = {
439 NULL, NULL, NULL, NULL,
440 NULL, NULL, NULL, NULL,
441 MDSNetProtocolNames,
442 MDSDbRetrievalModeNames
443 };
444
445 static const CSSM_DB_INDEX_INFO dlEncapsulatedIndex[] =
446 {
447 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
448 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
449 };
450
451 // CL Primary Relation.
452 static const CSSM_DB_ATTRIBUTE_INFO clPrimaryAttrs[] =
453 {
454 DB_ATTRIBUTE(ModuleID, STRING),
455 DB_ATTRIBUTE(SSID, UINT32),
456 DB_ATTRIBUTE(Manifest, BLOB),
457 DB_ATTRIBUTE(ModuleName, STRING),
458 DB_ATTRIBUTE(ProductVersion, STRING),
459 DB_ATTRIBUTE(Vendor, STRING),
460 DB_ATTRIBUTE(CertTypeFormat, UINT32),
461 DB_ATTRIBUTE(CrlTypeFormat, UINT32),
462 DB_ATTRIBUTE(CertFieldNames, BLOB),
463 DB_ATTRIBUTE(BundleTypeFormat, MULTI_UINT32),
464 DB_ATTRIBUTE(XlationTypeFormat, MULTI_UINT32),
465 DB_ATTRIBUTE(TemplateFieldNames, BLOB),
466 };
467
468 static const MDSNameValuePair *clPrimaryNvp[] = {
469 NULL, NULL, NULL, NULL,
470 NULL, NULL, MDSCertTypeNames, MDSCrlTypeNames,
471 NULL,
472 MDSCertBundleTypeNames,
473 MDSCertTypeNames, // translation type - same as cert type - right?
474 NULL
475 };
476
477 static const CSSM_DB_INDEX_INFO clPrimaryIndex[] =
478 {
479 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
480 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
481 };
482
483 // CL Encapsulated Products Relation.
484 static const CSSM_DB_ATTRIBUTE_INFO clEncapsulatedAttrs[] =
485 {
486 DB_ATTRIBUTE(ModuleID, STRING),
487 DB_ATTRIBUTE(SSID, UINT32),
488 DB_ATTRIBUTE(ProductDesc, STRING),
489 DB_ATTRIBUTE(ProductVendor, STRING),
490 DB_ATTRIBUTE(ProductVersion, STRING),
491 DB_ATTRIBUTE(ProductFlags, UINT32),
492 DB_ATTRIBUTE(StandardDesc, STRING),
493 DB_ATTRIBUTE(StandardVersion, STRING),
494 };
495
496 static const CSSM_DB_INDEX_INFO clEncapsulatedIndex[] =
497 {
498 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
499 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
500 };
501
502 // TP Primary Relation.
503 static const CSSM_DB_ATTRIBUTE_INFO tpPrimaryAttrs[] =
504 {
505 DB_ATTRIBUTE(ModuleID, STRING),
506 DB_ATTRIBUTE(SSID, UINT32),
507 DB_ATTRIBUTE(Manifest, BLOB),
508 DB_ATTRIBUTE(ModuleName, STRING),
509 DB_ATTRIBUTE(ProductVersion, STRING),
510 DB_ATTRIBUTE(Vendor, STRING),
511 DB_ATTRIBUTE(CertTypeFormat, UINT32),
512 DB_ATTRIBUTE(SampleTypes, MULTI_UINT32),
513 DB_ATTRIBUTE(AclSubjectTypes, MULTI_UINT32),
514 DB_ATTRIBUTE(AuthTags, MULTI_UINT32),
515 };
516
517 static const MDSNameValuePair *tpPrimaryNvp[] = {
518 NULL, NULL, NULL, NULL,
519 NULL, NULL,
520 MDSCertTypeNames,
521 MDSSampleTypeNames,
522 MDSAclSubjectTypeNames,
523 MDSAclAuthTagNames,
524 };
525
526 static const CSSM_DB_INDEX_INFO tpPrimaryIndex[] =
527 {
528 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
529 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
530 };
531
532 // TP Policy-OIDs Relation.
533 static const CSSM_DB_ATTRIBUTE_INFO tpPolicyOidsAttrs[] =
534 {
535 DB_ATTRIBUTE(ModuleID, STRING),
536 DB_ATTRIBUTE(SSID, UINT32),
537 DB_ATTRIBUTE(OID, BLOB),
538 DB_ATTRIBUTE(Value, BLOB),
539 };
540
541 static const CSSM_DB_INDEX_INFO tpPolicyOidsIndex[] =
542 {
543 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
544 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32),
545 UNIQUE_INDEX_ATTRIBUTE(OID, BLOB)
546 };
547
548 // special case "subschema" for parsing tpPolicyOidsAttrs. These arrays correspond
549 // dictionaries within a tpPolicyOidsAttrs info file; they are not part of
550 // our DB's schema. They are declared only to streamline the
551 // MDSAttrParser::parseTpPolicyOidsRecord function. No index info is needed.
552
553 // top-level info, applied to the dictionary for the whole file.
554 static const CSSM_DB_ATTRIBUTE_INFO tpPolicyOidsDict1[] =
555 {
556 DB_ATTRIBUTE(ModuleID, STRING),
557 DB_ATTRIBUTE(SSID, UINT32),
558 };
559 const RelationInfo TpPolicyOidsDict1RelInfo =
560 RELATION_INFO(
561 MDS_CDSADIR_TP_OIDS_RECORDTYPE, // actually a don't care
562 tpPolicyOidsDict1,
563 NULL, // no NVP needed
564 NULL); // no index
565
566 // One element of the "Policies" array maps to one of these.
567 static const CSSM_DB_ATTRIBUTE_INFO tpPolicyOidsDict2[] =
568 {
569 DB_ATTRIBUTE(OID, BLOB),
570 DB_ATTRIBUTE(Value, BLOB),
571 };
572 const RelationInfo TpPolicyOidsDict2RelInfo =
573 RELATION_INFO(
574 MDS_CDSADIR_TP_OIDS_RECORDTYPE, // actually a don't care
575 tpPolicyOidsDict2,
576 NULL, // no NVP needed
577 NULL); // no index
578
579 // TP Encapsulated Products Relation.
580 static const CSSM_DB_ATTRIBUTE_INFO tpEncapsulatedAttrs[] =
581 {
582 DB_ATTRIBUTE(ModuleID, STRING),
583 DB_ATTRIBUTE(SSID, UINT32),
584 DB_ATTRIBUTE(ProductDesc, STRING),
585 DB_ATTRIBUTE(ProductVendor, STRING),
586 DB_ATTRIBUTE(ProductVersion, STRING),
587 DB_ATTRIBUTE(ProductFlags, UINT32), // vendor-specific, right?
588 DB_ATTRIBUTE(AuthorityRequestType, MULTI_UINT32),
589 DB_ATTRIBUTE(StandardDesc, STRING),
590 DB_ATTRIBUTE(StandardVersion, STRING),
591 DB_ATTRIBUTE(ProtocolDesc, STRING),
592 DB_ATTRIBUTE(ProtocolFlags, UINT32),
593 DB_ATTRIBUTE(CertClassName, STRING),
594 DB_ATTRIBUTE(RootCertificate, BLOB),
595 DB_ATTRIBUTE(RootCertTypeFormat, UINT32),
596 };
597 static const MDSNameValuePair *tpEncapsulatedNvp[] = {
598 NULL, NULL, NULL, NULL,
599 NULL, NULL, MDSTpAuthRequestNames, NULL,
600 NULL, NULL, NULL, NULL,
601 NULL, MDSCertTypeNames
602 };
603
604 static const CSSM_DB_INDEX_INFO tpEncapsulatedIndex[] =
605 {
606 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
607 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
608 };
609
610 #if DEFINE_META_TABLES
611 // MDS Schema Relations (meta) Relation.
612 static const CSSM_DB_ATTRIBUTE_INFO mdsSchemaRelationsAttrs[] =
613 {
614 DB_ATTRIBUTE(RelationID, UINT32),
615 DB_ATTRIBUTE(RelationName, STRING),
616 };
617
618 static const CSSM_DB_INDEX_INFO mdsSchemaRelationsIndex[] =
619 {
620 UNIQUE_INDEX_ATTRIBUTE(RelationID, UINT32),
621 };
622
623 // MDS Schema Attributes (meta) Relation.
624 static const CSSM_DB_ATTRIBUTE_INFO mdsSchemaAttributesAttrs[] =
625 {
626 DB_ATTRIBUTE(RelationID, UINT32),
627 DB_ATTRIBUTE(AttributeID, UINT32),
628 DB_ATTRIBUTE(AttributeNameFormat, UINT32),
629 DB_ATTRIBUTE(AttributeName, STRING),
630 DB_ATTRIBUTE(AttributeNameID, BLOB),
631 DB_ATTRIBUTE(AttributeFormat, UINT32),
632 };
633
634 static const CSSM_DB_INDEX_INFO mdsSchemaAttributesIndex[] =
635 {
636 UNIQUE_INDEX_ATTRIBUTE(RelationID, UINT32),
637 UNIQUE_INDEX_ATTRIBUTE(AttributeID, UINT32)
638 };
639
640 // MDS Schema Indexes (meta) Relation.
641 static const CSSM_DB_ATTRIBUTE_INFO mdsSchemaIndexesAttrs[] =
642 {
643 DB_ATTRIBUTE(RelationID, UINT32),
644 DB_ATTRIBUTE(IndexID, UINT32),
645 DB_ATTRIBUTE(AttributeID, UINT32),
646 DB_ATTRIBUTE(IndexType, UINT32),
647 DB_ATTRIBUTE(IndexedDataLocation, UINT32),
648 };
649
650 static const CSSM_DB_INDEX_INFO mdsSchemaIndexesIndex[] =
651 {
652 UNIQUE_INDEX_ATTRIBUTE(RelationID, UINT32),
653 UNIQUE_INDEX_ATTRIBUTE(IndexID, UINT32)
654 };
655
656 #endif /* DEFINE_META_TABLES */
657
658 // AC Primary Relation.
659 static const CSSM_DB_ATTRIBUTE_INFO acPrimaryAttrs[] =
660 {
661 DB_ATTRIBUTE(ModuleID, STRING),
662 DB_ATTRIBUTE(SSID, UINT32),
663 DB_ATTRIBUTE(Manifest, BLOB),
664 DB_ATTRIBUTE(ModuleName, STRING),
665 DB_ATTRIBUTE(ProductVersion, STRING),
666 DB_ATTRIBUTE(Vendor, STRING),
667 };
668
669 static const CSSM_DB_INDEX_INFO acPrimaryIndex[] =
670 {
671 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
672 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
673 };
674
675 // KR Primary Relation.
676 static const CSSM_DB_ATTRIBUTE_INFO krPrimaryAttrs[] =
677 {
678 DB_ATTRIBUTE(ModuleID, STRING),
679 DB_ATTRIBUTE(SSID, UINT32),
680 DB_ATTRIBUTE(Manifest, BLOB),
681 DB_ATTRIBUTE(ModuleName, STRING),
682 DB_ATTRIBUTE(CompatCSSMVersion, STRING),
683 DB_ATTRIBUTE(Version, STRING),
684 DB_ATTRIBUTE(Vendor, STRING),
685 DB_ATTRIBUTE(Description, STRING),
686 DB_ATTRIBUTE(ConfigFileLocation, STRING),
687 };
688
689 static const CSSM_DB_INDEX_INFO krPrimaryIndex[] =
690 {
691 UNIQUE_INDEX_ATTRIBUTE(ModuleID, STRING),
692 UNIQUE_INDEX_ATTRIBUTE(SSID, UINT32)
693 };
694
695 // list of all built-in schema for the CDSA Directory DB.
696 const RelationInfo kMDSRelationInfo[] =
697 {
698 RELATION_INFO(MDS_CDSADIR_CSSM_RECORDTYPE,
699 cssmAttrs,
700 cssmNvp,
701 cssmIndex),
702 RELATION_INFO(MDS_CDSADIR_KRMM_RECORDTYPE,
703 krmmAttrs,
704 krmmNvp,
705 krmmIndex),
706 RELATION_INFO(MDS_CDSADIR_EMM_RECORDTYPE,
707 emmAttrs,
708 NO_NVP, // FIXME - what is the uint32 EmmType here?
709 emmIndex),
710 RELATION_INFO(MDS_CDSADIR_EMM_PRIMARY_RECORDTYPE,
711 emmPrimaryAttrs,
712 emmPrimaryNvp,
713 emmPrimaryIndex),
714 RELATION_INFO(MDS_CDSADIR_COMMON_RECORDTYPE,
715 commonAttrs,
716 commonNvp,
717 commonIndex),
718 RELATION_INFO(MDS_CDSADIR_CSP_PRIMARY_RECORDTYPE,
719 cspPrimaryAttrs,
720 cspPrimaryNvp,
721 cspPrimaryIndex),
722 RELATION_INFO(MDS_CDSADIR_CSP_CAPABILITY_RECORDTYPE,
723 cspCapabilitiesAttrs,
724 cspCapabilitiesNvp,
725 cspCapabilitiesIndex),
726 RELATION_INFO(MDS_CDSADIR_CSP_ENCAPSULATED_PRODUCT_RECORDTYPE,
727 cspEncapsulatedAttrs,
728 cspEncapsulatedNvp,
729 cspEncapsulatedIndex),
730 RELATION_INFO(MDS_CDSADIR_CSP_SC_INFO_RECORDTYPE,
731 cspSmartCardAttrs,
732 cspSmartCardNvp,
733 cspSmartCardIndex),
734 RELATION_INFO(MDS_CDSADIR_DL_PRIMARY_RECORDTYPE,
735 dlPrimaryAttrs,
736 dlPrimaryNvp,
737 dlPrimaryIndex),
738 RELATION_INFO(MDS_CDSADIR_DL_ENCAPSULATED_PRODUCT_RECORDTYPE,
739 dlEncapsulatedAttrs,
740 dlEncapsulatedNvp,
741 dlEncapsulatedIndex),
742 RELATION_INFO(MDS_CDSADIR_CL_PRIMARY_RECORDTYPE,
743 clPrimaryAttrs,
744 clPrimaryNvp,
745 clPrimaryIndex),
746 RELATION_INFO(MDS_CDSADIR_CL_ENCAPSULATED_PRODUCT_RECORDTYPE,
747 clEncapsulatedAttrs,
748 NO_NVP, // none needed
749 clEncapsulatedIndex),
750 RELATION_INFO(MDS_CDSADIR_TP_PRIMARY_RECORDTYPE,
751 tpPrimaryAttrs,
752 tpPrimaryNvp,
753 tpPrimaryIndex),
754 RELATION_INFO(MDS_CDSADIR_TP_OIDS_RECORDTYPE,
755 tpPolicyOidsAttrs,
756 NO_NVP, // none needed
757 tpPolicyOidsIndex),
758 RELATION_INFO(MDS_CDSADIR_TP_ENCAPSULATED_PRODUCT_RECORDTYPE,
759 tpEncapsulatedAttrs,
760 tpEncapsulatedNvp,
761 tpEncapsulatedIndex),
762 #if DEFINE_META_TABLES
763 RELATION_INFO(MDS_CDSADIR_MDS_SCHEMA_RELATIONS,
764 mdsSchemaRelationsAttrs,
765 NO_NVP,
766 mdsSchemaRelationsIndex),
767 RELATION_INFO(MDS_CDSADIR_MDS_SCHEMA_ATTRIBUTES,
768 mdsSchemaAttributesAttrs,
769 NO_NVP,
770 mdsSchemaAttributesIndex),
771 RELATION_INFO(MDS_CDSADIR_MDS_SCHEMA_INDEXES,
772 mdsSchemaIndexesAttrs,
773 NO_NVP,
774 mdsSchemaIndexesIndex),
775 #endif /* DEFINE_META_TABLES */
776 RELATION_INFO(MDS_CDSADIR_AC_PRIMARY_RECORDTYPE,
777 acPrimaryAttrs,
778 NO_NVP, // none needed
779 acPrimaryIndex),
780 RELATION_INFO(MDS_CDSADIR_KR_PRIMARY_RECORDTYPE,
781 krPrimaryAttrs,
782 NO_NVP, // none needed
783 krPrimaryIndex)
784 };
785
786 const unsigned kNumMdsRelations = sizeof(kMDSRelationInfo) / sizeof(RelationInfo);
787
788 // Map a CSSM_DB_RECORDTYPE to a RelationInfo *.
789 extern const RelationInfo *MDSRecordTypeToRelation(
790 CSSM_DB_RECORDTYPE recordType)
791 {
792 const RelationInfo *relInfo = kMDSRelationInfo;
793 unsigned dex;
794
795 for(dex=0; dex<kNumMdsRelations; dex++) {
796 if(relInfo->DataRecordType == recordType) {
797 return relInfo;
798 }
799 relInfo++;
800 }
801 if(recordType == MDS_OBJECT_RECORDTYPE) {
802 return &kObjectRelation;
803 }
804 return NULL;
805 }
806
807 // same as above, based on record type as string.
808 extern const RelationInfo *MDSRecordTypeNameToRelation(
809 const char *recordTypeName)
810 {
811 const RelationInfo *relInfo = kMDSRelationInfo;
812 unsigned dex;
813
814 for(dex=0; dex<kNumMdsRelations; dex++) {
815 if(!strcmp(recordTypeName, relInfo->relationName)) {
816 return relInfo;
817 }
818 relInfo++;
819 }
820 return NULL;
821 }
822
823 } // end namespace Security