1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2009 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 <netinet/in.h>
27 #include <sys/socket.h>
28 #include <arpa/inet.h>
42 static gpg_error_t
ssh_connect_finalize(pwm_t
*pwm
);
44 static void ssh_deinit(pwmd_tcp_conn_t
*conn
)
50 libssh2_channel_close(conn
->channel
);
51 libssh2_channel_free(conn
->channel
);
55 libssh2_session_disconnect(conn
->session
, N_("libpwmd saying bye!"));
56 libssh2_session_free(conn
->session
);
64 static int read_hook(assuan_context_t ctx
, assuan_fd_t fd
, void *data
,
65 size_t len
, ssize_t
*ret
)
67 pwm_t
*pwm
= assuan_get_pointer(ctx
);
69 if (!pwm
|| !pwm
->tcp_conn
)
71 *ret
= pth_recv((int)fd
, data
, len
, 0);
73 *ret
= recv((int)fd
, data
, len
, 0);
76 *ret
= libssh2_channel_read(pwm
->tcp_conn
->channel
, data
, len
);
78 return *ret
>= 0 ? 1 : 0;
81 static int write_hook(assuan_context_t ctx
, assuan_fd_t fd
, const void *data
,
82 size_t len
, ssize_t
*ret
)
84 pwm_t
*pwm
= assuan_get_pointer(ctx
);
86 if (!pwm
|| !pwm
->tcp_conn
)
88 *ret
= pth_send((int)fd
, data
, len
, 0);
90 *ret
= send((int)fd
, data
, len
, 0);
93 *ret
= libssh2_channel_write(pwm
->tcp_conn
->channel
, data
, len
);
95 return *ret
>= 0 ? 1 : 0;
98 void _free_ssh_conn(pwmd_tcp_conn_t
*conn
)
103 if (conn
->username
) {
104 pwmd_free(conn
->username
);
105 conn
->username
= NULL
;
108 if (conn
->known_hosts
) {
109 pwmd_free(conn
->known_hosts
);
110 conn
->known_hosts
= NULL
;
113 if (conn
->identity
) {
114 pwmd_free(conn
->identity
);
115 conn
->identity
= NULL
;
118 if (conn
->identity_pub
) {
119 pwmd_free(conn
->identity_pub
);
120 conn
->identity_pub
= NULL
;
124 pwmd_free(conn
->host
);
129 pwmd_free(conn
->hostkey
);
130 conn
->hostkey
= NULL
;
134 ares_destroy(conn
->chan
);
139 ares_free_hostent(conn
->he
);
143 if (!conn
->session
&& conn
->fd
>= 0) {
154 /* Only called from libassuan after the BYE command. */
155 static void ssh_assuan_deinit(assuan_context_t ctx
)
157 pwm_t
*pwm
= assuan_get_pointer(ctx
);
160 pwm
->tcp_conn
->fd
= -1;
161 ssh_deinit(pwm
->tcp_conn
);
162 pwm
->tcp_conn
= NULL
;
167 * Sets common options from both pwmd_ssh_connect() and
168 * pwmd_ssh_connect_async().
170 static gpg_error_t
init_tcp_conn(pwmd_tcp_conn_t
**dst
, const char *host
,
171 int port
, const char *identity
, const char *user
,
172 const char *known_hosts
, int get
, int resume
)
174 pwmd_tcp_conn_t
*conn
= *dst
;
181 return GPG_ERR_INV_STATE
;
187 return GPG_ERR_INV_ARG
;
190 if (!host
|| !*host
|| !identity
|| !*identity
|| !known_hosts
||
192 return GPG_ERR_INV_ARG
;
196 return GPG_ERR_INV_STATE
;
198 if (!identity
|| !*identity
|| !known_hosts
|| !*known_hosts
)
199 return GPG_ERR_INV_ARG
;
203 conn
= pwmd_calloc(1, sizeof(pwmd_tcp_conn_t
));
206 return gpg_error_from_errno(ENOMEM
);
212 pwbuf
= _getpwuid(&pw
);
215 rc
= gpg_error_from_errno(errno
);
220 pwmd_free(conn
->username
);
222 conn
->username
= pwmd_strdup(user
? user
: pw
.pw_name
);
224 if (!conn
->username
) {
225 rc
= gpg_error_from_errno(ENOMEM
);
230 pwmd_free(conn
->identity
);
232 conn
->identity
= _expand_homedir((char *)identity
, &pw
);
234 if (!conn
->identity
) {
235 rc
= gpg_error_from_errno(ENOMEM
);
239 if (conn
->identity_pub
)
240 pwmd_free(conn
->identity_pub
);
242 conn
->identity_pub
= pwmd_strdup_printf("%s.pub", conn
->identity
);
244 if (!conn
->identity_pub
) {
245 rc
= gpg_error_from_errno(ENOMEM
);
249 if (conn
->known_hosts
)
250 pwmd_free(conn
->known_hosts
);
252 conn
->known_hosts
= _expand_homedir((char *)known_hosts
, &pw
);
254 if (!conn
->known_hosts
) {
255 rc
= gpg_error_from_errno(ENOMEM
);
263 conn
->port
= port
== -1 ? 22 : port
;
264 conn
->host
= pwmd_strdup(host
);
267 rc
= gpg_error_from_errno(ENOMEM
);
280 _free_ssh_conn(conn
);
284 static gpg_error_t
do_connect(pwm_t
*pwm
, int prot
, void *addr
)
286 struct sockaddr_in their_addr
;
288 pwm
->tcp_conn
->fd
= socket(prot
, SOCK_STREAM
, 0);
290 if (pwm
->tcp_conn
->fd
== -1)
291 return gpg_error_from_syserror();
293 if (pwm
->tcp_conn
->async
)
294 fcntl(pwm
->tcp_conn
->fd
, F_SETFL
, O_NONBLOCK
);
296 pwm
->cmd
= ASYNC_CMD_CONNECT
;
297 their_addr
.sin_family
= prot
;
298 their_addr
.sin_port
= htons(pwm
->tcp_conn
->port
);
299 their_addr
.sin_addr
= *((struct in_addr
*)addr
);
300 memset(their_addr
.sin_zero
, '\0', sizeof their_addr
.sin_zero
);
303 if (pth_connect(pwm
->tcp_conn
->fd
, (struct sockaddr
*)&their_addr
,
304 sizeof(their_addr
)) == -1)
306 if (connect(pwm
->tcp_conn
->fd
, (struct sockaddr
*)&their_addr
,
307 sizeof(their_addr
)) == -1)
309 return gpg_error_from_syserror();
314 static gpg_error_t
ares_error_to_pwmd(int status
)
316 if (status
!= ARES_SUCCESS
)
317 warnx("%s", ares_strerror(status
));
320 case ARES_EDESTRUCTION
:
321 return GPG_ERR_CANCELED
;
325 return GPG_ERR_UNKNOWN_HOST
;
327 return GPG_ERR_EHOSTDOWN
;
329 return GPG_ERR_TIMEOUT
;
331 return gpg_error_from_errno(ENOMEM
);
332 case ARES_ECONNREFUSED
:
333 return GPG_ERR_ECONNREFUSED
;
336 return GPG_ERR_EHOSTUNREACH
;
342 static void dns_resolve_cb(void *arg
, int status
, int timeouts
,
343 unsigned char *abuf
, int alen
)
349 if (status
!= ARES_SUCCESS
) {
350 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
354 /* Check for an IPv4 address first. */
355 if (pwm
->prot
== PWMD_IP_ANY
|| pwm
->prot
== PWMD_IPV4
)
356 rc
= ares_parse_a_reply(abuf
, alen
, &he
, NULL
, NULL
);
358 rc
= ares_parse_aaaa_reply(abuf
, alen
, &he
, NULL
, NULL
);
360 if (rc
!= ARES_SUCCESS
) {
361 if (pwm
->prot
!= PWMD_IP_ANY
|| rc
!= ARES_ENODATA
) {
362 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
366 rc
= ares_parse_a_reply(abuf
, alen
, &he
, NULL
, NULL
);
368 if (rc
!= ARES_SUCCESS
) {
369 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
374 pwm
->tcp_conn
->he
= he
;
375 pwm
->tcp_conn
->rc
= do_connect(pwm
, he
->h_addrtype
, he
->h_addr
);
378 gpg_error_t
_do_pwmd_ssh_connect_async(pwm_t
*pwm
, const char *host
,
379 int port
, const char *identity
, const char *user
,
380 const char *known_hosts
, pwmd_async_cmd_t which
)
382 pwmd_tcp_conn_t
*conn
;
387 return GPG_ERR_INV_ARG
;
389 if (pwm
->cmd
!= ASYNC_CMD_NONE
)
390 return GPG_ERR_ASS_NESTED_COMMANDS
;
392 /* Resume an existing connection that may have been started from
393 * pwmd_get_hostkey(). */
396 conn
= pwm
->tcp_conn
;
399 rc
= init_tcp_conn(&conn
, host
, port
, identity
, user
, known_hosts
,
400 which
== ASYNC_CMD_HOSTKEY
? 1 : 0, resume
);
406 pwm
->tcp_conn
= conn
;
407 pwm
->tcp_conn
->cmd
= which
;
408 pwm
->cmd
= resume
? ASYNC_CMD_CONNECT
: ASYNC_CMD_DNS
;
409 pwm
->state
= ASYNC_PROCESS
;
414 ares_init(&pwm
->tcp_conn
->chan
);
416 if (inet_aton(pwm
->tcp_conn
->host
, &addr
)) {
417 pwm
->tcp_conn
->rc
= do_connect(pwm
,
418 pwm
->prot
== PWMD_IP_ANY
||
419 pwm
->prot
== PWMD_IPV4
? PF_INET
: PF_INET6
,
424 ares_query(pwm
->tcp_conn
->chan
, pwm
->tcp_conn
->host
, ns_c_any
,
425 ns_t_any
, dns_resolve_cb
, pwm
);
428 /* There may not be any pending data waiting to be read from the SSH
429 * FD so resume the connection here instead of from pwmd_process(). */
430 rc
= _setup_ssh_session(pwm
);
432 if (rc
== GPG_ERR_EAGAIN
)
439 static void *ssh_malloc(size_t size
, void **data
)
441 return pwmd_malloc(size
);
444 static void ssh_free(void *ptr
, void **data
)
449 static void *ssh_realloc(void *ptr
, size_t size
, void **data
)
451 return pwmd_realloc(ptr
, size
);
454 gpg_error_t
_setup_ssh_auth(pwm_t
*pwm
)
458 pwm
->tcp_conn
->state
= SSH_AUTH
;
459 n
= libssh2_userauth_publickey_fromfile(pwm
->tcp_conn
->session
,
460 pwm
->tcp_conn
->username
, pwm
->tcp_conn
->identity_pub
,
461 pwm
->tcp_conn
->identity
, NULL
);
463 if (n
== LIBSSH2_ERROR_EAGAIN
)
464 return GPG_ERR_EAGAIN
;
466 _free_ssh_conn(pwm
->tcp_conn
);
467 pwm
->tcp_conn
= NULL
;
468 return GPG_ERR_BAD_SECKEY
;
471 return _setup_ssh_channel(pwm
);
474 gpg_error_t
_setup_ssh_authlist(pwm_t
*pwm
)
479 pwm
->tcp_conn
->state
= SSH_AUTHLIST
;
480 userauth
= libssh2_userauth_list(pwm
->tcp_conn
->session
,
481 pwm
->tcp_conn
->username
, strlen(pwm
->tcp_conn
->username
));
482 n
= libssh2_session_last_errno(pwm
->tcp_conn
->session
);
484 if (!userauth
&& n
== LIBSSH2_ERROR_EAGAIN
)
485 return GPG_ERR_EAGAIN
;
487 if (!userauth
|| !strstr(userauth
, "publickey")) {
488 _free_ssh_conn(pwm
->tcp_conn
);
489 pwm
->tcp_conn
= NULL
;
490 return GPG_ERR_BAD_PIN_METHOD
;
493 return _setup_ssh_auth(pwm
);
496 static gpg_error_t
check_known_hosts(pwm_t
*pwm
)
499 const char *key
= libssh2_session_hostkey(pwm
->tcp_conn
->session
, &len
);
502 struct libssh2_knownhost
*kh
;
504 while (!libssh2_knownhost_get(pwm
->tcp_conn
->kh
, &kh
, NULL
))
505 libssh2_knownhost_del(pwm
->tcp_conn
->kh
, kh
);
507 n
= libssh2_knownhost_readfile(pwm
->tcp_conn
->kh
,
508 pwm
->tcp_conn
->known_hosts
, LIBSSH2_KNOWNHOST_FILE_OPENSSH
);
510 if (n
< 0 && pwm
->tcp_conn
->cmd
!= ASYNC_CMD_HOSTKEY
&&
511 n
!= LIBSSH2_ERROR_FILE
)
512 return GPG_ERR_BAD_CERT
;
514 n
= libssh2_knownhost_check(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->host
,
516 LIBSSH2_KNOWNHOST_TYPE_PLAIN
|LIBSSH2_KNOWNHOST_KEYENC_RAW
,
517 &pwm
->tcp_conn
->hostent
);
520 case LIBSSH2_KNOWNHOST_CHECK_MATCH
:
522 case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND
:
523 if (pwm
->tcp_conn
->cmd
!= ASYNC_CMD_HOSTKEY
) {
525 rc
= GPG_ERR_MISSING_CERT
;
527 rc
= pwm
->kh_cb(pwm
->kh_data
, pwm
->tcp_conn
->host
, key
,
534 libssh2_knownhost_add(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->host
, NULL
,
536 LIBSSH2_KNOWNHOST_TYPE_PLAIN
|
537 LIBSSH2_KNOWNHOST_KEYENC_RAW
|
538 LIBSSH2_KNOWNHOST_KEY_SSHRSA
,
539 &pwm
->tcp_conn
->hostent
);
541 /* It's not an error if writing the new host file fails since
542 * there isn't a way to notify the user. The hostkey is still
544 if (pwm
->tcp_conn
->cmd
!= ASYNC_CMD_HOSTKEY
) {
545 char *tmp
= tempnam(NULL
, "khost");
550 if (!libssh2_knownhost_writefile(pwm
->tcp_conn
->kh
, tmp
,
551 LIBSSH2_KNOWNHOST_FILE_OPENSSH
)) {
555 buf
= pwmd_malloc(LINE_MAX
);
562 ifp
= fopen(tmp
, "r");
563 ofp
= fopen(pwm
->tcp_conn
->known_hosts
, "w+");
565 while ((fgets(buf
, LINE_MAX
, ifp
))) {
566 if (fprintf(ofp
, buf
, strlen(buf
)) < 0)
579 case LIBSSH2_KNOWNHOST_CHECK_MISMATCH
:
580 case LIBSSH2_KNOWNHOST_CHECK_FAILURE
:
581 return GPG_ERR_BAD_CERT
;
587 static gpg_error_t
verify_hostkey(pwm_t
*pwm
)
593 if (!pwm
->tcp_conn
->kh
)
594 pwm
->tcp_conn
->kh
= libssh2_knownhost_init(pwm
->tcp_conn
->session
);
596 if (!pwm
->tcp_conn
->kh
)
597 return GPG_ERR_ENOMEM
;
599 rc
= check_known_hosts(pwm
);
604 buf
= pwmd_malloc(LINE_MAX
);
607 return gpg_error_from_errno(ENOMEM
);
609 if (libssh2_knownhost_writeline(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->hostent
,
610 buf
, LINE_MAX
, &outlen
, LIBSSH2_KNOWNHOST_FILE_OPENSSH
)) {
612 return gpg_error_from_errno(ENOMEM
);
615 if (pwm
->tcp_conn
->hostkey
)
616 pwmd_free(pwm
->tcp_conn
->hostkey
);
618 pwm
->tcp_conn
->hostkey
= buf
;
620 if (pwm
->tcp_conn
->cmd
== ASYNC_CMD_HOSTKEY
) {
621 libssh2_knownhost_del(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->hostent
);
622 pwm
->tcp_conn
->hostent
= NULL
;
623 pwm
->tcp_conn
->state
= SSH_RESUME
;
627 return _setup_ssh_authlist(pwm
);
630 gpg_error_t
_setup_ssh_channel(pwm_t
*pwm
)
635 pwm
->tcp_conn
->state
= SSH_CHANNEL
;
636 libssh2_session_set_blocking(pwm
->tcp_conn
->session
, 1);
637 pwm
->tcp_conn
->channel
=
638 libssh2_channel_open_session(pwm
->tcp_conn
->session
);
639 n
= libssh2_session_last_errno(pwm
->tcp_conn
->session
);
641 if (!pwm
->tcp_conn
->channel
&& n
== LIBSSH2_ERROR_EAGAIN
)
642 return GPG_ERR_EAGAIN
;
644 if (!pwm
->tcp_conn
->channel
) {
645 rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
646 _free_ssh_conn(pwm
->tcp_conn
);
647 pwm
->tcp_conn
= NULL
;
651 return _setup_ssh_shell(pwm
);
654 gpg_error_t
_setup_ssh_shell(pwm_t
*pwm
)
659 pwm
->tcp_conn
->state
= SSH_SHELL
;
660 n
= libssh2_channel_shell(pwm
->tcp_conn
->channel
);
662 if (n
== LIBSSH2_ERROR_EAGAIN
)
663 return GPG_ERR_EAGAIN
;
665 rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
666 _free_ssh_conn(pwm
->tcp_conn
);
667 pwm
->tcp_conn
= NULL
;
671 return ssh_connect_finalize(pwm
);
674 static gpg_error_t
ssh_connect_finalize(pwm_t
*pwm
)
677 assuan_context_t ctx
;
678 struct assuan_io_hooks io_hooks
= {read_hook
, write_hook
};
680 assuan_set_io_hooks(&io_hooks
);
681 rc
= assuan_socket_connect_fd(&ctx
, pwm
->tcp_conn
->fd
, 0, pwm
);
686 assuan_set_finish_handler(ctx
, ssh_assuan_deinit
);
688 rc
= _connect_finalize(pwm
);
696 _free_ssh_conn(pwm
->tcp_conn
);
697 pwm
->tcp_conn
= NULL
;
698 return gpg_err_code(rc
);
701 gpg_error_t
_setup_ssh_init(pwm_t
*pwm
)
705 /* Resuming an SSH connection which may have been initially created with
706 * pwmd_get_hostkey(). */
707 if (pwm
->tcp_conn
->state
== SSH_RESUME
)
710 pwm
->tcp_conn
->state
= SSH_INIT
;
711 n
= libssh2_session_startup(pwm
->tcp_conn
->session
, pwm
->tcp_conn
->fd
);
713 if (n
== LIBSSH2_ERROR_EAGAIN
)
714 return GPG_ERR_EAGAIN
;
716 _free_ssh_conn(pwm
->tcp_conn
);
717 pwm
->tcp_conn
= NULL
;
718 return GPG_ERR_ASSUAN_SERVER_FAULT
;
722 return verify_hostkey(pwm
);
725 gpg_error_t
_setup_ssh_session(pwm_t
*pwm
)
729 if (!pwm
->tcp_conn
->session
)
730 pwm
->tcp_conn
->session
= libssh2_session_init_ex(ssh_malloc
, ssh_free
,
733 if (!pwm
->tcp_conn
->session
) {
734 rc
= gpg_error_from_errno(ENOMEM
);
738 libssh2_session_set_blocking(pwm
->tcp_conn
->session
, !pwm
->tcp_conn
->async
);
739 return _setup_ssh_init(pwm
);
742 _free_ssh_conn(pwm
->tcp_conn
);
743 pwm
->tcp_conn
= NULL
;
744 return gpg_err_code(rc
);
747 static void gethostbyname_cb(void *arg
, int status
, int timeouts
,
752 if (status
!= ARES_SUCCESS
) {
753 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
757 pwm
->tcp_conn
->rc
= do_connect(pwm
, he
->h_addrtype
, he
->h_addr
);
760 gpg_error_t
_do_pwmd_ssh_connect(pwm_t
*pwm
, const char *host
, int port
,
761 const char *identity
, const char *user
, const char *known_hosts
, int get
)
763 pwmd_tcp_conn_t
*conn
;
769 return GPG_ERR_INV_ARG
;
771 if (pwm
->cmd
!= ASYNC_CMD_NONE
)
772 return GPG_ERR_INV_STATE
;
775 pwm
->tcp_conn
->async
= 0;
777 conn
= pwm
->tcp_conn
;
780 rc
= init_tcp_conn(&conn
, host
, port
, identity
, user
, known_hosts
, get
,
786 pwm
->tcp_conn
= conn
;
787 pwm
->tcp_conn
->cmd
= get
? ASYNC_CMD_HOSTKEY
: ASYNC_CMD_NONE
;
788 pwm
->cmd
= ASYNC_CMD_NONE
;
793 pwm
->cmd
= ASYNC_CMD_DNS
;
795 if (inet_aton(pwm
->tcp_conn
->host
, &addr
)) {
797 pwm
->prot
== PWMD_IP_ANY
||
798 pwm
->prot
== PWMD_IPV4
? PF_INET
: PF_INET6
,
807 ares_init(&pwm
->tcp_conn
->chan
);
808 ares_gethostbyname(pwm
->tcp_conn
->chan
, pwm
->tcp_conn
->host
,
809 pwm
->prot
== PWMD_IP_ANY
||
810 pwm
->prot
== PWMD_IPV4
? PF_INET
: PF_INET6
,
811 gethostbyname_cb
, pwm
);
813 /* gethostbyname_cb() may have already been called. */
814 if (pwm
->tcp_conn
->rc
) {
815 rc
= pwm
->tcp_conn
->rc
;
820 * Fake a blocking DNS lookup. libcares does a better job than
830 n
= ares_fds(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
831 ares_timeout(pwm
->tcp_conn
->chan
, NULL
, &tv
);
837 n
= pth_select(n
, &rfds
, &wfds
, NULL
, &tv
);
839 n
= select(n
, &rfds
, &wfds
, NULL
, &tv
);
843 rc
= gpg_error_from_syserror();
847 rc
= GPG_ERR_TIMEOUT
;
851 ares_process(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
853 if (pwm
->tcp_conn
->rc
)
855 } while (pwm
->cmd
== ASYNC_CMD_DNS
);
857 if (pwm
->tcp_conn
->rc
) {
858 rc
= pwm
->tcp_conn
->rc
;
863 rc
= _setup_ssh_session(pwm
);
864 pwm
->cmd
= ASYNC_CMD_NONE
;
867 pwm
->tcp_conn
->cmd
= ASYNC_CMD_NONE
;
874 * ssh://[username@]hostname[:port],identity,known_hosts
876 * Any missing parameters are checked for in init_tcp_conn().
878 gpg_error_t
_parse_ssh_url(char *str
, char **host
, int *port
, char **user
,
879 char **identity
, char **known_hosts
)
885 *host
= *user
= *identity
= *known_hosts
= NULL
;
887 p
= strrchr(str
, '@');
890 len
= strlen(str
)-strlen(p
)+1;
891 *user
= pwmd_malloc(len
);
894 return gpg_error_from_errno(ENOMEM
);
896 snprintf(*user
, len
, "%s", str
);
905 len
= strlen(p
)-strlen(t
)+1;
906 *host
= pwmd_malloc(len
);
909 return gpg_error_from_errno(ENOMEM
);
911 snprintf(*host
, len
, "%s", p
);
915 while (*t
&& isdigit(*t
))
927 len
= strlen(p
)-strlen(t
)+1;
928 *host
= pwmd_malloc(len
);
931 return gpg_error_from_errno(ENOMEM
);
933 snprintf(*host
, len
, "%s", p
);
940 len
= strlen(t
)-strlen(t2
)+1;
944 *identity
= pwmd_malloc(len
);
947 return gpg_error_from_errno(ENOMEM
);
949 snprintf(*identity
, len
, "%s", t
);
955 *known_hosts
= pwmd_malloc(len
);
958 return gpg_error_from_errno(ENOMEM
);
960 snprintf(*known_hosts
, len
, "%s", t2
);
966 *host
= pwmd_malloc(len
);
969 return gpg_error_from_errno(ENOMEM
);
971 snprintf(*host
, len
, "%s", p
);
978 void _ssh_disconnect(pwm_t
*pwm
)
980 ssh_deinit(pwm
->tcp_conn
);
981 pwm
->tcp_conn
= NULL
;