|
Packit |
f7449a |
/*
|
|
Packit |
f7449a |
* fprint D-Bus daemon
|
|
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 "config.h"
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
#include <poll.h>
|
|
Packit |
f7449a |
#include <stdlib.h>
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
#include <dbus/dbus-glib-bindings.h>
|
|
Packit |
f7449a |
#include <glib.h>
|
|
Packit |
f7449a |
#include <glib/gi18n.h>
|
|
Packit |
f7449a |
#include <fprint.h>
|
|
Packit |
f7449a |
#include <glib-object.h>
|
|
Packit |
f7449a |
#include <gmodule.h>
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
#include "fprintd.h"
|
|
Packit |
f7449a |
#include "storage.h"
|
|
Packit |
f7449a |
#include "file_storage.h"
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
extern DBusGConnection *fprintd_dbus_conn;
|
|
Packit |
f7449a |
static gboolean no_timeout = FALSE;
|
|
Packit |
f7449a |
static gboolean g_fatal_warnings = FALSE;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static void
|
|
Packit |
f7449a |
set_storage_file (void)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
store.init = &file_storage_init;
|
|
Packit |
f7449a |
store.deinit = &file_storage_deinit;
|
|
Packit |
f7449a |
store.print_data_save = &file_storage_print_data_save;
|
|
Packit |
f7449a |
store.print_data_load = &file_storage_print_data_load;
|
|
Packit |
f7449a |
store.print_data_delete = &file_storage_print_data_delete;
|
|
Packit |
f7449a |
store.discover_prints = &file_storage_discover_prints;
|
|
Packit |
f7449a |
store.discover_users = &file_storage_discover_users;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static gboolean
|
|
Packit |
f7449a |
load_storage_module (const char *module_name)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GModule *module;
|
|
Packit |
f7449a |
char *filename;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
filename = g_module_build_path (PLUGINDIR, module_name);
|
|
Packit |
f7449a |
module = g_module_open (filename, 0);
|
|
Packit |
f7449a |
g_free (filename);
|
|
Packit |
f7449a |
if (module == NULL)
|
|
Packit |
f7449a |
return FALSE;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (!g_module_symbol (module, "init", (gpointer *) &store.init) ||
|
|
Packit |
f7449a |
!g_module_symbol (module, "deinit", (gpointer *) &store.deinit) ||
|
|
Packit |
f7449a |
!g_module_symbol (module, "print_data_save", (gpointer *) &store.print_data_save) ||
|
|
Packit |
f7449a |
!g_module_symbol (module, "print_data_load", (gpointer *) &store.print_data_load) ||
|
|
Packit |
f7449a |
!g_module_symbol (module, "print_data_delete", (gpointer *) &store.print_data_delete) ||
|
|
Packit |
f7449a |
!g_module_symbol (module, "discover_prints", (gpointer *) &store.discover_prints)) {
|
|
Packit |
f7449a |
g_module_close (module);
|
|
Packit |
f7449a |
return FALSE;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_module_make_resident (module);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
return TRUE;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static gboolean
|
|
Packit |
f7449a |
load_conf (void)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GKeyFile *file;
|
|
Packit |
f7449a |
char *filename;
|
|
Packit |
f7449a |
char *module_name;
|
|
Packit |
f7449a |
GError *error = NULL;
|
|
Packit |
f7449a |
gboolean ret;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
filename = g_build_filename (SYSCONFDIR, "fprintd.conf", NULL);
|
|
Packit |
f7449a |
file = g_key_file_new ();
|
|
Packit |
f7449a |
g_debug("About to load configuration file '%s'", filename);
|
|
Packit |
f7449a |
if (!g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error)) {
|
|
Packit |
f7449a |
g_warning ("Could not open \"%s\": %s\n", filename, error->message);
|
|
Packit |
f7449a |
goto bail;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_free (filename);
|
|
Packit |
f7449a |
filename = NULL;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
module_name = g_key_file_get_string (file, "storage", "type", &error);
|
|
Packit |
f7449a |
if (module_name == NULL)
|
|
Packit |
f7449a |
goto bail;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_key_file_free (file);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (g_str_equal (module_name, "file")) {
|
|
Packit |
f7449a |
g_free (module_name);
|
|
Packit |
f7449a |
set_storage_file ();
|
|
Packit |
f7449a |
return TRUE;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
ret = load_storage_module (module_name);
|
|
Packit |
f7449a |
g_free (module_name);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
return ret;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
bail:
|
|
Packit |
f7449a |
g_key_file_free (file);
|
|
Packit |
f7449a |
g_free (filename);
|
|
Packit |
f7449a |
g_error_free (error);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
return FALSE;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
static const GOptionEntry entries[] = {
|
|
Packit |
f7449a |
{"g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL},
|
|
Packit |
f7449a |
{"no-timeout", 't', 0, G_OPTION_ARG_NONE, &no_timeout, "Do not exit after unused for a while", NULL},
|
|
Packit |
f7449a |
{ NULL }
|
|
Packit |
f7449a |
};
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
int main(int argc, char **argv)
|
|
Packit |
f7449a |
{
|
|
Packit |
f7449a |
GOptionContext *context;
|
|
Packit |
f7449a |
GMainLoop *loop;
|
|
Packit |
f7449a |
GError *error = NULL;
|
|
Packit |
f7449a |
FprintManager *manager;
|
|
Packit |
f7449a |
DBusGProxy *driver_proxy;
|
|
Packit |
f7449a |
guint32 request_name_ret;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
|
Packit |
f7449a |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
Packit |
f7449a |
textdomain (GETTEXT_PACKAGE);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
context = g_option_context_new ("Fingerprint handler daemon");
|
|
Packit |
f7449a |
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
#if !GLIB_CHECK_VERSION (2, 36, 0)
|
|
Packit |
f7449a |
g_type_init();
|
|
Packit |
f7449a |
#endif
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
|
|
Packit |
f7449a |
g_warning ("couldn't parse command-line options: %s\n", error->message);
|
|
Packit |
f7449a |
g_error_free (error);
|
|
Packit |
f7449a |
return 1;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (g_fatal_warnings) {
|
|
Packit |
f7449a |
GLogLevelFlags fatal_mask;
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
Packit |
f7449a |
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
Packit |
f7449a |
g_log_set_always_fatal (fatal_mask);
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
/* Obtain a connection to the session bus */
|
|
Packit |
f7449a |
fprintd_dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
|
|
Packit |
f7449a |
if (fprintd_dbus_conn == NULL) {
|
|
Packit |
f7449a |
g_warning("Failed to open connection to bus: %s", error->message);
|
|
Packit |
f7449a |
return 1;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
driver_proxy = dbus_g_proxy_new_for_name(fprintd_dbus_conn,
|
|
Packit |
f7449a |
DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
/* Load the configuration file,
|
|
Packit |
f7449a |
* and the default storage plugin */
|
|
Packit |
f7449a |
if (!load_conf())
|
|
Packit |
f7449a |
set_storage_file ();
|
|
Packit |
f7449a |
store.init ();
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
loop = g_main_loop_new(NULL, FALSE);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_debug("Launching FprintObject");
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
/* create the one instance of the Manager object to be shared between
|
|
Packit |
f7449a |
* all fprintd users */
|
|
Packit |
f7449a |
manager = fprint_manager_new(no_timeout);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
/* Obtain the well-known name after the manager has been initialized.
|
|
Packit |
f7449a |
* Otherwise a client immediately enumerating the devices will not see
|
|
Packit |
f7449a |
* any. */
|
|
Packit |
f7449a |
if (!org_freedesktop_DBus_request_name(driver_proxy, FPRINT_SERVICE_NAME,
|
|
Packit |
f7449a |
0, &request_name_ret, &error)) {
|
|
Packit |
f7449a |
g_warning("Failed to get name: %s", error->message);
|
|
Packit |
f7449a |
g_object_unref (manager);
|
|
Packit |
f7449a |
return 1;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
|
|
Packit |
f7449a |
g_warning ("Got result code %u from requesting name", request_name_ret);
|
|
Packit |
f7449a |
g_object_unref (manager);
|
|
Packit |
f7449a |
return 1;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_debug("D-Bus service launched with name: %s", FPRINT_SERVICE_NAME);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_debug("entering main loop");
|
|
Packit |
f7449a |
g_main_loop_run(loop);
|
|
Packit |
f7449a |
g_debug("main loop completed");
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
g_object_unref (manager);
|
|
Packit |
f7449a |
|
|
Packit |
f7449a |
return 0;
|
|
Packit |
f7449a |
}
|
|
Packit |
f7449a |
|