Foreach-Variable-X and =~
Does this work for anyone else? I'm running 3.0.x HEAD, and finding that this: if (Cisco-AVPair) { foreach &Cisco-AVPair { if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) { update request { IC-Cisco-ASID := "%{1}" } } } } ...doesn't work; with a packet of: Received Access-Request Id 10 from ... Cisco-AVPair = 'blah=foo' Cisco-AVPair = 'audit-session-id=foo' ...I get: (10) if (Cisco-AVPair) (10) if (Cisco-AVPair) -> TRUE (10) if (Cisco-AVPair) { (10) foreach &Cisco-AVPair (10) update request { (10) EXPAND %{Foreach-Variable-0} (10) --> blah=foo (10) Tmp-String-0 := '"blah=foo"' (10) } # update request = noop (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) -> FALSE (10) update request { (10) EXPAND %{Foreach-Variable-0} (10) --> audit-session-id=foo (10) Tmp-String-0 := '"audit-session-id=foo"' (10) } # update request = noop (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) -> FALSE (10) } # foreach &Cisco-AVPair = noop (10) } # if (Cisco-AVPair) = noop ...but it works if I copy Foreach-Variable-0 to Tmp-String-0 and do the regexp against that. Before I dig any deeper, just wanted to see if it actually works for anyone?
It works for me with a 3.0.2 FRD. I have a few differences in syntax, I'm not sure if it's important... Here is what I have: foreach Cisco-AVPair { if ("%{Foreach-Variable-0}" =~ /^circuit-id-tag=(.+)/ ) { update control { SRS-Cisco-Circuit-Id = "%{1}" }
-----Message d'origine----- De : freeradius-users- bounces+nicolas.chaigneau=capgemini.com@lists.freeradius.org [mailto:freeradius-users- bounces+nicolas.chaigneau=capgemini.com@lists.freeradius.org] De la part de Phil Mayers Envoyé : vendredi 16 mai 2014 15:59 À : FreeRadius users mailing list Objet : Foreach-Variable-X and =~
Does this work for anyone else? I'm running 3.0.x HEAD, and finding that this:
if (Cisco-AVPair) { foreach &Cisco-AVPair { if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) { update request { IC-Cisco-ASID := "%{1}" } } } }
...doesn't work; with a packet of:
Received Access-Request Id 10 from ... Cisco-AVPair = 'blah=foo' Cisco-AVPair = 'audit-session-id=foo'
...I get:
(10) if (Cisco-AVPair) (10) if (Cisco-AVPair) -> TRUE (10) if (Cisco-AVPair) { (10) foreach &Cisco-AVPair (10) update request { (10) EXPAND %{Foreach-Variable-0} (10) --> blah=foo (10) Tmp-String-0 := '"blah=foo"' (10) } # update request = noop (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) -> FALSE (10) update request { (10) EXPAND %{Foreach-Variable-0} (10) --> audit-session-id=foo (10) Tmp-String-0 := '"audit-session-id=foo"' (10) } # update request = noop (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) (10) if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) -> FALSE (10) } # foreach &Cisco-AVPair = noop (10) } # if (Cisco-AVPair) = noop
...but it works if I copy Foreach-Variable-0 to Tmp-String-0 and do the regexp against that.
Before I dig any deeper, just wanted to see if it actually works for anyone? - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
On 16/05/14 15:11, Chaigneau, Nicolas wrote:
It works for me with a 3.0.2 FRD. I have a few differences in syntax, I'm not sure if it's important... Here is what I have:
foreach Cisco-AVPair { if ("%{Foreach-Variable-0}" =~ /^circuit-id-tag=(.+)/ ) { update control { SRS-Cisco-Circuit-Id = "%{1}" }
Yeah I think it's need to be string-ified. Looking at the source code, Foreach-Variable-X aren't real attributes, they're only xlats. Shame, as it throws away type info unless you push it into an intermediate attribute of the same type.
Phil Mayers wrote:
Does this work for anyone else? I'm running 3.0.x HEAD, and finding that this:
if (Cisco-AVPair) { foreach &Cisco-AVPair { if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) {
Foreach-Variable-N is magic. :( Use this instead: "%{Foreach-Variable-0}" Or, "git pull". I've put a check in for this. It's ~10 lines of code, and means people won't get surprised and annoyed. Alan DeKok.
On 16 May 2014, at 14:58, Phil Mayers <p.mayers@IMPERIAL.AC.UK> wrote:
Does this work for anyone else? I'm running 3.0.x HEAD, and finding that this:
if (Cisco-AVPair) { foreach &Cisco-AVPair { if (Foreach-Variable-0 =~ /^audit-session-id=(.+)$/) {
Foreach-Variable-0 isn't an actual attribute. Needs to be access as %{Foreach-Variable-0} still. Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
participants (4)
-
Alan DeKok -
Arran Cudbard-Bell -
Chaigneau, Nicolas -
Phil Mayers