From f653482d5c1d2466b28792777ee7b1e57e27cfdf Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 24 Sep 2009 17:13:10 +0100 Subject: [PATCH] Start virt-tools-get-key. --- linux/50-virt-tools.in | 2 +- linux/Makefile.am | 2 +- tools/virt-ifconfig.pl | 6 +- tools/virt-tools-get-key.pl | 173 +++++++++++++++++++++++++++++++++++++++++++- tools/virt-uname.pl | 18 +++-- virt-tools.spec.in | 2 +- 6 files changed, 187 insertions(+), 16 deletions(-) diff --git a/linux/50-virt-tools.in b/linux/50-virt-tools.in index 5b7073f..b723262 100644 --- a/linux/50-virt-tools.in +++ b/linux/50-virt-tools.in @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -/sbin/ip addr show dev "$1" > @localstatedir@/run/virt-tools/ip-"$1" +/sbin/ip addr show dev "$1" > @localstatedir@/lib/virt-tools/ip-"$1" # Ensure the blocks get written to disk. sync diff --git a/linux/Makefile.am b/linux/Makefile.am index b8339c7..4e21609 100644 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -20,7 +20,7 @@ nmconfdir = $(sysconfdir)/NetworkManager/dispatcher.d nmconf_SCRIPTS = 50-virt-tools # Directory for sharing data with the host. -sharingdir = $(localstatedir)/run/virt-tools +sharingdir = $(localstatedir)/lib/virt-tools install-data-hook: $(MKDIR_P) $(DESTDIR)$(sharingdir) diff --git a/tools/virt-ifconfig.pl b/tools/virt-ifconfig.pl index 523c125..3455ed5 100755 --- a/tools/virt-ifconfig.pl +++ b/tools/virt-ifconfig.pl @@ -19,9 +19,7 @@ use strict; use Sys::Guestfs; -use Sys::Guestfs::Lib qw(open_guest get_partitions resolve_windows_path - inspect_all_partitions inspect_partition - inspect_operating_systems mount_operating_system inspect_in_detail); +use Sys::Guestfs::Lib qw(open_guest get_partitions); use Pod::Usage; use Getopt::Long; use Locale::TextDomain 'virt-tools'; @@ -171,7 +169,7 @@ sub do_ifconfig eval { $g->mount_ro ($partition, "/"); my $dir; - my @dirs = ("/var/run/virt-tools", "/run/virt-tools"); + my @dirs = ("/var/lib/virt-tools", "/lib/virt-tools"); foreach $dir (@dirs) { if ($g->is_dir ($dir)) { my @names = $g->ls ($dir); diff --git a/tools/virt-tools-get-key.pl b/tools/virt-tools-get-key.pl index 0b478b8..3dce2db 100755 --- a/tools/virt-tools-get-key.pl +++ b/tools/virt-tools-get-key.pl @@ -16,5 +16,176 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -use Net::SNMP; +use Sys::Virt; +use Sys::Guestfs; +use Sys::Guestfs::Lib qw(open_guest get_partitions); +use Pod::Usage; +use Getopt::Long; +use Locale::TextDomain 'virt-tools'; +=encoding utf8 + +=head1 NAME + +virt-tools-get-key - virt-tools helper to get the guest's key + +=head1 SYNOPSIS + + virt-tools-get-key [--options] domname + +=head1 DESCRIPTION + +This helper program is used by L to get the guest's +secret key. If you don't know anything about this, you probably want +to start by reading L. Otherwise read on. + +The single command line argument should be a libvirt domain name (see +C). + +=head2 KEY CACHE + +The cache is described in detail in L. In brief, if +C<@LOCALSTATEDIR@/lib/virt-tools/keys/EUUIDE> exists (where +EUUIDE is the guest's UUID), then the contents of that file +are returned directly. Otherwise we will try to create this file +after reading the key so that we don't have to read the key out of the +guest's filesystem each time. + +=head1 OPTIONS + +=over 4 + +=cut + +my $help; + +=item B<--help> + +Display brief help. + +=cut + +my $version; + +=item B<--version> + +Display version number and exit. + +=cut + +my $uri; + +=item B<--connect URI> | B<-c URI> + +If using libvirt, connect to the given I. If omitted, then we +connect to the default libvirt hypervisor. + +=cut + +my $verbose; + +=item B<--verbose> | B<-v> + +Enable verbose messages, useful for debugging. + +=back + +=cut + +GetOptions ("help|?" => \$help, + "version" => \$version, + "connect|c=s" => \$uri, + "verbose|v" => \$verbose, + ) or pod2usage (2); +pod2usage (1) if $help; +if ($version) { + print "@PACKAGE_STRING@\n"; + exit +} + +die __"no domain name or UUID listed on the command line\n" unless @ARGV == 1; + +my $g; + +if ($uri) { + $g = open_guest (\@ARGV, address => $uri); +} else { + $g = open_guest (\@ARGV); +} + +$g->launch (); + +# Don't care about mountpoints. Instead, just look for a +# directory with one of a selection of names on one of the +# partitions that we found. +my @partitions = get_partitions ($g); + +my $key; + +SEARCH: +foreach my $partition (@partitions) { + eval { + $g->mount_ro ($partition, "/"); + my $dir; + my @dirs = ("/var/lib/virt-tools", "/lib/virt-tools"); + foreach $dir (@dirs) { + if ($g->is_dir ($dir) && $g->is_file ("$dir/key")) { + $key = $g->cat ("$dir/key"); + last SEARCH; + } + } + }; + $g->umount_all (); +} + +undef $g; + +die __x("{n}: no key found in guest.\nDoes it have the virt-tool-guest package installed?\n", + n => $ARGV[0]) + unless $key; + +print $key; + +exit 0; + +=head1 SEE ALSO + +L, +L, +L, +L, +L, +L, +L. + +=head1 AUTHORS + +=over 4 + +=item * + +Richard W.M. Jones (C) + +=item * + +Matthew Booth (C) + +=back + +=head1 COPYRIGHT + +Copyright (C) 2009 Red Hat Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/tools/virt-uname.pl b/tools/virt-uname.pl index 4c7e253..ee1ced3 100755 --- a/tools/virt-uname.pl +++ b/tools/virt-uname.pl @@ -325,10 +325,10 @@ guest side. =head2 COMMUNICATIONS DIRECTORY The guest writes various static, mostly unchanging, information into -its own directory. On Linux the directory is C -and under Windows it is C<%systemroot%\virttool\>. In the discussion -below, this communications directory is referred to as -C<$GUESTCOMMSDIR>. +its own directory. On Linux the directory is +C<@LOCALSTATEDIR@/lib/virt-tools/> and under Windows it is +C<%systemroot%\virttool\>. In the discussion below, this +communications directory is referred to as C<$GUESTCOMMSDIR>. The host is able to read files out of this directory using L (without any cooperation needed by the guest). @@ -426,13 +426,14 @@ verify its operation: C caches the keys of guests that it has seen before so it doesn't have to read them each time. The cache is in -C (in the host). +C<@LOCALSTATEDIR@/lib/virt-tools/keys/> (in the host). You can just delete the files in this directory at any time, I you can drop a file in here which contains the key of a guest. -To do this, create a file CUUIDE> -where EUUIDE is the guest's UUID as displayed by this command: +To do this, create a file +C<@LOCALSTATEDIR@/lib/virt-tools/keys/EUUIDE> where +EUUIDE is the guest's UUID as displayed by this command: virsh domuuid @@ -486,7 +487,8 @@ command by hand. C caches the transports of guests that it has seen before so it doesn't have to determine them each time. The -cache is in C (in the host). +cache is in C<@LOCALSTATEDIR@/lib/virt-tools/transports/> (in the +host). As for the L, this directory is just some files that are named after the UUID of the guest, containing the transport. diff --git a/virt-tools.spec.in b/virt-tools.spec.in index 343b406..8443d90 100644 --- a/virt-tools.spec.in +++ b/virt-tools.spec.in @@ -84,7 +84,7 @@ rm -rf $RPM_BUILD_ROOT %defattr(-,root,root,-) %doc COPYING %{_sysconfdir}/NetworkManager/dispatcher.d/50-virt-tools -%dir %{_localstatedir}/run/virt-tools/ +%dir %{_localstatedir}/lib/virt-tools/ %changelog -- 1.8.3.1