core: Check for GPG_TTY as well as DISPLAY.
* src/engine-assuan.c (llass_new): Update --ttyname from GPG_TTY. * src/engine-g13.c (g13_new): Ditto. * src/engine-gpg.c (gpg_new): Ditto. * src/engine-uiserver.c (uiserver_new): Ditto. * src/engine-gpgsm.c (gpgsm_new): Ditto. -- Useful when no DISPLAY is set and there is no attached terminal to the current process. Signed-off-by: Ben Kibbey <bjk@luxsci.net>
This commit is contained in:
parent
a8ff34fc30
commit
9d62bacac7
@ -219,6 +219,7 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
gpgme_error_t err = 0;
|
gpgme_error_t err = 0;
|
||||||
engine_llass_t llass;
|
engine_llass_t llass;
|
||||||
char *optstr;
|
char *optstr;
|
||||||
|
char *env_tty = NULL;
|
||||||
|
|
||||||
(void)version; /* Not yet used. */
|
(void)version; /* Not yet used. */
|
||||||
|
|
||||||
@ -280,13 +281,24 @@ llass_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (llass->opt.gpg_agent && isatty (1))
|
if (llass->opt.gpg_agent)
|
||||||
|
err = _gpgme_getenv ("GPG_TTY", &env_tty);
|
||||||
|
|
||||||
|
if (llass->opt.gpg_agent && (isatty (1) || env_tty || err))
|
||||||
{
|
{
|
||||||
int rc;
|
int rc = 0;
|
||||||
char dft_ttyname[64];
|
char dft_ttyname[64];
|
||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
if (err)
|
||||||
|
goto leave;
|
||||||
|
else if (env_tty)
|
||||||
|
{
|
||||||
|
snprintf (dft_ttyname, sizeof (dft_ttyname), "%s", env_tty);
|
||||||
|
free (env_tty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
|
|
||||||
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
@ -222,6 +222,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
const char *argv[5];
|
const char *argv[5];
|
||||||
char *dft_display = NULL;
|
char *dft_display = NULL;
|
||||||
char dft_ttyname[64];
|
char dft_ttyname[64];
|
||||||
|
char *env_tty = NULL;
|
||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
char *optstr;
|
char *optstr;
|
||||||
|
|
||||||
@ -284,11 +285,20 @@ g13_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty (1))
|
err = _gpgme_getenv ("GPG_TTY", &env_tty);
|
||||||
|
if (isatty (1) || env_tty || err)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc = 0;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
if (err)
|
||||||
|
goto leave;
|
||||||
|
else if (env_tty)
|
||||||
|
{
|
||||||
|
snprintf (dft_ttyname, sizeof (dft_ttyname), "%s", env_tty);
|
||||||
|
free (env_tty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
|
|
||||||
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
@ -454,6 +454,7 @@ gpg_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
char *dft_display = NULL;
|
char *dft_display = NULL;
|
||||||
char dft_ttyname[64];
|
char dft_ttyname[64];
|
||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
|
char *env_tty = NULL;
|
||||||
|
|
||||||
gpg = calloc (1, sizeof *gpg);
|
gpg = calloc (1, sizeof *gpg);
|
||||||
if (!gpg)
|
if (!gpg)
|
||||||
@ -560,11 +561,20 @@ gpg_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty (1))
|
rc = _gpgme_getenv ("GPG_TTY", &env_tty);
|
||||||
|
if (isatty (1) || env_tty || rc)
|
||||||
{
|
{
|
||||||
int err;
|
int err = 0;
|
||||||
|
|
||||||
err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
if (rc)
|
||||||
|
goto leave;
|
||||||
|
else if (env_tty)
|
||||||
|
{
|
||||||
|
snprintf (dft_ttyname, sizeof (dft_ttyname), "%s", env_tty);
|
||||||
|
free (env_tty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
|
|
||||||
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
@ -253,6 +253,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
#endif
|
#endif
|
||||||
char *dft_display = NULL;
|
char *dft_display = NULL;
|
||||||
char dft_ttyname[64];
|
char dft_ttyname[64];
|
||||||
|
char *env_tty = NULL;
|
||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
char *optstr;
|
char *optstr;
|
||||||
|
|
||||||
@ -410,11 +411,20 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty (1))
|
err = _gpgme_getenv ("GPG_TTY", &env_tty);
|
||||||
|
if (isatty (1) || env_tty || err)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc = 0;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
if (err)
|
||||||
|
goto leave;
|
||||||
|
else if (env_tty)
|
||||||
|
{
|
||||||
|
snprintf (dft_ttyname, sizeof (dft_ttyname), "%s", env_tty);
|
||||||
|
free (env_tty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
|
|
||||||
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
@ -248,6 +248,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
engine_uiserver_t uiserver;
|
engine_uiserver_t uiserver;
|
||||||
char *dft_display = NULL;
|
char *dft_display = NULL;
|
||||||
char dft_ttyname[64];
|
char dft_ttyname[64];
|
||||||
|
char *env_tty = NULL;
|
||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
char *optstr;
|
char *optstr;
|
||||||
|
|
||||||
@ -330,11 +331,20 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir,
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty (1))
|
err = _gpgme_getenv ("GPG_TTY", &env_tty);
|
||||||
|
if (isatty (1) || env_tty || err)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc = 0;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
if (err)
|
||||||
|
goto leave;
|
||||||
|
else if (env_tty)
|
||||||
|
{
|
||||||
|
snprintf (dft_ttyname, sizeof (dft_ttyname), "%s", env_tty);
|
||||||
|
free (env_tty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
|
|
||||||
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
ways, e.g., when /dev/pts is not accessible under chroot. */
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
Loading…
Reference in New Issue
Block a user