diff options
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/conf.c | 60 | ||||
-rw-r--r-- | p11-kit/modules.c | 38 |
2 files changed, 7 insertions, 91 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)) diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 18400bb..19ba895 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -41,6 +41,7 @@ #include "dict.h" #include "library.h" #include "message.h" +#include "path.h" #include "pkcs11.h" #include "p11-kit.h" #include "private.h" @@ -217,39 +218,6 @@ alloc_module_unlocked (void) return mod; } -static int -is_relative_path (const char *path) -{ - assert (path); - - return (*path != '/'); -} - -static char* -build_path (const char *dir, const char *filename) -{ - char *path; - int len; - - assert (dir); - assert (filename); - - len = snprintf (NULL, 0, "%s/%s", dir, filename) + 1; - return_val_if_fail (len > 0, NULL); - -#ifdef PATH_MAX - if (len > PATH_MAX) - return NULL; -#endif - - path = malloc (len); - return_val_if_fail (path != NULL, NULL); - - sprintf (path, "%s/%s", dir, filename); - - return path; -} - static CK_RV dlopen_and_get_function_list (Module *mod, const char *path) { @@ -326,9 +294,9 @@ expand_module_path (const char *filename) { char *path; - if (is_relative_path (filename)) { + if (!p11_path_absolute (filename)) { p11_debug ("module path is relative, loading from: %s", P11_MODULE_PATH); - path = build_path (P11_MODULE_PATH, filename); + path = p11_path_build (P11_MODULE_PATH, filename, NULL); } else { path = strdup (filename); } |