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.

98 lines
2.7 KiB

8 years ago
17 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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 <udisks/udisks.h>
  21. #include "conf.h"
  22. #include "log.h"
  23. #include "pad.h"
  24. #include "device.h"
  25. static int pusb_device_connected(t_pusb_options *opts, UDisksClient *udisks)
  26. {
  27. GDBusObjectManager *manager = udisks_client_get_object_manager(udisks);
  28. GList *objects = g_dbus_object_manager_get_objects(manager);
  29. int retval = 0;
  30. int i;
  31. UDisksObject *object = NULL;
  32. UDisksDrive *drive = NULL;
  33. manager = udisks_client_get_object_manager(udisks);
  34. objects = g_dbus_object_manager_get_objects(manager);
  35. log_debug("Searching for \"%s\" in the hardware database...\n",
  36. opts->device.name);
  37. for (i = 0; i < g_list_length(objects); ++i)
  38. {
  39. object = UDISKS_OBJECT(g_list_nth(objects, i)->data);
  40. if (udisks_object_peek_drive(object))
  41. {
  42. drive = udisks_object_get_drive(object);
  43. retval = strcmp(udisks_drive_get_serial(drive), opts->device.serial) == 0 &&
  44. strcmp(udisks_drive_get_vendor(drive), opts->device.vendor) == 0 &&
  45. strcmp(udisks_drive_get_model(drive), opts->device.model) == 0;
  46. g_object_unref(drive);
  47. if (retval)
  48. break;
  49. }
  50. }
  51. if (retval)
  52. log_info("Authentication device \"%s\" is connected.\n",
  53. opts->device.name);
  54. else
  55. log_error("Authentication device \"%s\" is not connected.\n",
  56. opts->device.name);
  57. g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  58. g_list_free (objects);
  59. return (retval);
  60. }
  61. int pusb_device_check(t_pusb_options *opts, const char *user)
  62. {
  63. UDisksClient *udisks = NULL;
  64. int retval = 0;
  65. udisks = udisks_client_new_sync(NULL, NULL);
  66. if (!pusb_device_connected(opts, udisks))
  67. {
  68. g_object_unref(udisks);
  69. return (0);
  70. }
  71. if (opts->one_time_pad)
  72. {
  73. log_info("Performing one time pad verification...\n");
  74. retval = pusb_pad_check(opts, udisks, user);
  75. }
  76. else
  77. {
  78. log_debug("One time pad is disabled, no more verifications to do.\n");
  79. retval = 1;
  80. }
  81. g_object_unref(udisks);
  82. return (retval);
  83. }