1 ######################################################################
2 # Copyright (c) 2011, Network RADIUS SARL
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of the <organization> nor the
13 # names of its contributors may be used to endorse or promote products
14 # derived from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ######################################################################
30 our $begin_vendor = 0;
32 $vendorpec{'0'} = "IETF";
43 open $fh, "<$filename" or die "Failed to open $filename: $!\n";
57 if (/^VENDOR\s+([\w-]+)\s+(\w+)(.*)/) {
60 $vendor{$me}{'pec'} = $2;
63 $vendor{$me}{'type'} = 1;
64 $vendor{$me}{'length'} = 1;
70 if ($format !~ /^format=(\d+),(\d+)$/) {
71 die "Unknown format $format\n";
73 $vendor{$me}{'type'} = $1;
74 $vendor{$me}{'length'} = $2;
80 # Remember if we did begin-vendor.
82 if (/^BEGIN-VENDOR\s+([\w-]+)/) {
83 if (!defined $vendor{$1}) {
84 die "Unknown vendor $1\n";
86 $begin_vendor = $vendor{$1}{'pec'};
91 # Remember if we did this.
101 if (/^ATTRIBUTE\s+([\w-\/.]+)\s+(\w+)\s+(\w+)(.*)/) {
107 $value =~ tr/[A-F]/[a-f]/; # normal form for hex
110 if ($value =~ /^0x/) {
116 next if (($begin_vendor == 0) && ($index > 255));
118 $index += ($begin_vendor << 16);
120 $attributes{$index}{'name'} = $name;
121 $attributes{$index}{'value'} = $value;
122 if ($begin_vendor ne "") {
123 $attributes{$index}{'vendor'} = $begin_vendor;
126 $type =~ tr/a-z/A-Z/;
127 $attributes{$index}{'type'} = "RS_TYPE_$type";
132 foreach $text (split /,/, $stuff) {
133 if ($text eq "encrypt=1") {
134 $attributes{$index}{'flags'}{'encrypt'} = "FLAG_ENCRYPT_USER_PASSWORD";
135 } elsif ($text eq "encrypt=2") {
136 $attributes{$index}{'flags'}{'encrypt'} = "FLAG_ENCRYPT_TUNNEL_PASSWORD";
138 } elsif ($text eq "encrypt=3") {
139 $attributes{$index}{'flags'}{'encrypt'} = "FLAG_ENCRYPT_ASCEND_SECRET";
141 } elsif ($text eq "has_tag") {
142 $attributes{$index}{'flags'}{'has_tag'} = "1";
144 } elsif ($text =~ /\[(\d+)\]/) {
145 $attributes{$index}{'flags'}{'length'} = $1;
148 die "$filename: $lineno - Unknown flag $text\n";
153 if ($type eq "BYTE") {
154 $attributes{$index}{'flags'}{'length'} = "1";
156 } elsif ($type eq "SHORT") {
157 $attributes{$index}{'flags'}{'length'} = "2";
159 } elsif ($type eq "INTEGER") {
160 $attributes{$index}{'flags'}{'length'} = "4";
162 } elsif ($type eq "IPADDR") {
163 $attributes{$index}{'flags'}{'length'} = "4";
165 } elsif ($type eq "DATE") {
166 $attributes{$index}{'flags'}{'length'} = "4";
168 } elsif ($type eq "IFID") {
169 $attributes{$index}{'flags'}{'length'} = "8";
171 } elsif ($type eq "IPV6ADDR") {
173 $attributes{$index}{'flags'}{'length'} = "16";
176 $name2val{$name} = $index;
183 if (/^VALUE\s+([\d\w-\/.]+)\s+([\w-\/,.+]+)\s+(\w+)(.*)/) {
191 $value =~ tr/[A-F]/[a-f]/; # normal form for hex
194 if ($value =~ /^0x/) {
200 if (!defined $name2val{$attr}) {
201 print "# FIXME: FORWARD REF?\nVALUE $attr $name $value$stuff\n";
205 $values{$name2val{$attr}}{$index} = "$attr $name $value$stuff";
209 if (/^\$INCLUDE\s+(.*)$/) {
214 die "unknown text in line $lineno of $filename: $_\n";