From 34e16a827fdef11f4821cea1c206705a751d9e96 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 18 Jan 2017 16:34:07 +0100 Subject: [PATCH] tests: add 'fprint-check' to check system is on Will use the manager.HasPrints() DBus method to query if the fingerprint system has any prints for the given user. https://bugs.freedesktop.org/show_bug.cgi?id=99811 --- tests/Makefile.am | 6 ++++- tests/check.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/check.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 01e2184..e6ccffd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ BUILT_SOURCES = manager-dbus-glue.h device-dbus-glue.h $(MARSHALFILES) noinst_HEADERS = $(BUILT_SOURCES) CLEANFILES = $(BUILT_SOURCES) -bin_PROGRAMS = fprintd-verify fprintd-enroll fprintd-list fprintd-delete +bin_PROGRAMS = fprintd-verify fprintd-enroll fprintd-list fprintd-delete fprintd-check fprintd_verify_SOURCES = verify.c $(MARSHALFILES) fprintd_verify_CFLAGS = $(WARN_CFLAGS) $(GLIB_CFLAGS) @@ -20,6 +20,10 @@ fprintd_delete_SOURCES = delete.c fprintd_delete_CFLAGS = $(WARN_CFLAGS) $(GLIB_CFLAGS) fprintd_delete_LDADD = $(GLIB_LIBS) +fprintd_check_SOURCES = check.c +fprintd_check_CFLAGS = $(WARN_CFLAGS) $(GLIB_CFLAGS) +fprintd_check_LDADD = $(GLIB_LIBS) + manager-dbus-glue.h: ../src/manager.xml dbus-binding-tool --prefix=fprint_manager --mode=glib-client $< --output=$@ diff --git a/tests/check.c b/tests/check.c new file mode 100644 index 0000000..a72ea47 --- /dev/null +++ b/tests/check.c @@ -0,0 +1,80 @@ +/* + * fprintd example to check if system is active and user has prints + * Copyright (C) 2016 Christian Kellner + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include "manager-dbus-glue.h" + +#include + +static DBusGProxy *manager = NULL; +static DBusGConnection *connection = NULL; + +static void create_manager(void) +{ + GError *error = NULL; + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + g_fprintf(stderr, "Failed to connect to session bus: %s\n", error->message); + exit (1); + } + + manager = dbus_g_proxy_new_for_name(connection, + "net.reactivated.Fprint", "/net/reactivated/Fprint/Manager", + "net.reactivated.Fprint.Manager"); +} + + +int main(int argc, char **argv) +{ + gboolean active; + gboolean ok; + GError *error = NULL; + char *user; + +#if !GLIB_CHECK_VERSION (2, 36, 0) + g_type_init(); +#endif + + create_manager(); + + if (argc != 2) { + g_print ("Usage: %s \n", argv[0]); + return 1; + } + + user = argv[1]; + + ok = dbus_g_proxy_call (manager, "HasPrints", &error, + G_TYPE_STRING, user, G_TYPE_INVALID, + G_TYPE_BOOLEAN, &active, G_TYPE_INVALID); + + if (!ok) { + g_fprintf(stderr, "HasPrints call failed: %s\n", error->message); + exit(1); + } + + g_print("User '%s' has %s fingerprints enrolled.\n", user, + active ? "indeed" : "no"); + + return 0; +} + -- 2.9.3