[PATCH] gpg: Avoid using XDG_RUNTIME_DIR as socketdir.
Damien Goutte-Gattat
dgouttegattat at incenp.org
Tue Jan 3 15:52:37 CET 2017
* common/homedir.c (_gnupg_socketdir_internal): Check that the
directory under [/var]/run/user is not set as XDG_RUNTIME_DIR.
* tools/gpgconf.c (main): Report avoidance of XDG_RUNTIME_DIR.
--
We do not want to put the sockets in XDG_RUNTIME_DIR because
the XDG Base Directory specification says the directory is to
be removed when the user logs out. Unfortunately, on some
GNU/Linux distributions XDG_RUNTIME_DIR happens to be set to
/run/user/$UID; we should then avoid using that directory if
we do not want our sockets to be forcibly removed.
Signed-off-by: Damien Goutte-Gattat <dgouttegattat at incenp.org>
---
common/homedir.c | 7 +++++++
tools/gpgconf.c | 1 +
2 files changed, 8 insertions(+)
diff --git a/common/homedir.c b/common/homedir.c
index 6b40bb6..a57ab25 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -448,6 +448,7 @@ gnupg_default_homedir_p (void)
* 32 := Non default homedir; checking subdir.
* 64 := Subdir does not exist.
* 128 := Using homedir as fallback.
+ * 256 := /run/user directory is the same as XDG_RUNTIME_DIR.
*/
char *
_gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
@@ -501,6 +502,12 @@ _gnupg_socketdir_internal (int skip_checks, unsigned *r_info)
goto leave;
}
+ if ((s = getenv ("XDG_RUNTIME_DIR")) && !strcmp (s, prefix))
+ {
+ *r_info |= 256; /* Same directory as XDG_RUNTIME_DIR. */
+ goto leave;
+ }
+
if (strlen (prefix) + 7 >= sizeof prefix)
{
*r_info |= 1; /* Ooops: Buffer too short to append "/gnupg". */
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index af65424..5f24d9c 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -721,6 +721,7 @@ main (int argc, char **argv)
if ((flags & 32)) log_info ("\tnon-default homedir\n");
if ((flags & 64)) log_info ("\tno such subdir\n");
if ((flags & 128)) log_info ("\tusing homedir as fallback\n");
+ if ((flags & 256)) log_info ("\tavoiding XDG_RUNTIME_DIR\n");
}
if ((flags & ~32) && !opt.dry_run)
--
2.9.0
More information about the Gnupg-devel
mailing list