return cred;
}
+/**
+ * Check if a file has an absolute path, if not prepend a base directory
+ */
+static void make_absolute(char *buf, size_t bufsize, char *base, char *file)
+{
+ if (*file == '/')
+ {
+ snprintf(buf, bufsize, "%s", file);
+ }
+ else
+ {
+ snprintf(buf, bufsize, "%s/%s", base, file);
+ }
+}
+
METHOD(stroke_cred_t, load_ca, certificate_t*,
private_stroke_cred_t *this, char *filename)
{
}
else
{
- if (*filename == '/')
- {
- snprintf(path, sizeof(path), "%s", filename);
- }
- else
- {
- snprintf(path, sizeof(path), "%s/%s", CA_CERTIFICATE_DIR, filename);
- }
-
+ make_absolute(path, sizeof(path), CA_CERTIFICATE_DIR, filename);
if (this->force_ca_cert)
{ /* we treat this certificate as a CA certificate even if it has no
* CA basic constraint */
}
else
{
- if (*filename == '/')
- {
- snprintf(path, sizeof(path), "%s", filename);
- }
- else
- {
- snprintf(path, sizeof(path), "%s/%s", CERTIFICATE_DIR, filename);
- }
-
+ make_absolute(path, sizeof(path), CERTIFICATE_DIR, filename);
cert = lib->creds->create(lib->creds,
CRED_CERTIFICATE, CERT_ANY,
BUILD_FROM_FILE, path,
}
else
{
- if (*filename == '/')
- {
- snprintf(path, sizeof(path), "%s", filename);
- }
- else
- {
- snprintf(path, sizeof(path), "%s/%s", CERTIFICATE_DIR, filename);
- }
-
+ make_absolute(path, sizeof(path), CERTIFICATE_DIR, filename);
cert = lib->creds->create(lib->creds,
CRED_CERTIFICATE, CERT_TRUSTED_PUBKEY,
BUILD_FROM_FILE, path,
certificate_t *cert;
char path[PATH_MAX];
- if (*filename == '/')
- {
- snprintf(path, sizeof(path), "%s", filename);
- }
- else
- {
- snprintf(path, sizeof(path), "%s/%s", CERTIFICATE_DIR, filename);
- }
+ make_absolute(path, sizeof(path), CERTIFICATE_DIR, filename);
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_CGA_PARAMS,
BUILD_FROM_FILE, path, BUILD_END);
if (cert)