]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_configlock.c
configd-24.tar.gz
[apple/configd.git] / configd.tproj / _configlock.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include "configd.h"
24 #include "configd_server.h"
25 #include "session.h"
26
27
28 SCDStatus
29 _SCDLock(SCDSessionRef session)
30 {
31 SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
32 serverSessionRef mySession;
33
34 SCDLog(LOG_DEBUG, CFSTR("_SCDLock:"));
35
36 if ((session == NULL) || (sessionPrivate->server == MACH_PORT_NULL)) {
37 return SCD_NOSESSION; /* you must have an open session to play */
38 }
39
40 if (SCDOptionGet(NULL, kSCDOptionIsLocked)) {
41 return SCD_LOCKED; /* sorry, someone (you) already have the lock */
42 }
43
44 /* check credentials */
45 mySession = getSession(sessionPrivate->server);
46 if (mySession->callerEUID != 0) {
47 #ifdef DEBUG
48 if (!SCDOptionGet(NULL, kSCDOptionDebug)) {
49 #endif /* DEBUG */
50 return SCD_EACCESS;
51 #ifdef DEBUG
52 } else {
53 SCDLog(LOG_DEBUG, CFSTR(" non-root access granted while debugging"));
54 }
55 #endif /* DEBUG */
56 }
57
58 SCDOptionSet(NULL, kSCDOptionIsLocked, TRUE); /* global lock flag */
59 SCDOptionSet(session, kSCDOptionIsLocked, TRUE); /* per-session lock flag */
60
61 /*
62 * defer all (actually, most) changes until the call to _SCDUnlock()
63 */
64 if (cacheData_s) {
65 CFRelease(cacheData_s);
66 CFRelease(changedKeys_s);
67 CFRelease(deferredRemovals_s);
68 CFRelease(removedSessionKeys_s);
69 }
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);
74
75 /* Add a "locked" mode run loop source for this port */
76 CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession->serverRunLoopSource, CFSTR("locked"));
77
78 return SCD_OK;
79 }
80
81
82 kern_return_t
83 _configlock(mach_port_t server, int *scd_status)
84 {
85 serverSessionRef mySession = getSession(server);
86
87 SCDLog(LOG_DEBUG, CFSTR("Lock configuration database."));
88 SCDLog(LOG_DEBUG, CFSTR(" server = %d"), server);
89
90 *scd_status = _SCDLock(mySession->session);
91 if (*scd_status != SCD_OK) {
92 SCDLog(LOG_DEBUG, CFSTR(" SCDLock(): %s"), SCDError(*scd_status));
93 return KERN_SUCCESS;
94 }
95
96 return KERN_SUCCESS;
97 }