2 * Copyright (c) 2005-2007 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@
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
37 #include <CoreFoundation/CoreFoundation.h>
38 #include <SystemConfiguration/SCPrivate.h>
40 #include "SCHelper_client.h"
41 #include "helper_comm.h"
44 #define HELPER "SCHelper"
45 #define HELPER_LEN (sizeof(HELPER) - 1)
47 #define SUFFIX_SYM "~sym"
48 #define SUFFIX_SYM_LEN (sizeof(SUFFIX_SYM) - 1)
53 _SCHelperOpen(CFDataRef authorizationData
)
57 struct sockaddr_un sun
;
61 if ((sock
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
62 perror("_SCHelperOpen socket() failed");
66 sun
.sun_family
= AF_UNIX
;
67 strlcpy(sun
.sun_path
, "/var/run/SCHelper", sizeof(sun
.sun_path
));
68 if (connect(sock
, (struct sockaddr
*)&sun
, sizeof(sun
)) == -1) {
69 perror("_SCHelperOpen connect() failed");
74 if (setsockopt(sock
, SOL_SOCKET
, SO_NOSIGPIPE
, (const void *)&yes
, sizeof(yes
)) == -1) {
75 perror("_SCHelperOpen setsockopt() failed");
80 ok
= _SCHelperExec(sock
, SCHELPER_MSG_AUTH
, authorizationData
, &status
, NULL
);
82 SCLog(TRUE
, LOG_INFO
, CFSTR("_SCHelperOpen: could not send authorization"));
89 SCLog(TRUE
, LOG_INFO
, CFSTR("could not start \"" HELPER
"\", status = %u"), status
);
100 _SCHelperClose(int helper
)
102 if (!_SCHelperExec(helper
, SCHELPER_MSG_EXIT
, NULL
, NULL
, NULL
)) {
103 SCLog(TRUE
, LOG_INFO
, CFSTR("_SCHelperOpen: could not send exit request"));