acct_unique with more than one Class attribute

Andrea Gabellini andrea.gabellini at telecomitalia.sm
Mon Mar 27 11:37:40 CEST 2017



Il 24/03/2017 10:59, Brian Candler ha scritto:
> On 24/03/2017 09:48, Andrea Gabellini wrote:
>> as a workaround I tried to use &Class[n] instead of &Class. The Class
>> attribute is added in the reply as the last thing in post-auth. So if
>> the NAS doesn't touch the list, probably this works.
>>
>> Is there a better solution?
>
> http://networkradius.com/doc/3.0.10/unlang/foreach.html
>
> It says "The foreach statement loops over a list of attributes", but I
> think it means "The foreach statement loops over all the instances of
> a specified attribute".  Example:
>
> https://lists.freeradius.org/pipermail/freeradius-users/2014-February/070473.html
>
>
> Or, if you can rewrite the whole test as a single regexp, then you try:
>
>     if (&Class[*] =~ /regexp(captures)/) { ... }
>
>

Hi,

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.

- foreach statement:
"%{string:%{Foreach-Variable-0}}" results in an empty string

This is my test configuration snippet:
acct_unique {
...
    update request {
        &Tmp-String-8 := "%{&Class[0]}"
        &Tmp-String-7 := "%{&Class[1]}"
        &Tmp-String-6 := "%{&Class[*]}"
        &Tmp-String-8 := "%{string:&Class[0]}"
        &Tmp-String-7 := "%{string:&Class[1]}"
        &Tmp-String-6 := "%{string:&Class[*]}"
    }
    foreach &Class {
        update request {
            &Tmp-String-6 := "%{Foreach-Variable-0}"
            &Tmp-String-5 := "%{string:%{Foreach-Variable-0}}"
        }
    }
...
}

and this the debug output:
(3) Mon Mar 27 11:33:31 2017: Debug:     policy acct_unique {
(3) Mon Mar 27 11:33:31 2017: Debug:       update request {
(3) Mon Mar 27 11:33:31 2017: Debug:       } # update request = noop
(3) Mon Mar 27 11:33:31 2017: Debug:       update request {
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{&Class[0]}
(3) Mon Mar 27 11:33:31 2017: Debug:            --> 0x54657374436c617373
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{&Class[1]}
(3) Mon Mar 27 11:33:31 2017: Debug:            -->
0x617574685f69643a6532613166366265393632356165613337316436363865326236303433363363
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{&Class[*]}
(3) Mon Mar 27 11:33:31 2017: Debug:            -->
0x54657374436c617373,0x617574685f69643a6532613166366265393632356165613337316436363865326236303433363363
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{string:&Class[0]}
(3) Mon Mar 27 11:33:31 2017: Debug:            --> TestClass
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{string:&Class[1]}
(3) Mon Mar 27 11:33:31 2017: Debug:            -->
auth_id:e2a1f6be9625aea371d668e2b604363c
(3) Mon Mar 27 11:33:31 2017: Debug:         EXPAND %{string:&Class[*]}
(3) Mon Mar 27 11:33:31 2017: Debug:            --> TestClass
(3) Mon Mar 27 11:33:31 2017: Debug:       } # update request = noop
(3) Mon Mar 27 11:33:31 2017: Debug:       foreach &Class
(3) Mon Mar 27 11:33:31 2017: Debug:         update request {
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND Foreach-Variable-0
(3) Mon Mar 27 11:33:31 2017: Debug:              --> 0x54657374436c617373
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND %{Foreach-Variable-0}
(3) Mon Mar 27 11:33:31 2017: Debug:              --> 0x54657374436c617373
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND Foreach-Variable-0
(3) Mon Mar 27 11:33:31 2017: Debug:              --> 0x54657374436c617373
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND
%{string:%{Foreach-Variable-0}}
(3) Mon Mar 27 11:33:31 2017: Debug:              -->
(3) Mon Mar 27 11:33:31 2017: Debug:         } # update request = noop
(3) Mon Mar 27 11:33:31 2017: Debug:         update request {
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND Foreach-Variable-0
(3) Mon Mar 27 11:33:31 2017: Debug:              -->
0x617574685f69643a6532613166366265393632356165613337316436363865326236303433363363
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND %{Foreach-Variable-0}
(3) Mon Mar 27 11:33:31 2017: Debug:              -->
0x617574685f69643a6532613166366265393632356165613337316436363865326236303433363363
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND Foreach-Variable-0
(3) Mon Mar 27 11:33:31 2017: Debug:              -->
0x617574685f69643a6532613166366265393632356165613337316436363865326236303433363363
(3) Mon Mar 27 11:33:31 2017: Debug:           EXPAND
%{string:%{Foreach-Variable-0}}
(3) Mon Mar 27 11:33:31 2017: Debug:              -->
(3) Mon Mar 27 11:33:31 2017: Debug:         } # update request = noop
(3) Mon Mar 27 11:33:31 2017: Debug:       } # foreach &Class = noop





> -
> List info/subscribe/unsubscribe? See
> http://www.freeradius.org/list/users.html

-- 
----------------------------------------------------------------
The name is Baud......, James Baud. 

----------------------------------------------------------------

Ing. Andrea Gabellini
Email: andrea.gabellini at 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



More information about the Freeradius-Users mailing list