]> git.saurik.com Git - apple/configd.git/blob - dnsinfo/dnsinfo_server.c
configd-136.1.tar.gz
[apple/configd.git] / dnsinfo / dnsinfo_server.c
1 /*
2 * Copyright (c) 2004 Apple Computer, 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 * March 9, 2004 Allan Nathanson <ajn@apple.com>
28 * - initial revision
29 */
30
31 #include <notify.h>
32 #include <sysexits.h>
33 #include <syslog.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36 #include <servers/bootstrap.h>
37 #include <mach/mach.h>
38 #include <mach/mach_error.h>
39 #include <CoreFoundation/CoreFoundation.h>
40 #include <SystemConfiguration/SCPrivate.h>
41
42 #include "dnsinfo_server.h"
43 #include "dnsinfo_private.h"
44
45 #include "session.h"
46
47 static CFDataRef shared_dns_info = NULL;
48
49 __private_extern__
50 kern_return_t
51 _shared_dns_infoGet(mach_port_t server, dnsDataOut_t *dataRef, mach_msg_type_number_t *dataLen)
52 {
53 *dataRef = NULL;
54 *dataLen = 0;
55
56 if (shared_dns_info != NULL) {
57 if (!_SCSerializeData(shared_dns_info, (void **)dataRef, (CFIndex *)dataLen)) {
58 return KERN_FAILURE;
59 }
60 }
61
62 return KERN_SUCCESS;
63 }
64
65
66 __private_extern__
67 kern_return_t
68 _shared_dns_infoSet(mach_port_t server, dnsData_t dataRef, mach_msg_type_number_t dataLen)
69 {
70 CFDataRef new_dns_info = NULL;
71 const char *notify_key;
72 serverSessionRef mySession = getSession(server);
73
74 if ((dataRef != NULL) && (dataLen > 0)) {
75 if (!_SCUnserializeData(&new_dns_info, (void *)dataRef, dataLen)) {
76 goto error;
77 }
78 }
79
80 if (mySession->callerEUID != 0) {
81 goto error;
82 }
83
84 if (shared_dns_info != NULL) CFRelease(shared_dns_info);
85 shared_dns_info = new_dns_info;
86
87 notify_key = _dns_configuration_notify_key();
88 if (notify_key != NULL) {
89 uint32_t status;
90
91 status = notify_post(notify_key);
92 if (status != NOTIFY_STATUS_OK) {
93 SCLog(TRUE, LOG_ERR, CFSTR("notify_post() failed: %d"), status);
94 // notification posting failures are non-fatal
95 }
96 }
97
98 return KERN_SUCCESS;
99
100 error :
101
102 if (new_dns_info != NULL) CFRelease(new_dns_info);
103 return KERN_FAILURE;
104 }