2 * Copyright (c) 2000, 2001, 2003, 2004, 2006, 2008, 2011, 2012, 2014 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
;
46 SCTrace(TRUE
, _configd_trace
,
47 CFSTR("%s%s : %5d : %@\n"),
49 storePrivate
->useSessionKeys
? "t " : " ",
55 * Ensure that this is a new key.
57 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
, TRUE
);
60 /* store key does not exist, proceed */
64 /* store key exists, sorry */
66 sc_status
= kSCStatusKeyExists
;
71 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddValue __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status
));
79 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
82 __SCDynamicStorePush();
92 _configadd(mach_port_t server
,
93 xmlData_t keyRef
, /* raw XML bytes */
94 mach_msg_type_number_t keyLen
,
95 xmlData_t dataRef
, /* raw XML bytes */
96 mach_msg_type_number_t dataLen
,
99 audit_token_t audit_token
)
101 CFStringRef key
= NULL
; /* key (un-serialized) */
102 CFDataRef data
= NULL
; /* data (un-serialized) */
103 serverSessionRef mySession
;
105 *sc_status
= kSCStatusOK
;
107 /* un-serialize the key */
108 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
109 *sc_status
= kSCStatusFailed
;
113 /* un-serialize the data */
114 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
115 *sc_status
= kSCStatusFailed
;
118 if (*sc_status
!= kSCStatusOK
) {
122 if (!isA_CFString(key
)) {
123 *sc_status
= kSCStatusInvalidArgument
;
127 mySession
= getSession(server
);
128 if (mySession
== NULL
) {
129 mySession
= tempSession(server
, CFSTR("SCDynamicStoreAddValue"), audit_token
);
130 if (mySession
== NULL
) {
131 /* you must have an open session to play */
132 *sc_status
= kSCStatusNoStoreSession
;
137 if (!hasWriteAccess(mySession
, key
)) {
138 *sc_status
= kSCStatusAccessError
;
142 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
143 if (*sc_status
== kSCStatusOK
) {
149 if (key
!= NULL
) CFRelease(key
);
150 if (data
!= NULL
) CFRelease(data
);
158 _configadd_s(mach_port_t server
,
159 xmlData_t keyRef
, /* raw XML bytes */
160 mach_msg_type_number_t keyLen
,
161 xmlData_t dataRef
, /* raw XML bytes */
162 mach_msg_type_number_t dataLen
,
166 CFDataRef data
= NULL
; /* data (un-serialized) */
167 CFStringRef key
= NULL
; /* key (un-serialized) */
168 serverSessionRef mySession
;
169 SCDynamicStorePrivateRef storePrivate
;
170 Boolean useSessionKeys
;
172 *sc_status
= kSCStatusOK
;
174 /* un-serialize the key */
175 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
176 *sc_status
= kSCStatusFailed
;
179 /* un-serialize the data */
180 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
181 *sc_status
= kSCStatusFailed
;
184 if (*sc_status
!= kSCStatusOK
) {
188 if (!isA_CFString(key
)) {
189 *sc_status
= kSCStatusInvalidArgument
;
193 mySession
= getSession(server
);
194 if (mySession
== NULL
) {
195 /* you must have an open session to play */
196 *sc_status
= kSCStatusNoStoreSession
;
200 if (!hasWriteAccess(mySession
, key
)) {
201 *sc_status
= kSCStatusAccessError
;
205 // force "useSessionKeys"
206 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
207 useSessionKeys
= storePrivate
->useSessionKeys
;
208 storePrivate
->useSessionKeys
= TRUE
;
210 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);
211 if (*sc_status
== kSCStatusOK
) {
215 // restore "useSessionKeys"
216 storePrivate
->useSessionKeys
= useSessionKeys
;
220 if (key
!= NULL
) CFRelease(key
);
221 if (data
!= NULL
) CFRelease(data
);