mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0040-virt-win-reg-Allow-URIs-RHBZ-912193.patch

cd6068
From 612294872852be2f34f683c2a97e24adcfab288d Mon Sep 17 00:00:00 2001
cd6068
From: "Richard W.M. Jones" <rjones@redhat.com>
cd6068
Date: Thu, 14 Nov 2013 15:50:03 +0000
cd6068
Subject: [PATCH] virt-win-reg: Allow URIs (RHBZ#912193).
cd6068
cd6068
(cherry picked from commit 793a5677cbd6f80ae0f4fbc3cdf478e7f84edadb)
cd6068
---
cd6068
 tools/virt-win-reg | 33 ++++++++++++++++++++++++++++++++-
cd6068
 1 file changed, 32 insertions(+), 1 deletion(-)
cd6068
cd6068
diff --git a/tools/virt-win-reg b/tools/virt-win-reg
cd6068
index a302857..bcd836c 100755
cd6068
--- a/tools/virt-win-reg
cd6068
+++ b/tools/virt-win-reg
cd6068
@@ -252,9 +252,40 @@ push @lib_args, format => $format if defined $format;
cd6068
 
cd6068
 my $g = Sys::Guestfs->new ();
cd6068
 
cd6068
-if (-e $domname_or_image) {
cd6068
+# If the parameter looks like a URI, try parsing it using guestfish.
cd6068
+# This is a massive hack, but we'll fix it when virt-win-reg gets
cd6068
+# rewritten in C ...
cd6068
+if ($domname_or_image =~ m|://|) {
cd6068
+    # Whitelist the characters permitted in the URI.
cd6068
+    die "$0: $domname_or_image: URI parameter contains invalid characters"
cd6068
+        unless $domname_or_image =~ m|^[A-Za-z0-9/:#%&*+,-.=?@_~]+$|;
cd6068
+
cd6068
+    my $cmd = "LANG=C guestfish -a '$domname_or_image' -x exit 2>&1 | grep 'trace: add_drive [^=]'";
cd6068
+    open CMD, "$cmd|" or die "open: $cmd: $!";
cd6068
+    $_ = <CMD>;
cd6068
+    close CMD or die "close: $cmd: $!";
cd6068
+    chomp;
cd6068
+    die "$0: could not parse '$_'"
cd6068
+        unless m/^libguestfs: trace: add_drive "(.*?)"(.*)/;
cd6068
+    my @args = ($1, @lib_args);
cd6068
+    $_ = $2;
cd6068
+    while (/\S/) {
cd6068
+        die "$0: cound not parse remainder from '$_'"
cd6068
+            unless $_ =~ /^\s*"([a-z]+):(.*?)"(.*)/;
cd6068
+        if ($1 ne "server") {
cd6068
+            push @args, $1, $2;
cd6068
+        } else {
cd6068
+            push @args, $1, [$2];
cd6068
+        }
cd6068
+        $_ = $3;
cd6068
+    }
cd6068
+    $g->add_drive (@args);
cd6068
+}
cd6068
+# If the parameter looks like a local file:
cd6068
+elsif (-e $domname_or_image) {
cd6068
     $g->add_drive ($domname_or_image, @lib_args);
cd6068
 }
cd6068
+# Try a libvirt domain name:
cd6068
 else {
cd6068
     push @lib_args, libvirturi => $uri if defined $uri;
cd6068
     $g->add_domain ($domname_or_image, @lib_args);
cd6068
-- 
cd6068
1.8.3.1
cd6068