summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/conf.c35
-rw-r--r--p11-kit/conf.h3
-rw-r--r--p11-kit/tests/test-conf.c6
3 files changed, 21 insertions, 23 deletions
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index ef542f2..8a328ed 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -92,7 +92,9 @@ _p11_conf_merge_defaults (p11_dict *map,
}
p11_dict *
-_p11_conf_parse_file (const char* filename, int flags)
+_p11_conf_parse_file (const char* filename,
+ struct stat *sb,
+ int flags)
{
p11_dict *map = NULL;
void *data;
@@ -106,7 +108,7 @@ _p11_conf_parse_file (const char* filename, int flags)
p11_debug ("reading config file: %s", filename);
- mmap = p11_mmap_open (filename, &data, &length);
+ mmap = p11_mmap_open (filename, sb, &data, &length);
if (mmap == NULL) {
error = errno;
if ((flags & CONF_IGNORE_MISSING) &&
@@ -215,7 +217,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
*/
/* Load the main configuration */
- config = _p11_conf_parse_file (system_conf, CONF_IGNORE_MISSING);
+ config = _p11_conf_parse_file (system_conf, NULL, CONF_IGNORE_MISSING);
if (!config)
goto finished;
@@ -240,7 +242,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
/* Load up the user configuration, ignore selinux denying us access */
flags = CONF_IGNORE_MISSING | CONF_IGNORE_ACCESS_DENIED;
- uconfig = _p11_conf_parse_file (path, flags);
+ uconfig = _p11_conf_parse_file (path, NULL, flags);
if (!uconfig) {
error = errno;
goto finished;
@@ -325,6 +327,7 @@ calc_name_from_filename (const char *fname)
static bool
load_config_from_file (const char *configfile,
+ struct stat *sb,
const char *name,
p11_dict *configs,
int flags)
@@ -343,7 +346,7 @@ load_config_from_file (const char *configfile,
return_val_if_fail (key != NULL, false);
}
- config = _p11_conf_parse_file (configfile, flags);
+ config = _p11_conf_parse_file (configfile, sb, flags);
if (!config) {
free (key);
return false;
@@ -408,22 +411,16 @@ load_configs_from_directory (const char *directory,
path = p11_path_build (directory, dp->d_name, NULL);
return_val_if_fail (path != NULL, false);
-#ifdef HAVE_STRUCT_DIRENT_D_TYPE
- if(dp->d_type != DT_UNKNOWN) {
- is_dir = (dp->d_type == DT_DIR);
- } else
-#endif
- {
- if (stat (path, &st) < 0) {
- error = errno;
- p11_message_err (error, "couldn't stat path: %s", path);
- free (path);
- break;
- }
- is_dir = S_ISDIR (st.st_mode);
+ if (stat (path, &st) < 0) {
+ error = errno;
+ p11_message_err (error, "couldn't stat path: %s", path);
+ free (path);
+ break;
}
- if (!is_dir && !load_config_from_file (path, dp->d_name, configs, flags)) {
+ is_dir = S_ISDIR (st.st_mode);
+
+ if (!is_dir && !load_config_from_file (path, &st, dp->d_name, configs, flags)) {
error = errno;
free (path);
break;
diff --git a/p11-kit/conf.h b/p11-kit/conf.h
index c4d7ae2..911e650 100644
--- a/p11-kit/conf.h
+++ b/p11-kit/conf.h
@@ -54,7 +54,8 @@ bool _p11_conf_merge_defaults (p11_dict *config,
p11_dict *defaults);
/* Returns a hash of char *key -> char *value */
-p11_dict * _p11_conf_parse_file (const char *filename,
+p11_dict * _p11_conf_parse_file (const char *filename,
+ struct stat *sb,
int flags);
/* Returns a hash of char *key -> char *value */
diff --git a/p11-kit/tests/test-conf.c b/p11-kit/tests/test-conf.c
index 3a94c12..dc82da8 100644
--- a/p11-kit/tests/test-conf.c
+++ b/p11-kit/tests/test-conf.c
@@ -58,7 +58,7 @@ test_parse_conf_1 (void)
p11_dict *map;
const char *value;
- map = _p11_conf_parse_file (SRCDIR "/files/test-1.conf", 0);
+ map = _p11_conf_parse_file (SRCDIR "/files/test-1.conf", NULL, 0);
assert_ptr_not_null (map);
value = p11_dict_get (map, "key1");
@@ -81,7 +81,7 @@ test_parse_ignore_missing (void)
{
p11_dict *map;
- map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", CONF_IGNORE_MISSING);
+ map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", NULL, CONF_IGNORE_MISSING);
assert_ptr_not_null (map);
assert_num_eq (0, p11_dict_size (map));
@@ -94,7 +94,7 @@ test_parse_fail_missing (void)
{
p11_dict *map;
- map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", 0);
+ map = _p11_conf_parse_file (SRCDIR "/files/non-existant.conf", NULL, 0);
assert (map == NULL);
assert_ptr_not_null (p11_message_last ());
}