aboutsummaryrefslogtreecommitdiffstats
path: root/g10/misc.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g10/misc.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/g10/misc.c b/g10/misc.c
index 3eae2aee8..2c3fbf129 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -1,6 +1,6 @@
/* misc.c - miscellaneous functions
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
- * 2004 Free Software Foundation, Inc.
+ * 2004, 2005 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -40,7 +40,19 @@
#ifdef _WIN32
#include <time.h>
#include <process.h>
+#include <windows.h>
+#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 /*_WIN32*/
+
#include "util.h"
#include "main.h"
#include "photoid.h"
@@ -49,6 +61,8 @@
#include "cardglue.h"
+
+
#ifdef ENABLE_SELINUX_HACKS
/* A object and a global variable to keep track of files marked as
secured. */
@@ -1002,3 +1016,46 @@ parse_options(char *str,unsigned int *options,
return 1;
}
+
+
+/* Set up the default home directory. The usual --homedir option
+ should be parsed later. */
+char *
+default_homedir (void)
+{
+ char *dir;
+
+ dir = getenv("GNUPGHOME");
+#ifdef HAVE_W32_SYSTEM
+ if (!dir || !*dir)
+ dir = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG", "HomeDir");
+ if (!dir || !*dir)
+ {
+ char path[MAX_PATH];
+
+ /* 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_HOMEDIR;
+
+ return dir;
+}