[gnome-boxes] Add smartcard support



commit 39b39e6915d8a77d0550d590d2f64aade89d446d
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Dec 18 16:43:17 2012 +0100

    Add smartcard support
    
    If --enable-smartcard support is passed we create new VMs with
    smartcard support, or let you add it to old VMs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690422

 configure.ac             |   10 ++++++++++
 src/config.vapi          |    1 +
 src/libvirt-machine.vala |   33 ++++++++++++++++++++++++++++++++-
 src/vm-configurator.vala |   10 ++++++++++
 4 files changed, 53 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fab78d9..bd7c580 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,14 @@ AS_IF([test "x$enable_usbredir" = "xyes"],
       [AC_DEFINE([HAVE_USBREDIR], [1], [Qemu supports usbredir]) AC_MSG_RESULT([yes])],
       [AC_DEFINE([HAVE_USBREDIR], [0], [Qemu supports usbredir]) AC_MSG_RESULT([no])])
 
+AC_MSG_CHECKING([whether smartcard support was enabled with --enable-smartcard])
+AC_ARG_ENABLE(smartcard,
+	AS_HELP_STRING([--enable-smartcard],[Enable smartcard support]),,
+        enable_smartcard=no)
+AS_IF([test "x$enable_smartcard" = "xyes"],
+      [AC_DEFINE([HAVE_SMARTCARD], [1], [Qemu supports smartcard]) AC_MSG_RESULT([yes])],
+      [AC_DEFINE([HAVE_SMARTCARD], [0], [Qemu supports smartcard]) AC_MSG_RESULT([no])])
+
 dnl Strict compiler
 AC_ARG_ENABLE([strict-cc],
   AS_HELP_STRING([--enable-strict-cc],[Enable strict C compiler]))
@@ -165,4 +173,6 @@ AC_MSG_NOTICE([
         prefix:                   ${prefix}
         c compiler:               ${CC} ${CFLAGS}
         build from vala sources:  $enable_vala
+        USB redirection support:  $enable_usbredir
+        Smartcard support:        $enable_smartcard
 ])
diff --git a/src/config.vapi b/src/config.vapi
index 01ccc6b..12bfd32 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -10,4 +10,5 @@ namespace Config {
         public const string PACKAGE_BUGREPORT;
         public const string PACKAGE_URL;
         public const bool HAVE_USBREDIR;
+        public const bool HAVE_SMARTCARD;
 }
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index e7552e8..2a9a527 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -321,6 +321,17 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             notify_reboot_required ();
     }
 
+    public void try_enable_smartcard () throws GLib.Error {
+        var config = domain.get_config (GVir.DomainXMLFlags.INACTIVE);
+
+        VMConfigurator.add_smartcard_support (config);
+
+        // This will take effect only after next reboot
+        domain.set_config (config);
+        if (is_on ())
+            notify_reboot_required ();
+    }
+
     private string collect_logs () {
         var builder = new StringBuilder ();
 
@@ -536,6 +547,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             }
 
             bool has_usb_redir = false;
+            bool has_smartcard = false;
             // We look at the INACTIVE config here, because we want to show the usb
             // widgetry if usb has been added already but we have not rebooted
             try {
@@ -543,7 +555,9 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                 foreach (var device in inactive_config.get_devices ()) {
                     if (device is GVirConfig.DomainRedirdev) {
                         has_usb_redir = true;
-                        break;
+                    }
+                    if (device is GVirConfig.DomainSmartcard) {
+                        has_smartcard = true;
                     }
                 }
             } catch (GLib.Error error) {
@@ -570,6 +584,23 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
                 });
             }
 
+            // Only add smartcart support to guests if HAVE_SMARTCARD, as qemu built
+            // without smartcard support will not start vms with it.
+            if (!has_smartcard && Config.HAVE_SMARTCARD) {
+                var button = new Gtk.Button.with_label (_("Add support to guest"));
+                button.halign = Gtk.Align.START;
+                var property = add_property (ref list, _("Smartcard support"), button);
+                button.clicked.connect (() => {
+                    try {
+                        try_enable_smartcard ();
+                        update_domain_config ();
+                        property.refresh_properties ();
+                    } catch (GLib.Error error) {
+                        warning ("Failed to enable smartcard");
+                    }
+                });
+            }
+
             break;
         }
 
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 973163d..093c7f5 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -79,6 +79,9 @@ private class Boxes.VMConfigurator {
         if (Config.HAVE_USBREDIR)
             add_usb_support (domain);
 
+        if (Config.HAVE_SMARTCARD)
+            add_smartcard_support (domain);
+
         set_video_config (domain, install_media);
         set_sound_config (domain, install_media);
         set_tablet_config (domain, install_media);
@@ -370,6 +373,13 @@ private class Boxes.VMConfigurator {
         } catch (GLib.Error error) { assert_not_reached (); /* We are so screwed if this happens */ }
     }
 
+    public static void add_smartcard_support (Domain domain) {
+        var smartcard = new DomainSmartcardPassthrough ();
+        var vmc = new DomainChardevSourceSpiceVmc ();
+        smartcard.set_source (vmc);
+        domain.add_device (smartcard);
+    }
+
     public static void add_usb_support (Domain domain) {
         // 4 USB redirection channels
         for (int i = 0; i < 4; i++) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]