backport from HEAD
[freeradius.git] / doc / variables.txt
1   Run-time variables
2   ------------------
3
4   The run-time variables defined by the server are:
5
6      %{Attribute-Name}               The value of the given Attribute-Name
7                                      in the request packet
8
9      %{request:Attribute-Name}       The value of value the given
10                                      Attribute-Name in the request packet
11      %{reply:Attribute-Name}         The value of the given Attribute-Name
12                                      in the reply packet
13      %{proxy-request:Attribute-Name} The value of the given Attribute-Name
14                                      in the proxy request packet (if it exists)
15      %{proxy-reply:Attribute-Name}   The value of the given Attribute-Name
16                                      in the proxy reply packet (if it exists)
17
18   The above variable expansions also support the meta-Attribute
19 Packet-Type as well. See the RADIUS dictionary for details on its
20 values.
21          
22      %{check:Attribute-Name}         Corresponding value for Attribute-Name
23                                      in check items for request
24         
25
26      %{config:section.subsection.item} Corresponding value in 'radiusd.conf'
27                                        for the string value of that item.
28
29   The %{config:...} variables should be used VERY carefully, as they
30 may leak secret information from your RADIUS server, if you use them
31 in reply attributes to the NAS!
32
33   If your system supports regular expressions, then regular expression
34 matching defines other special variables, just like in Perl.
35
36      %{0}       What the regular expression matched
37      %{1}       The first group which matched
38      %{2}       The second group which matched
39      ...
40      %{8}       The eight group which matched.
41
42   These variables are defined during a regular expression match =~,
43 and only when the expression matches.  They are NOT defined for the
44 operator !~, or when =~ doesn't match.  Any use of =~ destroys all
45 previous values of %{0}..%{8}, but the variables.
46
47
48   Some examples.
49
50   %{User-Name}                   The string value of the User-Name attribute.
51   %{proxy-reply:Framed-Protocol} The string value of the Framed-Protocol
52                                  attribute, from the proxy reply.
53   %{config:modules.unix.passwd}  The string value of the 'passwd' configuration
54                                  item in the 'unix' module, in the 'modules'
55                                  section of radiusd.conf.
56
57 DEFAULT  User-Name =~ "^([^@]+)@(.*)"
58          All-That-Matched = `%{0}`
59          Just-The-User-Name = `%{1}`
60          Just-The-Realm-Name = `%{2}`
61
62
63   The variables are used in dynamically translated strings.  Most of
64 the configuration entries in radiusd.conf (and related files) will do
65 dynamic string translation.  To do the same dynamic translation in a
66 RADIUS attribute (when pulling it from a database, or "users" file),
67 you must put the string into an back-quoted string:
68
69        Session-Timeout = `%{expr: 2 + 3}`
70
71   To do the dynamic translation in the 'radiusd.conf' (or some other
72 configuration files), just use the variable as-is.  See 'radiusd.conf'
73 for examples.
74
75
76   Conditional syntax
77   --------------------
78
79   Additionally, you can use conditional syntax similar to ${foo:-bar} as
80 defined in 'sh'.  For example:
81
82   1.  %{Foo:-bar}
83     When attribute Foo is set:    returns value of Foo
84     When attribute Foo is unset:  returns literal string 'bar'
85
86   2.  %{Foo:-%{Bar}}
87     When attribute Foo is set:    returns value of attribute Foo
88     When attribute Foo is unset:  returns value of attribute Bar (if any)
89
90   3.  %{Foo:-%{Bar:-baz}}
91     When attribute Foo is set:    returns value of attribute Foo
92     When attribute Foo is unset:  returns value of attribute Bar (if any)
93     When attribute Bar is unset:  returns literal string 'baz'
94
95
96   Attributes as environment variables in executed programs
97   --------------------------------------------------------
98
99   When calling an external program (e.g. from Exec-Program-Wait), these
100 variables can be passed on the command line to the program.  In
101 addition, the server places all of the attributes in the RADIUS
102 request into environment variables for the external program.  The
103 variables are renamed under the following rules:
104
105   1.  All letters are made upper-case.
106
107   2.  All hyphens '-' are turned into underscores '_'
108
109 so the attribute User-Name can be passed on the command line to the
110 program as %{User-Name}, or used inside the program as the environment
111 variable USER_NAME (or $USER_NAME for shell scripts).
112
113   If you want to see the list of all of the variables, try adding a
114 line 'printenv > /tmp/exec-program-wait' to the script.  Then look in
115 the file for a complete list of variables.
116
117
118   One-character variables
119   -----------------------
120
121   The following one-character variables are also defined.  However, they
122 are duplicates of the previous general cases, and are only provided
123 for backwards compatibility.  They WILL BE removed in a future
124 release.  They also do NOT permit the use of conditional syntax
125 (':-'), as described above.
126
127
128     Variable  Description                 Proper Equivalent
129     --------  -----------                 ----------------
130      %a       Protocol (SLIP/PPP)         %{Framed-Protocol}
131      %c       Callback-Number             %{Callback-Number}
132      %d       request day (DD)
133      %f       Framed IP address           %{Framed-IP-Address}
134      %i       Calling Station ID          %{Calling-Station-Id}
135      %l       request timestamp
136      %m       request month (MM)
137      %n       NAS IP address              %{NAS-IP-Address}
138      %p       Port number                 %{NAS-Port}
139      %s       Speed (PW_CONNECT_INFO)     %{Connect-Info}
140      %t       request in ctime format
141      %u       User name                   %{User-Name}
142      %A       radacct_dir                 %{config:radacctdir}
143      %C       clientname
144      %D       request date (YYYYMMDD)
145      %H       request hour
146      %L       radlog_dir                  %{config:logdir}
147      %M       MTU                         %{Framed-MTU}
148      %R       radius_dir                  %{config:raddbdir}
149      %S       request timestamp
150                 in SQL format
151      %T       request timestamp
152                 in database format
153      %U       Stripped User name          %{Stripped-User-Name}
154      %V       Request-Authenticator
155                 (Verified/None)
156      %Y       request year (YYYY)
157      %Z       All request attributes
158                except password
159                (must have a big buffer)
160
161  $Id$