From 1fd3ec80976b7974ce2d89fac1314b809f8df810 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 24 Dec 2007 07:44:03 -0500 Subject: [PATCH] Set pinentry options by using the pinentry OPTIONs and not command line switches. --- src/pinentry.c | 69 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/pinentry.c b/src/pinentry.c index 5beb6286..46d02533 100644 --- a/src/pinentry.c +++ b/src/pinentry.c @@ -62,8 +62,8 @@ static int mem_realloc_cb(void *data, const void *buffer, size_t len) return 0; } -static gpg_error_t assuan_command(struct pinentry_s *pin, char **result, - const char *cmd) +static gpg_error_t assuan_command(struct pinentry_s *pin, gchar **result, + const gchar *cmd) { membuf_t data; gpg_error_t rc; @@ -90,17 +90,15 @@ static gpg_error_t assuan_command(struct pinentry_s *pin, char **result, return rc; } -static gpg_error_t launch_pinentry(struct pinentry_s *pin) +static gpg_error_t set_pinentry_options(struct pinentry_s *pin) { - int rc; - assuan_context_t ctx; - int child_list[] = {-1}; - char *display = getenv("DISPLAY"); - const char *argv[6]; - int have_display = 0; - char *tty = NULL; - - //update_pinentry_settings(pin); + gchar *display = getenv("DISPLAY"); + gint have_display = 0; + gchar *tty = NULL, *ttytype = NULL; + gchar *opt, *val; + gpg_error_t rc; + gchar *result = NULL; + gchar cmd[ASSUAN_LINELENGTH]; if (pin->display || display) have_display = 1; @@ -108,30 +106,44 @@ static gpg_error_t launch_pinentry(struct pinentry_s *pin) tty = pin->ttyname ? pin->ttyname : ttyname(STDOUT_FILENO); if (!tty) - return GPG_ERR_INV_VALUE; - + return GPG_ERR_CANCELED; } if (!have_display && !tty) - return GPG_ERR_INV_VALUE; - - argv[0] = "pinentry"; - argv[1] = have_display ? "--display" : "--ttyname"; - argv[2] = have_display ? pin->display ? pin->display : display : tty; - argv[3] = NULL; + return GPG_ERR_CANCELED; if (!have_display) { gchar *p = getenv("TERM"); - if (p) { - argv[3] = "--ttytype"; - argv[4] = pin->ttytype ? pin->ttytype : p; - argv[5] = NULL; - } - else - return GPG_ERR_INV_VALUE; + ttytype = pin->ttytype ? pin->ttytype : p; + + if (!ttytype) + return GPG_ERR_CANCELED; } + opt = have_display ? "DISPLAY" : "TTYNAME"; + val = have_display ? pin->display ? pin->display : display : tty; + snprintf(cmd, sizeof(cmd), "OPTION %s=%s", g_ascii_strdown(opt, strlen(opt)), val); + rc = assuan_command(pin, &result, cmd); + + if (rc) + return rc; + + if (!have_display) { + snprintf(cmd, sizeof(cmd), "OPTION ttytype=%s", ttytype); + rc = assuan_command(pin, &result, cmd); + } + + return rc; +} + +static gpg_error_t launch_pinentry(struct pinentry_s *pin) +{ + gpg_error_t rc; + assuan_context_t ctx; + gint child_list[] = {-1}; + const gchar *argv[] = { "pinentry", NULL }; + rc = assuan_pipe_connect(&ctx, pin->path ? pin->path : PINENTRY_PATH, argv, child_list); @@ -140,7 +152,8 @@ static gpg_error_t launch_pinentry(struct pinentry_s *pin) pin->pid = assuan_get_pid(ctx); pin->ctx = ctx; - return set_pinentry_strings(pin, 0); + rc = set_pinentry_options(pin); + return rc ? rc : set_pinentry_strings(pin, 0); } static gpg_error_t pinentry_command(struct pinentry_s *pin, gchar **result, -- 2.11.4.GIT