2 * Copyright (c) 2000-2004 Apple Computer, 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
;
89 service
= getservbyname(proxy_service
, "tcp");
90 num
= CFNumberCreate(NULL
,
92 (service
!= NULL
) ? &service
->s_port
: &proxy_defaultport
);
93 CFDictionarySetValue(proxies
, proxy_port
, num
);
103 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
104 CFDictionarySetValue(proxies
, proxy_enable
, num
);
106 CFDictionaryRemoveValue(proxies
, proxy_host
);
107 if (proxy_port
!= NULL
) {
108 CFDictionaryRemoveValue(proxies
, proxy_port
);
116 SCDynamicStoreCopyProxies(SCDynamicStoreRef store
)
120 CFMutableDictionaryRef newProxies
= NULL
;
122 CFDictionaryRef proxies
;
123 Boolean tempSession
= FALSE
;
126 /* copy proxy information from dynamic store */
129 store
= SCDynamicStoreCreate(NULL
,
130 CFSTR("SCDynamicStoreCopyProxies"),
139 key
= SCDynamicStoreKeyCreateProxies(NULL
);
140 proxies
= SCDynamicStoreCopyValue(store
, key
);
145 if (proxies
!= NULL
) {
146 if (isA_CFDictionary(proxies
)) {
147 newProxies
= CFDictionaryCreateMutableCopy(NULL
, 0, proxies
);
152 if (newProxies
== NULL
) {
153 newProxies
= CFDictionaryCreateMutable(NULL
,
155 &kCFTypeDictionaryKeyCallBacks
,
156 &kCFTypeDictionaryValueCallBacks
);
159 /* validate [and augment] proxy content */
161 validate_proxy_content(newProxies
,
162 kSCPropNetProxiesFTPEnable
,
163 kSCPropNetProxiesFTPProxy
,
164 kSCPropNetProxiesFTPPort
,
167 validate_proxy_content(newProxies
,
168 kSCPropNetProxiesGopherEnable
,
169 kSCPropNetProxiesGopherProxy
,
170 kSCPropNetProxiesGopherPort
,
173 validate_proxy_content(newProxies
,
174 kSCPropNetProxiesHTTPEnable
,
175 kSCPropNetProxiesHTTPProxy
,
176 kSCPropNetProxiesHTTPPort
,
179 validate_proxy_content(newProxies
,
180 kSCPropNetProxiesHTTPSEnable
,
181 kSCPropNetProxiesHTTPSProxy
,
182 kSCPropNetProxiesHTTPSPort
,
185 validate_proxy_content(newProxies
,
186 kSCPropNetProxiesRTSPEnable
,
187 kSCPropNetProxiesRTSPProxy
,
188 kSCPropNetProxiesRTSPPort
,
191 validate_proxy_content(newProxies
,
192 kSCPropNetProxiesSOCKSEnable
,
193 kSCPropNetProxiesSOCKSProxy
,
194 kSCPropNetProxiesSOCKSPort
,
197 validate_proxy_content(newProxies
,
198 kSCPropNetProxiesProxyAutoConfigEnable
,
199 kSCPropNetProxiesProxyAutoConfigURLString
,
204 // validate WPAD setting
205 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesProxyAutoDiscoveryEnable
);
209 if (!isA_CFNumber(num
) ||
210 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
211 // if we don't like the enabled key/value
213 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
214 CFDictionarySetValue(newProxies
,
215 kSCPropNetProxiesProxyAutoDiscoveryEnable
,
221 // validate proxy exception list
222 array
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExceptionsList
);
227 n
= isA_CFArray(array
) ? CFArrayGetCount(array
) : 0;
228 for (i
= 0; i
< n
; i
++) {
231 str
= CFArrayGetValueAtIndex(array
, i
);
232 if (!isA_CFString(str
)) {
233 // if we don't like the array contents
240 CFDictionaryRemoveValue(newProxies
, kSCPropNetProxiesExceptionsList
);
244 // validate exclude simple hostnames setting
245 num
= CFDictionaryGetValue(newProxies
, kSCPropNetProxiesExcludeSimpleHostnames
);
249 if (!isA_CFNumber(num
) ||
250 !CFNumberGetValue(num
, kCFNumberIntType
, &enabled
)) {
251 // if we don't like the enabled key/value
253 num
= CFNumberCreate(NULL
, kCFNumberIntType
, &enabled
);
254 CFDictionarySetValue(newProxies
,
255 kSCPropNetProxiesExcludeSimpleHostnames
,
262 proxies
= CFDictionaryCreateCopy(NULL
, newProxies
);
263 CFRelease(newProxies
);
265 if (tempSession
) CFRelease(store
);