aboutsummaryrefslogtreecommitdiffstats
path: root/common/homedir.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/homedir.c')
-rw-r--r--common/homedir.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/common/homedir.c b/common/homedir.c
index ab5b1d270..a118cbac1 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -1,5 +1,5 @@
/* homedir.c - Setup the home directory.
- * Copyright (C) 2004 Free Software Foundation, Inc.
+ * Copyright (C) 2004, 2006 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -41,6 +41,47 @@
#include "util.h"
#include "sysutils.h"
+
+/* This is a helper function to load a Windows function from either of
+ one DLLs. */
+#ifdef HAVE_W32_SYSTEM
+static HRESULT
+w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d, LPSTR e)
+{
+ static int initialized;
+ static HRESULT (WINAPI * func)(HWND,int,HANDLE,DWORD,LPSTR);
+
+ if (!initialized)
+ {
+ static char *dllnames[] = { "shell32.dll", "shfolder.dll", NULL };
+ void *handle;
+ int i;
+
+ initialized = 1;
+
+ for (i=0, handle = NULL; !handle && dllnames[i]; i++)
+ {
+ handle = dlopen (dllnames[i], RTLD_LAZY);
+ if (handle)
+ {
+ func = dlsym (handle, "SHGetFolderPathA");
+ if (!func)
+ {
+ dlclose (handle);
+ handle = NULL;
+ }
+ }
+ }
+ }
+
+ if (func)
+ return func (a,b,c,d,e);
+ else
+ return -1;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
+
/* Set up the default home directory. The usual --homedir option
should be parsed later. */
const char *
@@ -56,15 +97,15 @@ default_homedir (void)
{
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
+ /* 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
+ using a system roaming services 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)
+ if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE,
+ NULL, 0, path) >= 0)
{
char *tmp = xmalloc (strlen (path) + 6 +1);
strcpy (stpcpy (tmp, path), "\\gnupg");