2008-03-04 12:36:28 +00:00
|
|
|
/*
|
|
|
|
|
* fprintd example to verify a fingerprint
|
|
|
|
|
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-04-07 01:12:44 +03:00
|
|
|
#include <stdio.h>
|
2008-03-04 12:36:28 +00:00
|
|
|
#include <stdlib.h>
|
2008-11-19 20:05:54 +00:00
|
|
|
#include <string.h>
|
2008-03-04 12:36:28 +00:00
|
|
|
#include <dbus/dbus-glib-bindings.h>
|
2008-03-05 20:00:28 +00:00
|
|
|
#include "manager-dbus-glue.h"
|
|
|
|
|
#include "device-dbus-glue.h"
|
2008-11-22 00:00:06 +00:00
|
|
|
#include "marshal.h"
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
static DBusGProxy *manager = NULL;
|
2008-03-04 12:36:28 +00:00
|
|
|
static DBusGConnection *connection = NULL;
|
2008-11-19 20:05:54 +00:00
|
|
|
static char *finger_name = "any";
|
2008-10-30 22:35:34 +00:00
|
|
|
static gboolean g_fatal_warnings = FALSE;
|
|
|
|
|
static char **usernames = NULL;
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
static void create_manager(void)
|
2008-03-04 12:36:28 +00:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2008-05-13 20:02:08 +01:00
|
|
|
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
2008-03-04 12:36:28 +00:00
|
|
|
if (connection == NULL)
|
|
|
|
|
g_error("Failed to connect to session bus: %s", error->message);
|
|
|
|
|
|
2008-05-13 20:02:08 +01:00
|
|
|
manager = dbus_g_proxy_new_for_name(connection,
|
2008-03-05 20:00:28 +00:00
|
|
|
"net.reactivated.Fprint", "/net/reactivated/Fprint/Manager",
|
2008-05-13 20:02:08 +01:00
|
|
|
"net.reactivated.Fprint.Manager");
|
2008-03-04 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-30 16:53:05 +00:00
|
|
|
static DBusGProxy *open_device(const char *username)
|
2008-03-04 12:36:28 +00:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
2008-03-05 20:00:28 +00:00
|
|
|
gchar *path;
|
|
|
|
|
DBusGProxy *dev;
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-11-20 10:53:32 +00:00
|
|
|
if (!net_reactivated_Fprint_Manager_get_default_device(manager, &path, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("list_devices failed: %s", error->message);
|
|
|
|
|
|
2008-11-20 10:53:32 +00:00
|
|
|
if (path == NULL) {
|
2008-03-04 12:36:28 +00:00
|
|
|
g_print("No devices found\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
g_print("Using device %s\n", path);
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
/* FIXME use for_name_owner?? */
|
|
|
|
|
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
|
|
|
|
path, "net.reactivated.Fprint.Device");
|
|
|
|
|
|
2008-11-20 10:53:32 +00:00
|
|
|
g_free (path);
|
2008-03-05 20:00:28 +00:00
|
|
|
|
2008-10-30 16:53:05 +00:00
|
|
|
if (!net_reactivated_Fprint_Device_claim(dev, username, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("failed to claim device: %s", error->message);
|
2008-11-03 17:20:59 +00:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
return dev;
|
2008-03-04 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-10-30 22:35:34 +00:00
|
|
|
static void find_finger(DBusGProxy *dev, const char *username)
|
2008-03-04 12:36:28 +00:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
2008-11-19 20:05:54 +00:00
|
|
|
char **fingers;
|
2008-03-04 12:36:28 +00:00
|
|
|
guint i;
|
|
|
|
|
|
2008-10-30 16:53:05 +00:00
|
|
|
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("ListEnrolledFingers failed: %s", error->message);
|
|
|
|
|
|
2008-11-19 20:05:54 +00:00
|
|
|
if (fingers == NULL || g_strv_length (fingers) == 0) {
|
2008-03-04 12:36:28 +00:00
|
|
|
g_print("No fingers enrolled for this device.\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_print("Listing enrolled fingers:\n");
|
2008-11-19 20:05:54 +00:00
|
|
|
for (i = 0; fingers[i] != NULL; i++) {
|
|
|
|
|
g_print(" - #%d: %s\n", i, fingers[i]);
|
2008-03-04 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-19 20:05:54 +00:00
|
|
|
if (strcmp (finger_name, "any") == 0)
|
|
|
|
|
finger_name = fingers[0];
|
|
|
|
|
|
|
|
|
|
g_strfreev (fingers);
|
2008-03-04 12:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-11-21 10:26:06 +00:00
|
|
|
static void verify_result(GObject *object, const char *result, gboolean done, void *user_data)
|
2008-03-06 13:12:34 +00:00
|
|
|
{
|
|
|
|
|
gboolean *verify_completed = user_data;
|
2008-11-20 16:51:46 +00:00
|
|
|
g_print("Verify result: %s\n", result);
|
2008-11-21 10:26:06 +00:00
|
|
|
if (done != FALSE)
|
2008-03-06 13:12:34 +00:00
|
|
|
*verify_completed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-19 20:05:54 +00:00
|
|
|
static void verify_finger_selected(GObject *object, const char *name, void *user_data)
|
2008-10-30 22:35:34 +00:00
|
|
|
{
|
2008-11-19 20:05:54 +00:00
|
|
|
g_print("Verifying: %s\n", name);
|
2008-10-30 22:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_verify(DBusGProxy *dev)
|
2008-03-04 12:36:28 +00:00
|
|
|
{
|
|
|
|
|
GError *error;
|
2008-03-06 13:12:34 +00:00
|
|
|
gboolean verify_completed = FALSE;
|
|
|
|
|
|
2008-11-22 00:00:06 +00:00
|
|
|
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
|
2008-10-30 22:35:34 +00:00
|
|
|
dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_INT, NULL);
|
2008-03-06 16:37:19 +00:00
|
|
|
dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result),
|
2008-11-22 00:00:06 +00:00
|
|
|
&verify_completed, NULL);
|
2008-10-30 22:35:34 +00:00
|
|
|
dbus_g_proxy_connect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected),
|
|
|
|
|
NULL, NULL);
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-11-19 20:05:54 +00:00
|
|
|
if (!net_reactivated_Fprint_Device_verify_start(dev, finger_name, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("VerifyStart failed: %s", error->message);
|
|
|
|
|
|
2008-03-06 13:12:34 +00:00
|
|
|
while (!verify_completed)
|
|
|
|
|
g_main_context_iteration(NULL, TRUE);
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-03-06 16:37:19 +00:00
|
|
|
dbus_g_proxy_disconnect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result), &verify_completed);
|
2008-10-30 22:35:34 +00:00
|
|
|
dbus_g_proxy_disconnect_signal(dev, "VerifyFingerSelected", G_CALLBACK(verify_finger_selected), NULL);
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
if (!net_reactivated_Fprint_Device_verify_stop(dev, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("VerifyStop failed: %s", error->message);
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-05 20:00:28 +00:00
|
|
|
static void release_device(DBusGProxy *dev)
|
2008-03-04 12:36:28 +00:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
2008-03-05 20:00:28 +00:00
|
|
|
if (!net_reactivated_Fprint_Device_release(dev, &error))
|
2008-03-04 12:36:28 +00:00
|
|
|
g_error("ReleaseDevice failed: %s", error->message);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-30 22:35:34 +00:00
|
|
|
static const GOptionEntry entries[] = {
|
2008-11-19 20:05:54 +00:00
|
|
|
{ "finger", 'f', 0, G_OPTION_ARG_STRING, &finger_name, "Finger selected to verify (default is automatic)", NULL },
|
2008-10-30 22:35:34 +00:00
|
|
|
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
|
|
|
|
|
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &usernames, NULL, "[username]" },
|
|
|
|
|
{ NULL }
|
|
|
|
|
};
|
|
|
|
|
|
2008-03-04 12:36:28 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2008-10-30 22:35:34 +00:00
|
|
|
GOptionContext *context;
|
2008-03-04 12:36:28 +00:00
|
|
|
GMainLoop *loop;
|
2008-10-30 22:35:34 +00:00
|
|
|
GError *err = NULL;
|
2008-03-05 20:00:28 +00:00
|
|
|
DBusGProxy *dev;
|
2008-10-30 16:53:05 +00:00
|
|
|
char *username;
|
2008-03-04 12:36:28 +00:00
|
|
|
|
|
|
|
|
g_type_init();
|
2008-10-30 22:35:34 +00:00
|
|
|
|
2008-11-22 00:00:06 +00:00
|
|
|
dbus_g_object_register_marshaller (fprintd_marshal_VOID__STRING_BOOLEAN,
|
|
|
|
|
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID);
|
|
|
|
|
|
2008-10-30 22:35:34 +00:00
|
|
|
context = g_option_context_new ("Verify a fingerprint");
|
|
|
|
|
g_option_context_add_main_entries (context, entries, NULL);
|
|
|
|
|
|
|
|
|
|
if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
|
|
|
|
|
g_print ("couldn't parse command-line options: %s\n", err->message);
|
|
|
|
|
g_error_free (err);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (usernames == NULL) {
|
|
|
|
|
username = "";
|
|
|
|
|
} else {
|
|
|
|
|
username = usernames[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_fatal_warnings) {
|
|
|
|
|
GLogLevelFlags fatal_mask;
|
|
|
|
|
|
|
|
|
|
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
|
|
|
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
|
|
|
g_log_set_always_fatal (fatal_mask);
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-04 12:36:28 +00:00
|
|
|
loop = g_main_loop_new(NULL, FALSE);
|
2008-03-05 20:00:28 +00:00
|
|
|
create_manager();
|
2008-03-04 12:36:28 +00:00
|
|
|
|
2008-10-30 16:53:05 +00:00
|
|
|
dev = open_device(username);
|
2008-10-30 22:35:34 +00:00
|
|
|
find_finger(dev, username);
|
|
|
|
|
do_verify(dev);
|
2008-03-05 20:00:28 +00:00
|
|
|
release_device(dev);
|
2008-03-04 12:36:28 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|