2 * Copyright (c) 2000-2009, 2011, 2015-2017, 2019 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
35 #include "configd_server.h"
38 #include <bsm/libbsm.h>
39 #include <sys/types.h>
44 __SCDynamicStoreOpen(SCDynamicStoreRef
*store
, CFStringRef name
)
47 * allocate and initialize a new session
49 *store
= (SCDynamicStoreRef
)__SCDynamicStoreCreatePrivate(NULL
, name
, NULL
, NULL
);
52 * If necessary, initialize the store and session data dictionaries
54 if (storeData
== NULL
) {
55 storeData
= CFDictionaryCreateMutable(NULL
,
57 &kCFTypeDictionaryKeyCallBacks
,
58 &kCFTypeDictionaryValueCallBacks
);
59 patternData
= CFDictionaryCreateMutable(NULL
,
61 &kCFTypeDictionaryKeyCallBacks
,
62 &kCFTypeDictionaryValueCallBacks
);
63 changedKeys
= CFSetCreateMutable(NULL
,
65 &kCFTypeSetCallBacks
);
66 deferredRemovals
= CFSetCreateMutable(NULL
,
68 &kCFTypeSetCallBacks
);
69 removedSessionKeys
= CFSetCreateMutable(NULL
,
71 &kCFTypeSetCallBacks
);
80 _configopen(mach_port_t server
,
81 xmlData_t nameRef
, /* raw XML bytes */
82 mach_msg_type_number_t nameLen
,
83 xmlData_t optionsRef
, /* raw XML bytes */
84 mach_msg_type_number_t optionsLen
,
85 mach_port_t
*newServer
,
87 audit_token_t audit_token
)
89 serverSessionRef mySession
;
90 CFStringRef name
= NULL
; /* name (un-serialized) */
91 CFDictionaryRef options
= NULL
; /* options (un-serialized) */
92 SCDynamicStorePrivateRef storePrivate
;
93 CFBooleanRef useSessionKeys
= NULL
;
95 *newServer
= MACH_PORT_NULL
;
96 *sc_status
= kSCStatusOK
;
98 /* un-serialize the name */
99 if (!_SCUnserializeString(&name
, NULL
, (void *)nameRef
, nameLen
)) {
100 *sc_status
= kSCStatusFailed
;
103 if ((optionsRef
!= NULL
) && (optionsLen
> 0)) {
104 /* un-serialize the [session] options */
105 if (!_SCUnserialize((CFPropertyListRef
*)&options
, NULL
, (void *)optionsRef
, optionsLen
)) {
106 *sc_status
= kSCStatusFailed
;
110 if (*sc_status
!= kSCStatusOK
) {
114 if (!isA_CFString(name
)) {
115 *sc_status
= kSCStatusInvalidArgument
;
119 if (options
!= NULL
) {
120 if (!isA_CFDictionary(options
)) {
121 *sc_status
= kSCStatusInvalidArgument
;
126 * [pre-]process any provided options
128 useSessionKeys
= CFDictionaryGetValue(options
, kSCDynamicStoreUseSessionKeys
);
129 if (useSessionKeys
!= NULL
) {
130 if (!isA_CFBoolean(useSessionKeys
)) {
131 *sc_status
= kSCStatusInvalidArgument
;
138 * establish the new session
140 mySession
= addClient(server
, audit_token
);
141 if (mySession
== NULL
) {
142 SC_log(LOG_NOTICE
, "session is already open");
143 *sc_status
= kSCStatusFailed
; /* you can't re-open an "open" session */
147 *newServer
= mySession
->key
;
148 __MACH_PORT_DEBUG(TRUE
, "*** _configopen (after addClient)", *newServer
);
150 SC_trace("open : %5d : %@",
154 *sc_status
= __SCDynamicStoreOpen(&mySession
->store
, name
);
155 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
158 * Make the server port accessible to the framework routines.
159 * ... and be sure to clear before calling CFRelease(store)
161 storePrivate
->server
= *newServer
;
164 * Process any provided [session] options
166 if (useSessionKeys
!= NULL
) {
167 storePrivate
->useSessionKeys
= CFBooleanGetValue(useSessionKeys
);
171 * Save the name of the calling application / plug-in with the session data.
173 mySession
->name
= name
;
176 * Note: at this time we should be holding ONE send right and
177 * ONE receive right to the server. The send right is
178 * moved to the caller.
183 if (options
!= NULL
) CFRelease(options
);