[svn] GnuPG - r4693 - in trunk: agent common g10 po sm
svn author wk
cvs at cvs.gnupg.org
Thu Feb 14 20:50:28 CET 2008
Author: wk
Date: 2008-02-14 20:50:10 +0100 (Thu, 14 Feb 2008)
New Revision: 4693
Modified:
trunk/agent/ChangeLog
trunk/agent/call-pinentry.c
trunk/agent/command.c
trunk/common/ChangeLog
trunk/common/sysutils.c
trunk/common/sysutils.h
trunk/g10/ChangeLog
trunk/g10/call-agent.c
trunk/po/be.po
trunk/po/ca.po
trunk/po/cs.po
trunk/po/da.po
trunk/po/de.po
trunk/po/el.po
trunk/po/eo.po
trunk/po/es.po
trunk/po/et.po
trunk/po/fi.po
trunk/po/fr.po
trunk/po/gl.po
trunk/po/hu.po
trunk/po/id.po
trunk/po/it.po
trunk/po/ja.po
trunk/po/nb.po
trunk/po/pl.po
trunk/po/pt.po
trunk/po/pt_BR.po
trunk/po/ro.po
trunk/po/ru.po
trunk/po/sk.po
trunk/po/sv.po
trunk/po/tr.po
trunk/po/zh_CN.po
trunk/po/zh_TW.po
trunk/sm/ChangeLog
trunk/sm/call-agent.c
trunk/sm/gpgsm.h
trunk/sm/server.c
Log:
Poems for AllowSetForegroundWindow (W32)
[The diff below has been truncated]
Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/agent/ChangeLog 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,3 +1,10 @@
+2008-02-14 Werner Koch <wk at g10code.com>
+
+ * command.c (agent_inq_pinentry_launched): New.
+ (option_handler): Add option allow-pinentry-notify.
+ * call-pinentry.c (getinfo_pid_cb): New.
+ (start_pinentry): Ask for the PID and notify the client.
+
2008-01-15 Marcus Brinkmann <marcus at g10code.de>
* call-pinentry.c (start_pinentry): Start pinentry in detached
Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/common/ChangeLog 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,3 +1,8 @@
+2008-02-14 Werner Koch <wk at g10code.com>
+
+ * sysutils.c (gnupg_allow_set_foregound_window): New.
+ (WINVER) [W32]: Define.
+
2008-01-31 Werner Koch <wk at g10code.com>
* audit.c (audit_print_result): Make sure that the output is
Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/g10/ChangeLog 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,3 +1,13 @@
+2008-02-14 Werner Koch <wk at g10code.com>
+
+ * call-agent.c (default_inq_cb): New.
+ (agent_learn, agent_scd_getattr, agent_scd_pksign)
+ (agent_scd_pkdecrypt, agent_scd_change_pin, agent_scd_checkpin)
+ (agent_get_passphrase, agent_clear_passphrase): Use new callback.
+ (inq_writekey_parms): Fall back to the new callback for other
+ inquiries.
+ (start_agent): Tell agent that we accept pinentry notifications.
+
2008-02-11 Werner Koch <wk at g10code.com>
* server.c (cmd_getinfo): New.
Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/sm/ChangeLog 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,3 +1,16 @@
+2008-02-14 Werner Koch <wk at g10code.com>
+
+ * server.c (option_handler): Add option allow-pinentry-notify.
+ (gpgsm_proxy_pinentry_notify): New.
+ * call-agent.c (default_inq_cb): New.
+ (gpgsm_agent_pksign, gpgsm_scd_pksign, gpgsm_agent_readkey)
+ (gpgsm_agent_istrusted, gpgsm_agent_marktrusted)
+ (gpgsm_agent_passwd, gpgsm_agent_get_confirmation): Call it.
+ (struct cipher_parm_s, struct genkey_parm_s): Add field CTRL.
+ (inq_ciphertext_cb): Test keyword and fallback to default_inq_cb.
+ (inq_genkey_parms): Ditto.
+ (start_agent): Tell agent to send us the pinentry notifications.
+
2008-02-13 Werner Koch <wk at g10code.com>
* call-dirmngr.c (gpgsm_dirmngr_lookup): Add arg CACHE_ONLY.
Modified: trunk/agent/call-pinentry.c
===================================================================
--- trunk/agent/call-pinentry.c 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/agent/call-pinentry.c 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,5 +1,5 @@
/* call-pinentry.c - fork of the pinentry to query stuff from the user
- * Copyright (C) 2001, 2002, 2004, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2004, 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -177,7 +177,24 @@
}
}
+static int
+getinfo_pid_cb (void *opaque, const void *buffer, size_t length)
+{
+ unsigned long *pid = opaque;
+ char pidbuf[50];
+ /* There is only the pid in the server's response. */
+ if (length >= sizeof pidbuf)
+ length = sizeof pidbuf -1;
+ if (length)
+ {
+ strncpy (pidbuf, buffer, length);
+ pidbuf[length] = 0;
+ *pid = strtoul (pidbuf, NULL, 10);
+ }
+ return 0;
+}
+
/* Fork off the pin entry if this has not already been done. Note,
that this function must always be used to aquire the lock for the
pinentry - we will serialize _all_ pinentry calls.
@@ -193,6 +210,7 @@
int i;
pth_event_t evt;
const char *tmpstr;
+ unsigned long pinentry_pid;
evt = pth_event (PTH_EVENT_TIME, pth_timeout (LOCK_TIMEOUT, 0));
if (!pth_mutex_acquire (&entry_lock, 0, evt))
@@ -357,9 +375,33 @@
}
}
+
+ /* Now ask the Pinentry for its PID. If the Pinentry is new enough
+ it will send the pid back and we will use an inquire to notify
+ our client. The client may answer the inquiry either with END or
+ with CAN to cancel the pinentry. */
+ rc = assuan_transact (entry_ctx, "GETINFO pid",
+ getinfo_pid_cb, &pinentry_pid,
+ NULL, NULL, NULL, NULL);
+ if (rc)
+ {
+ log_info ("You may want to update to a newer pinentry\n");
+ rc = 0;
+ }
+ else if (!rc && (pid_t)pinentry_pid == (pid_t)(-1))
+ log_error ("pinentry did not return a PID\n");
+ else
+ {
+ rc = agent_inq_pinentry_launched (ctrl, pinentry_pid);
+ if (gpg_err_code (rc) == GPG_ERR_CANCELED)
+ return unlock_pinentry (gpg_error (GPG_ERR_CANCELED));
+ rc = 0;
+ }
+
return 0;
}
+
/* Returns True is the pinentry is currently active. If WAITSECONDS is
greater than zero the function will wait for this many seconds
before returning. */
Modified: trunk/agent/command.c
===================================================================
--- trunk/agent/command.c 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/agent/command.c 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,6 +1,6 @@
/* command.c - gpg-agent command handler
* Copyright (C) 2001, 2002, 2003, 2004, 2005,
- * 2006 Free Software Foundation, Inc.
+ * 2006, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -60,6 +60,8 @@
int stopme; /* If set to true the agent will be terminated after
the end of this session. */
#endif
+ int allow_pinentry_notify; /* Set if pinentry notifications should
+ be done. */
};
@@ -318,6 +320,22 @@
}
+/* Helper to notify the client about a lauchned Pinentry. Because
+ that might disturb some older clients, this is only done when
+ enabled via an option. Returns an gpg error code. */
+gpg_error_t
+agent_inq_pinentry_launched (ctrl_t ctrl, unsigned long pid)
+{
+ char line[100];
+
+ if (!ctrl || !ctrl->server_local
+ || !ctrl->server_local->allow_pinentry_notify)
+ return 0;
+ snprintf (line, DIM(line)-1, "PINENTRY_LAUNCHED %lu", pid);
+ return assuan_inquire (ctrl->server_local->assuan_ctx, line, NULL, NULL, 0);
+}
+
+
/* GETEVENTCOUNTER
@@ -697,7 +715,7 @@
part. Here is an example transaction:
C: GENKEY
- S: INQUIRE KEYPARM
+ S: INQUIRE KEYPARAM
C: D (genkey (rsa (nbits 1024)))
C: END
S: D (public-key
@@ -1465,6 +1483,8 @@
}
else if (!strcmp (key, "use-cache-for-signing"))
ctrl->server_local->use_cache_for_signing = *value? atoi (value) : 0;
+ else if (!strcmp (key, "allow-pinentry-notify"))
+ ctrl->server_local->allow_pinentry_notify = 1;
else
return gpg_error (GPG_ERR_UNKNOWN_OPTION);
Modified: trunk/common/sysutils.c
===================================================================
--- trunk/common/sysutils.c 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/common/sysutils.c 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,6 +1,6 @@
/* sysutils.c - system helpers
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004,
- * 2007 Free Software Foundation, Inc.
+ * 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -43,6 +43,7 @@
# include <sys/resource.h>
#endif
#ifdef HAVE_W32_SYSTEM
+# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */
# include <windows.h>
#endif
#ifdef HAVE_PTH
@@ -471,3 +472,17 @@
#endif /* HAVE_STAT && !HAVE_W32_SYSTEM */
}
+
+/* Hack required for Windows. */
+void
+gnupg_allow_set_foregound_window (pid_t pid)
+{
+ if (!pid || pid == (pid_t)(-1))
+ log_info ("%s called with invalid pid %lu\n",
+ "gnupg_allow_set_foregound_window", (unsigned long)pid);
+#ifdef HAVE_W32_SYSTEM
+ else if (!AllowSetForegroundWindow (pid))
+ log_info ("AllowSetForegroundWindow(%lu) failed: %s\n",
+ (unsigned long)pid, w32_strerror (-1));
+#endif
+}
Modified: trunk/common/sysutils.h
===================================================================
--- trunk/common/sysutils.h 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/common/sysutils.h 2008-02-14 19:50:10 UTC (rev 4693)
@@ -47,6 +47,7 @@
int translate_sys2libc_fd_int (int fd, int for_write);
FILE *gnupg_tmpfile (void);
void gnupg_reopen_std (const char *pgmname);
+void gnupg_allow_set_foregound_window (pid_t pid);
#ifdef HAVE_W32_SYSTEM
Modified: trunk/g10/call-agent.c
===================================================================
--- trunk/g10/call-agent.c 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/g10/call-agent.c 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,5 +1,6 @@
-/* call-agent.c - divert operations to the agent
- * Copyright (C) 2001, 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
+/* call-agent.c - Divert GPG operations to the agent.
+ * Copyright (C) 2001, 2002, 2003, 2006, 2007,
+ * 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -36,6 +37,7 @@
#include "options.h"
#include "i18n.h"
#include "asshelp.h"
+#include "sysutils.h"
#include "call-agent.h"
#ifndef DBG_ASSUAN
@@ -72,19 +74,31 @@
static int
start_agent (void)
{
+ int rc;
+
if (agent_ctx)
return 0; /* Fixme: We need a context for each thread or serialize
the access to the agent. */
- return start_new_gpg_agent (&agent_ctx,
- GPG_ERR_SOURCE_DEFAULT,
- opt.homedir,
- opt.agent_program,
- opt.display, opt.ttyname, opt.ttytype,
- opt.lc_ctype, opt.lc_messages,
- opt.xauthority, opt.pinentry_user_data,
- opt.verbose, DBG_ASSUAN,
- NULL, NULL);
+ rc = start_new_gpg_agent (&agent_ctx,
+ GPG_ERR_SOURCE_DEFAULT,
+ opt.homedir,
+ opt.agent_program,
+ opt.display, opt.ttyname, opt.ttytype,
+ opt.lc_ctype, opt.lc_messages,
+ opt.xauthority, opt.pinentry_user_data,
+ opt.verbose, DBG_ASSUAN,
+ NULL, NULL);
+ if (!rc)
+ {
+ /* Tell the agent that we support Pinentry notifications. No
+ error checking so that it will work also with older
+ agents. */
+ assuan_transact (agent_ctx, "OPTION allow-pinentry-notify",
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ }
+
+ return rc;
}
@@ -187,6 +201,29 @@
+/* This is the default inquiry callback. It mainly handles the
+ Pinentry notifications. */
+static int
+default_inq_cb (void *opaque, const char *line)
+{
+ (void)opaque;
+
+ if (!strncmp (line, "PINENTRY_LAUNCHED", 17) && (line[17]==' '||!line[17]))
+ {
+ /* There is no working server mode yet thus we use
+ AllowSetForegroundWindow window right here. We might want to
+ do this anyway in case gpg is called on the console. */
+ gnupg_allow_set_foregound_window ((pid_t)strtoul (line+17, NULL, 10));
+ /* We do not pass errors to avoid breaking other code. */
+ }
+ else
+ log_debug ("ignoring gpg-agent inquiry `%s'\n", line);
+
+ return 0;
+}
+
+
+
/* Release the card info structure INFO. */
void
agent_release_card_info (struct agent_card_info_s *info)
@@ -326,7 +363,7 @@
memset (info, 0, sizeof *info);
rc = assuan_transact (agent_ctx, "LEARN --send",
- NULL, NULL, NULL, NULL,
+ NULL, NULL, default_inq_cb, NULL,
learn_status_cb, info);
return rc;
@@ -353,7 +390,7 @@
if (rc)
return rc;
- rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL,
+ rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL,
learn_status_cb, info);
return rc;
@@ -401,7 +438,8 @@
if (rc)
return rc;
- rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+ rc = assuan_transact (agent_ctx, line, NULL, NULL,
+ default_inq_cb, NULL, NULL, NULL);
return rc;
}
@@ -409,12 +447,20 @@
/* Handle a KEYDATA inquiry. Note, we only send the data,
assuan_transact takes care of flushing and writing the end */
-static assuan_error_t
-inq_writekey_parms (void *opaque, const char *keyword)
+static int
+inq_writekey_parms (void *opaque, const char *line)
{
+ int rc;
struct writekey_parm_s *parm = opaque;
- return assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen);
+ if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7]))
+ {
+ rc = assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen);
+ }
+ else
+ rc = default_inq_cb (opaque, line);
+
+ return rc;
}
@@ -529,7 +575,7 @@
memset (info, 0, sizeof *info);
rc = assuan_transact (agent_ctx, line,
- NULL, NULL, NULL, NULL,
+ NULL, NULL, default_inq_cb, NULL,
scd_genkey_cb, info);
return rc;
@@ -589,7 +635,7 @@
serialno);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line, membuf_data_cb, &data,
- NULL, NULL, NULL, NULL);
+ default_inq_cb, NULL, NULL, NULL);
if (rc)
{
xfree (get_membuf (&data, &len));
@@ -639,7 +685,7 @@
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
- NULL, NULL, NULL, NULL);
+ default_inq_cb, NULL, NULL, NULL);
if (rc)
{
xfree (get_membuf (&data, &len));
@@ -679,7 +725,7 @@
snprintf (line, DIM(line)-1, "SCD PASSWD %s %d", reset, chvno);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line, NULL, NULL,
- NULL, NULL, NULL, NULL);
+ default_inq_cb, NULL, NULL, NULL);
return rc;
}
@@ -701,7 +747,7 @@
line[DIM(line)-1] = 0;
return assuan_transact (agent_ctx, line,
NULL, NULL,
- NULL, NULL, NULL, NULL);
+ default_inq_cb, NULL, NULL, NULL);
}
@@ -775,7 +821,8 @@
init_membuf_secure (&data, 64);
rc = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data, NULL, NULL, NULL, NULL);
+ membuf_data_cb, &data,
+ default_inq_cb, NULL, NULL, NULL);
if (rc)
xfree (get_membuf (&data, NULL));
@@ -806,5 +853,6 @@
snprintf (line, DIM(line)-1, "CLEAR_PASSPHRASE %s", cache_id);
line[DIM(line)-1] = 0;
- return assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+ return assuan_transact (agent_ctx, line, NULL, NULL,
+ default_inq_cb, NULL, NULL, NULL);
}
Modified: trunk/po/be.po [not shown]
Modified: trunk/po/ca.po [not shown]
Modified: trunk/po/cs.po [not shown]
Modified: trunk/po/da.po [not shown]
Modified: trunk/po/de.po [not shown]
Modified: trunk/po/el.po [not shown]
Modified: trunk/po/eo.po [not shown]
Modified: trunk/po/es.po [not shown]
Modified: trunk/po/et.po [not shown]
Modified: trunk/po/fi.po [not shown]
Modified: trunk/po/fr.po [not shown]
Modified: trunk/po/gl.po [not shown]
Modified: trunk/po/hu.po [not shown]
Modified: trunk/po/id.po [not shown]
Modified: trunk/po/it.po [not shown]
Modified: trunk/po/ja.po [not shown]
Modified: trunk/po/nb.po [not shown]
Modified: trunk/po/pl.po [not shown]
Modified: trunk/po/pt.po [not shown]
Modified: trunk/po/pt_BR.po [not shown]
Modified: trunk/po/ro.po [not shown]
Modified: trunk/po/ru.po [not shown]
Modified: trunk/po/sk.po [not shown]
Modified: trunk/po/sv.po [not shown]
Modified: trunk/po/tr.po [not shown]
Modified: trunk/po/zh_CN.po [not shown]
Modified: trunk/po/zh_TW.po [not shown]
Modified: trunk/sm/call-agent.c
===================================================================
--- trunk/sm/call-agent.c 2008-02-13 16:47:14 UTC (rev 4692)
+++ trunk/sm/call-agent.c 2008-02-14 19:50:10 UTC (rev 4693)
@@ -1,6 +1,6 @@
-/* call-agent.c - divert operations to the agent
- * Copyright (C) 2001, 2002, 2003, 2005,
- * 2007 Free Software Foundation, Inc.
+/* call-agent.c - Divert GPGSM operations to the agent
+ * Copyright (C) 2001, 2002, 2003, 2005, 2007,
+ * 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -44,6 +44,7 @@
struct cipher_parm_s
{
+ ctrl_t ctrl;
assuan_context_t ctx;
const unsigned char *ciphertext;
size_t ciphertextlen;
@@ -51,6 +52,7 @@
struct genkey_parm_s
{
+ ctrl_t ctrl;
assuan_context_t ctx;
const unsigned char *sexp;
size_t sexplen;
@@ -78,15 +80,27 @@
serialize the access to the agent (which is
suitable given that the agent is not MT. */
else
- rc = start_new_gpg_agent (&agent_ctx,
- GPG_ERR_SOURCE_DEFAULT,
- opt.homedir,
- opt.agent_program,
- opt.display, opt.ttyname, opt.ttytype,
- opt.lc_ctype, opt.lc_messages,
- opt.xauthority, opt.pinentry_user_data,
- opt.verbose, DBG_ASSUAN,
- gpgsm_status2, ctrl);
+ {
+ rc = start_new_gpg_agent (&agent_ctx,
+ GPG_ERR_SOURCE_DEFAULT,
+ opt.homedir,
+ opt.agent_program,
+ opt.display, opt.ttyname, opt.ttytype,
+ opt.lc_ctype, opt.lc_messages,
+ opt.xauthority, opt.pinentry_user_data,
+ opt.verbose, DBG_ASSUAN,
+ gpgsm_status2, ctrl);
+
+ if (!rc)
+ {
+ /* Tell the agent that we support Pinentry notifications. No
+ error checking so that it will work also with older
+ agents. */
+ assuan_transact (agent_ctx, "OPTION allow-pinentry-notify",
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ }
+ }
+
if (!ctrl->agent_seen)
{
ctrl->agent_seen = 1;
@@ -109,7 +123,30 @@
}
More information about the Gnupg-commits
mailing list