Support HX509_CERTS_UNPROTECT_ALL.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22465 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2008-01-16 14:25:24 +00:00
parent 634a0a544f
commit 18be53daa7

View File

@@ -289,19 +289,25 @@ struct pem_formats {
}; };
struct pem_ctx {
int flags;
struct hx509_collector *c;
};
static int static int
pem_func(hx509_context context, const char *type, pem_func(hx509_context context, const char *type,
const hx509_pem_header *header, const hx509_pem_header *header,
const void *data, size_t len, void *ctx) const void *data, size_t len, void *ctx)
{ {
struct hx509_collector *c = ctx; struct pem_ctx *pem_ctx = (struct pem_ctx*)ctx;
int ret, j; int ret = 0, j;
for (j = 0; j < sizeof(formats)/sizeof(formats[0]); j++) { for (j = 0; j < sizeof(formats)/sizeof(formats[0]); j++) {
const char *q = formats[j].name; const char *q = formats[j].name;
if (strcasecmp(type, q) == 0) { if (strcasecmp(type, q) == 0) {
ret = (*formats[j].func)(context, NULL, c, header, data, len); ret = (*formats[j].func)(context, NULL, pem_ctx->c, header, data, len);
break; if (ret == 0)
break;
} }
} }
if (j == sizeof(formats)/sizeof(formats[0])) { if (j == sizeof(formats)/sizeof(formats[0])) {
@@ -310,6 +316,8 @@ pem_func(hx509_context context, const char *type,
"Found no matching PEM format for %s", type); "Found no matching PEM format for %s", type);
return ret; return ret;
} }
if (ret && (pem_ctx->flags & HX509_CERTS_UNPROTECT_ALL))
return ret;
return 0; return 0;
} }
@@ -324,9 +332,12 @@ file_init_common(hx509_context context,
{ {
char *p, *pnext; char *p, *pnext;
struct ks_file *f = NULL; struct ks_file *f = NULL;
struct hx509_collector *c = NULL;
hx509_private_key *keys = NULL; hx509_private_key *keys = NULL;
int ret; int ret;
struct pem_ctx pem_ctx;
pem_ctx.flags = flags;
pem_ctx.c = NULL;
*data = NULL; *data = NULL;
@@ -361,7 +372,7 @@ file_init_common(hx509_context context,
return 0; return 0;
} }
ret = _hx509_collector_alloc(context, lock, &c); ret = _hx509_collector_alloc(context, lock, &pem_ctx.c);
if (ret) if (ret)
goto out; goto out;
@@ -381,7 +392,7 @@ file_init_common(hx509_context context,
goto out; goto out;
} }
ret = hx509_pem_read(context, f, pem_func, c); ret = hx509_pem_read(context, f, pem_func, &pem_ctx);
fclose(f); fclose(f);
if (ret != 0 && ret != HX509_PARSING_KEY_FAILED) if (ret != 0 && ret != HX509_PARSING_KEY_FAILED)
goto out; goto out;
@@ -397,7 +408,7 @@ file_init_common(hx509_context context,
} }
for (i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) { for (i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) {
ret = (*formats[i].func)(context, p, c, NULL, ptr, length); ret = (*formats[i].func)(context, p, pem_ctx.c, NULL, ptr, length);
if (ret == 0) if (ret == 0)
break; break;
} }
@@ -407,11 +418,11 @@ file_init_common(hx509_context context,
} }
} }
ret = _hx509_collector_collect_certs(context, c, &f->certs); ret = _hx509_collector_collect_certs(context, pem_ctx.c, &f->certs);
if (ret) if (ret)
goto out; goto out;
ret = _hx509_collector_collect_private_keys(context, c, &keys); ret = _hx509_collector_collect_private_keys(context, pem_ctx.c, &keys);
if (ret == 0) { if (ret == 0) {
int i; int i;
@@ -428,8 +439,9 @@ out:
free(f->fn); free(f->fn);
free(f); free(f);
} }
if (c) if (pem_ctx.c)
_hx509_collector_free(c); _hx509_collector_free(pem_ctx.c);
return ret; return ret;
} }