2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of libpwmd.
8 Libpwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Libpwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Libpwmd. If not, see <http://www.gnu.org/licenses/>.
32 #include <sys/types.h>
33 #include <sys/socket.h>
43 #include <sys/select.h>
67 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
68 #include <sys/types.h>
69 #include <sys/socket.h>
71 #include <netinet/in.h>
74 #define FINISH(rc) (gpg_err_source(rc) == GPG_ERR_SOURCE_UNKNOWN) \
84 hook_read (assuan_context_t ctx
, assuan_fd_t fd
, void *data
, size_t len
)
86 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
87 pwm_t
*pwm
= assuan_get_pointer (ctx
);
90 if (pwm
&& pwm
->tcp
&& pwm
->tcp
->ssh
)
91 return read_hook_ssh (pwm
->tcp
->ssh
, fd
, data
, len
);
94 if (pwm
&& pwm
->tcp
&& pwm
->tcp
->tls
)
95 return read_hook_tls (pwm
, fd
, data
, len
);
99 return read ((int) fd
, data
, len
);
103 hook_write (assuan_context_t ctx
, assuan_fd_t fd
, const void *data
,
107 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
108 pwm_t
*pwm
= assuan_get_pointer (ctx
);
111 if (pwm
&& pwm
->tcp
&& pwm
->tcp
->ssh
)
112 return write_hook_ssh (pwm
->tcp
->ssh
, fd
, data
, len
);
115 if (pwm
&& pwm
->tcp
&& pwm
->tcp
->tls
)
116 return write_hook_tls (pwm
, fd
, data
, len
);
120 /* libassuan cannot handle EAGAIN when doing writes. */
123 wrote
= write ((int) fd
, data
, len
);
124 if (wrote
== -1 && errno
== EAGAIN
)
127 while (wrote
== -1 && errno
== EAGAIN
);
133 hook_waitpid (assuan_context_t ctx
, pid_t pid
, int action
, int *status
,
136 return waitpid (pid
, status
, options
);
142 static int initialized
;
145 // May be called more than once.
146 gnutls_global_init ();
153 bindtextdomain ("libpwmd", LOCALEDIR
);
159 gpgrt_set_alloc_func (_xrealloc_gpgrt
);
173 gnutls_global_deinit ();
181 _connect_finalize (pwm_t
* pwm
)
186 int n
= assuan_get_active_fds (pwm
->ctx
, 0, active
, N_ARRAY (active
));
189 return GPG_ERR_EBADFD
;
193 pwm
->pinentry_pid
= -1;
196 rc
= pwmd_command (pwm
, &result
, NULL
, NULL
, NULL
, "GETINFO VERSION");
199 pwm
->version
= strtoul (result
, NULL
, 16);
203 if (!rc
&& pwm
->name
)
204 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION NAME=%s",
211 connect_uds (pwm_t
* pwm
, const char *path
)
213 char *socketpath
= NULL
;
219 return GPG_ERR_INV_ARG
;
221 pwbuf
= _getpwuid (&pw
);
223 return gpg_error_from_syserror ();
226 socketpath
= pwmd_strdup_printf ("%s/.pwmd/socket", pw
.pw_dir
);
228 socketpath
= _expand_homedir ((char *) path
, &pw
);
232 return GPG_ERR_ENOMEM
;
234 rc
= assuan_socket_connect (pwm
->ctx
, socketpath
, ASSUAN_INVALID_FD
, 0);
235 pwmd_free (socketpath
);
236 return rc
? rc
: _connect_finalize (pwm
);
240 init_handle (pwm_t
* pwm
)
243 static struct assuan_malloc_hooks mhooks
= {
244 pwmd_malloc
, pwmd_realloc
, pwmd_free
246 static struct assuan_system_hooks shooks
= {
247 ASSUAN_SYSTEM_HOOKS_VERSION
,
255 NULL
, //sendmsg both are used for FD passing
263 rc
= assuan_new_ext (&pwm
->ctx
, GPG_ERR_SOURCE_DEFAULT
, &mhooks
, NULL
,
268 assuan_set_pointer (pwm
->ctx
, pwm
);
269 assuan_ctx_set_system_hooks (pwm
->ctx
, &shooks
);
273 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
275 free_tcp (pwm_t
*pwm
)
277 struct tcp_s
*tcp
= pwm
->tcp
;
283 _free_ssh_conn (tcp
->ssh
);
289 pwmd_free (tcp
->host
);
292 freeaddrinfo (tcp
->addrs
);
296 pthread_cond_destroy (&tcp
->dns_cond
);
297 pthread_mutex_destroy (&tcp
->dns_mutex
);
303 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
305 resolve_host_thread (void *arg
)
308 struct addrinfo hints
= { 0 };
314 hints
.ai_family
= AF_UNSPEC
;
317 hints
.ai_family
= AF_INET
;
320 hints
.ai_family
= AF_INET6
;
324 hints
.ai_socktype
= SOCK_STREAM
;
325 snprintf (portstr
, sizeof (portstr
), "%i", pwm
->tcp
->port
);
326 int *n
= pwmd_malloc (sizeof (int));
327 pthread_cleanup_push (pwmd_free
, n
);
328 *n
= getaddrinfo (pwm
->tcp
->host
, portstr
, &hints
, &pwm
->tcp
->addrs
);
329 pthread_cleanup_pop (0);
330 pthread_cond_broadcast (&pwm
->tcp
->dns_cond
);
336 tcp_connect_common (pwm_t
* pwm
)
338 #define TS_TIMEOUT 50000000L
345 n
= pthread_create (&tid
, NULL
, resolve_host_thread
, pwm
);
347 return gpg_error_from_errno (n
);
349 pthread_mutex_lock (&pwm
->tcp
->dns_mutex
);
356 clock_gettime (CLOCK_REALTIME
, &ts
);
357 if (ts
.tv_nsec
+ TS_TIMEOUT
>= 1000000000LL) {
362 ts
.tv_nsec
+= TS_TIMEOUT
;
366 #ifdef HAVE_PTHREAD_CANCEL
367 pthread_cancel (tid
);
368 pthread_join (tid
, NULL
);
370 pthread_join (tid
, (void **)&result
);
373 return GPG_ERR_CANCELED
;
376 n
= pthread_cond_timedwait (&pwm
->tcp
->dns_cond
, &pwm
->tcp
->dns_mutex
,
380 if (pwm
->socket_timeout
&& ts
.tv_sec
- now
>= pwm
->socket_timeout
)
382 #ifdef HAVE_PTHREAD_CANCEL
383 pthread_cancel (tid
);
384 pthread_join (tid
, NULL
);
386 pthread_join (tid
, (void **)&result
);
389 return GPG_ERR_ETIMEDOUT
;
396 #ifdef HAVE_PTHREAD_CANCEL
397 pthread_cancel (tid
);
398 pthread_join (tid
, NULL
);
400 pthread_join (tid
, (void **)&result
);
403 return gpg_error_from_errno (n
);
406 pthread_join (tid
, (void **)&result
);
413 return GPG_ERR_UNKNOWN_HOST
; //FIXME
415 for (pwm
->tcp
->addr
= pwm
->tcp
->addrs
; pwm
->tcp
->addr
;
416 pwm
->tcp
->addr
= pwm
->tcp
->addrs
->ai_next
)
418 pwm
->fd
= socket (pwm
->tcp
->addr
->ai_family
, SOCK_STREAM
, 0);
421 rc
= gpg_error_from_syserror ();
422 if (pwm
->tcp
->addr
== pwm
->tcp
->addrs
->ai_next
)
427 if (fcntl (pwm
->fd
, F_SETFL
, O_NONBLOCK
) == -1)
429 rc
= gpg_error_from_syserror ();
433 if (connect (pwm
->fd
, pwm
->tcp
->addr
->ai_addr
,
434 pwm
->tcp
->addr
->ai_family
== AF_INET6
435 ? sizeof (struct sockaddr_in6
)
436 : sizeof (struct sockaddr
)) == -1)
441 unsigned elapsed
= 0;
443 rc
= gpg_error_from_syserror ();
444 if (gpg_err_code (rc
) != GPG_ERR_EINPROGRESS
)
448 if (pwm
->tcp
->addr
== pwm
->tcp
->addrs
->ai_next
)
457 FD_SET (pwm
->fd
, &wfds
);
458 n
= select (pwm
->fd
+1, NULL
, &wfds
, NULL
, &tv
);
460 if (!n
|| pwm
->cancel
)
463 rc
= gpg_error (GPG_ERR_CANCELED
);
464 else if (++elapsed
>= pwm
->socket_timeout
)
465 rc
= gpg_error (GPG_ERR_ETIMEDOUT
);
471 socklen_t len
= sizeof(int);
473 getsockopt (pwm
->fd
, SOL_SOCKET
, SO_ERROR
, &n
, &len
);
475 rc
= gpg_error_from_errno (n
);
478 rc
= gpg_error_from_syserror ();
484 if (pwm
->tcp
->addr
== pwm
->tcp
->addrs
->ai_next
485 || gpg_err_code (rc
) == GPG_ERR_ETIMEDOUT
497 if (fcntl (pwm
->fd
, F_SETFL
, 0) == -1)
498 rc
= gpg_error_from_syserror ();
505 command_start (pwm_t
*pwm
)
511 pwmd_connect (pwm_t
* pwm
, const char *url
, ...)
517 return FINISH (GPG_ERR_INV_ARG
);
520 rc
= init_handle (pwm
);
527 if (!(pwm
->opts
& OPT_SIGPIPE
))
528 signal (SIGPIPE
, SIG_IGN
);
533 rc
= GPG_ERR_UNSUPPORTED_PROTOCOL
;
535 if (p
&& (*p
== '/' || *p
== '~'))
536 rc
= connect_uds (pwm
, p
);
537 else if (!p
|| !strncmp (p
, "file://", 7))
541 #ifdef DEFAULT_PWMD_SOCKET
543 p
= DEFAULT_PWMD_SOCKET
;
545 rc
= connect_uds (pwm
, p
);
547 else if (!strncmp (p
, "ssh://", 6) || !strncmp (p
, "ssh6://", 7) ||
548 !strncmp (p
, "ssh4://", 7))
551 return FINISH (GPG_ERR_NOT_IMPLEMENTED
);
555 char *username
= NULL
;
557 if (!strncmp (p
, "ssh6://", 7))
559 pwm
->prot
= PWMD_IPV6
;
562 else if (!strncmp (p
, "ssh4://", 7))
564 pwm
->prot
= PWMD_IPV4
;
569 pwm
->prot
= PWMD_IP_ANY
;
573 rc
= _parse_ssh_url (p
, &host
, &port
, &username
);
577 char *identity
= NULL
;
578 char *knownhosts
= NULL
;
581 identity
= va_arg (ap
, char *);
583 if (!identity
&& !pwm
->use_agent
)
584 rc
= GPG_ERR_INV_ARG
;
586 knownhosts
= va_arg (ap
, char *);
591 rc
= _do_ssh_connect (pwm
, host
, port
, identity
, username
,
595 rc
= _connect_finalize (pwm
);
602 pwmd_free (username
);
603 pwm
->local_pinentry
= 1;
606 else if (!strncmp (p
, "tls://", 6) || !strncmp (p
, "tls6://", 7) ||
607 !strncmp (p
, "tls4://", 7))
610 return FINISH (GPG_ERR_NOT_IMPLEMENTED
);
615 if (!strncmp (p
, "tls6://", 7))
617 pwm
->prot
= PWMD_IPV6
;
620 else if (!strncmp (p
, "tls4://", 7))
622 pwm
->prot
= PWMD_IPV4
;
627 pwm
->prot
= PWMD_IP_ANY
;
631 rc
= _parse_tls_url (p
, &host
, &port
);
635 char *clientcert
= NULL
;
636 char *clientkey
= NULL
;
639 char *server_fp
= NULL
;
642 clientcert
= va_arg (ap
, char *);
645 rc
= GPG_ERR_INV_ARG
;
648 clientkey
= va_arg (ap
, char *);
650 rc
= GPG_ERR_INV_ARG
;
653 cacert
= va_arg (ap
, char *);
655 rc
= GPG_ERR_INV_ARG
;
658 prio
= va_arg (ap
, char *);
659 server_fp
= va_arg (ap
, char *);
667 rc
= _do_tls_connect (pwm
, host
, port
, clientcert
, clientkey
,
668 cacert
, prio
, server_fp
, pwm
->tls_verify
);
671 rc
= _connect_finalize (pwm
);
678 pwm
->local_pinentry
= 1;
689 disconnect (pwm_t
* pwm
)
695 assuan_release (pwm
->ctx
);
697 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
706 pwmd_close (pwm_t
* pwm
)
712 pwmd_free (pwm
->pinentry_error
);
713 pwmd_free (pwm
->pinentry_desc
);
714 pwmd_free (pwm
->pinentry_prompt
);
715 pwmd_free (pwm
->pinentry_tty
);
716 pwmd_free (pwm
->pinentry_display
);
717 pwmd_free (pwm
->pinentry_term
);
718 pwmd_free (pwm
->pinentry_lcctype
);
719 pwmd_free (pwm
->pinentry_lcmessages
);
720 pwmd_free (pwm
->filename
);
721 pwmd_free (pwm
->name
);
722 pwmd_free (pwm
->passphrase_info
);
723 pwmd_free (pwm
->passphrase_hint
);
727 _pinentry_disconnect (pwm
);
734 inquire_realloc_cb (void *data
, const void *buffer
, size_t len
)
736 membuf_t
*mem
= (membuf_t
*) data
;
742 if ((p
= pwmd_realloc (mem
->buf
, mem
->len
+ len
)) == NULL
)
743 return gpg_error (GPG_ERR_ENOMEM
);
746 memcpy ((char *) mem
->buf
+ mem
->len
, buffer
, len
);
752 get_password (pwm_t
* pwm
, char **result
, size_t * len
,
753 pwmd_pinentry_t w
, int echo
)
755 char buf
[ASSUAN_LINELENGTH
+1] = { 0 }, *p
;
756 struct termios told
, tnew
;
765 if (!isatty (STDIN_FILENO
))
767 fprintf (stderr
, N_("Input is not from a terminal! Failing.\n"));
768 return GPG_ERR_ENOTTY
;
773 if (tcgetattr (STDIN_FILENO
, &told
) == -1)
774 return gpg_error_from_syserror ();
776 memcpy (&tnew
, &told
, sizeof (struct termios
));
777 tnew
.c_lflag
&= ~(ECHO
);
778 tnew
.c_lflag
|= ICANON
| ECHONL
;
780 if (tcsetattr (STDIN_FILENO
, TCSANOW
, &tnew
) == -1)
784 tcsetattr (STDIN_FILENO
, TCSANOW
, &told
);
785 return gpg_error_from_errno (n
);
789 if (pwm
->passphrase_hint
)
790 fprintf(stderr
, N_("Key info: %s\n"), pwm
->passphrase_hint
);
794 case PWMD_PINENTRY_OPEN
:
795 fprintf (stderr
, N_("Passphrase for %s: "), pwm
->filename
);
797 case PWMD_PINENTRY_OPEN_FAILED
:
798 fprintf (stderr
, N_("Invalid passphrase. Passphrase for %s: "),
801 case PWMD_PINENTRY_SAVE
:
802 fprintf (stderr
, N_("New passphrase for %s: "), pwm
->filename
);
804 case PWMD_PINENTRY_SAVE_CONFIRM
:
805 fprintf (stderr
, N_("Repeat passphrase: "));
807 case PWMD_PINENTRY_CONFIRM
:
808 if (pwm
->pinentry_desc
)
809 fprintf (stderr
, "%s", pwm
->pinentry_desc
);
811 if (pwm
->pinentry_prompt
)
812 fprintf (stderr
, "%s", pwm
->pinentry_prompt
);
814 fprintf(stderr
, N_("Confirm [y/N]:"));
819 p
= fgets (buf
, sizeof (buf
), stdin
);
822 tcsetattr (STDIN_FILENO
, TCSANOW
, &told
);
824 if (!p
|| feof (stdin
))
827 return GPG_ERR_CANCELED
;
830 /* Strip the newline character. */
831 p
[strlen (p
) - 1] = 0;
835 if (w
== PWMD_PINENTRY_CONFIRM
)
837 if (*p
!= 'y' && *p
!= 'Y')
838 return GPG_ERR_CANCELED
;
842 key
= pwmd_strdup_printf ("%s", p
);
843 wipememory (buf
, 0, sizeof (buf
));
845 return GPG_ERR_ENOMEM
;
855 if (w
== PWMD_PINENTRY_CONFIRM
)
856 return GPG_ERR_CANCELED
;
858 /* To satisfy inquire_cb(). */
860 *result
= pwmd_strdup ("");
870 pwmd_password (pwm_t
* pwm
, const char *keyword
, char **data
, size_t * size
)
873 int new_password
= 0;
874 char *password
= NULL
, *newpass
= NULL
;
885 if (!strcmp (keyword
, "NEW_PASSPHRASE"))
888 if (!new_password
&& pwm
->pinentry_try
)
892 if (pwm
->disable_pinentry
)
894 rc
= get_password (pwm
, &password
, size
,
895 new_password
? PWMD_PINENTRY_SAVE
:
896 error
? PWMD_PINENTRY_OPEN_FAILED
:
897 PWMD_PINENTRY_OPEN
, 0);
898 if (!rc
&& new_password
)
899 rc
= get_password (pwm
, &newpass
, size
, PWMD_PINENTRY_SAVE_CONFIRM
,
904 pwmd_pinentry_t which
;
908 ? PWMD_PINENTRY_SAVE_FAILED
: PWMD_PINENTRY_OPEN_FAILED
;
910 which
= new_password
? PWMD_PINENTRY_SAVE
: PWMD_PINENTRY_OPEN
;
912 rc
= pwmd_getpin (pwm
, pwm
->filename
, &password
, size
, which
);
913 if (!rc
&& new_password
)
914 rc
= pwmd_getpin (pwm
, pwm
->filename
, &newpass
, size
,
915 PWMD_PINENTRY_SAVE_CONFIRM
);
918 if (!rc
&& new_password
)
920 if ((!password
&& newpass
) || (!newpass
&& password
)
921 || (newpass
&& password
&& strcmp (newpass
, password
)))
923 if (pwm
->disable_pinentry
)
924 fprintf (stderr
, N_("Passphrases do not match.\n"));
926 pwmd_free (password
);
928 password
= newpass
= NULL
;
934 (void) pwmd_getpin (pwm
, pwm
->filename
, NULL
, NULL
, PWMD_PINENTRY_CLOSE
);
939 pwmd_free (password
);
945 inquire_cb (void *data
, const char *keyword
)
947 pwm_t
*pwm
= (pwm_t
*) data
;
952 int new_password
= 0;
954 if (!strcmp (keyword
, "PASSPHRASE") || !strcmp (keyword
, "SIGN_PASSPHRASE"))
956 else if (!strcmp (keyword
, "NEW_PASSPHRASE") || !strcmp (keyword
, "GENKEY"))
959 /* Shouldn't get this far without a callback. */
960 if (!pwm
->override_inquire
&& !pwm
->inquire_func
961 && !is_password
&& !new_password
)
962 return gpg_error (GPG_ERR_ASS_NO_INQUIRE_CB
);
971 if (!pwm
->override_inquire
&& (is_password
|| new_password
))
974 rc
= pwmd_password (data
, keyword
, &result
, &len
);
979 rc
= pwm
->inquire_func (pwm
->inquire_data
, keyword
, rc
, &result
,
982 /* gpg will truncate a passphrase at the first nil byte which may be bad
983 * for generated key files. */
984 if ((!rc
|| gpg_err_code (rc
) == GPG_ERR_EOF
)
985 && (is_password
|| new_password
))
987 if (len
&& result
&& *result
)
989 for (size_t n
= 0; n
< len
; n
++)
991 if (result
[n
] == 0 && n
+1 != len
)
992 rc
= GPG_ERR_INV_PASSPHRASE
;
998 if (rc
&& gpg_err_code (rc
) != GPG_ERR_EOF
)
1000 #ifndef LIBASSUAN_2_1_0
1001 gpg_error_t trc
= rc
;
1003 /* Cancel this inquire. */
1004 rc
= assuan_send_data (pwm
->ctx
, NULL
, 1);
1010 /* There is a bug (or feature?) in assuan_send_data() that
1011 * when cancelling an inquire the next read from the server is
1012 * not done until the next command making the next command
1013 * fail with GPG_ERR_ASS_UNEXPECTED_CMD.
1015 rc
= assuan_read_line (pwm
->ctx
, &line
, &len
);
1017 /* Restore the original error. This differs from the error
1018 * returned from the pwmd command (GPG_ERR_CANCELED). This
1019 * error is returned to the calling function.
1028 if (gpg_err_code (rc
) == GPG_ERR_EOF
|| !rc
)
1030 if (len
<= 0 && !result
)
1035 else if ((len
<= 0 && result
) || (len
&& !result
))
1037 rc
= gpg_error (GPG_ERR_INV_ARG
);
1041 if (pwm
->inquire_maxlen
1042 && pwm
->inquire_sent
+ len
> pwm
->inquire_maxlen
)
1044 rc
= gpg_error (GPG_ERR_TOO_LARGE
);
1046 rc
= pwm
->inquire_func (pwm
->inquire_data
, keyword
, rc
,
1051 arc
= assuan_send_data (pwm
->ctx
, result
, len
);
1052 if (gpg_err_code (rc
) == GPG_ERR_EOF
)
1065 pwm
->inquire_sent
+= len
;
1067 if (pwm
->status_func
)
1069 char buf
[ASSUAN_LINELENGTH
];
1071 snprintf (buf
, sizeof (buf
), "XFER %zu %zu", pwm
->inquire_sent
,
1072 pwm
->inquire_total
);
1073 rc
= pwm
->status_func (pwm
->status_data
, buf
);
1083 pwm
->inquire_maxlen
= pwm
->inquire_sent
= 0;
1088 parse_assuan_line (pwm_t
* pwm
)
1094 rc
= assuan_read_line (pwm
->ctx
, &line
, &len
);
1097 if (line
[0] == 'O' && line
[1] == 'K' &&
1098 (line
[2] == 0 || line
[2] == ' '))
1101 else if (line
[0] == '#')
1104 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' '))
1106 if (pwm
->status_func
)
1108 rc
= pwm
->status_func (pwm
->status_data
,
1109 line
[1] == 0 ? line
+ 1 : line
+ 2);
1112 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
1113 (line
[3] == 0 || line
[3] == ' '))
1116 rc
= strtol (line
, NULL
, 10);
1124 reset_handle (pwm_t
*pwm
)
1128 pwm
->pinentry_disabled
= 0;
1129 #ifdef WITH_PINENTRY
1131 _pinentry_disconnect (pwm
);
1133 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
1144 pwmd_disconnect (pwm_t
* pwm
)
1147 return FINISH (GPG_ERR_INV_ARG
);
1149 command_start (pwm
);
1152 return FINISH (GPG_ERR_INV_STATE
);
1159 /* Note that this should only be called when not in a command. */
1161 pwmd_process (pwm_t
* pwm
)
1165 struct timeval tv
= { 0, 0 };
1168 if (!pwm
|| pwm
->fd
== -1)
1169 return FINISH (GPG_ERR_INV_ARG
);
1171 return FINISH (GPG_ERR_INV_STATE
);
1174 FD_SET (pwm
->fd
, &fds
);
1175 n
= select (pwm
->fd
+ 1, &fds
, NULL
, NULL
, &tv
);
1178 return FINISH (gpg_error_from_syserror ());
1182 if (FD_ISSET (pwm
->fd
, &fds
))
1183 rc
= parse_assuan_line (pwm
);
1186 while (!rc
&& assuan_pending_line (pwm
->ctx
))
1187 rc
= parse_assuan_line (pwm
);
1189 #if defined (WITH_SSH) || defined (WITH_GNUTLS)
1190 if (gpg_err_code (rc
) == GPG_ERR_EOF
&& pwm
->tcp
)
1201 status_cb (void *data
, const char *line
)
1205 if (!strncmp (line
, "INQUIRE_MAXLEN ", 15))
1206 pwm
->inquire_maxlen
= strtol (line
+ 15, NULL
, 10);
1207 else if (!strncmp (line
, "PASSPHRASE_HINT ", 16))
1209 pwmd_free (pwm
->passphrase_hint
);
1210 pwm
->passphrase_hint
= pwmd_strdup (line
+16);
1212 else if (!strncmp (line
, "PASSPHRASE_INFO ", 16))
1214 pwmd_free (pwm
->passphrase_info
);
1215 pwm
->passphrase_info
= pwmd_strdup (line
+16);
1218 if (pwm
->status_func
)
1219 return pwm
->status_func (pwm
->status_data
, line
);
1225 _assuan_command (pwm_t
* pwm
, assuan_context_t ctx
,
1226 char **result
, size_t * len
, const char *cmd
)
1232 return FINISH (GPG_ERR_INV_ARG
);
1234 if (strlen (cmd
) >= ASSUAN_LINELENGTH
+ 1)
1235 return FINISH (GPG_ERR_LINE_TOO_LONG
);
1239 rc
= assuan_transact (ctx
, cmd
, inquire_realloc_cb
, &data
,
1241 pwm
->pctx
== ctx
? pwm
->_inquire_func
: inquire_cb
,
1242 pwm
->pctx
== ctx
? pwm
->_inquire_data
: pwm
,
1252 pwmd_free (data
.buf
);
1260 inquire_realloc_cb (&data
, "", 1);
1263 *result
= (char *) data
.buf
;
1265 pwmd_free (data
.buf
);
1272 pwm
->inquire_maxlen
= 0;
1277 pwmd_command_ap (pwm_t
* pwm
, char **result
, size_t * rlen
,
1278 pwmd_inquire_cb_t func
, void *user
, const char *cmd
,
1285 command_start (pwm
);
1294 return FINISH (GPG_ERR_INV_ARG
);
1296 return FINISH (GPG_ERR_INV_STATE
);
1299 * C99 allows the dst pointer to be null which will calculate the length
1300 * of the would-be result and return it.
1303 len
= vsnprintf (NULL
, 0, cmd
, ap
) + 1;
1304 buf
= (char *) pwmd_malloc (len
);
1308 return FINISH (GPG_ERR_ENOMEM
);
1311 len
= vsnprintf (buf
, len
, cmd
, ap2
);
1314 if (buf
[strlen (buf
) - 1] == '\n')
1315 buf
[strlen (buf
) - 1] = 0;
1316 if (buf
[strlen (buf
) - 1] == '\r')
1317 buf
[strlen (buf
) - 1] = 0;
1319 pwm
->inquire_func
= func
;
1320 pwm
->inquire_data
= user
;
1321 pwm
->inquire_sent
= 0;
1322 gpg_error_t rc
= _assuan_command (pwm
, pwm
->ctx
, result
, rlen
, buf
);
1328 pwmd_command (pwm_t
* pwm
, char **result
, size_t * len
,
1329 pwmd_inquire_cb_t func
, void *user
, const char *cmd
, ...)
1340 return FINISH (GPG_ERR_INV_ARG
);
1342 return FINISH (GPG_ERR_INV_STATE
);
1345 gpg_error_t rc
= pwmd_command_ap (pwm
, result
, len
, func
, user
, cmd
, ap
);
1351 send_pinentry_timeout (pwm_t
*pwm
)
1355 if ((pwm
->pinentry_timeout
>= 0
1356 && pwm
->pinentry_timeout
!= pwm
->current_pinentry_timeout
)
1357 || (pwm
->pinentry_timeout
== -1
1358 && pwm
->pinentry_timeout
!= pwm
->current_pinentry_timeout
))
1360 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
,
1361 "OPTION pinentry-timeout=%i",
1362 pwm
->pinentry_timeout
);
1364 pwm
->current_pinentry_timeout
= pwm
->pinentry_timeout
;
1371 send_pinentry_options (pwm_t
* pwm
)
1375 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
,
1376 "OPTION disable-pinentry=0");
1377 if (!rc
&& pwm
->pinentry_tty
)
1378 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION TTYNAME=%s",
1381 if (!rc
&& pwm
->pinentry_term
)
1382 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION TTYTYPE=%s",
1383 pwm
->pinentry_term
);
1385 if (!rc
&& pwm
->pinentry_display
)
1386 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION DISPLAY=%s",
1387 pwm
->pinentry_display
);
1389 if (!rc
&& pwm
->pinentry_desc
)
1390 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION DESC=%s",
1391 pwm
->pinentry_desc
);
1393 if (!rc
&& pwm
->pinentry_lcctype
)
1394 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION LC_CTYPE=%s",
1395 pwm
->pinentry_lcctype
);
1397 if (!rc
&& pwm
->pinentry_lcmessages
)
1398 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION LC_MESSAGES=%s",
1399 pwm
->pinentry_lcmessages
);
1402 rc
= send_pinentry_timeout (pwm
);
1408 pwmd_socket_type (pwm_t
* pwm
, pwmd_socket_t
* result
)
1410 if (!pwm
|| !result
)
1411 return FINISH (GPG_ERR_INV_ARG
);
1413 *result
= PWMD_SOCKET_LOCAL
;
1416 return FINISH (GPG_ERR_INV_STATE
);
1418 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
1420 if (pwm
->tcp
&& pwm
->tcp
->ssh
)
1421 *result
= PWMD_SOCKET_SSH
;
1424 if (pwm
->tcp
&& pwm
->tcp
->tls
)
1425 *result
= PWMD_SOCKET_TLS
;
1432 disable_pinentry (pwm_t
*pwm
, int *disable
)
1435 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
1436 int no_pinentry
= pwm
->disable_pinentry
|| pwm
->tcp
|| pwm
->local_pinentry
;
1438 int no_pinentry
= pwm
->disable_pinentry
|| pwm
->local_pinentry
;
1442 *disable
= no_pinentry
;
1444 if (pwm
->pinentry_disabled
&& no_pinentry
)
1446 else if (!pwm
->pinentry_disabled
&& !no_pinentry
)
1449 rc
= pwmd_command (pwm
, NULL
, NULL
, NULL
, NULL
, "OPTION disable-pinentry=%i",
1452 pwm
->pinentry_disabled
= no_pinentry
;
1458 pwmd_open (pwm_t
* pwm
, const char *filename
, pwmd_inquire_cb_t cb
,
1462 int no_pinentry
= 0;
1464 if (!pwm
|| !filename
|| !*filename
)
1465 return FINISH (GPG_ERR_INV_ARG
);
1468 return FINISH (GPG_ERR_INV_STATE
);
1470 command_start (pwm
);
1471 rc
= disable_pinentry (pwm
, &no_pinentry
);
1472 if (!rc
&& !no_pinentry
)
1473 rc
= send_pinentry_options (pwm
);
1477 pwm
->pinentry_try
= 0;
1478 pwmd_free (pwm
->filename
);
1479 pwm
->filename
= pwmd_strdup (filename
);
1483 rc
= pwmd_command (pwm
, NULL
, NULL
, cb
, data
, "OPEN %s%s",
1484 (pwm
->opts
& OPT_LOCK_ON_OPEN
) ? "--lock " : "",
1487 while (gpg_err_code (rc
) == GPG_ERR_BAD_PASSPHRASE
1488 && pwm
->pinentry_disabled
1489 && ++pwm
->pinentry_try
< pwm
->pinentry_tries
);
1491 pwm
->pinentry_try
= 0;
1495 pwmd_free (pwm
->filename
);
1496 pwm
->filename
= NULL
;
1500 pwmd_free (pwm
->passphrase_hint
);
1501 pwmd_free (pwm
->passphrase_info
);
1502 pwm
->passphrase_info
= pwm
->passphrase_hint
= NULL
;
1507 do_pwmd_save_passwd (pwm_t
* pwm
, const char *args
, pwmd_inquire_cb_t cb
,
1508 void *data
, int save
)
1511 int no_pinentry
= 0;
1514 return FINISH (GPG_ERR_INV_ARG
);
1516 return FINISH (GPG_ERR_INV_STATE
);
1518 command_start (pwm
);
1519 rc
= disable_pinentry (pwm
, &no_pinentry
);
1520 if (!rc
&& !no_pinentry
)
1521 rc
= send_pinentry_options (pwm
);
1524 rc
= pwmd_command (pwm
, NULL
, NULL
, cb
, data
,
1525 save
? "SAVE %s" : "PASSWD %s", args
? args
: "");
1527 pwmd_free (pwm
->passphrase_hint
);
1528 pwmd_free (pwm
->passphrase_info
);
1529 pwm
->passphrase_info
= pwm
->passphrase_hint
= NULL
;
1534 pwmd_passwd (pwm_t
* pwm
, const char *args
, pwmd_inquire_cb_t cb
, void *data
)
1536 return do_pwmd_save_passwd (pwm
, args
, cb
, data
, 0);
1540 pwmd_save (pwm_t
* pwm
, const char *args
, pwmd_inquire_cb_t cb
, void *data
)
1542 return do_pwmd_save_passwd (pwm
, args
, cb
, data
, 1);
1546 pwmd_get_set_opt (pwm_t
*pwm
, pwmd_option_t opt
, int get
, va_list ap
)
1550 char *arg1
, **charpp
;
1554 return GPG_ERR_INV_ARG
;
1556 command_start (pwm
);
1559 case PWMD_OPTION_SERVER_VERSION
:
1561 return GPG_ERR_NOT_SUPPORTED
;
1564 rc
= GPG_ERR_INV_ARG
;
1566 rc
= GPG_ERR_INV_STATE
;
1569 unsigned *u
= va_arg (ap
, unsigned *);
1574 case PWMD_OPTION_SIGPIPE
:
1577 intp
= va_arg (ap
, int *);
1578 *intp
= pwm
->opts
& OPT_SIGPIPE
? 1 : 0;
1582 n
= va_arg (ap
, int);
1584 rc
= GPG_ERR_INV_VALUE
;
1587 pwm
->opts
|= OPT_SIGPIPE
;
1589 pwm
->opts
&= ~OPT_SIGPIPE
;
1592 case PWMD_OPTION_LOCK_ON_OPEN
:
1595 intp
= va_arg (ap
, int *);
1596 *intp
= pwm
->opts
& OPT_LOCK_ON_OPEN
? 1 : 0;
1600 n
= va_arg (ap
, int);
1603 rc
= GPG_ERR_INV_VALUE
;
1606 pwm
->opts
|= OPT_LOCK_ON_OPEN
;
1608 pwm
->opts
&= ~OPT_LOCK_ON_OPEN
;
1611 case PWMD_OPTION_INQUIRE_TOTAL
:
1614 sizetp
= va_arg (ap
, size_t *);
1615 *sizetp
= pwm
->inquire_total
;
1619 pwm
->inquire_total
= va_arg (ap
, size_t);
1621 case PWMD_OPTION_STATUS_CB
:
1624 pwmd_status_cb_t
*cb
= va_arg (ap
, pwmd_status_cb_t
*);
1626 *cb
= pwm
->status_func
;
1630 pwm
->status_func
= va_arg (ap
, pwmd_status_cb_t
);
1632 case PWMD_OPTION_STATUS_DATA
:
1635 void **data
= va_arg (ap
, void **);
1637 *data
= pwm
->status_data
;
1641 pwm
->status_data
= va_arg (ap
, void *);
1643 case PWMD_OPTION_NO_PINENTRY
:
1646 intp
= va_arg (ap
, int *);
1647 *intp
= pwm
->disable_pinentry
;
1651 n
= va_arg (ap
, int);
1654 rc
= GPG_ERR_INV_VALUE
;
1656 pwm
->disable_pinentry
= n
;
1658 case PWMD_OPTION_LOCAL_PINENTRY
:
1661 intp
= va_arg (ap
, int *);
1662 *intp
= pwm
->local_pinentry
;
1666 n
= va_arg (ap
, int);
1669 rc
= GPG_ERR_INV_VALUE
;
1671 pwm
->local_pinentry
= n
;
1674 case PWMD_OPTION_PINENTRY_TIMEOUT
:
1677 intp
= va_arg (ap
, int *);
1678 *intp
= pwm
->pinentry_timeout
;
1682 n
= va_arg (ap
, int);
1685 rc
= GPG_ERR_INV_VALUE
;
1687 pwm
->pinentry_timeout
= n
;
1689 case PWMD_OPTION_PINENTRY_TRIES
:
1692 intp
= va_arg (ap
, int *);
1693 *intp
= pwm
->pinentry_tries
;
1697 n
= va_arg (ap
, int);
1698 pwm
->pinentry_tries
= n
;
1700 case PWMD_OPTION_PINENTRY_PATH
:
1703 charpp
= va_arg (ap
, char **);
1704 *charpp
= pwm
->pinentry_path
;
1708 arg1
= va_arg (ap
, char *);
1709 pwmd_free (pwm
->pinentry_path
);
1710 pwm
->pinentry_path
= arg1
? _expand_homedir (arg1
, NULL
) : NULL
;
1712 case PWMD_OPTION_PINENTRY_TTY
:
1715 charpp
= va_arg (ap
, char **);
1716 *charpp
= pwm
->pinentry_tty
;
1720 arg1
= va_arg (ap
, char *);
1721 pwmd_free (pwm
->pinentry_tty
);
1722 pwm
->pinentry_tty
= arg1
? pwmd_strdup (arg1
) : NULL
;
1724 case PWMD_OPTION_PINENTRY_DISPLAY
:
1727 charpp
= va_arg (ap
, char **);
1728 *charpp
= pwm
->pinentry_display
;
1732 arg1
= va_arg (ap
, char *);
1733 pwmd_free (pwm
->pinentry_display
);
1734 pwm
->pinentry_display
= arg1
? pwmd_strdup (arg1
) : NULL
;
1736 case PWMD_OPTION_PINENTRY_TERM
:
1739 charpp
= va_arg (ap
, char **);
1740 *charpp
= pwm
->pinentry_term
;
1744 arg1
= va_arg (ap
, char *);
1745 pwmd_free (pwm
->pinentry_term
);
1746 pwm
->pinentry_term
= arg1
? pwmd_strdup (arg1
) : NULL
;
1748 case PWMD_OPTION_PINENTRY_ERROR
:
1751 charpp
= va_arg (ap
, char **);
1752 *charpp
= pwm
->pinentry_error
;
1756 arg1
= va_arg (ap
, char *);
1757 pwmd_free (pwm
->pinentry_error
);
1758 if (pwm
->disable_pinentry
)
1759 pwm
->pinentry_error
= arg1
? pwmd_strdup (arg1
) : NULL
;
1761 pwm
->pinentry_error
= arg1
? _percent_escape (arg1
) : NULL
;
1763 case PWMD_OPTION_PINENTRY_PROMPT
:
1766 charpp
= va_arg (ap
, char **);
1767 *charpp
= pwm
->pinentry_prompt
;
1771 arg1
= va_arg (ap
, char *);
1772 pwmd_free (pwm
->pinentry_prompt
);
1773 if (pwm
->disable_pinentry
)
1774 pwm
->pinentry_prompt
= arg1
? pwmd_strdup (arg1
) : NULL
;
1776 pwm
->pinentry_prompt
= arg1
? _percent_escape (arg1
) : NULL
;
1778 case PWMD_OPTION_PINENTRY_DESC
:
1781 charpp
= va_arg (ap
, char **);
1782 *charpp
= pwm
->pinentry_desc
;
1786 arg1
= va_arg (ap
, char *);
1787 pwmd_free (pwm
->pinentry_desc
);
1788 if (pwm
->disable_pinentry
)
1789 pwm
->pinentry_desc
= arg1
? pwmd_strdup (arg1
) : NULL
;
1791 pwm
->pinentry_desc
= arg1
? _percent_escape (arg1
) : NULL
;
1793 case PWMD_OPTION_PINENTRY_LC_CTYPE
:
1796 charpp
= va_arg (ap
, char **);
1797 *charpp
= pwm
->pinentry_lcctype
;
1801 arg1
= va_arg (ap
, char *);
1802 pwmd_free (pwm
->pinentry_lcctype
);
1803 pwm
->pinentry_lcctype
= arg1
? pwmd_strdup (arg1
) : NULL
;
1805 case PWMD_OPTION_PINENTRY_LC_MESSAGES
:
1808 charpp
= va_arg (ap
, char **);
1809 *charpp
= pwm
->pinentry_lcmessages
;
1813 arg1
= va_arg (ap
, char *);
1814 pwmd_free (pwm
->pinentry_lcmessages
);
1815 pwm
->pinentry_lcmessages
= arg1
? pwmd_strdup (arg1
) : NULL
;
1817 case PWMD_OPTION_KNOWNHOST_CB
:
1820 pwmd_knownhost_cb_t
*cb
= va_arg (ap
, pwmd_knownhost_cb_t
*);
1826 pwm
->kh_cb
= va_arg (ap
, pwmd_knownhost_cb_t
);
1828 case PWMD_OPTION_KNOWNHOST_DATA
:
1831 void **data
= va_arg (ap
, void **);
1833 *data
= pwm
->kh_data
;
1837 pwm
->kh_data
= va_arg (ap
, void *);
1839 case PWMD_OPTION_SSH_AGENT
:
1842 intp
= va_arg (ap
, int *);
1843 *intp
= pwm
->use_agent
;
1847 pwm
->use_agent
= va_arg (ap
, int);
1849 if (pwm
->use_agent
< 0 || pwm
->use_agent
> 1)
1852 rc
= GPG_ERR_INV_VALUE
;
1855 case PWMD_OPTION_SSH_NEEDS_PASSPHRASE
:
1858 intp
= va_arg (ap
, int *);
1859 *intp
= pwm
->needs_passphrase
;
1863 pwm
->needs_passphrase
= va_arg (ap
, int);
1865 if (pwm
->needs_passphrase
< 0 || pwm
->needs_passphrase
> 1)
1867 pwm
->needs_passphrase
= 0;
1868 rc
= GPG_ERR_INV_VALUE
;
1871 case PWMD_OPTION_TLS_VERIFY
:
1874 intp
= va_arg (ap
, int *);
1875 *intp
= pwm
->tls_verify
;
1879 pwm
->tls_verify
= va_arg (ap
, int);
1881 if (pwm
->tls_verify
< 0 || pwm
->tls_verify
> 1)
1883 pwm
->tls_verify
= 0;
1884 rc
= GPG_ERR_INV_VALUE
;
1887 case PWMD_OPTION_SOCKET_TIMEOUT
:
1890 intp
= va_arg (ap
, int *);
1891 *intp
= pwm
->socket_timeout
;
1895 pwm
->socket_timeout
= va_arg (ap
, int);
1896 if (pwm
->socket_timeout
< 0)
1898 pwm
->socket_timeout
= 0;
1899 rc
= GPG_ERR_INV_VALUE
;
1903 if (pwm
->tcp
&& pwm
->tcp
->ssh
&& pwm
->tcp
->ssh
->session
)
1905 pwm
->tcp
->ssh
->timeout
= pwm
->socket_timeout
;
1906 libssh2_session_set_timeout (pwm
->tcp
->ssh
->session
,
1907 pwm
->socket_timeout
* 1000);
1911 if (pwm
->tcp
&& pwm
->tcp
->tls
&& pwm
->tcp
->tls
->session
)
1912 pwm
->tcp
->tls
->timeout
= pwm
->socket_timeout
;
1915 case PWMD_OPTION_OVERRIDE_INQUIRE
:
1918 intp
= va_arg (ap
, int *);
1919 *intp
= pwm
->override_inquire
;
1923 pwm
->override_inquire
= va_arg (ap
, int);
1925 if (pwm
->override_inquire
< 0 || pwm
->override_inquire
> 1)
1927 pwm
->override_inquire
= 0;
1928 rc
= GPG_ERR_INV_VALUE
;
1932 rc
= GPG_ERR_UNKNOWN_OPTION
;
1940 pwmd_setopt (pwm_t
* pwm
, int opt
, ...)
1946 rc
= pwmd_get_set_opt (pwm
, opt
, 0, ap
);
1952 pwmd_getopt (pwm_t
*pwm
, int opt
, ...)
1958 rc
= pwmd_get_set_opt (pwm
, opt
, 1, ap
);
1964 pwmd_new (const char *name
, pwm_t
** pwm
)
1966 pwm_t
*h
= pwmd_calloc (1, sizeof (pwm_t
));
1970 return FINISH (GPG_ERR_ENOMEM
);
1974 h
->name
= pwmd_strdup (name
);
1978 return FINISH (GPG_ERR_ENOMEM
);
1983 h
->pinentry_timeout
= -1;
1984 h
->current_pinentry_timeout
= -1;
1985 h
->pinentry_tries
= 3;
1986 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
1987 h
->prot
= PWMD_IP_ANY
;
1990 if (isatty (STDOUT_FILENO
))
1993 int err
= ttyname_r (STDOUT_FILENO
, buf
, sizeof (buf
));
1997 h
->pinentry_tty
= pwmd_strdup (buf
);
1998 if (!h
->pinentry_tty
)
2000 rc
= GPG_ERR_ENOMEM
;
2006 if (getenv ("TERM") && h
->pinentry_tty
)
2008 h
->pinentry_term
= pwmd_strdup (getenv ("TERM"));
2009 if (!h
->pinentry_term
)
2011 rc
= GPG_ERR_ENOMEM
;
2016 if (getenv ("DISPLAY"))
2018 h
->pinentry_display
= pwmd_strdup (getenv ("DISPLAY"));
2019 if (!h
->pinentry_display
)
2021 rc
= GPG_ERR_ENOMEM
;
2035 pwmd_free (void *ptr
)
2041 pwmd_malloc (size_t size
)
2043 return _xmalloc (size
);
2047 pwmd_calloc (size_t nmemb
, size_t size
)
2049 return _xcalloc (nmemb
, size
);
2053 pwmd_realloc (void *ptr
, size_t size
)
2055 return _xrealloc (ptr
, size
);
2059 pwmd_strdup (const char *str
)
2066 t
= _xmalloc ((len
+ 1) * sizeof (char));
2070 for (c
= 0; c
< len
; c
++)
2078 pwmd_strdup_printf (const char *fmt
, ...)
2089 len
= vsnprintf (NULL
, 0, fmt
, ap
);
2091 buf
= pwmd_malloc (++len
);
2093 vsnprintf (buf
, len
, fmt
, ap2
);
2100 pwmd_getpin (pwm_t
* pwm
, const char *filename
, char **result
,
2101 size_t * len
, pwmd_pinentry_t which
)
2103 #ifndef WITH_PINENTRY
2104 return FINISH (GPG_ERR_NOT_IMPLEMENTED
);
2108 command_start (pwm
);
2109 if (which
== PWMD_PINENTRY_CONFIRM
&& pwm
->disable_pinentry
)
2111 rc
= get_password (pwm
, NULL
, NULL
, which
, 1);
2115 rc
= _pwmd_getpin (pwm
, filename
, result
, len
, which
);
2123 return LIBPWMD_VERSION_STR
;
2131 #ifdef WITH_PINENTRY
2132 n
|= PWMD_FEATURE_PINENTRY
;
2135 n
|= PWMD_FEATURE_SSH
;
2138 n
|= PWMD_FEATURE_QUALITY
;
2141 n
|= PWMD_FEATURE_GNUTLS
;
2147 pwmd_fd (pwm_t
* pwm
, int *fd
)
2150 return FINISH (GPG_ERR_INV_ARG
);
2153 return FINISH (GPG_ERR_INV_STATE
);
2160 pwmd_set_pointer (pwm_t
*pwm
, void *data
)
2162 pwm
->user_data
= data
;
2166 pwmd_get_pointer (pwm_t
*pwm
)
2168 return pwm
->user_data
;
2172 pwmd_gnutls_error (pwm_t
*pwm
, const char **str
)
2177 if (str
&& pwm
&& pwm
->tls_error
)
2178 *str
= gnutls_strerror (pwm
->tls_error
);
2180 return pwm
? pwm
->tls_error
: 0;
2185 pwmd_cancel (pwm_t
*pwm
)
2188 return FINISH (GPG_ERR_INV_ARG
);
2190 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
2191 if (pwm
->fd
== -1 && !pwm
->tcp
)
2195 return FINISH (GPG_ERR_INV_STATE
);
2197 /* Can only cancel the connection for the time being. */
2199 return FINISH (GPG_ERR_INV_STATE
);
2206 pwmd_test_quality (const char *str
, double *result
)
2208 #ifndef WITH_QUALITY
2209 return GPG_ERR_NOT_IMPLEMENTED
;
2212 return GPG_ERR_INV_ARG
;
2214 *result
= ZxcvbnMatch (str
, NULL
, NULL
);