|
Packit |
f7449a |
/*
|
|
Packit |
f7449a |
* fprintd example to delete fingerprints
|
|
Packit |
f7449a |
* Copyright (C) 2008 Daniel Drake <dsd@gentoo.org>
|
|
Packit |
f7449a |
*
|
|
Packit |
f7449a |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
f7449a |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
f7449a |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
f7449a |
* (at your option) any later version.
|
|
Packit |
f7449a |
*
|
|
Packit |
f7449a |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
f7449a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
f7449a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
f7449a |
* GNU General Public License for more details.
|
|
Packit |
f7449a |
*
|
|
Packit |
f7449a |
* You should have received a copy of the GNU General Public License along
|
|
Packit |
f7449a |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
f7449a |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
f7449a |
*/
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
#include <stdio.h>
|
|
Packit |
f7449a |
#include <stdlib.h>
|
|
Packit |
f7449a |
#include <dbus/dbus-glib-bindings.h>
|
|
Packit |
f7449a |
#include "manager-dbus-glue.h"
|
|
Packit |
f7449a |
#include "device-dbus-glue.h"
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static DBusGProxy *manager = NULL;
|
|
Packit |
f7449a |
static DBusGConnection *connection = NULL;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static void create_manager(void)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GError *error = NULL;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
|
Packit |
f7449a |
if (connection == NULL) {
|
|
Packit |
f7449a |
g_print("Failed to connect to session bus: %s\n", error->message);
|
|
Packit |
f7449a |
exit (1);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
manager = dbus_g_proxy_new_for_name(connection,
|
|
Packit |
f7449a |
"net.reactivated.Fprint", "/net/reactivated/Fprint/Manager",
|
|
Packit |
f7449a |
"net.reactivated.Fprint.Manager");
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static void delete_fingerprints(DBusGProxy *dev, const char *username)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GError *error = NULL;
|
|
Packit |
f7449a |
GHashTable *props;
|
|
Packit |
f7449a |
DBusGProxy *p;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
p = dbus_g_proxy_new_from_proxy(dev, "org.freedesktop.DBus.Properties", NULL);
|
|
Packit |
f7449a |
if (!dbus_g_proxy_call (p, "GetAll", &error, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
|
|
Packit |
f7449a |
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
|
|
Packit |
f7449a |
g_print("GetAll on the Properties interface failed: %s\n", error->message);
|
|
Packit |
f7449a |
exit (1);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (!net_reactivated_Fprint_Device_delete_enrolled_fingers(dev, username, &error)) {
|
|
Packit |
f7449a |
if (dbus_g_error_has_name (error, "net.reactivated.Fprint.Error.NoEnrolledPrints") == FALSE) {
|
|
Packit |
f7449a |
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
|
Packit |
f7449a |
exit (1);
|
|
Packit |
f7449a |
} else {
|
|
Packit |
f7449a |
g_print ("No fingerprints to delete on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
} else {
|
|
Packit |
f7449a |
g_print ("Fingerprints deleted on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
g_hash_table_destroy (props);
|
|
Packit |
f7449a |
g_object_unref (p);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static void process_devices(char **argv)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GError *error = NULL;
|
|
Packit |
f7449a |
GPtrArray *devices;
|
|
Packit |
f7449a |
char *path;
|
|
Packit |
f7449a |
guint i;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (!net_reactivated_Fprint_Manager_get_devices(manager, &devices, &error)) {
|
|
Packit |
f7449a |
g_print("list_devices failed: %s\n", error->message);
|
|
Packit |
f7449a |
exit (1);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (devices->len == 0) {
|
|
Packit |
f7449a |
g_print("No devices found\n");
|
|
Packit |
f7449a |
exit(1);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_print("found %d devices\n", devices->len);
|
|
Packit |
f7449a |
for (i = 0; i < devices->len; i++) {
|
|
Packit |
f7449a |
path = g_ptr_array_index(devices, i);
|
|
Packit |
f7449a |
g_print("Device at %s\n", path);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
for (i = 0; i < devices->len; i++) {
|
|
Packit |
f7449a |
guint j;
|
|
Packit |
f7449a |
DBusGProxy *dev;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
path = g_ptr_array_index(devices, i);
|
|
Packit |
f7449a |
g_print("Using device %s\n", path);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
/* FIXME use for_name_owner?? */
|
|
Packit |
f7449a |
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
|
|
Packit |
f7449a |
path, "net.reactivated.Fprint.Device");
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
for (j = 1; argv[j] != NULL; j++)
|
|
Packit |
f7449a |
delete_fingerprints (dev, argv[j]);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_object_unref (dev);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_ptr_array_foreach(devices, (GFunc) g_free, NULL);
|
|
Packit |
f7449a |
g_ptr_array_free(devices, TRUE);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
int main(int argc, char **argv)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
#if !GLIB_CHECK_VERSION (2, 36, 0)
|
|
Packit |
f7449a |
g_type_init();
|
|
Packit |
f7449a |
#endif
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
create_manager();
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (argc < 2) {
|
|
Packit |
f7449a |
g_print ("Usage: %s <username> [usernames...]\n", argv[0]);
|
|
Packit |
f7449a |
return 1;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
process_devices (argv);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
return 0;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|