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 17char pppd_version[] = VERSION; 18 19static char pptpd_original_ip[PATH_MAX+1]; 20static bool pptpd_logwtmp_strip_domain = 0; 21 22static option_t options[] = { 23 { "pptpd-original-ip", o_string, pptpd_original_ip, 24 "Original IP address of the PPTP connection", 25 OPT_STATIC, NULL, PATH_MAX }, 26 { "pptpd-logwtmp-strip-domain", o_bool, &pptpd_logwtmp_strip_domain, 27 "Strip domain from username before logging", OPT_PRIO | 1 }, 28 { NULL } 29}; 30 31static char *reduce(char *user) 32{ 33 char *sep; 34 if (!pptpd_logwtmp_strip_domain) return user; 35 36 sep = strstr(user, "//"); /* two slash */ 37 if (sep != NULL) user = sep + 2; 38 sep = strstr(user, "\\"); /* or one backslash */ 39 if (sep != NULL) user = sep + 1; 40 return user; 41} 42 43static void ip_up(void *opaque, int arg) 44{ 45 char *user = reduce(peer_authname); 46 if (debug) 47 notice("pptpd-logwtmp.so ip-up %s %s %s", ifname, user, 48 pptpd_original_ip); 49 logwtmp(ifname, user, pptpd_original_ip); 50} 51 52static void ip_down(void *opaque, int arg) 53{ 54 if (debug) 55 notice("pptpd-logwtmp.so ip-down %s", ifname); 56 logwtmp(ifname, "", ""); 57} 58 59void plugin_init(void) 60{ 61 add_options(options); 62 add_notifier(&ip_up_notifier, ip_up, NULL); 63 add_notifier(&ip_down_notifier, ip_down, NULL); 64 if (debug) 65 notice("pptpd-logwtmp: $Version$"); 66} 67