void secd_test_setup_temp_keychain(const char* test_prefix, dispatch_block_t do_before_reset) { CFStringRef tmp_dir = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("/tmp/%s.%X/"), test_prefix, arc4random()); CFStringRef keychain_dir = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@Library/Keychains"), tmp_dir); CFStringPerformWithCString(keychain_dir, ^(const char *keychain_dir_string) { ok_unix(mkpath_np(keychain_dir_string, 0755), "Create temp dir %s", keychain_dir_string); });
int main(int argc, char *argv[]) { int ch, exitval, success, pflag; mode_t omode, *set = (mode_t *)NULL; char *mode; pflag = 0; mode = NULL; while ((ch = getopt(argc, argv, "m:pv")) != -1) switch(ch) { case 'm': mode = optarg; break; case 'p': pflag = 1; break; case 'v': vflag = 1; break; case '?': default: usage(); } // argc -= optind; argv += optind; if (argv[0] == NULL) usage(); if (mode == NULL) { omode = S_IRWXU | S_IRWXG | S_IRWXO; } else { if ((set = setmode(mode)) == NULL) errx(1, "invalid file mode: %s", mode); omode = getmode(set, S_IRWXU | S_IRWXG | S_IRWXO); free(set); } for (exitval = 0; *argv != NULL; ++argv) { success = 1; if (pflag) { int status = mkpath_np(*argv, omode); if (status && status != EEXIST) { warnc(status, "%s", *argv); success = 0; } } else if (mkdir(*argv, omode) < 0) { if (errno == ENOTDIR || errno == ENOENT) warn("%s", dirname(*argv)); else warn("%s", *argv); success = 0; } else if (vflag) (void)printf("mkdir: created directory '%s'\n", *argv); if (!success) exitval = 1; /* * The mkdir() and umask() calls both honor only the low * nine bits, so if you try to set a mode including the * sticky, setuid, setgid bits you lose them. Don't do * this unless the user has specifically requested a mode, * as chmod will (obviously) ignore the umask. */ if (success && mode != NULL && chmod(*argv, omode) == -1) { warn("%s", *argv); exitval = 1; } } exit(exitval); }