]>
git.saurik.com Git - apple/security.git/blob - OSX/sec/ProjectHeaders/Security/Tool/log_control.c
11 #include <Security/SecItem.h>
12 #include <CoreFoundation/CoreFoundation.h>
14 #include <SecurityTool/tool_errors.h>
16 #include <Security/SecLogging.h>
18 #include <utilities/debugging.h>
20 #include <utilities/SecCFWrappers.h>
22 #include "SecurityCommands.h"
26 set_log_settings(const char * settings
)
28 CFErrorRef error
= NULL
;
30 CFStringRef scope
= CFStringCreateWithCString(kCFAllocatorDefault
, settings
, kCFStringEncodingUTF8
);
32 if (!SecSetLoggingInfoForXPCScope((CFPropertyListRef
) scope
, &error
)) {
33 fprintf(stderr
, "Failed: ");
42 set_circle_settings(const char * settings
)
44 CFErrorRef error
= NULL
;
46 CFStringRef scope
= CFStringCreateWithCString(kCFAllocatorDefault
, settings
, kCFStringEncodingUTF8
);
48 if (!SecSetLoggingInfoForCircleScope((CFPropertyListRef
) scope
, &error
)) {
49 fprintf(stderr
, "Failed: ");
57 static const char * getScopeIDName(int id
)
60 case kScopeIDXPC
: return "XPC";
61 case kScopeIDDefaults
: return "Defaults";
62 case kScopeIDEnvironment
: return "Environment Variables";
63 case kScopeIDConfig
: return "Config";
64 case kScopeIDCircle
: return "Circle";
65 default: return "Unknown";
69 static const char * getPriorityName(CFNumberRef id_number
)
73 CFNumberGetValue(id_number
, kCFNumberIntType
, &priority
);
76 case ASL_LEVEL_EMERG
: return ASL_STRING_EMERG
;
77 case ASL_LEVEL_ALERT
: return ASL_STRING_ALERT
;
78 case ASL_LEVEL_CRIT
: return ASL_STRING_CRIT
;
79 case ASL_LEVEL_ERR
: return ASL_STRING_ERR
;
80 case ASL_LEVEL_WARNING
: return ASL_STRING_WARNING
;
81 case ASL_LEVEL_NOTICE
: return ASL_STRING_NOTICE
;
82 case ASL_LEVEL_INFO
: return ASL_STRING_INFO
;
83 case ASL_LEVEL_DEBUG
: return ASL_STRING_DEBUG
;
84 default: return "Unknown";
89 static void print_comma_separated(FILE* file
, CFArrayRef array
)
92 __block
const char *separator
= "";
93 CFArrayForEach(array
, ^(const void *value
) {
94 cffprint(file
, CFSTR("%s%@"), separator
, value
);
104 CFErrorRef error
= NULL
;
106 CFArrayRef result
= SecGetCurrentServerLoggingInfo(&error
);
108 __block
int index
= 0;
109 CFArrayForEach(result
, ^(const void *value
) {
110 printf("%s: ", getScopeIDName(index
));
112 if (isArray(value
)) {
113 print_comma_separated(stdout
, (CFArrayRef
) value
);
115 } else if (isDictionary(value
)) {
117 CFDictionaryForEach((CFDictionaryRef
) value
, ^(const void *level
, const void *array
) {
118 printf(" %s: ", getPriorityName(level
));
119 if (isArray(array
)) {
120 print_comma_separated(stdout
, (CFArrayRef
) array
);
122 cffprint(stdout
, CFSTR("%@"), array
);
127 cffprint(stdout
, CFSTR("%@\n"), value
);
133 fprintf(stderr
, "Failed: ");
137 CFReleaseSafe(error
);
140 int log_control(int argc
, char * const *argv
)
142 int ch
, result
= 2; /* @@@ Return 2 triggers usage message. */
148 while ((ch
= getopt(argc
, argv
, "ls:c:")) != -1)
156 set_log_settings(optarg
);
159 set_circle_settings(optarg
);
174 set_log_settings(argv
[0]);