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.

67 lines
1.8 KiB

  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 <stdio.h>
  18. #include <string.h>
  19. #include <unistd.h>
  20. #include <utmp.h>
  21. #include "log.h"
  22. #include "conf.h"
  23. int pusb_local_login(t_pusb_options *opts, const char *user)
  24. {
  25. struct utmp utsearch;
  26. struct utmp *utent;
  27. const char *from;
  28. int i;
  29. if (!opts->deny_remote)
  30. {
  31. log_debug("deny_remote is disabled. Skipping local check.\n");
  32. return (1);
  33. }
  34. log_debug("Checking whether the caller is local or not...\n");
  35. from = ttyname(STDIN_FILENO);
  36. if (!from || !(*from))
  37. {
  38. log_debug("Couldn't retrieve the tty name, aborting.\n");
  39. return (1);
  40. }
  41. if (!strncmp(from, "/dev/", strlen("/dev/")))
  42. from += strlen("/dev/");
  43. log_debug("Authentication request from tty %s\n", from);
  44. strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line) - 1);
  45. setutent();
  46. utent = getutline(&utsearch);
  47. endutent();
  48. if (!utent)
  49. {
  50. log_debug("No utmp entry found for tty \"%s\"\n",
  51. from);
  52. return (1);
  53. }
  54. for (i = 0; i < 4; ++i)
  55. {
  56. if (utent->ut_addr_v6[i] != 0)
  57. {
  58. log_error("Remote authentication request: %s\n", utent->ut_host);
  59. return (0);
  60. }
  61. }
  62. log_debug("Caller is local (good)\n");
  63. return (1);
  64. }