]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCPrivate.h
configd-963.200.27.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCPrivate.h
1 /*
2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCPRIVATE_H
25 #define _SCPRIVATE_H
26
27 #include <sys/cdefs.h>
28 #include <sys/socket.h>
29 #include <sys/stat.h>
30 #include <sys/syslog.h>
31 #include <mach/message.h>
32 #include <os/activity.h>
33 #include <os/log.h>
34 #include <sys/sysctl.h>
35
36 #include <CoreFoundation/CoreFoundation.h>
37
38 /* SCDynamicStore SPIs */
39 #include <SystemConfiguration/SCDynamicStorePrivate.h>
40 #include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
41 #include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
42
43 /* SCPreferences SPIs */
44 #include <SystemConfiguration/SCPreferencesPrivate.h>
45 #include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
46 #include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
47
48 /* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
49 #include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
50
51 /* SCNetworkConfiguration SPIs */
52 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
53
54 /* SCNetworkConnection SPIs */
55 #include <SystemConfiguration/SCNetworkConnectionPrivate.h>
56
57 /* Keychain SPIs */
58 #include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
59
60 /*!
61 @header SCPrivate
62 */
63
64
65 /* "server" defines */
66 #if !TARGET_OS_SIMULATOR
67 #define _SC_SERVER_PROG "configd"
68 #else // !TARGET_OS_SIMULATOR
69 #define _SC_SERVER_PROG "configd_sim"
70 #endif // !TARGET_OS_SIMULATOR
71
72
73 /* atomic operations */
74 #define _SC_ATOMIC_CMPXCHG(p, o, n) __sync_bool_compare_and_swap((p), (o), (n))
75 #define _SC_ATOMIC_INC(p) __sync_fetch_and_add((p), 1) // return (n++);
76 #define _SC_ATOMIC_DEC(p) __sync_sub_and_fetch((p), 1) // return (--n);
77 #define _SC_ATOMIC_ZERO(p) __sync_fetch_and_and((p), 0) // old_n = n; n = 0; return(old_n);
78
79
80 /* framework path */
81 #if !TARGET_OS_WATCH
82 #define SYSTEMCONFIGURATION_FRAMEWORK_PATH "/System/Library/Frameworks/SystemConfiguration.framework"
83 #else
84 #define SYSTEMCONFIGURATION_FRAMEWORK_PATH "/System/Library/PrivateFrameworks/SystemConfiguration.framework"
85 #endif
86
87
88 /* get-network-info script path */
89 #if TARGET_OS_OSX
90 #define SYSTEMCONFIGURATION_GET_NETWORK_INFO_PATH SYSTEMCONFIGURATION_FRAMEWORK_PATH "/Resources/get-network-info"
91 #else
92 #define SYSTEMCONFIGURATION_GET_NETWORK_INFO_PATH SYSTEMCONFIGURATION_FRAMEWORK_PATH "/get-network-info"
93 #endif
94
95
96 /* crash report(s) directory path */
97 #if TARGET_OS_OSX
98 #define _SC_CRASH_DIR "/Library/Logs/DiagnosticReports"
99 #else
100 #define _SC_CRASH_DIR "/Library/Logs/CrashReporter"
101 #endif
102
103
104 /* framework variables */
105 extern int _sc_debug; /* non-zero if debugging enabled */
106 extern int _sc_verbose; /* non-zero if verbose logging enabled */
107 extern int _sc_log; /* 0 if SC messages should be written to stdout/stderr,
108 1 if SC messages should be logged w/os_log(3),
109 2 if SC messages should be written to stdout/stderr AND logged */
110
111
112 /* notify(3) keys */
113
114 #define _SC_NOTIFY_PREFIX "com.apple.system.config"
115 #define _SC_NOTIFY_NETWORK_CHANGE _SC_NOTIFY_PREFIX ".network_change"
116 #define _SC_NOTIFY_NETWORK_CHANGE_DNS _SC_NOTIFY_NETWORK_CHANGE ".dns"
117 #define _SC_NOTIFY_NETWORK_CHANGE_NWI _SC_NOTIFY_NETWORK_CHANGE ".nwi"
118 #define _SC_NOTIFY_NETWORK_CHANGE_PROXY _SC_NOTIFY_PREFIX ".proxy_change"
119
120
121 /*!
122 @group SCNetworkReachabilityCreateWithOptions #defines
123 @discussion The following defines the keys and values that can
124 be passed to the SCNetworkReachabilityCreateWithOptions
125 API.
126 */
127
128 /*!
129 @constant kSCNetworkReachabilityOptionNodeName
130 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
131 value is either a valid host name or a numeric host address string
132 consisting of a dotted decimal IPv4 address or an IPv6 address.
133 */
134 #define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
135
136 /*!
137 @constant kSCNetworkReachabilityOptionLocalAddress
138 @discussion A CFData wrapping a "struct sockaddr" that represents
139 local address associated with a network connection.
140 */
141 #define kSCNetworkReachabilityOptionLocalAddress CFSTR("local-address")
142
143 /*!
144 @constant kSCNetworkReachabilityOptionPTRAddress
145 @discussion A CFData wrapping a "struct sockaddr" that represents
146 the reverse-address to be queried.
147 */
148 #define kSCNetworkReachabilityOptionPTRAddress CFSTR("ptr-address")
149
150 /*!
151 @constant kSCNetworkReachabilityOptionRemoteAddress
152 @discussion A CFData wrapping a "struct sockaddr" that represents
153 remote address associated with a network connection.
154 */
155 #define kSCNetworkReachabilityOptionRemoteAddress CFSTR("remote-address")
156
157 /*!
158 @constant kSCNetworkReachabilityOptionInterface
159 @discussion A CFString specifying that the reachability query should be
160 limited to the provided network interface (e.g. "en0", "en1", ...).
161 */
162 #define kSCNetworkReachabilityOptionInterface CFSTR("interface")
163
164
165 /*!
166 @constant kSCNetworkReachabilityOptionConnectionOnDemandBypass
167 @discussion A CFBoolean that indicates if we should bypass the VPNOnDemand
168 checks for this target.
169 */
170 #define kSCNetworkReachabilityOptionConnectionOnDemandBypass CFSTR("ConnectionOnDemandBypass")
171
172 /*!
173 @constant kSCNetworkReachabilityOptionResolverBypass
174 @discussion A CFBoolean that indicates if we should bypass resolving any
175 node names. Instead, the status of the DNS server configuration
176 associated with the name will be returned. */
177 #define kSCNetworkReachabilityOptionResolverBypass CFSTR("ResolverBypass")
178
179
180 /*!
181 @constant kSCNetworkReachabilityOptionServerBypass
182 @discussion A CFBoolean that indicates if we should bypass usage of the
183 SCNetworkReachability "server" for this target.
184 */
185 #define kSCNetworkReachabilityOptionServerBypass CFSTR("ServerBypass")
186
187
188
189
190 /*!
191 @group
192 */
193
194 __BEGIN_DECLS
195
196
197 #pragma mark -
198 #pragma mark SCError()
199
200
201 /*!
202 @function _SCErrorSet
203 @discussion Sets the last SystemConfiguration.framework API error code.
204 @param error The error encountered.
205 */
206 void _SCErrorSet (int error);
207
208
209 #pragma mark -
210 #pragma mark Serialization/Unserialization
211
212
213 /*!
214 @function _SCSerialize
215 @discussion Serialize a CFPropertyList object for passing
216 to/from configd.
217 @param obj CFPropertyList object to serialize
218 @param xml A pointer to a CFDataRef, NULL if data should be
219 vm_allocated.
220 @param dataRef A pointer to the newly allocated/serialized data
221 @param dataLen A pointer to the length in bytes of the newly
222 allocated/serialized data
223 */
224 Boolean _SCSerialize (CFPropertyListRef obj,
225 CFDataRef *xml,
226 void **dataRef,
227 CFIndex *dataLen);
228
229 /*!
230 @function _SCUnserialize
231 @discussion Unserialize a stream of bytes passed from/to configd
232 into a CFPropertyList object.
233 @param obj A pointer to memory that will be filled with the CFPropertyList
234 associated with the stream of bytes.
235 @param xml CFDataRef with the serialized data
236 @param dataRef A pointer to the serialized data
237 @param dataLen A pointer to the length of the serialized data
238
239 Specify either "xml" or "data/dataLen".
240 */
241 Boolean _SCUnserialize (CFPropertyListRef *obj,
242 CFDataRef xml,
243 void *dataRef,
244 CFIndex dataLen);
245
246 /*!
247 @function _SCSerializeString
248 @discussion Serialize a CFString object for passing
249 to/from configd.
250 @param str CFString key to serialize
251 @param data A pointer to a CFDataRef, NULL if storage should be
252 vm_allocated.
253 @param dataRef A pointer to the newly allocated/serialized data
254 @param dataLen A pointer to the length in bytes of the newly
255 allocated/serialized data
256 */
257 Boolean _SCSerializeString (CFStringRef str,
258 CFDataRef *data,
259 void **dataRef,
260 CFIndex *dataLen);
261
262 /*!
263 @function _SCUnserializeString
264 @discussion Unserialize a stream of bytes passed from/to configd
265 into a CFString object.
266 @param str A pointer to memory that will be filled with the CFString
267 associated with the stream of bytes.
268 @param utf8 CFDataRef with the serialized data
269 @param dataRef A pointer to the serialized data
270 @param dataLen A pointer to the length of the serialized data
271
272 Specify either "utf8" or "data/dataLen".
273 */
274 Boolean _SCUnserializeString (CFStringRef *str,
275 CFDataRef utf8,
276 void *dataRef,
277 CFIndex dataLen);
278
279 /*!
280 @function _SCSerializeData
281 @discussion Serialize a CFData object for passing
282 to/from configd.
283 @param data CFData key to serialize
284 @param dataRef A pointer to the newly allocated/serialized data
285 @param dataLen A pointer to the length in bytes of the newly
286 allocated/serialized data
287 */
288 Boolean _SCSerializeData (CFDataRef data,
289 void **dataRef,
290 CFIndex *dataLen);
291
292 /*!
293 @function _SCUnserializeData
294 @discussion Unserialize a stream of bytes passed from/to configd
295 into a CFData object.
296 @param data A pointer to memory that will be filled with the CFData
297 associated with the stream of bytes.
298 @param dataRef A pointer to the serialized data
299 @param dataLen A pointer to the length of the serialized data
300 */
301 Boolean _SCUnserializeData (CFDataRef *data,
302 void *dataRef,
303 CFIndex dataLen);
304
305 /*!
306 @function _SCSerializeMultiple
307 @discussion Convert a CFDictionary containing a set of CFPropertlyList
308 values into a CFDictionary containing a set of serialized CFData
309 values.
310 @param dict The CFDictionary with CFPropertyList values.
311 @result The serialized CFDictionary with CFData values
312 */
313 CF_RETURNS_RETAINED
314 CFDictionaryRef _SCSerializeMultiple (CFDictionaryRef dict);
315
316 /*!
317 @function _SCUnserializeMultiple
318 @discussion Convert a CFDictionary containing a set of CFData
319 values into a CFDictionary containing a set of serialized
320 CFPropertlyList values.
321 @param dict The CFDictionary with CFData values.
322 @result The serialized CFDictionary with CFPropertyList values
323 */
324 CF_RETURNS_RETAINED
325 CFDictionaryRef _SCUnserializeMultiple (CFDictionaryRef dict);
326
327
328 #pragma mark -
329
330
331 /*!
332 @function _SCCreatePropertyListFromResource
333 @discussion Reads a property list referenced by a file URL.
334 @param url The file URL.
335 @result The CFPropertyList content of the URL.
336 */
337 CFPropertyListRef
338 _SCCreatePropertyListFromResource (CFURLRef url);
339
340
341 #pragma mark -
342 #pragma mark String conversion
343
344
345 /*!
346 @function _SC_cfstring_to_cstring
347 @discussion Extracts a C-string from a CFString.
348 @param cfstr The CFString to extract the data from.
349 @param buf A user provided buffer of the specified length. If NULL,
350 a new buffer will be allocated to contain the C-string. It
351 is the responsiblity of the caller to free an allocated
352 buffer.
353 @param bufLen The size of the user provided buffer.
354 @param encoding The string encoding
355 @result If the extraction (conversion) is successful then a pointer
356 to the user provided (or allocated) buffer is returned, NULL
357 if the string could not be extracted.
358 */
359 char * _SC_cfstring_to_cstring (CFStringRef cfstr,
360 char *buf,
361 CFIndex bufLen,
362 CFStringEncoding encoding);
363
364 /*!
365 * @function _SC_sockaddr_to_string
366 * @discussion Formats a "struct sockaddr" for reporting
367 * @param address The address to format
368 * @param buf A user provided buffer of the specified length.
369 * @param bufLen The size of the user provided buffer.
370 */
371 void _SC_sockaddr_to_string (const struct sockaddr *address,
372 char *buf,
373 size_t bufLen);
374
375
376 /*!
377 * @function _SC_string_to_sockaddr
378 * @discussion Parses a string into a "struct sockaddr"
379 * @param str The address string to parse
380 * @param af Allowed address families (AF_UNSPEC, AF_INET, AF_INET6)
381 * @param buf A user provided buffer of the specified length; NULL
382 * if a new buffer should be allocated (and deallocated by the
383 * caller).
384 * @param bufLen The size of the user provided buffer.
385 * @result A pointer to the parsed "struct sockaddr"; NULL if
386 * the string could not be parsed as an IP[v6] address.
387 */
388 struct sockaddr *
389 _SC_string_to_sockaddr (const char *str,
390 sa_family_t af,
391 void *buf,
392 size_t bufLen);
393
394 /*!
395 * @function _SC_trimDomain
396 * @discussion Trims leading and trailing "."s from a domain or host name
397 * @param domain The domain name to trim
398 * @result The trimmed domain name.
399 */
400 CF_RETURNS_RETAINED
401 CFStringRef _SC_trimDomain (CFStringRef domain);
402
403
404 #pragma mark -
405 #pragma mark Mach IPC
406
407
408 /*!
409 @function _SC_sendMachMessage
410 @discussion Sends a trivial mach message (one with just a
411 message ID) to the specified port.
412 @param port The mach port.
413 @param msg_id The message id.
414 */
415 void _SC_sendMachMessage (mach_port_t port,
416 mach_msg_id_t msg_id);
417
418
419 #pragma mark -
420 #pragma mark Logging
421
422
423 /*!
424 @function _SC_LOG_DEFAULT
425 @discussion A function returning a default os_log_t object to be
426 used for [SystemConfiguration] logging.
427 @result The os_log_t object
428 */
429 os_log_t _SC_LOG_DEFAULT (void);
430
431
432 /*!
433 @function _SC_syslog_os_log_mapping
434 @discussion Maps a syslog logging level to an os_log level.
435 @param level The syslog logging level
436 @result The os_log level
437 */
438 os_log_type_t _SC_syslog_os_log_mapping (int level);
439
440
441 /*!
442 @function _SCCopyDescription
443 @discussion Returns a formatted textual description of a CF object.
444 @param cf The CFType object (a generic reference of type CFTypeRef) from
445 which to derive a description.
446 @param formatOptions A dictionary containing formatting options for the object.
447 @result A string that contains a formatted description of cf.
448 */
449 CFStringRef _SCCopyDescription (CFTypeRef cf,
450 CFDictionaryRef formatOptions);
451
452
453 /*!
454 @function SCLog
455 @discussion Conditionally issue a log message.
456 @param condition A boolean value indicating if the message should be logged
457 @param level A syslog(3) logging priority.
458 @param formatString The format string
459 */
460 void SCLog (Boolean condition,
461 int level,
462 CFStringRef formatString,
463 ...) CF_FORMAT_FUNCTION(3, 4);
464
465
466 /*!
467 @function SC_log
468 @discussion Issue an os_log() message.
469
470 Note: By default, the log messages will be associated with the
471 "com.apple.SystemConfiguration" subsystem. This behavior
472 can be overwritten by #define'ing SC_LOG_HANDLE with the name
473 of an os_log_t global (or a function that returns an os_log_t)
474 *BEFORE* this header is #include'd. In that case, the noted
475 log handle will be used.
476
477 Also, by #define'ing SC_LOG_OR_PRINT, we will check the "_sc_log"
478 global to see if the messages should [also] be directed to stdout/stderr.
479
480 @param level The syslog(3 logging priority.
481 @param __string The format string
482 @result The specified message will be written to the unified logging system.
483 */
484 #ifndef SC_log
485 #ifdef SC_LOG_HANDLE
486 #ifndef SC_LOG_HANDLE_TYPE
487 #define SC_LOG_HANDLE_TYPE
488 #endif // SC_LOG_HANDLE_TYPE
489 SC_LOG_HANDLE_TYPE os_log_t SC_LOG_HANDLE;
490 #else // SC_LOG_HANDLE
491 #define SC_LOG_HANDLE _SC_LOG_DEFAULT() // use [SC] default os_log handle
492 #ifndef SC_LOG_OR_PRINT
493 #define USE_SC_LOG_OR_PRINT 1 // and use '_sc_log' to control os_log, printf
494 #endif // !SC_LOG_OR_PRINT
495 #endif // !SC_LOG_HANDLE
496
497 #if USE_SC_LOG_OR_PRINT
498 #define SC_log(__level, __format, ...) \
499 do { \
500 os_log_t __handle = SC_LOG_HANDLE; \
501 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
502 \
503 if (((_sc_log != 1) && ((__level > LOG_DEBUG) || _sc_debug)) || \
504 os_log_type_enabled(__handle, __type)) { \
505 __SC_Log(__level, \
506 CFSTR( __format ), \
507 __handle, \
508 __type, \
509 __format, \
510 ## __VA_ARGS__); \
511 } \
512 } while (0)
513 #else // USE_SC_LOG_OR_PRINT
514 #define SC_log(__level, __format, ...) \
515 do { \
516 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
517 os_log_with_type(SC_LOG_HANDLE, __type, __format, ## __VA_ARGS__); \
518 } while (0)
519 #endif // USE_SC_LOG_OR_PRINT
520 #endif // !SC_log
521
522
523 /*!
524 @function __SC_Log
525 @discussion Issue a log message w/os_log(3) or printf(3).
526 The specified message will be written to the system message
527 logger.
528 @param level A syslog(3) logging priority. If less than 0, log message is multi-line
529 @param format_CF The format string (as a CFString for stdout/stderr)
530 @param log The os_log_t handle (for logging)
531 @param type The os_log_type_t type (for logging)
532 @param format The format string (for logging)
533 stream.
534 */
535 void __SC_Log (int level,
536 CFStringRef format_CF,
537 os_log_t log,
538 os_log_type_t type,
539 const char *format,
540 ...) CF_FORMAT_FUNCTION(2, 6) __attribute__((format(os_log, 5, 6)));
541
542
543 /*!
544 @function SCPrint
545 @discussion Conditionally issue a debug message.
546 The message will be written to the specified output stream.
547 @param condition A boolean value indicating if the message should be written
548 @param stream The output stream for the log message.
549 @param formatString The format string
550 */
551 void SCPrint (Boolean condition,
552 FILE *stream,
553 CFStringRef formatString,
554 ...) CF_FORMAT_FUNCTION(3, 4);
555
556
557 #pragma mark -
558 #pragma mark Proxies
559
560
561 /*!
562 @function SCNetworkProxiesCopyMatching
563 @discussion Return the proxy configurations matching a target host
564 and/or one associated with a specific network interface.
565 @param globalConfiguration the proxy dictionary currently returned
566 by SCDynamicStoreCopyProxies().
567 @param server A CFString specying the hostname of interest; NULL if
568 no specific hostname should be used in selecting the proxy
569 configurations.
570 @param interface A CFString specifying that the proxy configuration
571 for the provided network interface (e.g. "en0", "en1", ...)
572 should be returned; NULL if proxy usage will not be scoped
573 to an interface.
574 @result A CFArray containing the proxy configurations associated
575 with the requested server and/or network interface.
576
577 */
578 CFArrayRef
579 SCNetworkProxiesCopyMatching (CFDictionaryRef globalConfiguration,
580 CFStringRef server,
581 CFStringRef interface) API_AVAILABLE(macos(10.7)) SPI_AVAILABLE(ios(5.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
582
583 #define kSCProxiesMatchServer CFSTR("Server") /* CFString */
584 #define kSCProxiesMatchInterface CFSTR("Interface") /* CFString */
585 #define kSCProxiesMatchExecutableUUID CFSTR("UUID") /* CFUUID */
586
587 /*!
588 @function SCNetworkProxiesCopyMatchingWithOptions
589 @discussion Return the proxy configurations matching a target host
590 and/or one associated with a specific network interface.
591 @param globalConfiguration the proxy dictionary currently returned
592 by SCDynamicStoreCopyProxies().
593 @param options A dictionary containing any (or none) of the following:
594 key value description
595 ------------------------------------------------------------------------------------------------
596 kSCProxiesMatchServer CFString The hostname of interest; do not include if no
597 specific hostname should be used in selecting the
598 proxy configurations.
599 kSCProxiesMatchInterface CFString If present, specifies the network interface
600 (e.g. "en0", "en1", ...) whose proxy configuration
601 should be returned. If not present, then proxy usage
602 will not be scoped to an interface.
603 kSCProxiesMatchExecutableUUID CFUUID If present, specifies the Mach-O UUID of the executable
604 on whose behalf the match operation is being performed.
605 If kSCProxiesMatchInterface is present then this option
606 is ignored. If not present, then the Mach-O UUID of
607 the current process is used. The Mach-O UUID is used
608 to match application-specific proxy configurations
609 (i.e., if per-app VPN rules are in effect).
610 @result A CFArray containing the proxy configurations associated with the given options.
611 */
612 CFArrayRef
613 SCNetworkProxiesCopyMatchingWithOptions (CFDictionaryRef globalConfiguration,
614 CFDictionaryRef options) API_AVAILABLE(macos(10.10)) SPI_AVAILABLE(ios(8.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
615
616 extern const CFStringRef kSCProxiesNoGlobal;
617
618 /*!
619 @function SCNetworkProxiesCreateProxyAgentData
620 @discussion Returns a serialized representation of a proxy configuration.
621 @param proxyConfig A dictionary representing a proxy configuration
622 @result returns a CFData representing a proxy configuration. This data is
623 readable by all "config-agents" (Agents with domain as "SystemConfig")
624 via config_agent_copy_proxy_information().
625 You must release the returned value.
626 */
627 CFDataRef
628 SCNetworkProxiesCreateProxyAgentData (CFDictionaryRef proxyConfig) API_AVAILABLE(macos(10.12)) SPI_AVAILABLE(ios(10.0), tvos(10.0), watchos(3.0), bridgeos(3.0));
629
630 /*!
631 @function SCDynamicStoreCopyProxiesWithOptions
632 @discussion Return the proxy configurations matching the provided
633 criteria.
634 @param store An SCDynamicStoreRef representing the dynamic store
635 session that should be used for communication with the server.
636 If NULL, a temporary session will be used.
637 @param options A dictionary of proxy options which can include 1 (or more) of the following :
638 key value description
639 ---------------------------------------------------------------------------------------
640 kSCProxiesNoGlobal CFBoolean Bypass any "global" proxy configuration
641 ...
642 @result Returns a dictionary containing key-value pairs that represent
643 the current internet proxy settings;
644 NULL if no proxy settings have been defined or if an error
645 was encountered.
646 You must release the returned value.
647 */
648 CFDictionaryRef
649 SCDynamicStoreCopyProxiesWithOptions (SCDynamicStoreRef store,
650 CFDictionaryRef options) API_AVAILABLE(macos(10.9)) SPI_AVAILABLE(ios(7.0), tvos(9.0), watchos(1.0), bridgeos(1.0));
651
652 #pragma mark -
653 #pragma mark Reachability
654
655
656 /*!
657 @function SCNetworkReachabilityCopyResolvedAddress
658 @discussion Return the resolved addresses associated with the
659 target host.
660 @result A CFArray[CFData], where each CFData is a (struct sockaddr)
661 */
662 CFArrayRef
663 SCNetworkReachabilityCopyResolvedAddress (SCNetworkReachabilityRef target,
664 int *error_num);
665
666 /*!
667 @function SCNetworkReachabilityCreateWithOptions
668 @discussion Creates a reference to a specified network host. The
669 options allow the caller to specify the node name and/or
670 the service name. This reference can be used later to
671 monitor the reachability of the target host.
672 @param allocator The CFAllocator that should be used to allocate
673 memory for the SCNetworkReachability object.
674 This parameter may be NULL in which case the current
675 default CFAllocator is used. If this reference is not
676 a valid CFAllocator, the behavior is undefined.
677 @param options A CFDictionary containing options specifying the
678 network host. The options reflect the arguments that would
679 be passed to getaddrinfo().
680 */
681 SCNetworkReachabilityRef
682 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator,
683 CFDictionaryRef options);
684
685 /*!
686 @function _SC_checkResolverReachabilityByAddress
687 @discussion Check the reachability of a reverse DNS query
688 */
689 Boolean
690 _SC_checkResolverReachabilityByAddress (SCDynamicStoreRef *storeP,
691 SCNetworkReachabilityFlags *flags,
692 Boolean *haveDNS,
693 struct sockaddr *sa);
694
695 /*!
696 @function SCNetworkReachabilityGetInterfaceIndex
697 @discussion Returns the interface index associated with network interface that will
698 be used to interact with the target host.
699 @param target The SCNetworkReachability reference associated with the address or
700 name to be checked for reachability.
701 @result Returns the interface index associated with the target. Returning -1 means that
702 the target is not reachable.
703 */
704 int
705 SCNetworkReachabilityGetInterfaceIndex (SCNetworkReachabilityRef target);
706
707
708 #pragma mark -
709 #pragma mark Domain
710 /*!
711 @function _SC_domainEndsWithDomain
712 @discussion Checks if one domain is a subset of another
713 @param compare_domain The domain to be compared.
714 @param match_domain The domain to be matched.
715 @return TRUE if the match_domain is contained in the compare_domain.
716 FLASE otherwise.
717 */
718 Boolean
719 _SC_domainEndsWithDomain (CFStringRef compare_domain,
720 CFStringRef match_domain);
721
722 /*!
723 @function _SC_hostMatchesDomain
724 @discussion Checks if a hostname matches a domain. "*" not accepted as a domain. Top-level domain matching not supported.
725 The algorithm is as follows:
726
727 1. Trim .’s and *’s from the front and back of hostname and domain.
728 2. If the number of .’s left in the hostname and domain are equal, require an exact match.
729 3. Else, if the number of .’s in the hostname is greater than the number of .’s in the domain, and the number of .’s in the domain is greater than zero, append a . to the front of the domain and do a suffix match on the hostname.
730 4. Else, fail.
731
732 Examples
733 www.apple.com > * : NO
734 www.apple.com > apple.com : YES
735 www.badapple.com > apple.com : NO
736 www.apple.com > .com : NO
737 foobar > foobar : YES
738 www.apple.com > www.apple.com : YES
739 www.apple.com... > .*.apple.com. : YES
740
741 @param hostname The specific hostname to check.
742 @param domain The domain to be matched.
743 @return TRUE if the hostname matches the domain. FALSE otherwise.
744 */
745 Boolean
746 _SC_hostMatchesDomain (CFStringRef hostname,
747 CFStringRef domain);
748
749 #pragma mark -
750 #pragma mark NetBIOS
751
752
753 #if !TARGET_OS_IPHONE
754 /*
755 * DOS encoding/codepage
756 */
757 void
758 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding,
759 UInt32 macRegion,
760 CFStringEncoding *dosEncoding,
761 UInt32 *dosCodepage);
762 #endif // !TARGET_OS_IPHONE
763
764 #pragma mark -
765 #pragma mark Bundle
766
767
768 /*
769 * bundle access
770 */
771 CFBundleRef
772 _SC_CFBundleGet (void);
773
774 CFStringRef
775 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle,
776 CFStringRef key,
777 CFStringRef value,
778 CFStringRef tableName);
779
780 #pragma mark -
781 #pragma mark Misc
782
783
784 /*
785 * mach port access
786 */
787 CFMachPortRef
788 _SC_CFMachPortCreateWithPort (const char * portDescription,
789 mach_port_t portNum,
790 CFMachPortCallBack callout,
791 CFMachPortContext *context);
792
793 /*
794 * misc
795 */
796 static __inline__ Boolean
797 _SC_CFEqual(CFTypeRef val1, CFTypeRef val2)
798 {
799 if (val1 == val2) {
800 return TRUE;
801 }
802 if (val1 != NULL && val2 != NULL) {
803 return CFEqual(val1, val2);
804 }
805 return FALSE;
806 }
807
808 static __inline__ Boolean
809 _SC_isAppleInternal()
810 {
811 static int isInternal = 0;
812
813 if (isInternal == 0) {
814 int ret;
815 struct stat statbuf;
816
817 ret = stat("/AppleInternal", &statbuf);
818 isInternal = (ret == 0) ? 1 : 2;
819 }
820
821 return (isInternal == 1);
822 }
823
824 Boolean
825 _SC_isInstallEnvironment (void);
826
827 #define MODEL CFSTR("Model")
828
829 CFStringRef
830 _SC_hw_model (Boolean trim);
831
832 void *
833 _SC_dlopen (const char *framework);
834
835 /*
836 * debugging
837 */
838
839 #ifdef DEBUG_MACH_PORT_ALLOCATIONS
840 #define __MACH_PORT_DEBUG(cond, str, port) \
841 do { \
842 if (cond) _SC_logMachPortReferences(str, port); \
843 } while (0)
844 #else // DEBUG_MACH_PORT_ALLOCATIONS
845 #define __MACH_PORT_DEBUG(cond, str, port)
846 #endif // DEBUG_MACH_PORT_ALLOCATIONS
847
848 void
849 _SC_logMachPortStatus (void);
850
851 void
852 _SC_logMachPortReferences (const char *str,
853 mach_port_t port);
854
855 CFStringRef
856 _SC_copyBacktrace (void);
857
858 void
859 _SC_crash (const char *crash_info,
860 CFStringRef notifyHeader,
861 CFStringRef notifyMessage);
862
863 Boolean
864 _SC_getconninfo (int socket,
865 struct sockaddr_storage *src_addr,
866 struct sockaddr_storage *dest_addr,
867 int *if_index,
868 uint32_t *flags);
869
870 __END_DECLS
871
872 #endif /* _SCPRIVATE_H */