X-Git-Url: https://git.saurik.com/apple/configd.git/blobdiff_plain/5e9ce69ef59d7d98ff13748ce18266968031faaf..refs/heads/master:/libSystemConfiguration/libSystemConfiguration_server.c?ds=sidebyside diff --git a/libSystemConfiguration/libSystemConfiguration_server.c b/libSystemConfiguration/libSystemConfiguration_server.c index 82a201a..c193147 100644 --- a/libSystemConfiguration/libSystemConfiguration_server.c +++ b/libSystemConfiguration/libSystemConfiguration_server.c @@ -1,15 +1,15 @@ /* - * 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, @@ -17,13 +17,11 @@ * 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 #include -#include #include #include #include @@ -32,24 +30,14 @@ #include #include - #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_t SC_LOG_HANDLE(void); +#endif //SC_LOG_HANDLE #pragma mark - @@ -79,7 +67,6 @@ _client_key(xpc_connection_t c) } -#if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000)) static void _handle_entitlement_check_failure(pid_t pid) { @@ -99,7 +86,7 @@ _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; @@ -113,7 +100,6 @@ _handle_entitlement_check_failure(pid_t pid) CFRelease(pidNumber); }); } -#endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000)) /* @@ -126,7 +112,7 @@ _handle_entitlement_check_failure(pid_t pid) __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, @@ -195,16 +181,19 @@ void _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); @@ -227,16 +216,16 @@ _libSC_info_server_get_data(libSC_info_server_t *server_info, 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 @@ -265,16 +254,13 @@ _libSC_info_server_acknowledged(libSC_info_server_t *server_info, 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) { @@ -287,13 +273,12 @@ _libSC_info_server_acknowledged(libSC_info_server_t *server_info, _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 @@ -331,18 +316,18 @@ Boolean _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) {