2 * Copyright (c) 2000-2004, 2006, 2007 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 CFNumberRef port
= NULL
;
62 num
= CFDictionaryGetValue(proxies
, proxy_enable
);
64 if (!isA_CFNumber(num
) ||
65 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
66 // if we don't like the enabled key/value
71 host
= CFDictionaryGetValue(proxies
, proxy_host
);
72 if (((enabled
== 0) && (host
!= NULL
)) ||
73 ((enabled
!= 0) && !isA_CFString(host
))) {
74 // pass only valid proxy hosts and only when enabled
78 if (proxy_port
!= NULL
) {
79 port
= CFDictionaryGetValue(proxies
, proxy_port
);
80 if (((enabled
== 0) && (port
!= NULL
)) ||
81 ((enabled
!= 0) && (port
!= NULL
) && !isA_CFNumber(port
))) {
82 // pass only provided/valid proxy ports and only when enabled
86 if ((enabled
!= 0) && (port
== NULL
)) {
87 struct servent
*service
;
90 service
= getservbyname(proxy_service
, "tcp");
91 if (service
!= NULL
) {
92 s_port
= ntohs(service
->s_port
);
94 s_port
= proxy_defaultport
;
96 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &s_port
);
97 CFDictionarySetValue(proxies
, proxy_port
, num
);
107 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
108 CFDictionarySetValue(proxies
, proxy_enable
, num
);
110 CFDictionaryRemoveValue(proxies
, proxy_host
);
111 if (proxy_port
!= NULL
) {
112 CFDictionaryRemoveValue(proxies
, proxy_port
);
120 SCDynamicStoreCopyProxies(SCDynamicStoreRef store
)
124 CFMutableDictionaryRef newProxies
= NULL
;
126 CFDictionaryRef proxies
;
127 Boolean tempSession
= FALSE
;
130 /* copy proxy information from dynamic store */
133 store
= SCDynamicStoreCreate(NULL
,
134 CFSTR("SCDynamicStoreCopyProxies"),
143 key
= SCDynamicStoreKeyCreateProxies(NULL
);
144 proxies
= SCDynamicStoreCopyValue(store
, key
);
149 if (proxies
!= NULL
) {
150 if (isA_CFDictionary(proxies
)) {
151 newProxies
= CFDictionaryCreateMutableCopy(NULL
, 0, proxies
);
156 if (newProxies
== NULL
) {
157 newProxies
= CFDictionaryCreateMutable(NULL
,
159 &kCFTypeDictionaryKeyCallBacks
,
160 &kCFTypeDictionaryValueCallBacks
);
163 /* validate [and augment] proxy content */
165 validate_proxy_content(newProxies
,
166 kSCPropNetProxiesFTPEnable
,
167 kSCPropNetProxiesFTPProxy
,
168 kSCPropNetProxiesFTPPort
,
171 validate_proxy_content(newProxies
,
172 kSCPropNetProxiesGopherEnable
,
173 kSCPropNetProxiesGopherProxy
,
174 kSCPropNetProxiesGopherPort
,
177 validate_proxy_content(newProxies
,
178 kSCPropNetProxiesHTTPEnable
,
179 kSCPropNetProxiesHTTPProxy
,
180 kSCPropNetProxiesHTTPPort
,
183 validate_proxy_content(newProxies
,
184 kSCPropNetProxiesHTTPSEnable
,
185 kSCPropNetProxiesHTTPSProxy
,
186 kSCPropNetProxiesHTTPSPort
,
189 validate_proxy_content(newProxies
,
190 kSCPropNetProxiesRTSPEnable
,
191 kSCPropNetProxiesRTSPProxy
,
192 kSCPropNetProxiesRTSPPort
,
195 validate_proxy_content(newProxies
,
196 kSCPropNetProxiesSOCKSEnable
,
197 kSCPropNetProxiesSOCKSProxy
,
198 kSCPropNetProxiesSOCKSPort
,
201 validate_proxy_content(newProxies
,
202 kSCPropNetProxiesProxyAutoConfigEnable
,
203 kSCPropNetProxiesProxyAutoConfigURLString
,
208 // validate FTP passive setting
209 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesFTPPassive
);
213 if (!isA_CFNumber(num
) ||
214 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
215 // if we don't like the enabled key/value
217 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
218 CFDictionarySetValue(newProxies
,
219 kSCPropNetProxiesFTPPassive
,
225 // validate WPAD setting
226 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesProxyAutoDiscoveryEnable
);
230 if (!isA_CFNumber(num
) ||
231 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
232 // if we don't like the enabled key/value
234 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
235 CFDictionarySetValue(newProxies
,
236 kSCPropNetProxiesProxyAutoDiscoveryEnable
,
242 // validate proxy exception list
243 array
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExceptionsList
);
248 n
= isA_CFArray(array
) ? CFArrayGetCount(array
) : 0;
249 for (i
= 0; i
< n
; i
++) {
252 str
= CFArrayGetValueAtIndex(array
, i
);
253 if (!isA_CFString(str
)) {
254 // if we don't like the array contents
261 CFDictionaryRemoveValue(newProxies
, kSCPropNetProxiesExceptionsList
);
265 // validate exclude simple hostnames setting
266 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExcludeSimpleHostnames
);
270 if (!isA_CFNumber(num
) ||
271 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
272 // if we don't like the enabled key/value
274 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
275 CFDictionarySetValue(newProxies
,
276 kSCPropNetProxiesExcludeSimpleHostnames
,
283 proxies
= CFDictionaryCreateCopy(NULL
, newProxies
);
284 CFRelease(newProxies
);
286 if (tempSession
) CFRelease(store
);