2 * Copyright (c) 2015-2017 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
&& xpc_get_type(value
) == XPC_TYPE_DICTIONARY
) {
40 agent_uuid
= xpc_dictionary_get_value(info
,
41 kConfigAgentOutOfBandDataUUID
);
42 if (agent_uuid
!= NULL
) {
48 } else if (xpc_get_type(info
) == XPC_TYPE_DICTIONARY
) {
49 agent_uuid
= xpc_dictionary_get_value(info
,
50 kConfigAgentOutOfBandDataUUID
);
53 if (agent_uuid
!= NULL
) {
54 const void *bytes
= xpc_data_get_bytes_ptr(agent_uuid
);
55 uuid_copy(uuid
, bytes
);
62 is_a_config_agent(const struct netagent
*agent
)
64 const char *agentDomain
;
70 agentDomain
= agent
->netagent_domain
;
71 if (agentDomain
== NULL
|| strcmp(agentDomain
, kConfigAgentDomain
)) {
79 is_config_agent_type_dns(const struct netagent
*agent
)
81 if (!is_a_config_agent(agent
)) {
85 const char *agentDesc
= agent
->netagent_type
;
86 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeDNS
)) {
94 is_config_agent_type_proxy(const struct netagent
*agent
)
96 if (!is_a_config_agent(agent
)) {
100 const char *agentDesc
= agent
->netagent_type
;
101 if (agentDesc
== NULL
|| strcmp(agentDesc
, kConfigAgentTypeProxy
)) {
109 is_config_agent_type_dns_multicast(const struct netagent
*agent
)
111 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSMulticast
, sizeof(kConfigAgentTypeDNSMulticast
)-1) == 0) {
119 is_config_agent_type_dns_private(const struct netagent
*agent
)
121 if (strncmp(agent
->netagent_desc
, kConfigAgentTypeDNSPrivate
, sizeof(kConfigAgentTypeDNSPrivate
)-1) == 0) {
129 config_agent_copy_dns_information(const struct netagent
*agent
)
131 xpc_object_t resolver
= NULL
;
133 if (!is_config_agent_type_dns(agent
)) {
137 if (agent
->netagent_data_size
<= 0 ) {
138 if (!is_config_agent_type_dns_private(agent
) && !is_config_agent_type_dns_multicast(agent
)) {
139 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeDNS
;
140 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
146 resolver
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
153 config_agent_get_dns_nameservers(xpc_object_t resolver
)
155 if (resolver
== NULL
) {
159 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSNameServers
);
163 config_agent_get_dns_searchdomains(xpc_object_t resolver
)
165 if (resolver
== NULL
) {
169 return xpc_dictionary_get_value(resolver
, kConfigAgentDNSSearchDomains
);
173 config_agent_free_dns_information(xpc_object_t resolver
)
175 if (resolver
== NULL
) {
176 syslog(LOG_ERR
, "Attempting to free invalid resolver");
180 xpc_release(resolver
);
184 config_agent_copy_proxy_information(const struct netagent
*agent
)
186 xpc_object_t info
= NULL
;
188 if (!is_config_agent_type_proxy(agent
)) {
192 if (agent
->netagent_data_size
<= 0 ) {
193 const char *agent_desc
= (*(agent
->netagent_desc
) != '\0') ? agent
->netagent_desc
: kConfigAgentTypeProxy
;
194 syslog(LOG_ERR
, "Cannot parse config agent (%s). No data available", agent_desc
);
198 info
= xpc_create_from_plist(agent
->netagent_data
, agent
->netagent_data_size
);
205 config_agent_update_proxy_information(xpc_object_t proxyConfig
)
207 if (proxyConfig
== NULL
) {
211 xpc_object_t newProxyConfig
= NULL
;
212 struct netagent agent
;
214 get_agent_uuid_if_OOB_data_required(proxyConfig
, agent
.netagent_uuid
);
216 if (uuid_is_null(agent
.netagent_uuid
) == 0) {
217 strlcpy(agent
.netagent_type
, kConfigAgentTypeProxy
, sizeof(agent
.netagent_type
));
220 const void *buffer
= _nwi_config_agent_copy_data(&agent
, &length
);
221 if (buffer
!= NULL
&& length
> 0) {
222 newProxyConfig
= xpc_create_from_plist(buffer
, (size_t)length
);
223 free((void *)buffer
);
227 return newProxyConfig
;
231 config_agent_free_proxy_information(xpc_object_t proxyConfig
)
233 if (proxyConfig
== NULL
) {
234 syslog(LOG_ERR
, "Attempting to free proxy configuration");
238 xpc_release(proxyConfig
);