Stripping prefix with unlang

Herwin Weststrate herwin at quarantainenet.nl
Thu Mar 3 16:16:56 CET 2016


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}"
    }
  }

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

-- 
Herwin Weststrate


More information about the Freeradius-Users mailing list