%{expr: 1 ` 2 ` (2^3) + 0xad}
rlm_expr
Synopsis
The expr
module implements math expressions in dynamically expanded
strings. It also implements a number of other useful expansions.
Processing Sections
None.
Expansions
The expr
module implements a number of expansions.
- Syntax
-
%{expr: …}
- Contents
-
The contents of the expansion are a series of mathematical expressions. The output of the expansion is the result of evaluating the mathematical expression.
-
Normal math operators are supported as shown in the table below.
Operator | Meaning |
---|---|
+ |
Addition |
- |
Subtraction |
/ |
Division |
* |
Multiplication |
%% |
Remainder |
<< |
Left shift |
>> |
Right shift |
& |
Bitwise "and" |
| |
Bitwise "or" |
^ |
Power |
( |
Open bracket, start sub-expression |
) |
Close bracket, end sub-expression |
-
All calculations are done via unsigned 64-bit integers. Floating point is not supported. All integers are assumed to be base 10. Hexadecimal numbers can be used by preceding them with
0x
, such as with0xabcdef
. -
.Example
- Syntax
-
%{escape: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the input string with the
safe_characters
escaped as=HH
, whereHH
is the hex value of the character.
- Syntax
-
%{rand: …}
- Contents
-
The contents of the expansion are an integer that is the limit for the random number generation. The output of the expansion is a random number that is between 0 and that limit.
-
The limit must be greater than zero and less than 2^30 (about one billion).
- Syntax
-
%{randstr: …}
- Contents
-
The contents of the expansion are a pattern describing the random string to generate. The output of the expansion is the random string.
-
The input pattern is described by the following table. Each modifier can take a numeric prefix, to create more than one character of output. e.g.
%{randstr:5n}
will create 5 numbers. The repetition is limited to 100. Any more than that is ignored.
Character | Meaning |
---|---|
! |
Punctuation. One of !"#$%&'()*+,-./:;<⇒?@[\\]^_`{|}~ |
. |
Alphanumeric plus punctuation |
a |
Alphanumeric [a-zA-Z0-9] |
c |
Latin lowercase character [a-z] |
C |
Latin uppercase character [A-Z] |
h |
two hex digits [0-f][0-f] |
n |
Numbers [0-9] |
s |
Salt [a-zA-Z0-9./] |
- Syntax
-
%{tolower: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the input string, converted to lowercase.
- Syntax
-
%{toupper: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the input string, converted to uppercase.
- Syntax
-
%{urlquote: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the input string with the
safe_characters
escaped as%HH
, whereHH
is the hex value of the character.
- Syntax
-
%{md5: …}
- Contents
-
The contents of the expansion are either a string or a reference to an attribute. The output of the expansion is the MD5 hash of the input string, printed as 32 hexadecimal digits.
%{md5:Hi, Mom}
%{md5:&User-Name}
-
The attribute reference syntax allows the expansion to take the MD5 hash of binary data. If attribute references were not allowed, then the MD5 expansion would be required to hash the printable form of the binary data, which is not the same as hashing the binary data.
- Syntax
-
%{sha1: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the sha1 hash of the string. This expansion otherwise operates the same as the
md5
one.
- Syntax
-
%{sha256: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the
sha256
hash of the string. This expansion otherwise operates the same as themd5
one.
- Syntax
-
%{sha512: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the
sha512
hash of the string. This expansion otherwise operates the same as themd5
one.
- Syntax
-
%{base64: …}
- Contents
-
The contents of the expansion are a string. The output of the expansion is the string converted to base64. This expansion supports attribute references, just like the
md5
expansion.
- Syntax
-
%{base64tohex: …}
- Contents
-
The contents of the expansion are a base64 string. The output of the expansion is the string converted to hex digits. The digits are not preceded by any
0x
characters.
- Syntax
-
%{lpad:&Attribute-Reference length pad}
- Contents
-
The contents of the expansion are 3 fields, with the third field being optional. The first field is an attribute references, e.g.
&User-Name
. The second is an integer specifying the size of the fixed-width field to produce, e.g.7
. The third field is a padding character, e.g.0
. If the the third field is omitted, then a space is used as the fill character.
%{lpad:&User-Name 7}
%{lpad:&User-Name 7 x}
%{lpad:&reply:Filter-Id 7}
-
The output of the expansion is a fixed-width string, composed of "length" characters, with the attribute printed to a string. If "length" is smaller than the length of the attribute string, the output is truncated to "length" characters. If "length" is equal to the length of the attribute string, the output is exactly the attribute string. If "length" is larger than the length of the attribute string, the output is filled to the left with the "pad" character.
Input | Output |
---|---|
%{lpad:&User-Name 7} |
|
%{lpad:&User-Name 2} |
|
%{lpad:&User-Name 6 0} |
|
- Syntax
-
%{rpad:&Attribute-Reference length pad}
- Contents
-
The contents of the expansion are 3 fields, with the third field being optional. The first field is an attribute references, e.g.
&User-Name
. The second is an integer specifying the size of the fixed-width field to produce, e.g.7
. The third field is a padding character, e.g.0
. If the the third field is omitted, then a space is used as the fill character.
%{rpad:&User-Name 7}
%{rpad:&User-Name 7 x}
%{rpad:&reply:Filter-Id 7}
-
The output of the expansion is a fixed-width string, composed of "length" characters, with the attribute printed to a string. If "length" is smaller than the length of the attribute string, the output is truncated to "length" characters. If "length" is equal to the length of the attribute string, the output is exactly the attribute string. If "length" is larger than the length of the attribute string, the output is filled to the right with the "pad" character.
Input | Output |
---|---|
%{rpad:&User-Name 7} |
|
%{rpad:&User-Name 2} |
|
%{rpad:&User-Name 6 0} |
|
Directives
- Syntax
-
safe-characters = string
- Default
-
@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-: /_
- Description
-
Characters that will not be encoded by the
%\{encode:…}
expansion.