2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 #include <CoreFoundation/CoreFoundation.h>
27 #include <CoreFoundation/CFRunLoop.h>
28 #include <mach/message.h>
29 #include <sys/cdefs.h>
30 #include <sys/syslog.h>
35 The SystemConfiguration framework provides access to the data used to configure a running system. The APIs provided by this framework communicate with the "configd" daemon.
37 The "configd" daemon manages a "cache" reflecting the desired configuration settings as well as the current state of the system. The daemon provides a notification mechanism for user-level processes which need to be aware of changes made to the "cache" data. Lastly, the daemon loads a number of bundles(or plug-ins) which monitor low-level kernel events and, via a set of policy modules, keep this cached data up to date.
39 The "configd" daemon also provides an address space/task/process which can be used by other CFRunLoop based functions which would otherwise require their own process/daemon for execution.
46 @discussion Returned status codes.
47 @constant SCD_OK Success
48 @constant SCD_NOSESSION Configuration daemon session not active
49 @constant SCD_NOSERVER Configuration daemon not (no longer) available
50 @constant SCD_LOCKED Lock already held
51 @constant SCD_NEEDLOCK Lock required for this operation
52 @constant SCD_EACCESS Permission denied (must be root to obtain lock)
53 @constant SCD_NOKEY No such key
54 @constant SCD_EXISTS Data associated with key already defined
55 @constant SCD_STALE Write attempted on stale version of object
56 @constant SCD_INVALIDARGUMENT Invalid argument
57 @constant SCD_NOTIFIERACTIVE Notifier is currently active
58 @constant SCD_FAILED Generic error
61 SCD_OK
= 0, /* Success */
62 SCD_NOSESSION
= 1, /* Configuration daemon session not active */
63 SCD_NOSERVER
= 2, /* Configuration daemon not (no longer) available */
64 SCD_LOCKED
= 3, /* Lock already held */
65 SCD_NEEDLOCK
= 4, /* Lock required for this operation */
66 SCD_EACCESS
= 5, /* Permission denied (must be root to obtain lock) */
67 SCD_NOKEY
= 6, /* No such key */
68 SCD_EXISTS
= 7, /* Data associated with key already defined */
69 SCD_STALE
= 8, /* Write attempted on stale version of object */
70 SCD_INVALIDARGUMENT
= 9, /* Invalid argument */
71 SCD_NOTIFIERACTIVE
= 10, /* Notifier is currently active */
72 SCD_FAILED
= 9999 /* Generic error */
77 @typedef SCDSessionRef
78 @discussion This is the type of a handle to an open "session" with the system
81 typedef const struct __SCDSession
* SCDSessionRef
;
85 @discussion This is the type of a handle to data being retrieved from or to be
86 stored by the system configuration daemon.
88 typedef const struct __SCDHandle
* SCDHandleRef
;
92 @typedef SCDCallbackRoutine_t
93 @discussion Type of the callback function used by the SCDNotifierInformViaCallback()
95 @param session The session handle.
96 @param callback_argument The user-defined argument to be passed to the callback
99 typedef boolean_t (*SCDCallbackRoutine_t
) (SCDSessionRef session
,
100 void *callback_argument
);
105 @discussion Used with the SCDList() and SCDNotifierAdd() functions to describe
106 the CFStringRef argument.
107 @constant kSCDRegexKey Specifies that the key consists of a regular expression.
110 kSCDRegexKey
= 0100000, /* pattern string is a regular expression */
116 @discussion Options which determine the run-time processing of the system
117 configuration framework functions.
118 @constant kSCDOptionDebug Enable debugging
119 @constant kSCDOptionVerbose Enable verbose logging
120 @constant kSCDOptionUseSyslog Use syslog(3) for log messages
121 @constant kSCDOptionUseCFRunLoop Calling application is CFRunLoop() based
124 kSCDOptionDebug
= 0, /* Enable debugging */
125 kSCDOptionVerbose
= 1, /* Enable verbose logging */
126 kSCDOptionUseSyslog
= 2, /* Use syslog(3) for log messages */
127 kSCDOptionUseCFRunLoop
= 3, /* Calling application is CFRunLoop() based */
132 * "configd" loadable bundle / plug-in options
136 @typedef SCDBundleStartRoutine_t
137 @discussion Type of the start() initializatioin function which will be called
138 after all plug-ins have been loaded. This function should initialize any
139 variables, open any sessions with "configd", and register any needed
141 @param bundlePath The path name associated with the plug-in / bundle.
142 @param bundleName The name of the plug-in / bundle.
144 typedef void (*SCDBundleStartRoutine_t
) (const char *bundlePath
,
145 const char *bundleName
);
148 @typedef SCDBundlePrimeRoutine_t
149 @discussion Type of the prime() initializatioin function which will be
150 called after all plug-ins have executed their start() function but
151 before the main plug-in run loop is started. This function should
152 be used to initialize any configuration information and/or state
155 typedef void (*SCDBundlePrimeRoutine_t
) ();
157 #define BUNDLE_DIRECTORY "/SystemConfiguration" /* [/System/Library]/... */
158 #define BUNDLE_OLD_SUBDIR "/"
159 #define BUNDLE_NEW_SUBDIR "/Contents/MacOS/"
160 #define BUNDLE_DIR_EXTENSION ".bundle"
161 #define BUNDLE_DEBUG_EXTENSION "_debug"
162 #define BUNDLE_ENTRY_POINT "_start"
163 #define BUNDLE_ENTRY_POINT2 "_prime"
169 @function SCDHandleInit
170 @discussion Creates a new handle used to access the cached configuration
172 @result A new "cache" data handle.
174 SCDHandleRef
SCDHandleInit ();
177 @function SCDHandleRelease
178 @discussion Releases the specified configuration data handle. The dictionary
179 (or other CFType) associated with this handle will also be released
180 unless a call was previously made to CFRetain().
181 @param handle The cache data handle to be released.
183 void SCDHandleRelease (SCDHandleRef handle
);
186 @function SCDHandleGetInstance
187 @discussion Returns the instance number associated with the specified
188 configuration handle.
189 @param handle The cache data handle.
190 @result The instance number associated with the specified handle.
192 int SCDHandleGetInstance (SCDHandleRef handle
);
195 @function SCDHandleGetData
196 @discussion Returns a reference to the data associated with the specified
197 configuration handle.
198 @param handle The cache data handle.
199 @result The CFType data associated with the specified handle.
201 CFPropertyListRef
SCDHandleGetData (SCDHandleRef handle
);
204 @function SCDHandleSetData
205 @discussion Returns a reference to the data associated with the specified
206 configuration handle.
207 @param handle The cache data handle.
208 @param data The CFType data to be associated with the handle.
210 void SCDHandleSetData (SCDHandleRef handle
,
211 CFPropertyListRef data
);
214 @discussion Initiates a connection with the configuration daemon.
215 @param session A pointer to memory which will be filled with an SCDSessionRef
216 handle to be used for all subsequent requests to the server.
217 If a session cannot be established with the server, the contents of
218 memory pointed to by this parameter are undefined.
219 @param name Pass a string which describes the name of the calling process or
220 plug-in name of the caller.
221 @result A constant of type SCDStatus indicating the success (or failure) of
224 SCDStatus
SCDOpen (SCDSessionRef
*session
,
229 @discussion Closes the specified session to the configuration daemon. All
230 outstanding notification requests will be cancelled.
231 @param session Pass a pointer to an SCDSessionRef handle which should be closed.
232 @result A constant of type SCDStatus indicating the success (or failure) of
235 SCDStatus
SCDClose (SCDSessionRef
*session
);
239 @discussion Locks access to the configuration "cache". All other clients
240 attempting to access the "cache" will block. All change notifications
241 will be deferred until the lock is released.
242 @param session Pass a SCDSessionRef handle which should be used for
243 communication with the server.
244 @result A constant of type SCDStatus indicating the success (or failure) of
247 SCDStatus
SCDLock (SCDSessionRef session
);
251 @discussion Unlocks access to the configuration "cache". Other clients will
252 be able to access the "cache". Any change notifications will be delivered.
253 @param session Pass a SCDSessionRef handle which should be used for
254 communication with the server.
255 @result A constant of type SCDStatus indicating the success (or failure) of
258 SCDStatus
SCDUnlock (SCDSessionRef session
);
262 @discussion Returns an array of CFStringRefs representing the configuration "cache"
263 entries which match the specified pattern key.
264 @param session Pass a SCDSessionRef handle which should be used for
265 communication with the server.
266 @param key The string which must prefix those keys in the configuration "cache"
267 (if regexOptions is zero) or a regex(3) regular expression string which
268 will be used to match configuration "cache" (if regexOptions is kSCDRegexKey).
269 @param regexOptions Pass a bitfield of type SCDKeyOption containing one or more
270 flags describing the pattern key.
271 @param subKeys Pass a pointer to a CFArrayRef which will be set to a new
272 array of CFStringRefs's matching the provided key.
273 @result A constant of type SCDStatus indicating the success (or failure) of
276 SCDStatus
SCDList (SCDSessionRef session
,
279 CFArrayRef
*subKeys
);
283 @discussion Creates a new entry in the configuration "cache" using the
284 specified key and data. An error is returned if the key is already
285 defined in the dictionary.
286 @param session Pass a SCDSessionRef handle which should be used for
287 communication with the server.
288 @param key Pass a reference to the CFStringRef object to be created.
289 @param handle Pass a reference to the SCDHandle object containing the data
290 to be associated with the specified key.
291 @result A constant of type SCDStatus indicating the success (or failure) of
294 SCDStatus
SCDAdd (SCDSessionRef session
,
296 SCDHandleRef handle
);
299 @function SCDAddSession
300 @discussion Creates a new entry in the configuration "cache" using the
301 specified key and data. This entry will, unless updated by another
302 session, automatically be removed when the session is closed. An
303 error is returned if the key is already defined in the dictionary.
305 @param session Pass a SCDSessionRef handle which should be used for
306 communication with the server.
307 @param key Pass a reference to the CFStringRef object to be created.
308 @param handle Pass a reference to the SCDHandle object containing the data
309 to be associated with the specified key.
310 @result A constant of type SCDStatus indicating the success (or failure) of
313 SCDStatus
SCDAddSession (SCDSessionRef session
,
315 SCDHandleRef handle
);
319 @discussion Returns a handle to the configuration "cache" data that corresponds
320 to the specified key.
321 @param session Pass a SCDSessionRef handle which should be used for
322 communication with the server.
323 @param key Pass a reference to the CFStringRef object to be returned.
324 @param handle Pass a pointer to a SCDHandleRef which will be set to a
325 new object containing the data associated with the specified key.
326 @result A constant of type SCDStatus indicating the success (or failure) of
329 SCDStatus
SCDGet (SCDSessionRef session
,
331 SCDHandleRef
*handle
);
335 @discussion Updates the entry in the configuration "cache" that corresponds to
336 the specified key with the provided data. An error will be returned if
337 the data in the "cache" has been updated since the data handle was last
339 @param session Pass the SCDSessionRef handle which should be used to communicate
341 @param key Pass a reference to the CFStringRef object to be updated.
342 @param handle Pass a reference to the SCDHandle object containing the data
343 to be associated with the specified key.
344 @result A constant of type SCDStatus indicating the success (or failure) of
347 SCDStatus
SCDSet (SCDSessionRef session
,
349 SCDHandleRef handle
);
353 @discussion Removes the data from the configuration "cache" data which corresponds
354 to the specified key.
355 @param session Pass a SCDSessionRef handle which should be used for
356 communication with the server.
357 @param key Pass a reference to the CFStringRef object to be removed.
358 @result A constant of type SCDStatus indicating the success (or failure) of
361 SCDStatus
SCDRemove (SCDSessionRef session
,
366 @discussion Updates the instance number for the data in the configuration "cache"
367 associated with the specified key. If the specified key does not exist
368 then a CFDate object will be associated with the key. If the associated
369 data is already a CFDate object then the value will be updated.
370 @param session Pass a SCDSessionRef handle which should be used for
371 communication with the server.
372 @param key Pass a reference to the CFStringRef object to be updated.
373 @result A constant of type SCDStatus indicating the success (or failure) of
376 SCDStatus
SCDTouch (SCDSessionRef session
,
380 @function SCDSnapshot
381 @discussion Records the current state of configd's cache dictionary into the
382 /var/tmp/configd-cache file and configd's session dictionary into the
383 /var/tmp/configd-session file.
384 @result A constant of type SCDStatus indicating the success (or failure) of
387 SCDStatus
SCDSnapshot (SCDSessionRef session
);
390 @function SCDNotifierList
391 @discussion Returns an array of CFStringRefs representing the system configuration
392 data entries being monitored for changes.
393 @param session Pass a SCDSessionRef handle which should be used for
394 communication with the server.
395 @param regexOptions Pass a bitfield of type SCDKeyOption which specifies whether
396 the specific configuration cache key patterns are to be returned or those
397 based on regex(3) pattern strings.
398 @param notifierKeys Pass a pointer to a CFArrayRef which will be set to a new
399 array of CFStringRef's being monitored.
400 @result A constant of type SCDStatus indicating the success (or failure) of
403 SCDStatus
SCDNotifierList (SCDSessionRef session
,
405 CFArrayRef
*notifierKeys
);
408 @function SCDNotifierAdd
409 @discussion Adds the specified key to the list of system configuration
410 data entries which are being monitored for changes.
411 @param session Pass a SCDSessionRef handle which should be used for
412 communication with the server.
413 @param key Pass a reference to the CFStringRef object to be monitored.
414 @param regexOptions Pass a bitfield of type SCDKeyOption which specifies whether
415 the key is for a specific configuration cache key or if it consists
416 of a regex(3) pattern string.
417 @result A constant of type SCDStatus indicating the success (or failure) of
420 SCDStatus
SCDNotifierAdd (SCDSessionRef session
,
425 @function SCDNotifierRemove
426 @discussion Removes the specified key from the list of system configuration
427 data entries which are being monitored for changes.
428 @param session Pass a SCDSessionRef handle which should be used for
429 communication with the server.
430 @param key Pass a reference to the CFStringRef object which should not be monitored.
431 @param regexOptions Pass a bitfield of type SCDKeyOption which specifies whether
432 the key is for a specific configuration cache key or if it consists
433 of a regex(3) pattern string.
434 @result A constant of type SCDStatus indicating the success (or failure) of
437 SCDStatus
SCDNotifierRemove (SCDSessionRef session
,
442 @function SCDNotifierGetChanges
443 @discussion Returns an array of CFStringRefs representing the monitored system
444 configuration data entries which have changed since this function
446 @param session Pass a SCDSessionRef handle which should be used for
447 communication with the server.
448 @param notifierKeys Pass a pointer to a CFArrayRef which will be set to a new
449 array of CFStringRef's being monitored.
450 @result A constant of type SCDStatus indicating the success (or failure) of
453 SCDStatus
SCDNotifierGetChanges (SCDSessionRef session
,
454 CFArrayRef
*notifierKeys
);
457 @function SCDNotifierWait
458 @discussion Waits for a change to be made to a system configuration data
459 entry associated with the current sessions notifier keys.
461 Note: this function is not valid for "configd" plug-ins.
463 @param session Pass a SCDSessionRef handle which should be used for
464 communication with the server.
465 @result A constant of type SCDStatus indicating the success (or failure) of
468 SCDStatus
SCDNotifierWait (SCDSessionRef session
);
471 @function SCDNotifierInformViaCallback
472 @discussion Requests that the specified function be called whenever a change
473 has been detected to one of the system configuration data entries
474 associated with the current sessions notifier keys.
476 The callback function will be called with two arguments, session and arg, which
477 correspond to the current session and the provided argument.
478 The function should return a boolean value indicating whether an
479 error occurred during execution of the callback.
481 Note: if the calling application is based on the CFRunLoop() then an additional
482 run loop source will be added for the notification.
483 Applications which are not based on the CFRunLoop() will have a separate thread
484 started to wait for changes.
485 In either case, the additional run loop source and/or thread will terminate if
486 the notification is cancelled or if the callback indicates that an error was
489 Note: this function is not valid for "configd" plug-ins.
491 @param session Pass a SCDSessionRef handle which should be used for
492 communication with the server.
493 @param func Pass a pointer to the callback applier function to call when a
494 monitored cache entry is changed. If this parameter is not a pointer to
495 a function of the correct prototype (SCDCallbackRoutine_t), the behavior
497 @result A constant of type SCDStatus indicating the success (or failure) of
500 SCDStatus
SCDNotifierInformViaCallback (SCDSessionRef session
,
501 SCDCallbackRoutine_t func
,
505 @function SCDNotifierInformViaMachPort
506 @discussion Allocates a mach port which can be used to detect changes to
507 one of the system configuration data entries associated with the
508 current sessions notifier keys. When a change is detected, an
509 empty (no data) mach message with the specified identifier will
510 be delivered to the calling application via the allocated port.
512 @param session Pass a SCDSessionRef handle which should be used for
513 communication with the server.
514 @param msgid Pass a mach message ID to be included with any notifications.
515 @param port Pass a pointer to a mach port. Upon return, port will be filled
516 with the mach port which will be used for any notifications.
517 @result A constant of type SCDStatus indicating the success (or failure) of
520 SCDStatus
SCDNotifierInformViaMachPort (SCDSessionRef session
,
525 @function SCDNotifierInformViaFD
526 @discussion Allocates a file descriptor which can be used to detect changes
527 to one of the system configuration data entries associated with the
528 current sessions notifier keys. When a change is detected, the
529 specified identifier (4 bytes) will be delivered to the calling
530 application via the allocated file descriptor.
532 @param session Pass a SCDSessionRef handle which should be used for
533 communication with the server.
534 @param identifier Pass an (4 byte) integer identifer which be used for any
536 @param fd Pass a pointer to a file descriptor. Upon return, fd will be filled
537 with the file descriptor which will be used for any notifications.
538 @result A constant of type SCDStatus indicating the success (or failure) of
541 SCDStatus
SCDNotifierInformViaFD (SCDSessionRef session
,
546 @function SCDNotifierInformViaSignal
547 @discussion Requests that the specified BSD signal be sent to the process
548 with the indicated process id whenever a change has been detected
549 to one of the system configuration data entries associated with the
550 current sessions notifier keys.
552 Note: this function is not valid for "configd" plug-ins.
554 @param session Pass a SCDSessionRef handle which should be used for
555 communication with the server.
556 @param pid Pass a UNIX proces ID which should be signalled for any notifications.
557 @param sig Pass a signal number to be used.
558 @result A constant of type SCDStatus indicating the success (or failure) of
561 SCDStatus
SCDNotifierInformViaSignal (SCDSessionRef session
,
566 @function SCDNotifierCancel
567 @discussion Cancels all outstanding notification delivery request for this
570 @param session Pass a SCDSessionRef handle which should be used for
571 communication with the server.
572 @result A constant of type SCDStatus indicating the success (or failure) of
575 SCDStatus
SCDNotifierCancel (SCDSessionRef session
);
578 @function SCDOptionGet
579 @discussion Returns the value associated with the specified option.
580 @param session Pass a SCDSessionRef handle of the option of interest (or
581 NULL for the global option setting).
582 @param option Pass the SCDOption of interest.
583 @result The current value of the specified option.
585 int SCDOptionGet (SCDSessionRef session
,
589 @function SCDOptionSet
590 @discussion Sets the value associated with the specified option.
591 @param session Pass a SCDSessionRef handle for the option to be set (or
592 NULL for the global option settings).
593 @param option Pass the SCDOption to be updated.
594 @param value Pass the new value for the option.
595 @result The current value of the specified option.
597 void SCDOptionSet (SCDSessionRef session
,
602 @function SCDSessionLog
603 @discussion Issues a log and/or debug message.
604 @param session Pass a SCDSessionRef handle for the current session..
605 @param level Pass a syslog(3) logging priority.
607 Note: LOG_DEBUG messages will not be issued if the verbose option has not been enabled.
608 @param formatString Pass the CF format string
609 @result The specified message will be logged.
611 void SCDSessionLog (SCDSessionRef session
,
613 CFStringRef formatString
,
618 @discussion Issues a log and/or debug message.
619 @param level Pass a syslog(3) logging priority.
620 @param formatString Pass the CF format string
621 @result The specified message will be logged.
623 void SCDLog (int level
,
624 CFStringRef formatString
,
627 const char * SCDError (SCDStatus status
);