]> git.saurik.com Git - apple/configd.git/blob - dnsinfo/dnsinfo_server.c
configd-395.6.tar.gz
[apple/configd.git] / dnsinfo / dnsinfo_server.c
1 /*
2 * Copyright (c) 2004-2008 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 * 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 <bsm/libbsm.h>
40
41 #include <CoreFoundation/CoreFoundation.h>
42 #include <SystemConfiguration/SCPrivate.h>
43
44 #include "dnsinfo_server.h"
45 #include "dnsinfo_private.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,
69 dnsData_t dataRef,
70 mach_msg_type_number_t dataLen,
71 audit_token_t audit_token)
72 {
73 uid_t euid = 0;
74 CFDataRef new_dns_info = NULL;
75 const char *notify_key;
76
77 if ((dataRef != NULL) && (dataLen > 0)) {
78 if (!_SCUnserializeData(&new_dns_info, (void *)dataRef, dataLen)) {
79 goto error;
80 }
81 }
82
83 audit_token_to_au32(audit_token,
84 NULL, // auidp
85 &euid, // euid
86 NULL, // egid
87 NULL, // ruid
88 NULL, // rgid
89 NULL, // pid
90 NULL, // asid
91 NULL); // tid
92 if (euid != 0) {
93 goto error;
94 }
95
96 if ((shared_dns_info != NULL) &&
97 (new_dns_info != NULL) &&
98 CFEqual(shared_dns_info, new_dns_info)) {
99 CFRelease(new_dns_info);
100 return KERN_SUCCESS;
101 }
102
103 if (shared_dns_info != NULL) CFRelease(shared_dns_info);
104 shared_dns_info = new_dns_info;
105
106 notify_key = _dns_configuration_notify_key();
107 if (notify_key != NULL) {
108 uint32_t status;
109
110 status = notify_post(notify_key);
111 if (status != NOTIFY_STATUS_OK) {
112 SCLog(TRUE, LOG_ERR, CFSTR("notify_post() failed: %d"), status);
113 // notification posting failures are non-fatal
114 }
115 }
116
117 return KERN_SUCCESS;
118
119 error :
120
121 if (new_dns_info != NULL) CFRelease(new_dns_info);
122 return KERN_FAILURE;
123 }