lpad on regular expression matches does not work

Jorge Pereira jpereira at freeradius.org
Thu Mar 4 16:26:17 CET 2021


Tomasz,

As Alan said, the current %{lpad:} (also the %{rpad:}) behaviour expects an attribute as you can see in https://github.com/FreeRADIUS/freeradius-server/blob/v3.0.x/raddb/mods-available/expr#L133 <https://github.com/FreeRADIUS/freeradius-server/blob/v3.0.x/raddb/mods-available/expr#L133>

Therefore, you could try something like:

…
if (&Calling-Station-Id && (&Calling-Station-Id =~ /^${policy.mac-addr-regexp}$/i)) {
    update control {
       &Tmp-String-1 := “%{1}”
       &Tmp-String-2 := “%{2}”
       &Tmp-String-3 := “%{3}”
       &Tmp-String-4 := “%{4}”
       &Tmp-String-5 := “%{5}”
       &Tmp-String-6 := “%{6}”
    }
    update request {
        &Calling-Station-Id := "%{toupper:%{lpad:&control:Tmp-String-1 2 0}:%{lpad:&control:Tmp-String-2 2 0}:%{lpad:&control:Tmp-String-3 2 0}:%{lpad:&control:Tmp-String-4 2 0}:%{lpad:&control:Tmp-String-5 2 0}:%{lpad:&control:Tmp-String-6 2 0}}"
    }
    updated
} else {
...

--
Jorge Pereira
jpereira at freeradius.org




> On 4 Mar 2021, at 07:13, Tomasz Chiliński via Freeradius-Users <freeradius-users at lists.freeradius.org> wrote:
> 
> Hello all,
> 
> I try to improve Calling-Station-Id MAC address canonicalization a little bit, so that
> is should left pad MAC octets with zeroes.
> 
> I modified default settings as is:
> 
> mac-addr-regexp = '([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})'
> 
> This regular expression matches example MAC address properly:
> 
>    [0] => 18:d0:71:f3:70:8
>    [1] => 18
>    [2] => d0
>    [3] => 71
>    [4] => f3
>    [5] => 70
>    [6] => 8
> 
> Then I want to make the whole thing this way:
> 
> rewrite_calling_station_id {
> 	if (&Calling-Station-Id && (&Calling-Station-Id =~ /^${policy.mac-addr-regexp}$/i)) {
> 		update request {
> 			&Calling-Station-Id := "%{toupper:%{lpad:%{1} 2 0}:%{lpad:%{2} 2 0}:%{lpad:%{3} 2 0}:%{lpad:%{4} 2 0}:%{lpad:%{5} 2 0}:%{lpad:%{6} 2 0}}"
> 		}
> 		updated
> 	}
> 	else {
> 		noop
> 	}
> }
> 
> And here's surprise - lpad expression function handles only attribute parameters (ex. {lpad:&User-Name 100 0}),
> but not regexp matches. What am I doing wrong?
> 
> -- 
> Bests,
> Tomasz Chiliński, Chilan
> opiekun projektu LMS - https://lms.org.pl
> kierownik projektu LMS Plus / LMS+ - https://lms-plus.org
> 
> 
> -- 
> Pozdrawiam
> Tomasz Chiliński, Chilan
> opiekun projektu LMS - https://lms.org.pl
> kierownik projektu LMS Plus / LMS+ - https://lms-plus.org
> -
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html



More information about the Freeradius-Users mailing list