libssh_transport: add new libssh-based transport

Implement a new libssh transport, which uses libssh to communicate with
remote hosts, and add all the build system stuff (search of libssh,
private symbols, etc) to built it.

This new transport supports all the common ssh authentication methods,
making use of libvirt's auth callbacks for interaction with the user.
This commit is contained in:
Pino Toscano 2016-11-09 15:28:35 +01:00 committed by Peter Krempa
parent 24ee5dc907
commit 6917467c2b
8 changed files with 1642 additions and 2 deletions

View File

@ -36,6 +36,7 @@
# undef WITH_DTRACE_PROBES
# undef WITH_GNUTLS
# undef WITH_GNUTLS_GCRYPT
# undef WITH_LIBSSH
# undef WITH_MACVTAP
# undef WITH_NUMACTL
# undef WITH_SASL
@ -60,6 +61,7 @@
# undef WITH_DTRACE_PROBES
# undef WITH_GNUTLS
# undef WITH_GNUTLS_GCRYPT
# undef WITH_LIBSSH
# undef WITH_MACVTAP
# undef WITH_NUMACTL
# undef WITH_SASL

View File

@ -217,6 +217,7 @@ if test "$with_remote" = "no" ; then
with_gnutls=no
with_ssh2=no
with_sasl=no
with_libssh=no
fi
# Stateful drivers are useful only when building the daemon.
if test "$with_libvirtd" = "no" ; then
@ -246,6 +247,7 @@ LIBVIRT_CHECK_DBUS
LIBVIRT_CHECK_FUSE
LIBVIRT_CHECK_GLUSTER
LIBVIRT_CHECK_HAL
LIBVIRT_CHECK_LIBSSH
LIBVIRT_CHECK_NETCF
LIBVIRT_CHECK_NUMACTL
LIBVIRT_CHECK_OPENWSMAN
@ -2665,6 +2667,7 @@ LIBVIRT_RESULT_DBUS
LIBVIRT_RESULT_FUSE
LIBVIRT_RESULT_GLUSTER
LIBVIRT_RESULT_HAL
LIBVIRT_RESULT_LIBSSH
LIBVIRT_RESULT_NETCF
LIBVIRT_RESULT_NUMACTL
LIBVIRT_RESULT_OPENWSMAN

26
m4/virt-libssh.m4 Normal file
View File

@ -0,0 +1,26 @@
dnl The libssh.so library
dnl
dnl Copyright (C) 2016 Red Hat, Inc.
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2.1 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library. If not, see
dnl <http://www.gnu.org/licenses/>.
dnl
AC_DEFUN([LIBVIRT_CHECK_LIBSSH],[
LIBVIRT_CHECK_PKG([LIBSSH], [libssh], [0.7])
])
AC_DEFUN([LIBVIRT_RESULT_LIBSSH],[
LIBVIRT_RESULT_LIB([LIBSSH])
])

View File

@ -145,6 +145,7 @@ src/rpc/virnetclient.c
src/rpc/virnetclientprogram.c
src/rpc/virnetclientstream.c
src/rpc/virnetdaemon.c
src/rpc/virnetlibsshsession.c
src/rpc/virnetmessage.c
src/rpc/virnetsaslcontext.c
src/rpc/virnetserver.c

View File

