pass NULL to library_init() to load settings from default file

This commit is contained in:
Martin Willi 2009-09-08 20:01:13 +02:00
parent 5b03a350fc
commit 356b2b2780
22 changed files with 51 additions and 56 deletions

View file

@ -1,7 +1,6 @@
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = \
-DPLUGINS="\"${libstrongswan_plugins}\"" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\"
-DPLUGINS="\"${libstrongswan_plugins}\""
noinst_PROGRAMS = bin2array bin2sql id2sql key2keyid keyid2sql \
thread_analysis dh_speed pubkey_speed

View file

@ -101,7 +101,7 @@ int main(int argc, char *argv[])
usage();
}
library_init(STRONGSWAN_CONF);
library_init(NULL);
lib->plugins->load(lib->plugins, NULL, argv[1]);
atexit(library_deinit);

View file

@ -59,7 +59,7 @@ int main(int argc, char *argv[])
usage();
}
library_init(STRONGSWAN_CONF);
library_init(NULL);
lib->plugins->load(lib->plugins, NULL, argv[1]);
atexit(library_deinit);

View file

@ -105,8 +105,7 @@ credentials/credential_set.h
INCLUDES = -I${linux_headers} -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
AM_CFLAGS = -rdynamic \
-DIPSEC_DIR=\"${ipsecdir}\" \
-DIPSEC_PIDDIR=\"${piddir}\" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\"
-DIPSEC_PIDDIR=\"${piddir}\"
charon_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lpthread -lm $(DLLIB) $(SOCKLIB)
# compile options

View file

@ -684,7 +684,7 @@ int main(int argc, char *argv[])
dbg = dbg_stderr;
/* initialize library */
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
library_deinit();
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);

View file

@ -2,7 +2,6 @@
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
AM_CFLAGS = -rdynamic \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DPLUGINS=\""${libstrongswan_plugins}\""
plugin_LTLIBRARIES = libstrongswan-sql.la

View file

@ -624,7 +624,7 @@ int main(int argc, char *argv[])
atexit(library_deinit);
/* initialize library */
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
}

View file

@ -54,7 +54,8 @@ libstrongswan_la_LIBADD = -lpthread $(DLLIB) $(BTLIB) $(SOCKLIB) $(RTLIB)
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = \
-DIPSEC_DIR=\"${ipsecdir}\" \
-DPLUGINDIR=\"${plugindir}\"
-DPLUGINDIR=\"${plugindir}\" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\"
if USE_LEAK_DETECTIVE
AM_CFLAGS += -DLEAK_DETECTIVE

View file

@ -484,8 +484,12 @@ static void destroy(private_settings_t *this)
*/
settings_t *settings_create(char *file)
{
private_settings_t *this = malloc_thing(private_settings_t);
private_settings_t *this;
char *pos;
FILE *fd;
int len;
this = malloc_thing(private_settings_t);
this->public.get_str = (char*(*)(settings_t*, char *key, char* def, ...))get_str;
this->public.get_int = (int(*)(settings_t*, char *key, int def, ...))get_int;
this->public.get_time = (u_int32_t(*)(settings_t*, char *key, u_int32_t def, ...))get_time;
@ -496,39 +500,35 @@ settings_t *settings_create(char *file)
this->top = NULL;
this->text = NULL;
if (file)
if (file == NULL)
{
FILE *fd;
int len;
char *pos;
file = STRONGSWAN_CONF;
}
fd = fopen(file, "r");
if (fd == NULL)
{
DBG1("'%s' does not exist or is not readable", file);
return &this->public;
}
fseek(fd, 0, SEEK_END);
len = ftell(fd);
rewind(fd);
this->text = malloc(len + 1);
this->text[len] = '\0';
if (fread(this->text, 1, len, fd) != len)
{
free(this->text);
this->text = NULL;
return &this->public;
}
fclose(fd);
fd = fopen(file, "r");
if (fd == NULL)
{
DBG1("'%s' does not exist or is not readable", file);
return &this->public;
}
fseek(fd, 0, SEEK_END);
len = ftell(fd);
rewind(fd);
this->text = malloc(len + 1);
this->text[len] = '\0';
if (fread(this->text, 1, len, fd) != len)
{
free(this->text);
this->text = NULL;
return &this->public;
}
fclose(fd);
pos = this->text;
this->top = parse_section(&pos, NULL);
if (this->top == NULL)
{
free(this->text);
this->text = NULL;
return &this->public;
}
pos = this->text;
this->top = parse_section(&pos, NULL);
if (this->top == NULL)
{
free(this->text);
this->text = NULL;
}
return &this->public;
}

