double-quoted strings: a literal %

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


Hello,

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()
ORDER BY value DESC LIMIT 1"

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?

Greetings,

Stefan Winter

-- 
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

http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC0DE6A358A39DC66
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freeradius.org/pipermail/freeradius-users/attachments/20190702/c5d50673/attachment.sig>


More information about the Freeradius-Users mailing list