Hardware authentication for Linux using ordinary USB Flash Drives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.0 KiB

13 years ago
17 years ago
17 years ago
13 years ago
  1. /*
  2. * Copyright (c) 2003-2007 Andrea Luzzardi <scox@sig11.org>
  3. *
  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.
  7. *
  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
  11. * details.
  12. *
  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., 51 Franklin
  15. * Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #include <unistd.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <dbus/dbus.h>
  21. #include "mem.h"
  22. #include "conf.h"
  23. #include "hal.h"
  24. #include "log.h"
  25. #include "pad.h"
  26. #include "device.h"
  27. static int pusb_device_connected(t_pusb_options *opts, DBusConnection *dbus)
  28. {
  29. char *udi = NULL;
  30. log_debug("Searching for \"%s\" in the hardware database...\n",
  31. opts->device.name);
  32. udi = pusb_hal_find_item(dbus,
  33. "DriveSerial", opts->device.serial,
  34. "DriveVendor", opts->device.vendor,
  35. "DriveModel", opts->device.model,
  36. NULL);
  37. if (!udi)
  38. {
  39. log_error("Device \"%s\" is not connected.\n",
  40. opts->device.name);
  41. return (0);
  42. }
  43. xfree(udi);
  44. log_info("Device \"%s\" is connected (good).\n", opts->device.name);
  45. return (1);
  46. }
  47. int pusb_device_check(t_pusb_options *opts,
  48. const char *user)
  49. {
  50. DBusConnection *dbus = NULL;
  51. int retval = 0;
  52. log_debug("Connecting to HAL...\n");
  53. if (!(dbus = pusb_hal_dbus_connect()))
  54. return (0);
  55. if (!pusb_device_connected(opts, dbus))
  56. {
  57. pusb_hal_dbus_disconnect(dbus);
  58. return (0);
  59. }
  60. if (opts->one_time_pad)
  61. {
  62. log_info("Performing one time pad verification...\n");
  63. retval = pusb_pad_check(opts, dbus, user);
  64. }
  65. else
  66. {
  67. log_debug("One time pad is disabled, no more verifications to do.\n");
  68. retval = 1;
  69. }
  70. pusb_hal_dbus_disconnect(dbus);
  71. return (retval);
  72. }