]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_snapshot.c
configd-42.tar.gz
[apple/configd.git] / configd.tproj / _snapshot.c
1 /*
2 * Copyright (c) 2000 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 (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
73 (void) close(fd);
74 CFRelease(xmlData);
75
76 /* Save a snapshot of the "session" data */
77
78 (void) unlink(SNAPSHOT_PATH_SESSION);
79 fd = open(SNAPSHOT_PATH_SESSION, O_WRONLY|O_CREAT|O_TRUNC, 0644);
80 if (fd < 0) {
81 return kSCStatusFailed;
82 }
83
84 /* Save a snapshot of the "session" data */
85
86 xmlData = CFPropertyListCreateXMLData(NULL, sessionData);
87 (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData));
88 (void) close(fd);
89 CFRelease(xmlData);
90
91 return kSCStatusOK;
92 }
93
94
95 kern_return_t
96 _snapshot(mach_port_t server, int *sc_status)
97 {
98 serverSessionRef mySession = getSession(server);
99
100 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Snapshot configuration database."));
101
102 *sc_status = __SCDynamicStoreSnapshot(mySession->store);
103 if (*sc_status != kSCStatusOK) {
104 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreSnapshot(): %s"), SCErrorString(*sc_status));
105 }
106
107 return KERN_SUCCESS;
108 }