]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/radius/radattr.c
plugins/radius: fix segfault during shutdown. (#455)
[ppp.git] / pppd / plugins / radius / radattr.c
index 77fc61dbd6d64fe75bd46cdc26dfdc67b98dfa0a..802cb66c370abb5d43e48c298e65db072a867d51 100644 (file)
 ***********************************************************************/
 
 static char const RCSID[] =
-"$Id: radattr.c,v 1.1 2002/01/22 16:03:00 dfs Exp $";
+"$Id: radattr.c,v 1.2 2004/10/28 00:24:40 paulus Exp $";
 
-#include "pppd.h"
-#include "radiusclient.h"
 #include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <pppd/pppd.h>
+
+#include "radiusclient.h"
 
 extern void (*radius_attributes_hook)(VALUE_PAIR *);
 static void print_attributes(VALUE_PAIR *);
 static void cleanup(void *opaque, int arg);
 
-char pppd_version[] = VERSION;
+char pppd_version[] = PPPD_VERSION;
 
 /**********************************************************************
 * %FUNCTION: plugin_init
@@ -41,10 +47,15 @@ plugin_init(void)
 {
     radius_attributes_hook = print_attributes;
 
-    add_notifier(&link_down_notifier, cleanup, NULL);
+#if 0
+    /* calling cleanup() on link down is problematic because print_attributes()
+       is called only after PAP or CHAP authentication, but not when the link
+       should go up again for any other reason */
+    ppp_add_notify(NF_LINK_DOWN, cleanup, NULL);
+#endif
 
     /* Just in case... */
-    add_notifier(&exitnotify, cleanup, NULL);
+    ppp_add_notify(NF_EXIT, cleanup, NULL);
     info("RADATTR plugin initialized.");
 }
 
@@ -65,9 +76,13 @@ print_attributes(VALUE_PAIR *vp)
     char fname[512];
     char name[2048];
     char value[2048];
+    int cnt = 0;
+    mode_t old_umask;
 
-    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
+    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
+    old_umask = umask(077);
     fp = fopen(fname, "w");
+    umask(old_umask);
     if (!fp) {
        warn("radattr plugin: Could not open %s for writing: %m", fname);
        return;
@@ -78,8 +93,10 @@ print_attributes(VALUE_PAIR *vp)
            continue;
        }
        fprintf(fp, "%s %s\n", name, value);
+       cnt++;
     }
     fclose(fp);
+    dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname);
 }
 
 /**********************************************************************
@@ -97,6 +114,7 @@ cleanup(void *opaque, int arg)
 {
     char fname[512];
 
-    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
+    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
     (void) remove(fname);
+    dbglog("RADATTR plugin removed file %s.", fname);
 }