| 1 |
= Further dynamic translation |
| 2 |
|
| 3 |
*Goal:* To use dynamic translation of strings to perform inter-module |
| 4 |
references. |
| 5 |
|
| 6 |
*Time:* 20-35 minutes. |
| 7 |
|
| 8 |
*Files:* |
| 9 |
|
| 10 |
- `etc/raddb/radiusd.conf` |
| 11 |
- `etc/raddb/users` |
| 12 |
|
| 13 |
Run-time variables in the server may include more than simple references to |
| 14 |
attributes in packets. The server supports the ability to perform complex |
| 15 |
inter-module queries, which significantly extends its usefulness. In this |
| 16 |
exercise, we will work through a number of different examples of configuring |
| 17 |
inter-module calls. |
| 18 |
|
| 19 |
To start, open `raddb/mods-available/exec` and read the sample configuration for |
| 20 |
the `exec` module. Then, edit the users file to add the following entry at the |
| 21 |
top: |
| 22 |
|
| 23 |
------------------------------------------------------------------------------- |
| 24 |
bob Password.Cleartext := "hello" |
| 25 |
Callback-Id = "%exec('/bin/echo', "Hello, there") |
| 26 |
------------------------------------------------------------------------------- |
| 27 |
|
| 28 |
The `echo` program may be in `/usr/bin/echo`, depending on your local system. On |
| 29 |
many systems you can use the following command: |
| 30 |
|
| 31 |
[source, bash] |
| 32 |
------------ |
| 33 |
$ which echo |
| 34 |
------------ |
| 35 |
|
| 36 |
This will tell you the full pathname of the `echo` command. Use that pathname in |
| 37 |
the file entry. |
| 38 |
|
| 39 |
Start the server and send it a test packet for user `bob`. The debug output of |
| 40 |
the server should print messages similar to the following. |
| 41 |
|
| 42 |
------------------------------------------------------------------------------- |
| 43 |
(0) files : users: Matched entry bob at line 1 |
| 44 |
Executing: /bin/echo Hello, there: |
| 45 |
Program returned code (0) and output 'Hello, there' |
| 46 |
(0) files : EXPAND %exec('/bin/echo', "Hello, there") |
| 47 |
(0) files : --> Hello, there |
| 48 |
(0) [files] = ok |
| 49 |
------------------------------------------------------------------------------- |
| 50 |
|
| 51 |
These message indicate that the first entry in the file (at line 1) was used to |
| 52 |
match the incoming request. |
| 53 |
|
| 54 |
The `exec` xlat function was then used to perform the dynamic translation of the |
| 55 |
string, which resulted in a call to the `rlm_exec` module. |
| 56 |
|
| 57 |
That module called the `Exec-Program` function of the server to execute a |
| 58 |
program, and finally, the `exec` xlat function returned the string "Hello |
| 59 |
there". |
| 60 |
|
| 61 |
That text was then sent back to the RADIUS client in the `Callback-Id` |
| 62 |
attribute, which was not quoted above. |
| 63 |
|
| 64 |
// Copyright (C) 2021 Network RADIUS SAS. Licenced under CC-by-NC 4.0. |
| 65 |
// This documentation was developed by Network RADIUS SAS. |
| 66 |
Another dynamic translation string function is the `expr` module. It performs |
| 67 |
some simple mathematical operations. The following sample file entry |
| 68 |
demonstrates how to use the `expr` module. |
| 69 |
|
| 70 |
------------------------------------------------------------------------------- |
| 71 |
bob Password.Cleartext := "hello" |
| 72 |
Session-Timeout = "%{60 * 60}" |
| 73 |
------------------------------------------------------------------------------- |
| 74 |
|
| 75 |
Dynamically translated strings may also be used as "check items" to match |
| 76 |
requests coming in to the server. The following examples show how those strings |
| 77 |
(or run-time variables) may be used to both match a request and to configure |
| 78 |
dynamic responses. |
| 79 |
|
| 80 |
You should use the `bob-login-one.sh` script to send a request to match the |
| 81 |
first entry and should send another request with a different NAS-Port. |
| 82 |
|
| 83 |
------------------------------------------------------------------------------- |
| 84 |
bob Password.Cleartext := "hello", NAS-Port == "%exec('/usr/bin/id', '-u')" |
| 85 |
Reply-Message = "Your port is very nice.", |
| 86 |
Session-Timeout = "%{60 * 60}" |
| 87 |
|
| 88 |
bob Password.Cleartext := "hello", NAS-Port != "%exec('/usr/bin/id', '-u')" |
| 89 |
Reply-Message = "Your port is less nice.", |
| 90 |
Session-Timeout = "%{60 * 2}" |
| 91 |
------------------------------------------------------------------------------- |
| 92 |
|
| 93 |
The run-time variables may be nested, too. The following file entry |
| 94 |
demonstrates this nesting. |
| 95 |
|
| 96 |
------------------------------------------------------------------------------- |
| 97 |
bob Password.Cleartext := "hello" |
| 98 |
Session-Timeout = "%{60 * %exec(/usr/bin/id -u})" |
| 99 |
------------------------------------------------------------------------------- |
| 100 |
|
| 101 |
In this case, the user "bob" is given one minute of access time, |
| 102 |
multiplied by the value of the "UID" of the RADIUS server. |
| 103 |
|
| 104 |
== Further considerations |
| 105 |
|
| 106 |
Run-time variables allow inter-module calling. The administrator may perform LDAP |
| 107 |
queries and SQL queries to use database information in other modules. |
| 108 |
|
| 109 |
Unfortunately, the format of the string is module-dependent. This limitation |
| 110 |
comes from the fact that each module has its own syntax for database queries. |
| 111 |
The syntax for querying LDAP databases is different than the syntax for querying |
| 112 |
SQL database. The administrator should consult the `man` pages for the relevant |
| 113 |
module for more information on the syntax for run-time dynamic translation of |
| 114 |
strings. |
| 115 |
|
| 116 |
Another limitation is that the query string can be only approximately 250 |
| 117 |
characters long in the current version of the server. This limitation may be |
| 118 |
removed in a later version. |
| 119 |
|
| 120 |
== Questions |
| 121 |
|
| 122 |
1. How would you perform an SQL query in a run-time variable, instead of |
| 123 |
executing a program? |
| 124 |
2. Why is it useful for modules to be able to query information from other |
| 125 |
modules? |
| 126 |
3. What is an example of conditional syntax for a run-time variable? |
| 127 |
|