]> git.saurik.com Git - apple/security.git/blob - Security/authd/debugging.c
Security-57031.1.35.tar.gz
[apple/security.git] / Security / authd / debugging.c
1 /* Copyright (c) 2012 Apple Inc. All Rights Reserved. */
2
3 #include "debugging.h"
4 #include "authd_private.h"
5 #include "authutilities.h"
6 #include <stdarg.h>
7 #include <syslog.h>
8 #include <dispatch/dispatch.h>
9 #include <CoreFoundation/CoreFoundation.h>
10
11 // sudo defaults write /Library/Preferences/com.apple.security.coderequirements Entitlements -string always
12
13 static bool
14 security_auth_verbose(void)
15 {
16 static dispatch_once_t onceToken;
17 static bool verbose_enabled = false;
18
19 //sudo defaults write /Library/Preferences/com.apple.authd verbose -bool true
20 dispatch_once(&onceToken, ^{
21 CFTypeRef verbose = (CFNumberRef)CFPreferencesCopyValue(CFSTR("verbose"), CFSTR(SECURITY_AUTH_NAME), kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
22
23 if (verbose && CFGetTypeID(verbose) == CFBooleanGetTypeID()) {
24 verbose_enabled = CFBooleanGetValue((CFBooleanRef)verbose);
25 }
26 #if DEBUG
27 syslog(LOG_NOTICE, "verbose: %s", verbose_enabled ? "enabled" : "disabled");
28 #endif
29 CFReleaseSafe(verbose);
30 });
31
32 return verbose_enabled;
33 }
34
35 void
36 security_auth_log(int type,const char * format,...)
37 {
38 va_list ap;
39 va_start(ap, format);
40 switch (type) {
41 case AUTH_LOG_NORMAL:
42 vsyslog(LOG_NOTICE, format, ap);
43 break;
44 case AUTH_LOG_VERBOSE:
45 if (security_auth_verbose()) {
46 vsyslog(LOG_NOTICE, format, ap);
47 }
48 break;
49 case AUTH_LOG_ERROR:
50 vsyslog(LOG_ERR, format, ap);
51 break;
52 default:
53 break;
54 }
55 va_end(ap);
56 }
57
58 void _show_cf(CFTypeRef value)
59 {
60 CFStringRef string = NULL;
61 char * tmp = NULL;
62 require(value != NULL, done);
63
64 if (security_auth_verbose()) {
65 string = CFCopyDescription(value);
66 tmp = _copy_cf_string(string, NULL);
67
68 syslog(LOG_NOTICE, "%s", tmp);
69 }
70
71 done:
72 CFReleaseSafe(string);
73 free_safe(tmp);
74 return;
75 }