@ -2127,6 +2127,12 @@ else ! WITH_ATOMIC_OPS_PTHREAD
SYM_FILES += $(srcdir)/libvirt_atomic.syms
endif ! WITH_ATOMIC_OPS_PTHREAD
if WITH_LIBSSH
USED_SYM_FILES += $(srcdir)/libvirt_libssh.syms
else ! WITH_LIBSSH
SYM_FILES += $(srcdir)/libvirt_libssh.syms
endif ! WITH_LIBSSH
EXTRA_DIST += \
libvirt_public.syms \
libvirt_lxc.syms \
@ -2204,7 +2210,8 @@ libvirt_admin_la_CFLAGS += \
$(YAJL_CFLAGS) \
$(SSH2_CFLAGS) \
$(SASL_CFLAGS) \
$(GNUTLS_CFLAGS)
$(GNUTLS_CFLAGS) \
$(LIBSSH_CFLAGS)
libvirt_admin_la_LIBADD += \
$(CAPNG_LIBS) \
@ -2213,7 +2220,8 @@ libvirt_admin_la_LIBADD += \
$(LIBXML_LIBS) \
$(SSH2_LIBS) \
$(SASL_LIBS) \
$(GNUTLS_LIBS)
$(GNUTLS_LIBS) \
$(LIBSSH_LIBS)
ADMIN_SYM_FILES = $(srcdir)/libvirt_admin_private.syms
@ -2790,16 +2798,25 @@ else ! WITH_SASL
EXTRA_DIST += \
rpc/virnetsaslcontext.h rpc/virnetsaslcontext.c
endif ! WITH_SASL
if WITH_LIBSSH
libvirt_net_rpc_la_SOURCES += \
rpc/virnetlibsshsession.h rpc/virnetlibsshsession.c
else ! WITH_LIBSSH
EXTRA_DIST += \
rpc/virnetlibsshsession.h rpc/virnetlibsshsession.c
endif ! WITH_LIBSSH
libvirt_net_rpc_la_CFLAGS = \
$(GNUTLS_CFLAGS) \
$(SASL_CFLAGS) \
$(SSH2_CFLAGS) \
$(LIBSSH_CFLAGS) \
$(XDR_CFLAGS) \
$(AM_CFLAGS)
libvirt_net_rpc_la_LDFLAGS = \
$(GNUTLS_LIBS) \
$(SASL_LIBS) \
$(SSH2_LIBS)\
$(LIBSSH_LIBS) \
$(SECDRIVER_LIBS) \
$(AM_LDFLAGS) \
$(NULL)

21
src/libvirt_libssh.syms Normal file
View File

@ -0,0 +1,21 @@
#
# libssh session - specific symbols
#
# rpc/virnetlibsshsession.h
virNetLibsshChannelRead;
virNetLibsshChannelWrite;
virNetLibsshSessionAuthAddAgentAuth;
virNetLibsshSessionAuthAddKeyboardAuth;
virNetLibsshSessionAuthAddPasswordAuth;
virNetLibsshSessionAuthAddPrivKeyAuth;
virNetLibsshSessionAuthSetCallback;
virNetLibsshSessionConnect;
virNetLibsshSessionHasCachedData;
virNetLibsshSessionSetChannelCommand;
virNetLibsshSessionSetHostKeyVerification;
# Let emacs know we want case-insensitive sorting
# Local Variables:
# sort-fold-case: t
# End:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,78 @@
/*
* virnetlibsshsession.h: ssh transport provider based on libssh
*
* Copyright (C) 2012-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Peter Krempa <pkrempa@redhat.com>
* Author: Pino Toscano <ptoscano@redhat.com>
*/
#ifndef __VIR_NET_LIBSSH_SESSION_H__
# define __VIR_NET_LIBSSH_SESSION_H__
# include "internal.h"
# include "viruri.h"
typedef struct _virNetLibsshSession virNetLibsshSession;
typedef virNetLibsshSession *virNetLibsshSessionPtr;
virNetLibsshSessionPtr virNetLibsshSessionNew(const char *username);
void virNetLibsshSessionFree(virNetLibsshSessionPtr sess);
typedef enum {
VIR_NET_LIBSSH_HOSTKEY_VERIFY_NORMAL,
VIR_NET_LIBSSH_HOSTKEY_VERIFY_AUTO_ADD,
VIR_NET_LIBSSH_HOSTKEY_VERIFY_IGNORE
} virNetLibsshHostkeyVerify;
int virNetLibsshSessionSetChannelCommand(virNetLibsshSessionPtr sess,
const char *command);
int virNetLibsshSessionAuthSetCallback(virNetLibsshSessionPtr sess,
virConnectAuthPtr auth);
int virNetLibsshSessionAuthAddPasswordAuth(virNetLibsshSessionPtr sess,
virURIPtr uri);
int virNetLibsshSessionAuthAddAgentAuth(virNetLibsshSessionPtr sess);
int virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
const char *keyfile,
const char *password);
int virNetLibsshSessionAuthAddKeyboardAuth(virNetLibsshSessionPtr sess,
int tries);
int virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr sess,
const char *hostname,
int port,
const char *hostsfile,
virNetLibsshHostkeyVerify opt);
int virNetLibsshSessionConnect(virNetLibsshSessionPtr sess,
int sock);
ssize_t virNetLibsshChannelRead(virNetLibsshSessionPtr sess,
char *buf,
size_t len);
ssize_t virNetLibsshChannelWrite(virNetLibsshSessionPtr sess,
const char *buf,
size_t len);
bool virNetLibsshSessionHasCachedData(virNetLibsshSessionPtr sess);
#endif /* ___VIR_NET_LIBSSH_SESSION_H_ */