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. I just need to strip ``adsl-bla/'' off the login request. Help much appreciated — thanks! Bernd
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
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
On Mar 3, 2016, at 9:34 AM, Bernd <bernd@kroenchenstadt.de> wrote:
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/) {
That's good.
update request { User-Name := "([^%%]+)%%adsl-sbt.kroenchenstadt.de/"
That's not. You're setting the value of User-Name to... a regular expression? Why? You need to set it to the value captured from the regular expression.
I just need to strip ``adsl-bla/'' off the login request.
if (User-Name =~ /^adsl-\/(.+)$/) { update request { User-Name := "%{1}" } } i.e. you don't need to escape the "-". You do need to escape the "/'. And then you just grab everything to the right of that. Alan DeKok.
Am 2016-03-03 16:23, schrieb Alan DeKok:
On Mar 3, 2016, at 9:34 AM, Bernd <bernd@kroenchenstadt.de> wrote:
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/) {
That's good.
update request { User-Name := "([^%%]+)%%adsl-sbt.kroenchenstadt.de/"
That's not. You're setting the value of User-Name to... a regular expression? Why?
You need to set it to the value captured from the regular expression.
I just need to strip ``adsl-bla/'' off the login request.
if (User-Name =~ /^adsl-\/(.+)$/) { update request { User-Name := "%{1}" } }
i.e. you don't need to escape the "-". You do need to escape the "/'. And then you just grab everything to the right of that.
Thanks a lot, that works for me now. Sorry for the late reply, had to head out for a few days.
Alan DeKok.
Regards, Bernd
participants (3)
-
Alan DeKok -
Bernd -
Herwin Weststrate