Il 27/03/2017 12:10, Brian Candler ha scritto:
On 27/03/2017 10:37, Andrea Gabellini wrote:
I tried both &Class[*] and the foreach statement. The next problem is the string conversion. What happens:
- &Class[*]: It returns all instances of the attribute separated with a comma. Only the first one is converted to a string.
Only if you write %{Class[*]} or %{&Class[*]}, i.e. you ask Freeradius to convert it into a string.
Don't do that. Try this:
if (&Class[*] =~ /pattern(.*)pattern/) { ... use %{1} to get the capture group }
if (&Class[*] =~ /(.*)/) { update request { &Tmp-String-5 := "Match: %{1}" } } results in: Mon Mar 27 12:40:37 2017 : Debug: (2) EXPAND %{&Class[*]} Mon Mar 27 12:40:37 2017 : Debug: (2) --> 0x54657374436c617373,0x617574685f69643a3066313863343665653637633462323563616131633361303830656233356538 Mon Mar 27 12:40:37 2017 : Debug: (2) &Tmp-String-6 := 0x54657374436c617373,0x617574685f69643a3066313863343665653637633462323563616131633361303830656233356538 ... Mon Mar 27 12:40:37 2017 : Debug: (2) if (&Class[*] =~ /(.*)/) { Mon Mar 27 12:40:37 2017 : Debug: (2) if (&Class[*] =~ /(.*)/) -> TRUE Mon Mar 27 12:40:37 2017 : Debug: (2) if (&Class[*] =~ /(.*)/) { Mon Mar 27 12:40:37 2017 : Debug: (2) update request { Mon Mar 27 12:40:37 2017 : Debug: (2) EXPAND Match: %{1} Mon Mar 27 12:40:37 2017 : Debug: (2) --> Match: 0x54657374436c617373 Mon Mar 27 12:40:37 2017 : Debug: (2) &Tmp-String-5 := Match: 0x54657374436c617373 Mon Mar 27 12:40:37 2017 : Debug: (2) } # update request = noop Mon Mar 27 12:40:37 2017 : Debug: (2) } # if (&Class[*] =~ /(.*)/) = noop Same problem. %{&Class[*]} when used contains only the first instance.
I think this should work if you are on FreeRADIUS 3.x. That is, only the first match should be used. (But I've not tested it myself)
- foreach statement: "%{string:%{Foreach-Variable-0}}" results in an empty string ... (3) Mon Mar 27 11:33:31 2017: Debug: EXPAND Foreach-Variable-0 (3) Mon Mar 27 11:33:31 2017: Debug: --> 0x54657374436c617373 That doesn't look empty to me. 54=T, 65=e, 63=s 74=t etc.
Please look few lines later. The problem is the string conversion of %{Foreach-Variable-0}
The underlying issue is that 'Class' is not a string attribute, so it's hard to treat it as such. I have in the past modified the dictionary so that Class *is* a string. But in general, it could contain binary data, and FreeRADIUS isn't great at handling that if the dictionary says the attribute is a String.
Regards,
Brian.
-- ---------------------------------------------------------------- I'm not a complete idiot, some parts are missing. ---------------------------------------------------------------- Ing. Andrea Gabellini Email: andrea.gabellini@telecomitalia.sm Skype: andreagabellini Tel: (+378) 0549 886111 Fax: (+378) 0549 886188 Telecom Italia San Marino S.p.A. Via XXVIII Luglio, 212 - Piano -2 47893 Borgo Maggiore Republic of San Marino http://www.telecomitalia.sm