Lines 22-32
static char const RCSID[] =
Link Here
|
22 |
#include <stdio.h> |
22 |
#include <stdio.h> |
23 |
extern void (*radius_attributes_hook)(VALUE_PAIR *); |
23 |
extern void (*radius_attributes_hook)(VALUE_PAIR *); |
|
|
24 |
void (*radattr_attributes_oldhook)(VALUE_PAIR *) = NULL; |
25 |
void (*radattr_ip_choose_oldhook) __P((u_int32_t *)) = NULL; |
24 |
static void print_attributes(VALUE_PAIR *); |
26 |
static void print_attributes(VALUE_PAIR *); |
25 |
static void cleanup(void *opaque, int arg); |
27 |
static void cleanup(void *opaque, int arg); |
26 |
char pppd_version[] = VERSION; |
28 |
char pppd_version[] = VERSION; |
|
|
29 |
char fname[512]; |
30 |
VALUE_PAIR *saved_vp=NULL; |
31 |
static radattr_ip_choose_hooked=0; |
32 |
|
27 |
/********************************************************************** |
33 |
/********************************************************************** |
28 |
* %FUNCTION: plugin_init |
34 |
* %FUNCTION: plugin_init |
29 |
* %ARGUMENTS: |
35 |
* %ARGUMENTS: |
Lines 39-46
char pppd_version[] = VERSION;
Link Here
|
39 |
void |
45 |
void |
40 |
plugin_init(void) |
46 |
plugin_init(void) |
41 |
{ |
47 |
{ |
|
|
48 |
radattr_attributes_oldhook = radius_attributes_hook; |
42 |
radius_attributes_hook = print_attributes; |
49 |
radius_attributes_hook = print_attributes; |
|
|
50 |
fname[0]='\0'; |
51 |
|
43 |
#if 0 |
52 |
#if 0 |
44 |
/* calling cleanup() on link down is problematic because print_attributes() |
53 |
/* calling cleanup() on link down is problematic because print_attributes() |
45 |
is called only after PAP or CHAP authentication, but not when the link |
54 |
is called only after PAP or CHAP authentication, but not when the link |
Lines 63-73
plugin_init(void)
Link Here
|
63 |
* Prints the attribute pairs to /var/run/radattr.pppN. Each line of the |
72 |
* Prints the attribute pairs to /var/run/radattr.pppN. Each line of the |
64 |
* file contains "name value" pairs. |
73 |
* file contains "name value" pairs. |
65 |
***********************************************************************/ |
74 |
***********************************************************************/ |
66 |
static void |
75 |
void print_attributes_to_file(VALUE_PAIR *vp) { |
67 |
print_attributes(VALUE_PAIR *vp) |
|
|
68 |
{ |
69 |
FILE *fp; |
76 |
FILE *fp; |
70 |
char fname[512]; |
|
|
71 |
char name[2048]; |
77 |
char name[2048]; |
72 |
char value[2048]; |
78 |
char value[2048]; |
73 |
int cnt = 0; |
79 |
int cnt = 0; |
Lines 90-95
print_attributes(VALUE_PAIR *vp)
Link Here
|
90 |
dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname); |
96 |
dbglog("RADATTR plugin wrote %d line(s) to file %s.", cnt, fname); |
91 |
} |
97 |
} |
|
|
98 |
|
99 |
static void radattr_ip_choose_hook(u_int32_t *addrp) { |
100 |
if (saved_vp && ifname[0]) { |
101 |
/* If multilink is enabled this is first available |
102 |
hook after setting ifname. |
103 |
Thankfully IPCP is first network protocol to be started |
104 |
and this hook will get called before any other |
105 |
protocols are started. |
106 |
We're assuming IP is always enabled if multilink is! */ |
107 |
|
108 |
print_attributes_to_file(saved_vp); |
109 |
rc_avpair_free(saved_vp); |
110 |
saved_vp=NULL; |
111 |
} |
112 |
if (radattr_ip_choose_oldhook) { |
113 |
radattr_ip_choose_oldhook(addrp); |
114 |
} |
115 |
} |
116 |
|
117 |
static void |
118 |
print_attributes(VALUE_PAIR *vp) |
119 |
{ |
120 |
|
121 |
if (radattr_attributes_oldhook) { |
122 |
radattr_attributes_oldhook(vp); |
123 |
} |
124 |
|
125 |
if (ifname[0]) { |
126 |
print_attributes_to_file(vp); |
127 |
} else { |
128 |
if (saved_vp) |
129 |
rc_avpair_free(saved_vp); |
130 |
saved_vp=rc_avpair_copy(vp); |
131 |
if (saved_vp && ! radattr_ip_choose_hooked) { |
132 |
radattr_ip_choose_oldhook=ip_choose_hook; |
133 |
ip_choose_hook=radattr_ip_choose_hook; |
134 |
radattr_ip_choose_hooked=1; |
135 |
} |
136 |
} |
137 |
} |
138 |
|
92 |
/********************************************************************** |
139 |
/********************************************************************** |
93 |
* %FUNCTION: cleanup |
140 |
* %FUNCTION: cleanup |
94 |
* %ARGUMENTS: |
141 |
* %ARGUMENTS: |
Lines 103-111
print_attributes(VALUE_PAIR *vp)
Link Here
|
103 |
static void |
150 |
static void |
104 |
cleanup(void *opaque, int arg) |
151 |
cleanup(void *opaque, int arg) |
105 |
{ |
152 |
{ |
106 |
char fname[512]; |
153 |
if (fname[0]) { |
107 |
|
|
|
108 |
slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname); |
109 |
(void) remove(fname); |
154 |
(void) remove(fname); |
110 |
dbglog("RADATTR plugin removed file %s.", fname); |
155 |
dbglog("RADATTR plugin removed file %s.", fname); |
|
|
156 |
} |
111 |
} |
157 |
} |