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.1 2002/01/22 16:03:00 dfs 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;
44 add_notifier(&link_down_notifier, cleanup, NULL);
47 add_notifier(&exitnotify, cleanup, NULL);
48 info("RADATTR plugin initialized.");
51 /**********************************************************************
52 * %FUNCTION: print_attributes
54 * vp -- linked-list of RADIUS attribute-value pairs
58 * Prints the attribute pairs to /var/run/radattr.pppN. Each line of the
59 * file contains "name value" pairs.
60 ***********************************************************************/
62 print_attributes(VALUE_PAIR *vp)
69 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
70 fp = fopen(fname, "w");
72 warn("radattr plugin: Could not open %s for writing: %m", fname);
76 for (; vp; vp=vp->next) {
77 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) {
80 fprintf(fp, "%s %s\n", name, value);
85 /**********************************************************************
93 * Deletes /var/run/radattr.pppN
94 ***********************************************************************/
96 cleanup(void *opaque, int arg)
100 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
101 (void) remove(fname);