2 changed files with 105 additions and 1 deletions
@ -0,0 +1,103 @@
|
||||
diff --git a/src/agent.c b/src/agent.c
|
||||
index 75d4933..ef5c72a 100644
|
||||
--- a/src/agent.c
|
||||
+++ b/src/agent.c
|
||||
@@ -255,7 +255,7 @@ agent_connect (assuan_context_t *ctx_r)
|
||||
|
||||
/* First check whether we can connect at the standard
|
||||
socket. */
|
||||
- sockname = make_filename (default_homedir (), "S.gpg-agent", NULL);
|
||||
+ sockname = make_filename (socketdir (), "S.gpg-agent", NULL);
|
||||
if (! sockname)
|
||||
return gpg_error_from_errno (errno);
|
||||
|
||||
diff --git a/src/get-path.c b/src/get-path.c
|
||||
index 0abd863..03097ca 100644
|
||||
--- a/src/get-path.c
|
||||
+++ b/src/get-path.c
|
||||
@@ -44,6 +44,9 @@
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <io.h>
|
||||
+#else
|
||||
+#include <sys/stat.h>
|
||||
+#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "support.h"
|
||||
@@ -440,6 +443,58 @@ default_homedir (void)
|
||||
return dir;
|
||||
}
|
||||
|
||||
+#ifdef HAVE_W32_SYSTEM
|
||||
+#define socketdir default_homedir
|
||||
+#else
|
||||
+
|
||||
+static int
|
||||
+check_socketdir (const char *dir)
|
||||
+{
|
||||
+ struct stat st;
|
||||
+
|
||||
+ if (stat (dir, &st) == -1)
|
||||
+ return 0;
|
||||
+ if (!S_ISDIR (st.st_mode))
|
||||
+ return 0;
|
||||
+ if (st.st_uid != getuid ())
|
||||
+ return 0;
|
||||
+ if (st.st_mode & (S_IRWXG|S_IRWXO))
|
||||
+ return 0;
|
||||
+
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
+const char *
|
||||
+socketdir (void)
|
||||
+{
|
||||
+ static char buffer[255];
|
||||
+ char *infostr, *dir = NULL;
|
||||
+
|
||||
+ if ((infostr = getenv ("GNUPGHOME")))
|
||||
+ /* FIXME: We should also check for a directory under [/var]/run. */
|
||||
+ dir = infostr;
|
||||
+ else
|
||||
+ {
|
||||
+ static const char *prefixes[] = { "/run", "/var/run", NULL };
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; !dir && prefixes[i]; i++)
|
||||
+ {
|
||||
+ snprintf (buffer, sizeof buffer, "%s/user/%u/gnupg",
|
||||
+ prefixes[i], getuid ());
|
||||
+ if (check_socketdir (buffer))
|
||||
+ dir = buffer;
|
||||
+ }
|
||||
+
|
||||
+ if (!dir)
|
||||
+ dir = GNUPG_DEFAULT_HOMEDIR;
|
||||
+ }
|
||||
+
|
||||
+ return dir;
|
||||
+}
|
||||
+
|
||||
+#endif /*!HAVE_W32_SYSTEM*/
|
||||
+
|
||||
|
||||
/* Construct a filename from the NULL terminated list of parts. Tilde
|
||||
expansion is done here. */
|
||||
diff --git a/src/support.h b/src/support.h
|
||||
index 3356224..6726947 100644
|
||||
--- a/src/support.h
|
||||
+++ b/src/support.h
|
||||
@@ -90,10 +90,11 @@ const char *get_gpg_agent_path (void);
|
||||
should be parsed later. */
|
||||
const char *default_homedir (void);
|
||||
|
||||
+const char *socketdir (void);
|
||||
+
|
||||
/* Construct a filename from the NULL terminated list of parts. Tilde
|
||||
expansion is done here. */
|
||||
char *make_filename (const char *first_part, ...);
|
||||
|
||||
-
|
||||
|
||||
#endif /* !SUPPORT_H */
|
Loading…
Reference in new issue