]> git.saurik.com Git - apple/security.git/blob - OSX/utilities/src/SecADWrapper.c
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / utilities / src / SecADWrapper.c
1 /*
2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include "SecADWrapper.h"
25
26 #if TARGET_OS_EMBEDDED
27 #include <AggregateDictionary/ADClient.h>
28
29 static typeof(ADClientAddValueForScalarKey) *soft_ADClientAddValueForScalarKey = NULL;
30 static typeof(ADClientClearScalarKey) *soft_ADClientClearScalarKey = NULL;
31 static typeof(ADClientSetValueForScalarKey) *soft_ADClientSetValueForScalarKey = NULL;
32 static typeof(ADClientPushValueForDistributionKey) *soft_ADClientPushValueForDistributionKey = NULL;
33
34 static bool
35 setup(void)
36 {
37 static dispatch_once_t onceToken;
38 static CFBundleRef bundle = NULL;
39 dispatch_once(&onceToken, ^{
40
41 CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/System/Library/PrivateFrameworks/AggregateDictionary.framework"), kCFURLPOSIXPathStyle, true);
42 if (url == NULL)
43 return;
44
45 bundle = CFBundleCreate(kCFAllocatorDefault, url);
46 CFRelease(url);
47 if (bundle == NULL)
48 return;
49
50 soft_ADClientClearScalarKey = CFBundleGetFunctionPointerForName(bundle, CFSTR("ADClientClearScalarKey"));
51 soft_ADClientSetValueForScalarKey = CFBundleGetFunctionPointerForName(bundle, CFSTR("ADClientSetValueForScalarKey"));
52 soft_ADClientAddValueForScalarKey = CFBundleGetFunctionPointerForName(bundle, CFSTR("ADClientAddValueForScalarKey"));
53 soft_ADClientPushValueForDistributionKey = CFBundleGetFunctionPointerForName(bundle, CFSTR("ADClientPushValueForDistributionKey"));
54
55 if (soft_ADClientClearScalarKey == NULL ||
56 soft_ADClientSetValueForScalarKey == NULL ||
57 soft_ADClientAddValueForScalarKey == NULL ||
58 soft_ADClientPushValueForDistributionKey == NULL)
59 {
60 CFRelease(bundle);
61 bundle = NULL;
62 }
63 });
64 return bundle != NULL;
65 }
66
67 void
68 SecADClearScalarKey(CFStringRef key)
69 {
70 if (setup())
71 soft_ADClientClearScalarKey(key);
72 }
73
74 void
75 SecADSetValueForScalarKey(CFStringRef key, int64_t value)
76 {
77 if (setup())
78 soft_ADClientSetValueForScalarKey(key, value);
79
80 }
81 void
82 SecADAddValueForScalarKey(CFStringRef key, int64_t value)
83 {
84 if (setup())
85 soft_ADClientAddValueForScalarKey(key, value);
86 }
87
88 void
89 SecADClientPushValueForDistributionKey(CFStringRef key, int64_t value)
90 {
91 if (setup())
92 soft_ADClientPushValueForDistributionKey(key, value);
93 }
94
95 #endif