diff options
Diffstat (limited to 'common/homedir.c')
-rw-r--r-- | common/homedir.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/common/homedir.c b/common/homedir.c index 8b5bc9f05..ab5b1d270 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -21,6 +21,22 @@ #include <config.h> #include <stdlib.h> #include <errno.h> +#include <fcntl.h> + +#ifdef HAVE_W32_SYSTEM +#include <shlobj.h> +#ifndef CSIDL_APPDATA +#define CSIDL_APPDATA 0x001a +#endif +#ifndef CSIDL_LOCAL_APPDATA +#define CSIDL_LOCAL_APPDATA 0x001c +#endif +#ifndef CSIDL_FLAG_CREATE +#define CSIDL_FLAG_CREATE 0x8000 +#endif +#endif /*HAVE_W32_SYSTEM*/ + + #include "util.h" #include "sysutils.h" @@ -36,6 +52,30 @@ default_homedir (void) #ifdef HAVE_W32_SYSTEM if (!dir || !*dir) dir = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG", "HomeDir"); + if (!dir || !*dir) + { + char path[MAX_PATH]; + + /* fixme: It might be better to use LOCAL_APPDATA because this + is defined as "non roaming" and thus more likely to be kept + locally. For private keys this is desired. However, given + that many users copy private keys anyway forth and back, + using a system roaming serives might be better than to let + them do it manually. A security conscious user will anyway + use the registry entry to have better control. */ + if (SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, + NULL, 0, path) >= 0) + { + char *tmp = xmalloc (strlen (path) + 6 +1); + strcpy (stpcpy (tmp, path), "\\gnupg"); + dir = tmp; + + /* Try to create the directory if it does not yet + exists. */ + if (access (dir, F_OK)) + CreateDirectory (dir, NULL); + } + } #endif /*HAVE_W32_SYSTEM*/ if (!dir || !*dir) dir = GNUPG_DEFAULT_HOMEDIR; |