Stripping prefix with unlang

Bernd bernd at kroenchenstadt.de
Fri Mar 11 09:36:31 CET 2016


Am 2016-03-03 16:16, schrieb Herwin Weststrate:

Sorry for the late reply, had to head out for a few days.

> On 03-03-16 15:34, Bernd wrote:
>> Hi,
>> 
>> I am pulling my hears for two hours now. I'd like to strip a prefix 
>> off
>> a request and I'm trying to use unlang in policy.d/filter to do that.
>> 
>>         if (User-Name =~
>> /adsl\-bla\/([^%%]+)%%adsl-bla.kroenchenstadt.de/) {
>>                 update request {
>>                 User-Name := "([^%%]+)%%adsl-sbt.kroenchenstadt.de/"
>>                 }
>>         }
>> 
>> doesn't work, as
>> 
>>         if (User-Name =~ /adsl\-bla\/ {
>>                 update request {
>>                 User-Name -= "adsl\-bla\/"
>>                 }
>>         }
>> 
>> also refuses to be that what I need.
> 
> That last one contains at least two errors that make it fail to start: 
> a
> missing / and a missing ) at the regex statement.
> 
> There is no need to escape the hypen in regexes, and you should use the
> matches of the regex to fix it. I assumed you wanted to strip adsl-bla/
> only if it the username starts with it.
> 
>   # Match everything except adsl-bla/ in (.*)
>   if (User-Name =~ /^adsl-bla\/(.*)/) {
>     update request {
>       # Use the match of (.*) as the result
>       &User-Name := "%{1}"
>     }
>   }

That makes much more sense, thanks.

> There may be even simpler solutions, since it looks a lot like a realm.
> The config for rlm_realm and the examples in policy.d/ can be a source
> of inspiration

Had a glimpse (or two) at policy.d, however, it's not a real realm. 
Upstream fiddles around a bit.

Thanks & regards,

Bernd


More information about the Freeradius-Users mailing list