double-quoted strings: a literal %

Stefan Winter stefan.winter at
Tue Jul 2 11:22:46 CEST 2019


I'm currently running into a wall with what should be a simple escaping
question. Apologies if this is documented in unlang.5 - I looked but
didn't find it there.

The thing is that I want to run an authorize_check_query:

authorize_check_query = "\
      SELECT 1 as id, username, 'Expiration' AS attribute,
date_format(stoptime, '\%d \%b \%Y \%H:\%i') AS value, ':=' AS op \
          FROM expirationinfo \
          WHERE username = '%{SQL-User-Name}' AND starttime <= NOW()

The whole thing needs to be a double-quoted string because I want the
expansion of %{SQL-User-Name} to happen.

However, there is a problem with the part that does date_format.
date_format wants literal % characters.

The above while FreeRADIUS-syntactically correct does not yield the
expected results: the \ characters are coming back as part of the format
string of the date_format function in MySql, like

"\19 \Jul \2099 \23:\59"

But if I omit the \ in front of the % then the FreeRADIUS parser fails
on the string because the % is not followed by a valid expansion.

Now the unlang manpage tells me that \" leads to a literal " but
apparently \% does not lead to a literal %.

So the question really is: how do I keep a literal % inside a
double-quoted string?


Stefan Winter

Ingenieur de Recherche
Fondation RESTENA - Réseau Téléinformatique de l'Education Nationale et
de la Recherche
2, avenue de l'Université
L-4365 Esch-sur-Alzette

Tel: +352 424409 1
Fax: +352 422473

PGP key updated to 4096 Bit RSA - I will encrypt all mails if the
recipient's key is known to me
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Freeradius-Users mailing list