+2008-02-14 Werner Koch <wk@g10code.com>
+
+ * assuan-pipe-connect.c (_gpgme_io_spawn): Adjust prototype.
+ (pipe_connect_gpgme, pipe_connect_gpgme): Adjust call.
+
2008-01-04 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (_gpgme_io_pipe)
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. */
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));
+2008-02-14 Werner Koch <wk@g10code.com>
+
+ * 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 <marcus@g10code.de>
* kdpipeiodevice.cpp: New version by Frank Osterfeld, fixes race
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]);
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]);
}
+/* 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)
{
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,
"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'
"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));
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"
\f
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;
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);
}
{
return 0;
}
+
+void
+_gpgme_allow_set_foregound_window (pid_t pid)
+{
+ (void)pid;
+ /* Not needed. */
+}
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
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);
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)
}
}
+ _gpgme_allow_set_foregound_window (pid);
+
gpg_io_event (gpg, GPGME_EVENT_START, NULL);
/* fixme: check what data we can release here */
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);
\f
/*-- replacement functions in <funcname>.c --*/
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]);
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 =
NULL, /* returns process handle */
0, /* returns primary thread handle */
0, /* returns pid */
- 0 /* returns tid */
+ 0 /* returns tid */
};
STARTUPINFO si;
char *envblock = NULL;
"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 ());
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 =
NULL, /* returns process handle */
0, /* returns primary thread handle */
0, /* returns pid */
- 0 /* returns tid */
+ 0 /* returns tid */
};
STARTUPINFO si;
char *envblock = NULL;
"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 ());
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 =
"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 ());
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);
+
+}
+