2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * March 24, 2000 Allan Nathanson <ajn@apple.com>
37 #include "configd_server.h"
43 __SCDynamicStoreLock(SCDynamicStoreRef store
, Boolean recursive
)
45 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 serverSessionRef mySession
;
48 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreLock:"));
50 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
51 return kSCStatusNoStoreSession
; /* you must have an open session to play */
54 if (storeLocked
> 0) {
55 if (storePrivate
->locked
&& recursive
) {
56 /* if this session holds the lock and this is a recursive (internal) request */
60 return kSCStatusLocked
; /* sorry, someone (you) already have the lock */
63 /* check credentials */
64 mySession
= getSession(storePrivate
->server
);
65 if (mySession
->callerEUID
!= 0) {
66 return kSCStatusAccessError
;
69 if (!recursive
&& _configd_trace
) {
70 SCTrace(TRUE
, _configd_trace
, CFSTR("lock : %5d\n"), storePrivate
->server
);
73 storeLocked
= 1; /* global lock flag */
74 storePrivate
->locked
= TRUE
; /* per-session lock flag */
77 * defer all (actually, most) changes until the call to __SCDynamicStoreUnlock()
80 CFRelease(storeData_s
);
81 CFRelease(patternData_s
);
82 CFRelease(changedKeys_s
);
83 CFRelease(deferredRemovals_s
);
84 CFRelease(removedSessionKeys_s
);
86 storeData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, storeData
);
87 patternData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, patternData
);
88 changedKeys_s
= CFSetCreateMutableCopy(NULL
, 0, changedKeys
);
89 deferredRemovals_s
= CFSetCreateMutableCopy(NULL
, 0, deferredRemovals
);
90 removedSessionKeys_s
= CFSetCreateMutableCopy(NULL
, 0, removedSessionKeys
);
92 /* Add a "locked" mode run loop source for this port */
93 CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession
->serverRunLoopSource
, CFSTR("locked"));
101 _configlock(mach_port_t server
, int *sc_status
)
103 serverSessionRef mySession
= getSession(server
);
105 if (_configd_verbose
) {
106 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Lock configuration database."));
107 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
111 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
115 *sc_status
= __SCDynamicStoreLock(mySession
->store
, FALSE
);
116 if (*sc_status
!= kSCStatusOK
) {
117 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" SCDynamicStoreLock(): %s"), SCErrorString(*sc_status
));