2 * Copyright (c) 2004-2008, 2011 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * March 9, 2004 Allan Nathanson <ajn@apple.com>
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>
41 #include <CoreFoundation/CoreFoundation.h>
42 #include <SystemConfiguration/SCPrivate.h>
44 #include "dnsinfo_server.h"
45 #include "dnsinfo_private.h"
46 #include <network_information.h>
48 static CFDataRef shared_dns_info
= NULL
;
49 static CFDataRef shared_nwi_state
= NULL
;
53 _shared_dns_infoGet(mach_port_t server
, dnsDataOut_t
*dataRef
, mach_msg_type_number_t
*dataLen
)
58 if (shared_dns_info
!= NULL
) {
62 ok
= _SCSerializeData(shared_dns_info
, (void **)dataRef
, &len
);
75 _shared_infoSet_common(mach_port_t server
,
77 mach_msg_type_number_t dataLen
,
78 audit_token_t audit_token
,
80 const char* notify_key
)
83 CFDataRef new_info
= NULL
;
84 CFDataRef n_cache
= *cache
;
86 if ((dataRef
!= NULL
) && (dataLen
> 0)) {
87 if (!_SCUnserializeData(&new_info
, (void *)dataRef
, dataLen
)) {
92 audit_token_to_au32(audit_token
,
105 if ((n_cache
!= NULL
) &&
106 (new_info
!= NULL
) &&
107 CFEqual(n_cache
, new_info
)) {
112 if (n_cache
!= NULL
) CFRelease(n_cache
);
115 if (notify_key
!= NULL
) {
118 status
= notify_post(notify_key
);
119 if (status
!= NOTIFY_STATUS_OK
) {
120 SCLog(TRUE
, LOG_ERR
, CFSTR("notify_post() failed: %d"), status
);
121 // notification posting failures are non-fatal
129 if (new_info
!= NULL
) CFRelease(new_info
);
136 _shared_dns_infoSet(mach_port_t server
,
138 mach_msg_type_number_t dataLen
,
139 audit_token_t audit_token
)
141 const char *notify_key
;
143 notify_key
= _dns_configuration_notify_key();
144 return _shared_infoSet_common(server
, dataRef
, dataLen
,
145 audit_token
, &shared_dns_info
,
152 _shared_nwi_stateGet(mach_port_t server
, dnsDataOut_t
*dataRef
, mach_msg_type_number_t
*dataLen
)
157 if (shared_nwi_state
!= NULL
) {
161 ok
= _SCSerializeData(shared_nwi_state
, (void **)dataRef
, &len
);
175 _shared_nwi_stateSet(mach_port_t server
,
177 mach_msg_type_number_t dataLen
,
178 audit_token_t audit_token
)
180 const char *notify_key
;
182 notify_key
= nwi_state_get_notify_key();
184 return _shared_infoSet_common(server
, dataRef
, dataLen
,
185 audit_token
, &shared_nwi_state
,