Escaping usernames during RADIUS accounting

Today I encountered a problem in my FreeRADIUS setup. Usernames can be sent to my RADIUS servers as a simple username (e.g. jonathan) or with a realm prepended (e.g. DOMAINjonathan).

When a username with a realm gets sent to a RADIUS authentication server that is doing MSCHAP, the domain is automatically stripped and you never notice. But when it gets sent to an accounting server (clearly no MSCHAP) there is no stripping or escaping done automatically.

This caught me out.

Users were authenticating on my network successfully. DOMAINrachel and DOMAINthomas were happily authenticated against the domain controllers and gained access to the wireless. But when they started sending accounting packets, the r and t portions of their usernames were sent to the database unquoted, where they were interpreted as a Unix newline and a tabspace respectively.


I didn’t notice until I saw that MySQL had converted these r and t characters to the hex equivalents. Where my accounting table should have contained rachel, it actually contained DOMAIN=0Dachel.


I fixed this by creating a local proxy realm. At the end of my proxy.conf, I added these lines:

realm DOMAIN {

Obviously substituting DOMAIN for the real name of my domain.

Then in the preacct section of my virtual server I added the module ntdomain to populate the variable %{Stripped-User-Name} with the domain part of the username that was originally in %{User-Name}.

Now, looking at the top of whichever dialup.conf suits your database architecture, make sure the following line is uncommented:

sql_user_name = "%{%{Stripped-User-Name}:-%{%{User-Name}:-DEFAULT}}"

…and that all other definitions of sql_user_name are commented.

Once you’ve done this, your accounting detail logs will contain username likes DOMAINusername (with an escaped backslash) and your database table will simply have username.

One thought on “Escaping usernames during RADIUS accounting

  1. Hi

    thanks for the post, am using Freeradius for authenticating mobile phone, am testing windows phone and it sends by default Domainusername to the freeradius, i want to remove the domain in order to authenticate can you please advice


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: