summaryrefslogtreecommitdiff
path: root/trust
diff options
context:
space:
mode:
Diffstat (limited to 'trust')
-rw-r--r--trust/anchor.c2
-rw-r--r--trust/parser.c3
-rw-r--r--trust/parser.h1
-rw-r--r--trust/save.c14
-rw-r--r--trust/tests/frob-cert.c2
-rw-r--r--trust/tests/test-module.c4
-rw-r--r--trust/tests/test-parser.c20
-rw-r--r--trust/tests/test-token.c12
-rw-r--r--trust/token.c2
9 files changed, 27 insertions, 33 deletions
diff --git a/trust/anchor.c b/trust/anchor.c
index fe46416..6620211 100644
--- a/trust/anchor.c
+++ b/trust/anchor.c
@@ -184,7 +184,7 @@ anchor_store (char **files,
NULL);
for (i = 0; i < nfiles; i++) {
- ret = p11_parse_file (parser, files[i], P11_PARSE_FLAG_ANCHOR);
+ ret = p11_parse_file (parser, files[i], NULL, P11_PARSE_FLAG_ANCHOR);
switch (ret) {
case P11_PARSE_SUCCESS:
break;
diff --git a/trust/parser.c b/trust/parser.c
index 54d9c15..f89092f 100644
--- a/trust/parser.c
+++ b/trust/parser.c
@@ -749,6 +749,7 @@ p11_parse_memory (p11_parser *parser,
int
p11_parse_file (p11_parser *parser,
const char *filename,
+ struct stat *sb,
int flags)
{
p11_mmap *map;
@@ -759,7 +760,7 @@ p11_parse_file (p11_parser *parser,
return_val_if_fail (parser != NULL, P11_PARSE_FAILURE);
return_val_if_fail (filename != NULL, P11_PARSE_FAILURE);
- map = p11_mmap_open (filename, &data, &size);
+ map = p11_mmap_open (filename, sb, &data, &size);
if (map == NULL) {
p11_message_err (errno, "couldn't open and map file: %s", filename);
return P11_PARSE_FAILURE;
diff --git a/trust/parser.h b/trust/parser.h
index 59cc378..b177844 100644
--- a/trust/parser.h
+++ b/trust/parser.h
@@ -66,6 +66,7 @@ int p11_parse_memory (p11_parser *parser,
int p11_parse_file (p11_parser *parser,
const char *filename,
+ struct stat *sb,
int flags);
p11_array * p11_parser_parsed (p11_parser *parser);
diff --git a/trust/save.c b/trust/save.c
index a549d93..6533bd1 100644
--- a/trust/save.c
+++ b/trust/save.c
@@ -512,11 +512,11 @@ cleanup_directory (const char *directory,
p11_dict *cache)
{
struct dirent *dp;
+ struct stat st;
p11_dict *remove;
p11_dictiter iter;
char *path;
DIR *dir;
- int skip;
bool ret;
/* First we load all the modules */
@@ -535,18 +535,8 @@ cleanup_directory (const char *directory,
if (asprintf (&path, "%s/%s", directory, dp->d_name) < 0)
return_val_if_reached (false);
-#ifdef HAVE_STRUCT_DIRENT_D_TYPE
- if(dp->d_type != DT_UNKNOWN) {
- skip = (dp->d_type == DT_DIR);
- } else
-#endif
- {
- struct stat st;
-
- skip = (stat (path, &st) < 0) || S_ISDIR (st.st_mode);
- }
- if (!skip) {
+ if (stat (path, &st) >= 0 && !S_ISDIR (st.st_mode)) {
if (!p11_dict_set (remove, path, path))
return_val_if_reached (false);
} else {
diff --git a/trust/tests/frob-cert.c b/trust/tests/frob-cert.c
index 71018bd..c1bc45c 100644
--- a/trust/tests/frob-cert.c
+++ b/trust/tests/frob-cert.c
@@ -106,7 +106,7 @@ main (int argc,
ret = asn1_create_element (definitions, argv[1], &cert);
err_if_fail (ret, "Certificate");
- map = p11_mmap_open (argv[3], &data, &size);
+ map = p11_mmap_open (argv[3], NULL, &data, &size);
if (map == NULL) {
fprintf (stderr, "couldn't open file: %s\n", argv[3]);
return 1;
diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c
index 5920076..c272a88 100644
--- a/trust/tests/test-module.c
+++ b/trust/tests/test-module.c
@@ -1108,7 +1108,7 @@ test_create_and_write (void)
/* The expected file name */
path = p11_path_build (test.directory, "yay.p11-kit", NULL);
p11_parser_formats (test.parser, p11_parser_format_persist, NULL);
- ret = p11_parse_file (test.parser, path, 0);
+ ret = p11_parse_file (test.parser, path, NULL, 0);
assert_num_eq (ret, P11_PARSE_SUCCESS);
free (path);
@@ -1164,7 +1164,7 @@ test_modify_and_write (void)
/* The expected file name */
path = p11_path_build (test.directory, "yay.p11-kit", NULL);
- ret = p11_parse_file (test.parser, path, 0);
+ ret = p11_parse_file (test.parser, path, NULL, 0);
assert_num_eq (ret, P11_PARSE_SUCCESS);
free (path);
diff --git a/trust/tests/test-parser.c b/trust/tests/test-parser.c
index 09ec71c..871973b 100644
--- a/trust/tests/test-parser.c
+++ b/trust/tests/test-parser.c
@@ -118,7 +118,7 @@ test_parse_der_certificate (void)
};
p11_parser_formats (test.parser, p11_parser_format_x509, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -146,7 +146,7 @@ test_parse_pem_certificate (void)
};
p11_parser_formats (test.parser, p11_parser_format_pem, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.pem",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.pem", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -173,7 +173,7 @@ test_parse_p11_kit_persist (void)
};
p11_parser_formats (test.parser, p11_parser_format_persist, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/input/verisign-v1.p11-kit",
+ ret = p11_parse_file (test.parser, SRCDIR "/input/verisign-v1.p11-kit", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -226,7 +226,7 @@ test_parse_openssl_trusted (void)
int i;
p11_parser_formats (test.parser, p11_parser_format_pem, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3-trusted.pem",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3-trusted.pem", NULL,
P11_PARSE_FLAG_ANCHOR);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -310,7 +310,7 @@ test_parse_openssl_distrusted (void)
* so we parse this as an anchor, but expect it to be blacklisted
*/
p11_parser_formats (test.parser, p11_parser_format_pem, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/distrusted.pem",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/distrusted.pem", NULL,
P11_PARSE_FLAG_ANCHOR);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -350,7 +350,7 @@ test_parse_anchor (void)
int ret;
p11_parser_formats (test.parser, p11_parser_format_x509, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.der", NULL,
P11_PARSE_FLAG_ANCHOR);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -380,7 +380,7 @@ test_parse_thawte (void)
};
p11_parser_formats (test.parser, p11_parser_format_pem, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/thawte.pem",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/thawte.pem", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_SUCCESS, ret);
@@ -401,7 +401,7 @@ test_parse_invalid_file (void)
p11_message_quiet ();
p11_parser_formats (test.parser, p11_parser_format_x509, NULL);
- ret = p11_parse_file (test.parser, "/nonexistant",
+ ret = p11_parse_file (test.parser, "/nonexistant", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_FAILURE, ret);
@@ -416,7 +416,7 @@ test_parse_unrecognized (void)
p11_message_quiet ();
p11_parser_formats (test.parser, p11_parser_format_x509, NULL);
- ret = p11_parse_file (test.parser, SRCDIR "/files/unrecognized-file.txt",
+ ret = p11_parse_file (test.parser, SRCDIR "/files/unrecognized-file.txt", NULL,
P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_UNRECOGNIZED, ret);
@@ -433,7 +433,7 @@ test_parse_no_asn1_cache (void)
assert_ptr_not_null (parser);
p11_parser_formats (parser, p11_parser_format_x509, NULL);
- ret = p11_parse_file (parser, SRCDIR "/files/cacert3.der", P11_PARSE_FLAG_NONE);
+ ret = p11_parse_file (parser, SRCDIR "/files/cacert3.der", NULL, P11_PARSE_FLAG_NONE);
assert_num_eq (P11_PARSE_SUCCESS, ret);
/* Should have gotten certificate */
diff --git a/trust/tests/test-token.c b/trust/tests/test-token.c
index bdf1120..a028d9c 100644
--- a/trust/tests/test-token.c
+++ b/trust/tests/test-token.c
@@ -238,9 +238,11 @@ test_not_writable (void)
{
p11_token *token;
- token = p11_token_new (333, "/", "Label");
- assert (!p11_token_is_writable (token));
- p11_token_free (token);
+ if (getuid () != 0) {
+ token = p11_token_new (333, "/", "Label");
+ assert (!p11_token_is_writable (token));
+ p11_token_free (token);
+ }
token = p11_token_new (333, "", "Label");
assert (!p11_token_is_writable (token));
@@ -533,7 +535,7 @@ test_write_new (void)
/* The expected file name */
path = p11_path_build (test.directory, "Yay_.p11-kit", NULL);
- ret = p11_parse_file (test.parser, path, 0);
+ ret = p11_parse_file (test.parser, path, NULL, 0);
assert_num_eq (ret, P11_PARSE_SUCCESS);
free (path);
@@ -573,7 +575,7 @@ test_write_no_label (void)
/* The expected file name */
path = p11_path_build (test.directory, "data.p11-kit", NULL);
- ret = p11_parse_file (test.parser, path, 0);
+ ret = p11_parse_file (test.parser, path, NULL, 0);
assert_num_eq (ret, P11_PARSE_SUCCESS);
free (path);
diff --git a/trust/token.c b/trust/token.c
index 4e7c631..22363f8 100644
--- a/trust/token.c
+++ b/trust/token.c
@@ -179,7 +179,7 @@ loader_load_file (p11_token *token,
else if (strcmp (filename, token->path) == 0 && !S_ISDIR (sb->st_mode))
flags = P11_PARSE_FLAG_ANCHOR;
- ret = p11_parse_file (token->parser, filename, flags);
+ ret = p11_parse_file (token->parser, filename, sb, flags);
switch (ret) {
case P11_PARSE_SUCCESS: