aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/call-agent.c54
-rw-r--r--g10/call-agent.h2
-rw-r--r--g10/gpgv.c5
-rw-r--r--g10/mainproc.c17
-rw-r--r--g10/test-stubs.c5
5 files changed, 67 insertions, 16 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c
index a023654bc..bd81811fc 100644
--- a/g10/call-agent.c
+++ b/g10/call-agent.c
@@ -285,6 +285,44 @@ warn_version_mismatch (assuan_context_t ctx, const char *servername, int mode)
return err;
}
+int
+agent_set_pinentry_mode (int pinentry_mode, int *old_mode)
+{
+ int rc;
+ char *tmp;
+
+ if (agent_ctx == NULL)
+ {
+ if (old_mode)
+ *old_mode = opt.pinentry_mode;
+
+ opt.pinentry_mode = pinentry_mode;
+ return 0;
+ }
+
+ tmp = xasprintf ("OPTION pinentry-mode=%s",
+ str_pinentry_mode (pinentry_mode));
+ rc = assuan_transact (agent_ctx, tmp,
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ xfree (tmp);
+ if (rc)
+ {
+ log_error ("setting pinentry mode '%s' failed: %s\n",
+ str_pinentry_mode (pinentry_mode),
+ gpg_strerror (rc));
+ write_status_error ("set_pinentry_mode", rc);
+ }
+ else
+ {
+ if (old_mode)
+ *old_mode = opt.pinentry_mode;
+
+ opt.pinentry_mode = pinentry_mode;
+ }
+
+ return rc;
+}
+
/* Try to connect to the agent via socket or fork it off and work by
pipes. Handle the server's initial greeting */
@@ -332,21 +370,7 @@ start_agent (ctrl_t ctrl, int for_card)
NULL, NULL, NULL, NULL, NULL, NULL);
/* Pass on the pinentry mode. */
if (opt.pinentry_mode)
- {
- char *tmp = xasprintf ("OPTION pinentry-mode=%s",
- str_pinentry_mode (opt.pinentry_mode));
- rc = assuan_transact (agent_ctx, tmp,
- NULL, NULL, NULL, NULL, NULL, NULL);
- xfree (tmp);
- if (rc)
- {
- log_error ("setting pinentry mode '%s' failed: %s\n",
- str_pinentry_mode (opt.pinentry_mode),
- gpg_strerror (rc));
- write_status_error ("set_pinentry_mode", rc);
- }
- }
-
+ agent_set_pinentry_mode (opt.pinentry_mode, NULL);
check_hijacking (agent_ctx);
}
}
diff --git a/g10/call-agent.h b/g10/call-agent.h
index d85a6fd5d..154adfce2 100644
--- a/g10/call-agent.h
+++ b/g10/call-agent.h
@@ -123,6 +123,8 @@ int agent_scd_checkpin (const char *serialno);
/* Dummy function, only implemented by gpg 1.4. */
void agent_clear_pin_cache (const char *sn);
+/* XXX */
+int agent_set_pinentry_mode (int pinentry_mode, int *old_mode);
/* Send the GET_PASSPHRASE command to the agent. */
gpg_error_t agent_get_passphrase (const char *cache_id,
diff --git a/g10/gpgv.c b/g10/gpgv.c
index d08dc5a7a..ee52a5e42 100644
--- a/g10/gpgv.c
+++ b/g10/gpgv.c
@@ -697,3 +697,8 @@ void
tofu_end_batch_update (void)
{
}
+
+int
+agent_set_pinentry_mode (int pinentry_mode, int *old_mode)
+{
+}
diff --git a/g10/mainproc.c b/g10/mainproc.c
index 4217ccdb4..2ac8f7c51 100644
--- a/g10/mainproc.c
+++ b/g10/mainproc.c
@@ -39,6 +39,8 @@
#include "photoid.h"
#include "mbox-util.h"
#include "call-dirmngr.h"
+#include "call-agent.h"
+#include "../common/shareddefs.h"
/* Put an upper limit on nested packets. The 32 is an arbitrary
value, a much lower should actually be sufficient. */
@@ -1174,13 +1176,19 @@ int
proc_packets (ctrl_t ctrl, void *anchor, iobuf_t a )
{
int rc;
+ int old_mode;
CTX c = xmalloc_clear (sizeof *c);
c->ctrl = ctrl;
c->anchor = anchor;
+
+ agent_set_pinentry_mode (PINENTRY_MODE_CANCEL, &old_mode);
rc = do_proc_packets (ctrl, c, a);
- xfree (c);
+ agent_set_pinentry_mode (old_mode, NULL);
+ if (rc)
+ rc = do_proc_packets (ctrl, c, a);
+ xfree (c);
return rc;
}
@@ -1272,12 +1280,19 @@ int
proc_encryption_packets (ctrl_t ctrl, void *anchor, iobuf_t a )
{
CTX c = xmalloc_clear (sizeof *c);
+ int old_mode;
int rc;
c->ctrl = ctrl;
c->anchor = anchor;
c->encrypt_only = 1;
+
+ agent_set_pinentry_mode (PINENTRY_MODE_CANCEL, &old_mode);
rc = do_proc_packets (ctrl, c, a);
+ agent_set_pinentry_mode (old_mode, NULL);
+ if (rc)
+ rc = do_proc_packets (ctrl, c, a);
+
xfree (c);
return rc;
}
diff --git a/g10/test-stubs.c b/g10/test-stubs.c
index 6f50759d5..f7ba387a8 100644
--- a/g10/test-stubs.c
+++ b/g10/test-stubs.c
@@ -505,3 +505,8 @@ void
tofu_end_batch_update (void)
{
}
+
+int
+agent_set_pinentry_mode (int pinentry_mode, int *old_mode)
+{
+}