Pass filename to the parse functions and use it in the error messages

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19296 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-12-08 02:35:19 +00:00
parent 76a79be26e
commit c2633ac58b

View File

@@ -98,7 +98,8 @@ find_header(const struct header *headers, const char *header)
*/ */
static int static int
parse_certificate(hx509_context context, struct hx509_collector *c, parse_certificate(hx509_context context, const char *fn,
struct hx509_collector *c,
const struct header *headers, const struct header *headers,
const void *data, size_t len) const void *data, size_t len)
{ {
@@ -109,7 +110,9 @@ parse_certificate(hx509_context context, struct hx509_collector *c,
ret = decode_Certificate(data, len, &t, &size); ret = decode_Certificate(data, len, &t, &size);
if (ret) { if (ret) {
hx509_clear_error_string(context); hx509_set_error_string(context, 0, ret,
"Failed to parse certificate in %s",
fn);
return ret; return ret;
} }
@@ -188,7 +191,8 @@ out:
} }
static int static int
parse_rsa_private_key(hx509_context context, struct hx509_collector *c, parse_rsa_private_key(hx509_context context, const char *fn,
struct hx509_collector *c,
const struct header *headers, const struct header *headers,
const void *data, size_t len) const void *data, size_t len)
{ {
@@ -210,14 +214,15 @@ parse_rsa_private_key(hx509_context context, struct hx509_collector *c,
if (lock == NULL) { if (lock == NULL) {
hx509_set_error_string(context, 0, HX509_ALG_NOT_SUPP, hx509_set_error_string(context, 0, HX509_ALG_NOT_SUPP,
"Failed to get password for " "Failed to get password for "
"password protected file"); "password protected file %s", fn);
return HX509_ALG_NOT_SUPP; return HX509_ALG_NOT_SUPP;
} }
if (strcmp(enc, "4,ENCRYPTED") != 0) { if (strcmp(enc, "4,ENCRYPTED") != 0) {
hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED, hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
"RSA key encrypted in unknown method %s", "RSA key encrypted in unknown method %s "
enc); "in file",
enc, fn);
hx509_clear_error_string(context); hx509_clear_error_string(context);
return HX509_PARSING_KEY_FAILED; return HX509_PARSING_KEY_FAILED;
} }
@@ -331,7 +336,7 @@ parse_rsa_private_key(hx509_context context, struct hx509_collector *c,
struct pem_formats { struct pem_formats {
const char *name; const char *name;
int (*func)(hx509_context, struct hx509_collector *, int (*func)(hx509_context, const char *, struct hx509_collector *,
const struct header *, const void *, size_t); const struct header *, const void *, size_t);
} formats[] = { } formats[] = {
{ "CERTIFICATE", parse_certificate }, { "CERTIFICATE", parse_certificate },
@@ -442,7 +447,8 @@ parse_pem_file(hx509_context context,
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, c, headers, data, len); ret = (*formats[j].func)(context, fn, c,
headers, data, len);
break; break;
} }
} }
@@ -540,7 +546,7 @@ file_init(hx509_context context,
goto out; goto out;
} }
ret = parse_certificate(context, c, NULL, ptr, length); ret = parse_certificate(context, p, c, NULL, ptr, length);
_hx509_unmap_file(ptr, length); _hx509_unmap_file(ptr, length);
if (ret) if (ret)
goto out; goto out;