import 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   Some examples.
48
49   %{User-Name}                   The string value of the User-Name attribute.
50   %{proxy-reply:Framed-Protocol} The string value of the Framed-Protocol
51                                  attribute, from the proxy reply.
52   %{config:modules.unix.passwd}  The string value of the 'passwd' configuration
53                                  item in the 'unix' module, in the 'modules'
54                                  section of radiusd.conf.
55
56 DEFAULT  User-Name =~ "^([^@]+)@(.*)"
57          All-That-Matched = `%{0}`
58          Just-The-User-Name = `%{1}`
59          Just-The-Realm-Name = `%{2}`
60
61
62   The variables are used in dynamically translated strings.  Most of
63 the configuration entries in radiusd.conf (and related files) will do
64 dynamic string translation.  To do the same dynamic translation in a
65 RADIUS attribute (when pulling it from a database, or "users" file),
66 you must put the string into an back-quoted string:
67
68        Session-Timeout = `%{expr: 2 + 3}`
69
70   To do the dynamic translation in the 'radiusd.conf' (or some other
71 configuration files), just use the variable as-is.  See 'radiusd.conf'
72 for examples.
73
74
75   Conditional syntax
76   --------------------
77
78   Additionally, you can use conditional syntax similar to ${foo:-bar} as
79 defined in 'sh'.  For example:
80
81   1.  %{Foo:-bar}
82     When attribute Foo is set:    returns value of Foo
83     When attribute Foo is unset:  returns literal string 'bar'
84
85   2.  %{Foo:-%{Bar}}
86     When attribute Foo is set:    returns value of attribute Foo
87     When attribute Foo is unset:  returns value of attribute Bar (if any)
88
89   3.  %{Foo:-%{Bar:-baz}}
90     When attribute Foo is set:    returns value of attribute Foo
91     When attribute Foo is unset:  returns value of attribute Bar (if any)
92     When attribute Bar is unset:  returns literal string 'baz'
93
94
95   Multiple-valued attributes
96   --------------------------
97
98      %{Attribute-Name[index]}
99         Reference the N'th occurance of the given attribute.  The
100         indexes start at zero.  This feature is NOT available for
101         non-attribute dynamic translations, like %{sql:...}.
102
103         e.g. %{User-Name[0]} is the same as %{User-Name}
104         e.g. %{Cisco-AVPair[2]} references the value of the *third*
105              Cisco-AVPair attribute (if it exists) in the request
106              packet,
107
108
109   Attributes as environment variables in executed programs
110   --------------------------------------------------------
111
112   When calling an external program (e.g. from 'rlm_exec' module),
113 these variables can be passed on the command line to the program.
114 In addition, the server places all of the attributes in the RADIUS
115 request into environment variables for the external program. The
116 variables are renamed under the following rules:
117
118   1.  All letters are made upper-case.
119
120   2.  All hyphens '-' are turned into underscores '_'
121
122 so the attribute User-Name can be passed on the command line to the
123 program as %{User-Name}, or used inside the program as the environment
124 variable USER_NAME (or $USER_NAME for shell scripts).
125
126   If you want to see the list of all of the variables, try adding a
127 line 'printenv > /tmp/exec-program-wait' to the script.  Then look in
128 the file for a complete list of variables.
129
130
131   One-character variables
132   -----------------------
133
134   The following one-character variables are also defined.  However, they
135 are duplicates of the previous general cases, and are only provided
136 for backwards compatibility.  They WILL BE removed in a future
137 release.  They also do NOT permit the use of conditional syntax
138 (':-'), as described above.
139
140
141     Variable  Description                 Proper Equivalent
142     --------  -----------                 ----------------
143      %a       Protocol (SLIP/PPP)         %{Framed-Protocol}
144      %c       Callback-Number             %{Callback-Number}
145      %d       request day (DD)
146      %f       Framed IP address           %{Framed-IP-Address}
147      %i       Calling Station ID          %{Calling-Station-Id}
148      %l       request timestamp
149      %m       request month (MM)
150      %n       NAS IP address              %{NAS-IP-Address}
151      %p       Port number                 %{NAS-Port}
152      %s       Speed (PW_CONNECT_INFO)     %{Connect-Info}
153      %t       request in ctime format
154      %u       User name                   %{User-Name}
155      %A       radacct_dir                 %{config:radacctdir}
156      %C       clientname
157      %D       request date (YYYYMMDD)
158      %H       request hour
159      %L       radlog_dir                  %{config:logdir}
160      %M       MTU                         %{Framed-MTU}
161      %R       radius_dir                  %{config:raddbdir}
162      %S       request timestamp
163                 in SQL format
164      %T       request timestamp
165                 in database format
166      %U       Stripped User name          %{Stripped-User-Name}
167      %V       Request-Authenticator
168                 (Verified/None)
169      %Y       request year (YYYY)
170      %Z       All request attributes
171                except password
172                (must have a big buffer)
173
174  $Id$