1/*********************************************************************** 2* 3* radattr.c 4* 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. 9* 10* Copyright (C) 2002 Roaring Penguin Software Inc. 11* 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. 14* 15***********************************************************************/ 16 17static char const RCSID[] = 18"$Id: radattr.c,v 1.1.1.1 2008/10/15 03:30:47 james26_jang Exp $"; 19 20#include "pppd.h" 21#include "radiusclient.h" 22#include <stdio.h> 23 24extern void (*radius_attributes_hook)(VALUE_PAIR *); 25static void print_attributes(VALUE_PAIR *); 26static void cleanup(void *opaque, int arg); 27 28char pppd_version[] = VERSION; 29 30/********************************************************************** 31* %FUNCTION: plugin_init 32* %ARGUMENTS: 33* None 34* %RETURNS: 35* Nothing 36* %DESCRIPTION: 37* Initializes radattr plugin. 38***********************************************************************/ 39void 40plugin_init(void) 41{ 42 radius_attributes_hook = print_attributes; 43 44 add_notifier(&link_down_notifier, cleanup, NULL); 45 46 /* Just in case... */ 47 add_notifier(&exitnotify, cleanup, NULL); 48 info("RADATTR plugin initialized."); 49} 50 51/********************************************************************** 52* %FUNCTION: print_attributes 53* %ARGUMENTS: 54* vp -- linked-list of RADIUS attribute-value pairs 55* %RETURNS: 56* Nothing 57* %DESCRIPTION: 58* Prints the attribute pairs to /var/run/radattr.pppN. Each line of the 59* file contains "name value" pairs. 60***********************************************************************/ 61static void 62print_attributes(VALUE_PAIR *vp) 63{ 64 FILE *fp; 65 char fname[512]; 66 char name[2048]; 67 char value[2048]; 68 69 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname); 70 fp = fopen(fname, "w"); 71 if (!fp) { 72 warn("radattr plugin: Could not open %s for writing: %m", fname); 73 return; 74 } 75 76 for (; vp; vp=vp->next) { 77 if (rc_avpair_tostr(vp, name, sizeof(name), value, sizeof(value)) < 0) { 78 continue; 79 } 80 fprintf(fp, "%s %s\n", name, value); 81 } 82 fclose(fp); 83} 84 85/********************************************************************** 86* %FUNCTION: cleanup 87* %ARGUMENTS: 88* opaque -- not used 89* arg -- not used 90* %RETURNS: 91* Nothing 92* %DESCRIPTION: 93* Deletes /var/run/radattr.pppN 94***********************************************************************/ 95static void 96cleanup(void *opaque, int arg) 97{ 98 char fname[512]; 99 100 slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname); 101 (void) remove(fname); 102} 103