1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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

directory.
This commit is contained in:
Werner Koch 2004-12-21 12:44:42 +00:00
parent 878cf20766
commit 7b9e5a343f
2 changed files with 42 additions and 1 deletions

View File

@ -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.

View File

@ -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;