summaryrefslogtreecommitdiff
path: root/p11-kit/conf.c
diff options
context:
space:
mode:
authorStef Walter <stefw@redhat.com>2013-04-03 10:50:59 +0200
committerStef Walter <stefw@gnome.org>2013-04-03 12:45:43 +0200
commita63311a0f3f2669138d09ff8f618fd4d12fa0c3d (patch)
treed5a9b8cd32dda2e0e1eff1a8393b5dcb2174f86b /p11-kit/conf.c
parentc3f1b0a45eb1c28b6f025f8ae56c3b020801b6aa (diff)
More compatible path munging and handling code
Centralize the path handling code, so we can remove unixy assumptions and have a chance of running on Windows. The current goal is to run all the tests on Windows. Includes some code from LRN <lrn1986@gmail.com> https://bugs.freedesktop.org/show_bug.cgi?id=63062
Diffstat (limited to 'p11-kit/conf.c')
-rw-r--r--p11-kit/conf.c60
1 files changed, 4 insertions, 56 deletions
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index c3eb05e..a2b46c4 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -42,6 +42,7 @@
#include "debug.h"
#include "lexer.h"
#include "message.h"
+#include "path.h"
#include "private.h"
#include <sys/param.h>
@@ -52,19 +53,9 @@
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-
-#ifdef OS_UNIX
-#include <pwd.h>
-#endif
-
-#ifdef OS_WIN32
-#include <shlobj.h>
-#endif
static int
strequal (const char *one, const char *two)
@@ -230,49 +221,6 @@ _p11_conf_parse_file (const char* filename, int flags)
return map;
}
-static char *
-expand_user_path (const char *path)
-{
- const char *env;
-
- if (path[0] != '~' || path[1] != '/')
- return strdup (path);
-
- path += 1;
- env = getenv ("HOME");
- if (env && env[0]) {
- return strconcat (env, path, NULL);
-
- } else {
-#ifdef OS_UNIX
- struct passwd *pwd;
- int error = 0;
-
- pwd = getpwuid (getuid ());
- if (!pwd) {
- error = errno;
- p11_message ("couldn't lookup home directory for user %d: %s",
- getuid (), strerror (errno));
- errno = error;
- return NULL;
- }
-
- return strconcat (pwd->pw_dir, path, NULL);
-
-#else /* OS_WIN32 */
- char directory[MAX_PATH + 1];
-
- if (!SHGetSpecialFolderPathA (NULL, directory, CSIDL_PROFILE, TRUE)) {
- p11_message ("couldn't lookup home directory for user");
- errno = ENOTDIR;
- return NULL;
- }
-
- return strconcat (directory, path, NULL);
-#endif /* OS_WIN32 */
- }
-}
-
static int
user_config_mode (p11_dict *config,
int defmode)
@@ -329,7 +277,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
}
if (mode != CONF_USER_NONE) {
- path = expand_user_path (user_conf);
+ path = p11_path_expand (user_conf);
if (!path) {
error = errno;
goto finished;
@@ -504,7 +452,7 @@ load_configs_from_directory (const char *directory,
/* We're within a global mutex, so readdir is safe */
while ((dp = readdir(dir)) != NULL) {
- path = strconcat (directory, "/", dp->d_name, NULL);
+ path = p11_path_build (directory, dp->d_name, NULL);
return_val_if_fail (path != NULL, false);
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
@@ -560,7 +508,7 @@ _p11_conf_load_modules (int mode,
/* Load each user config first, if user config is allowed */
if (mode != CONF_USER_NONE) {
flags = CONF_IGNORE_MISSING | CONF_IGNORE_ACCESS_DENIED;
- path = expand_user_path (user_dir);
+ path = p11_path_expand (user_dir);
if (!path)
error = errno;
else if (!load_configs_from_directory (path, configs, flags))