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