2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * April 14, 2000 Allan Nathanson <ajn@apple.com>
38 #include "configd_server.h"
42 #define SNAPSHOT_PATH_STORE _PATH_VARTMP "configd-store.xml"
43 #define SNAPSHOT_PATH_SESSION _PATH_VARTMP "configd-session.xml"
47 __SCDynamicStoreSnapshot(SCDynamicStoreRef store
)
50 serverSessionRef mySession
;
51 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
54 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreSnapshot:"));
56 /* check credentials */
58 mySession
= getSession(storePrivate
->server
);
59 if (mySession
->callerEUID
!= 0) {
60 return kSCStatusAccessError
;
63 /* Save a snapshot of the "store" data */
65 (void) unlink(SNAPSHOT_PATH_STORE
);
66 fd
= open(SNAPSHOT_PATH_STORE
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
68 return kSCStatusFailed
;
71 xmlData
= CFPropertyListCreateXMLData(NULL
, storeData
);
72 (void) write(fd
, CFDataGetBytePtr(xmlData
), CFDataGetLength(xmlData
));
76 /* Save a snapshot of the "session" data */
78 (void) unlink(SNAPSHOT_PATH_SESSION
);
79 fd
= open(SNAPSHOT_PATH_SESSION
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
81 return kSCStatusFailed
;
84 /* Save a snapshot of the "session" data */
86 xmlData
= CFPropertyListCreateXMLData(NULL
, sessionData
);
87 (void) write(fd
, CFDataGetBytePtr(xmlData
), CFDataGetLength(xmlData
));
96 _snapshot(mach_port_t server
, int *sc_status
)
98 serverSessionRef mySession
= getSession(server
);
100 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Snapshot configuration database."));
102 *sc_status
= __SCDynamicStoreSnapshot(mySession
->store
);
103 if (*sc_status
!= kSCStatusOK
) {
104 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreSnapshot(): %s"), SCErrorString(*sc_status
));