w32: Add new global flag "w32-inst-dir".

* src/gpgme.c (gpgme_set_global_flag): Add flag "w32-inst-dir";
* src/posix-util.c (_gpgme_set_override_inst_dir): New stub.
* src/w32-util.c (override_inst_dir): New var.
(_gpgme_get_inst_dir): Return this var is set.
(_gpgme_set_override_inst_dir): New.
--

See
https://lists.gnupg.org/pipermail/gnupg-devel/2015-September/030267.html
for background.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-10-28 16:24:30 +01:00
parent 0d9d0a6b5b
commit bb600aa8fd
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 51 additions and 1 deletions

View File

@ -701,6 +701,16 @@ directory part is used as the default installation directory; the
@code{.exe} suffix is added by GPGME. Use forward slashed even under @code{.exe} suffix is added by GPGME. Use forward slashed even under
Windows. Windows.
@item "w32-inst-dir"
On Windows GPGME needs to know its installation directory to find its
spawn helper. This is in general no problem because a DLL has this
information. Some applications however link statically to GPGME and
thus GPGME can only figure out the installation directory of this
application which may be wrong in certain cases. By supplying an
installation directory as value to this flag, GPGME will assume that
that directory is the installation directory. This flag has no effect
on non-Windows platforms.
@end table @end table
This function returns @code{0} on success. In contrast to other This function returns @code{0} on success. In contrast to other

View File

@ -75,6 +75,8 @@ gpgme_set_global_flag (const char *name, const char *value)
return _gpgme_set_default_gpgconf_name (value); return _gpgme_set_default_gpgconf_name (value);
else if (!strcmp (name, "gpg-name")) else if (!strcmp (name, "gpg-name"))
return _gpgme_set_default_gpg_name (value); return _gpgme_set_default_gpg_name (value);
else if (!strcmp (name, "w32-inst-dir"))
return _gpgme_set_override_inst_dir (value);
else else
return -1; return -1;
} }

View File

@ -71,6 +71,15 @@ _gpgme_set_default_gpgconf_name (const char *name)
} }
/* Dummy function - see w32-util.c for the actual code. */
int
_gpgme_set_override_inst_dir (const char *dir)
{
(void)dir;
return 0;
}
/* Find an executable program PGM along the envvar PATH. */ /* Find an executable program PGM along the envvar PATH. */
static char * static char *
walk_path (const char *pgm) walk_path (const char *pgm)

View File

@ -23,6 +23,7 @@
/*-- {posix,w32}-util.c --*/ /*-- {posix,w32}-util.c --*/
int _gpgme_set_default_gpg_name (const char *name); int _gpgme_set_default_gpg_name (const char *name);
int _gpgme_set_default_gpgconf_name (const char *name); int _gpgme_set_default_gpgconf_name (const char *name);
int _gpgme_set_override_inst_dir (const char *dir);
char *_gpgme_get_gpg_path (void); char *_gpgme_get_gpg_path (void);
char *_gpgme_get_gpgconf_path (void); char *_gpgme_get_gpgconf_path (void);

View File

@ -85,7 +85,10 @@ static HMODULE my_hmodule;
binaries. The are set only once by gpgme_set_global_flag. */ binaries. The are set only once by gpgme_set_global_flag. */
static char *default_gpg_name; static char *default_gpg_name;
static char *default_gpgconf_name; static char *default_gpgconf_name;
/* If this variable is not NULL the value is assumed to be the
installation directory. The variable may only be set once by
gpgme_set_global_flag and accessed by _gpgme_get_inst_dir. */
static char *override_inst_dir;
#ifdef HAVE_ALLOW_SET_FOREGROUND_WINDOW #ifdef HAVE_ALLOW_SET_FOREGROUND_WINDOW
@ -347,6 +350,9 @@ _gpgme_get_inst_dir (void)
{ {
static char *inst_dir; static char *inst_dir;
if (override_inst_dir)
return override_inst_dir;
LOCK (get_path_lock); LOCK (get_path_lock);
if (!inst_dir) if (!inst_dir)
{ {
@ -456,6 +462,28 @@ _gpgme_set_default_gpgconf_name (const char *name)
} }
/* Set the override installation directory. This function may only be
called by gpgme_set_global_flag. Returns 0 on success. */
int
_gpgme_set_override_inst_dir (const char *dir)
{
if (!override_inst_dir)
{
override_inst_dir = malloc (strlen (dir) + 1);
if (override_inst_dir)
{
strcpy (override_inst_dir, dir);
replace_slashes (override_inst_dir);
/* Remove a trailing slash. */
if (*override_inst_dir
&& override_inst_dir[strlen (override_inst_dir)-1] == '\\')
override_inst_dir[strlen (override_inst_dir)-1] = 0;
}
}
return !override_inst_dir;
}
/* Return the full file name of the GPG binary. This function is used /* Return the full file name of the GPG binary. This function is used
iff gpgconf was not found and thus it can be assumed that gpg2 is iff gpgconf was not found and thus it can be assumed that gpg2 is
not installed. This function is only called by get_gpgconf_item not installed. This function is only called by get_gpgconf_item