From dda5ee09f369c2beaf475fe91871fc3131a14e88 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 24 Mar 2009 20:45:01 -0400 Subject: [PATCH] Let pwmd_open_nb() use PWMD_OPTION_PINENTRY_TIMEOUT rather than a extra parameter. --- src/libpwmd.c | 17 ++++++++--------- src/libpwmd.h.in | 35 +++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/libpwmd.c b/src/libpwmd.c index fad09bfc..7e526656 100644 --- a/src/libpwmd.c +++ b/src/libpwmd.c @@ -1079,7 +1079,7 @@ gpg_error_t pwmd_pending_line(pwm_t *pwm) return assuan_pending_line(pwm->ctx) ? 0 : GPG_ERR_NO_DATA; } -pwmd_async_t pwmd_process(pwm_t *pwm, gpg_error_t *rc, const char **result) +pwmd_async_t pwmd_process(pwm_t *pwm, gpg_error_t *rc, char **result) { fd_set fds; int n; @@ -1690,7 +1690,7 @@ static gpg_error_t do_open_command(pwm_t *pwm, const char *filename, char *passw } static int do_pwmd_open(pwm_t *pwm, gpg_error_t *error, const char *filename, - int nb, int timeout) + int nb) { char *result = NULL; char *password = NULL; @@ -1765,9 +1765,9 @@ static int do_pwmd_open(pwm_t *pwm, gpg_error_t *error, const char *filename, pw.filename[sizeof(pw.filename)-1] = 0; pw.fd = p[0]; - if (timeout > 0) { + if (pwm->pinentry_timeout > 0) { gpwm = pwm; - gtimeout = timeout; + gtimeout = pwm->pinentry_timeout; gelapsed = 0; } @@ -1799,7 +1799,7 @@ getpin_nb_fail: signal(SIGALRM, SIG_DFL); *error = do_open_command(pwm, filename, password); - if (timeout) + if (pwm->pinentry_timeout) signal(SIGALRM, catchsig); if (pwm->pctx && *error == EPWMD_BADKEY) { @@ -1896,18 +1896,17 @@ gpg_error_t pwmd_open(pwm_t *pwm, const char *filename) { gpg_error_t error; - do_pwmd_open(pwm, &error, filename, 0, 0); + do_pwmd_open(pwm, &error, filename, 0); return error; } -int pwmd_open_nb(pwm_t *pwm, gpg_error_t *error, const char *filename, - int timeout) +int pwmd_open_nb(pwm_t *pwm, gpg_error_t *error, const char *filename) { #ifndef WITH_PINENTRY *error = GPG_ERR_NOT_IMPLEMENTED; return -1; #else - return do_pwmd_open(pwm, error, filename, 1, timeout); + return do_pwmd_open(pwm, error, filename, 1); #endif } diff --git a/src/libpwmd.h.in b/src/libpwmd.h.in index 6842a612..f0f3f118 100644 --- a/src/libpwmd.h.in +++ b/src/libpwmd.h.in @@ -200,8 +200,7 @@ typedef enum { /* PWMD_OPTION_PINENTRY_TIMEOUT * - * "OPTION TIMEOUT" pwmd command. Only useful when pwmd is used as the - * pinentry method. + * The pinentry timeout in seconds. */ PWMD_OPTION_PINENTRY_TIMEOUT, @@ -282,6 +281,11 @@ gpg_error_t pwmd_get_hostkey_async(pwm_t *pwm, const char *hostname, int port) _ * Sets 'fd' to the file descriptor which is connected to the pwmd server. * You can select() or poll() this fd to determine when to call * pwmd_process(). Returns 0 on success or an error code. + * + * Note that this FD is the assuan context FD and not set during the TCP + * connection phase when used with pwmd_tcp_connect_async() or + * pwmd_get_hostkey_async(). You must wait until pwmd_process() returns + * ASYNC_DONE (then check for an error) and then call this function. */ gpg_error_t pwmd_get_fd(pwm_t *pwm, int *fd) __attribute__ ((warn_unused_result)); @@ -314,20 +318,19 @@ gpg_error_t pwmd_open(pwm_t *pwm, const char *filename) __attribute__ ((warn_unu * to retrieve the password. It returns -2 when the file is cached (ISCACHED) * on the server or if the file doesn't exist on the file system (a new file). * Otherwise it returns a file descriptor that select() can use. When ready - * for a read, read() should read a pwmd_nb_status_t. If there is a system - * error (pipe() or fork()), then -1 is returned and 'error' is set to an - * error code that pwmd_strerror() can describe. See pwmd_open_nb_finalize(). + * for a read, a pwmd_nb_status_t should be read. If there is a system error + * (pipe() or fork()), then -1 is returned and 'error' is set to an error code + * that pwmd_strerror() can describe. See pwmd_open_nb_finalize(). * - * The 'timeout' parameter specifies the number of seconds until the pinentry - * terminates. Setting to 0 (the default) will disable timeouts. Note that the - * child process will reset the SIGALRM handler (if any) to it's own handler - * and that the actual OPEN command isn't calculated as part of the elapsed - * time. + * Setting PWMD_OPTION_PINENTRY_TIMEOUT specifies the number of seconds until + * the pinentry terminates. Setting to 0 (the default) will disable timeouts. + * Note that the child process will reset the SIGALRM handler (if any) to it's + * own handler and that the actual OPEN command isn't calculated as part of + * the elapsed time. * * Be sure to set PWMD_OPTION_PINENTRY. */ -int pwmd_open_nb(pwm_t *pwm, gpg_error_t *error, const char *filename, - int timeout) __attribute__ ((warn_unused_result)); +int pwmd_open_nb(pwm_t *pwm, gpg_error_t *error, const char *filename) __attribute__ ((warn_unused_result)); /* * When a file descriptor has been returned from pwmd_open_nb() and after a @@ -363,7 +366,7 @@ gpg_error_t pwmd_open_async(pwm_t *pwm, const char *filename) __attribute__ ((wa * The result should not be modified by the client. It should be freed by * calling pwmd_free() before the next asynchronous command. */ -pwmd_async_t pwmd_process(pwm_t *pwm, gpg_error_t *rc, const char **result) __attribute__ ((warn_unused_result)); +pwmd_async_t pwmd_process(pwm_t *pwm, gpg_error_t *rc, char **result) __attribute__ ((warn_unused_result)); ; /* @@ -382,9 +385,9 @@ gpg_error_t pwmd_save(pwm_t *pwm) __attribute__ ((warn_unused_result)); * error (pipe() or fork()), then -1 is returned and 'error' is set to an * error code that pwmd_strerror() can describe. See pwmd_save_nb_finalize(). * - * Note that there is no timeout setting. If a password is required, pinentry - * won't timeout but will wait until either it is canceled or a successful - * passphrase is entered. + * PWMD_OPTION_PINENTRY_TIMEOUT is ignored when using this method. If a + * password is required, pinentry won't timeout but will wait until either it + * is canceled or a successful passphrase is entered. * * Be sure to set PWMD_OPTION_PINENTRY. */ -- 2.11.4.GIT