aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-10-29 11:47:25 +0200
committerMartin Willi <martin@revosec.ch>2011-01-05 16:45:40 +0100
commita13c1d649f686347d4512580faa51a3e21a6cf0c (patch)
tree0d8078be72434acffaa90b7fc9abf70d0f4a12c0
parentd1041fa463c14339b439ba24d86e678b8c37d00a (diff)
downloadstrongswan-a13c1d649f686347d4512580faa51a3e21a6cf0c.tar.bz2
strongswan-a13c1d649f686347d4512580faa51a3e21a6cf0c.tar.xz
Load certificates from both, suite and test config
-rw-r--r--src/conftest/conftest.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/conftest/conftest.c b/src/conftest/conftest.c
index 9db59b053..34051977b 100644
--- a/src/conftest/conftest.c
+++ b/src/conftest/conftest.c
@@ -89,21 +89,25 @@ static bool load_configs(char *suite_file, char *test_file)
/**
* Load certificates from the confiuguration file
*/
-static bool load_certs()
+static bool load_certs(settings_t *settings, char *dir)
{
enumerator_t *enumerator;
- char *key, *value;
+ char *key, *value, wd[PATH_MAX];
certificate_t *cert;
- if (chdir(conftest->suite_dir) != 0)
+ if (getcwd(wd, sizeof(wd)) == NULL)
{
- fprintf(stderr, "opening suite directory '%s' failed",
- conftest->suite_dir);
+ fprintf(stderr, "getting cwd failed: %s\n", strerror(errno));
+ return FALSE;
+ }
+ if (chdir(dir) != 0)
+ {
+ fprintf(stderr, "opening directory '%s' failed: %s\n",
+ dir, strerror(errno));
return FALSE;
}
- enumerator = conftest->suite->create_key_value_enumerator(
- conftest->suite, "certs.trusted");
+ enumerator = settings->create_key_value_enumerator(settings, "certs.trusted");
while (enumerator->enumerate(enumerator, &key, &value))
{
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
@@ -119,8 +123,7 @@ static bool load_certs()
}
enumerator->destroy(enumerator);
- enumerator = conftest->suite->create_key_value_enumerator(
- conftest->suite, "certs.untrusted");
+ enumerator = settings->create_key_value_enumerator(settings, "certs.untrusted");
while (enumerator->enumerate(enumerator, &key, &value))
{
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
@@ -136,6 +139,12 @@ static bool load_certs()
}
enumerator->destroy(enumerator);
+ if (chdir(wd) != 0)
+ {
+ fprintf(stderr, "opening directory '%s' failed: %s\n",
+ wd, strerror(errno));
+ return FALSE;
+ }
return TRUE;
}
@@ -292,7 +301,8 @@ int main(int argc, char *argv[])
{
return 1;
}
- if (!load_certs(suite_file))
+ if (!load_certs(conftest->suite, suite_file) ||
+ !load_certs(conftest->test, test_file))
{
return 1;
}