mirror of
https://gitlab.freedesktop.org/libfprint/fprintd.git
synced 2025-12-20 04:40:05 +01:00
fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide various features we can take advantage of, like the ones for async authentication mechanism. So, remove all the dbus-glib dependencies and simplify the code, but without any further refactor, and keeping everything as it used to work, while this will give room for further improvements in subsequent commits. Internally, we just use dbus-codegen to generate the skeletons, and we use the generated FprintdDBusManager with composition, while we implement the device skeleton interface in FprintDevice, so that we don't have to use it as a proxy, and keep being closer to what it used to be with dbus-glib. Fixes: #61
This commit is contained in:
parent
e224913b80
commit
93bad82540
15 changed files with 750 additions and 588 deletions
|
|
@ -68,11 +68,11 @@ endif
|
|||
# Dependencies
|
||||
glib_dep = dependency('glib-2.0', version: '>=' + glib_min_version)
|
||||
gio_dep = dependency('gio-2.0', version: '>=' + glib_min_version)
|
||||
gio_unix_dep = dependency('gio-unix-2.0', version: '>=' + glib_min_version)
|
||||
gmodule_dep = dependency('gmodule-2.0', version: '>=' + glib_min_version)
|
||||
libfprint_dep = dependency('libfprint-2', version: '>=' + libfprint_min_version)
|
||||
polkit_gobject_dep = dependency('polkit-gobject-1', version: '>= 0.91')
|
||||
dbus_dep = dependency('dbus-1', required: false)
|
||||
dbus_glib_dep = dependency('dbus-glib-1')
|
||||
libsystemd_dep = dependency('libsystemd', required: get_option('pam'))
|
||||
pam_dep = cc.find_library('pam',
|
||||
required: get_option('pam'),
|
||||
|
|
|
|||
555
src/device.c
555
src/device.c
File diff suppressed because it is too large
Load diff
|
|
@ -12,9 +12,6 @@
|
|||
|
||||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
||||
<interface name="net.reactivated.Fprint.Device">
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol"
|
||||
value="fprint_device" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:title id="polkit-integration">
|
||||
PolicyKit integration
|
||||
|
|
@ -282,8 +279,6 @@
|
|||
<arg type="as" name="enrolled_fingers" direction="out">
|
||||
<doc:doc><doc:summary>An array of strings representing the enrolled fingerprints. See <doc:ref type="description" to="fingerprint-names">Fingerprint names</doc:ref>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -304,8 +299,6 @@
|
|||
<arg type="s" name="username" direction="in">
|
||||
<doc:doc><doc:summary>The username for whom to delete the enrolled fingerprints. See <doc:ref type="description" to="usernames">Usernames</doc:ref>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -327,8 +320,6 @@
|
|||
<!-- ************************************************************ -->
|
||||
|
||||
<method name="DeleteEnrolledFingers2">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -348,8 +339,6 @@
|
|||
<arg type="s" name="username" direction="in">
|
||||
<doc:doc><doc:summary>The username for whom to claim the device. See <doc:ref type="description" to="usernames">Usernames</doc:ref>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -368,8 +357,6 @@
|
|||
<!-- ************************************************************ -->
|
||||
|
||||
<method name="Release">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -390,8 +377,6 @@
|
|||
<arg type="s" name="finger_name" direction="in">
|
||||
<doc:doc><doc:summary>A string representing the finger to verify. See <doc:ref type="description" to="fingerprint-names">Fingerprint names</doc:ref>.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -415,8 +400,6 @@
|
|||
<!-- ************************************************************ -->
|
||||
|
||||
<method name="VerifyStop">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -486,8 +469,6 @@
|
|||
<doc:ref type="description" to="fingerprint-names">Fingerprint names</doc:ref>.
|
||||
Note that "any" is not a valid finger name for this method.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
@ -511,8 +492,6 @@
|
|||
<!-- ************************************************************ -->
|
||||
|
||||
<method name="EnrollStop">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value="" />
|
||||
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
VOID:STRING,BOOLEAN
|
||||
|
|
@ -20,19 +20,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <gio/gio.h>
|
||||
#include <fprint.h>
|
||||
#include "fprintd-dbus.h"
|
||||
|
||||
/* General */
|
||||
#define TIMEOUT 30
|
||||
#define FPRINT_SERVICE_NAME "net.reactivated.Fprint"
|
||||
#define FPRINT_SERVICE_PATH "/net/reactivated/Fprint"
|
||||
|
||||
/* Errors */
|
||||
GQuark fprint_error_quark(void);
|
||||
GType fprint_error_get_type(void);
|
||||
|
||||
#define FPRINT_ERROR fprint_error_quark()
|
||||
#define FPRINT_TYPE_ERROR fprint_error_get_type()
|
||||
#define FPRINT_ERROR_DBUS_INTERFACE "net.reactivated.Fprint.Error"
|
||||
typedef enum {
|
||||
FPRINT_ERROR_CLAIM_DEVICE, /* developer didn't claim the device */
|
||||
|
|
@ -53,23 +53,18 @@ struct _FprintManager {
|
|||
GObject parent;
|
||||
};
|
||||
|
||||
FprintManager *fprint_manager_new(gboolean no_timeout);
|
||||
FprintManager *fprint_manager_new (GDBusConnection *connection, gboolean no_timeout);
|
||||
|
||||
/* Device */
|
||||
#define FPRINT_TYPE_DEVICE (fprint_device_get_type())
|
||||
G_DECLARE_FINAL_TYPE (FprintDevice, fprint_device, FPRINT, DEVICE, GObject)
|
||||
G_DECLARE_FINAL_TYPE (FprintDevice, fprint_device, FPRINT, DEVICE,
|
||||
FprintDBusDeviceSkeleton)
|
||||
|
||||
struct _FprintDevice {
|
||||
GObject parent;
|
||||
FprintDBusDeviceSkeleton parent;
|
||||
};
|
||||
|
||||
FprintDevice *fprint_device_new(FpDevice *dev);
|
||||
guint32 _fprint_device_get_id(FprintDevice *rdev);
|
||||
/* Print */
|
||||
/* TODO */
|
||||
|
||||
/* Binding data included in main.c through server-bindings.h which individual
|
||||
* class implementations need to access.
|
||||
*/
|
||||
extern const DBusGObjectInfo dbus_glib_fprint_manager_object_info;
|
||||
extern const DBusGObjectInfo dbus_glib_fprint_device_object_info;
|
||||
|
|
|
|||
62
src/main.c
62
src/main.c
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* fprint D-Bus daemon
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
#include <poll.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <fprint.h>
|
||||
|
|
@ -37,7 +38,6 @@
|
|||
|
||||
fp_storage store;
|
||||
|
||||
DBusGConnection *fprintd_dbus_conn = NULL;
|
||||
static gboolean no_timeout = FALSE;
|
||||
static gboolean g_fatal_warnings = FALSE;
|
||||
|
||||
|
|
@ -139,13 +139,33 @@ static gboolean sigterm_callback(gpointer data)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_acquired (GDBusConnection *connection,
|
||||
const char *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_debug ("D-Bus service launched with name: %s", name);
|
||||
}
|
||||
|
||||
static void
|
||||
on_name_lost (GDBusConnection *connection,
|
||||
const char *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
GMainLoop *loop = user_data;
|
||||
|
||||
g_warning ("Failed to get name: %s", name);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_autoptr(GOptionContext) context = NULL;
|
||||
g_autoptr(GMainLoop) loop = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
FprintManager *manager;
|
||||
DBusGProxy *driver_proxy;
|
||||
g_autoptr(FprintManager) manager = NULL;
|
||||
g_autoptr(GDBusConnection) connection = NULL;
|
||||
guint32 request_name_ret;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
|
@ -170,16 +190,13 @@ int main(int argc, char **argv)
|
|||
g_log_set_always_fatal (fatal_mask);
|
||||
}
|
||||
|
||||
/* Obtain a connection to the session bus */
|
||||
fprintd_dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||
if (fprintd_dbus_conn == NULL) {
|
||||
/* Obtain a connection to the system bus */
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (!G_IS_DBUS_CONNECTION (connection)) {
|
||||
g_warning("Failed to open connection to bus: %s", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
driver_proxy = dbus_g_proxy_new_for_name(fprintd_dbus_conn,
|
||||
DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
|
||||
|
||||
/* Load the configuration file,
|
||||
* and the default storage plugin */
|
||||
if (!load_conf())
|
||||
|
|
@ -193,32 +210,23 @@ int main(int argc, char **argv)
|
|||
|
||||
/* create the one instance of the Manager object to be shared between
|
||||
* all fprintd users. This blocks until all the devices are enumerated */
|
||||
manager = fprint_manager_new (no_timeout);
|
||||
manager = fprint_manager_new (connection, no_timeout);
|
||||
|
||||
/* Obtain the well-known name after the manager has been initialized.
|
||||
* Otherwise a client immediately enumerating the devices will not see
|
||||
* any. */
|
||||
if (!org_freedesktop_DBus_request_name(driver_proxy, FPRINT_SERVICE_NAME,
|
||||
0, &request_name_ret, &error)) {
|
||||
g_warning("Failed to get name: %s", error->message);
|
||||
g_object_unref (manager);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
||||
g_warning ("Got result code %u from requesting name", request_name_ret);
|
||||
g_object_unref (manager);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_debug("D-Bus service launched with name: %s", FPRINT_SERVICE_NAME);
|
||||
request_name_ret = g_bus_own_name_on_connection (connection,
|
||||
FPRINT_SERVICE_NAME,
|
||||
G_BUS_NAME_OWNER_FLAGS_NONE,
|
||||
on_name_acquired,
|
||||
on_name_lost,
|
||||
loop, NULL);
|
||||
|
||||
g_debug("entering main loop");
|
||||
g_main_loop_run(loop);
|
||||
g_bus_unown_name (request_name_ret);
|
||||
g_debug("main loop completed");
|
||||
|
||||
g_object_unref (manager);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
208
src/manager.c
208
src/manager.c
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* /net/reactivated/Fprint/Manager object implementation
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -19,7 +20,6 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <fprint.h>
|
||||
|
|
@ -27,17 +27,16 @@
|
|||
|
||||
#include "fprintd.h"
|
||||
|
||||
extern DBusGConnection *fprintd_dbus_conn;
|
||||
|
||||
static void fprint_manager_constructed (GObject *object);
|
||||
static gboolean fprint_manager_get_devices(FprintManager *manager,
|
||||
GPtrArray **devices, GError **error);
|
||||
static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
||||
const char **device, GError **error);
|
||||
#include "manager-dbus-glue.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
FprintDBusManager *dbus_manager;
|
||||
FpContext *context;
|
||||
GSList *dev_registry;
|
||||
gboolean no_timeout;
|
||||
|
|
@ -46,28 +45,81 @@ typedef struct
|
|||
|
||||
G_DEFINE_TYPE_WITH_CODE(FprintManager, fprint_manager, G_TYPE_OBJECT, G_ADD_PRIVATE (FprintManager))
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
FPRINT_MANAGER_CONNECTION,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties[N_PROPS];
|
||||
|
||||
static void fprint_manager_finalize(GObject *object)
|
||||
{
|
||||
FprintManagerPrivate *priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
|
||||
|
||||
g_clear_object (&priv->dbus_manager);
|
||||
g_clear_object (&priv->connection);
|
||||
g_clear_object (&priv->context);
|
||||
g_slist_free(priv->dev_registry);
|
||||
|
||||
G_OBJECT_CLASS(fprint_manager_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void fprint_manager_set_property (GObject *object, guint property_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
FprintManager *self = FPRINT_MANAGER (object);
|
||||
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
|
||||
|
||||
switch (property_id) {
|
||||
case FPRINT_MANAGER_CONNECTION:
|
||||
priv->connection = g_value_dup_object (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void fprint_manager_get_property (GObject *object, guint property_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
FprintManager *self = FPRINT_MANAGER (object);
|
||||
FprintManagerPrivate *priv = fprint_manager_get_instance_private (self);
|
||||
|
||||
switch (property_id) {
|
||||
case FPRINT_MANAGER_CONNECTION:
|
||||
g_value_set_object (value, priv->connection);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void fprint_manager_class_init(FprintManagerClass *klass)
|
||||
{
|
||||
dbus_g_object_type_install_info(FPRINT_TYPE_MANAGER,
|
||||
&dbus_glib_fprint_manager_object_info);
|
||||
dbus_g_error_domain_register (FPRINT_ERROR, FPRINT_ERROR_DBUS_INTERFACE, FPRINT_TYPE_ERROR);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
G_OBJECT_CLASS(klass)->finalize = fprint_manager_finalize;
|
||||
object_class->constructed = fprint_manager_constructed;
|
||||
object_class->set_property = fprint_manager_set_property;
|
||||
object_class->get_property = fprint_manager_get_property;
|
||||
object_class->finalize = fprint_manager_finalize;
|
||||
|
||||
properties[FPRINT_MANAGER_CONNECTION] =
|
||||
g_param_spec_object ("connection",
|
||||
"Connection",
|
||||
"Set GDBus connection property",
|
||||
G_TYPE_DBUS_CONNECTION,
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static gchar *get_device_path(FprintDevice *rdev)
|
||||
{
|
||||
return g_strdup_printf("/net/reactivated/Fprint/Device/%d",
|
||||
return g_strdup_printf (FPRINT_SERVICE_PATH "/Device/%d",
|
||||
_fprint_device_get_id(rdev));
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +158,44 @@ fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintMana
|
|||
priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_get_devices (FprintManager *manager, GDBusMethodInvocation *invocation,
|
||||
FprintDBusManager *skeleton)
|
||||
{
|
||||
g_autoptr(GPtrArray) devices = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fprint_manager_get_devices (manager, &devices, &error)) {
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fprint_dbus_manager_complete_get_devices (skeleton, invocation,
|
||||
(const gchar *const *)
|
||||
devices->pdata);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_get_default_device (FprintManager *manager,
|
||||
GDBusMethodInvocation *invocation,
|
||||
FprintDBusManager *skeleton)
|
||||
{
|
||||
const gchar *device;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!fprint_manager_get_default_device (manager, &device, &error)) {
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fprint_dbus_manager_complete_get_default_device (skeleton, invocation,
|
||||
device);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
||||
{
|
||||
|
|
@ -118,8 +208,9 @@ device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
|||
|
||||
priv->dev_registry = g_slist_prepend (priv->dev_registry, rdev);
|
||||
path = get_device_path (rdev);
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn, path,
|
||||
G_OBJECT(rdev));
|
||||
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (rdev),
|
||||
priv->connection,
|
||||
path, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -140,7 +231,8 @@ device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
|||
|
||||
priv->dev_registry = g_slist_delete_link (priv->dev_registry, item);
|
||||
|
||||
dbus_g_connection_unregister_g_object(fprintd_dbus_conn, G_OBJECT(rdev));
|
||||
g_dbus_interface_skeleton_unexport (
|
||||
G_DBUS_INTERFACE_SKELETON (rdev));
|
||||
|
||||
g_signal_handlers_disconnect_by_data (rdev, manager);
|
||||
g_object_unref (rdev);
|
||||
|
|
@ -154,13 +246,29 @@ device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
|
|||
fprint_manager_in_use_notified (NULL, NULL, manager);
|
||||
}
|
||||
|
||||
static void
|
||||
fprint_manager_init (FprintManager *manager)
|
||||
static void fprint_manager_constructed (GObject *object)
|
||||
{
|
||||
FprintManager *manager = FPRINT_MANAGER (object);
|
||||
FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
|
||||
|
||||
priv->dbus_manager = fprint_dbus_manager_skeleton_new ();
|
||||
priv->context = fp_context_new ();
|
||||
|
||||
g_signal_connect_object (priv->dbus_manager,
|
||||
"handle-get-devices",
|
||||
G_CALLBACK (handle_get_devices),
|
||||
manager,
|
||||
G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (priv->dbus_manager,
|
||||
"handle-get-default-device",
|
||||
G_CALLBACK (handle_get_default_device),
|
||||
manager,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->dbus_manager),
|
||||
priv->connection,
|
||||
FPRINT_SERVICE_PATH "/Manager", NULL);
|
||||
|
||||
/* And register the signals for initial enumeration and hotplug. */
|
||||
g_signal_connect_object (priv->context,
|
||||
"device-added",
|
||||
|
|
@ -179,16 +287,20 @@ fprint_manager_init (FprintManager *manager)
|
|||
*/
|
||||
fp_context_enumerate (priv->context);
|
||||
|
||||
dbus_g_connection_register_g_object(fprintd_dbus_conn,
|
||||
"/net/reactivated/Fprint/Manager", G_OBJECT(manager));
|
||||
G_OBJECT_CLASS (fprint_manager_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
FprintManager *fprint_manager_new(gboolean no_timeout)
|
||||
static void
|
||||
fprint_manager_init (FprintManager *manager)
|
||||
{
|
||||
}
|
||||
|
||||
FprintManager *fprint_manager_new (GDBusConnection *connection, gboolean no_timeout)
|
||||
{
|
||||
FprintManagerPrivate *priv;
|
||||
GObject *object;
|
||||
|
||||
object = g_object_new(FPRINT_TYPE_MANAGER, NULL);
|
||||
object = g_object_new (FPRINT_TYPE_MANAGER, "connection", connection, NULL);
|
||||
priv = fprint_manager_get_instance_private (FPRINT_MANAGER (object));
|
||||
priv->no_timeout = no_timeout;
|
||||
|
||||
|
|
@ -213,10 +325,15 @@ static gboolean fprint_manager_get_devices(FprintManager *manager,
|
|||
|
||||
if (num_open > 0) {
|
||||
for (l = elem; l != NULL; l = l->next) {
|
||||
FprintDevice *rdev = l->data;
|
||||
g_ptr_array_add(devs, get_device_path(rdev));
|
||||
GDBusInterfaceSkeleton *dev_skeleton = l->data;
|
||||
const char *path;
|
||||
|
||||
path = g_dbus_interface_skeleton_get_object_path (
|
||||
dev_skeleton);
|
||||
g_ptr_array_add (devs, (char *) path);
|
||||
}
|
||||
}
|
||||
g_ptr_array_add (devs, NULL);
|
||||
|
||||
g_slist_free(elem);
|
||||
|
||||
|
|
@ -235,7 +352,8 @@ static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
|||
num_open = g_slist_length(elem);
|
||||
|
||||
if (num_open > 0) {
|
||||
*device = get_device_path (g_slist_last (elem)->data);
|
||||
GDBusInterfaceSkeleton *dev_skeleton = g_slist_last (elem)->data;
|
||||
*device = g_dbus_interface_skeleton_get_object_path (dev_skeleton);
|
||||
return TRUE;
|
||||
} else {
|
||||
g_set_error (error, FPRINT_ERROR, FPRINT_ERROR_NO_SUCH_DEVICE,
|
||||
|
|
@ -245,34 +363,28 @@ static gboolean fprint_manager_get_default_device(FprintManager *manager,
|
|||
}
|
||||
}
|
||||
|
||||
GQuark fprint_error_quark(void)
|
||||
#define ERROR_ENTRY(name, dbus_name) \
|
||||
{ FPRINT_ERROR_ ## name, FPRINT_ERROR_DBUS_INTERFACE "." dbus_name }
|
||||
GDBusErrorEntry fprint_error_entries[] =
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string("fprintd-error-quark");
|
||||
return quark;
|
||||
}
|
||||
ERROR_ENTRY (CLAIM_DEVICE, "ClaimDevice"),
|
||||
ERROR_ENTRY (ALREADY_IN_USE, "AlreadyInUse"),
|
||||
ERROR_ENTRY (INTERNAL, "Internal"),
|
||||
ERROR_ENTRY (PERMISSION_DENIED, "PermissionDenied"),
|
||||
ERROR_ENTRY (NO_ENROLLED_PRINTS, "NoEnrolledPrints"),
|
||||
ERROR_ENTRY (NO_ACTION_IN_PROGRESS, "NoActionInProgress"),
|
||||
ERROR_ENTRY (INVALID_FINGERNAME, "InvalidFingername"),
|
||||
ERROR_ENTRY (NO_SUCH_DEVICE, "NoSuchDevice"),
|
||||
};
|
||||
|
||||
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
|
||||
GType
|
||||
fprint_error_get_type (void)
|
||||
GQuark fprint_error_quark (void)
|
||||
{
|
||||
static GType etype = 0;
|
||||
|
||||
if (etype == 0) {
|
||||
static const GEnumValue values[] =
|
||||
{
|
||||
ENUM_ENTRY (FPRINT_ERROR_CLAIM_DEVICE, "ClaimDevice"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_ALREADY_IN_USE, "AlreadyInUse"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_INTERNAL, "Internal"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_PERMISSION_DENIED, "PermissionDenied"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_NO_ENROLLED_PRINTS, "NoEnrolledPrints"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_NO_ACTION_IN_PROGRESS, "NoActionInProgress"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_INVALID_FINGERNAME, "InvalidFingername"),
|
||||
ENUM_ENTRY (FPRINT_ERROR_NO_SUCH_DEVICE, "NoSuchDevice"),
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
etype = g_enum_register_static ("FprintError", values);
|
||||
static volatile gsize quark = 0;
|
||||
if (!quark) {
|
||||
g_dbus_error_register_error_domain ("fprintd-error-quark",
|
||||
&quark,
|
||||
fprint_error_entries,
|
||||
G_N_ELEMENTS (fprint_error_entries));
|
||||
}
|
||||
return etype;
|
||||
return (GQuark) quark;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
]>
|
||||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
||||
<interface name="net.reactivated.Fprint.Manager">
|
||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol"
|
||||
value="fprint_manager" />
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,10 @@
|
|||
fprintd_marshal = gnome.genmarshal('fprintd-marshal',
|
||||
prefix: 'fprintd_marshal',
|
||||
sources: 'fprintd-marshal.list',
|
||||
valist_marshallers: true,
|
||||
)
|
||||
|
||||
bash = find_program('bash')
|
||||
dbus_binding_tool = find_program('dbus-binding-tool')
|
||||
dbus_interfaces = ['Manager', 'Device']
|
||||
dbus_interfaces_files = []
|
||||
dbus_server_glue_sources = []
|
||||
|
||||
foreach interface_name: dbus_interfaces
|
||||
interface = interface_name.to_lower()
|
||||
interface_file = interface + '.xml'
|
||||
glue_name = interface + '-dbus-glue.h'
|
||||
dbus_server_glue_sources += custom_target(glue_name,
|
||||
input: interface_file,
|
||||
output: glue_name,
|
||||
command: [
|
||||
dbus_binding_tool,
|
||||
'--prefix=fprint_' + interface,
|
||||
'--mode=glib-server',
|
||||
'--output=@OUTPUT@',
|
||||
'@INPUT@',
|
||||
])
|
||||
|
||||
dbus_interfaces_files += custom_target('dbus_interface_' + interface,
|
||||
input: interface_file,
|
||||
output: 'net.reactivated.Fprint.@0@.xml'.format(interface_name),
|
||||
|
|
@ -34,14 +14,24 @@ foreach interface_name: dbus_interfaces
|
|||
)
|
||||
endforeach
|
||||
|
||||
fprintd_dbus_sources = gnome.gdbus_codegen('fprintd-dbus',
|
||||
sources: dbus_interfaces_files,
|
||||
autocleanup: 'all',
|
||||
interface_prefix: 'net.reactivated.Fprint.',
|
||||
namespace: 'FprintDBus',
|
||||
)
|
||||
|
||||
fprintd_deps = declare_dependency(
|
||||
include_directories: [
|
||||
include_directories('..'),
|
||||
],
|
||||
sources: [
|
||||
fprintd_dbus_sources,
|
||||
],
|
||||
dependencies: [
|
||||
dbus_glib_dep,
|
||||
glib_dep,
|
||||
gio_dep,
|
||||
gio_unix_dep,
|
||||
gmodule_dep,
|
||||
libfprint_dep,
|
||||
polkit_gobject_dep,
|
||||
|
|
@ -58,8 +48,6 @@ libfprintd_private = static_library('fprintd-private',
|
|||
'device.c',
|
||||
'fprintd.h',
|
||||
'manager.c',
|
||||
dbus_server_glue_sources,
|
||||
fprintd_marshal,
|
||||
],
|
||||
dependencies: fprintd_deps,
|
||||
gnu_symbol_visibility: 'hidden',
|
||||
|
|
|
|||
|
|
@ -16,15 +16,12 @@ import unittest
|
|||
import sys
|
||||
import subprocess
|
||||
import dbus
|
||||
import dbus.mainloop.glib
|
||||
import dbusmock
|
||||
import fcntl
|
||||
import os
|
||||
import time
|
||||
import pypamtest
|
||||
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
PAM_SUCCESS = 0
|
||||
PAM_AUTH_ERR = 7
|
||||
PAM_AUTHINFO_UNAVAIL = 9
|
||||
|
|
|
|||
105
utils/delete.c
105
utils/delete.c
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* fprintd example to delete fingerprints
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -20,109 +21,115 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include "manager-dbus-glue.h"
|
||||
#include "device-dbus-glue.h"
|
||||
#include "fprintd-dbus.h"
|
||||
|
||||
static DBusGProxy *manager = NULL;
|
||||
static DBusGConnection *connection = NULL;
|
||||
static FprintDBusManager *manager = NULL;
|
||||
static GDBusConnection *connection = NULL;
|
||||
|
||||
static void create_manager(void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (connection == NULL) {
|
||||
g_print("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");
|
||||
}
|
||||
|
||||
static void delete_fingerprints(DBusGProxy *dev, const char *username)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GHashTable *props;
|
||||
DBusGProxy *p;
|
||||
|
||||
p = dbus_g_proxy_new_from_proxy(dev, "org.freedesktop.DBus.Properties", NULL);
|
||||
if (!dbus_g_proxy_call (p, "GetAll", &error, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
|
||||
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
|
||||
g_print("GetAll on the Properties interface failed: %s\n", error->message);
|
||||
manager = fprint_dbus_manager_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
"/net/reactivated/Fprint/Manager",
|
||||
NULL, &error);
|
||||
if (manager == NULL) {
|
||||
g_print ("Failed to get Fprintd manager: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!net_reactivated_Fprint_Device_claim(dev, username, &error)) {
|
||||
static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
|
||||
g_print("failed to claim device: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!net_reactivated_Fprint_Device_delete_enrolled_fingers2(dev, &error)) {
|
||||
if (dbus_g_error_has_name (error, "net.reactivated.Fprint.Error.NoEnrolledPrints") == FALSE) {
|
||||
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
||||
if (!fprint_dbus_device_call_delete_enrolled_fingers2_sync (dev, NULL,
|
||||
&error)) {
|
||||
gboolean ignore_error = FALSE;
|
||||
if (g_dbus_error_is_remote_error (error)) {
|
||||
g_autofree char *dbus_error =
|
||||
g_dbus_error_get_remote_error (error);
|
||||
if (g_str_equal (dbus_error,
|
||||
"net.reactivated.Fprint.Error.NoEnrolledPrints")) {
|
||||
g_print ("No fingerprints to delete on %s\n",
|
||||
fprint_dbus_device_get_name (dev));
|
||||
ignore_error = TRUE;
|
||||
}
|
||||
}
|
||||
if (!ignore_error) {
|
||||
g_print("ListEnrolledFingers failed: %s\n",
|
||||
error->message);
|
||||
exit (1);
|
||||
} else {
|
||||
g_print ("No fingerprints to delete on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
|
||||
g_print ("No fingerprints to delete on %s\n",
|
||||
fprint_dbus_device_get_name (dev));
|
||||
g_clear_error (&error);
|
||||
}
|
||||
} else {
|
||||
g_print ("Fingerprints deleted on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
|
||||
g_print ("Fingerprints deleted on %s\n",
|
||||
fprint_dbus_device_get_name (dev));
|
||||
}
|
||||
|
||||
if (!net_reactivated_Fprint_Device_release(dev, &error)) {
|
||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_hash_table_destroy (props);
|
||||
g_object_unref (p);
|
||||
}
|
||||
|
||||
static void process_devices(char **argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GPtrArray *devices;
|
||||
g_auto(GStrv) devices = NULL;
|
||||
char *path;
|
||||
guint num_devices;
|
||||
guint i;
|
||||
|
||||
if (!net_reactivated_Fprint_Manager_get_devices(manager, &devices, &error)) {
|
||||
if (!fprint_dbus_manager_call_get_devices_sync (manager, &devices,
|
||||
NULL, &error)) {
|
||||
g_print("Impossible to get devices: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (devices->len == 0) {
|
||||
|
||||
num_devices = g_strv_length (devices);
|
||||
if (num_devices == 0) {
|
||||
g_print("No devices available\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_print("found %d devices\n", devices->len);
|
||||
for (i = 0; i < devices->len; i++) {
|
||||
path = g_ptr_array_index(devices, i);
|
||||
g_print ("found %u devices\n", num_devices);
|
||||
for (i = 0; devices[i] != NULL; i++) {
|
||||
path = devices[i];
|
||||
g_print("Device at %s\n", path);
|
||||
}
|
||||
|
||||
for (i = 0; i < devices->len; i++) {
|
||||
for (i = 0; devices[i] != NULL; i++) {
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
guint j;
|
||||
DBusGProxy *dev;
|
||||
|
||||
path = g_ptr_array_index(devices, i);
|
||||
path = devices[i];
|
||||
g_print("Using device %s\n", path);
|
||||
|
||||
/* FIXME use for_name_owner?? */
|
||||
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
||||
path, "net.reactivated.Fprint.Device");
|
||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
path, NULL, &error);
|
||||
|
||||
for (j = 1; argv[j] != NULL; j++)
|
||||
delete_fingerprints (dev, argv[j]);
|
||||
|
||||
g_object_unref (dev);
|
||||
}
|
||||
|
||||
g_ptr_array_foreach(devices, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free(devices, TRUE);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* fprintd example to enroll right index finger
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -21,17 +22,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include "manager-dbus-glue.h"
|
||||
#include "device-dbus-glue.h"
|
||||
#include "fprintd-marshal.h"
|
||||
#include "fprintd-dbus.h"
|
||||
|
||||
#define N_(x) x
|
||||
#define TR(x) x
|
||||
#include "fingerprint-strings.h"
|
||||
|
||||
static DBusGProxy *manager = NULL;
|
||||
static DBusGConnection *connection = NULL;
|
||||
static FprintDBusManager *manager = NULL;
|
||||
static GDBusConnection *connection = NULL;
|
||||
static char *finger_name = NULL;
|
||||
static char **usernames = NULL;
|
||||
|
||||
|
|
@ -39,41 +37,54 @@ static void create_manager(void)
|
|||
{
|
||||
GError *error = NULL;
|
||||
|
||||
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (connection == NULL) {
|
||||
g_print("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");
|
||||
manager = fprint_dbus_manager_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
"/net/reactivated/Fprint/Manager",
|
||||
NULL, &error);
|
||||
if (manager == NULL) {
|
||||
g_print ("Failed to get Fprintd manager: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static DBusGProxy *open_device(const char *username)
|
||||
static FprintDBusDevice *open_device (const char *username)
|
||||
{
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
GError *error = NULL;
|
||||
gchar *path;
|
||||
DBusGProxy *dev;
|
||||
|
||||
if (!net_reactivated_Fprint_Manager_get_default_device(manager, &path, &error)) {
|
||||
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
||||
NULL, &error)) {
|
||||
g_print("Impossible to enroll: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_print("Using device %s\n", path);
|
||||
|
||||
/* FIXME use for_name_owner?? */
|
||||
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
||||
path, "net.reactivated.Fprint.Device");
|
||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
path, NULL, &error);
|
||||
|
||||
g_free (path);
|
||||
|
||||
if (!net_reactivated_Fprint_Device_claim(dev, username, &error)) {
|
||||
if (error) {
|
||||
g_print ("failed to connect to device: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
|
||||
g_print("failed to claim device: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
return dev;
|
||||
return g_steal_pointer (&dev);
|
||||
}
|
||||
|
||||
static void enroll_result(GObject *object, const char *result, gboolean done, void *user_data)
|
||||
|
|
@ -84,16 +95,30 @@ static void enroll_result(GObject *object, const char *result, gboolean done, vo
|
|||
*enroll_completed = TRUE;
|
||||
}
|
||||
|
||||
static void do_enroll(DBusGProxy *dev)
|
||||
static void proxy_signal_cb (GDBusProxy *proxy,
|
||||
const gchar *sender_name,
|
||||
const gchar *signal_name,
|
||||
GVariant *parameters,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (g_str_equal (signal_name, "EnrollStatus")) {
|
||||
const gchar *result;
|
||||
gboolean done;
|
||||
|
||||
g_variant_get (parameters, "(&sb)", &result, &done);
|
||||
enroll_result (G_OBJECT (proxy), result, done, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_enroll (FprintDBusDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gboolean enroll_completed = FALSE;
|
||||
gboolean found;
|
||||
guint i;
|
||||
|
||||
dbus_g_proxy_add_signal(dev, "EnrollStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
|
||||
dbus_g_proxy_connect_signal(dev, "EnrollStatus", G_CALLBACK(enroll_result),
|
||||
&enroll_completed, NULL);
|
||||
g_signal_connect (dev, "g-signal", G_CALLBACK (proxy_signal_cb),
|
||||
&enroll_completed);
|
||||
|
||||
found = FALSE;
|
||||
for (i = 0; fingers[i].dbus_name != NULL; i++) {
|
||||
|
|
@ -118,7 +143,8 @@ static void do_enroll(DBusGProxy *dev)
|
|||
}
|
||||
|
||||
g_print("Enrolling %s finger.\n", finger_name);
|
||||
if (!net_reactivated_Fprint_Device_enroll_start(dev, finger_name, &error)) {
|
||||
if (!fprint_dbus_device_call_enroll_start_sync (dev, finger_name, NULL,
|
||||
&error)) {
|
||||
g_print("EnrollStart failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
|
@ -126,19 +152,18 @@ static void do_enroll(DBusGProxy *dev)
|
|||
while (!enroll_completed)
|
||||
g_main_context_iteration(NULL, TRUE);
|
||||
|
||||
dbus_g_proxy_disconnect_signal(dev, "EnrollStatus",
|
||||
G_CALLBACK(enroll_result), &enroll_completed);
|
||||
g_signal_handlers_disconnect_by_func (dev, proxy_signal_cb, &enroll_result);
|
||||
|
||||
if (!net_reactivated_Fprint_Device_enroll_stop(dev, &error)) {
|
||||
if (!fprint_dbus_device_call_enroll_stop_sync (dev, NULL, &error)) {
|
||||
g_print("VerifyStop failed: %s\n", error->message);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void release_device(DBusGProxy *dev)
|
||||
static void release_device (FprintDBusDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
if (!net_reactivated_Fprint_Device_release(dev, &error)) {
|
||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
|
@ -152,15 +177,12 @@ static const GOptionEntry entries[] = {
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
GOptionContext *context;
|
||||
GError *err = NULL;
|
||||
DBusGProxy *dev;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
dbus_g_object_register_marshaller (fprintd_marshal_VOID__STRING_BOOLEAN,
|
||||
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
|
||||
|
||||
context = g_option_context_new ("Enroll a fingerprint");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
||||
|
|
@ -175,7 +197,7 @@ int main(int argc, char **argv)
|
|||
|
||||
create_manager();
|
||||
|
||||
dev = open_device(usernames ? usernames[0] : NULL);
|
||||
dev = open_device (usernames ? usernames[0] : "");
|
||||
do_enroll(dev);
|
||||
release_device(dev);
|
||||
g_free(finger_name);
|
||||
|
|
|
|||
94
utils/list.c
94
utils/list.c
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* fprintd example to list enrolled fingerprints
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -20,38 +21,52 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include "manager-dbus-glue.h"
|
||||
#include "device-dbus-glue.h"
|
||||
#include "fprintd-dbus.h"
|
||||
|
||||
static DBusGProxy *manager = NULL;
|
||||
static DBusGConnection *connection = NULL;
|
||||
static FprintDBusManager *manager = NULL;
|
||||
static GDBusConnection *connection = NULL;
|
||||
|
||||
static void create_manager(void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (connection == NULL) {
|
||||
g_print("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");
|
||||
manager = fprint_dbus_manager_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
"/net/reactivated/Fprint/Manager",
|
||||
NULL, &error);
|
||||
if (manager == NULL) {
|
||||
g_print ("Failed to get Fprintd manager: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static void list_fingerprints(DBusGProxy *dev, const char *username)
|
||||
static void list_fingerprints (FprintDBusDevice *dev, const char *username)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char **fingers;
|
||||
GHashTable *props;
|
||||
DBusGProxy *p;
|
||||
guint i;
|
||||
|
||||
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error)) {
|
||||
if (dbus_g_error_has_name (error, "net.reactivated.Fprint.Error.NoEnrolledPrints") == FALSE) {
|
||||
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
||||
&fingers, NULL,
|
||||
&error)) {
|
||||
gboolean ignore_error = FALSE;
|
||||
if (g_dbus_error_is_remote_error (error)) {
|
||||
g_autofree char *dbus_error =
|
||||
g_dbus_error_get_remote_error (error);
|
||||
if (g_str_equal (dbus_error,
|
||||
"net.reactivated.Fprint.Error.NoEnrolledPrints")) {
|
||||
ignore_error = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignore_error) {
|
||||
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
||||
exit (1);
|
||||
} else {
|
||||
|
|
@ -60,24 +75,16 @@ static void list_fingerprints(DBusGProxy *dev, const char *username)
|
|||
}
|
||||
}
|
||||
|
||||
p = dbus_g_proxy_new_from_proxy(dev, "org.freedesktop.DBus.Properties", NULL);
|
||||
if (!dbus_g_proxy_call (p, "GetAll", &error, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
|
||||
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
|
||||
g_print("GetAll on the Properties interface failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (fingers == NULL || g_strv_length (fingers) == 0) {
|
||||
g_print("User %s has no fingers enrolled for %s.\n", username, g_value_get_string (g_hash_table_lookup (props, "name")));
|
||||
g_print ("User %s has no fingers enrolled for %s.\n", username,
|
||||
fprint_dbus_device_get_name (dev));
|
||||
return;
|
||||
}
|
||||
|
||||
g_print("Fingerprints for user %s on %s (%s):\n",
|
||||
username,
|
||||
g_value_get_string (g_hash_table_lookup (props, "name")),
|
||||
g_value_get_string (g_hash_table_lookup (props, "scan-type")));
|
||||
g_hash_table_destroy (props);
|
||||
g_object_unref (p);
|
||||
fprint_dbus_device_get_name (dev),
|
||||
fprint_dbus_device_get_scan_type (dev));
|
||||
|
||||
for (i = 0; fingers[i] != NULL; i++) {
|
||||
g_print(" - #%d: %s\n", i, fingers[i]);
|
||||
|
|
@ -88,46 +95,45 @@ static void list_fingerprints(DBusGProxy *dev, const char *username)
|
|||
|
||||
static void process_devices(char **argv)
|
||||
{
|
||||
g_auto(GStrv) devices = NULL;
|
||||
GError *error = NULL;
|
||||
GPtrArray *devices;
|
||||
char *path;
|
||||
guint num_devices;
|
||||
guint i;
|
||||
|
||||
if (!net_reactivated_Fprint_Manager_get_devices(manager, &devices, &error)) {
|
||||
if (!fprint_dbus_manager_call_get_devices_sync (manager, &devices, NULL,
|
||||
&error)) {
|
||||
g_print("Impossible to get devices: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (devices->len == 0) {
|
||||
|
||||
num_devices = g_strv_length (devices);
|
||||
if (num_devices == 0) {
|
||||
g_print("No devices available\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
g_print("found %d devices\n", devices->len);
|
||||
for (i = 0; i < devices->len; i++) {
|
||||
path = g_ptr_array_index(devices, i);
|
||||
g_print ("found %u devices\n", num_devices);
|
||||
for (i = 0; devices[i] != NULL; i++) {
|
||||
path = devices[i];
|
||||
g_print("Device at %s\n", path);
|
||||
}
|
||||
|
||||
for (i = 0; i < devices->len; i++) {
|
||||
for (i = 0; devices[i] != NULL; i++) {
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
guint j;
|
||||
DBusGProxy *dev;
|
||||
|
||||
path = g_ptr_array_index(devices, i);
|
||||
path = devices[i];
|
||||
g_print("Using device %s\n", path);
|
||||
|
||||
/* FIXME use for_name_owner?? */
|
||||
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
||||
path, "net.reactivated.Fprint.Device");
|
||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
path, NULL, &error);
|
||||
|
||||
for (j = 1; argv[j] != NULL; j++)
|
||||
list_fingerprints (dev, argv[j]);
|
||||
|
||||
g_object_unref (dev);
|
||||
}
|
||||
|
||||
g_ptr_array_foreach(devices, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free(devices, TRUE);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
|
|||
|
|
@ -1,42 +1,19 @@
|
|||
dbus_client_glue_sources = []
|
||||
|
||||
foreach interface_name: dbus_interfaces
|
||||
interface = interface_name.to_lower()
|
||||
interface_file = meson.source_root() / 'src' / interface + '.xml'
|
||||
glue_name = interface + '-dbus-glue.h'
|
||||
dbus_client_glue_sources += custom_target(glue_name,
|
||||
input: interface_file,
|
||||
output: glue_name,
|
||||
command: [
|
||||
dbus_binding_tool,
|
||||
'--prefix=fprint_' + interface,
|
||||
'--mode=glib-client',
|
||||
'--output=@OUTPUT@',
|
||||
'@INPUT@',
|
||||
])
|
||||
endforeach
|
||||
|
||||
libfprintd_utils_dep = declare_dependency(
|
||||
include_directories: [
|
||||
include_directories('../src'),
|
||||
include_directories('../pam'),
|
||||
],
|
||||
dependencies: [
|
||||
glib_dep,
|
||||
dbus_glib_dep,
|
||||
gio_dep,
|
||||
gio_unix_dep,
|
||||
],
|
||||
sources: [
|
||||
fprintd_marshal,
|
||||
dbus_client_glue_sources,
|
||||
fprintd_dbus_sources,
|
||||
],
|
||||
link_with: [
|
||||
libfprintd_private
|
||||
],
|
||||
link_with: static_library('fprintd_utils',
|
||||
sources: [
|
||||
dbus_client_glue_sources,
|
||||
fprintd_marshal,
|
||||
],
|
||||
dependencies: [
|
||||
glib_dep,
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
utils = [
|
||||
|
|
|
|||
107
utils/verify.c
107
utils/verify.c
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* fprintd example to verify a fingerprint
|
||||
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
||||
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -21,66 +22,79 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <dbus/dbus-glib-bindings.h>
|
||||
#include "manager-dbus-glue.h"
|
||||
#include "device-dbus-glue.h"
|
||||
#include "fprintd-marshal.h"
|
||||
#include <gio/gio.h>
|
||||
#include "fprintd-dbus.h"
|
||||
|
||||
static DBusGProxy *manager = NULL;
|
||||
static DBusGConnection *connection = NULL;
|
||||
static FprintDBusManager *manager = NULL;
|
||||
static GDBusConnection *connection = NULL;
|
||||
static char *finger_name = NULL;
|
||||
static gboolean g_fatal_warnings = FALSE;
|
||||
static char **usernames = NULL;
|
||||
|
||||
static void create_manager(void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||
if (connection == NULL) {
|
||||
g_print("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");
|
||||
manager = fprint_dbus_manager_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
"/net/reactivated/Fprint/Manager",
|
||||
NULL, &error);
|
||||
if (manager == NULL) {
|
||||
g_print ("Failed to get Fprintd manager: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static DBusGProxy *open_device(const char *username)
|
||||
static FprintDBusDevice *open_device (const char *username)
|
||||
{
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
GError *error = NULL;
|
||||
gchar *path;
|
||||
DBusGProxy *dev;
|
||||
|
||||
if (!net_reactivated_Fprint_Manager_get_default_device(manager, &path, &error)) {
|
||||
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
||||
NULL, &error)) {
|
||||
g_print("Impossible to verify: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_print("Using device %s\n", path);
|
||||
|
||||
/* FIXME use for_name_owner?? */
|
||||
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
||||
path, "net.reactivated.Fprint.Device");
|
||||
|
||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"net.reactivated.Fprint",
|
||||
path, NULL, &error);
|
||||
|
||||
g_free (path);
|
||||
|
||||
if (!net_reactivated_Fprint_Device_claim(dev, username, &error)) {
|
||||
if (error) {
|
||||
g_print ("failed to connect to device: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
|
||||
g_print("failed to claim device: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
return dev;
|
||||
return g_steal_pointer (&dev);
|
||||
}
|
||||
|
||||
static void find_finger(DBusGProxy *dev, const char *username)
|
||||
static void find_finger (FprintDBusDevice *dev, const char *username)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char **fingers;
|
||||
guint i;
|
||||
|
||||
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error)) {
|
||||
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
||||
&fingers,
|
||||
NULL, &error)) {
|
||||
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
|
@ -123,19 +137,36 @@ static void verify_finger_selected(GObject *object, const char *name, void *user
|
|||
g_print("Verifying: %s\n", name);
|
||||
}
|
||||
|
||||
static void do_verify(DBusGProxy *dev)
|
||||
static void proxy_signal_cb (GDBusProxy *proxy,
|
||||
const gchar *sender_name,
|
||||
const gchar *signal_name,
|
||||
GVariant *parameters,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (g_str_equal (signal_name, "VerifyStatus")) {
|
||||
const gchar *result;
|
||||
gboolean done;
|
||||
|
||||
g_variant_get (parameters, "(&sb)", &result, &done);
|
||||
verify_result (G_OBJECT (proxy), result, done, user_data);
|
||||
} else if (g_str_equal (signal_name, "VerifyFingerSelected")) {
|
||||
const gchar *name;
|
||||
|
||||
g_variant_get (parameters, "(&s)", &name);
|
||||
verify_finger_selected (G_OBJECT (proxy), name, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_verify (FprintDBusDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gboolean verify_completed = FALSE;
|
||||
|
||||
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
|
||||
dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_INT, NULL);
|
||||
dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result),
|
||||
&verify_completed, NULL);
|
||||
dbus_g_proxy_connect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected),
|
||||
NULL, NULL);
|
||||
g_signal_connect (dev, "g-signal", G_CALLBACK (proxy_signal_cb),
|
||||
&verify_completed);
|
||||
|
||||
if (!net_reactivated_Fprint_Device_verify_start(dev, finger_name, &error)) {
|
||||
if (!fprint_dbus_device_call_verify_start_sync (dev, finger_name, NULL,
|
||||
&error)) {
|
||||
g_print("VerifyStart failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
|
@ -143,19 +174,20 @@ static void do_verify(DBusGProxy *dev)
|
|||
while (!verify_completed)
|
||||
g_main_context_iteration(NULL, TRUE);
|
||||
|
||||
dbus_g_proxy_disconnect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result), &verify_completed);
|
||||
dbus_g_proxy_disconnect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected), NULL);
|
||||
|
||||
if (!net_reactivated_Fprint_Device_verify_stop(dev, &error)) {
|
||||
g_signal_handlers_disconnect_by_func (dev, proxy_signal_cb,
|
||||
&verify_completed);
|
||||
|
||||
if (!fprint_dbus_device_call_verify_stop_sync (dev, NULL, &error)) {
|
||||
g_print("VerifyStop failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
static void release_device(DBusGProxy *dev)
|
||||
static void release_device (FprintDBusDevice *dev)
|
||||
{
|
||||
GError *error = NULL;
|
||||
if (!net_reactivated_Fprint_Device_release(dev, &error)) {
|
||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
|
@ -170,16 +202,13 @@ static const GOptionEntry entries[] = {
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||
GOptionContext *context;
|
||||
GError *err = NULL;
|
||||
DBusGProxy *dev;
|
||||
const char *username = NULL;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
dbus_g_object_register_marshaller (fprintd_marshal_VOID__STRING_BOOLEAN,
|
||||
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
|
||||
|
||||
context = g_option_context_new ("Verify a fingerprint");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue