summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/android
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
committerYves-Alexis Perez <corsac@corsac.net>2012-06-28 21:16:07 +0200
commitb34738ed08c2227300d554b139e2495ca5da97d6 (patch)
tree62f33b52820f2e49f0e53c0f8c636312037c8054 /src/libcharon/plugins/android
parent0a9d51a49042a68daa15b0c74a2b7f152f52606b (diff)
downloadvyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.tar.gz
vyos-strongswan-b34738ed08c2227300d554b139e2495ca5da97d6.zip
Imported Upstream version 4.6.4
Diffstat (limited to 'src/libcharon/plugins/android')
-rw-r--r--src/libcharon/plugins/android/Makefile.in7
-rw-r--r--src/libcharon/plugins/android/android_handler.c36
-rw-r--r--src/libcharon/plugins/android/android_handler.h6
-rw-r--r--src/libcharon/plugins/android/android_logger.c5
-rw-r--r--src/libcharon/plugins/android/android_plugin.c11
5 files changed, 42 insertions, 23 deletions
diff --git a/src/libcharon/plugins/android/Makefile.in b/src/libcharon/plugins/android/Makefile.in
index 08248da12..50e5f638e 100644
--- a/src/libcharon/plugins/android/Makefile.in
+++ b/src/libcharon/plugins/android/Makefile.in
@@ -195,6 +195,9 @@ am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
+attest_plugins = @attest_plugins@
+axis2c_CFLAGS = @axis2c_CFLAGS@
+axis2c_LIBS = @axis2c_LIBS@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
@@ -203,6 +206,7 @@ build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
c_plugins = @c_plugins@
+clearsilver_LIBS = @clearsilver_LIBS@
datadir = @datadir@
datarootdir = @datarootdir@
dbusservicedir = @dbusservicedir@
@@ -219,11 +223,13 @@ host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
+imcvdir = @imcvdir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
ipsecdir = @ipsecdir@
ipsecgroup = @ipsecgroup@
+ipseclibdir = @ipseclibdir@
ipsecuser = @ipsecuser@
libcharon_plugins = @libcharon_plugins@
libdir = @libdir@
@@ -267,6 +273,7 @@ sharedstatedir = @sharedstatedir@
soup_CFLAGS = @soup_CFLAGS@
soup_LIBS = @soup_LIBS@
srcdir = @srcdir@
+starter_plugins = @starter_plugins@
strongswan_conf = @strongswan_conf@
sysconfdir = @sysconfdir@
systemdsystemunitdir = @systemdsystemunitdir@
diff --git a/src/libcharon/plugins/android/android_handler.c b/src/libcharon/plugins/android/android_handler.c
index ec3ff7a51..a53962f16 100644
--- a/src/libcharon/plugins/android/android_handler.c
+++ b/src/libcharon/plugins/android/android_handler.c
@@ -1,6 +1,6 @@
/*
+ * Copyright (C) 2010-2011 Tobias Brunner
* Copyright (C) 2010 Martin Willi
- * Copyright (C) 2010 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -36,9 +36,20 @@ struct private_android_handler_t {
* List of registered DNS servers
*/
linked_list_t *dns;
+
+ /**
+ * Whether the VPN frontend is used
+ */
+ bool frontend;
};
/**
+ * Prefixes to be used when installing DNS servers
+ */
+#define DNS_PREFIX_DEFAULT "net"
+#define DNS_PREFIX_FRONTEND "vpn"
+
+/**
* Struct to store a pair of old and installed DNS servers
*/
typedef struct {
@@ -70,12 +81,13 @@ bool filter_dns_pair(void *data, dns_pair_t **in, host_t **out)
/**
* Read DNS server property with a given index
*/
-host_t *get_dns_server(int index)
+host_t *get_dns_server(private_android_handler_t *this, int index)
{
host_t *dns = NULL;
- char key[10], value[PROPERTY_VALUE_MAX];
+ char key[10], value[PROPERTY_VALUE_MAX],
+ *prefix = this->frontend ? DNS_PREFIX_FRONTEND : DNS_PREFIX_DEFAULT;
- if (snprintf(key, sizeof(key), "vpn.dns%d", index) >= sizeof(key))
+ if (snprintf(key, sizeof(key), "%s.dns%d", prefix, index) >= sizeof(key))
{
return NULL;
}
@@ -90,11 +102,12 @@ host_t *get_dns_server(int index)
/**
* Set DNS server property with a given index
*/
-bool set_dns_server(int index, host_t *dns)
+bool set_dns_server(private_android_handler_t *this, int index, host_t *dns)
{
- char key[10], value[PROPERTY_VALUE_MAX];
+ char key[10], value[PROPERTY_VALUE_MAX],
+ *prefix = this->frontend ? DNS_PREFIX_FRONTEND : DNS_PREFIX_DEFAULT;
- if (snprintf(key, sizeof(key), "vpn.dns%d", index) >= sizeof(key))
+ if (snprintf(key, sizeof(key), "%s.dns%d", prefix, index) >= sizeof(key))
{
return FALSE;
}
@@ -136,8 +149,8 @@ METHOD(attribute_handler_t, handle, bool,
pair = malloc_thing(dns_pair_t);
pair->dns = dns;
index = this->dns->get_count(this->dns) + 1;
- pair->old = get_dns_server(index);
- set_dns_server(index, dns);
+ pair->old = get_dns_server(this, index);
+ set_dns_server(this, index, dns);
this->dns->insert_last(this->dns, pair);
return TRUE;
}
@@ -164,7 +177,7 @@ METHOD(attribute_handler_t, release, void,
if (chunk_equals(pair->dns->get_address(pair->dns), data))
{
this->dns->remove_at(this->dns, enumerator);
- set_dns_server(index, pair->old);
+ set_dns_server(this, index, pair->old);
destroy_dns_pair(pair);
}
}
@@ -204,7 +217,7 @@ METHOD(android_handler_t, destroy, void,
/**
* See header
*/
-android_handler_t *android_handler_create()
+android_handler_t *android_handler_create(bool frontend)
{
private_android_handler_t *this;
@@ -218,6 +231,7 @@ android_handler_t *android_handler_create()
.destroy = _destroy,
},
.dns = linked_list_create(),
+ .frontend = frontend,
);
return &this->public;
diff --git a/src/libcharon/plugins/android/android_handler.h b/src/libcharon/plugins/android/android_handler.h
index af620505b..0170958ee 100644
--- a/src/libcharon/plugins/android/android_handler.h
+++ b/src/libcharon/plugins/android/android_handler.h
@@ -1,6 +1,6 @@
/*
+ * Copyright (C) 2010-2011 Tobias Brunner
* Copyright (C) 2010 Martin Willi
- * Copyright (C) 2010 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -44,7 +44,9 @@ struct android_handler_t {
/**
* Create a android_handler instance.
+ *
+ * @param frontend TRUE if the VPN frontend is used
*/
-android_handler_t *android_handler_create();
+android_handler_t *android_handler_create(bool frontend);
#endif /** ANDROID_HANDLER_H_ @}*/
diff --git a/src/libcharon/plugins/android/android_logger.c b/src/libcharon/plugins/android/android_logger.c
index 43c56e656..f7624b2c7 100644
--- a/src/libcharon/plugins/android/android_logger.c
+++ b/src/libcharon/plugins/android/android_logger.c
@@ -47,18 +47,19 @@ METHOD(listener_t, log_, bool,
{
if (level <= this->level)
{
+ int prio = level > 1 ? ANDROID_LOG_DEBUG : ANDROID_LOG_INFO;
char sgroup[16], buffer[8192];
char *current = buffer, *next;
snprintf(sgroup, sizeof(sgroup), "%N", debug_names, group);
vsnprintf(buffer, sizeof(buffer), format, args);
while (current)
- { /* log each line seperately */
+ { /* log each line separately */
next = strchr(current, '\n');
if (next)
{
*(next++) = '\0';
}
- __android_log_print(ANDROID_LOG_INFO, "charon", "%.2d[%s] %s\n",
+ __android_log_print(prio, "charon", "%.2d[%s] %s\n",
thread, sgroup, current);
current = next;
}
diff --git a/src/libcharon/plugins/android/android_plugin.c b/src/libcharon/plugins/android/android_plugin.c
index 54a7017a1..091f34a8e 100644
--- a/src/libcharon/plugins/android/android_plugin.c
+++ b/src/libcharon/plugins/android/android_plugin.c
@@ -92,21 +92,16 @@ plugin_t *android_plugin_create()
},
},
.logger = android_logger_create(),
- .handler = android_handler_create(),
.creds = android_creds_create(),
);
+ this->service = android_service_create(this->creds);
+ this->handler = android_handler_create(this->service != NULL);
+
charon->bus->add_listener(charon->bus, &this->logger->listener);
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
- this->service = android_service_create(this->creds);
- if (!this->service)
- {
- destroy(this);
- return NULL;
- }
-
return &this->public.plugin;
}