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