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