]> git.saurik.com Git - apple/security.git/blob - OSX/utilities/SecADWrapper.c
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / utilities / 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_IPHONE && !TARGET_OS_SIMULATOR
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 #endif
67
68 void
69 SecADClearScalarKey(CFStringRef key)
70 {
71 #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
72 if (setup())
73 soft_ADClientClearScalarKey(key);
74 #endif
75 }
76
77 void
78 SecADSetValueForScalarKey(CFStringRef key, int64_t value)
79 {
80 #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
81 if (setup())
82 soft_ADClientSetValueForScalarKey(key, value);
83 #endif
84 }
85 void
86 SecADAddValueForScalarKey(CFStringRef key, int64_t value)
87 {
88 #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
89 if (setup())
90 soft_ADClientAddValueForScalarKey(key, value);
91 #endif
92 }
93
94 void
95 SecADClientPushValueForDistributionKey(CFStringRef key, int64_t value)
96 {
97 #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR
98 if (setup())
99 soft_ADClientPushValueForDistributionKey(key, value);
100 #endif
101 }
102