[libvirt-designer PATCHv4 8/9] Implement gvir_designer_domain_add_smartcard()

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

 



This setups smartcard redirection to the guest.
I'm not yet fully sure what users could want to tweak there
(there are various ways of setting up the smartcard redirection),
so this code may need to be made more flexible.
The current code is also not checking whether the hypervisor
supports this kind of redirection or not.
---
 examples/virtxml.c                         | 12 ++++++++++
 libvirt-designer/libvirt-designer-domain.c | 36 ++++++++++++++++++++++++++++++
 libvirt-designer/libvirt-designer-domain.h |  1 +
 libvirt-designer/libvirt-designer.sym      |  1 +
 4 files changed, 50 insertions(+)

diff --git a/examples/virtxml.c b/examples/virtxml.c
index 6027335..bd5d14c 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -565,6 +565,7 @@ main(int argc, char *argv[])
     static char *connect_uri = NULL;
     static char *graphics_str = NULL;
     GVirDesignerDomainGraphics graphics;
+    static gboolean enable_smartcard;
     static gboolean enable_usb;
     static char *resources_str = NULL;
     GVirDesignerDomainResources resources;
@@ -595,6 +596,8 @@ main(int argc, char *argv[])
             "add interface with NETWORK source. Possible ARGs: mac, link={up,down}", "NETWORK[,ARG=VAL]"},
         {"graphics", 'g', 0, G_OPTION_ARG_STRING, &graphics_str,
             "add graphical output to the VM. Possible values are 'spice' or 'vnc'", "GRAPHICS"},
+        {"smartcard", 's', 0, G_OPTION_ARG_NONE, &enable_smartcard,
+            "add smartcard reader to the VM.", NULL},
         {"usb", 'u', 0, G_OPTION_ARG_NONE, &enable_usb,
             "add USB redirection to the VM.", NULL},
         {"resources", 'r', 0, G_OPTION_ARG_STRING, &resources_str,
@@ -658,6 +661,11 @@ main(int argc, char *argv[])
         }
     }
 
+    if (enable_smartcard) {
+        g_object_unref(gvir_designer_domain_add_smartcard(domain, &error));
+        CHECK_ERROR;
+    }
+
     g_object_unref(gvir_designer_domain_add_sound(domain, &error));
     CHECK_ERROR;
 
@@ -815,6 +823,10 @@ I<link>={up|down}
 Add a graphics device of type I<GRAPHICS>. Valid values are spice
 or vnc.
 
+=item -s
+
+Add smartcard reader to the VM conifguration
+
 =item -u
 
 Add USB controllers and setup USB redirection in the VM configuration.
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index a435ea0..34f5852 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -704,6 +704,42 @@ gvir_designer_domain_add_usb_redir(GVirDesignerDomain *design, GError **error)
 }
 
 
+/**
+ * gvir_designer_domain_add_smartcard:
+ * @design: (transfer none): the domain designer instance
+ * @error: return location for a #GError, or NULL
+ *
+ * Add a new virtual smartcard reader to @design. This will allow to
+ * share a smartcard reader between the guest and the host.
+ *
+ * Returns: (transfer full): the pointer to the new smartcard device
+ */
+GVirConfigDomainSmartcard *
+gvir_designer_domain_add_smartcard(GVirDesignerDomain *design, GError **error)
+{
+    /* FIXME: check if OS/hypervisor support smartcard, might need
+     *        libosinfo improvements
+     */
+    GVirConfigDomainSmartcardPassthrough *smartcard;
+    GVirConfigDomainChardevSourceSpiceVmc *vmc;
+    GVirConfigDomainChardevSource *source;
+
+    g_return_val_if_fail(GVIR_DESIGNER_IS_DOMAIN(design), NULL);
+    g_return_val_if_fail(!error_is_set(error), NULL);
+
+    smartcard = gvir_config_domain_smartcard_passthrough_new();
+    vmc = gvir_config_domain_chardev_source_spicevmc_new();
+    source = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(vmc);
+    gvir_config_domain_smartcard_passthrough_set_source(smartcard, source);
+    g_object_unref(G_OBJECT(vmc));
+
+    gvir_config_domain_add_device(design->priv->config,
+                                  GVIR_CONFIG_DOMAIN_DEVICE(smartcard));
+
+    return GVIR_CONFIG_DOMAIN_SMARTCARD(smartcard);
+}
+
+
 static void gvir_designer_domain_add_power_management(GVirDesignerDomain *design)
 {
     GVirConfigDomainPowerManagement *pm;
diff --git a/libvirt-designer/libvirt-designer-domain.h b/libvirt-designer/libvirt-designer-domain.h
index 981fd2e..643e3bf 100644
--- a/libvirt-designer/libvirt-designer-domain.h
+++ b/libvirt-designer/libvirt-designer-domain.h
@@ -135,6 +135,7 @@ GVirConfigDomainInterface *gvir_designer_domain_add_interface_network(GVirDesign
 GVirConfigDomainGraphics *gvir_designer_domain_add_graphics(GVirDesignerDomain *design,
                                                             GVirDesignerDomainGraphics type,
                                                             GError **error);
+GVirConfigDomainSmartcard *gvir_designer_domain_add_smartcard(GVirDesignerDomain *design, GError **error);
 GVirConfigDomainSound *gvir_designer_domain_add_sound(GVirDesignerDomain *design, GError **error);
 GVirConfigDomainRedirdev *gvir_designer_domain_add_usb_redir(GVirDesignerDomain *design, GError **error);
 
diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
index 2894dee..da2cad6 100644
--- a/libvirt-designer/libvirt-designer.sym
+++ b/libvirt-designer/libvirt-designer.sym
@@ -22,6 +22,7 @@ LIBVIRT_DESIGNER_0.0.2 {
 	gvir_designer_domain_add_floppy_device;
 	gvir_designer_domain_add_graphics;
 	gvir_designer_domain_add_interface_network;
+	gvir_designer_domain_add_smartcard;
 	gvir_designer_domain_add_sound;
 	gvir_designer_domain_add_usb_redir;
 
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]