diff --git a/common/ChangeLog b/common/ChangeLog index 667deb51a..6a381b300 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -4,7 +4,8 @@ (got_fatal_signal) [DOSISH]: Don't build. * simple-gettext.c: Include sysutils.h - * homedir.c: New. + * homedir.c: New. Use CSIDL_APPDATA for W32 as the default home + directory. * Makefile.am (libcommon_a_SOURCES): Add it. (EXTRA_DIST): Removed mkerror and mkerrtok. 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 #include #include +#include + +#ifdef HAVE_W32_SYSTEM +#include +#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;