2 * Copyright (c) 2000-2004, 2006-2008 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 * Modification History
27 * May 18, 2001 Allan Nathanson <ajn@apple.com>
31 #include <SystemConfiguration/SystemConfiguration.h>
32 #include <SystemConfiguration/SCValidation.h>
33 #include <SystemConfiguration/SCPrivate.h>
41 SCDynamicStoreKeyCreateProxies(CFAllocatorRef allocator
)
43 return SCDynamicStoreKeyCreateNetworkGlobalEntity(allocator
,
44 kSCDynamicStoreDomainState
,
50 validate_proxy_content(CFMutableDictionaryRef proxies
,
51 CFStringRef proxy_enable
,
52 CFStringRef proxy_host
,
53 CFStringRef proxy_port
,
54 const char * proxy_service
,
55 int proxy_defaultport
)
60 num
= CFDictionaryGetValue(proxies
, proxy_enable
);
62 if (!isA_CFNumber(num
) ||
63 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
64 // if we don't like the enabled key/value
69 if (proxy_host
!= NULL
) {
72 host
= CFDictionaryGetValue(proxies
, proxy_host
);
73 if (((enabled
== 0) && (host
!= NULL
)) ||
74 ((enabled
!= 0) && !isA_CFString(host
))) {
75 // pass only valid proxy hosts and only when enabled
80 if (proxy_port
!= NULL
) {
83 port
= CFDictionaryGetValue(proxies
, proxy_port
);
84 if (((enabled
== 0) && (port
!= NULL
)) ||
85 ((enabled
!= 0) && (port
!= NULL
) && !isA_CFNumber(port
))) {
86 // pass only provided/valid proxy ports and only when enabled
90 if ((enabled
!= 0) && (port
== NULL
)) {
91 struct servent
*service
;
94 service
= getservbyname(proxy_service
, "tcp");
95 if (service
!= NULL
) {
96 s_port
= ntohs(service
->s_port
);
98 s_port
= proxy_defaultport
;
100 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &s_port
);
101 CFDictionarySetValue(proxies
, proxy_port
, num
);
111 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
112 CFDictionarySetValue(proxies
, proxy_enable
, num
);
114 if (proxy_host
!= NULL
) {
115 CFDictionaryRemoveValue(proxies
, proxy_host
);
117 if (proxy_port
!= NULL
) {
118 CFDictionaryRemoveValue(proxies
, proxy_port
);
126 SCDynamicStoreCopyProxies(SCDynamicStoreRef store
)
130 CFMutableDictionaryRef newProxies
= NULL
;
132 CFDictionaryRef proxies
;
133 Boolean tempSession
= FALSE
;
136 /* copy proxy information from dynamic store */
139 store
= SCDynamicStoreCreate(NULL
,
140 CFSTR("SCDynamicStoreCopyProxies"),
149 key
= SCDynamicStoreKeyCreateProxies(NULL
);
150 proxies
= SCDynamicStoreCopyValue(store
, key
);
155 if (proxies
!= NULL
) {
156 if (isA_CFDictionary(proxies
)) {
157 newProxies
= CFDictionaryCreateMutableCopy(NULL
, 0, proxies
);
162 if (newProxies
== NULL
) {
163 newProxies
= CFDictionaryCreateMutable(NULL
,
165 &kCFTypeDictionaryKeyCallBacks
,
166 &kCFTypeDictionaryValueCallBacks
);
169 /* validate [and augment] proxy content */
171 validate_proxy_content(newProxies
,
172 kSCPropNetProxiesFTPEnable
,
173 kSCPropNetProxiesFTPProxy
,
174 kSCPropNetProxiesFTPPort
,
177 validate_proxy_content(newProxies
,
178 kSCPropNetProxiesGopherEnable
,
179 kSCPropNetProxiesGopherProxy
,
180 kSCPropNetProxiesGopherPort
,
183 validate_proxy_content(newProxies
,
184 kSCPropNetProxiesHTTPEnable
,
185 kSCPropNetProxiesHTTPProxy
,
186 kSCPropNetProxiesHTTPPort
,
189 validate_proxy_content(newProxies
,
190 kSCPropNetProxiesHTTPSEnable
,
191 kSCPropNetProxiesHTTPSProxy
,
192 kSCPropNetProxiesHTTPSPort
,
195 validate_proxy_content(newProxies
,
196 kSCPropNetProxiesRTSPEnable
,
197 kSCPropNetProxiesRTSPProxy
,
198 kSCPropNetProxiesRTSPPort
,
201 validate_proxy_content(newProxies
,
202 kSCPropNetProxiesSOCKSEnable
,
203 kSCPropNetProxiesSOCKSProxy
,
204 kSCPropNetProxiesSOCKSPort
,
207 validate_proxy_content(newProxies
,
208 kSCPropNetProxiesProxyAutoConfigEnable
,
209 kSCPropNetProxiesProxyAutoConfigURLString
,
213 validate_proxy_content(newProxies
,
214 kSCPropNetProxiesProxyAutoDiscoveryEnable
,
220 // validate FTP passive setting
221 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesFTPPassive
);
225 if (!isA_CFNumber(num
) ||
226 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
227 // if we don't like the enabled key/value
229 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
230 CFDictionarySetValue(newProxies
,
231 kSCPropNetProxiesFTPPassive
,
237 // validate proxy exception list
238 array
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExceptionsList
);
243 n
= isA_CFArray(array
) ? CFArrayGetCount(array
) : 0;
244 for (i
= 0; i
< n
; i
++) {
247 str
= CFArrayGetValueAtIndex(array
, i
);
248 if (!isA_CFString(str
)) {
249 // if we don't like the array contents
256 CFDictionaryRemoveValue(newProxies
, kSCPropNetProxiesExceptionsList
);
260 // validate exclude simple hostnames setting
261 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExcludeSimpleHostnames
);
265 if (!isA_CFNumber(num
) ||
266 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
267 // if we don't like the enabled key/value
269 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
270 CFDictionarySetValue(newProxies
,
271 kSCPropNetProxiesExcludeSimpleHostnames
,
278 proxies
= CFDictionaryCreateCopy(NULL
, newProxies
);
279 CFRelease(newProxies
);
281 if (tempSession
) CFRelease(store
);