]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_snapshot.c
9f6764f1a0f9cd5a340abb5573e783390f76df70
[apple/configd.git] / configd.tproj / _snapshot.c
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Modification History
25 *
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
28 *
29 * April 14, 2000 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33 #include <fcntl.h>
34 #include <paths.h>
35 #include <unistd.h>
36
37 #include "configd.h"
38 #include "configd_server.h"
39 #include "session.h"
40
41
42 #define SNAPSHOT_PATH_STORE _PATH_VARTMP "configd-store.xml"
43 #define SNAPSHOT_PATH_SESSION _PATH_VARTMP "configd-session.xml"
44
45
46 int
47 __SCDynamicStoreSnapshot(SCDynamicStoreRef store)
48 {
49 int fd;
50 serverSessionRef mySession;
51 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
52 CFDataRef xmlData;
53
54 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreSnapshot:"));
55
56 /* check credentials */
57
58 mySession = getSession(storePrivate->server);
59 if (mySession->callerEUID != 0) {
60 return kSCStatusAccessError;
61 }
62
63 /* Save a snapshot of the "store" data */
64
65 (void) unlink(SNAPSHOT_PATH_STORE);
66 fd = open(SNAPSHOT_PATH_STORE, O_WRONLY|O_CREAT|O_TRUNC, 0644);
67 if (fd < 0) {
68 return kSCStatusFailed;
69 }
70
71 xmlData = CFPropertyListCreateXMLData(NULL, storeData);
72 if (!xmlData) {
73 SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed"));
74 close(fd);
75 return kSCStatusFailed;
76 }
77 (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
78 (void) close(fd);
79 CFRelease(xmlData);
80
81 /* Save a snapshot of the "session" data */
82
83 (void) unlink(SNAPSHOT_PATH_SESSION);
84 fd = open(SNAPSHOT_PATH_SESSION, O_WRONLY|O_CREAT|O_TRUNC, 0644);
85 if (fd < 0) {
86 return kSCStatusFailed;
87 }
88
89 /* Save a snapshot of the "session" data */
90
91 xmlData = CFPropertyListCreateXMLData(NULL, sessionData);
92 if (!xmlData) {
93 SCLog(TRUE, LOG_ERR, CFSTR("CFPropertyListCreateXMLData() failed"));
94 close(fd);
95 return kSCStatusFailed;
96 }
97 (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
98 (void) close(fd);
99 CFRelease(xmlData);
100
101 return kSCStatusOK;
102 }
103
104
105 kern_return_t
106 _snapshot(mach_port_t server, int *sc_status)
107 {
108 serverSessionRef mySession = getSession(server);
109
110 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Snapshot configuration database."));
111
112 *sc_status = __SCDynamicStoreSnapshot(mySession->store);
113 if (*sc_status != kSCStatusOK) {
114 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreSnapshot(): %s"), SCErrorString(*sc_status));
115 }
116
117 return KERN_SUCCESS;
118 }