From 73e8e4f3acebb2382fa5f22b7ac5c44b128738b8 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Wed, 26 May 2010 19:06:14 -0400 Subject: [PATCH] No longer require a knownhosts parameter to the SSH connection functions. Use a default of ~/.ssh/known_hosts. --- doc/libpwmd.3 | 4 ++-- doc/pwmc.1.in | 12 ++++++------ src/libpwmd.h.in | 6 ++++-- src/pwmc.c | 2 +- src/ssh.c | 8 +++++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/libpwmd.3 b/doc/libpwmd.3 index 6e7e5779..f1834c02 100644 --- a/doc/libpwmd.3 +++ b/doc/libpwmd.3 @@ -1409,7 +1409,7 @@ Establish a remote connection to a pwmd server. Connects to a pwmd server over a .br \fIuser\fP The username on the SSH server to login as. If NULL then invoking username will be used. .br -\fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. +\fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. If NULL, the default of \fI'~/.ssh/known_hosts'\fP will be used. .RE .PP \fBReturns:\fP @@ -1446,7 +1446,7 @@ Establish a remote connection to a pwmd server (asynchronously). This is a varia .br \fIuser\fP The username on the SSH server to login as. If NULL, the invoking username will be used. .br -\fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. +\fIknown_hosts\fP An OpenSSH known hosts formatted file containing public SSH server hashes which may be obtained with \fBpwmd_get_hostkey()\fP or via \fBpwmd_knownhost_cb_t\fP during a connection. If NULL, the default of \fI'~/.ssh/known_hosts'\fP will be used. .RE .PP \fBReturns:\fP diff --git a/doc/pwmc.1.in b/doc/pwmc.1.in index 94c3ec32..c4033090 100644 --- a/doc/pwmc.1.in +++ b/doc/pwmc.1.in @@ -63,12 +63,11 @@ The port of the hostname to connect to. The default is 22. .TP .I "\--known-hosts, -k " -A file containing a list of SHA1 fingerprints of remote SSH servers that +An OpenSSH formatted known_hosts file that .BR libpwmd (3) -will check against while authenticating the remote host. Note that this file -format differs from the usual -.BR ssh (1) -known_hosts file format. +will verify the hostkey against while connecting to a remote host. The default +is +.B ~/.ssh/known_hosts. .TP .I "\--identity, -i " @@ -85,7 +84,8 @@ user. .TP .I "\--get-hostkey, -g" -Retrieve the SHA1 fingerprint of the remote SSH hostname specified with +Retrieve the OpenSSH formatted host key of the remote SSH hostname specified +with .B -h . The result should be appended to the known hosts file. diff --git a/src/libpwmd.h.in b/src/libpwmd.h.in index ca61a412..5c57f82b 100644 --- a/src/libpwmd.h.in +++ b/src/libpwmd.h.in @@ -579,7 +579,8 @@ LIBPWMD_API gpg_error_t pwmd_connect(pwm_t *pwm, const char *path); * invoking username will be used. * \param known_hosts An OpenSSH known hosts formatted file containing public * SSH server hashes which may be obtained with \ref pwmd_get_hostkey() or via - * \ref pwmd_knownhost_cb_t during a connection. + * \ref pwmd_knownhost_cb_t during a connection. If NULL, the default of + * \a "~/.ssh/known_hosts" will be used. * \return 0 on success or an error code. * \filepath * \see pwmd_ssh_connect_async(), \ref PWMD_OPTION_IP_VERSION, @@ -608,7 +609,8 @@ LIBPWMD_API gpg_error_t pwmd_ssh_connect(pwm_t *pwm, const char *host, * invoking username will be used. * \param known_hosts An OpenSSH known hosts formatted file containing public * SSH server hashes which may be obtained with \ref pwmd_get_hostkey() or via - * \ref pwmd_knownhost_cb_t during a connection. + * \ref pwmd_knownhost_cb_t during a connection. If NULL, the default of + * \a "~/.ssh/known_hosts" will be used. * \return 0 on success or an error code. * \filepath * \see pwmd_process(), \ref PWMD_OPTION_IP_VERSION, pwmd_disconnect(), diff --git a/src/pwmc.c b/src/pwmc.c index 417f18e0..99c1cce3 100644 --- a/src/pwmc.c +++ b/src/pwmc.c @@ -570,7 +570,7 @@ int main(int argc, char *argv[]) if (!url_string) { #endif #ifdef WITH_TCP - if (host && !get && (!known_hosts || !ident)) { + if (host && !get && !ident) { pwmd_free(password); usage(argv[0], EXIT_FAILURE); } diff --git a/src/ssh.c b/src/ssh.c index ceba8ea3..4fd74afc 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -183,15 +183,14 @@ static gpg_error_t init_tcp_conn(pwmd_tcp_conn_t **dst, const char *host, return GPG_ERR_INV_ARG; } else if (!resume) { - if (!host || !*host || !identity || !*identity || !known_hosts || - !*known_hosts) + if (!host || !*host || !identity || !*identity) return GPG_ERR_INV_ARG; } else if (resume) { if (host) return GPG_ERR_INV_STATE; - if (!identity || !*identity || !known_hosts || !*known_hosts) + if (!identity || !*identity) return GPG_ERR_INV_ARG; } @@ -245,6 +244,9 @@ static gpg_error_t init_tcp_conn(pwmd_tcp_conn_t **dst, const char *host, if (conn->known_hosts) pwmd_free(conn->known_hosts); + if (!known_hosts) + known_hosts = "~/.ssh/known_hosts"; + conn->known_hosts = _expand_homedir((char *)known_hosts, &pw); if (!conn->known_hosts) { -- 2.11.4.GIT