"switch" statement": would you know a more compact statement?
Hi FR people, Is there a more compact way to state what follows? switch { ("%{User-Name}" =~ /@tenant101\.bic\.local/) {update control{Proxy-To-Realm := "tenant101"} ("%{User-Name}" =~ /@tenant102\.bic\.local/) {update control{Proxy-To-Realm := "tenant102"} ("%{User-Name}" =~ /@tenant103\.bic\.local/) {update control{Proxy-To-Realm := "tenant103"} ("%{User-Name}" =~ /@tenant104\.bic\.local/) {update control{Proxy-To-Realm := "tenant104"} ("%{User-Name}" =~ /@tenant105\.bic\.local/) {update control{Proxy-To-Realm := "tenant105"} ("%{User-Name}" =~ /@tenant106\.bic\.local/) {update control{Proxy-To-Realm := "tenant106"} ("%{User-Name}" =~ /@tenant107\.bic\.local/) {update control{Proxy-To-Realm := "tenant107"} .... ("%{User-Name}" =~ /@tenant170\.bic\.local/) {update control{Proxy-To-Realm := "tenant170"} } Eventually, I may get the value of the Proxy-To-Realm variable, by stripping the 2nd and top level domain and there would not need to repeat the case. Thanks, Alex
On Apr 26, 2023, at 11:03 AM, Alex Zetaeffesse <fzetafs@gmail.com> wrote:
Is there a more compact way to state what follows?
switch { ("%{User-Name}" =~ /@tenant101\.bic\.local/) {update control{Proxy-To-Realm := "tenant101"}
That's not correct configuration syntax, but OK... In general things like this are best done with regular expressions. Especially if the data you're trying to use is part of the input packet. if (&User-Name =~ /([^.]+)\.bic\.local) { update control { &Proxy-To-Realm := "%{1}" } } You also don't have to put quotes around references to User-Name. Just use &User-Name. This works, and that's what the documentation says to do. I have no idea why so many people use constructs like "%{User-Name}". It's just not necessary. Alan DeKok.
Thanks Alan, indeed I should have written (still not using it the right way as you pointed out) switch "%{User-Name}" { case "/@tenant101\.bic\.local/" {update control{Proxy-To-Realm := "tenant101"}} case "/@tenant102\.bic\.local/" {update control{Proxy-To-Realm := "tenant102"}} ... } BTW, I think this is called back-reference, isn't it? I'm pointing this out, just for anybody who may read this mail thread looking for the same feature. Thanks for your fast reply! Alex On Wed, Apr 26, 2023 at 5:30 PM Alan DeKok <aland@deployingradius.com> wrote:
On Apr 26, 2023, at 11:03 AM, Alex Zetaeffesse <fzetafs@gmail.com> wrote:
Is there a more compact way to state what follows?
switch { ("%{User-Name}" =~ /@tenant101\.bic\.local/) {update control{Proxy-To-Realm := "tenant101"}
That's not correct configuration syntax, but OK...
In general things like this are best done with regular expressions. Especially if the data you're trying to use is part of the input packet.
if (&User-Name =~ /([^.]+)\.bic\.local) { update control { &Proxy-To-Realm := "%{1}" } }
You also don't have to put quotes around references to User-Name. Just use &User-Name. This works, and that's what the documentation says to do. I have no idea why so many people use constructs like "%{User-Name}". It's just not necessary.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
Sorry, me again. While reading this https://networkradius.com/doc/3.0.10/unlang/regex.html I noticed the i for matching the regex in a non case-sensitive way. I played a bit and then I tried sending a request as user@tenAnt101.bic.local; the catch-group was tenAnt101 and there was still a match for >> realm "tenant101" << in the proxy.conf, though the catch was not based on the case. So, are all the variables that relate to the username always treated as case-insensitive? To which other strings does this rule apply? Thanks, Alex On Wed, Apr 26, 2023 at 5:40 PM Alex Zetaeffesse <fzetafs@gmail.com> wrote:
Thanks Alan,
indeed I should have written (still not using it the right way as you pointed out)
switch "%{User-Name}" { case "/@tenant101\.bic\.local/" {update control{Proxy-To-Realm := "tenant101"}} case "/@tenant102\.bic\.local/" {update control{Proxy-To-Realm := "tenant102"}} ... }
BTW, I think this is called back-reference, isn't it? I'm pointing this out, just for anybody who may read this mail thread looking for the same feature.
Thanks for your fast reply!
Alex
On Wed, Apr 26, 2023 at 5:30 PM Alan DeKok <aland@deployingradius.com> wrote:
On Apr 26, 2023, at 11:03 AM, Alex Zetaeffesse <fzetafs@gmail.com> wrote:
Is there a more compact way to state what follows?
switch { ("%{User-Name}" =~ /@tenant101\.bic\.local/) {update control{Proxy-To-Realm := "tenant101"}
That's not correct configuration syntax, but OK...
In general things like this are best done with regular expressions. Especially if the data you're trying to use is part of the input packet.
if (&User-Name =~ /([^.]+)\.bic\.local) { update control { &Proxy-To-Realm := "%{1}" } }
You also don't have to put quotes around references to User-Name. Just use &User-Name. This works, and that's what the documentation says to do. I have no idea why so many people use constructs like "%{User-Name}". It's just not necessary.
Alan DeKok.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Apr 26, 2023, at 1:18 PM, Alex Zetaeffesse <fzetafs@gmail.com> wrote:
https://networkradius.com/doc/3.0.10/unlang/regex.html
I noticed the i for matching the regex in a non case-sensitive way.
That works where it's documented to work. i.e. for "if" statements.
I played a bit and then I tried sending a request as user@tenAnt101.bic.local; the catch-group was tenAnt101 and there was still a match for >> realm "tenant101" << in the proxy.conf, though the catch was not based on the case.
Domain names are case insensitive, so realm comparisons are case insensitive.
So, are all the variables that relate to the username always treated as case-insensitive?
No.
To which other strings does this rule apply?
There is no "rule". Pretty much everything is obsessively documented, and it all works as documented. I guess there's no statement that "realm comparisons are case insensitive". I can go add that. But for everything else, strings are strings, and comparisons are done by comparing the strings byte-by-byte. If you need case insensitive comparisons, use a regex. Alan DeKok.
participants (2)
-
Alan DeKok -
Alex Zetaeffesse