#define ENABLE_DNSSEC_CERTS 0
/* Define to 1 if keychain is used */
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#undef HAVE_KEYCHAIN
-#else
+#else // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define HAVE_KEYCHAIN 1
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
/* Define to 1 if keychain is used */
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#undef HAVE_SECURITY_FRAMEWORK
-#else
+#else // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define HAVE_SECURITY_FRAMEWORK 1
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
/* Define to 1 if Open Dir available */
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#undef HAVE_OPENDIR
-#else
+#else // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define HAVE_OPENDIR 1
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define HAVE_NETINET6_IPSEC 1
#define IPSECASLDOMAIN CONSTSTR("com.apple.Networking.ipsec.asl")
#define IPSECASLKEY CONSTSTR("IPSEC")
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define IPSECCONFIGTRACEREVENT(config, eventCode, message, failure_reason)
#define IPSECSESSIONTRACERSTOP(session, is_failure, reason)
#define IPSECSESSIONTRACERESTABLISHED(session)
-#else
+#else // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#define IPSECCONFIGTRACEREVENT(config, eventCode, message, failure_reason) ipsecConfigTracerEvent(config, eventCode, message, failure_reason)
#define IPSECSESSIONTRACERSTOP(session, is_failure, reason) ipsecSessionTracerStop(session, is_failure, reason)
#define IPSECSESSIONTRACERESTABLISHED(session) ipsecSessionTracerLogEstablished(session)
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
-#if 1 //TARGET_OS_EMBEDDED
+#if 1
#define IPSECLOGASLMSG(format, args...) plog(ASL_LEVEL_NOTICE, format, ##args);
#else
#define IPSECLOGASLMSG(format, args...) do { \
#include <Security/SecPolicySearch.h>
#endif
#include <CoreFoundation/CoreFoundation.h>
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <Security/SecIdentitySearch.h>
#include <Security/SecKeychain.h>
#include <Security/SecKeychainItem.h>
#include <Security/SecKeychainItemPriv.h>
#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include "plog.h"
#include "debug.h"
#include "misc.h"
CFDictionaryRef persistFind = NULL;
const void *keys_persist[] = { kSecReturnRef, kSecValuePersistentRef, kSecClass,
-#if TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
kSecUseSystemKeychain,
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
};
const void *values_persist[] = { kCFBooleanTrue, persistentCertRef, kSecClassIdentity,
-#if TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
kCFBooleanTrue,
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
};
#define SIG_BUF_SIZE 1024
CFDataRef certData = NULL;
SecIdentityRef identityRef = NULL;
const void *keys_persist[] = { kSecReturnRef, kSecValuePersistentRef, kSecClass,
-#if TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
kSecUseSystemKeychain,
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
};
const void *values_persist[] = { kCFBooleanTrue, persistentCertRef, kSecClassIdentity,
-#if TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
kCFBooleanTrue,
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
};
/* find identity by persistent ref */
case errSecNotAvailable:
return "errSecNotAvailable";
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
case memFullErr:
return "memFullErr";
case paramErr:
return "paramErr";
case unimpErr:
return "unimpErr";
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#ifndef HAVE_OPENSSL
/* SecBase.h: */
#endif
#include <sys/socket.h>
-#include <schedule.h>
+#include "schedule.h"
#if __has_include(<nw/private.h>)
#include <nw/private.h>
#include "vmbuf.h"
#include "racoon_types.h"
-#include <schedule.h>
+#include "schedule.h"
#if __has_include(<nw/private.h>)
#include <nw/private.h>
#else
#ifndef _LOCALCONF_H
#define _LOCALCONF_H
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <vproc.h>
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <dispatch/dispatch.h>
#if __has_include(<nw/private.h>)
#include <nw/private.h>
* is enable, racoon uses old format.
*/
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
vproc_transaction_t vt; /* returned by vproc_transaction_begin */
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
};
#include "crypto_openssl.h"
#include "vendorid.h"
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <sandbox.h>
-#endif // !TARGET_OS_EMBEDDED
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <CoreFoundation/CoreFoundation.h>
{
int error;
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
char *errorbuf;
if (sandbox_init("racoon", SANDBOX_NAMED, &errorbuf) == -1) {
plog(ASL_LEVEL_ERR, "initializing sandbox failed %s", errorbuf);
sandbox_free_error(errorbuf);
return -1;
}
-#endif // !TARGET_OS_EMBEDDED
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
/*
* Check IPSec plist
goto err;
}
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if ( lcconf->vt == NULL){
if (!(lcconf->vt = vproc_transaction_begin(NULL)))
plog(ASL_LEVEL_ERR,
"vproc_transaction_begin returns NULL.\n");
}
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
return 0;
#include <IOKit/IOKitLib.h>
#include <IOKit/pwr_mgt/IOPM.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
#include <IOKit/pwr_mgt/IOPMLibPrivate.h>
-#endif /* !TARGET_OS_EMBEDDED */
+#endif /* !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
#include <IOKit/IOMessage.h>
#include "var.h"
{
struct remoteconf *p;
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
static const char default_idv[] = "macuser@localhost";
static const int default_idv_len = sizeof(default_idv) - 1;
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
TAILQ_FOREACH(p, &rmtree, chain) {
if (ignore_anonymous) {
if (p->remote->ss_family == AF_UNSPEC) /* anonymous */
continue;
}
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
// ignore the default btmm ipv6 config thats always present in racoon.conf
if (p->remote->ss_family == AF_INET6 &&
p->idvtype == IDTYPE_USERFQDN &&
strncmp(p->idv->v, default_idv, p->idv->l) == 0) {
continue;
}
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
return 0;
}
return 1;
#include <vproc_priv.h>
#include <dispatch/dispatch.h>
#include <xpc/xpc.h>
+#include <os/transaction_private.h>
#include "libpfkey.h"
#include <libproc.h>
+#define IKEv1_TRANSACTION "IKEv1_Transaction"
+
extern pid_t racoon_pid;
extern int launchdlaunched;
static void close_session (int);
static NEPolicySessionRef policySession = NULL;
+static os_transaction_t g_ikev1_transaction = NULL;
+
/*
* This is used to (manually) update racoon's launchd keepalive, which is needed because racoon is (mostly)
* launched on demand and for <rdar://problem/8768510> requires a keepalive on dirty/failure exits.
"cannot open %s", pid_file);
}
}
+
+ if (g_ikev1_transaction == NULL) {
+ g_ikev1_transaction = os_transaction_create(IKEv1_TRANSACTION);
+ }
- xpc_transaction_begin();
-
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
// enable keepalive for recovery (from crashes and bad exits... after init)
(void)launchd_update_racoon_keepalive(true);
-#endif // !TARGET_OS_EMBEDDED
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
// Off to the races!
if (!terminated) {
ike_session_flush_all_phase1(false);
close_sockets();
- xpc_transaction_end();
+ if (g_ikev1_transaction != NULL) {
+ os_release(g_ikev1_transaction);
+ g_ikev1_transaction = NULL;
+ }
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
// a clean exit, so disable launchd keepalive
(void)launchd_update_racoon_keepalive(false);
-#endif // !TARGET_OS_EMBEDDED
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
plog(ASL_LEVEL_NOTICE, "racoon shutdown\n");
exit(0);
return;
}
-#if !TARGET_OS_EMBEDDED
+#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (lcconf->vt)
vproc_transaction_end(NULL, lcconf->vt);
-#endif
+#endif // !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
close_session(0);
}
if (lcconf->logfile_param == NULL && logFileStr[0] == 0)
plogresetfile(lcconf->pathinfo[LC_PATHTYPE_LOGFILE]);
-#if TARGET_OS_EMBEDDED
+#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
if (no_remote_configs(TRUE)) {
#if ENABLE_NO_SA_FLUSH
close_session(0);
dying();
#endif /* ENABLE_NO_SA_FLUSH */
}
-#endif
+#endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
break;
* SUCH DAMAGE.
*/
-//#define LION_TEST 1
-
-
#include "config.h"
#include <sys/types.h>
#include <unistd.h>
#endif
#include <launch.h>
-#ifndef LION_TEST
-#include <launch_priv.h>
-#endif
#include <fcntl.h>
#include "var.h"
int
checklaunchd()
{
- launch_data_t checkin_response = NULL;
-#ifdef LION_TEST
- launch_data_t checkin_request = NULL;
-#endif
- launch_data_t sockets_dict, listening_fd_array;
- launch_data_t listening_fd;
- struct sockaddr_storage fdsockaddr;
- socklen_t fdsockaddrlen = sizeof(fdsockaddr);
- int socketct;
- int i;
- int listenerct;
int returnval = 0;
- int fd;
-
- /* check in with launchd */
-#ifdef LION_TEST
- if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
-#else
- if ((checkin_response = launch_socket_service_check_in()) == NULL) {
-#endif
- plog(ASL_LEVEL_ERR,
- "failed to launch_socket_service_check_in.\n");
- goto done;
- }
-#ifdef LION_TEST
- if ((checkin_response = launch_msg(checkin_request)) == NULL) {
- plog(ASL_LEVEL_ERR, "failed to launch_msg.\n");
- goto done;
- }
-#endif
- if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
- plog(ASL_LEVEL_ERR,
- "launch_data_get_type error %d\n",
- launch_data_get_errno(checkin_response));
- goto done;
- }
- if ( (sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS)) == NULL){
- plog(ASL_LEVEL_ERR,
- "failed to launch_data_dict_lookup.\n");
- goto done;
- }
- if ( !(socketct = launch_data_dict_get_count(sockets_dict))){
- plog(ASL_LEVEL_ERR,
- "launch_data_dict_get_count returns no socket defined.\n");
- goto done;
- }
-
- if ( (listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners")) == NULL ){
- plog(ASL_LEVEL_ERR,
- "failed to launch_data_dict_lookup.\n");
- goto done;
+ int *listening_fd_array = NULL;
+ size_t fd_count = 0;
+
+ int result = launch_activate_socket("Listeners", &listening_fd_array, &fd_count);
+ if (result != 0) {
+ plog(ASL_LEVEL_ERR, "failed to launch_activate_socket with error %s.\n", strerror(result));
+ return returnval;
}
- listenerct = launch_data_array_get_count(listening_fd_array);
- for (i = 0; i < listenerct; i++) {
- listening_fd = launch_data_array_get_index(listening_fd_array, i);
- fd = launch_data_get_fd( listening_fd );
- if ( getsockname( fd , (struct sockaddr *)&fdsockaddr, &fdsockaddrlen)){
- continue;
- }
-
- /* Is this the VPN control socket? */
- if ( fdsockaddr.ss_family == AF_UNIX &&
- (!(strcmp(vpncontrolsock_path, ((struct sockaddr_un *)&fdsockaddr)->sun_path))))
- {
- plog(ASL_LEVEL_NOTICE,
- "found launchd socket.\n");
- returnval = fd;
- break;
+
+ if (listening_fd_array != NULL) {
+ if (fd_count > 0) {
+ returnval = listening_fd_array[0];
}
+ free(listening_fd_array);
+ listening_fd_array = NULL;
}
- // TODO: check if we have any leaked fd
- if ( listenerct == i){
- plog(ASL_LEVEL_ERR,
- "failed to find launchd socket\n");
- returnval = 0;
- }
-
-done:
- if (checkin_response)
- launch_data_free(checkin_response);
- return(returnval);
+
+ return returnval;
}
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
SKIP_INSTALL = YES;
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
YACCFLAGS = "$(YACCFLAGS) -d -p__libipsec";
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
YACCFLAGS = "$(YACCFLAGS) -d -p__libipsec";
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
SKIP_INSTALL = YES;
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
WARNING_CFLAGS = "-Wcast-align";
INSTALL_GROUP = wheel;
INSTALL_MODE_FLAG = 555;
INSTALL_PATH = /usr/lib;
+ IS_ZIPPERED = YES;
LEXFLAGS = "$(LEXFLAGS) -P__libipsec";
PRODUCT_NAME = ipsec.A;
WARNING_CFLAGS = "-Wcast-align";