]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/xpc_services/xpc_services.c
mDNSResponder-1096.0.2.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / xpc_services / xpc_services.c
1 /*
2 * Copyright (c) 2019 Apple Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "xpc_services.h"
18 #include <xpc/private.h> // xpc_connection_copy_entitlement_value
19
20 #include "mDNSMacOSX.h" // KQueueLock/KQueueUnlock
21 #include "dnsproxy.h" // DNSProxyInit/ProxyUDPCallback/ProxyTCPCallback
22 #include "xpc_service_dns_proxy.h" // init_dnsproxy_service
23 #include "xpc_service_log_utility.h" // init_dnsctl_service
24
25 extern mDNS mDNSStorage;
26
27 mDNSexport void xpc_server_init()
28 {
29 // add XPC Services here
30 init_dnsproxy_service();
31 init_log_utility_service();
32 }
33
34 // Utilities
35
36 mDNSexport mDNSBool IsEntitled(xpc_connection_t conn, const char *entitlement_name)
37 {
38 mDNSBool entitled = mDNSfalse;
39 xpc_object_t entitled_obj = xpc_connection_copy_entitlement_value(conn, entitlement_name);
40
41 if (entitled_obj) {
42 if (xpc_get_type(entitled_obj) == XPC_TYPE_BOOL && xpc_bool_get_value(entitled_obj)) {
43 entitled = mDNStrue;
44 }
45 xpc_release(entitled_obj);
46 } else {
47 LogRedact(MDNS_LOG_CATEGORY_DEFAULT, MDNS_LOG_DEFAULT, "IsEntitled: Client Entitlement is NULL");
48 }
49
50 if (!entitled) {
51 LogRedact(MDNS_LOG_CATEGORY_DEFAULT, MDNS_LOG_DEFAULT, "IsEntitled: Client is missing Entitlement!");
52 }
53
54 return entitled;
55 }