2 * Copyright (c) 2000-2003 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 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 serverSessionRef mySession
;
46 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreLock:"));
48 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
49 return kSCStatusNoStoreSession
; /* you must have an open session to play */
52 if (storeLocked
> 0) {
53 if (storePrivate
->locked
&& recursive
) {
54 /* if this session holds the lock and this is a recursive (internal) request */
58 return kSCStatusLocked
; /* sorry, someone (you) already have the lock */
61 /* check credentials */
62 mySession
= getSession(storePrivate
->server
);
63 if (mySession
->callerEUID
!= 0) {
64 return kSCStatusAccessError
;
67 if (!recursive
&& _configd_trace
) {
68 SCTrace(TRUE
, _configd_trace
, CFSTR("lock : %5d\n"), storePrivate
->server
);
71 storeLocked
= 1; /* global lock flag */
72 storePrivate
->locked
= TRUE
; /* per-session lock flag */
75 * defer all (actually, most) changes until the call to __SCDynamicStoreUnlock()
78 CFRelease(storeData_s
);
79 CFRelease(patternData_s
);
80 CFRelease(changedKeys_s
);
81 CFRelease(deferredRemovals_s
);
82 CFRelease(removedSessionKeys_s
);
84 storeData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, storeData
);
85 patternData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, patternData
);
86 changedKeys_s
= CFSetCreateMutableCopy(NULL
, 0, changedKeys
);
87 deferredRemovals_s
= CFSetCreateMutableCopy(NULL
, 0, deferredRemovals
);
88 removedSessionKeys_s
= CFSetCreateMutableCopy(NULL
, 0, removedSessionKeys
);
90 /* Add a "locked" mode run loop source for this port */
91 CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession
->serverRunLoopSource
, CFSTR("locked"));
99 _configlock(mach_port_t server
, int *sc_status
)
101 serverSessionRef mySession
= getSession(server
);
103 if (_configd_verbose
) {
104 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Lock configuration database."));
105 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
109 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
113 *sc_status
= __SCDynamicStoreLock(mySession
->store
, FALSE
);
114 if (*sc_status
!= kSCStatusOK
) {
115 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" SCDynamicStoreLock(): %s"), SCErrorString(*sc_status
));