]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCPApply.c
configd-1109.101.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCPApply.c
1 /*
2 * Copyright (c) 2000, 2001, 2004-2006, 2010, 2015, 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 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * November 9, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "SCPreferencesInternal.h"
35 #include "SCHelper_client.h"
36
37
38 static Boolean
39 __SCPreferencesApplyChanges_helper(SCPreferencesRef prefs)
40 {
41 Boolean ok;
42 SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
43 uint32_t status = kSCStatusOK;
44
45 if (prefsPrivate->helper_port == MACH_PORT_NULL) {
46 // if no helper
47 goto fail;
48 }
49
50 // have the helper "apply" the prefs
51 // status = kSCStatusOK;
52 ok = _SCHelperExec(prefsPrivate->helper_port,
53 SCHELPER_MSG_PREFS_APPLY,
54 NULL,
55 &status,
56 NULL);
57 if (!ok) {
58 goto fail;
59 }
60
61 if (status != kSCStatusOK) {
62 goto error;
63 }
64
65 return TRUE;
66
67 fail :
68
69 // close helper
70 if (prefsPrivate->helper_port != MACH_PORT_NULL) {
71 _SCHelperClose(&prefsPrivate->helper_port);
72 }
73
74 status = kSCStatusAccessError;
75
76 error :
77
78 // return error
79 _SCErrorSet(status);
80 return FALSE;
81 }
82
83
84 Boolean
85 SCPreferencesApplyChanges(SCPreferencesRef prefs)
86 {
87 Boolean ok = FALSE;
88 SCPreferencesPrivateRef prefsPrivate = (SCPreferencesPrivateRef)prefs;
89 Boolean wasLocked;
90
91 if (prefs == NULL) {
92 /* sorry, you must provide a session */
93 _SCErrorSet(kSCStatusNoPrefsSession);
94 return FALSE;
95 }
96
97 /*
98 * Determine if the we have exclusive access to the preferences
99 * and acquire the lock if necessary.
100 */
101 wasLocked = prefsPrivate->locked;
102 if (!wasLocked) {
103 if (!SCPreferencesLock(prefs, TRUE)) {
104 SC_log(LOG_INFO, "SCPreferencesLock() failed");
105 return FALSE;
106 }
107 }
108
109 if (prefsPrivate->authorizationData != NULL) {
110 ok = __SCPreferencesApplyChanges_helper(prefs);
111 goto done;
112 }
113
114 SC_log(LOG_INFO, "SCPreferences() apply: %s",
115 prefsPrivate->newPath ? prefsPrivate->newPath : prefsPrivate->path);
116
117 /* post notification */
118 ok = SCDynamicStoreNotifyValue(NULL, prefsPrivate->sessionKeyApply);
119 if (!ok) {
120 SC_log(LOG_INFO, "SCDynamicStoreNotifyValue() failed");
121 _SCErrorSet(kSCStatusFailed);
122 }
123
124 done :
125
126 if (!wasLocked) {
127 uint32_t status;
128
129 status = SCError(); // preserve status across unlock
130 (void) SCPreferencesUnlock(prefs);
131 _SCErrorSet(status);
132 }
133 return ok;
134 }