View file

@ -110,7 +110,10 @@ struct settings_t {
};
/**
* Load setings from a file.
* Load settings from a file.
*
* @param file file to read settings from, NULL for default
* @return settings object
*/
settings_t *settings_create(char *file);

View file

@ -14,7 +14,6 @@ manager_fcgi_LDADD = $(top_builddir)/src/libfast/libfast.la ${xml_LIBS}
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libfast ${xml_CFLAGS}
AM_CFLAGS = -rdynamic \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DIPSECDIR=\"${ipsecdir}\" \
-DIPSEC_PIDDIR=\"${piddir}\" \
-DPLUGINS=\""${libstrongswan_plugins}\""

View file

@ -34,7 +34,7 @@ int main (int arc, char *argv[])
bool debug;
int threads, timeout;
library_init(STRONGSWAN_CONF);
library_init(NULL);
if (!lib->plugins->load(lib->plugins, NULL,
lib->settings->get_str(lib->settings, "manager.load", PLUGINS)))
{

View file

@ -11,7 +11,6 @@ medsrv_fcgi_LDADD = $(top_builddir)/src/libfast/libfast.la
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libfast
AM_CFLAGS = -rdynamic \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DIPSECDIR=\"${ipsecdir}\" \
-DIPSEC_PIDDIR=\"${piddir}\" \
-DPLUGINS=\""${libstrongswan_plugins}\""

View file

@ -33,7 +33,7 @@ int main(int arc, char *argv[])
char *uri;
int timeout, threads;
library_init(STRONGSWAN_CONF);
library_init(NULL);
if (!lib->plugins->load(lib->plugins, NULL,
lib->settings->get_str(lib->settings, "medsrv.load", PLUGINS)))
{

View file

@ -5,7 +5,6 @@ dist_man_MANS = openac.8
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = \
-DIPSEC_CONFDIR=\"${sysconfdir}\" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DPLUGINS=\""${libstrongswan_plugins}\""
openac_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la

View file

@ -221,7 +221,7 @@ int main(int argc, char **argv)
/* initialize library */
atexit(library_deinit);
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
}

View file

@ -7,5 +7,4 @@ pki_SOURCES = pki.c pki.h command.c command.h \
pki_LDADD = $(top_builddir)/src/libstrongswan/libstrongswan.la
INCLUDES = -I$(top_srcdir)/src/libstrongswan
AM_CFLAGS = \
-DPLUGINS=\""${libstrongswan_plugins}\"" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\"
-DPLUGINS=\""${libstrongswan_plugins}\""

View file

@ -79,7 +79,7 @@ hash_algorithm_t get_digest(char *name)
int main(int argc, char *argv[])
{
atexit(library_deinit);
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
}

View file

@ -69,7 +69,6 @@ AM_CFLAGS = \
-DIPSEC_PIDDIR=\"${piddir}\" \
-DSHARED_SECRETS_FILE=\"${confdir}/ipsec.secrets\" \
-DPLUGINS=\""${pluto_plugins}\"" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DPKCS11_DEFAULT_LIB=\"${default_pkcs11}\" \
-DKERNEL26_SUPPORT -DKERNEL26_HAS_KAME_DUPLICATES \
-DPLUTO -DKLIPS -DDEBUG

View file

@ -261,7 +261,7 @@ int main(int argc, char **argv)
#endif /* CAPABILITIES */
/* initialize library and optionsfrom */
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
library_deinit();
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);

View file

@ -18,7 +18,6 @@ INCLUDES = \
AM_CFLAGS = \
-DIPSEC_CONFDIR=\"${sysconfdir}\" \
-DPLUGINS=\""${pluto_plugins}\"" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DDEBUG -DNO_PLUTO
LIBSTRONGSWANBUILDDIR=$(top_builddir)/src/libstrongswan

View file

@ -387,7 +387,7 @@ int main(int argc, char **argv)
log_to_stderr = TRUE;
/* initialize library */
if (!library_init(STRONGSWAN_CONF))
if (!library_init(NULL))
{
library_deinit();
exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);