2 * Copyright (c) 2000, 2001, 2003, 2004, 2006, 2008, 2011, 2012, 2014-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>
39 __SCDynamicStoreAddValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef value
)
41 int sc_status
= kSCStatusOK
;
42 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
45 SC_trace("add %s : %5d : %@",
46 storePrivate
->useSessionKeys
? "t " : " ",
51 * Ensure that this is a new key.
53 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
, TRUE
);
56 /* store key does not exist, proceed */
60 /* store key exists, sorry */
62 sc_status
= kSCStatusKeyExists
;
67 SC_log(LOG_DEBUG
, "__SCDynamicStoreCopyValue() failed: %s", SCErrorString(sc_status
));
75 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
78 __SCDynamicStorePush();
88 _configadd(mach_port_t server
,
89 xmlData_t keyRef
, /* raw XML bytes */
90 mach_msg_type_number_t keyLen
,
91 xmlData_t dataRef
, /* raw XML bytes */
92 mach_msg_type_number_t dataLen
,
95 audit_token_t audit_token
)
97 CFStringRef key
= NULL
; /* key (un-serialized) */
98 CFDataRef data
= NULL
; /* data (un-serialized) */
99 serverSessionRef mySession
;
102 *sc_status
= kSCStatusOK
;
104 /* un-serialize the key */
105 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
106 *sc_status
= kSCStatusFailed
;
109 /* un-serialize the data */
110 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
111 *sc_status
= kSCStatusFailed
;
114 if (*sc_status
!= kSCStatusOK
) {
118 if (!isA_CFString(key
)) {
119 *sc_status
= kSCStatusInvalidArgument
;
123 mySession
= getSession(server
);
124 if (mySession
== NULL
) {
125 mySession
= tempSession(server
, CFSTR("SCDynamicStoreAddValue"), audit_token
);
126 if (mySession
== NULL
) {
127 /* you must have an open session to play */
128 *sc_status
= kSCStatusNoStoreSession
;
133 if (!hasWriteAccess(mySession
, "add", key
)) {
134 *sc_status
= kSCStatusAccessError
;
138 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
142 if (key
!= NULL
) CFRelease(key
);
143 if (data
!= NULL
) CFRelease(data
);
151 _configadd_s(mach_port_t server
,
152 xmlData_t keyRef
, /* raw XML bytes */
153 mach_msg_type_number_t keyLen
,
154 xmlData_t dataRef
, /* raw XML bytes */
155 mach_msg_type_number_t dataLen
,
159 CFDataRef data
= NULL
; /* data (un-serialized) */
160 CFStringRef key
= NULL
; /* key (un-serialized) */
161 serverSessionRef mySession
;
162 SCDynamicStorePrivateRef storePrivate
;
163 Boolean useSessionKeys
;
166 *sc_status
= kSCStatusOK
;
168 /* un-serialize the key */
169 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
170 *sc_status
= kSCStatusFailed
;
173 /* un-serialize the data */
174 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
175 *sc_status
= kSCStatusFailed
;
178 if (*sc_status
!= kSCStatusOK
) {
182 if (!isA_CFString(key
)) {
183 *sc_status
= kSCStatusInvalidArgument
;
187 mySession
= getSession(server
);
188 if (mySession
== NULL
) {
189 /* you must have an open session to play */
190 *sc_status
= kSCStatusNoStoreSession
;
194 if (!hasWriteAccess(mySession
, "add (session)", key
)) {
195 *sc_status
= kSCStatusAccessError
;
199 // force "useSessionKeys"
200 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
201 useSessionKeys
= storePrivate
->useSessionKeys
;
202 storePrivate
->useSessionKeys
= TRUE
;
204 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
206 // restore "useSessionKeys"
207 storePrivate
->useSessionKeys
= useSessionKeys
;
211 if (key
!= NULL
) CFRelease(key
);
212 if (data
!= NULL
) CFRelease(data
);