Search code examples
freeradiusradius

FreeRadius filter_username


I need to adjust the filter to a radius in order to allow a connection only with the username which contains the word "test".

Set up the block:

filter_private  {
            if (User-Name =~ /^(?!test).*$/) {
                    update reply {
                            Reply-Message += "Rejected: Username rejected, because not test"
                    }
                    reject
            }
    }

But it allows absolutely any username.


Solution

  • Based on the documentation, I think you need to negate the logic:

    if (User-Name !~ /^(?!test).*$/) {
        # etc.
    }
    

    Also, the regex above probably (depending on your local regex engine) allows usernames starting with test (due to ^) not any username containing test. For the latter, you would need to change the logic to be:

    if (User-Name !~ /.*test.*/) {
        # etc.
    }