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 $";
25 #include "radiusclient.h"
27 #include <sys/types.h>
30 extern void (*radius_attributes_hook)(VALUE_PAIR *);
31 static void print_attributes(VALUE_PAIR *);
32 static void cleanup(void *opaque, int arg);
34 char pppd_version[] = VERSION;
36 /**********************************************************************
37 * %FUNCTION: plugin_init
43 * Initializes radattr plugin.
44 ***********************************************************************/
48 radius_attributes_hook = print_attributes;
51 /* calling cleanup() on link down is problematic because print_attributes()
52 is called only after PAP or CHAP authentication, but not when the link
53 should go up again for any other reason */
54 add_notifier(&link_down_notifier, cleanup, NULL);
58 add_notifier(&exitnotify, cleanup, NULL);
59 info("RADATTR plugin initialized.");
62 /**********************************************************************
63 * %FUNCTION: print_attributes
65 * vp -- linked-list of RADIUS attribute-value pairs
69 * Prints the attribute pairs to /var/run/radattr.pppN. Each line of the
70 * file contains "name value" pairs.
71 ***********************************************************************/
73 print_attributes(VALUE_PAIR *vp)
82 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
83 old_umask = umask(077);
84 fp = fopen(fname, "w");
87 warn("radattr plugin: Could not open %s for writing: %m", fname);
91 for (; vp; vp=vp->next) {
92 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) {
95 fprintf(fp, "%s %s\n", name, value);
99 dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname);
102 /**********************************************************************
110 * Deletes /var/run/radattr.pppN
111 ***********************************************************************/
113 cleanup(void *opaque, int arg)
117 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
118 (void) remove(fname);
119 dbglog("RADATTR plugin removed file %s.", fname);