]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000, 2001, 2003, 2004, 2006, 2009 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
11 | * file. | |
12 | * | |
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. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | /* | |
25 | * Modification History | |
26 | * | |
27 | * June 1, 2001 Allan Nathanson <ajn@apple.com> | |
28 | * - public API conversion | |
29 | * | |
30 | * March 24, 2000 Allan Nathanson <ajn@apple.com> | |
31 | * - initial revision | |
32 | */ | |
33 | ||
34 | #include "configd.h" | |
35 | #include "configd_server.h" | |
36 | #include "session.h" | |
37 | ||
38 | ||
39 | __private_extern__ | |
40 | int | |
41 | __SCDynamicStoreLock(SCDynamicStoreRef store, Boolean recursive) | |
42 | { | |
43 | serverSessionRef mySession; | |
44 | SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; | |
45 | ||
46 | if ((store == NULL) || (storePrivate->server == MACH_PORT_NULL)) { | |
47 | return kSCStatusNoStoreSession; /* you must have an open session to play */ | |
48 | } | |
49 | ||
50 | if (storeLocked > 0) { | |
51 | if (storePrivate->locked && recursive) { | |
52 | /* if this session holds the lock and this is a recursive (internal) request */ | |
53 | storeLocked++; | |
54 | return kSCStatusOK; | |
55 | } | |
56 | return kSCStatusLocked; /* sorry, someone (you) already have the lock */ | |
57 | } | |
58 | ||
59 | /* check credentials */ | |
60 | mySession = getSession(storePrivate->server); | |
61 | if (!hasWriteAccess(mySession)) { | |
62 | return kSCStatusAccessError; | |
63 | } | |
64 | ||
65 | if (!recursive && _configd_trace) { | |
66 | SCTrace(TRUE, _configd_trace, CFSTR("lock : %5d\n"), storePrivate->server); | |
67 | } | |
68 | ||
69 | storeLocked = 1; /* global lock flag */ | |
70 | storePrivate->locked = TRUE; /* per-session lock flag */ | |
71 | ||
72 | /* | |
73 | * defer all (actually, most) changes until the call to __SCDynamicStoreUnlock() | |
74 | */ | |
75 | if (storeData_s) { | |
76 | CFRelease(storeData_s); | |
77 | CFRelease(patternData_s); | |
78 | CFRelease(changedKeys_s); | |
79 | CFRelease(deferredRemovals_s); | |
80 | CFRelease(removedSessionKeys_s); | |
81 | } | |
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); | |
87 | ||
88 | /* Add a "locked" mode run loop source for this port */ | |
89 | CFRunLoopAddSource(CFRunLoopGetCurrent(), mySession->serverRunLoopSource, CFSTR("locked")); | |
90 | ||
91 | return kSCStatusOK; | |
92 | } | |
93 | ||
94 | ||
95 | __private_extern__ | |
96 | kern_return_t | |
97 | _configlock(mach_port_t server, int *sc_status) | |
98 | { | |
99 | serverSessionRef mySession = getSession(server); | |
100 | ||
101 | if (mySession == NULL) { | |
102 | *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */ | |
103 | return KERN_SUCCESS; | |
104 | } | |
105 | ||
106 | *sc_status = __SCDynamicStoreLock(mySession->store, FALSE); | |
107 | if (*sc_status != kSCStatusOK) { | |
108 | return KERN_SUCCESS; | |
109 | } | |
110 | ||
111 | return KERN_SUCCESS; | |
112 | } |