1
0

pptpd-logwtmp.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * $Id: pptpd-logwtmp.c,v 1.5 2007/04/16 00:21:02 quozl Exp $
  3. * pptpd-logwtmp.c - pppd plugin to update wtmp for a pptpd user
  4. *
  5. * Copyright 2004 James Cameron.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <unistd.h>
  13. #include <utmp.h>
  14. #include <string.h>
  15. #include "pppd.h"
  16. char pppd_version[] = VERSION;
  17. static char pptpd_original_ip[PATH_MAX+1];
  18. static bool pptpd_logwtmp_strip_domain = 0;
  19. static option_t options[] = {
  20. { "pptpd-original-ip", o_string, pptpd_original_ip,
  21. "Original IP address of the PPTP connection",
  22. OPT_STATIC, NULL, PATH_MAX },
  23. { "pptpd-logwtmp-strip-domain", o_bool, &pptpd_logwtmp_strip_domain,
  24. "Strip domain from username before logging", OPT_PRIO | 1 },
  25. { NULL }
  26. };
  27. static char *reduce(char *user)
  28. {
  29. char *sep;
  30. if (!pptpd_logwtmp_strip_domain) return user;
  31. sep = strstr(user, "//"); /* two slash */
  32. if (sep != NULL) user = sep + 2;
  33. sep = strstr(user, "\\"); /* or one backslash */
  34. if (sep != NULL) user = sep + 1;
  35. return user;
  36. }
  37. static void ip_up(void *opaque, int arg)
  38. {
  39. char *user = reduce(peer_authname);
  40. if (debug)
  41. notice("pptpd-logwtmp.so ip-up %s %s %s", ifname, user,
  42. pptpd_original_ip);
  43. logwtmp(ifname, user, pptpd_original_ip);
  44. }
  45. static void ip_down(void *opaque, int arg)
  46. {
  47. if (debug)
  48. notice("pptpd-logwtmp.so ip-down %s", ifname);
  49. logwtmp(ifname, "", "");
  50. }
  51. void plugin_init(void)
  52. {
  53. add_options(options);
  54. add_notifier(&ip_up_notifier, ip_up, NULL);
  55. add_notifier(&ip_down_notifier, ip_down, NULL);
  56. if (debug)
  57. notice("pptpd-logwtmp: $Version$");
  58. }