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