2 * Copyright (c) 2000, 2001, 2003, 2004, 2006 Apple Computer, 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 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
35 #include "configd_server.h"
41 __SCDynamicStoreLock(SCDynamicStoreRef store
, Boolean recursive
)
43 serverSessionRef mySession
;
44 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 if ((store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
47 return kSCStatusNoStoreSession
; /* you must have an open session to play */
50 if (storeLocked
> 0) {
51 if (storePrivate
->locked
&& recursive
) {
52 /* if this session holds the lock and this is a recursive (internal) request */
56 return kSCStatusLocked
; /* sorry, someone (you) already have the lock */
59 /* check credentials */
60 mySession
= getSession(storePrivate
->server
);
61 if (mySession
->callerEUID
!= 0) {
62 return kSCStatusAccessError
;
65 if (!recursive
&& _configd_trace
) {
66 SCTrace(TRUE
, _configd_trace
, CFSTR("lock : %5d\n"), storePrivate
->server
);
69 storeLocked
= 1; /* global lock flag */
70 storePrivate
->locked
= TRUE
; /* per-session lock flag */
73 * defer all (actually, most) changes until the call to __SCDynamicStoreUnlock()
76 CFRelease(storeData_s
);
77 CFRelease(patternData_s
);
78 CFRelease(changedKeys_s
);
79 CFRelease(deferredRemovals_s
);
80 CFRelease(removedSessionKeys_s
);
82 storeData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, storeData
);
83 patternData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, patternData
);
84 changedKeys_s
= CFSetCreateMutableCopy(NULL
, 0, changedKeys
);
85 deferredRemovals_s
= CFSetCreateMutableCopy(NULL
, 0, deferredRemovals
);
86 removedSessionKeys_s
= CFSetCreateMutableCopy(NULL
, 0, removedSessionKeys
);
88 /* Add a "locked" mode run loop source for this port */
89 CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession
->serverRunLoopSource
, CFSTR("locked"));
97 _configlock(mach_port_t server
, int *sc_status
)
99 serverSessionRef mySession
= getSession(server
);
101 if (mySession
== NULL
) {
102 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
106 *sc_status
= __SCDynamicStoreLock(mySession
->store
, FALSE
);
107 if (*sc_status
!= kSCStatusOK
) {