]>
git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Tool/log_control.c
2 * Copyright (c) 2003-2007,2009-2010,2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
30 #include <Security/SecItem.h>
31 #include <CoreFoundation/CoreFoundation.h>
33 #include <SecurityTool/tool_errors.h>
35 #include <Security/SecLogging.h>
37 #include <utilities/debugging.h>
39 #include <utilities/SecCFWrappers.h>
41 #include "SecurityCommands.h"
45 set_log_settings(const char * settings
)
47 CFErrorRef error
= NULL
;
49 CFStringRef scope
= CFStringCreateWithCString(kCFAllocatorDefault
, settings
, kCFStringEncodingUTF8
);
51 if (!SecSetLoggingInfoForXPCScope((CFPropertyListRef
) scope
, &error
)) {
52 fprintf(stderr
, "Failed: ");
61 set_circle_settings(const char * settings
)
63 CFErrorRef error
= NULL
;
65 CFStringRef scope
= CFStringCreateWithCString(kCFAllocatorDefault
, settings
, kCFStringEncodingUTF8
);
67 if (!SecSetLoggingInfoForCircleScope((CFPropertyListRef
) scope
, &error
)) {
68 fprintf(stderr
, "Failed: ");
76 static const char * getScopeIDName(int id
)
79 case kScopeIDXPC
: return "XPC";
80 case kScopeIDDefaults
: return "Defaults";
81 case kScopeIDEnvironment
: return "Environment Variables";
82 case kScopeIDConfig
: return "Config";
83 case kScopeIDCircle
: return "Circle";
84 default: return "Unknown";
88 static const char * getPriorityName(CFNumberRef id_number
)
92 CFNumberGetValue(id_number
, kCFNumberIntType
, &priority
);
95 case ASL_LEVEL_EMERG
: return ASL_STRING_EMERG
;
96 case ASL_LEVEL_ALERT
: return ASL_STRING_ALERT
;
97 case ASL_LEVEL_CRIT
: return ASL_STRING_CRIT
;
98 case ASL_LEVEL_ERR
: return ASL_STRING_ERR
;
99 case ASL_LEVEL_WARNING
: return ASL_STRING_WARNING
;
100 case ASL_LEVEL_NOTICE
: return ASL_STRING_NOTICE
;
101 case ASL_LEVEL_INFO
: return ASL_STRING_INFO
;
102 case ASL_LEVEL_DEBUG
: return ASL_STRING_DEBUG
;
103 default: return "Unknown";
108 static void print_comma_separated(FILE* file
, CFArrayRef array
)
111 __block
const char *separator
= "";
112 CFArrayForEach(array
, ^(const void *value
) {
113 cffprint(file
, CFSTR("%s%@"), separator
, value
);
123 CFErrorRef error
= NULL
;
125 CFArrayRef result
= SecGetCurrentServerLoggingInfo(&error
);
127 __block
int index
= 0;
128 CFArrayForEach(result
, ^(const void *value
) {
129 printf("%s: ", getScopeIDName(index
));
131 if (isArray(value
)) {
132 print_comma_separated(stdout
, (CFArrayRef
) value
);
134 } else if (isDictionary(value
)) {
136 CFDictionaryForEach((CFDictionaryRef
) value
, ^(const void *level
, const void *array
) {
137 printf(" %s: ", getPriorityName(level
));
138 if (isArray(array
)) {
139 print_comma_separated(stdout
, (CFArrayRef
) array
);
141 cffprint(stdout
, CFSTR("%@"), array
);
146 cffprint(stdout
, CFSTR("%@\n"), value
);
152 fprintf(stderr
, "Failed: ");
156 CFReleaseSafe(error
);
159 int log_control(int argc
, char * const *argv
)
161 int ch
, result
= 2; /* @@@ Return 2 triggers usage message. */
167 while ((ch
= getopt(argc
, argv
, "ls:c:")) != -1)
175 set_log_settings(optarg
);
178 set_circle_settings(optarg
);
193 set_log_settings(argv
[0]);