Added Android plugin, currently provides DNS handling on Android
This commit is contained in:
@@ -135,6 +135,7 @@ ARG_ENABL_SET([openssl], [enables the OpenSSL crypto plugin.])
|
|||||||
ARG_ENABL_SET([gcrypt], [enables the libgcrypt plugin.])
|
ARG_ENABL_SET([gcrypt], [enables the libgcrypt plugin.])
|
||||||
ARG_ENABL_SET([agent], [enables the ssh-agent signing plugin.])
|
ARG_ENABL_SET([agent], [enables the ssh-agent signing plugin.])
|
||||||
ARG_ENABL_SET([uci], [enable OpenWRT UCI configuration plugin.])
|
ARG_ENABL_SET([uci], [enable OpenWRT UCI configuration plugin.])
|
||||||
|
ARG_ENABL_SET([android], [enable Android specific plugin.])
|
||||||
ARG_ENABL_SET([nm], [enable NetworkManager plugin.])
|
ARG_ENABL_SET([nm], [enable NetworkManager plugin.])
|
||||||
ARG_ENABL_SET([vstr], [enforce using the Vstr string library to replace glibc-like printf hooks.])
|
ARG_ENABL_SET([vstr], [enforce using the Vstr string library to replace glibc-like printf hooks.])
|
||||||
|
|
||||||
@@ -554,6 +555,11 @@ if test x$uci = xtrue; then
|
|||||||
AC_CHECK_HEADER([uci.h],,[AC_MSG_ERROR([UCI header uci.h not found!])])
|
AC_CHECK_HEADER([uci.h],,[AC_MSG_ERROR([UCI header uci.h not found!])])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test x$android = xtrue; then
|
||||||
|
AC_HAVE_LIBRARY([cutils],[LIBS="$LIBS"],[AC_MSG_ERROR([Android library libcutils not found])])
|
||||||
|
AC_CHECK_HEADER([cutils/properties.h],,[AC_MSG_ERROR([Android header cutils/properties.h not found!])])
|
||||||
|
fi
|
||||||
|
|
||||||
if test x$nm = xtrue; then
|
if test x$nm = xtrue; then
|
||||||
PKG_CHECK_EXISTS([libnm-glib],
|
PKG_CHECK_EXISTS([libnm-glib],
|
||||||
[PKG_CHECK_MODULES(nm, [NetworkManager gthread-2.0 libnm-glib libnm-glib-vpn])],
|
[PKG_CHECK_MODULES(nm, [NetworkManager gthread-2.0 libnm-glib libnm-glib-vpn])],
|
||||||
@@ -752,6 +758,7 @@ AM_CONDITIONAL(USE_MEDSRV, test x$medsrv = xtrue)
|
|||||||
AM_CONDITIONAL(USE_MEDCLI, test x$medcli = xtrue)
|
AM_CONDITIONAL(USE_MEDCLI, test x$medcli = xtrue)
|
||||||
AM_CONDITIONAL(USE_NM, test x$nm = xtrue)
|
AM_CONDITIONAL(USE_NM, test x$nm = xtrue)
|
||||||
AM_CONDITIONAL(USE_UCI, test x$uci = xtrue)
|
AM_CONDITIONAL(USE_UCI, test x$uci = xtrue)
|
||||||
|
AM_CONDITIONAL(USE_ANDROID, test x$android = xtrue)
|
||||||
AM_CONDITIONAL(USE_SMP, test x$smp = xtrue)
|
AM_CONDITIONAL(USE_SMP, test x$smp = xtrue)
|
||||||
AM_CONDITIONAL(USE_SQL, test x$sql = xtrue)
|
AM_CONDITIONAL(USE_SQL, test x$sql = xtrue)
|
||||||
AM_CONDITIONAL(USE_UPDOWN, test x$updown = xtrue)
|
AM_CONDITIONAL(USE_UPDOWN, test x$updown = xtrue)
|
||||||
@@ -874,6 +881,7 @@ AC_OUTPUT(
|
|||||||
src/charon/plugins/medcli/Makefile
|
src/charon/plugins/medcli/Makefile
|
||||||
src/charon/plugins/nm/Makefile
|
src/charon/plugins/nm/Makefile
|
||||||
src/charon/plugins/uci/Makefile
|
src/charon/plugins/uci/Makefile
|
||||||
|
src/charon/plugins/android/Makefile
|
||||||
src/charon/plugins/stroke/Makefile
|
src/charon/plugins/stroke/Makefile
|
||||||
src/charon/plugins/updown/Makefile
|
src/charon/plugins/updown/Makefile
|
||||||
src/charon/plugins/attr/Makefile
|
src/charon/plugins/attr/Makefile
|
||||||
|
|||||||
@@ -261,6 +261,11 @@ if USE_RESOLVE
|
|||||||
PLUGINS += resolve
|
PLUGINS += resolve
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if USE_ANDROID
|
||||||
|
SUBDIRS += plugins/android
|
||||||
|
PLUGINS += android
|
||||||
|
endif
|
||||||
|
|
||||||
if USE_UCI
|
if USE_UCI
|
||||||
SUBDIRS += plugins/uci
|
SUBDIRS += plugins/uci
|
||||||
PLUGINS += uci
|
PLUGINS += uci
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
|
||||||
|
|
||||||
|
AM_CFLAGS = -rdynamic
|
||||||
|
|
||||||
|
plugin_LTLIBRARIES = libstrongswan-android.la
|
||||||
|
|
||||||
|
libstrongswan_android_la_SOURCES = \
|
||||||
|
android_plugin.c android_plugin.h \
|
||||||
|
android_handler.c android_handler.h
|
||||||
|
|
||||||
|
libstrongswan_android_la_LDFLAGS = -module -avoid-version
|
||||||
|
libstrongswan_android_la_LIBADD = -lcutils
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mipv4_handler.h"
|
||||||
|
|
||||||
|
#include <utils/linked_list.h>
|
||||||
|
|
||||||
|
#include <cutils/properties.h>
|
||||||
|
|
||||||
|
typedef struct private_mipv4_handler_t private_mipv4_handler_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private data of an mipv4_handler_t object.
|
||||||
|
*/
|
||||||
|
struct private_mipv4_handler_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public mipv4_handler_t interface.
|
||||||
|
*/
|
||||||
|
mipv4_handler_t public;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of registered DNS servers
|
||||||
|
*/
|
||||||
|
linked_list_t *dns;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Struct to store a pair of old and installed DNS servers
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
/** installed dns server */
|
||||||
|
host_t *dns;
|
||||||
|
/** old dns server */
|
||||||
|
host_t *old;
|
||||||
|
} dns_pair_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy a pair of old and installed DNS servers
|
||||||
|
*/
|
||||||
|
void destroy_dns_pair(dns_pair_t *this)
|
||||||
|
{
|
||||||
|
DESTROY_IF(this->dns);
|
||||||
|
DESTROY_IF(this->old);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter pairs of DNS servers
|
||||||
|
*/
|
||||||
|
bool filter_dns_pair(void *data, dns_pair_t **in, host_t **out)
|
||||||
|
{
|
||||||
|
*out = (*in)->dns;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read DNS server property with a given index
|
||||||
|
*/
|
||||||
|
host_t *get_dns_server(int index)
|
||||||
|
{
|
||||||
|
host_t *dns = NULL;
|
||||||
|
char key[10], value[PROPERTY_VALUE_MAX];
|
||||||
|
|
||||||
|
if (snprintf(key, sizeof(key), "net.dns%d", index) >= sizeof(key))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property_get(key, value, NULL) > 0)
|
||||||
|
{
|
||||||
|
dns = host_create_from_string(value, 0);
|
||||||
|
}
|
||||||
|
return dns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DNS server property with a given index
|
||||||
|
*/
|
||||||
|
bool set_dns_server(int index, host_t *dns)
|
||||||
|
{
|
||||||
|
char key[10], value[PROPERTY_VALUE_MAX];
|
||||||
|
|
||||||
|
if (snprintf(key, sizeof(key), "net.dns%d", index) >= sizeof(key))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dns)
|
||||||
|
{
|
||||||
|
if (snprintf(value, sizeof(value), "%H", dns) >= sizeof(value))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property_set(key, value) != 0)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(attribute_handler_t, handle, bool,
|
||||||
|
private_mipv4_handler_t *this, identification_t *id,
|
||||||
|
configuration_attribute_type_t type, chunk_t data)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case INTERNAL_IP4_DNS:
|
||||||
|
{
|
||||||
|
host_t *dns;
|
||||||
|
dns_pair_t *pair;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
dns = host_create_from_chunk(AF_INET, data, 0);
|
||||||
|
if (dns)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
this->dns->insert_last(this->dns, pair);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(attribute_handler_t, release, void,
|
||||||
|
private_mipv4_handler_t *this, identification_t *server,
|
||||||
|
configuration_attribute_type_t type, chunk_t data)
|
||||||
|
{
|
||||||
|
if (type == INTERNAL_IP4_DNS)
|
||||||
|
{
|
||||||
|
enumerator_t *enumerator;
|
||||||
|
dns_pair_t *pair;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
enumerator = this->dns->create_enumerator(this->dns);
|
||||||
|
for (index = 1; enumerator->enumerate(enumerator, &pair); index++)
|
||||||
|
{
|
||||||
|
if (chunk_equals(pair->dns->get_address(pair->dns), data))
|
||||||
|
{
|
||||||
|
this->dns->remove_at(this->dns, enumerator);
|
||||||
|
set_dns_server(index, pair->old);
|
||||||
|
destroy_dns_pair(pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(enumerator_t, enumerate_dns, bool,
|
||||||
|
enumerator_t *this, configuration_attribute_type_t *type, chunk_t *data)
|
||||||
|
{
|
||||||
|
*type = INTERNAL_IP4_DNS;
|
||||||
|
*data = chunk_empty;
|
||||||
|
/* stop enumeration */
|
||||||
|
this->enumerate = (void*)return_false;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(attribute_handler_t, create_attribute_enumerator, enumerator_t *,
|
||||||
|
mipv4_handler_t *this, identification_t *id, host_t *vip)
|
||||||
|
{
|
||||||
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
|
INIT(enumerator,
|
||||||
|
.enumerate = (void*)_enumerate_dns,
|
||||||
|
.destroy = (void*)free,
|
||||||
|
);
|
||||||
|
return enumerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(mipv4_handler_t, destroy, void,
|
||||||
|
private_mipv4_handler_t *this)
|
||||||
|
{
|
||||||
|
this->dns->destroy_function(this->dns, (void*)destroy_dns_pair);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See header
|
||||||
|
*/
|
||||||
|
mipv4_handler_t *mipv4_handler_create()
|
||||||
|
{
|
||||||
|
private_mipv4_handler_t *this;
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.public = {
|
||||||
|
.handler = {
|
||||||
|
.handle = _handle,
|
||||||
|
.release = _release,
|
||||||
|
.create_attribute_enumerator = _create_attribute_enumerator,
|
||||||
|
},
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.dns = linked_list_create(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return &this->public;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup android_handler android_handler
|
||||||
|
* @{ @ingroup android
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_HANDLER_H_
|
||||||
|
#define ANDROID_HANDLER_H_
|
||||||
|
|
||||||
|
#include <attributes/attribute_handler.h>
|
||||||
|
|
||||||
|
typedef struct android_handler_t android_handler_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Android specific DNS attribute handler.
|
||||||
|
*/
|
||||||
|
struct android_handler_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements attribute_handler_t.
|
||||||
|
*/
|
||||||
|
attribute_handler_t handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy a android_handler_t.
|
||||||
|
*/
|
||||||
|
void (*destroy)(android_handler_t *this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a android_handler instance.
|
||||||
|
*/
|
||||||
|
android_handler_t *android_handler_create();
|
||||||
|
|
||||||
|
#endif /** ANDROID_HANDLER_H_ @}*/
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "android_plugin.h"
|
||||||
|
#include "android_handler.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
#include <daemon.h>
|
||||||
|
|
||||||
|
typedef struct private_android_plugin_t private_android_plugin_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private data of an android_plugin_t object.
|
||||||
|
*/
|
||||||
|
struct private_android_plugin_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public android_plugin_t interface.
|
||||||
|
*/
|
||||||
|
android_plugin_t public;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Android specific DNS handler
|
||||||
|
*/
|
||||||
|
android_handler_t *handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
METHOD(plugin_t, destroy, void,
|
||||||
|
private_android_plugin_t *this)
|
||||||
|
{
|
||||||
|
lib->attributes->remove_handler(lib->attributes, &this->handler->handler);
|
||||||
|
this->handler->destroy(this->handler);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See header
|
||||||
|
*/
|
||||||
|
plugin_t *plugin_create()
|
||||||
|
{
|
||||||
|
private_android_plugin_t *this;
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.public.plugin = {
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.handler = android_handler_create(),
|
||||||
|
);
|
||||||
|
|
||||||
|
lib->attributes->add_handler(lib->attributes, &this->handler->handler);
|
||||||
|
|
||||||
|
return &this->public.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup android android
|
||||||
|
* @ingroup cplugins
|
||||||
|
*
|
||||||
|
* @defgroup android_plugin android_plugin
|
||||||
|
* @{ @ingroup android
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANDROID_PLUGIN_H_
|
||||||
|
#define ANDROID_PLUGIN_H_
|
||||||
|
|
||||||
|
#include <plugins/plugin.h>
|
||||||
|
|
||||||
|
typedef struct android_plugin_t android_plugin_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin providing functionality specific to the Android platform.
|
||||||
|
*/
|
||||||
|
struct android_plugin_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements plugin interface.
|
||||||
|
*/
|
||||||
|
plugin_t plugin;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the android_plugin instance.
|
||||||
|
*/
|
||||||
|
plugin_t *plugin_create();
|
||||||
|
|
||||||
|
#endif /** ANDROID_PLUGIN_H_ @}*/
|
||||||
Reference in New Issue
Block a user