[spice-gtk,v2] smartcard: Warn if multiple readers are detected

Submitted by Christophe Fergeau on Feb. 22, 2019, 9:07 a.m.

Details

Message ID 20190222090718.27910-1-cfergeau@redhat.com
State New
Headers show
Series "smartcard: Warn if multiple readers are detected" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Christophe Fergeau Feb. 22, 2019, 9:07 a.m.
spice-server does not deal properly with multiple smartcard readers,
only the first one will be working. Add a warning when this happens to
make it easier to diagnose such issues.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
---

Alternate version using g_list_length rather than manually counting the
elements.

 src/smartcard-manager.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
index ceecfdc7..144caf9b 100644
--- a/src/smartcard-manager.c
+++ b/src/smartcard-manager.c
@@ -389,6 +389,24 @@  typedef struct {
     GError *err;
 } SmartcardManagerInitArgs;
 
+
+static void unref_smartcard_reader(gpointer data)
+{
+    g_boxed_free(SPICE_TYPE_SMARTCARD_READER, data);
+}
+
+/* spice-server only supports one smartcard reader being in use */
+static void smartcard_check_reader_count(void)
+{
+    GList *readers;
+
+    readers = spice_smartcard_manager_get_readers(spice_smartcard_manager_get());
+    if (g_list_length(readers) > 1) {
+        g_warning("Multiple smartcard readers are plugged in, only the first one will be shared with the VM");
+    }
+    g_list_free_full(readers, unref_smartcard_reader);
+}
+
 static gboolean smartcard_manager_init(SmartcardManagerInitArgs *args)
 {
     gchar *emul_args = NULL;
@@ -442,6 +460,7 @@  init:
                                 "Failed to initialize smartcard");
         goto end;
     }
+    smartcard_check_reader_count();
 
     retval = TRUE;
 

Comments

> 
> spice-server does not deal properly with multiple smartcard readers,
> only the first one will be working. Add a warning when this happens to
> make it easier to diagnose such issues.
> 
> Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> ---
> 
> Alternate version using g_list_length rather than manually counting the
> elements.
> 
>  src/smartcard-manager.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
> index ceecfdc7..144caf9b 100644
> --- a/src/smartcard-manager.c
> +++ b/src/smartcard-manager.c
> @@ -389,6 +389,24 @@ typedef struct {
>      GError *err;
>  } SmartcardManagerInitArgs;
>  
> +
> +static void unref_smartcard_reader(gpointer data)

We usually use verbs after the name, like smartcard_reader_unref.

> +{
> +    g_boxed_free(SPICE_TYPE_SMARTCARD_READER, data);
> +}
> +
> +/* spice-server only supports one smartcard reader being in use */
> +static void smartcard_check_reader_count(void)
> +{
> +    GList *readers;
> +
> +    readers =
> spice_smartcard_manager_get_readers(spice_smartcard_manager_get());
> +    if (g_list_length(readers) > 1) {
> +        g_warning("Multiple smartcard readers are plugged in, only the first
> one will be shared with the VM");
> +    }
> +    g_list_free_full(readers, unref_smartcard_reader);
> +}
> +
>  static gboolean smartcard_manager_init(SmartcardManagerInitArgs *args)
>  {
>      gchar *emul_args = NULL;
> @@ -442,6 +460,7 @@ init:
>                                  "Failed to initialize smartcard");
>          goto end;
>      }
> +    smartcard_check_reader_count();
>  
>      retval = TRUE;
>  

I think the ack from Marc-andre is still valid, nothing against it.

Frediano
Hi

On Fri, Feb 22, 2019 at 10:44 AM Frediano Ziglio <fziglio@redhat.com> wrote:
>
> >
> > spice-server does not deal properly with multiple smartcard readers,
> > only the first one will be working. Add a warning when this happens to
> > make it easier to diagnose such issues.
> >
> > Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
> > ---
> >
> > Alternate version using g_list_length rather than manually counting the
> > elements.
> >
> >  src/smartcard-manager.c | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
> > index ceecfdc7..144caf9b 100644
> > --- a/src/smartcard-manager.c
> > +++ b/src/smartcard-manager.c
> > @@ -389,6 +389,24 @@ typedef struct {
> >      GError *err;
> >  } SmartcardManagerInitArgs;
> >
> > +
> > +static void unref_smartcard_reader(gpointer data)
>
> We usually use verbs after the name, like smartcard_reader_unref.

And in this case, it should probably be smartcard_reader_free()
(otherwise I expect _ref to exist!)

>
> > +{
> > +    g_boxed_free(SPICE_TYPE_SMARTCARD_READER, data);
> > +}
> > +
> > +/* spice-server only supports one smartcard reader being in use */
> > +static void smartcard_check_reader_count(void)
> > +{
> > +    GList *readers;
> > +
> > +    readers =
> > spice_smartcard_manager_get_readers(spice_smartcard_manager_get());
> > +    if (g_list_length(readers) > 1) {
> > +        g_warning("Multiple smartcard readers are plugged in, only the first
> > one will be shared with the VM");
> > +    }
> > +    g_list_free_full(readers, unref_smartcard_reader);
> > +}
> > +
> >  static gboolean smartcard_manager_init(SmartcardManagerInitArgs *args)
> >  {
> >      gchar *emul_args = NULL;
> > @@ -442,6 +460,7 @@ init:
> >                                  "Failed to initialize smartcard");
> >          goto end;
> >      }
> > +    smartcard_check_reader_count();
> >
> >      retval = TRUE;
> >
>
> I think the ack from Marc-andre is still valid, nothing against it.
>
> Frediano
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel