2 * Copyright (c) 2015, 2016 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
) {
38 if (value
&& xpc_get_type(value
) == XPC_TYPE_DICTIONARY
) {
39 agent_uuid
= xpc_dictionary_get_value(info
,
40 kConfigAgentOutOfBandDataUUID
);
41 if (agent_uuid
!= NULL
) {
47 } else if (xpc_get_type(info
) == XPC_TYPE_DICTIONARY
) {
48 agent_uuid
= xpc_dictionary_get_value(info
,
49 kConfigAgentOutOfBandDataUUID
);
52 if (agent_uuid
!= NULL
) {
53 const void *bytes
= xpc_data_get_bytes_ptr(agent_uuid
);
54 uuid_copy(uuid
, bytes
);
61 is_a_config_agent(const struct netagent
*agent
)
63 const char *agentDomain
;
69 agentDomain
= agent
->netagent_domain
;
70 if (agentDomain
== NULL
|| strcmp(agentDomain
, kConfigAgentDomain
)) {
78 is_config_agent_type_dns(const struct netagent
*agent
)
80 if (!is_a_config_agent(agent
)) {
84 const char *agentDesc
= agent
->netagent_type
;
85 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeDNS
)) {
93 is_config_agent_type_proxy(const struct netagent
*agent
)
95 if (!is_a_config_agent(agent
)) {
99 const char *agentDesc
= agent
->netagent_type
;
100 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeProxy
)) {
108 is_config_agent_type_dns_multicast(const struct netagent
*agent
)
110 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSMulticast
, sizeof(kConfigAgentTypeDNSMulticast
)-1) == 0) {
118 is_config_agent_type_dns_private(const struct netagent
*agent
)
120 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSPrivate
, sizeof(kConfigAgentTypeDNSPrivate
)-1) == 0) {
128 config_agent_copy_dns_information(const struct netagent
*agent
)
130 xpc_object_t resolver
= NULL
;
132 if (!is_config_agent_type_dns(agent
)) {
136 if (agent
->netagent_data_size
<= 0 ) {
137 if (!is_config_agent_type_dns_private(agent
) && !is_config_agent_type_dns_multicast(agent
)) {
138 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeDNS
;
139 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
145 resolver
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
152 config_agent_get_dns_nameservers(xpc_object_t resolver
)
154 if (resolver
== NULL
) {
158 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSNameServers
);
162 config_agent_get_dns_searchdomains(xpc_object_t resolver
)
164 if (resolver
== NULL
) {
168 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSSearchDomains
);
172 config_agent_free_dns_information(xpc_object_t resolver
)
174 if (resolver
== NULL
) {
175 syslog(LOG_ERR
, "Attempting to free invalid resolver");
179 xpc_release(resolver
);
183 config_agent_copy_proxy_information(const struct netagent
*agent
)
185 xpc_object_t info
= NULL
;
187 if (!is_config_agent_type_proxy(agent
)) {
191 if (agent
->netagent_data_size
<= 0 ) {
192 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeProxy
;
193 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
197 info
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
204 config_agent_update_proxy_information(xpc_object_t proxyConfig
)
206 if (proxyConfig
== NULL
) {
210 xpc_object_t newProxyConfig
= NULL
;
211 struct netagent agent
;
213 get_agent_uuid_if_OOB_data_required(proxyConfig
, agent
.netagent_uuid
);
215 if (uuid_is_null(agent
.netagent_uuid
) == 0) {
216 strlcpy(agent
.netagent_type
, kConfigAgentTypeProxy
, sizeof(agent
.netagent_type
));
219 const void *buffer
= _nwi_config_agent_copy_data(&agent
, &length
);
220 if (buffer
!= NULL
&& length
> 0) {
221 newProxyConfig
= xpc_create_from_plist(buffer
, (size_t)length
);
222 free((void *)buffer
);
226 return newProxyConfig
;
230 config_agent_free_proxy_information(xpc_object_t proxyConfig
)
232 if (proxyConfig
== NULL
) {
233 syslog(LOG_ERR
, "Attempting to free proxy configuration");
237 xpc_release(proxyConfig
);