2 * Copyright (c) 2003-2007 Andrea Luzzardi <scox@sig11.org>
4 * This file is part of the pam_usb project. pam_usb is free software;
5 * you can redistribute it and/or modify it under the terms of the GNU General
6 * Public License version 2, as published by the Free Software Foundation.
8 * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <dbus/dbus.h>
21 #include <libhal-storage.h>
28 static int pusb_device_connected(t_pusb_options
*opts
, LibHalContext
*ctx
)
32 log_debug("Searching for \"%s\" in the hardware database...\n",
34 udi
= pusb_hal_find_item(ctx
,
35 "storage.serial", opts
->device
.serial
,
36 "storage.vendor", opts
->device
.vendor
,
37 "info.product", opts
->device
.model
,
41 /* Backward compatibility with older versions (0.4.1) */
42 udi
= pusb_hal_find_item(ctx
,
43 "usb_device.serial", opts
->device
.serial
,
44 "usb_device.vendor", opts
->device
.vendor
,
45 "info.product", opts
->device
.model
,
49 log_error("Device \"%s\" is not connected.\n",
53 log_error("Warning: The configuration file has been " \
54 "generated by an older version of pamusb-conf\n");
56 libhal_free_string(udi
);
57 log_info("Device \"%s\" is connected (good).\n", opts
->device
.name
);
61 int pusb_device_check(t_pusb_options
*opts
,
64 DBusConnection
*dbus
= NULL
;
65 LibHalContext
*ctx
= NULL
;
68 log_debug("Connecting to HAL...\n");
69 if (!(dbus
= pusb_hal_dbus_connect()))
72 if (!(ctx
= pusb_hal_init(dbus
)))
74 pusb_hal_dbus_disconnect(dbus
);
78 if (!pusb_device_connected(opts
, ctx
))
80 pusb_hal_dbus_disconnect(dbus
);
85 if (opts
->one_time_pad
)
87 log_info("Performing one time pad verification...\n");
88 retval
= pusb_pad_check(opts
, ctx
, user
);
92 log_debug("One time pad is disabled, no more verifications to do.\n");
96 pusb_hal_dbus_disconnect(dbus
);