]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_mds/lib/MDSAttrUtils.h
Security-58286.200.222.tar.gz
[apple/security.git] / OSX / libsecurity_mds / lib / MDSAttrUtils.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: MDSAttrUtils.h
21
22 Contains: Stateless functions used by MDSAttrParser.
23
24 Copyright (c) 2001,2011,2014 Apple Inc. All Rights Reserved.
25 */
26
27 #ifndef _MDS_ATTR_UTILS_H_
28 #define _MDS_ATTR_UTILS_H_ 1
29
30 #include <Security/cssmtype.h>
31 #include <security_utilities/debugging.h>
32 #include <CoreFoundation/CoreFoundation.h>
33 #include "MDSAttrStrings.h"
34 #include "MDSSession.h"
35
36 /* log parsing events */
37 #define MPDebug(args...) secinfo("MDS_Parse", ## args)
38
39 /* log scanning events */
40 #define MSDebug(args...) secinfo("MDS_Scan", ## args)
41
42 /*
43 * I can't believe that CFRelease does not do this...
44 */
45 #define CF_RELEASE(c) if(c != NULL) { CFRelease(c); c = NULL; }
46
47 namespace Security
48 {
49
50 /*
51 * Fill in one CSSM_DB_ATTRIBUTE_DATA with specified data, type and attribute name.
52 * CSSM_DB_ATTRIBUTE_DATA.Value and its referent are new[]'d and copied.
53 * Assumes:
54 * -- AttributeNameFormat = CSSM_DB_ATTRIBUTE_NAME_AS_STRING
55 */
56 extern void MDSRawValueToDbAttr(
57 const void *value,
58 size_t len,
59 CSSM_DB_ATTRIBUTE_FORMAT attrFormat, // CSSM_DB_ATTRIBUTE_FORMAT_STRING, etc.
60 const char *attrName,
61 CSSM_DB_ATTRIBUTE_DATA &attr,
62 uint32 numValues = 1);
63
64 /*
65 * Free data new[]'d in the above function.
66 */
67 extern void MDSFreeDbRecordAttrs(
68 CSSM_DB_ATTRIBUTE_DATA *attrs,
69 unsigned numAttrs);
70
71
72 /* safely get a new[]'d C string from a CFString */
73 char *MDSCFStringToCString(
74 CFStringRef cfStr);
75
76 /* copy a new[]'d C string from a C string */
77 char *MDSCopyCstring(
78 const char *inStr);
79
80 /*
81 * Given a CFTypeRef which is either a CFString or a CFNumber, do our best to
82 * convert it to a uint32. If it's a CFString, we'll use a MDSNameValuePair
83 * to convert it. CFStrings expressed as decimal numbers are also converted
84 * properly. (MAYBE we'll convert hex strings too...TBD...)
85 * Returns true if conversion was successful.
86 */
87 bool MDSCfTypeToUInt32(
88 CFTypeRef cfValue,
89 const MDSNameValuePair *nameValues, // optional for converting strings to numbers
90 const char *key, // for debug logging only
91 uint32 &value, // RETURNED
92 size_t &valueLen); // RETURNED
93
94 /*
95 * Insert a record, defined by a CSSM_DB_ATTRIBUTE_DATA array, into specified
96 * DL and DB. Returns true on success.
97 */
98 bool MDSInsertRecord(
99 const CSSM_DB_ATTRIBUTE_DATA *inAttr,
100 unsigned numAttrs,
101 CSSM_DB_RECORDTYPE recordType,
102 MDSSession &dl,
103 CSSM_DB_HANDLE dbHand);
104
105 /*
106 * Convert a number expressed as a CFString to a uint32 using the specified
107 * name/value conversion table. The string may have multiple fields from that
108 * table, ORd together in normal C syntax. Like
109 *
110 * CSSM_SERVICE_CSP | CSSM_SERVICE_DL
111 */
112 CSSM_RETURN MDSStringToUint32(
113 CFStringRef str,
114 const MDSNameValuePair *table,
115 uint32 &value); // RETURNED
116
117
118 } // end namespace Security
119
120 #endif /* _MDS_ATTR_UTILS_H_ */