diff options
author | Werner Koch <wk@gnupg.org> | 2004-12-21 13:44:42 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2004-12-21 13:44:42 +0100 |
commit | 7b9e5a343f05b51a5e5cb0ea6b92028187849d9f (patch) | |
tree | de9453f0ebeb5873adf94a26dd90b45237cda476 /common/homedir.c | |
parent | * gpg-agent.c (main): Use default_homedir(). (diff) | |
download | gnupg2-7b9e5a343f05b51a5e5cb0ea6b92028187849d9f.tar.xz gnupg2-7b9e5a343f05b51a5e5cb0ea6b92028187849d9f.zip |
* homedir.c: New. Use CSIDL_APPDATA for W32 as the default home
directory.
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; |