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@
24 #include "configd_server.h"
29 _SCDLock(SCDSessionRef session
)
31 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
32 serverSessionRef mySession
;
34 SCDLog(LOG_DEBUG
, CFSTR("_SCDLock:"));
36 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
37 return SCD_NOSESSION
; /* you must have an open session to play */
40 if (SCDOptionGet(NULL
, kSCDOptionIsLocked
)) {
41 return SCD_LOCKED
; /* sorry, someone (you) already have the lock */
44 /* check credentials */
45 mySession
= getSession(sessionPrivate
->server
);
46 if (mySession
->callerEUID
!= 0) {
48 if (!SCDOptionGet(NULL
, kSCDOptionDebug
)) {
53 SCDLog(LOG_DEBUG
, CFSTR(" non-root access granted while debugging"));
58 SCDOptionSet(NULL
, kSCDOptionIsLocked
, TRUE
); /* global lock flag */
59 SCDOptionSet(session
, kSCDOptionIsLocked
, TRUE
); /* per-session lock flag */
62 * defer all (actually, most) changes until the call to _SCDUnlock()
65 CFRelease(cacheData_s
);
66 CFRelease(changedKeys_s
);
67 CFRelease(deferredRemovals_s
);
68 CFRelease(removedSessionKeys_s
);
70 cacheData_s
= CFDictionaryCreateMutableCopy(NULL
, 0, cacheData
);
71 changedKeys_s
= CFSetCreateMutableCopy(NULL
, 0, changedKeys
);
72 deferredRemovals_s
= CFSetCreateMutableCopy(NULL
, 0, deferredRemovals
);
73 removedSessionKeys_s
= CFSetCreateMutableCopy(NULL
, 0, removedSessionKeys
);
75 /* Add a "locked" mode run loop source for this port */
76 CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession
->serverRunLoopSource
, CFSTR("locked"));
83 _configlock(mach_port_t server
, int *scd_status
)
85 serverSessionRef mySession
= getSession(server
);
87 SCDLog(LOG_DEBUG
, CFSTR("Lock configuration database."));
88 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
90 *scd_status
= _SCDLock(mySession
->session
);
91 if (*scd_status
!= SCD_OK
) {
92 SCDLog(LOG_DEBUG
, CFSTR(" SCDLock(): %s"), SCDError(*scd_status
));