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.

96 lines
2.2 KiB

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 <stdio.h>
  18. #include <syslog.h>
  19. #include <stdarg.h>
  20. #include "conf.h"
  21. #include "log.h"
  22. static t_pusb_options *pusb_opts = NULL;
  23. static void pusb_log_syslog(int level, const char *format, va_list ap)
  24. {
  25. openlog("pam_usb", LOG_PID, LOG_AUTH);
  26. vsyslog(level, format, ap);
  27. closelog();
  28. }
  29. static void pusb_log_output(int level, const char *format, va_list ap)
  30. {
  31. if ((pusb_opts && !pusb_opts->quiet) ||
  32. level == LOG_ERR)
  33. {
  34. if (pusb_opts && pusb_opts->color_log)
  35. {
  36. if (level == LOG_ERR)
  37. fprintf(stderr, "\033[01;31m*\033[00m ");
  38. else if (level == LOG_NOTICE)
  39. fprintf(stderr, "\033[01;32m*\033[00m ");
  40. }
  41. else
  42. fprintf(stderr, "* ");
  43. vfprintf(stderr, format, ap);
  44. }
  45. }
  46. void __log_debug(const char *file, int line, const char *fmt, ...)
  47. {
  48. va_list ap;
  49. if (!pusb_opts || !pusb_opts->debug)
  50. return ;
  51. fprintf(stderr, "[%s:%03d] ", file, line);
  52. va_start(ap, fmt);
  53. vfprintf(stderr, fmt, ap);
  54. va_end(ap);
  55. va_start(ap, fmt);
  56. pusb_log_syslog(LOG_DEBUG, fmt, ap);
  57. va_end(ap);
  58. }
  59. void log_error(const char *fmt, ...)
  60. {
  61. va_list ap;
  62. va_start(ap, fmt);
  63. pusb_log_syslog(LOG_ERR, fmt, ap);
  64. va_end(ap);
  65. va_start(ap, fmt);
  66. pusb_log_output(LOG_ERR, fmt, ap);
  67. va_end(ap);
  68. }
  69. void log_info(const char *fmt, ...)
  70. {
  71. va_list ap;
  72. va_start(ap, fmt);
  73. pusb_log_syslog(LOG_NOTICE, fmt, ap);
  74. va_end(ap);
  75. va_start(ap, fmt);
  76. pusb_log_output(LOG_NOTICE, fmt, ap);
  77. va_end(ap);
  78. }
  79. void pusb_log_init(t_pusb_options *opts)
  80. {
  81. pusb_opts = opts;
  82. }