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 return GPG_ERR_BAD_CERT
;
513 n
= libssh2_knownhost_check(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->host
,
515 LIBSSH2_KNOWNHOST_TYPE_PLAIN
|LIBSSH2_KNOWNHOST_KEYENC_RAW
,
516 &pwm
->tcp_conn
->hostent
);
519 case LIBSSH2_KNOWNHOST_CHECK_MATCH
:
521 case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND
:
522 if (pwm
->tcp_conn
->cmd
!= ASYNC_CMD_HOSTKEY
) {
524 rc
= GPG_ERR_MISSING_CERT
;
526 rc
= pwm
->kh_cb(pwm
->kh_data
, pwm
->tcp_conn
->host
, key
,
533 libssh2_knownhost_add(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->host
, NULL
,
535 LIBSSH2_KNOWNHOST_TYPE_PLAIN
|
536 LIBSSH2_KNOWNHOST_KEYENC_RAW
|
537 LIBSSH2_KNOWNHOST_KEY_SSHRSA
,
538 &pwm
->tcp_conn
->hostent
);
540 /* It's not an error if writing the new host file fails since
541 * there isn't a way to notify the user. The hostkey is still
543 if (pwm
->tcp_conn
->cmd
!= ASYNC_CMD_HOSTKEY
) {
544 char *tmp
= tempnam(NULL
, "khost");
549 if (!libssh2_knownhost_writefile(pwm
->tcp_conn
->kh
, tmp
,
550 LIBSSH2_KNOWNHOST_FILE_OPENSSH
)) {
554 buf
= pwmd_malloc(LINE_MAX
);
561 ifp
= fopen(tmp
, "r");
562 ofp
= fopen(pwm
->tcp_conn
->known_hosts
, "w+");
564 while ((fgets(buf
, LINE_MAX
, ifp
))) {
565 if (fprintf(ofp
, buf
, strlen(buf
)) < 0)
578 case LIBSSH2_KNOWNHOST_CHECK_MISMATCH
:
579 case LIBSSH2_KNOWNHOST_CHECK_FAILURE
:
580 return GPG_ERR_BAD_CERT
;
586 static gpg_error_t
verify_hostkey(pwm_t
*pwm
)
592 if (!pwm
->tcp_conn
->kh
)
593 pwm
->tcp_conn
->kh
= libssh2_knownhost_init(pwm
->tcp_conn
->session
);
595 if (!pwm
->tcp_conn
->kh
)
596 return GPG_ERR_ENOMEM
;
598 rc
= check_known_hosts(pwm
);
603 buf
= pwmd_malloc(LINE_MAX
);
606 return gpg_error_from_errno(ENOMEM
);
608 if (libssh2_knownhost_writeline(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->hostent
,
609 buf
, LINE_MAX
, &outlen
, LIBSSH2_KNOWNHOST_FILE_OPENSSH
)) {
611 return gpg_error_from_errno(ENOMEM
);
614 if (pwm
->tcp_conn
->hostkey
)
615 pwmd_free(pwm
->tcp_conn
->hostkey
);
617 pwm
->tcp_conn
->hostkey
= buf
;
619 if (pwm
->tcp_conn
->cmd
== ASYNC_CMD_HOSTKEY
) {
620 libssh2_knownhost_del(pwm
->tcp_conn
->kh
, pwm
->tcp_conn
->hostent
);
621 pwm
->tcp_conn
->hostent
= NULL
;
622 pwm
->tcp_conn
->state
= SSH_RESUME
;
626 return _setup_ssh_authlist(pwm
);
629 gpg_error_t
_setup_ssh_channel(pwm_t
*pwm
)
634 pwm
->tcp_conn
->state
= SSH_CHANNEL
;
635 libssh2_session_set_blocking(pwm
->tcp_conn
->session
, 1);
636 pwm
->tcp_conn
->channel
=
637 libssh2_channel_open_session(pwm
->tcp_conn
->session
);
638 n
= libssh2_session_last_errno(pwm
->tcp_conn
->session
);
640 if (!pwm
->tcp_conn
->channel
&& n
== LIBSSH2_ERROR_EAGAIN
)
641 return GPG_ERR_EAGAIN
;
643 if (!pwm
->tcp_conn
->channel
) {
644 rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
645 _free_ssh_conn(pwm
->tcp_conn
);
646 pwm
->tcp_conn
= NULL
;
650 return _setup_ssh_shell(pwm
);
653 gpg_error_t
_setup_ssh_shell(pwm_t
*pwm
)
658 pwm
->tcp_conn
->state
= SSH_SHELL
;
659 n
= libssh2_channel_shell(pwm
->tcp_conn
->channel
);
661 if (n
== LIBSSH2_ERROR_EAGAIN
)
662 return GPG_ERR_EAGAIN
;
664 rc
= GPG_ERR_ASSUAN_SERVER_FAULT
;
665 _free_ssh_conn(pwm
->tcp_conn
);
666 pwm
->tcp_conn
= NULL
;
670 return ssh_connect_finalize(pwm
);
673 static gpg_error_t
ssh_connect_finalize(pwm_t
*pwm
)
676 assuan_context_t ctx
;
677 struct assuan_io_hooks io_hooks
= {read_hook
, write_hook
};
679 assuan_set_io_hooks(&io_hooks
);
680 rc
= assuan_socket_connect_fd(&ctx
, pwm
->tcp_conn
->fd
, 0, pwm
);
685 assuan_set_finish_handler(ctx
, ssh_assuan_deinit
);
687 rc
= _connect_finalize(pwm
);
695 _free_ssh_conn(pwm
->tcp_conn
);
696 pwm
->tcp_conn
= NULL
;
697 return gpg_err_code(rc
);
700 gpg_error_t
_setup_ssh_init(pwm_t
*pwm
)
704 /* Resuming an SSH connection which may have been initially created with
705 * pwmd_get_hostkey(). */
706 if (pwm
->tcp_conn
->state
== SSH_RESUME
)
709 pwm
->tcp_conn
->state
= SSH_INIT
;
710 n
= libssh2_session_startup(pwm
->tcp_conn
->session
, pwm
->tcp_conn
->fd
);
712 if (n
== LIBSSH2_ERROR_EAGAIN
)
713 return GPG_ERR_EAGAIN
;
715 _free_ssh_conn(pwm
->tcp_conn
);
716 pwm
->tcp_conn
= NULL
;
717 return GPG_ERR_ASSUAN_SERVER_FAULT
;
721 return verify_hostkey(pwm
);
724 gpg_error_t
_setup_ssh_session(pwm_t
*pwm
)
728 if (!pwm
->tcp_conn
->session
)
729 pwm
->tcp_conn
->session
= libssh2_session_init_ex(ssh_malloc
, ssh_free
,
732 if (!pwm
->tcp_conn
->session
) {
733 rc
= gpg_error_from_errno(ENOMEM
);
737 libssh2_session_set_blocking(pwm
->tcp_conn
->session
, !pwm
->tcp_conn
->async
);
738 return _setup_ssh_init(pwm
);
741 _free_ssh_conn(pwm
->tcp_conn
);
742 pwm
->tcp_conn
= NULL
;
743 return gpg_err_code(rc
);
746 static void gethostbyname_cb(void *arg
, int status
, int timeouts
,
751 if (status
!= ARES_SUCCESS
) {
752 pwm
->tcp_conn
->rc
= ares_error_to_pwmd(status
);
756 pwm
->tcp_conn
->rc
= do_connect(pwm
, he
->h_addrtype
, he
->h_addr
);
759 gpg_error_t
_do_pwmd_ssh_connect(pwm_t
*pwm
, const char *host
, int port
,
760 const char *identity
, const char *user
, const char *known_hosts
, int get
)
762 pwmd_tcp_conn_t
*conn
;
768 return GPG_ERR_INV_ARG
;
770 if (pwm
->cmd
!= ASYNC_CMD_NONE
)
771 return GPG_ERR_INV_STATE
;
774 pwm
->tcp_conn
->async
= 0;
776 conn
= pwm
->tcp_conn
;
779 rc
= init_tcp_conn(&conn
, host
, port
, identity
, user
, known_hosts
, get
,
785 pwm
->tcp_conn
= conn
;
786 pwm
->tcp_conn
->cmd
= get
? ASYNC_CMD_HOSTKEY
: ASYNC_CMD_NONE
;
787 pwm
->cmd
= ASYNC_CMD_NONE
;
792 pwm
->cmd
= ASYNC_CMD_DNS
;
794 if (inet_aton(pwm
->tcp_conn
->host
, &addr
)) {
796 pwm
->prot
== PWMD_IP_ANY
||
797 pwm
->prot
== PWMD_IPV4
? PF_INET
: PF_INET6
,
806 ares_init(&pwm
->tcp_conn
->chan
);
807 ares_gethostbyname(pwm
->tcp_conn
->chan
, pwm
->tcp_conn
->host
,
808 pwm
->prot
== PWMD_IP_ANY
||
809 pwm
->prot
== PWMD_IPV4
? PF_INET
: PF_INET6
,
810 gethostbyname_cb
, pwm
);
812 /* gethostbyname_cb() may have already been called. */
813 if (pwm
->tcp_conn
->rc
) {
814 rc
= pwm
->tcp_conn
->rc
;
819 * Fake a blocking DNS lookup. libcares does a better job than
829 n
= ares_fds(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
830 ares_timeout(pwm
->tcp_conn
->chan
, NULL
, &tv
);
836 n
= pth_select(n
, &rfds
, &wfds
, NULL
, &tv
);
838 n
= select(n
, &rfds
, &wfds
, NULL
, &tv
);
842 rc
= gpg_error_from_syserror();
846 rc
= GPG_ERR_TIMEOUT
;
850 ares_process(pwm
->tcp_conn
->chan
, &rfds
, &wfds
);
852 if (pwm
->tcp_conn
->rc
)
854 } while (pwm
->cmd
== ASYNC_CMD_DNS
);
856 if (pwm
->tcp_conn
->rc
) {
857 rc
= pwm
->tcp_conn
->rc
;
862 rc
= _setup_ssh_session(pwm
);
863 pwm
->cmd
= ASYNC_CMD_NONE
;
866 pwm
->tcp_conn
->cmd
= ASYNC_CMD_NONE
;
873 * ssh://[username@]hostname[:port],identity,known_hosts
875 * Any missing parameters are checked for in init_tcp_conn().
877 gpg_error_t
_parse_ssh_url(char *str
, char **host
, int *port
, char **user
,
878 char **identity
, char **known_hosts
)
884 *host
= *user
= *identity
= *known_hosts
= NULL
;
886 p
= strrchr(str
, '@');
889 len
= strlen(str
)-strlen(p
)+1;
890 *user
= pwmd_malloc(len
);
893 return gpg_error_from_errno(ENOMEM
);
895 snprintf(*user
, len
, "%s", str
);
904 len
= strlen(p
)-strlen(t
)+1;
905 *host
= pwmd_malloc(len
);
908 return gpg_error_from_errno(ENOMEM
);
910 snprintf(*host
, len
, "%s", p
);
914 while (*t
&& isdigit(*t
))
926 len
= strlen(p
)-strlen(t
)+1;
927 *host
= pwmd_malloc(len
);
930 return gpg_error_from_errno(ENOMEM
);
932 snprintf(*host
, len
, "%s", p
);
939 len
= strlen(t
)-strlen(t2
)+1;
943 *identity
= pwmd_malloc(len
);
946 return gpg_error_from_errno(ENOMEM
);
948 snprintf(*identity
, len
, "%s", t
);
954 *known_hosts
= pwmd_malloc(len
);
957 return gpg_error_from_errno(ENOMEM
);
959 snprintf(*known_hosts
, len
, "%s", t2
);
965 *host
= pwmd_malloc(len
);
968 return gpg_error_from_errno(ENOMEM
);
970 snprintf(*host
, len
, "%s", p
);
977 void _ssh_disconnect(pwm_t
*pwm
)
979 ssh_deinit(pwm
->tcp_conn
);
980 pwm
->tcp_conn
= NULL
;