1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2008 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
26 #include <sys/socket.h>
35 #include <sys/types.h>
37 #include <sys/select.h>
39 #include <netinet/in.h>
40 #include <sys/socket.h>
52 #define DNS_USE_GETTIMEOFDAY_FOR_ID 1
54 #include <arpa/nameser.h>
57 GCRY_THREAD_OPTION_PTH_IMPL
;
70 #define N_(msgid) dgettext("libpwmd", msgid)
76 #define xrealloc realloc
77 #define xmalloc malloc
78 #define xstrdup strdup
79 #define xcalloc calloc
86 static int gelapsed
, gtimeout
;
87 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
);
88 static gpg_error_t global_error
;
91 const char *pwmd_strerror(gpg_error_t e
)
93 gpg_err_code_t code
= gpg_err_code(e
);
95 if (code
>= GPG_ERR_USER_1
&& code
< gpg_err_code(EPWMD_MAX
)) {
99 return N_("Unknown error");
101 return N_("No cache slots available");
103 return N_("Recursion loop");
105 return N_("No file is open");
107 return N_("General LibXML error");
109 return N_("File modified");
111 return N_("Access denied");
115 return gpg_strerror(e
);
118 gpg_error_t
pwmd_init()
120 static int initialized
;
126 gcry_control (GCRYCTL_SET_THREAD_CBS
, &gcry_threads_pth
);
130 bindtextdomain("libpwmd", LOCALEDIR
);
133 assuan_set_malloc_hooks(xmalloc
, xrealloc
, xfree
);
134 assuan_set_assuan_err_source(GPG_ERR_SOURCE_DEFAULT
);
139 static pwm_t
*_socket_connect_finalize(pwm_t
*pwm
, assuan_context_t ctx
)
142 int n
= assuan_get_active_fds(ctx
, 0, active
, sizeof(active
));
144 pwm
->fd
= n
<= 0 ? -1 : dup(active
[0]);
148 pwm
->pinentry_tries
= 3;
150 assuan_set_pointer(ctx
, pwm
);
155 static int read_hook(assuan_context_t ctx
, assuan_fd_t fd
, void *data
,
156 size_t len
, ssize_t
*ret
)
158 pwm_t
*pwm
= assuan_get_pointer(ctx
);
160 if (!pwm
|| !pwm
->tcp_conn
)
161 *ret
= read((int)fd
, data
, len
);
164 *ret
= libssh2_channel_read(pwm
->tcp_conn
->channel
, data
, len
);
165 } while (*ret
== LIBSSH2_ERROR_EAGAIN
);
168 return *ret
<= 0 ? 0 : 1;
171 static int write_hook(assuan_context_t ctx
, assuan_fd_t fd
, const void *data
,
172 size_t len
, ssize_t
*ret
)
174 pwm_t
*pwm
= assuan_get_pointer(ctx
);
176 if (!pwm
|| !pwm
->tcp_conn
)
177 *ret
= write((int)fd
, data
, len
);
180 *ret
= libssh2_channel_write(pwm
->tcp_conn
->channel
, data
, len
);
181 } while (*ret
== LIBSSH2_ERROR_EAGAIN
);
184 return *ret
<= 0 ? 0 : 1;
187 static void _ssh_deinit(pwmd_tcp_conn_t
*conn
);
188 static void free_tcp_conn(pwmd_tcp_conn_t
*conn
)
193 if (conn
->username
) {
194 xfree(conn
->username
);
195 conn
->username
= NULL
;
198 if (conn
->known_hosts
) {
199 xfree(conn
->known_hosts
);
200 conn
->known_hosts
= NULL
;
203 if (conn
->identity
) {
204 xfree(conn
->identity
);
205 conn
->identity
= NULL
;
208 if (conn
->identity_pub
) {
209 xfree(conn
->identity_pub
);
210 conn
->identity_pub
= NULL
;
219 xfree(conn
->hostkey
);
220 conn
->hostkey
= NULL
;
224 ares_destroy(conn
->chan
);
229 ares_free_hostent(conn
->he
);
244 static void _ssh_deinit(pwmd_tcp_conn_t
*conn
)
250 libssh2_channel_free(conn
->channel
);
253 libssh2_session_disconnect(conn
->session
, "Bye!");
254 libssh2_session_free(conn
->session
);
257 conn
->session
= NULL
;
258 conn
->channel
= NULL
;
262 static void _ssh_assuan_deinit(assuan_context_t ctx
)
264 pwm_t
*pwm
= assuan_get_pointer(ctx
);
266 _ssh_deinit(pwm
->tcp_conn
);
270 * Sets common options from both pwmd_tcp_connect() and
271 * pwmd_tcp_connect_async().
273 static gpg_error_t
init_tcp_conn(pwmd_tcp_conn_t
**dst
, const char *host
,
274 int port
, const char *identity
, const char *user
, const char *hosts
,
277 pwmd_tcp_conn_t
*conn
;
282 return GPG_ERR_INV_ARG
;
285 if (!host
|| !identity
|| !user
|| !hosts
)
286 return GPG_ERR_INV_ARG
;
289 conn
= xcalloc(1, sizeof(pwmd_tcp_conn_t
));
292 return gpg_error_from_errno(ENOMEM
);
294 conn
->port
= port
== -1 ? 22 : port
;
295 conn
->host
= xstrdup(host
);
298 rc
= gpg_error_from_errno(ENOMEM
);
303 conn
->identity
= xstrdup(identity
);
305 if (!conn
->identity
) {
306 rc
= gpg_error_from_errno(ENOMEM
);
310 conn
->identity_pub
= xmalloc(strlen(conn
->identity
)+5);
312 if (!conn
->identity_pub
) {
313 rc
= gpg_error_from_errno(ENOMEM
);
317 sprintf(conn
->identity_pub
, "%s.pub", conn
->identity
);
318 conn
->username
= xstrdup(user
);
320 if (!conn
->username
) {
321 rc
= gpg_error_from_errno(ENOMEM
);
325 conn
->known_hosts
= xstrdup(hosts
);
327 if (!conn
->known_hosts
) {
328 rc
= gpg_error_from_errno(ENOMEM
);
341 static gpg_error_t
do_connect(pwm_t
*pwm
, int prot
, void *addr
)
343 struct sockaddr_in their_addr
;
345 pwm
->tcp_conn
->fd
= socket(prot
, SOCK_STREAM
, 0);
347 if (pwm
->tcp_conn
->fd
== -1)
348 return gpg_error_from_syserror();
350 if (pwm
->tcp_conn
->async
)
351 fcntl(pwm
->tcp_conn
->fd
, F_SETFL
, O_NONBLOCK
);
353 pwm
->cmd
= ASYNC_CMD_CONNECT
;
354 their_addr
.sin_family
= prot
;
355 their_addr
.sin_port
= htons(pwm
->tcp_conn
->port
);
356 their_addr
.sin_addr
= *((struct in_addr
*)addr
);
357 memset(their_addr
.sin_zero
, '\0', sizeof their_addr
.sin_zero
);
360 if (pth_connect(pwm
->tcp_conn
->fd
, (struct sockaddr
*)&their_addr
,
361 sizeof(their_addr
)) == -1)
363 if (connect(pwm
->tcp_conn
->fd
, (struct sockaddr
*)&their_addr
,
364 sizeof(their_addr
)) == -1)
366 return gpg_error_from_syserror();
371 static gpg_error_t
ares_error_to_pwmd(int status
)
373 if (status
!= ARES_SUCCESS
)
374 warnx("%s", ares_strerror(status
));
380 return GPG_ERR_UNKNOWN_HOST
;
382 return GPG_ERR_EHOSTDOWN
;
384 return GPG_ERR_TIMEOUT
;
386 return gpg_error_from_errno(ENOMEM
);
387 case ARES_ECONNREFUSED
:
388 return GPG_ERR_ECONNREFUSED
;
391 return GPG_ERR_EHOSTUNREACH
;
397 static void dns_resolve_cb(void *arg
, int status
, int timeouts
,
398 unsigned char *abuf
, int alen
)
404 if (status
== ARES_EDESTRUCTION
)
407 if (status
!= ARES_SUCCESS
) {
408 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
412 //FIXME localhost. works with ipv4. maybe local system config error
413 /* Check for an IPv6 address first. */
414 rc
= ares_parse_a_reply(abuf
, alen
, &he
, NULL
, NULL
);
416 if (rc
!= ARES_SUCCESS
) {
417 if (rc
!= ARES_ENODATA
) {
418 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
422 rc
= ares_parse_aaaa_reply(abuf
, alen
, &he
, NULL
, NULL
);
424 if (rc
!= ARES_SUCCESS
) {
425 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
430 pwm
->tcp_conn
->he
= he
;
431 pwm
->tcp_conn
->rc
= do_connect(pwm
, he
->h_addrtype
, he
->h_addr
);
434 pwm_t
*_do_pwmd_tcp_connect_async(const char *host
, int port
,
435 const char *identity
, const char *user
, const char *known_hosts
,
436 gpg_error_t
*rc
, pwmd_async_cmd_t which
)
438 pwmd_tcp_conn_t
*conn
;
441 *rc
= init_tcp_conn(&conn
, host
, port
, identity
, user
, known_hosts
,
442 which
== ASYNC_CMD_HOSTKEY
? 1 : 0);
447 if ((pwm
= (pwm_t
*)xcalloc(1, sizeof(pwm_t
))) == NULL
) {
448 *rc
= gpg_error_from_syserror();
454 pwm
->tcp_conn
= conn
;
455 pwm
->tcp_conn
->cmd
= which
;
457 if (pwm
->tcp_conn
->cmd
== ASYNC_CMD_HOSTKEY
)
458 pwm
->tcp_conn
->get_only
= 1;
460 pwm
->cmd
= ASYNC_CMD_DNS
;
461 pwm
->state
= ASYNC_PROCESS
;
462 ares_init(&pwm
->tcp_conn
->chan
);
463 ares_query(pwm
->tcp_conn
->chan
, pwm
->tcp_conn
->host
, ns_c_any
, ns_t_any
,
464 dns_resolve_cb
, pwm
);
468 pwm_t
*pwmd_tcp_connect_async(const char *host
, int port
, const char *identity
,
469 const char *user
, const char *known_hosts
, gpg_error_t
*rc
)
471 return _do_pwmd_tcp_connect_async(host
, port
, identity
, user
, known_hosts
,
472 rc
, ASYNC_CMD_CONNECT
);
475 void *_ssh_malloc(size_t size
, void **data
)
477 return xmalloc(size
);
480 void _ssh_free(void *ptr
, void **data
)
485 void *_ssh_realloc(void *ptr
, size_t size
, void **data
)
487 return xrealloc(ptr
, size
);
490 static char *to_hex(const char *str
, size_t slen
)
493 char *buf
= xmalloc(slen
*2+1);
498 for (i
= 0, buf
[0] = 0; i
< slen
; i
++) {
501 sprintf(tmp
, "%02x", (unsigned char)str
[i
]);
508 static int verify_host_key(pwm_t
*pwm
)
510 FILE *fp
= fopen(pwm
->tcp_conn
->known_hosts
, "r");
516 buf
= xmalloc(LINE_MAX
);
521 while ((p
= fgets(buf
, LINE_MAX
, fp
))) {
522 if (*p
== '#' || isspace(*p
))
525 if (p
[strlen(p
)-1] == '\n')
528 if (!strcmp(buf
, pwm
->tcp_conn
->hostkey
))
545 static gpg_error_t
authenticate_ssh(pwm_t
*pwm
)
547 const char *fp
= libssh2_hostkey_hash(pwm
->tcp_conn
->session
,
548 LIBSSH2_HOSTKEY_HASH_SHA1
);
551 pwm
->tcp_conn
->hostkey
= to_hex(fp
, 20);
553 if (!pwm
->tcp_conn
->hostkey
)
554 return gpg_error_from_errno(ENOMEM
);
556 if (pwm
->tcp_conn
->get_only
)
559 if (!fp
|| verify_host_key(pwm
))
560 return GPG_ERR_CHECKSUM
;
562 userauth
= libssh2_userauth_list(pwm
->tcp_conn
->session
,
563 pwm
->tcp_conn
->username
, strlen(pwm
->tcp_conn
->username
));
565 if (!userauth
|| !strstr(userauth
, "publickey"))
566 return GPG_ERR_BAD_PIN_METHOD
;
568 if (libssh2_userauth_publickey_fromfile(pwm
->tcp_conn
->session
,
569 pwm
->tcp_conn
->username
, pwm
->tcp_conn
->identity_pub
,
570 pwm
->tcp_conn
->identity
, NULL
))
571 return GPG_ERR_BAD_SECKEY
;
576 static pwm_t
*setup_context(pwm_t
*pwm
, gpg_error_t
*rc
)
578 assuan_context_t ctx
;
579 struct assuan_io_hooks io_hooks
= {read_hook
, write_hook
};
581 pwm
->tcp_conn
->session
= libssh2_session_init_ex(_ssh_malloc
, _ssh_free
,
584 if (!pwm
->tcp_conn
->session
) {
585 *rc
= gpg_error_from_errno(ENOMEM
);
589 if (libssh2_session_startup(pwm
->tcp_conn
->session
, pwm
->tcp_conn
->fd
)) {
590 *rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
594 *rc
= authenticate_ssh(pwm
);
599 /* pwmd_get_hostkey(). */
600 if (pwm
->tcp_conn
->get_only
) {
601 pwm
->result
= xstrdup(pwm
->tcp_conn
->hostkey
);
604 *rc
= gpg_error_from_errno(ENOMEM
);
611 pwm
->tcp_conn
->channel
= libssh2_channel_open_session(pwm
->tcp_conn
->session
);
613 if (!pwm
->tcp_conn
->channel
) {
614 *rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
618 if (libssh2_channel_shell(pwm
->tcp_conn
->channel
)) {
619 *rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
623 assuan_set_io_hooks(&io_hooks
);
624 *rc
= assuan_socket_connect_fd(&ctx
, pwm
->tcp_conn
->fd
, 0, pwm
);
629 assuan_set_finish_handler(ctx
, _ssh_assuan_deinit
);
630 return _socket_connect_finalize(pwm
, ctx
);
633 if (!pwm
->tcp_conn
->async
)
639 static pwm_t
*_do_pwmd_tcp_connect(const char *host
, int port
,
640 const char *identity
, const char *user
, const char *known_hosts
,
641 gpg_error_t
*rc
, int get
)
644 pwmd_tcp_conn_t
*conn
;
646 *rc
= init_tcp_conn(&conn
, host
, port
, identity
, user
, known_hosts
, get
);
651 if ((pwm
= (pwm_t
*)xcalloc(1, sizeof(pwm_t
))) == NULL
) {
652 *rc
= gpg_error_from_errno(ENOMEM
);
656 pwm
->tcp_conn
= conn
;
657 pwm
->tcp_conn
->get_only
= get
;
658 pwm
->cmd
= ASYNC_CMD_DNS
;
659 ares_init(&pwm
->tcp_conn
->chan
);
660 ares_query(pwm
->tcp_conn
->chan
, pwm
->tcp_conn
->host
, ns_c_any
, ns_t_any
,
661 dns_resolve_cb
, pwm
);
663 /* dns_resolve_cb() may have already been called. */
664 if (pwm
->tcp_conn
->rc
) {
665 *rc
= pwm
->tcp_conn
->rc
;
670 * Fake a blocking DNS lookup. libcares does a better job than
680 n
= ares_fds(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
681 ares_timeout(pwm
->tcp_conn
->chan
, NULL
, &tv
);
683 n
= pth_select(n
, &rfds
, &wfds
, NULL
, &tv
);
685 n
= select(n
, &rfds
, &wfds
, NULL
, &tv
);
689 *rc
= gpg_error_from_syserror();
693 *rc
= GPG_ERR_TIMEOUT
;
697 ares_process(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
699 if (pwm
->tcp_conn
->rc
)
701 } while (pwm
->cmd
== ASYNC_CMD_DNS
);
703 if (pwm
->tcp_conn
->rc
) {
704 *rc
= pwm
->tcp_conn
->rc
;
708 return setup_context(pwm
, rc
);
715 pwm_t
*pwmd_tcp_connect(const char *host
, int port
, const char *identity
,
716 const char *user
, const char *known_hosts
, gpg_error_t
*rc
)
718 return _do_pwmd_tcp_connect(host
, port
, identity
, user
, known_hosts
, rc
, 0);
721 /* Must free the result with pwmd_free_result(). */
722 char *pwmd_get_hostkey(const char *host
, int port
, gpg_error_t
*rc
)
727 pwm
= _do_pwmd_tcp_connect(host
, port
, NULL
, NULL
, NULL
, rc
, 1);
732 hostkey
= xstrdup(pwm
->tcp_conn
->hostkey
);
735 *rc
= gpg_error_from_errno(ENOMEM
);
741 pwm_t
*pwmd_get_hostkey_async(const char *host
, int port
, gpg_error_t
*rc
)
743 return _do_pwmd_tcp_connect_async(host
, port
, NULL
, NULL
, NULL
, rc
,
748 pwm_t
*pwmd_connect(const char *path
, gpg_error_t
*rc
)
751 char *socketpath
= NULL
;
753 assuan_context_t ctx
;
756 pw
= getpwuid(getuid());
757 socketpath
= (char *)xmalloc(strlen(pw
->pw_dir
) + strlen("/.pwmd/socket") + 1);
758 sprintf(socketpath
, "%s/.pwmd/socket", pw
->pw_dir
);
761 socketpath
= xstrdup(path
);
763 *rc
= assuan_socket_connect_ext(&ctx
, socketpath
, -1, 0);
769 if ((pwm
= (pwm_t
*)xcalloc(1, sizeof(pwm_t
))) == NULL
) {
770 *rc
= gpg_error_from_syserror();
774 return _socket_connect_finalize(pwm
, ctx
);
777 gpg_error_t
pwmd_pending_line(pwm_t
*pwm
, char **line
, size_t *len
)
780 return GPG_ERR_INV_ARG
;
782 if (assuan_pending_line(pwm
->ctx
))
783 return assuan_read_line(pwm
->ctx
, line
, len
);
785 return GPG_ERR_NO_DATA
;
788 void pwmd_close(pwm_t
*pwm
)
794 assuan_disconnect(pwm
->ctx
);
797 xfree(pwm
->password
);
808 if (pwm
->pinentry_tty
)
809 xfree(pwm
->pinentry_tty
);
811 if (pwm
->pinentry_display
)
812 xfree(pwm
->pinentry_display
);
814 if (pwm
->pinentry_term
)
815 xfree(pwm
->pinentry_term
);
818 xfree(pwm
->filename
);
825 free_tcp_conn(pwm
->tcp_conn
);
831 static int mem_realloc_cb(void *data
, const void *buffer
, size_t len
)
833 membuf_t
*mem
= (membuf_t
*)data
;
839 if ((p
= xrealloc(mem
->buf
, mem
->len
+ len
)) == NULL
)
843 memcpy((char *)mem
->buf
+ mem
->len
, buffer
, len
);
848 void pwmd_free_result(void *data
)
853 static int _inquire_cb(void *data
, const char *keyword
)
855 pwm_t
*pwm
= (pwm_t
*)data
;
857 int flags
= fcntl(pwm
->fd
, F_GETFL
);
859 /* Shouldn't get this far without a callback. */
860 if (!pwm
->inquire_func
)
861 return GPG_ERR_INV_ARG
;
864 * Since the socket file descriptor is probably set to non-blocking, set to
865 * blocking to prevent GPG_ERR_EAGAIN errors. This should be fixes when
866 * asynchronous INQUIRE is supported by either libassuan or a later
869 fcntl(pwm
->fd
, F_SETFL
, 0);
876 rc
= pwm
->inquire_func(pwm
->inquire_data
, keyword
, rc
, &result
, &len
);
877 rc
= gpg_err_code(rc
);
879 if (rc
== GPG_ERR_EOF
|| !rc
) {
880 if (len
<= 0 || !result
|| !*result
) {
885 arc
= assuan_send_data(pwm
->ctx
, result
, len
);
887 if (rc
== GPG_ERR_EOF
) {
898 fcntl(pwm
->fd
, F_SETFL
, flags
);
902 gpg_error_t
pwmd_finalize(pwm_t
*pwm
)
904 if (!pwm
|| pwm
->cmd
== ASYNC_CMD_NONE
|| pwm
->state
!= ASYNC_DONE
)
905 return GPG_ERR_INV_ARG
;
907 pwm
->state
= ASYNC_INIT
;
908 pwm
->cmd
= ASYNC_CMD_NONE
;
911 if (pwm
->cmd
== ASYNC_CMD_CONNECT
|| pwm
->cmd
== ASYNC_CMD_DNS
) {
912 gpg_error_t rc
= pwm
->tcp_conn
->rc
;
919 /* pwm is no longer a valid handle. */
928 return GPG_ERR_INV_ARG
;
932 pwm
->is_open_cmd
= 0;
937 static gpg_error_t
do_nb_command(pwm_t
*pwm
, const char *cmd
, const char *arg
)
941 size_t len
= strlen(cmd
) + 2;
943 len
+= arg
? strlen(arg
) : 0;
945 if (pwm
->state
!= ASYNC_INIT
)
946 return GPG_ERR_INV_STATE
;
948 buf
= (char *)xmalloc(len
);
951 rc
= gpg_error_from_errno(ENOMEM
);
955 snprintf(buf
, len
, "%s %s", cmd
, arg
? arg
: "");
956 rc
= assuan_write_line(pwm
->ctx
, buf
);
960 pwm
->state
= ASYNC_PROCESS
;
966 gpg_error_t
pwmd_open_async(pwm_t
*pwm
, const char *filename
)
968 if (!pwm
|| !filename
)
969 return GPG_ERR_INV_ARG
;
971 /* For pinentry retries. */
972 if (!pwm
->is_open_cmd
) {
974 xfree(pwm
->filename
);
976 pwm
->filename
= xstrdup(filename
);
979 pwm
->is_open_cmd
= 1;
980 return do_nb_command(pwm
, "OPEN", filename
);
983 gpg_error_t
pwmd_save_async(pwm_t
*pwm
)
986 return GPG_ERR_INV_ARG
;
988 return do_nb_command(pwm
, "SAVE", NULL
);
991 static gpg_error_t
parse_assuan_line(pwm_t
*pwm
)
997 rc
= assuan_read_line(pwm
->ctx
, &line
, &len
);
1000 if (line
[0] == 'O' && line
[1] == 'K' &&
1001 (line
[2] == 0 || line
[2] == ' ')) {
1002 pwm
->state
= ASYNC_DONE
;
1004 else if (line
[0] == '#') {
1006 else if (line
[0] == 'S' && (line
[1] == 0 || line
[1] == ' ')) {
1007 if (pwm
->status_func
) {
1008 pwm
->status_func(pwm
->status_data
,
1009 line
[1] == 0 ? line
+1 : line
+2);
1012 else if (line
[0] == 'E' && line
[1] == 'R' && line
[2] == 'R' &&
1013 (line
[3] == 0 || line
[3] == ' ')) {
1016 pwm
->state
= ASYNC_DONE
;
1023 gpg_error_t
pwmd_get_result(pwm_t
*pwm
, const char **result
)
1025 if (!pwm
|| !result
)
1026 return GPG_ERR_INV_ARG
;
1028 if (pwm
->state
!= ASYNC_DONE
)
1029 return GPG_ERR_INV_STATE
;
1032 return GPG_ERR_NO_DATA
;
1034 *result
= pwm
->result
;
1038 pwmd_async_t
pwmd_process(pwm_t
*pwm
, gpg_error_t
*rc
)
1042 struct timeval tv
= {0, 0};
1047 *rc
= GPG_ERR_INV_ARG
;
1052 if (pwm
->cmd
== ASYNC_CMD_DNS
) {
1055 if (pwm
->tcp_conn
->rc
) {
1056 *rc
= pwm
->tcp_conn
->rc
;
1057 close(pwm
->tcp_conn
->fd
);
1058 pwm
->state
= ASYNC_DONE
;
1064 n
= ares_fds(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
1066 /* Shouldn't happen. */
1070 n
= select(n
, &rfds
, &wfds
, NULL
, &tv
);
1073 ares_process(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
1077 else if (pwm
->cmd
== ASYNC_CMD_CONNECT
) {
1078 if (pwm
->tcp_conn
->rc
== GPG_ERR_EINPROGRESS
) {
1080 socklen_t len
= sizeof(int);
1083 FD_SET(pwm
->tcp_conn
->fd
, &fds
);
1084 n
= select(pwm
->tcp_conn
->fd
+1, NULL
, &fds
, NULL
, &tv
);
1086 if (!n
|| !FD_ISSET(pwm
->tcp_conn
->fd
, &fds
))
1089 *rc
= gpg_error_from_syserror();
1090 close(pwm
->tcp_conn
->fd
);
1091 pwm
->state
= ASYNC_DONE
;
1095 ret
= getsockopt(pwm
->tcp_conn
->fd
, SOL_SOCKET
, SO_ERROR
, &n
, &len
);
1097 *rc
= ret
? gpg_error_from_syserror() : gpg_error_from_errno(n
);
1098 close(pwm
->tcp_conn
->fd
);
1099 pwm
->state
= ASYNC_DONE
;
1103 else if (pwm
->tcp_conn
->rc
) {
1104 *rc
= pwm
->tcp_conn
->rc
;
1105 close(pwm
->tcp_conn
->fd
);
1106 pwm
->state
= ASYNC_DONE
;
1110 fcntl(pwm
->tcp_conn
->fd
, F_SETFL
, 0);
1111 setup_context(pwm
, rc
);
1112 pwm
->state
= ASYNC_DONE
;
1118 *rc
= GPG_ERR_INV_ARG
;
1121 else if (pwm
->state
== ASYNC_DONE
)
1123 else if (pwm
->state
== ASYNC_INIT
) {
1124 *rc
= GPG_ERR_INV_STATE
;
1129 FD_SET(pwm
->fd
, &fds
);
1131 n
= pth_select(pwm
->fd
+1, &fds
, NULL
, NULL
, &tv
);
1133 n
= select(pwm
->fd
+1, &fds
, NULL
, NULL
, &tv
);
1137 if (FD_ISSET(pwm
->fd
, &fds
))
1138 *rc
= parse_assuan_line(pwm
);
1141 while (!*rc
&& assuan_pending_line(pwm
->ctx
))
1142 *rc
= parse_assuan_line(pwm
);
1144 if (pwm
->is_open_cmd
&& gpg_err_code(*rc
) == EPWMD_BADKEY
&&
1145 ++pwm
->ntries
< pwm
->pinentry_tries
) {
1146 pwm
->state
= ASYNC_INIT
;
1147 *rc
= pwmd_open_async(pwm
, pwm
->filename
);
1153 static gpg_error_t
assuan_command(pwm_t
*pwm
, assuan_context_t ctx
,
1154 char **result
, const char *cmd
)
1162 rc
= assuan_transact(ctx
, cmd
, mem_realloc_cb
, &data
, _inquire_cb
, pwm
,
1163 pwm
->status_func
, pwm
->status_data
);
1173 mem_realloc_cb(&data
, "", 1);
1174 *result
= (char *)data
.buf
;
1178 return gpg_err_code(rc
);
1181 gpg_error_t
pwmd_inquire(pwm_t
*pwm
, const char *cmd
, pwmd_inquire_fn fn
,
1184 if (!pwm
|| !cmd
|| !fn
)
1185 return GPG_ERR_INV_ARG
;
1187 pwm
->inquire_func
= fn
;
1188 pwm
->inquire_data
= data
;
1189 return assuan_command(pwm
, pwm
->ctx
, NULL
, cmd
);
1192 gpg_error_t
pwmd_terminate_pinentry(pwm_t
*pwm
)
1194 #ifndef WITH_PINENTRY
1195 return GPG_ERR_NOT_IMPLEMENTED
;
1197 if (!pwm
|| pwm
->pid
== -1)
1198 return GPG_ERR_INV_ARG
;
1200 if (kill(pwm
->pid
, 0) == 0) {
1201 if (kill(pwm
->pid
, SIGTERM
) == -1) {
1202 if (kill(pwm
->pid
, SIGKILL
) == -1)
1203 return gpg_error_from_errno(errno
);
1206 pwm
->pin_error
= GPG_ERR_TIMEOUT
;
1209 return gpg_error_from_errno(errno
);
1215 #ifdef WITH_PINENTRY
1216 static gpg_error_t
set_pinentry_strings(pwm_t
*pwm
, int which
)
1219 char tmp
[ASSUAN_LINELENGTH
];
1223 pwm
->title
= xstrdup(N_("LibPWMD"));
1226 pwm
->prompt
= xstrdup(N_("Passphrase:"));
1228 if (!pwm
->desc
&& !which
)
1229 pwm
->desc
= xstrdup(N_("Enter a passphrase."));
1232 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Invalid passphrase, please try again."));
1235 else if (which
== 2) {
1236 snprintf(tmp
, sizeof(tmp
), "SETERROR %s", N_("Please type the passphrase again for confirmation."));
1240 buf
= (char *)xmalloc(strlen("SETERROR ") + strlen(pwm
->desc
) + 1);
1241 sprintf(buf
, "SETERROR %s", pwm
->desc
);
1244 error
= pinentry_command(pwm
, NULL
, buf
);
1250 buf
= (char *)xmalloc(strlen("SETPROMPT ") + strlen(pwm
->prompt
) + 1);
1251 sprintf(buf
, "SETPROMPT %s", pwm
->prompt
);
1252 error
= pinentry_command(pwm
, NULL
, buf
);
1258 buf
= (char *)xmalloc(strlen("SETDESC ") + strlen(pwm
->title
) + 1);
1259 sprintf(buf
, "SETDESC %s", pwm
->title
);
1260 error
= pinentry_command(pwm
, NULL
, buf
);
1265 static void update_pinentry_settings(pwm_t
*pwm
)
1269 struct passwd
*pw
= getpwuid(getuid());
1272 snprintf(buf
, sizeof(buf
), "%s/.pwmd/pinentry.conf", pw
->pw_dir
);
1274 if ((fp
= fopen(buf
, "r")) == NULL
)
1277 while ((p
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
1278 char name
[32], val
[256];
1280 if (sscanf(p
, " %31[a-zA-Z] = %255s", name
, val
) != 2)
1283 if (strcasecmp(name
, "TTYNAME") == 0) {
1284 xfree(pwm
->pinentry_tty
);
1285 pwm
->pinentry_tty
= xstrdup(val
);
1287 else if (strcasecmp(name
, "TTYTYPE") == 0) {
1288 xfree(pwm
->pinentry_term
);
1289 pwm
->pinentry_term
= xstrdup(val
);
1291 else if (strcasecmp(name
, "DISPLAY") == 0) {
1292 xfree(pwm
->pinentry_display
);
1293 pwm
->pinentry_display
= xstrdup(val
);
1295 else if (strcasecmp(name
, "PATH") == 0) {
1296 xfree(pwm
->pinentry_path
);
1297 pwm
->pinentry_path
= xstrdup(val
);
1304 static gpg_error_t
launch_pinentry(pwm_t
*pwm
)
1307 assuan_context_t ctx
;
1308 int child_list
[] = {-1};
1309 char *display
= getenv("DISPLAY");
1310 const char *argv
[6];
1311 int have_display
= 0;
1314 update_pinentry_settings(pwm
);
1316 if (pwm
->pinentry_display
|| display
)
1319 tty
= pwm
->pinentry_tty
? pwm
->pinentry_tty
: ttyname(STDOUT_FILENO
);
1322 return gpg_error_from_errno(errno
);
1325 if (!have_display
&& !tty
)
1326 return GPG_ERR_ENOTTY
;
1328 argv
[0] = "pinentry";
1329 argv
[1] = have_display
? "--display" : "--ttyname";
1330 argv
[2] = have_display
? pwm
->pinentry_display
? pwm
->pinentry_display
: display
: tty
;
1333 if (!have_display
) {
1334 argv
[3] = "--ttytype";
1335 argv
[4] = pwm
->pinentry_term
? pwm
->pinentry_term
: getenv("TERM");
1339 rc
= assuan_pipe_connect(&ctx
, pwm
->pinentry_path
? pwm
->pinentry_path
: PINENTRY_PATH
, argv
, child_list
);
1344 pwm
->pid
= assuan_get_pid(ctx
);
1346 return set_pinentry_strings(pwm
, 0);
1349 static gpg_error_t
pinentry_command(pwm_t
*pwm
, char **result
, const char *cmd
)
1354 n
= launch_pinentry(pwm
);
1360 return assuan_command(pwm
, pwm
->pctx
, result
, cmd
);
1363 static void pinentry_disconnect(pwm_t
*pwm
)
1366 assuan_disconnect(pwm
->pctx
);
1373 * Only called from a child process.
1375 static void catchsig(int sig
)
1379 if (gelapsed
++ >= gtimeout
) {
1380 global_error
= pwmd_terminate_pinentry(gpwm
);
1383 global_error
= GPG_ERR_TIMEOUT
;
1396 * Borrowed from libassuan.
1398 static char *percent_escape(const char *atext
)
1400 const unsigned char *s
;
1401 int len
= strlen(atext
) * 3 + 1;
1402 char *buf
= (char *)xmalloc(len
), *p
= buf
;
1407 for (s
=(const unsigned char *)atext
; *s
; s
++) {
1409 sprintf (p
, "%%%02X", *s
);
1421 static gpg_error_t
send_command(pwm_t
*pwm
, char **result
, const char *cmd
)
1424 return GPG_ERR_INV_ARG
;
1426 return assuan_command(pwm
, pwm
->ctx
, result
, cmd
);
1429 gpg_error_t
pwmd_command_ap(pwm_t
*pwm
, char **result
, const char *cmd
,
1437 * C99 allows the dst pointer to be null which will calculate the length
1438 * of the would-be result and return it.
1440 len
= vsnprintf(NULL
, 0, cmd
, ap
)+1;
1441 buf
= (char *)xmalloc(len
);
1442 len
= vsnprintf(buf
, len
, cmd
, ap
);
1443 error
= send_command(pwm
, result
, buf
);
1449 * Avoid sending the BYE command here. libassuan will close the file
1450 * descriptor and release the assuan context. Use pwmd_close() instead.
1452 gpg_error_t
pwmd_command(pwm_t
*pwm
, char **result
, const char *cmd
, ...)
1458 return GPG_ERR_INV_ARG
;
1462 error
= pwmd_command_ap(pwm
, result
, cmd
, ap
);
1467 #ifdef WITH_PINENTRY
1468 static gpg_error_t
do_getpin(pwm_t
*pwm
, char **result
)
1471 signal(SIGALRM
, catchsig
);
1476 return pinentry_command(pwm
, result
, "GETPIN");
1479 static gpg_error_t
getpin(pwm_t
*pwm
, char **result
, int *try_n
, int which
)
1481 int pin_try
= *try_n
;
1487 if (pin_try
== -1) {
1488 error
= set_pinentry_strings(pwm
, which
);
1491 pinentry_disconnect(pwm
);
1496 if (pwm
->pinentry_tries
-1 != pin_try
) {
1497 error
= set_pinentry_strings(pwm
, 1);
1500 pinentry_disconnect(pwm
);
1506 error
= do_getpin(pwm
, result
);
1509 * Since there was input cancel any timeout setting.
1514 if (error
== GPG_ERR_CANCELED
)
1515 return GPG_ERR_CANCELED
;
1517 if (pin_try
!= -1 && pin_try
--)
1521 pinentry_disconnect(pwm
);
1531 gpg_error_t
pwmd_open_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
1535 #ifndef WITH_PINENTRY
1536 return GPG_ERR_NOT_IMPLEMENTED
;
1539 if (!pwm
|| !pw
|| !pw
->filename
[0])
1540 return GPG_ERR_INV_ARG
;
1550 xfree(pwm
->filename
);
1552 pwm
->filename
= xstrdup(pw
->filename
);
1553 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1557 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1561 static gpg_error_t
do_open_command(pwm_t
*pwm
, const char *filename
, char *password
)
1563 char buf
[ASSUAN_LINELENGTH
];
1565 char *result
= NULL
;
1567 snprintf(buf
, sizeof(buf
), "OPEN %s %s", filename
, password
? password
: "");
1568 error
= send_command(pwm
, &result
, buf
);
1569 memset(buf
, 0, sizeof(buf
));
1571 if (error
&& result
)
1577 static int do_pwmd_open(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
1578 int nb
, int timeout
)
1580 char *result
= NULL
;
1581 char *password
= NULL
;
1582 char path
[PATH_MAX
];
1583 #ifdef WITH_PINENTRY
1587 if (!pwm
|| !filename
|| !*filename
) {
1588 *error
= GPG_ERR_INV_ARG
;
1592 #ifdef WITH_PINENTRY
1593 pin_try
= pwm
->pinentry_tries
- 1;
1597 * Avoid calling pinentry if the password is cached on the server or if
1598 * this is a new file.
1600 *error
= pwmd_command(pwm
, &result
, "GETCONFIG data_directory");
1605 snprintf(path
, sizeof(path
), "%s/%s", result
, filename
);
1606 pwmd_free_result(result
);
1608 if (access(path
, R_OK
) == -1) {
1609 if (errno
== ENOENT
)
1613 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", filename
);
1615 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1616 if (pwm
->passfunc
) {
1617 password
= pwm
->passfunc(pwm
, pwm
->passdata
);
1621 #ifdef WITH_PINENTRY
1623 * Get the password from pinentry.
1625 if (pwm
->use_pinentry
) {
1627 * Nonblocking is wanted. fork() then return a file descriptor
1628 * that the client can use to read() from.
1633 pwmd_nb_status_t pw
;
1635 if (pipe(p
) == -1) {
1636 *error
= gpg_error_from_syserror();
1649 strncpy(pw
.filename
, filename
, sizeof(pw
.filename
));
1650 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1660 *error
= getpin(pwm
, &password
, &pin_try
, 0);
1665 pinentry_disconnect(pwm
);
1667 if (gtimeout
&& gelapsed
>= gtimeout
)
1668 *error
= GPG_ERR_TIMEOUT
;
1672 pth_write(p
[1], &pw
, sizeof(pw
));
1674 write(p
[1], &pw
, sizeof(pw
));
1681 * Don't count the time it takes to open the file
1682 * which may have many iterations.
1684 signal(SIGALRM
, SIG_DFL
);
1685 *error
= do_open_command(pwm
, filename
, password
);
1688 signal(SIGALRM
, catchsig
);
1690 if (pwm
->pctx
&& *error
== EPWMD_BADKEY
) {
1692 goto getpin_nb_again
;
1694 goto getpin_nb_fail
;
1697 pinentry_disconnect(pwm
);
1700 pth_write(p
[1], &pw
, sizeof(pw
));
1702 write(p
[1], &pw
, sizeof(pw
));
1708 *error
= gpg_error_from_syserror();
1724 * Not using pinentry and the file was not found
1727 password
= pwm
->password
;
1728 #ifdef WITH_PINENTRY
1736 *error
= do_open_command(pwm
, filename
, password
);
1739 * Keep the user defined password set with pwmd_setopt(). The password may
1740 * be needed later (pwmd_save()) depending on the pwmd file cache settings.
1742 if (password
&& password
!= pwm
->password
)
1745 #ifdef WITH_PINENTRY
1746 if (*error
== EPWMD_BADKEY
) {
1747 if (pin_try
-- > 0 && !nb
) {
1748 *error
= pwmd_command(pwm
, &result
, "OPTION TITLE=%s",
1749 N_("Invalid passphrase, please try again."));
1758 pinentry_disconnect(pwm
);
1766 xfree(pwm
->filename
);
1768 pwm
->filename
= xstrdup(filename
);
1772 * The file is cached or the file is a new file.
1775 return *error
? -1 : -2;
1777 return *error
? 1 : 0;
1780 gpg_error_t
pwmd_open(pwm_t
*pwm
, const char *filename
)
1784 do_pwmd_open(pwm
, &error
, filename
, 0, 0);
1788 int pwmd_open_nb(pwm_t
*pwm
, gpg_error_t
*error
, const char *filename
,
1791 #ifndef WITH_PINENTRY
1792 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1795 return do_pwmd_open(pwm
, error
, filename
, 1, timeout
);
1799 #ifdef WITH_PINENTRY
1800 static gpg_error_t
do_save_getpin(pwm_t
*pwm
, char **password
)
1804 char *result
= NULL
;
1808 error
= getpin(pwm
, &result
, &pin_try
, confirm
? 2 : 0);
1812 pinentry_disconnect(pwm
);
1825 if (strcmp(*password
, result
)) {
1828 pinentry_disconnect(pwm
);
1829 error
= EPWMD_BADKEY
;
1834 pinentry_disconnect(pwm
);
1839 static gpg_error_t
do_save_command(pwm_t
*pwm
, char *password
)
1841 char buf
[ASSUAN_LINELENGTH
];
1843 char *result
= NULL
;
1845 snprintf(buf
, sizeof(buf
), "SAVE %s", password
? password
: "");
1846 error
= send_command(pwm
, &result
, buf
);
1847 memset(&buf
, 0, sizeof(buf
));
1849 if (error
&& result
)
1855 gpg_error_t
pwmd_save_nb_finalize(pwm_t
*pwm
, pwmd_nb_status_t
*pw
)
1859 #ifndef WITH_PINENTRY
1860 return GPG_ERR_NOT_IMPLEMENTED
;
1863 if (!pwm
|| !pw
|| !pw
->filename
[0])
1864 return GPG_ERR_INV_ARG
;
1868 memset(pw
, 0, sizeof(pwmd_nb_status_t
));
1872 static int do_pwmd_save(pwm_t
*pwm
, gpg_error_t
*error
, int nb
)
1874 char *result
= NULL
;
1875 char *password
= NULL
;
1878 *error
= GPG_ERR_INV_ARG
;
1882 if (pwm
->use_pinentry
|| pwm
->passfunc
) {
1883 *error
= pwmd_command(pwm
, &result
, "ISCACHED %s", pwm
->filename
);
1885 if (*error
== EPWMD_CACHE_NOT_FOUND
) {
1886 #ifdef WITH_PINENTRY
1887 if (pwm
->use_pinentry
) {
1891 pwmd_nb_status_t pw
;
1893 if (pipe(p
) == -1) {
1894 *error
= gpg_error_from_syserror();
1907 strncpy(pw
.filename
, pwm
->filename
, sizeof(pw
.filename
));
1908 pw
.filename
[sizeof(pw
.filename
)-1] = 0;
1913 *error
= do_save_getpin(pwm
, &password
);
1914 } while (*error
== EPWMD_BADKEY
);
1918 pinentry_disconnect(pwm
);
1922 pth_write(p
[1], &pw
, sizeof(pw
));
1924 write(p
[1], &pw
, sizeof(pw
));
1930 *error
= do_save_command(pwm
, password
);
1931 pinentry_disconnect(pwm
);
1934 pth_write(p
[1], &pw
, sizeof(pw
));
1936 write(p
[1], &pw
, sizeof(pw
));
1942 *error
= gpg_error_from_syserror();
1955 *error
= do_save_getpin(pwm
, &password
);
1963 password
= (*pwm
->passfunc
)(pwm
, pwm
->passdata
);
1964 #ifdef WITH_PINENTRY
1974 password
= pwm
->password
;
1976 *error
= do_save_command(pwm
, password
);
1978 if (password
&& password
!= pwm
->password
)
1982 return *error
? -1 : -2;
1984 return *error
? 1 : 0;
1987 int pwmd_save_nb(pwm_t
*pwm
, gpg_error_t
*error
)
1989 #ifndef WITH_PINENTRY
1990 *error
= GPG_ERR_NOT_IMPLEMENTED
;
1993 return do_pwmd_save(pwm
, error
, 1);
1997 gpg_error_t
pwmd_save(pwm_t
*pwm
)
2001 do_pwmd_save(pwm
, &error
, 0);
2005 gpg_error_t
pwmd_setopt(pwm_t
*pwm
, pwmd_option_t opt
, ...)
2008 #ifdef WITH_PINENTRY
2009 int n
= va_arg(ap
, int);
2013 gpg_error_t error
= 0;
2016 return GPG_ERR_INV_ARG
;
2021 case PWMD_OPTION_STATUS_FUNC
:
2022 pwm
->status_func
= va_arg(ap
, pwmd_status_fn
);
2024 case PWMD_OPTION_STATUS_DATA
:
2025 pwm
->status_data
= va_arg(ap
, void *);
2027 case PWMD_OPTION_PASSWORD_FUNC
:
2028 pwm
->passfunc
= va_arg(ap
, pwmd_password_fn
);
2030 case PWMD_OPTION_PASSWORD_DATA
:
2031 pwm
->passdata
= va_arg(ap
, void *);
2033 case PWMD_OPTION_PASSWORD
:
2034 arg1
= va_arg(ap
, char *);
2037 xfree(pwm
->password
);
2039 pwm
->password
= xstrdup(arg1
);
2041 #ifdef WITH_PINENTRY
2042 case PWMD_OPTION_PINENTRY
:
2043 n
= va_arg(ap
, int);
2045 if (n
!= 0 && n
!= 1) {
2047 error
= GPG_ERR_INV_VALUE
;
2050 pwm
->use_pinentry
= n
;
2051 error
= pwmd_command(pwm
, &result
, "OPTION PINENTRY=%i",
2052 !pwm
->use_pinentry
);
2055 case PWMD_OPTION_PINENTRY_TRIES
:
2056 n
= va_arg(ap
, int);
2060 error
= GPG_ERR_INV_VALUE
;
2063 pwm
->pinentry_tries
= n
;
2065 case PWMD_OPTION_PINENTRY_PATH
:
2066 if (pwm
->pinentry_path
)
2067 xfree(pwm
->pinentry_path
);
2069 pwm
->pinentry_path
= xstrdup(va_arg(ap
, char *));
2071 case PWMD_OPTION_PINENTRY_TTY
:
2072 if (pwm
->pinentry_tty
)
2073 xfree(pwm
->pinentry_tty
);
2075 pwm
->pinentry_tty
= xstrdup(va_arg(ap
, char *));
2077 case PWMD_OPTION_PINENTRY_DISPLAY
:
2078 if (pwm
->pinentry_display
)
2079 xfree(pwm
->pinentry_display
);
2081 pwm
->pinentry_display
= xstrdup(va_arg(ap
, char *));
2083 case PWMD_OPTION_PINENTRY_TERM
:
2084 if (pwm
->pinentry_term
)
2085 xfree(pwm
->pinentry_term
);
2087 pwm
->pinentry_term
= xstrdup(va_arg(ap
, char *));
2089 case PWMD_OPTION_PINENTRY_TITLE
:
2092 pwm
->title
= percent_escape(va_arg(ap
, char *));
2094 case PWMD_OPTION_PINENTRY_PROMPT
:
2097 pwm
->prompt
= percent_escape(va_arg(ap
, char *));
2099 case PWMD_OPTION_PINENTRY_DESC
:
2102 pwm
->desc
= percent_escape(va_arg(ap
, char *));
2105 case PWMD_OPTION_PINENTRY
:
2106 case PWMD_OPTION_PINENTRY_TRIES
:
2107 case PWMD_OPTION_PINENTRY_PATH
:
2108 case PWMD_OPTION_PINENTRY_TTY
:
2109 case PWMD_OPTION_PINENTRY_DISPLAY
:
2110 case PWMD_OPTION_PINENTRY_TERM
:
2111 case PWMD_OPTION_PINENTRY_TITLE
:
2112 case PWMD_OPTION_PINENTRY_PROMPT
:
2113 case PWMD_OPTION_PINENTRY_DESC
:
2114 error
= GPG_ERR_NOT_IMPLEMENTED
;
2118 error
= GPG_ERR_NOT_IMPLEMENTED
;
2127 * Prevent requiring assuan.h when setting ctx. The ctx is really an
2128 * assuan_context_t *.
2130 gpg_error_t
pwmd_assuan_ctx(pwm_t
*pwm
, void *ctx
, int *fd
)
2133 return GPG_ERR_INV_ARG
;