files: Add simple plugin to load files from file:// URIs
This commit is contained in:
parent
69bb1b8c18
commit
1735d80f38
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2007-2014 Tobias Brunner
|
||||
# Copyright (C) 2007-2015 Tobias Brunner
|
||||
# Copyright (C) 2006-2014 Andreas Steffen
|
||||
# Copyright (C) 2006-2014 Martin Willi
|
||||
# Hochschule fuer Technik Rapperswil
|
||||
|
@ -159,6 +159,7 @@ ARG_DISBL_SET([sshkey], [disable SSH key decoding plugin.])
|
|||
ARG_DISBL_SET([x509], [disable X509 certificate implementation plugin.])
|
||||
# fetcher/resolver plugins
|
||||
ARG_ENABL_SET([curl], [enable CURL fetcher plugin to fetch files via libcurl. Requires libcurl.])
|
||||
ARG_ENABL_SET([files], [enable simple file:// URI fetcher.])
|
||||
ARG_ENABL_SET([ldap], [enable LDAP fetching plugin to fetch files via libldap. Requires openLDAP.])
|
||||
ARG_ENABL_SET([soup], [enable soup fetcher plugin to fetch from HTTP via libsoup. Requires libsoup.])
|
||||
ARG_ENABL_SET([unbound], [enable UNBOUND resolver plugin to perform DNS queries via libunbound. Requires libldns and libunbound.])
|
||||
|
@ -1259,6 +1260,7 @@ ADD_PLUGIN([gcm], [s charon scripts nm cmd])
|
|||
ADD_PLUGIN([ntru], [s charon scripts nm cmd])
|
||||
ADD_PLUGIN([bliss], [s charon pki scripts nm cmd])
|
||||
ADD_PLUGIN([curl], [s charon scepclient pki scripts nm cmd])
|
||||
ADD_PLUGIN([files], [s charon scepclient pki scripts nm cmd])
|
||||
ADD_PLUGIN([winhttp], [s charon pki scripts])
|
||||
ADD_PLUGIN([soup], [s charon pki scripts nm cmd])
|
||||
ADD_PLUGIN([mysql], [s charon pool manager medsrv attest])
|
||||
|
@ -1362,6 +1364,7 @@ AC_SUBST(t_plugins)
|
|||
# -----------------------
|
||||
AM_CONDITIONAL(USE_TEST_VECTORS, test x$test_vectors = xtrue)
|
||||
AM_CONDITIONAL(USE_CURL, test x$curl = xtrue)
|
||||
AM_CONDITIONAL(USE_FILES, test x$files = xtrue)
|
||||
AM_CONDITIONAL(USE_WINHTTP, test x$winhttp = xtrue)
|
||||
AM_CONDITIONAL(USE_UNBOUND, test x$unbound = xtrue)
|
||||
AM_CONDITIONAL(USE_SOUP, test x$soup = xtrue)
|
||||
|
@ -1636,6 +1639,7 @@ AC_CONFIG_FILES([
|
|||
src/libstrongswan/plugins/sshkey/Makefile
|
||||
src/libstrongswan/plugins/pem/Makefile
|
||||
src/libstrongswan/plugins/curl/Makefile
|
||||
src/libstrongswan/plugins/files/Makefile
|
||||
src/libstrongswan/plugins/winhttp/Makefile
|
||||
src/libstrongswan/plugins/unbound/Makefile
|
||||
src/libstrongswan/plugins/soup/Makefile
|
||||
|
|
|
@ -429,6 +429,13 @@ if MONOLITHIC
|
|||
endif
|
||||
endif
|
||||
|
||||
if USE_FILES
|
||||
SUBDIRS += plugins/files
|
||||
if MONOLITHIC
|
||||
libstrongswan_la_LIBADD += plugins/files/libstrongswan-files.la
|
||||
endif
|
||||
endif
|
||||
|
||||
if USE_WINHTTP
|
||||
SUBDIRS += plugins/winhttp
|
||||
if MONOLITHIC
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src/libstrongswan
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(PLUGIN_CFLAGS)
|
||||
|
||||
if MONOLITHIC
|
||||
noinst_LTLIBRARIES = libstrongswan-files.la
|
||||
else
|
||||
plugin_LTLIBRARIES = libstrongswan-files.la
|
||||
endif
|
||||
|
||||
libstrongswan_files_la_SOURCES = \
|
||||
files_plugin.h files_plugin.c files_fetcher.c files_fetcher.h
|
||||
|
||||
libstrongswan_files_la_LDFLAGS = -module -avoid-version
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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 <errno.h>
|
||||
|
||||
#include <library.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
#include "files_fetcher.h"
|
||||
|
||||
typedef struct private_files_fetcher_t private_files_fetcher_t;
|
||||
|
||||
/**
|
||||
* private data of a files_fetcher_t object.
|
||||
*/
|
||||
struct private_files_fetcher_t {
|
||||
|
||||
/**
|
||||
* Public data
|
||||
*/
|
||||
files_fetcher_t public;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*/
|
||||
fetcher_callback_t cb;
|
||||
};
|
||||
|
||||
METHOD(fetcher_t, fetch, status_t,
|
||||
private_files_fetcher_t *this, char *uri, void *userdata)
|
||||
{
|
||||
chunk_t *data;
|
||||
status_t status = FAILED;
|
||||
|
||||
if (this->cb == fetcher_default_callback)
|
||||
{
|
||||
*(chunk_t*)userdata = chunk_empty;
|
||||
}
|
||||
if (!strpfx(uri, "file://"))
|
||||
{
|
||||
return NOT_SUPPORTED;
|
||||
}
|
||||
uri = uri + strlen("file://");
|
||||
data = chunk_map(uri, FALSE);
|
||||
if (!data)
|
||||
{
|
||||
DBG1(DBG_LIB, " opening '%s' failed: %s", uri, strerror(errno));
|
||||
return FAILED;
|
||||
}
|
||||
if (this->cb(userdata, *data))
|
||||
{
|
||||
status = SUCCESS;
|
||||
}
|
||||
chunk_unmap(data);
|
||||
return status;
|
||||
}
|
||||
|
||||
METHOD(fetcher_t, set_option, bool,
|
||||
private_files_fetcher_t *this, fetcher_option_t option, ...)
|
||||
{
|
||||
bool supported = TRUE;
|
||||
va_list args;
|
||||
|
||||
va_start(args, option);
|
||||
switch (option)
|
||||
{
|
||||
case FETCH_CALLBACK:
|
||||
{
|
||||
this->cb = va_arg(args, fetcher_callback_t);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
supported = FALSE;
|
||||
break;
|
||||
}
|
||||
va_end(args);
|
||||
return supported;
|
||||
}
|
||||
|
||||
METHOD(fetcher_t, destroy, void,
|
||||
private_files_fetcher_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
files_fetcher_t *files_fetcher_create()
|
||||
{
|
||||
private_files_fetcher_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.interface = {
|
||||
.fetch = _fetch,
|
||||
.set_option = _set_option,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
.cb = fetcher_default_callback,
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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 files_fetcher files_fetcher
|
||||
* @{ @ingroup files_p
|
||||
*/
|
||||
|
||||
#ifndef FILES_FETCHER_H_
|
||||
#define FILES_FETCHER_H_
|
||||
|
||||
typedef struct files_fetcher_t files_fetcher_t;
|
||||
|
||||
/**
|
||||
* Fetcher implementation loading local files
|
||||
*/
|
||||
struct files_fetcher_t {
|
||||
|
||||
/**
|
||||
* Implements fetcher interface
|
||||
*/
|
||||
fetcher_t interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a files_fetcher instance.
|
||||
*/
|
||||
files_fetcher_t *files_fetcher_create();
|
||||
|
||||
#endif /** FILES_FETCHER_H_ @}*/
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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 "files_plugin.h"
|
||||
#include "files_fetcher.h"
|
||||
|
||||
#include <library.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
typedef struct private_files_plugin_t private_files_plugin_t;
|
||||
|
||||
/**
|
||||
* private data of files_plugin
|
||||
*/
|
||||
struct private_files_plugin_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
files_plugin_t public;
|
||||
};
|
||||
|
||||
METHOD(plugin_t, get_name, char*,
|
||||
private_files_plugin_t *this)
|
||||
{
|
||||
return "files";
|
||||
}
|
||||
|
||||
METHOD(plugin_t, get_features, int,
|
||||
private_files_plugin_t *this, plugin_feature_t *features[])
|
||||
{
|
||||
static plugin_feature_t f[] = {
|
||||
PLUGIN_REGISTER(FETCHER, files_fetcher_create),
|
||||
PLUGIN_PROVIDE(FETCHER, "file://"),
|
||||
};
|
||||
*features = f;
|
||||
return countof(f);
|
||||
}
|
||||
|
||||
METHOD(plugin_t, destroy, void,
|
||||
private_files_plugin_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
plugin_t *files_plugin_create()
|
||||
{
|
||||
private_files_plugin_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.plugin = {
|
||||
.get_name = _get_name,
|
||||
.get_features = _get_features,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return &this->public.plugin;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2015 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 files_p files
|
||||
* @ingroup plugins
|
||||
*
|
||||
* @defgroup files_plugin files_plugin
|
||||
* @{ @ingroup files_p
|
||||
*/
|
||||
|
||||
#ifndef FILES_PLUGIN_H_
|
||||
#define FILES_PLUGIN_H_
|
||||
|
||||
#include <plugins/plugin.h>
|
||||
|
||||
typedef struct files_plugin_t files_plugin_t;
|
||||
|
||||
/**
|
||||
* Plugin implementing fetcher interface loading local files directly.
|
||||
*/
|
||||
struct files_plugin_t {
|
||||
|
||||
/**
|
||||
* implements plugin interface
|
||||
*/
|
||||
plugin_t plugin;
|
||||
};
|
||||
|
||||
#endif /** FILES_PLUGIN_H_ @}*/
|
Loading…
Reference in New Issue