aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2008-02-14 19:51:21 +0000
committerWerner Koch <[email protected]>2008-02-14 19:51:21 +0000
commit3756fd0f0689915f3cf0ea77c0d1b8d8431c7744 (patch)
tree0cd8cc2896c61b268bf53d4bdfd9f8e5a26b87e1
parent(no commit message) (diff)
downloadgpgme-3756fd0f0689915f3cf0ea77c0d1b8d8431c7744.tar.gz
gpgme-3756fd0f0689915f3cf0ea77c0d1b8d8431c7744.zip
Chnages to supporta pinnetry notification
-rw-r--r--assuan/ChangeLog5
-rw-r--r--assuan/assuan-pipe-connect.c4
-rw-r--r--gpgme/ChangeLog15
-rw-r--r--gpgme/engine-gpgconf.c4
-rw-r--r--gpgme/engine-gpgsm.c43
-rw-r--r--gpgme/gpgme.h2
-rw-r--r--gpgme/posix-io.c5
-rw-r--r--gpgme/posix-util.c7
-rw-r--r--gpgme/priv-io.h2
-rw-r--r--gpgme/rungpg.c5
-rw-r--r--gpgme/util.h1
-rw-r--r--gpgme/version.c2
-rw-r--r--gpgme/w32-glib-io.c8
-rw-r--r--gpgme/w32-io.c6
-rw-r--r--gpgme/w32-qt-io.cpp4
-rw-r--r--gpgme/w32-util.c32
16 files changed, 129 insertions, 16 deletions
diff --git a/assuan/ChangeLog b/assuan/ChangeLog
index 65131625..22bc7353 100644
--- a/assuan/ChangeLog
+++ b/assuan/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-14 Werner Koch <[email protected]>
+
+ * assuan-pipe-connect.c (_gpgme_io_spawn): Adjust prototype.
+ (pipe_connect_gpgme, pipe_connect_gpgme): Adjust call.
+
2008-01-04 Marcus Brinkmann <[email protected]>
* assuan-pipe-connect.c (_gpgme_io_pipe)
diff --git a/assuan/assuan-pipe-connect.c b/assuan/assuan-pipe-connect.c
index 10f54c43..32a62191 100644
--- a/assuan/assuan-pipe-connect.c
+++ b/assuan/assuan-pipe-connect.c
@@ -44,7 +44,7 @@
int _gpgme_io_pipe (int filedes[2], int inherit_idx);
int _gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list);
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid);
#endif
/* Hacks for Slowaris. */
@@ -643,7 +643,7 @@ pipe_connect_gpgme (assuan_context_t *ctx,
child_fds[2].fd = -1;
/* Start the process. */
- res = _gpgme_io_spawn (name, argv, child_fds, child_fds);
+ res = _gpgme_io_spawn (name, argv, child_fds, child_fds, NULL);
if (res == -1)
{
_assuan_log_printf ("CreateProcess failed: %s\n", strerror (errno));
diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog
index 5bc5dca6..9ac1f61f 100644
--- a/gpgme/ChangeLog
+++ b/gpgme/ChangeLog
@@ -1,3 +1,18 @@
+2008-02-14 Werner Koch <[email protected]>
+
+ * w32-io.c (_gpgme_io_spawn): Add arg R_PID to return the pid.
+ * posix-io.c (_gpgme_io_spawn): Ditto.
+ * w32-glib-io.c (_gpgme_io_spawn): Ditto.
+ * w32-qt-io.cpp (_gpgme_io_spawn): Ditto.
+ * priv-io.h (_gpgme_io_spawn): Adjust prototyp and change all callers.
+ * rungpg.c (start): Call _gpgme_allow_set_foregound_window.
+
+ * w32-util.c (_gpgme_allow_set_foregound_window): New.
+ * posix-util.c (_gpgme_allow_set_foregound_window): New.
+ * engine-gpgsm.c (default_inq_cb): New.
+ (gpgsm_new) [W32]: Enable pinentry notifications.
+ (status_handler): Handle inquiries.
+
2008-01-30 Marcus Brinkmann <[email protected]>
* kdpipeiodevice.cpp: New version by Frank Osterfeld, fixes race
diff --git a/gpgme/engine-gpgconf.c b/gpgme/engine-gpgconf.c
index 584bbea9..26cd45f4 100644
--- a/gpgme/engine-gpgconf.c
+++ b/gpgme/engine-gpgconf.c
@@ -219,7 +219,7 @@ gpgconf_read (void *engine, char *arg1, char *arg2,
pfd[0].fd = rp[1];
cfd[0].fd = rp[1];
- status = _gpgme_io_spawn (gpgconf->file_name, argv, cfd, pfd);
+ status = _gpgme_io_spawn (gpgconf->file_name, argv, cfd, pfd, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);
@@ -630,7 +630,7 @@ gpgconf_write (void *engine, char *arg1, char *arg2, gpgme_data_t conf)
pfd[0].fd = rp[0];
cfd[0].fd = rp[0];
- status = _gpgme_io_spawn (gpgconf->file_name, argv, cfd, pfd);
+ status = _gpgme_io_spawn (gpgconf->file_name, argv, cfd, pfd, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);
diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c
index 2993f09d..615648b0 100644
--- a/gpgme/engine-gpgsm.c
+++ b/gpgme/engine-gpgsm.c
@@ -285,6 +285,20 @@ map_assuan_error (gpg_error_t err)
}
+/* This is the default inquiry callback. We use it to handle the
+ Pinentry notifications. */
+static gpgme_error_t
+default_inq_cb (engine_gpgsm_t gpgsm, const char *line)
+{
+ if (!strncmp (line, "PINENTRY_LAUNCHED", 17) && (line[17]==' '||!line[17]))
+ {
+ _gpgme_allow_set_foregound_window ((pid_t)strtoul (line+17, NULL, 10));
+ }
+
+ return 0;
+}
+
+
static gpgme_error_t
gpgsm_cancel (void *engine)
{
@@ -528,6 +542,19 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
err = 0; /* This is an optional feature of gpgsm. */
}
+
+#ifdef HAVE_W32_SYSTEM
+ /* Under Windows we need to use AllowSetForegroundWindow. Tell
+ gpgsm to tell us when it needs it. */
+ if (!err)
+ {
+ err = assuan_transact (gpgsm->assuan_ctx, "OPTION allow-pinentry-notify",
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ if (gpg_err_code (err) == GPG_ERR_UNKNOWN_OPTION)
+ err = 0; /* This is a new feature of gpgsm. */
+ }
+#endif /*HAVE_W32_SYSTEM*/
+
#if !USE_DESCRIPTOR_PASSING
if (!err
&& (_gpgme_io_set_close_notify (gpgsm->input_cb.fd,
@@ -861,7 +888,7 @@ status_handler (void *opaque, int fd)
"fd 0x%x: ERR line - mapped to: %s",
fd, err ? gpg_strerror (err) : "ok");
/* Try our best to terminate the connection friendly. */
- // assuan_write_line (gpgsm->assuan_ctx, "BYE");
+ /* assuan_write_line (gpgsm->assuan_ctx, "BYE"); */
}
else if (linelen >= 2
&& line[0] == 'O' && line[1] == 'K'
@@ -1028,6 +1055,20 @@ status_handler (void *opaque, int fd)
"fd 0x%x: S line (%s) - final status: %s",
fd, line+2, err? gpg_strerror (err):"ok");
}
+ else if (linelen >= 7
+ && line[0] == 'I' && line[1] == 'N' && line[2] == 'Q'
+ && line[3] == 'U' && line[4] == 'I' && line[5] == 'R'
+ && line[6] == 'E'
+ && (line[7] == '\0' || line[7] == ' '))
+ {
+ char *keyword = line+7;
+
+ while (*keyword == ' ')
+ keyword++;;
+ default_inq_cb (gpgsm, keyword);
+ assuan_write_line (gpgsm->assuan_ctx, "END");
+ }
+
}
while (!err && assuan_pending_line (gpgsm->assuan_ctx));
diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h
index 12ddee8a..8ae4daff 100644
--- a/gpgme/gpgme.h
+++ b/gpgme/gpgme.h
@@ -72,7 +72,7 @@ extern "C" {
AM_PATH_GPGME macro) check that this header matches the installed
library. Warning: Do not edit the next line. configure will do
that for you! */
-#define GPGME_VERSION "1.1.7-svn1300"
+#define GPGME_VERSION "1.1.7-svn1301"
diff --git a/gpgme/posix-io.c b/gpgme/posix-io.c
index 6b793f1e..f2a616d2 100644
--- a/gpgme/posix-io.c
+++ b/gpgme/posix-io.c
@@ -235,7 +235,7 @@ _gpgme_io_waitpid (int pid, int hang, int *r_status, int *r_signal)
int
_gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list)
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid)
{
pid_t pid;
int i;
@@ -358,6 +358,9 @@ _gpgme_io_spawn (const char *path, char **argv,
for (i = 0; fd_parent_list[i].fd != -1; i++)
_gpgme_io_close (fd_parent_list[i].fd);
+ if (r_pid)
+ *r_pid = pid;
+
return TRACE_SYSRES (0);
}
diff --git a/gpgme/posix-util.c b/gpgme/posix-util.c
index 168dad6e..9e669491 100644
--- a/gpgme/posix-util.c
+++ b/gpgme/posix-util.c
@@ -65,3 +65,10 @@ _gpgme_get_conf_int (const char *key, int *value)
{
return 0;
}
+
+void
+_gpgme_allow_set_foregound_window (pid_t pid)
+{
+ (void)pid;
+ /* Not needed. */
+}
diff --git a/gpgme/priv-io.h b/gpgme/priv-io.h
index 5841dc92..b0bc367d 100644
--- a/gpgme/priv-io.h
+++ b/gpgme/priv-io.h
@@ -56,7 +56,7 @@ int _gpgme_io_set_nonblocking (int fd);
fds in FD_CHILD_LIST in the child. */
int _gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list);
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid);
int _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock);
/* Write the printable version of FD to the buffer BUF of length
diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c
index 0ffdc7c7..64a8ee20 100644
--- a/gpgme/rungpg.c
+++ b/gpgme/rungpg.c
@@ -1226,6 +1226,7 @@ start (engine_gpg_t gpg)
int i, n;
int status;
struct spawn_fd_item_s *fd_child_list, *fd_parent_list;
+ pid_t pid;
if (!gpg)
return gpg_error (GPG_ERR_INV_VALUE);
@@ -1309,7 +1310,7 @@ start (engine_gpg_t gpg)
status = _gpgme_io_spawn (gpg->file_name ? gpg->file_name :
_gpgme_get_gpg_path (),
- gpg->argv, fd_child_list, fd_parent_list);
+ gpg->argv, fd_child_list, fd_parent_list, &pid);
saved_errno = errno;
free (fd_child_list);
if (status == -1)
@@ -1356,6 +1357,8 @@ start (engine_gpg_t gpg)
}
}
+ _gpgme_allow_set_foregound_window (pid);
+
gpg_io_event (gpg, GPGME_EVENT_START, NULL);
/* fixme: check what data we can release here */
diff --git a/gpgme/util.h b/gpgme/util.h
index 0cd6ab5c..64e63c70 100644
--- a/gpgme/util.h
+++ b/gpgme/util.h
@@ -33,6 +33,7 @@ const char *_gpgme_get_gpg_path (void);
const char *_gpgme_get_gpgsm_path (void);
const char *_gpgme_get_gpgconf_path (void);
int _gpgme_get_conf_int (const char *key, int *value);
+void _gpgme_allow_set_foregound_window (pid_t pid);
/*-- replacement functions in <funcname>.c --*/
diff --git a/gpgme/version.c b/gpgme/version.c
index 03d7aa01..f010249d 100644
--- a/gpgme/version.c
+++ b/gpgme/version.c
@@ -212,7 +212,7 @@ _gpgme_get_program_version (const char *const file_name)
pfd[0].fd = rp[1];
cfd[0].fd = rp[1];
- status = _gpgme_io_spawn (file_name, argv, cfd, pfd);
+ status = _gpgme_io_spawn (file_name, argv, cfd, pfd, NULL);
if (status < 0)
{
_gpgme_io_close (rp[0]);
diff --git a/gpgme/w32-glib-io.c b/gpgme/w32-glib-io.c
index 3204b578..8b284304 100644
--- a/gpgme/w32-glib-io.c
+++ b/gpgme/w32-glib-io.c
@@ -450,7 +450,7 @@ build_commandline (char **argv)
int
_gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list)
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid)
{
SECURITY_ATTRIBUTES sec_attr;
PROCESS_INFORMATION pi =
@@ -458,7 +458,7 @@ _gpgme_io_spawn (const char *path, char **argv,
NULL, /* returns process handle */
0, /* returns primary thread handle */
0, /* returns pid */
- 0 /* returns tid */
+ 0 /* returns tid */
};
STARTUPINFO si;
char *envblock = NULL;
@@ -593,7 +593,9 @@ _gpgme_io_spawn (const char *path, char **argv,
"dwProcessID=%d, dwThreadId=%d",
pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId);
-
+ if (r_pid)
+ *r_pid = (pid_t)pi.dwProcessId;
+
if (ResumeThread (pi.hThread) < 0)
TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
diff --git a/gpgme/w32-io.c b/gpgme/w32-io.c
index c4d2a1bf..e7dad2c3 100644
--- a/gpgme/w32-io.c
+++ b/gpgme/w32-io.c
@@ -1007,7 +1007,7 @@ build_commandline (char **argv)
int
_gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list)
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid)
{
SECURITY_ATTRIBUTES sec_attr;
PROCESS_INFORMATION pi =
@@ -1015,7 +1015,7 @@ _gpgme_io_spawn (const char *path, char **argv,
NULL, /* returns process handle */
0, /* returns primary thread handle */
0, /* returns pid */
- 0 /* returns tid */
+ 0 /* returns tid */
};
STARTUPINFO si;
char *envblock = NULL;
@@ -1147,6 +1147,8 @@ _gpgme_io_spawn (const char *path, char **argv,
"dwProcessID=%d, dwThreadId=%d",
pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId);
+ if (r_pid)
+ *r_pid = (pid_t)pi.dwProcessId;
if (ResumeThread (pi.hThread) < 0)
TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
diff --git a/gpgme/w32-qt-io.cpp b/gpgme/w32-qt-io.cpp
index ba43913c..9ccdff9a 100644
--- a/gpgme/w32-qt-io.cpp
+++ b/gpgme/w32-qt-io.cpp
@@ -399,7 +399,7 @@ build_commandline (char **argv)
int
_gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list)
+ struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid)
{
SECURITY_ATTRIBUTES sec_attr;
PROCESS_INFORMATION pi =
@@ -543,6 +543,8 @@ _gpgme_io_spawn (const char *path, char **argv,
"dwProcessID=%d, dwThreadId=%d",
pi.hProcess, pi.hThread,
(int) pi.dwProcessId, (int) pi.dwThreadId);
+ if (r_pid)
+ *r_pid = (pid_t)pi.dwProcessId;
if (ResumeThread (pi.hThread) < 0)
TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
diff --git a/gpgme/w32-util.c b/gpgme/w32-util.c
index b0f6df2d..a4763dec 100644
--- a/gpgme/w32-util.c
+++ b/gpgme/w32-util.c
@@ -363,3 +363,35 @@ _gpgme_get_conf_int (const char *key, int *value)
free (tmp);
return 1;
}
+
+
+void
+_gpgme_allow_set_foregound_window (pid_t pid)
+{
+ static int initialized;
+ static BOOL (WINAPI * func)(DWORD);
+ void *handle;
+
+ if (!initialized)
+ {
+ /* Available since W2000; thus we dynload it. */
+ initialized = 1;
+ handle = dlopen ("user32.dll", RTLD_LAZY);
+ if (handle)
+ {
+ func = dlsym (handle, "AllowSetForegroundWindow");
+ if (!func)
+ {
+ dlclose (handle);
+ handle = NULL;
+ }
+ }
+ }
+
+ if (!pid || pid == (pid_t)(-1))
+ ;
+ else if (func)
+ func (pid);
+
+}
+