2 // SecdKeychainUtilities.c
5 // Created by Mitch Adler on 6/11/13.
9 #include "SecdTestKeychainUtilities.h"
11 #include <test/testmore.h>
12 #include <utilities/SecFileLocations.h>
13 #include <utilities/SecCFWrappers.h>
15 #include <CoreFoundation/CoreFoundation.h>
22 void kc_dbhandle_reset(void);
24 void secd_test_setup_temp_keychain(const char* test_prefix
, dispatch_block_t do_before_reset
)
26 CFStringRef tmp_dir
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("/tmp/%s.%X/"), test_prefix
, arc4random());
27 CFStringRef keychain_dir
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%@Library/Keychains"), tmp_dir
);
29 CFStringPerformWithCString(keychain_dir
, ^(const char *keychain_dir_string
) {
30 ok_unix(mkpath_np(keychain_dir_string
, 0755), "Create temp dir");
32 printf("Created temporary directory %s\n", keychain_dir_string
);
36 /* set custom keychain dir, reset db */
37 CFStringPerformWithCString(tmp_dir
, ^(const char *tmp_dir_string
) {
38 SetCustomHomeURL(tmp_dir_string
);