GNUPG-1-9-BRANCH gnupg/common (ChangeLog homedir.c)

cvs user wk cvs at cvs.gnupg.org
Tue Dec 21 13:39:43 CET 2004


    Date: Tuesday, December 21, 2004 @ 13:44:42
  Author: wk
    Path: /cvs/gnupg/gnupg/common
     Tag: GNUPG-1-9-BRANCH

Modified: ChangeLog homedir.c

* homedir.c: New. Use CSIDL_APPDATA for W32 as the default home
directory.


-----------+
 ChangeLog |    3 ++-
 homedir.c |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)


Index: gnupg/common/ChangeLog
diff -u gnupg/common/ChangeLog:1.30.2.39 gnupg/common/ChangeLog:1.30.2.40
--- gnupg/common/ChangeLog:1.30.2.39	Tue Dec 21 11:03:00 2004
+++ gnupg/common/ChangeLog	Tue Dec 21 13:44:42 2004
@@ -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.
 
Index: gnupg/common/homedir.c
diff -u gnupg/common/homedir.c:1.1.2.1 gnupg/common/homedir.c:1.1.2.2
--- gnupg/common/homedir.c:1.1.2.1	Tue Dec 21 11:03:00 2004
+++ gnupg/common/homedir.c	Tue Dec 21 13:44:42 2004
@@ -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 @@
 #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;




More information about the Gnupg-commits mailing list