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"
42 __SCDynamicStoreOpen(SCDynamicStoreRef
*store
, CFStringRef name
)
44 if (_configd_verbose
) {
45 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreOpen:"));
46 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" name = %@"), name
);
50 * allocate and initialize a new session
52 *store
= (SCDynamicStoreRef
)__SCDynamicStoreCreatePrivate(NULL
, name
, NULL
, NULL
);
55 * If necessary, initialize the store and session data dictionaries
57 if (storeData
== NULL
) {
58 sessionData
= CFDictionaryCreateMutable(NULL
,
60 &kCFTypeDictionaryKeyCallBacks
,
61 &kCFTypeDictionaryValueCallBacks
);
62 storeData
= CFDictionaryCreateMutable(NULL
,
64 &kCFTypeDictionaryKeyCallBacks
,
65 &kCFTypeDictionaryValueCallBacks
);
66 patternData
= CFDictionaryCreateMutable(NULL
,
68 &kCFTypeDictionaryKeyCallBacks
,
69 &kCFTypeDictionaryValueCallBacks
);
70 changedKeys
= CFSetCreateMutable(NULL
,
72 &kCFTypeSetCallBacks
);
73 deferredRemovals
= CFSetCreateMutable(NULL
,
75 &kCFTypeSetCallBacks
);
76 removedSessionKeys
= CFSetCreateMutable(NULL
,
78 &kCFTypeSetCallBacks
);
87 _configopen(mach_port_t server
,
88 xmlData_t nameRef
, /* raw XML bytes */
89 mach_msg_type_number_t nameLen
,
90 mach_port_t
*newServer
,
94 serverSessionRef mySession
, newSession
;
95 CFStringRef name
; /* name (un-serialized) */
96 mach_port_t oldNotify
;
97 CFStringRef sessionKey
;
99 CFMutableDictionaryRef newInfo
;
102 if (_configd_verbose
) {
103 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Open new session."));
104 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
107 /* un-serialize the name */
108 if (!_SCUnserializeString(&name
, NULL
, (void *)nameRef
, nameLen
)) {
109 *sc_status
= kSCStatusFailed
;
113 if (!isA_CFString(name
)) {
115 *sc_status
= kSCStatusInvalidArgument
;
119 mySession
= getSession(server
);
120 if (mySession
->store
) {
122 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" Sorry, this session is already open."));
123 *sc_status
= kSCStatusFailed
; /* you can't re-open an "open" session */
127 /* Create the server port for this session */
128 mp
= CFMachPortCreate(NULL
, configdCallback
, NULL
, NULL
);
130 /* return the newly allocated port to be used for this session */
131 *newServer
= CFMachPortGetPort(mp
);
134 * establish the new session
136 newSession
= addSession(mp
);
138 /* Create and add a run loop source for the port */
139 newSession
->serverRunLoopSource
= CFMachPortCreateRunLoopSource(NULL
, mp
, 0);
140 CFRunLoopAddSource(CFRunLoopGetCurrent(),
141 newSession
->serverRunLoopSource
,
142 kCFRunLoopDefaultMode
);
145 * save the credentials associated with the caller.
147 newSession
->callerEUID
= mySession
->callerEUID
;
148 newSession
->callerEGID
= mySession
->callerEGID
;
150 if (_configd_trace
) {
151 SCTrace(TRUE
, _configd_trace
, CFSTR("open : %5d : %@\n"), *newServer
, name
);
154 *sc_status
= __SCDynamicStoreOpen(&newSession
->store
, name
);
157 * Make the server port accessible to the framework routines.
159 ((SCDynamicStorePrivateRef
)newSession
->store
)->server
= *newServer
;
161 /* Request a notification when/if the client dies */
162 status
= mach_port_request_notification(mach_task_self(),
164 MACH_NOTIFY_NO_SENDERS
,
167 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
169 if (status
!= KERN_SUCCESS
) {
170 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("mach_port_request_notification(): %s"), mach_error_string(status
));
172 cleanupSession(*newServer
);
173 *newServer
= MACH_PORT_NULL
;
174 *sc_status
= kSCStatusFailed
;
178 if (oldNotify
!= MACH_PORT_NULL
) {
179 SCLog(_configd_verbose
, LOG_ERR
, CFSTR("_configopen(): why is oldNotify != MACH_PORT_NULL?"));
183 * Save the name of the calling application / plug-in with the session data.
185 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), *newServer
);
186 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
188 newInfo
= CFDictionaryCreateMutableCopy(NULL
, 0, info
);
190 newInfo
= CFDictionaryCreateMutable(NULL
,
192 &kCFTypeDictionaryKeyCallBacks
,
193 &kCFTypeDictionaryValueCallBacks
);
195 CFDictionarySetValue(newInfo
, kSCDName
, name
);
197 CFDictionarySetValue(sessionData
, sessionKey
, newInfo
);
199 CFRelease(sessionKey
);