aboutsummaryrefslogtreecommitdiffstats
path: root/src/posix-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/posix-util.c')
-rw-r--r--src/posix-util.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/src/posix-util.c b/src/posix-util.c
index fd445070..d4e4e3f4 100644
--- a/src/posix-util.c
+++ b/src/posix-util.c
@@ -30,47 +30,60 @@
#include "util.h"
#include "sys-util.h"
-const char *
-_gpgme_get_gpg_path (void)
-{
-#ifdef GPG_PATH
- return GPG_PATH;
-#else
- return NULL;
-#endif
-}
-const char *
-_gpgme_get_gpgsm_path (void)
+/* Find an executable program PGM along the envvar PATH. */
+static char *
+walk_path (const char *pgm)
{
-#ifdef GPGSM_PATH
- return GPGSM_PATH;
-#else
+ const char *path, *s;
+ char *fname, *p;
+
+ path = getenv ("PATH");
+ if (!path)
+ path = "/bin:/usr/bin:.";
+
+ fname = malloc (strlen (path) + 1 + strlen (pgm) + 1);
+ if (!fname)
+ return NULL;
+
+ for (;;)
+ {
+ for (s=path, p=fname; *s && *s != ':'; s++, p++)
+ *p = *s;
+ if (*p != '/')
+ *p++ = '/';
+ strcpy (p, pgm);
+ if (!access (fname, X_OK))
+ return fname;
+ if (!*s)
+ break;
+ path = s + 1;
+ }
+
+ free (fname);
return NULL;
-#endif
}
-const char *
-_gpgme_get_gpgconf_path (void)
+
+/* Return the full file name of the GPG binary. This function is used
+ if gpgconf was not found and thus it can be assumed that gpg2 is
+ not installed. This function is only called by get_gpgconf_item
+ and may not be called concurrently. */
+char *
+_gpgme_get_gpg_path (void)
{
-#ifdef GPGCONF_PATH
- return GPGCONF_PATH;
-#else
- return NULL;
-#endif
+ return walk_path ("gpg");
}
-const char *
-_gpgme_get_g13_path (void)
+
+/* This function is only called by get_gpgconf_item and may not be
+ called concurrently. */
+char *
+_gpgme_get_gpgconf_path (void)
{
-#ifdef G13_PATH
- return G13_PATH;
-#else
- return NULL;
-#endif
+ return walk_path ("gpgconf");
}
-
/* See w32-util.c */
int
_gpgme_get_conf_int (const char *key, int *value)