Time for action – using regular expressions
Unlang allows regular expression evaluations in condition checking. These usually are Posix regular expressions. The operators =~
and !~
are associated with regular expressions. For a simple proof of concept we will modify the previous exercise:
- Edit the
sites-available/default
virtual server under the FreeRADIUS configuration directory and add the following inside thepost-auth
section, at the top of the section:if(request:Framed-Protocol =~ /.*PP$/i){ update reply { Reply-Message := "Regexp match for %{0}" } }
- Restart FreeRADIUS in debug mode and try to authenticate as
alice
. First add a1
to the end of theradtest
command, then omit the1
.Take note how the regular expression match changes the value of
Reply-Message
when you add the1
to theradtest
command.
What just happened?
We have shown the regular expression capabilities of unlang. Take note of the following important points on regular expressions in unlang...