]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_configopen.c
configd-1061.0.2.tar.gz
[apple/configd.git] / configd.tproj / _configopen.c
1 /*
2 * Copyright (c) 2000-2009, 2011, 2015-2017, 2019 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "configd.h"
35 #include "configd_server.h"
36 #include "session.h"
37
38 #include <bsm/libbsm.h>
39 #include <sys/types.h>
40 #include <unistd.h>
41
42 __private_extern__
43 int
44 __SCDynamicStoreOpen(SCDynamicStoreRef *store, CFStringRef name)
45 {
46 /*
47 * allocate and initialize a new session
48 */
49 *store = (SCDynamicStoreRef)__SCDynamicStoreCreatePrivate(NULL, name, NULL, NULL);
50
51 /*
52 * If necessary, initialize the store and session data dictionaries
53 */
54 if (storeData == NULL) {
55 storeData = CFDictionaryCreateMutable(NULL,
56 0,
57 &kCFTypeDictionaryKeyCallBacks,
58 &kCFTypeDictionaryValueCallBacks);
59 patternData = CFDictionaryCreateMutable(NULL,
60 0,
61 &kCFTypeDictionaryKeyCallBacks,
62 &kCFTypeDictionaryValueCallBacks);
63 changedKeys = CFSetCreateMutable(NULL,
64 0,
65 &kCFTypeSetCallBacks);
66 deferredRemovals = CFSetCreateMutable(NULL,
67 0,
68 &kCFTypeSetCallBacks);
69 removedSessionKeys = CFSetCreateMutable(NULL,
70 0,
71 &kCFTypeSetCallBacks);
72 }
73
74 return kSCStatusOK;
75 }
76
77
78 __private_extern__
79 kern_return_t
80 _configopen(mach_port_t server,
81 xmlData_t nameRef, /* raw XML bytes */
82 mach_msg_type_number_t nameLen,
83 xmlData_t optionsRef, /* raw XML bytes */
84 mach_msg_type_number_t optionsLen,
85 mach_port_t *newServer,
86 int *sc_status,
87 audit_token_t audit_token)
88 {
89 serverSessionRef mySession;
90 CFStringRef name = NULL; /* name (un-serialized) */
91 CFDictionaryRef options = NULL; /* options (un-serialized) */
92 SCDynamicStorePrivateRef storePrivate;
93 CFBooleanRef useSessionKeys = NULL;
94
95 *newServer = MACH_PORT_NULL;
96 *sc_status = kSCStatusOK;
97
98 /* un-serialize the name */
99 if (!_SCUnserializeString(&name, NULL, (void *)nameRef, nameLen)) {
100 *sc_status = kSCStatusFailed;
101 }
102
103 if ((optionsRef != NULL) && (optionsLen > 0)) {
104 /* un-serialize the [session] options */
105 if (!_SCUnserialize((CFPropertyListRef *)&options, NULL, (void *)optionsRef, optionsLen)) {
106 *sc_status = kSCStatusFailed;
107 }
108 }
109
110 if (*sc_status != kSCStatusOK) {
111 goto done;
112 }
113
114 if (!isA_CFString(name)) {
115 *sc_status = kSCStatusInvalidArgument;
116 goto done;
117 }
118
119 if (options != NULL) {
120 if (!isA_CFDictionary(options)) {
121 *sc_status = kSCStatusInvalidArgument;
122 goto done;
123 }
124
125 /*
126 * [pre-]process any provided options
127 */
128 useSessionKeys = CFDictionaryGetValue(options, kSCDynamicStoreUseSessionKeys);
129 if (useSessionKeys != NULL) {
130 if (!isA_CFBoolean(useSessionKeys)) {
131 *sc_status = kSCStatusInvalidArgument;
132 goto done;
133 }
134 }
135 }
136
137 /*
138 * establish the new session
139 */
140 mySession = addClient(server, audit_token);
141 if (mySession == NULL) {
142 SC_log(LOG_NOTICE, "session is already open");
143 *sc_status = kSCStatusFailed; /* you can't re-open an "open" session */
144 goto done;
145 }
146
147 *newServer = mySession->key;
148 __MACH_PORT_DEBUG(TRUE, "*** _configopen (after addClient)", *newServer);
149
150 SC_trace("open : %5d : %@",
151 *newServer,
152 name);
153
154 *sc_status = __SCDynamicStoreOpen(&mySession->store, name);
155 storePrivate = (SCDynamicStorePrivateRef)mySession->store;
156
157 /*
158 * Make the server port accessible to the framework routines.
159 * ... and be sure to clear before calling CFRelease(store)
160 */
161 storePrivate->server = *newServer;
162
163 /*
164 * Process any provided [session] options
165 */
166 if (useSessionKeys != NULL) {
167 storePrivate->useSessionKeys = CFBooleanGetValue(useSessionKeys);
168 }
169
170 /*
171 * Save the name of the calling application / plug-in with the session data.
172 */
173 mySession->name = name;
174
175 /*
176 * Note: at this time we should be holding ONE send right and
177 * ONE receive right to the server. The send right is
178 * moved to the caller.
179 */
180
181 done :
182
183 if (options != NULL) CFRelease(options);
184 return KERN_SUCCESS;
185 }