2 * Copyright (c) 2015-2017, 2019 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@
25 #include "config_agent_info.h"
26 #include "configAgentDefines.h"
27 #include "network_config_agent_info_priv.h"
32 get_agent_uuid_if_OOB_data_required(xpc_object_t info
, uuid_t uuid
)
34 __block xpc_object_t agent_uuid
= NULL
;
36 if (xpc_get_type(info
) == XPC_TYPE_ARRAY
) {
37 xpc_array_apply(info
, ^bool(size_t index
, xpc_object_t value
) {
39 if ((value
!= NULL
) &&
40 (xpc_get_type(value
) == XPC_TYPE_DICTIONARY
)) {
41 agent_uuid
= xpc_dictionary_get_value(value
,
42 kConfigAgentOutOfBandDataUUID
);
43 if (agent_uuid
!= NULL
) {
49 } else if (xpc_get_type(info
) == XPC_TYPE_DICTIONARY
) {
50 agent_uuid
= xpc_dictionary_get_value(info
,
51 kConfigAgentOutOfBandDataUUID
);
54 if ((agent_uuid
!= NULL
) &&
55 (xpc_get_type(agent_uuid
) == XPC_TYPE_DATA
) &&
56 (xpc_data_get_length(agent_uuid
) >= sizeof(uuid_t
))) {
57 const void *bytes
= xpc_data_get_bytes_ptr(agent_uuid
);
58 uuid_copy(uuid
, bytes
);
65 is_a_config_agent(const struct netagent
*agent
)
67 const char *agentDomain
;
73 agentDomain
= agent
->netagent_domain
;
74 if (agentDomain
== NULL
|| strcmp(agentDomain
, kConfigAgentDomain
)) {
82 is_config_agent_type_dns(const struct netagent
*agent
)
84 if (!is_a_config_agent(agent
)) {
88 const char *agentDesc
= agent
->netagent_type
;
89 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeDNS
)) {
97 is_config_agent_type_proxy(const struct netagent
*agent
)
99 if (!is_a_config_agent(agent
)) {
103 const char *agentDesc
= agent
->netagent_type
;
104 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeProxy
)) {
112 is_config_agent_type_dns_multicast(const struct netagent
*agent
)
114 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSMulticast
, sizeof(kConfigAgentTypeDNSMulticast
)-1) == 0) {
122 is_config_agent_type_dns_private(const struct netagent
*agent
)
124 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSPrivate
, sizeof(kConfigAgentTypeDNSPrivate
)-1) == 0) {
132 config_agent_copy_dns_information(const struct netagent
*agent
)
134 xpc_object_t resolver
= NULL
;
136 if (!is_config_agent_type_dns(agent
)) {
140 if (agent
->netagent_data_size
<= 0 ) {
141 if (!is_config_agent_type_dns_private(agent
) && !is_config_agent_type_dns_multicast(agent
)) {
142 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeDNS
;
143 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
149 resolver
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
156 config_agent_get_dns_nameservers(xpc_object_t resolver
)
158 if ((resolver
== NULL
) ||
159 (xpc_get_type(resolver
) != XPC_TYPE_DICTIONARY
)) {
163 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSNameServers
);
167 config_agent_get_dns_searchdomains(xpc_object_t resolver
)
169 if ((resolver
== NULL
) ||
170 (xpc_get_type(resolver
) != XPC_TYPE_DICTIONARY
)) {
174 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSSearchDomains
);
178 config_agent_free_dns_information(xpc_object_t resolver
)
180 if (resolver
== NULL
) {
181 syslog(LOG_ERR
, "Attempting to free invalid resolver");
185 xpc_release(resolver
);
189 config_agent_copy_proxy_information(const struct netagent
*agent
)
191 xpc_object_t info
= NULL
;
193 if (!is_config_agent_type_proxy(agent
)) {
197 if (agent
->netagent_data_size
<= 0 ) {
198 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeProxy
;
199 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
203 info
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
210 config_agent_update_proxy_information(xpc_object_t proxyConfig
)
212 if (proxyConfig
== NULL
) {
216 xpc_object_t newProxyConfig
= NULL
;
217 struct netagent agent
;
219 get_agent_uuid_if_OOB_data_required(proxyConfig
, agent
.netagent_uuid
);
221 if (uuid_is_null(agent
.netagent_uuid
) == 0) {
222 strlcpy(agent
.netagent_type
, kConfigAgentTypeProxy
, sizeof(agent
.netagent_type
));
225 const void *buffer
= _nwi_config_agent_copy_data(&agent
, &length
);
226 if (buffer
!= NULL
&& length
> 0) {
227 newProxyConfig
= xpc_create_from_plist(buffer
, (size_t)length
);
228 free((void *)buffer
);
232 return newProxyConfig
;
236 config_agent_free_proxy_information(xpc_object_t proxyConfig
)
238 if (proxyConfig
== NULL
) {
239 syslog(LOG_ERR
, "Attempting to free proxy configuration");
243 xpc_release(proxyConfig
);