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.

88 lines
2.3 KiB

18 years ago
18 years ago
18 years ago
18 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., 59 Temple
  15. * Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <dbus/dbus.h>
  20. #include <libhal-storage.h>
  21. #include "conf.h"
  22. #include "hal.h"
  23. #include "log.h"
  24. #include "pad.h"
  25. #include "device.h"
  26. static int pusb_device_connected(t_pusb_options *opts, LibHalContext *ctx)
  27. {
  28. char *udi = NULL;
  29. log_debug("Searching for \"%s\" in the hardware database...\n",
  30. opts->device.name);
  31. udi = pusb_hal_find_item(ctx,
  32. "usb_device.serial", opts->device.serial,
  33. "usb_device.vendor", opts->device.vendor,
  34. "info.product", opts->device.model,
  35. NULL);
  36. if (!udi)
  37. {
  38. log_error("Device \"%s\" is not connected.\n",
  39. opts->device.name);
  40. return (0);
  41. }
  42. libhal_free_string(udi);
  43. log_info("Device \"%s\" is connected (good).\n", opts->device.name);
  44. return (1);
  45. }
  46. int pusb_device_check(t_pusb_options *opts,
  47. const char *user)
  48. {
  49. DBusConnection *dbus = NULL;
  50. LibHalContext *ctx = NULL;
  51. int retval = 0;
  52. log_debug("Connecting to HAL...\n");
  53. if (!(dbus = pusb_hal_dbus_connect()))
  54. return (0);
  55. if (!(ctx = pusb_hal_init(dbus)))
  56. {
  57. pusb_hal_dbus_disconnect(dbus);
  58. return (0);
  59. }
  60. if (!pusb_device_connected(opts, ctx))
  61. {
  62. pusb_hal_dbus_disconnect(dbus);
  63. libhal_ctx_free(ctx);
  64. return (0);
  65. }
  66. if (opts->one_time_pad)
  67. {
  68. log_info("Performing one time pad verification...\n");
  69. retval = pusb_pad_check(opts, ctx, user);
  70. }
  71. else
  72. {
  73. log_debug("One time pad is disabled, no more verifications to do.\n");
  74. retval = 1;
  75. }
  76. pusb_hal_dbus_disconnect(dbus);
  77. libhal_ctx_free(ctx);
  78. return (retval);
  79. }