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 $";
21 #include "radiusclient.h"
24 extern void (*radius_attributes_hook)(VALUE_PAIR *);
25 static void print_attributes(VALUE_PAIR *);
26 static void cleanup(void *opaque, int arg);
28 char pppd_version[] = VERSION;
30 /**********************************************************************
31 * %FUNCTION: plugin_init
37 * Initializes radattr plugin.
38 ***********************************************************************/
42 radius_attributes_hook = print_attributes;
45 /* calling cleanup() on link down is problematic because print_attributes()
46 is called only after PAP or CHAP authentication, but not when the link
47 should go up again for any other reason */
48 add_notifier(&link_down_notifier, cleanup, NULL);
52 add_notifier(&exitnotify, cleanup, NULL);
53 info("RADATTR plugin initialized.");
56 /**********************************************************************
57 * %FUNCTION: print_attributes
59 * vp -- linked-list of RADIUS attribute-value pairs
63 * Prints the attribute pairs to /var/run/radattr.pppN. Each line of the
64 * file contains "name value" pairs.
65 ***********************************************************************/
67 print_attributes(VALUE_PAIR *vp)
75 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
76 fp = fopen(fname, "w");
78 warn("radattr plugin: Could not open %s for writing: %m", fname);
82 for (; vp; vp=vp->next) {
83 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) {
86 fprintf(fp, "%s %s\n", name, value);
90 dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname);
93 /**********************************************************************
101 * Deletes /var/run/radattr.pppN
102 ***********************************************************************/
104 cleanup(void *opaque, int arg)
108 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
109 (void) remove(fname);
110 dbglog("RADATTR plugin removed file %s.", fname);