/*
- * Copyright (c) 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2012-2018 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
-#include <Availability.h>
#include <TargetConditionals.h>
-#include <asl.h>
#include <dispatch/dispatch.h>
#include <vproc.h>
#include <vproc_priv.h>
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SCPrivate.h>
-
#include "libSystemConfiguration_server.h"
#define kTrailingEdgeAgentEntitlement "com.apple.SystemConfiguration.trailing-edge-agent"
-#pragma mark -
-#pragma mark Support functions
-
-
-//__private_extern__ void
-//log_xpc_object(const char *msg, xpc_object_t obj)
-//{
-// char *desc;
-//
-// desc = xpc_copy_description(obj);
-// asl_log(NULL, NULL, ASL_LEVEL_ERR, "%s = %s", msg, desc);
-// free(desc);
-//}
+#ifdef SC_LOG_HANDLE
+#include <os/log.h>
+os_log_t SC_LOG_HANDLE(void);
+#endif //SC_LOG_HANDLE
#pragma mark -
}
-#if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
static void
_handle_entitlement_check_failure(pid_t pid)
{
if (!CFArrayContainsValue(pids, CFRangeMake(0, CFArrayGetCount(pids)), pidNumber)) {
CFArrayAppendValue(pids, pidNumber);
- SCLog(TRUE, LOG_ERR, CFSTR("DNS/nwi dropping ack w/no entitlement, pid = %d"), pid);
+ SC_log(LOG_INFO, "DNS/nwi dropping ack w/no entitlement, pid = %d", pid);
if (!cleanupScheduled) {
cleanupScheduled = TRUE;
CFRelease(pidNumber);
});
}
-#endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
/*
__private_extern__
void
_libSC_info_server_init(libSC_info_server_t *server_info) {
- bzero(server_info, sizeof(*server_info));
+ memset(server_info, 0, sizeof(*server_info));
server_info->info = CFDictionaryCreateMutable(NULL,
0,
&kCFTypeDictionaryKeyCallBacks,
_libSC_info_server_open(libSC_info_server_t *server_info,
xpc_connection_t c)
{
- CFDataRef client_key;
- CFDataRef client_val;
- client_val_t val;
+ CFDataRef client_key;
+ CFMutableDataRef client_val;
+ client_val_t *val;
client_key = _client_key(c);
- val.pid = xpc_connection_get_pid(c);
- val.generation_pushed = 0;
- val.generation_acknowledged = 0;
- client_val = CFDataCreate(NULL, (UInt8 *)&val, sizeof(val));
+ client_val = CFDataCreateMutable(NULL, sizeof(*val));
+ CFDataSetLength(client_val, sizeof(*val));
+
+ val = (client_val_t *)(void *)CFDataGetMutableBytePtr(client_val);
+ val->pid = xpc_connection_get_pid(c);
+ val->generation_pushed = 0;
+ val->generation_acknowledged = 0;
CFDictionarySetValue(server_info->info, client_key, client_val);
CFRelease(client_key);
xpc_connection_t c,
uint64_t *generation)
{
- CFDataRef client_key;
- CFDataRef client_val;
- client_val_t *val;
+ CFDataRef client_key;
+ CFMutableDataRef client_val;
+ client_val_t *val;
// update last generation pushed to client
client_key = _client_key(c);
- client_val = CFDictionaryGetValue(server_info->info, client_key);
+ client_val = (CFMutableDataRef)CFDictionaryGetValue(server_info->info, client_key);
CFRelease(client_key);
- val = (client_val_t *)(void *)CFDataGetBytePtr(client_val);
+ val = (client_val_t *)(void *)CFDataGetMutableBytePtr(client_val);
val->generation_pushed = server_info->generation;
// return generation
xpc_connection_t c,
uint64_t generation)
{
- CFDataRef client_key;
- CFDataRef client_val;
-#if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
- xpc_object_t ent_value;
- Boolean entitled = FALSE;
-#endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
- Boolean sync_updated = FALSE;
- client_val_t *val;
-
-#if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
+ CFDataRef client_key;
+ CFMutableDataRef client_val;
+ xpc_object_t ent_value;
+ Boolean entitled = FALSE;
+ Boolean sync_updated = FALSE;
+ client_val_t *val;
+
ent_value = xpc_connection_copy_entitlement_value(c, kTrailingEdgeAgentEntitlement);
if (ent_value != NULL) {
if (xpc_get_type(ent_value) == XPC_TYPE_BOOL) {
_handle_entitlement_check_failure(xpc_connection_get_pid(c));
return FALSE;
}
-#endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000))
client_key = _client_key(c);
- client_val = CFDictionaryGetValue(server_info->info, client_key);
+ client_val = (CFMutableDataRef)CFDictionaryGetValue(server_info->info, client_key);
CFRelease(client_key);
- val = (client_val_t *)(void *)CFDataGetBytePtr(client_val);
+ val = (client_val_t *)(void *)CFDataGetMutableBytePtr(client_val);
if (val->generation_acknowledged == 0) {
// if first ack
_libSC_info_server_close(libSC_info_server_t *server_info,
xpc_connection_t c)
{
- CFDataRef client_key;
- CFDataRef client_val;
- Boolean sync_updated = FALSE;
+ CFDataRef client_key;
+ CFMutableDataRef client_val;
+ Boolean sync_updated = FALSE;
client_key = _client_key(c);
// get client info, remove ack'd info
- client_val = CFDictionaryGetValue(server_info->info, client_key);
+ client_val = (CFMutableDataRef)CFDictionaryGetValue(server_info->info, client_key);
if (client_val != NULL) {
client_val_t *val;
- val = (client_val_t *)(void *)CFDataGetBytePtr(client_val);
+ val = (client_val_t *)(void *)CFDataGetMutableBytePtr(client_val);
if (val->generation_acknowledged > 0) {
// if we've previously ack'd a configuration
if (val->generation_acknowledged == server_info->generation) {