1 /***********************************************************************
5 * A plugin which is stacked on top of radius.so. This plugin writes
6 * all RADIUS attributes from the server's authentication confirmation
7 * into /var/run/radattr.pppN. These attributes are available for
8 * consumption by /etc/ppp/ip-{up,down} scripts.
10 * Copyright (C) 2002 Roaring Penguin Software Inc.
12 * This plugin may be distributed according to the terms of the GNU
13 * General Public License, version 2 or (at your option) any later version.
15 ***********************************************************************/
17 static char const RCSID[] =
18 "$Id: radattr.c,v 1.2 2004/10/28 00:24:40 paulus Exp $";
22 #include <pppd/pppd.h>
24 #include "radiusclient.h"
26 extern void (*radius_attributes_hook)(VALUE_PAIR *);
27 static void print_attributes(VALUE_PAIR *);
28 static void cleanup(void *opaque, int arg);
30 char pppd_version[] = PPPD_VERSION;
32 /**********************************************************************
33 * %FUNCTION: plugin_init
39 * Initializes radattr plugin.
40 ***********************************************************************/
44 radius_attributes_hook = print_attributes;
47 /* calling cleanup() on link down is problematic because print_attributes()
48 is called only after PAP or CHAP authentication, but not when the link
49 should go up again for any other reason */
50 add_notifier(&link_down_notifier, cleanup, NULL);
54 add_notifier(&exitnotify, cleanup, NULL);
55 info("RADATTR plugin initialized.");
58 /**********************************************************************
59 * %FUNCTION: print_attributes
61 * vp -- linked-list of RADIUS attribute-value pairs
65 * Prints the attribute pairs to /var/run/radattr.pppN. Each line of the
66 * file contains "name value" pairs.
67 ***********************************************************************/
69 print_attributes(VALUE_PAIR *vp)
78 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
79 old_umask = umask(077);
80 fp = fopen(fname, "w");
83 warn("radattr plugin: Could not open %s for writing: %m", fname);
87 for (; vp; vp=vp->next) {
88 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) {
91 fprintf(fp, "%s %s\n", name, value);
95 dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname);
98 /**********************************************************************
106 * Deletes /var/run/radattr.pppN
107 ***********************************************************************/
109 cleanup(void *opaque, int arg)
113 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
114 (void) remove(fname);
115 dbglog("RADATTR plugin removed file %s.", fname);