Support GnuPG agent standard socket

If no GPG_AGENT_INFO environment variable is defined, try using the
GnuPG Agent's standard socket, which is expected to be in
$GNUPGHOME/S.gpg-agent.
develop
Damien Goutte-Gattat 8 years ago
parent ca4d184381
commit 7ae0a37b52
  1. 23
      src/scdrand.c

@ -32,6 +32,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <pwd.h>
#include <linux/random.h>
@ -101,14 +102,22 @@ See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.\n\
static char *
get_gpg_agent_socket_name(void)
{
char *agent_info, *socket_name, *colon_index;
char *env_info, *socket_name, *colon_index;
struct passwd *pwd;
if ( ! (agent_info = getenv("GPG_AGENT_INFO")) )
errx(EXIT_FAILURE, "No running GPG Agent found");
socket_name = xstrdup(agent_info);
if ( (colon_index = strchr(socket_name, ':')) )
*colon_index = '\0';
if ( (env_info = getenv("GPG_AGENT_INFO")) ) {
socket_name = xstrdup(env_info);
if ( (colon_index = strchr(socket_name, ':')) )
*colon_index = '\0';
}
else if ( (env_info = getenv("GNUPGHOME")) )
asprintf(&socket_name, "%s/S.gpg-agent", env_info);
else if ( (env_info = getenv("HOME")) )
asprintf(&socket_name, "%s/.gnupg/S.gpg-agent", env_info);
else if ( (pwd = getpwuid(getuid())) )
asprintf(&socket_name, "%s/.gnupg/S.gpg-agent", pwd->pw_dir);
else
errx(EXIT_FAILURE, "Cannot locate GPG Agent socket");
return socket_name;
}

Loading…
Cancel
Save