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 ***********************************************************************/
19 #include <sys/types.h>
23 #include <pppd/pppd.h>
25 #include "radiusclient.h"
27 extern void (*radius_attributes_hook)(VALUE_PAIR *);
28 static void print_attributes(VALUE_PAIR *);
29 static void cleanup(void *opaque, int arg);
31 char pppd_version[] = PPPD_VERSION;
33 /**********************************************************************
34 * %FUNCTION: plugin_init
40 * Initializes radattr plugin.
41 ***********************************************************************/
45 radius_attributes_hook = print_attributes;
48 /* calling cleanup() on link down is problematic because print_attributes()
49 is called only after PAP or CHAP authentication, but not when the link
50 should go up again for any other reason */
51 ppp_add_notify(NF_LINK_DOWN, cleanup, NULL);
55 ppp_add_notify(NF_EXIT, cleanup, NULL);
56 info("RADATTR plugin initialized.");
59 /**********************************************************************
60 * %FUNCTION: print_attributes
62 * vp -- linked-list of RADIUS attribute-value pairs
66 * Prints the attribute pairs to /var/run/radattr.pppN. Each line of the
67 * file contains "name value" pairs.
68 ***********************************************************************/
70 print_attributes(VALUE_PAIR *vp)
79 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
80 old_umask = umask(077);
81 fp = fopen(fname, "w");
84 warn("radattr plugin: Could not open %s for writing: %m", fname);
88 for (; vp; vp=vp->next) {
89 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) {
92 fprintf(fp, "%s %s\n", name, value);
96 dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname);
99 /**********************************************************************
107 * Deletes /var/run/radattr.pppN
108 ***********************************************************************/
110 cleanup(void *opaque, int arg)
114 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
115 (void) remove(fname);
116 dbglog("RADATTR plugin removed file %s.", fname);