1
1
/* homedir.c - Setup the home directory.
2
* Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
2
* Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
3
* Copyright (C) 2013 Werner Koch
4
5
* This file is part of GnuPG.
47
48
#include "sysutils.h"
51
#ifdef HAVE_W32_SYSTEM
52
/* A flag used to indicate that a control file for gpgconf has been
53
detected. Under Windows the presence of this file indicates a
54
portable installations and triggers several changes:
56
- The GNUGHOME directory is fixed relative to installation
57
directory. All other means to set the home directory are
60
- All registry variables are ignored.
62
This flag is not used on Unix systems.
64
static int w32_portable_app;
66
/* This flag is true if this process' binary has been installed under
67
bin and not in the root directory. */
68
static int w32_bin_is_bin;
70
/* Just a little prototype. */
71
static const char *w32_rootdir (void);
73
#endif /*HAVE_W32_SYSTEM*/
50
78
/* This is a helper function to load a Windows function from either of
52
80
#ifdef HAVE_W32_SYSTEM
104
/* It might be better to use LOCAL_APPDATA because this is
105
defined as "non roaming" and thus more likely to be kept
106
locally. For private keys this is desired. However, given
107
that many users copy private keys anyway forth and back,
108
using a system roaming services might be better than to let
109
them do it manually. A security conscious user will anyway
110
use the registry entry to have better control. */
111
if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE,
132
rdir = w32_rootdir ();
133
if (w32_portable_app)
114
char *tmp = xmalloc (strlen (path) + 6 +1);
115
strcpy (stpcpy (tmp, path), "\\gnupg");
118
/* Try to create the directory if it does not yet exists. */
119
if (access (dir, F_OK))
120
CreateDirectory (dir, NULL);
135
dir = xstrconcat (rdir, DIRSEP_S "home", NULL);
123
dir = GNUPG_DEFAULT_HOMEDIR;
141
/* It might be better to use LOCAL_APPDATA because this is
142
defined as "non roaming" and thus more likely to be kept
143
locally. For private keys this is desired. However,
144
given that many users copy private keys anyway forth and
145
back, using a system roaming services might be better
146
than to let them do it manually. A security conscious
147
user will anyway use the registry entry to have better
149
if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE,
152
char *tmp = xmalloc (strlen (path) + 6 +1);
153
strcpy (stpcpy (tmp, path), "\\gnupg");
156
/* Try to create the directory if it does not yet exists. */
157
if (access (dir, F_OK))
158
CreateDirectory (dir, NULL);
161
dir = GNUPG_DEFAULT_HOMEDIR;
126
165
#else/*!HAVE_W32_SYSTEM*/
174
220
#ifdef HAVE_W32_SYSTEM
221
/* Check whether gpgconf is installed and if so read the gpgconf.ctl
224
check_portable_app (const char *dir)
228
fname = xstrconcat (dir, DIRSEP_S "gpgconf.exe", NULL);
229
if (access (fname, F_OK))
230
log_error ("required binary '%s' is not installed\n", fname);
233
strcpy (fname + strlen (fname) - 3, "ctl");
234
if (!access (fname, F_OK))
236
/* gpgconf.ctl file found. Record this fact. */
237
w32_portable_app = 1;
239
/* FIXME: We should read the file to detect special flags
240
and print a warning if we don't understand them. */
175
246
static const char *
176
247
w32_rootdir (void)
191
262
p = strrchr (dir, DIRSEP_C);
267
check_portable_app (dir);
269
/* If we are installed below "bin" we strip that and use
270
the top directory instead. */
271
p = strrchr (dir, DIRSEP_C);
273
if (p && !strcmp (p+1, "bin"))
196
281
log_debug ("bad filename `%s' returned for this process\n", dir);
214
300
char path[MAX_PATH];
302
/* Make sure that w32_rootdir has been called so that we are
303
able to check the portable application flag. The common dir
304
is identical to the rootdir. In that case there is also no
305
need to strdup its value. */
306
rdir = w32_rootdir ();
307
if (w32_portable_app)
216
310
if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA,
217
311
NULL, 0, path) >= 0)