2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * October 30, 2003 Allan Nathanson <ajn@apple.com>
28 * - add plugin "stop()" function support
30 * June 11, 2001 Allan Nathanson <ajn@apple.com>
31 * - start using CFBundle code
33 * June 1, 2001 Allan Nathanson <ajn@apple.com>
34 * - public API conversion
36 * May 26, 2000 Allan Nathanson <ajn@apple.com>
40 #include <sys/types.h>
42 #include <sys/param.h>
50 #include "configd_server.h"
51 #include <SystemConfiguration/SCDPlugin.h>
52 #include "SystemConfigurationInternal.h"
56 * path components, extensions, entry points, ...
58 #define BUNDLE_DIRECTORY "/SystemConfiguration" /* [/System/Library]/... */
59 #define BUNDLE_DIR_EXTENSION ".bundle"
62 #define PLUGIN_ALL(p) CFSTR(p)
64 #define PLUGIN_MACOSX(p) CFSTR(p)
65 #define PLUGIN_IOS(p) NULL
66 #else // !TARGET_OS_IPHONE
67 #define PLUGIN_MACOSX(p) NULL
68 #define PLUGIN_IOS(p) CFSTR(p)
69 #endif // !TARGET_OS_IPHONE
71 // white-listed (ok-to-load) bundle identifiers
72 static const CFStringRef pluginWhitelist
[] = {
73 PLUGIN_MACOSX("com.apple.SystemConfiguration.ApplicationFirewall"),
74 PLUGIN_ALL ("com.apple.SystemConfiguration.EAPOLController"),
75 PLUGIN_ALL ("com.apple.SystemConfiguration.IPConfiguration"),
76 PLUGIN_ALL ("com.apple.SystemConfiguration.IPMonitor"),
77 PLUGIN_MACOSX("com.apple.SystemConfiguration.ISPreference"),
78 PLUGIN_ALL ("com.apple.SystemConfiguration.InterfaceNamer"),
79 PLUGIN_ALL ("com.apple.SystemConfiguration.KernelEventMonitor"),
80 PLUGIN_ALL ("com.apple.SystemConfiguration.LinkConfiguration"),
81 PLUGIN_ALL ("com.apple.SystemConfiguration.PPPController"),
82 PLUGIN_ALL ("com.apple.SystemConfiguration.PreferencesMonitor"),
83 PLUGIN_ALL ("com.apple.SystemConfiguration.QoSMarking"),
84 PLUGIN_MACOSX("com.apple.print.notification"),
86 #define N_PLUGIN_WHITELIST (sizeof(pluginWhitelist) / sizeof(pluginWhitelist[0]))
96 SCDynamicStoreBundleLoadFunction
*load
;
97 SCDynamicStoreBundleStartFunction
*start
;
98 SCDynamicStoreBundlePrimeFunction
*prime
;
99 SCDynamicStoreBundleStopFunction
*stop
;
103 // all loaded bundles
104 static CFMutableArrayRef allBundles
= NULL
;
107 static CFMutableDictionaryRef exiting
= NULL
;
110 extern SCDynamicStoreBundleLoadFunction load_IPMonitor
;
111 extern SCDynamicStoreBundlePrimeFunction prime_IPMonitor
;
112 #if !TARGET_OS_SIMULATOR
113 extern SCDynamicStoreBundleLoadFunction load_InterfaceNamer
;
114 extern SCDynamicStoreBundleLoadFunction load_KernelEventMonitor
;
115 extern SCDynamicStoreBundlePrimeFunction prime_KernelEventMonitor
;
116 extern SCDynamicStoreBundleLoadFunction load_LinkConfiguration
;
117 extern SCDynamicStoreBundleLoadFunction load_PreferencesMonitor
;
118 extern SCDynamicStoreBundlePrimeFunction prime_PreferencesMonitor
;
119 extern SCDynamicStoreBundleLoadFunction load_QoSMarking
;
120 #endif // !TARGET_OS_SIMULATOR
124 const CFStringRef bundleID
;
125 SCDynamicStoreBundleLoadFunction
*load
;
126 SCDynamicStoreBundleStartFunction
*start
;
127 SCDynamicStoreBundlePrimeFunction
*prime
;
128 SCDynamicStoreBundleStopFunction
*stop
;
129 } builtin
, *builtinRef
;
132 static const builtin builtin_plugins
[] = {
134 CFSTR("com.apple.SystemConfiguration.IPMonitor"),
140 #if !TARGET_OS_SIMULATOR
142 CFSTR("com.apple.SystemConfiguration.InterfaceNamer"),
149 CFSTR("com.apple.SystemConfiguration.KernelEventMonitor"),
150 load_KernelEventMonitor
,
152 prime_KernelEventMonitor
,
156 CFSTR("com.apple.SystemConfiguration.LinkConfiguration"),
157 load_LinkConfiguration
,
163 CFSTR("com.apple.SystemConfiguration.PreferencesMonitor"),
164 load_PreferencesMonitor
,
166 prime_PreferencesMonitor
,
170 CFSTR("com.apple.SystemConfiguration.QoSMarking"),
176 #endif // !TARGET_OS_SIMULATOR
181 addBundle(CFBundleRef bundle
, Boolean forceEnabled
)
183 CFDictionaryRef bundleDict
;
184 bundleInfoRef bundleInfo
;
186 bundleInfo
= CFAllocatorAllocate(NULL
, sizeof(*bundleInfo
), 0);
187 bundleInfo
->bundle
= (CFBundleRef
)CFRetain(bundle
);
188 bundleInfo
->loaded
= FALSE
;
189 bundleInfo
->builtin
= FALSE
;
190 bundleInfo
->enabled
= TRUE
;
191 bundleInfo
->forced
= forceEnabled
;
192 bundleInfo
->verbose
= FALSE
;
193 bundleInfo
->load
= NULL
;
194 bundleInfo
->start
= NULL
;
195 bundleInfo
->prime
= NULL
;
196 bundleInfo
->stop
= NULL
;
198 bundleDict
= CFBundleGetInfoDictionary(bundle
);
199 if (isA_CFDictionary(bundleDict
)) {
202 bVal
= CFDictionaryGetValue(bundleDict
, kSCBundleIsBuiltinKey
);
203 if (isA_CFBoolean(bVal
)) {
204 bundleInfo
->builtin
= CFBooleanGetValue(bVal
);
207 bVal
= CFDictionaryGetValue(bundleDict
, kSCBundleEnabledKey
);
208 if (isA_CFBoolean(bVal
)) {
209 bundleInfo
->enabled
= CFBooleanGetValue(bVal
);
212 bVal
= CFDictionaryGetValue(bundleDict
, kSCBundleVerboseKey
);
213 if (isA_CFBoolean(bVal
)) {
214 bundleInfo
->verbose
= CFBooleanGetValue(bVal
);
218 CFArrayAppendValue(allBundles
, bundleInfo
);
223 static CF_RETURNS_RETAINED CFStringRef
224 shortBundleIdentifier(CFStringRef bundleID
)
226 CFIndex len
= CFStringGetLength(bundleID
);
228 CFStringRef shortID
= NULL
;
230 if (CFStringFindWithOptions(bundleID
,
235 range
.location
= range
.location
+ range
.length
;
236 range
.length
= len
- range
.location
;
237 shortID
= CFStringCreateWithSubstring(NULL
, bundleID
, range
);
245 getBundleSymbol(CFBundleRef bundle
, CFStringRef functionName
, CFStringRef shortID
)
249 // search for load(), start(), prime(), stop(), ...
250 func
= CFBundleGetFunctionPointerForName(bundle
, functionName
);
255 if (shortID
!= NULL
) {
256 CFStringRef altFunctionName
;
258 // search for load_XXX(), ...
259 altFunctionName
= CFStringCreateWithFormat(NULL
,
264 func
= CFBundleGetFunctionPointerForName(bundle
, altFunctionName
);
265 CFRelease(altFunctionName
);
273 getBundleDirNameAndPath(CFBundleRef bundle
, char *buf
, size_t buf_len
)
280 url
= CFBundleCopyBundleURL(bundle
);
285 ok
= CFURLGetFileSystemRepresentation(url
, TRUE
, (UInt8
*)buf
, buf_len
);
291 cp
= strrchr(buf
, '/');
298 /* check if this directory entry is a valid bundle name */
300 if (len
<= sizeof(BUNDLE_DIR_EXTENSION
)) {
301 /* if entry name isn't long enough */
305 len
-= sizeof(BUNDLE_DIR_EXTENSION
) - 1;
306 if (strcmp(&cp
[len
], BUNDLE_DIR_EXTENSION
) != 0) {
307 /* if entry name doesn't end with ".bundle" */
320 loadBundle(const void *value
, void *context
) {
321 CFStringRef bundleID
;
322 Boolean bundleAllowed
;
323 bundleInfoRef bundleInfo
= (bundleInfoRef
)value
;
324 Boolean bundleExclude
;
325 CFIndex
*nLoaded
= (CFIndex
*)context
;
328 bundleID
= CFBundleGetIdentifier(bundleInfo
->bundle
);
329 if (bundleID
== NULL
) {
330 // sorry, no bundles without a bundle identifier
331 SC_log(LOG_NOTICE
, "skipped %@ (no bundle ID)", bundleInfo
->bundle
);
335 shortID
= shortBundleIdentifier(bundleID
);
337 bundleAllowed
= ((CFSetGetCount(_plugins_allowed
) == 0) || // if no white-listing
338 CFSetContainsValue(_plugins_allowed
, bundleID
) || // if [bundleID] white-listed
339 ((shortID
!= NULL
) &&
340 CFSetContainsValue(_plugins_allowed
, shortID
))|| // if [short bundleID] white-listed
341 bundleInfo
->forced
// if "testing" plugin
343 if (!bundleAllowed
) {
344 SC_log(LOG_INFO
, "skipped %@ (not allowed)", bundleID
);
348 bundleExclude
= (CFSetContainsValue(_plugins_exclude
, bundleID
) || // if [bundleID] excluded
349 ((shortID
!= NULL
) &&
350 CFSetContainsValue(_plugins_exclude
, shortID
)) // if [short bundleID] excluded
353 // sorry, this bundle has been excluded
354 SC_log(LOG_INFO
, "skipped %@ (excluded)", bundleID
);
358 if (!bundleInfo
->enabled
&& !bundleInfo
->forced
) {
359 // sorry, this bundle has not been enabled
360 SC_log(LOG_INFO
, "skipped %@ (disabled)", bundleID
);
364 if (!bundleInfo
->verbose
) {
365 bundleInfo
->verbose
= CFSetContainsValue(_plugins_verbose
, bundleID
);
366 if (!bundleInfo
->verbose
) {
367 if (shortID
!= NULL
) {
368 bundleInfo
->verbose
= CFSetContainsValue(_plugins_verbose
, shortID
);
373 if (bundleInfo
->builtin
) {
374 SC_log(LOG_INFO
, "adding %@", bundleID
);
376 for (size_t i
= 0; i
< sizeof(builtin_plugins
)/sizeof(builtin_plugins
[0]); i
++) {
377 if (CFEqual(bundleID
, builtin_plugins
[i
].bundleID
)) {
378 bundleInfo
->load
= builtin_plugins
[i
].load
;
379 bundleInfo
->start
= builtin_plugins
[i
].start
;
380 bundleInfo
->prime
= builtin_plugins
[i
].prime
;
381 bundleInfo
->stop
= builtin_plugins
[i
].stop
;
386 if ((bundleInfo
->load
== NULL
) &&
387 (bundleInfo
->start
== NULL
) &&
388 (bundleInfo
->prime
== NULL
) &&
389 (bundleInfo
->stop
== NULL
)) {
390 SC_log(LOG_NOTICE
, "%@ add failed", bundleID
);
394 CFErrorRef error
= NULL
;
396 SC_log(LOG_INFO
, "loading %@", bundleID
);
398 if (!CFBundleLoadExecutableAndReturnError(bundleInfo
->bundle
, &error
)) {
399 CFDictionaryRef user_info
;
401 SC_log(LOG_NOTICE
, "%@ load failed", bundleID
);
402 user_info
= CFErrorCopyUserInfo(error
);
403 if (user_info
!= NULL
) {
404 CFStringRef link_error_string
;
406 link_error_string
= CFDictionaryGetValue(user_info
,
407 CFSTR("NSDebugDescription"));
408 if (link_error_string
!= NULL
) {
409 SC_log(LOG_NOTICE
, "%@", link_error_string
);
411 CFRelease(user_info
);
417 // get bundle entry points
418 bundleInfo
->load
= getBundleSymbol(bundleInfo
->bundle
, CFSTR("load" ), shortID
);
419 bundleInfo
->start
= getBundleSymbol(bundleInfo
->bundle
, CFSTR("start"), shortID
);
420 bundleInfo
->prime
= getBundleSymbol(bundleInfo
->bundle
, CFSTR("prime"), shortID
);
421 bundleInfo
->stop
= getBundleSymbol(bundleInfo
->bundle
, CFSTR("stop" ), shortID
);
424 /* mark this bundle as having been loaded */
425 bundleInfo
->loaded
= TRUE
;
427 /* bump the count of loaded bundles */
428 *nLoaded
= *nLoaded
+ 1;
432 if (shortID
!= NULL
) CFRelease(shortID
);
438 callLoadFunction(const void *value
, void *context
)
440 #pragma unused(context)
441 bundleInfoRef bundleInfo
= (bundleInfoRef
)value
;
443 if (!bundleInfo
->loaded
) {
447 if (bundleInfo
->load
== NULL
) {
448 // if no load() function
452 SC_log(LOG_DEBUG
, "calling load() for %@",
453 CFBundleGetIdentifier(bundleInfo
->bundle
));
455 (*bundleInfo
->load
)(bundleInfo
->bundle
, bundleInfo
->verbose
);
466 callStartFunction(const void *value
, void *context
)
468 #pragma unused(context)
469 const char *bundleDirName
;
470 bundleInfoRef bundleInfo
= (bundleInfoRef
)value
;
471 char bundleName
[MAXNAMLEN
+ 1];
472 char bundlePath
[MAXPATHLEN
];
475 if (!bundleInfo
->loaded
) {
479 if (bundleInfo
->start
== NULL
) {
480 // if no start() function
484 /* copy the bundle's path */
485 bundleDirName
= getBundleDirNameAndPath(bundleInfo
->bundle
, bundlePath
, sizeof(bundlePath
));
486 if (bundleDirName
== NULL
) {
487 // if we have a problem with the bundle's path
491 /* copy (just) the bundle's name */
492 if (strlcpy(bundleName
, bundleDirName
, sizeof(bundleName
)) > sizeof(bundleName
)) {
493 // if we have a problem with the bundle's name
496 len
= strlen(bundleName
) - (sizeof(BUNDLE_DIR_EXTENSION
) - 1);
497 bundleName
[len
] = '\0';
499 SC_log(LOG_DEBUG
, "calling start() for %@",
500 CFBundleGetIdentifier(bundleInfo
->bundle
));
502 (*bundleInfo
->start
)(bundleName
, bundlePath
);
513 callPrimeFunction(const void *value
, void *context
)
515 #pragma unused(context)
516 bundleInfoRef bundleInfo
= (bundleInfoRef
)value
;
518 if (!bundleInfo
->loaded
) {
522 if (bundleInfo
->prime
== NULL
) {
523 // if no prime() function
527 SC_log(LOG_DEBUG
, "calling prime() for %@",
528 CFBundleGetIdentifier(bundleInfo
->bundle
));
530 (*bundleInfo
->prime
)();
541 stopComplete(void *info
)
543 CFBundleRef bundle
= (CFBundleRef
)info
;
544 CFStringRef bundleID
= CFBundleGetIdentifier(bundle
);
545 CFRunLoopSourceRef stopRls
;
547 SC_log(LOG_INFO
, "** %@ complete (%f)", bundleID
, CFAbsoluteTimeGetCurrent());
549 stopRls
= (CFRunLoopSourceRef
)CFDictionaryGetValue(exiting
, bundle
);
550 if (stopRls
== NULL
) {
554 CFRunLoopSourceInvalidate(stopRls
);
556 CFDictionaryRemoveValue(exiting
, bundle
);
558 if (CFDictionaryGetCount(exiting
) == 0) {
559 // if all of the plugins are happy
560 SC_log(LOG_INFO
, "server shutdown complete (%f)", CFAbsoluteTimeGetCurrent());
569 stopDelayed(CFRunLoopTimerRef timer
, void *info
)
571 #pragma unused(timer)
577 SC_log(LOG_INFO
, "server shutdown was delayed, unresponsive plugins:");
580 * we've asked our plugins to shutdown but someone
583 n
= CFDictionaryGetCount(exiting
);
584 keys
= CFAllocatorAllocate(NULL
, n
* sizeof(CFTypeRef
), 0);
585 CFDictionaryGetKeysAndValues(exiting
, keys
, NULL
);
586 for (i
= 0; i
< n
; i
++) {
588 CFStringRef bundleID
;
590 bundle
= (CFBundleRef
)keys
[i
];
591 bundleID
= CFBundleGetIdentifier(bundle
);
592 SC_log(LOG_NOTICE
, "** %@", bundleID
);
594 CFAllocatorDeallocate(NULL
, keys
);
600 stopRLSCopyDescription(const void *info
)
602 CFBundleRef bundle
= (CFBundleRef
)info
;
604 return CFStringCreateWithFormat(NULL
,
606 CFSTR("<stopRLS %p> {bundleID = %@}"),
608 CFBundleGetIdentifier(bundle
));
613 stopBundle(const void *value
, void *context
)
615 #pragma unused(context)
616 bundleInfoRef bundleInfo
= (bundleInfoRef
)value
;
617 CFRunLoopSourceRef stopRls
;
618 CFRunLoopSourceContext stopContext
= { 0 // version
619 , bundleInfo
->bundle
// info
621 , CFRelease
// release
622 , stopRLSCopyDescription
// copyDescription
627 , stopComplete
// perform
630 if (!bundleInfo
->loaded
) {
634 if (bundleInfo
->stop
== NULL
) {
635 // if no stop() function
639 stopRls
= CFRunLoopSourceCreate(NULL
, 0, &stopContext
);
640 CFRunLoopAddSource(CFRunLoopGetCurrent(), stopRls
, kCFRunLoopDefaultMode
);
641 CFDictionaryAddValue(exiting
, bundleInfo
->bundle
, stopRls
);
642 (*bundleInfo
->stop
)(stopRls
);
653 * If defined, call each bundles stop() function. This function is
654 * called when configd has been asked to shut down (via a SIGTERM). The
655 * function should signal the provided run loop source when it is "ready"
656 * for the shut down to proceeed.
658 SC_log(LOG_DEBUG
, "calling bundle stop() functions");
659 CFArrayApplyFunction(allBundles
,
660 CFRangeMake(0, CFArrayGetCount(allBundles
)),
664 if (CFDictionaryGetCount(exiting
) == 0) {
665 // if all of the plugins are happy
666 SC_log(LOG_INFO
, "server shutdown complete (%f)", CFAbsoluteTimeGetCurrent());
669 CFRunLoopTimerRef timer
;
672 * launchd will only wait 20 seconds before sending us a
673 * SIGKILL and because we want to know what's stuck before
674 * that time so set our own "we're not waiting any longer"
675 * timeout for 15 seconds.
677 timer
= CFRunLoopTimerCreate(NULL
, /* allocator */
678 CFAbsoluteTimeGetCurrent() + 15.0, /* fireDate (in 15 seconds) */
679 0.0, /* interval (== one-shot) */
682 stopDelayed
, /* callout */
684 CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer
, kCFRunLoopDefaultMode
);
698 plugin_term(int *status
)
700 if (CFArrayGetCount(allBundles
) == 0) {
703 return FALSE
; // don't delay shutdown
706 if (exiting
!= NULL
) {
707 // if shutdown already active
711 SC_log(LOG_INFO
, "starting server shutdown (%f)", CFAbsoluteTimeGetCurrent());
713 exiting
= CFDictionaryCreateMutable(NULL
,
715 &kCFTypeDictionaryKeyCallBacks
,
716 &kCFTypeDictionaryValueCallBacks
);
724 #pragma mark initialization
728 sortBundles(CFMutableArrayRef orig
)
732 CFMutableArrayRef
new;
733 CFMutableSetRef orig_bundleIDs
;
735 orig_bundleIDs
= CFSetCreateMutable(NULL
, 0, &kCFTypeSetCallBacks
);
737 n
= CFArrayGetCount(orig
);
738 for (i
= 0; i
< n
; i
++) {
739 bundleInfoRef bundleInfo
= (bundleInfoRef
)CFArrayGetValueAtIndex(orig
, i
);
740 CFStringRef bundleID
= CFBundleGetIdentifier(bundleInfo
->bundle
);
742 if (bundleID
!= NULL
) {
743 CFSetAddValue(orig_bundleIDs
, bundleID
);
747 new = CFArrayCreateMutable(NULL
, 0, NULL
);
749 Boolean inserted
= FALSE
;
751 for (i
= 0; i
< n
; i
++) {
752 bundleInfoRef bundleInfo1
= (bundleInfoRef
)CFArrayGetValueAtIndex(orig
, i
);
753 CFStringRef bundleID1
= CFBundleGetIdentifier(bundleInfo1
->bundle
);
755 CFDictionaryRef dict
;
758 CFArrayRef
requires = NULL
;
760 dict
= isA_CFDictionary(CFBundleGetInfoDictionary(bundleInfo1
->bundle
));
762 requires = CFDictionaryGetValue(dict
, kSCBundleRequiresKey
);
763 requires = isA_CFArray(requires);
765 if (bundleID1
== NULL
|| requires == NULL
) {
766 CFArrayInsertValueAtIndex(new, 0, bundleInfo1
);
767 CFArrayRemoveValueAtIndex(orig
, i
);
771 count
= nRequires
= CFArrayGetCount(requires);
772 for (j
= 0; j
< nRequires
; j
++) {
775 CFStringRef r
= CFArrayGetValueAtIndex(requires, j
);
777 if (!CFSetContainsValue(orig_bundleIDs
, r
)) {
778 // if dependency not present
783 nNew
= CFArrayGetCount(new);
784 for (k
= 0; k
< nNew
; k
++) {
785 bundleInfoRef bundleInfo2
= (bundleInfoRef
)CFArrayGetValueAtIndex(new, k
);
786 CFStringRef bundleID2
= CFBundleGetIdentifier(bundleInfo2
->bundle
);
788 if (bundleID2
&& CFEqual(bundleID2
, r
)) {
794 /* all dependencies are met, append */
795 CFArrayAppendValue(new, bundleInfo1
);
796 CFArrayRemoveValueAtIndex(orig
, i
);
803 SC_log(LOG_NOTICE
, "Bundles have circular dependency!!!");
807 n
= CFArrayGetCount(orig
);
809 if (CFArrayGetCount(orig
) > 0) {
810 /* we have a circular dependency, append remaining items on new array */
811 CFArrayAppendArray(new, orig
, CFRangeMake(0, CFArrayGetCount(orig
)));
814 /* new one is a sorted version of original */
817 CFArrayRemoveAllValues(orig
);
818 CFArrayAppendArray(orig
, new, CFRangeMake(0, CFArrayGetCount(new)));
820 CFRelease(orig_bundleIDs
);
828 * An alternate CFRelease() that we can use to fake out the
831 static __inline__
void
832 ALT_CFRelease(CFTypeRef cf
)
840 plugin_exec(void *arg
)
844 /* keep track of bundles */
845 allBundles
= CFArrayCreateMutable(NULL
, 0, NULL
);
847 /* add white-listed plugins to those we'll allow to be loaded */
848 for (size_t i
= 0; i
< N_PLUGIN_WHITELIST
; i
++) {
849 if (pluginWhitelist
[i
] != NULL
) {
850 CFSetSetValue(_plugins_allowed
, pluginWhitelist
[i
]);
854 /* allow plug-ins to exec child/helper processes */
855 _SCDPluginExecInit();
858 char path
[MAXPATHLEN
];
859 sysdir_search_path_enumeration_state state
;
862 * identify and load all bundles
864 state
= sysdir_start_search_path_enumeration(SYSDIR_DIRECTORY_LIBRARY
,
865 SYSDIR_DOMAIN_MASK_SYSTEM
);
866 while ((state
= sysdir_get_next_search_path_enumeration(state
, path
))) {
870 #if TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST
871 const char *path_sim_prefix
;
873 path_sim_prefix
= getenv("IPHONE_SIMULATOR_ROOT");
874 if ((path_sim_prefix
!= NULL
) && (strcmp(path_sim_prefix
, ".") != 0)) {
875 char path_sim
[MAXPATHLEN
];
877 strlcpy(path_sim
, path_sim_prefix
, sizeof(path_sim
));
878 strlcat(path_sim
, path
, sizeof(path_sim
));
879 strlcpy(path
, path_sim
, sizeof(path
));
883 #endif // TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST
885 /* load any available bundle */
886 strlcat(path
, BUNDLE_DIRECTORY
, sizeof(path
));
887 SC_log(LOG_DEBUG
, "searching for bundles in \"%s\"", path
);
888 url
= CFURLCreateFromFileSystemRepresentation(NULL
,
892 bundles
= CFBundleCreateBundlesFromDirectory(NULL
, url
, CFSTR(".bundle"));
895 if (bundles
!= NULL
) {
899 n
= CFArrayGetCount(bundles
);
900 for (i
= 0; i
< n
; i
++) {
903 bundle
= (CFBundleRef
)CFArrayGetValueAtIndex(bundles
, i
);
904 addBundle(bundle
, FALSE
);
906 // The CFBundleCreateBundlesFromDirectory() API has
907 // a known/outstanding bug in that it over-retains the
908 // returned bundles. Since we do not expect this to
909 // be fixed we release the extra references.
911 // See <rdar://problems/4912137&6078752> for more info.
913 // Also, we use the hack below to keep the static
915 ALT_CFRelease(bundle
);
921 sortBundles(allBundles
);
927 * load (only) the specified bundle
929 url
= CFURLCreateFromFileSystemRepresentation(NULL
,
933 bundle
= CFBundleCreate(NULL
, url
);
934 if (bundle
!= NULL
) {
935 addBundle(bundle
, TRUE
);
942 * Look for the InterfaceNamer plugin, and move it to the start
945 * Load the InterfaceNamer plugin (and thereby start its thread)
946 * first in an attempt to minimize the amount of time that
947 * opendirectoryd has to wait for the platform UUID to appear in
950 * InterfaceNamer is responsible for creating the platform UUID on
951 * platforms without a UUID in ROM. Until the platform UUID is created
952 * and stashed in nvram, all calls to opendirectoryd to do things like
953 * getpwuid() will block, because opendirectoryd will block while trying
954 * to read the platform UUID from the kernel.
956 * As an example, dlopen() causes XPC to do some intialization, and
957 * part of that initialization involves communicating with xpcd.
958 * Since xpcd calls getpwuid_r() during its initialization, it will
959 * block until the platform UUID is available.
961 for (CFIndex i
= 0; i
< CFArrayGetCount(allBundles
); i
++) {
962 bundleInfoRef bi
= (bundleInfoRef
)CFArrayGetValueAtIndex(allBundles
, i
);
963 CFStringRef bundleID
= CFBundleGetIdentifier(bi
->bundle
);
965 if (_SC_CFEqual(bundleID
,
966 CFSTR("com.apple.SystemConfiguration.InterfaceNamer")))
968 CFArrayRemoveValueAtIndex(allBundles
, i
);
969 CFArrayInsertValueAtIndex(allBundles
, 0, bi
);
977 SC_log(LOG_DEBUG
, "loading bundles");
978 CFArrayApplyFunction(allBundles
,
979 CFRangeMake(0, CFArrayGetCount(allBundles
)),
984 * If defined, call each bundles load() function. This function (or
985 * the start() function) should initialize any variables, open any
986 * sessions with "configd", and register any needed notifications.
988 * Note: Establishing initial information in the store should be
989 * deferred until the prime() initialization function so that
990 * any bundles which want to receive a notification that the
991 * data has changed will have an opportunity to install a
992 * notification handler.
994 SC_log(LOG_DEBUG
, "calling bundle load() functions");
995 CFArrayApplyFunction(allBundles
,
996 CFRangeMake(0, CFArrayGetCount(allBundles
)),
1001 // if no bundles loaded
1006 * If defined, call each bundles start() function. This function is
1007 * called after the bundle has been loaded and its load() function has
1008 * been called. It should initialize any variables, open any sessions
1009 * with "configd", and register any needed notifications.
1011 * Note: Establishing initial information in the store should be
1012 * deferred until the prime() initialization function so that
1013 * any bundles which want to receive a notification that the
1014 * data has changed will have an opportunity to install a
1015 * notification handler.
1017 SC_log(LOG_DEBUG
, "calling bundle start() functions");
1018 CFArrayApplyFunction(allBundles
,
1019 CFRangeMake(0, CFArrayGetCount(allBundles
)),
1024 * If defined, call each bundles prime() function. This function is
1025 * called after the bundle has been loaded and its load() and start()
1026 * functions have been called. It should initialize any configuration
1027 * information and/or state in the store.
1029 SC_log(LOG_DEBUG
, "calling bundle prime() functions");
1030 CFArrayApplyFunction(allBundles
,
1031 CFRangeMake(0, CFArrayGetCount(allBundles
)),
1036 * At this point, the assumption is that each loaded plugin will have
1037 * established CFMachPort, CFSocket, and CFRunLoopTimer input sources
1038 * to handle any events and registered these sources with this threads
1039 * run loop and we're ready to go.
1041 * Note: it is also assumed that any plugin needing to wait and/or block
1042 * will do so only a private thread (or asynchronously on a non-main