2 * Copyright (c) 2000, 2001, 2003, 2004, 2006, 2008, 2011, 2012, 2014, 2015 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(_configd_trace
, "%s%s : %5d : %@\n",
47 storePrivate
->useSessionKeys
? "t " : " ",
52 * Ensure that this is a new key.
54 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
, TRUE
);
57 /* store key does not exist, proceed */
61 /* store key exists, sorry */
63 sc_status
= kSCStatusKeyExists
;
68 SC_log(LOG_DEBUG
, "__SCDynamicStoreCopyValue() failed: %s", SCErrorString(sc_status
));
76 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
79 __SCDynamicStorePush();
89 _configadd(mach_port_t server
,
90 xmlData_t keyRef
, /* raw XML bytes */
91 mach_msg_type_number_t keyLen
,
92 xmlData_t dataRef
, /* raw XML bytes */
93 mach_msg_type_number_t dataLen
,
96 audit_token_t audit_token
)
98 CFStringRef key
= NULL
; /* key (un-serialized) */
99 CFDataRef data
= NULL
; /* data (un-serialized) */
100 serverSessionRef mySession
;
102 *sc_status
= kSCStatusOK
;
104 /* un-serialize the key */
105 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
106 *sc_status
= kSCStatusFailed
;
110 /* un-serialize the data */
111 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
112 *sc_status
= kSCStatusFailed
;
115 if (*sc_status
!= kSCStatusOK
) {
119 if (!isA_CFString(key
)) {
120 *sc_status
= kSCStatusInvalidArgument
;
124 mySession
= getSession(server
);
125 if (mySession
== NULL
) {
126 mySession
= tempSession(server
, CFSTR("SCDynamicStoreAddValue"), audit_token
);
127 if (mySession
== NULL
) {
128 /* you must have an open session to play */
129 *sc_status
= kSCStatusNoStoreSession
;
134 if (!hasWriteAccess(mySession
, key
)) {
135 *sc_status
= kSCStatusAccessError
;
139 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
140 if (*sc_status
== kSCStatusOK
) {
146 if (key
!= NULL
) CFRelease(key
);
147 if (data
!= NULL
) CFRelease(data
);
155 _configadd_s(mach_port_t server
,
156 xmlData_t keyRef
, /* raw XML bytes */
157 mach_msg_type_number_t keyLen
,
158 xmlData_t dataRef
, /* raw XML bytes */
159 mach_msg_type_number_t dataLen
,
163 CFDataRef data
= NULL
; /* data (un-serialized) */
164 CFStringRef key
= NULL
; /* key (un-serialized) */
165 serverSessionRef mySession
;
166 SCDynamicStorePrivateRef storePrivate
;
167 Boolean useSessionKeys
;
169 *sc_status
= kSCStatusOK
;
171 /* un-serialize the key */
172 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
173 *sc_status
= kSCStatusFailed
;
176 /* un-serialize the data */
177 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
178 *sc_status
= kSCStatusFailed
;
181 if (*sc_status
!= kSCStatusOK
) {
185 if (!isA_CFString(key
)) {
186 *sc_status
= kSCStatusInvalidArgument
;
190 mySession
= getSession(server
);
191 if (mySession
== NULL
) {
192 /* you must have an open session to play */
193 *sc_status
= kSCStatusNoStoreSession
;
197 if (!hasWriteAccess(mySession
, key
)) {
198 *sc_status
= kSCStatusAccessError
;
202 // force "useSessionKeys"
203 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
204 useSessionKeys
= storePrivate
->useSessionKeys
;
205 storePrivate
->useSessionKeys
= TRUE
;
207 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
208 if (*sc_status
== kSCStatusOK
) {
212 // restore "useSessionKeys"
213 storePrivate
->useSessionKeys
= useSessionKeys
;
217 if (key
!= NULL
) CFRelease(key
);
218 if (data
!= NULL
) CFRelease(data
);