📄 radtest.texi
字号:
$@{x::@} @print{} (<teletype>:1)x?$@{x::Enter value of x: @} @print{} Enter value of x: @end group@end smallexample@item $@{variable:&text@}Prompt for the value with echo turned off if unset. This is similarto the @code{$@{variable::text@}}, with the exception that the inputvalue will not be echoed on the screen. This notation provides aconvenient way for asking user to supply default values for variables(such as passwords, shared secrets, etc.) while preventing them frombeing compromised. @end table@node Accessing Elements of A/V Pair Lists@subsubsection Accessing Elements of A/V Pair ListsElements of an @code{avlist} are accessed as if it were an array,i.e.:@smallexample$@var{variable} [ @var{attribute-name} ]@end smallexampleIf the attribute @var{attribute-name} is of @code{string} data typeand @var{variable} may contain more than one pair with this attribute,adding an asterisk after @var{attribute-name} returns concatenatedvalues of all such pairs:@smallexample$@var{variable} [ @var{attribute-name} * ]@end smallexampleExamples:@smallexample@groupx = (NAS-Port-Id = 127.0.0.1 \ Reply-Message = "a long" Reply-Message = " string"$x[NAS-Port-Id] @result{} 127.0.0.1$x[Reply-Message] @result{} "a long"$x[Reply-Message*] @result{} "a long string"@end group@end smallexample@FIXME{How to get @var{n}th instance of an attribute? What getsreturned if there is no such attribute in the list?}@node Assignment Options@subsubsection Assignment OptionsYou can set any @command{radtest} variable from the command line.There are two ways of doing so.First, you can use @dfn{variable assignment option} @option{--assign}(or @option{-a}). Its syntax is:@smallexample@group--assign @var{variable}=@var{text}-a @var{variable}=@var{text}@end group@end smallexample@noindentFor example:@smallexampleradtest -a foobar=5@end smallexampleAnother way is useful when you load a @code{radtest} program by@option{--file} or @option{-f}. This second way consists in includinga variable assignment in the form@smallexample@var{variable}=@var{text}@end smallexample@noindentin the command line after the script name. For example:@smallexampleradtest -f myprog.rad foo=5 addr=127.0.0.1@end smallexample@noindentThis method is especially useful for executable scripts that arerun using @code{#!} shell magic. Consider a simple script:@smallexample@group#! /usr/local/bin/radtest -fprint $addr@end group@end smallexample@noindentThe value of @var{addr} can be given to the script from the commandline as in the example below:@smallexamplemyprog.rad addr=127.0.0.1@end smallexample@node Built-in Variables@subsubsection Built-in VariablesThe following variables are predefined:@table @var@item _(an underscore character)Contains the result of last evaluated expression.@item REPLY_CODEContains the last reply code received from the @RADIUS{} server(@code{integer}).@item REPLYContains the @AVP{}s lastly received from the @RADIUS{} server(@code{avlist}).@item SOURCEIPContains the source @IP{} of the @RADIUS{} client (@code{ipaddr}).By default, it equals the @IP{} set via @code{source_ip} statementin your @file{client.conf} file (@pxref{client.conf}).@item INPUTThe value of the input read by @code{input} statement(@pxref{Built-in Primitives,input}).@item OPTVARThe option obtained by the recent call to @code{getopt}(@pxref{Built-in Primitives,getopt}).@item OPTARGArgument to the option obtained by the recent call to @code{getopt}.@item OPTINDIndex of the next command line argument to be processed by@code{getopt}. If the last call to @code{getopt} returned false,@code{OPTIND} contains index of the first non-optional argumentin the command line.@end table@node Positional Parameters@subsection Positional ParametersNormally @command{radtest} stops parsing its command linewhen it encounters either first non-optional argument(i.e. the one not starting with dash), or an argument consistingof two dashes. The rest of the command line starting from thefirst non-optional argument forms @dfn{positional parameters}.These parameters are said to form the @dfn{top-level environment}.Similarly, when invoking a user-defined function (@pxref{FunctionDefinitions}), arguments passed to it are said to form the@dfn{current environment} of the function. These arguments arepositional parameters for this function.Positional parameters are assigned numbers starting from 1. To access(@dfn{dereference}) a positional parameter, the syntax @code{$@var{n}}is used, where @var{n} is the number of the parameter. Alternativeforms, such as @code{$@{@var{n}@}} or @code{$@{@var{n}:-text@}},can also be used. These work exactly as described in@ref{Dereferencing Variables}).The number of positional parameters can be accessed using a specialnotation @code{$#}.Several things need to be mentioned:@itemize @bullet@item All top-level positional parameters have @code{string} datatype, whereas the types of positional parameters in a functioncurrent environment are determined before inoking the function.@item Special notion @code{$0} returns the name of the functionbeing evaluated. When used in the top-level environment, it returnsthe name of @command{radtest} program as given by @option{--file}(@option{-f}) option.@item Dereferencing non-existing parameter returns empty string. Thisdiffers from dereferencing non-existing variable, which results inerror.@item @code{AWK} programmers should note that assignments(@pxref{Assignment Options}) are not included in the top levelenvironment (see example below).@end itemizeFor example, suppose you run: @smallexampleradtest -f script.rad name foo=bar 5@end smallexampleThen, the top-level environment of program @file{script.rad} consistsof the following variables:@smallexample@group$0 @result{} script.rad$1 @result{} name$2 @result{} 5@end group@end smallexample@node Expressions in radtest@subsection ExpressionsAn @dfn{expression} evaluates to a value, which can be printed,assigned to a variable, used in a conditional statement or passedto a function. As in other languages, expressions in @command{radtest}include literals, variable and positional parameter dereferences,function calls and combinations of these with various operators.@menu* Arithmetic Ops::* String Ops::* A/V List Ops::* Comparison Ops::* Boolean Ops::* Conversion Between Data Types::* Function Calls::* Precedence::@end menu@node Arithmetic Ops@subsubsection Arithmetic Operations@command{Radtest} provides the common arithmetic operators, whichfollow normal precedence rules (@pxref{Precedence}), and work asyou would expect them to. The only notable exception is subtractionoperator (minus) which can be used as part of a variable or attributename, and therefore expressions like @code{$x-3} are ambiguous. Thisexpression can be thought of either as a dereference of the variable@code{x-3} (@pxref{Dereferencing Variables}), or as subtraction of the value@code{3} from the value of the variable @code{x}. @command{Radtest}always resolves this ambiguityin the favor of variable dereference.Therefore we advise you to always surround minus sign by whitespace,if it is used as a subtraction operator. So, instead of @code{$x-3},write @code{$x - 3}. For other methods of solving this ambiguity,@xref{minus-ambiguity}.This table lists the arithmetic operators in order from highestprecedence to lowest:@table @code@item - @var{x}Negation.@item + @var{x}Unary plus. This is equivalent to @code{@var{x}}. @FIXME{Should thisimply converting @var{x} to integer?}@item @var{x} * @var{y}Multiplication.@item @var{x} / @var{y}Division.@item @var{x} % @var{y}Remainder.@item @var{x} + @var{y}Addition.@item @var{x} - @var{y}Subtraction.@end tableUnary plus and minus have the same precedence, the multiplication,division and remainder all have the same precedence, and addition andsubtraction have the same precedence.If @var{x} and @var{y} are of different data types, theirvalues are first coerced to a common data type, selectedusing a set of rules (@pxref{Conversion Between Data Types}).@node String Ops@subsubsection String OperationsThere is only one string operation: concatenation. It is representedby plus sign, e.g.:@smallexample"string" + "ent" @result{} "stringent"@end smallexample@node A/V List Ops@subsubsection Operations on A/V Lists@UNREVISED{}The following operations are defined on A/V lists:@table @code@item @var{x} + @var{y}@dfn{Addition}. The @AVP{}s from @var{y} are added to @var{x}, honoringthe respective pairs additivity (@pxref{Attributes,,additivity}).For example:@smallexample( User-Name = "foo" ) + ( Password = "bar" )@result{} ( User-Name = "foo" Password = "bar" )( User-Name = "foo" Service-Type = Login-User ) + \ ( Service-Type = Framed-User Password = "bar" )@result{} ( User-Name = "foo" \ Service-Type = Framed-User \ Password = "bar" )@end smallexample@item @var{x} - @var{y}@dfn{Subtraction}. The result of this operation is an A/V listconsisting of pairs from @var{x}, which are not found in @var{y}.@smallexample( User-Name = "foo" Service-Type = Login-User ) - \( Service-Type = Framed-User )@result{} ( User-Name = "foo" )@end smallexampleNotice, that only attribute name matters, its value isignored.@FIXME{Is this correct? Is there a better way to put it?should we provide an operation that whould compare both attributenumber and its value?}@item @var{x} % @var{y}@dfn{Intersection}. The result of this operation is an @AVP{} listconsisting of pairs from @var{x} which are also present in @var{y}.@smallexample( User-Name = "foo" Service-Type = Login-User ) - \( Service-Type = Framed-User )@result{} ( Service-Type = Login-User )@end smallexample@FIXME{Same as above.}@end table@node Comparison Ops@subsubsection Comparison Operations@dfn{Comparison expressions} compare operands for relationshipssuch as equality. They return boolean values, i.e. @code{true}or @code{false}. The comparison operations are nonassociative,i.e. they cannot be used together as in:@smallexample# @emph{Wrong!}1 < $x < 2@end smallexampleUse boolean operations (@pxref{Boolean Ops}) to group comparisons together.Comparison operations can only be used in conditional expressions.This table lists all comparison operators in order from highestprecedence to lowest (notice, however, the comment after it):@table @code@item @var{x} = @var{y}True if @var{x} is equal to @var{y}. @code{C} and @code{AWK}programmers, please note @emph{single} equal sign!@item @var{x} != @var{y}True if @var{x} is not equal to @var{y}.@item @var{x} < @var{y}True if @var{x} is less than @var{y}.@item @var{x} <= @var{y}True if @var{x} is less than or equal to @var{y}.@item @var{x} > @var{y}True if @var{x} is greater than @var{y}.@item @var{x} >= @var{y}True if @var{x} is greater than or equal to @var{y}.@end tableOperators @code{=} and @code{!=} have equal precedence. Operators@code{<}, @code{<=}, @code{>}, @code{>=} have equal precedence. Most operators are defined for all @command{radtest} data types.However, only @code{=} and @code{!=} are defined for @code{avlist}s.Using any other comparison operator with @code{avlist}s produceserror.If @var{x} and @var{y} are of different data types, theirvalues are first coerced to a common data type, selectedusing a set of rules (@pxref{Conversion Between Data Types}).@node Boolean Ops@subsubsection Boolean OperationsA @dfn{boolean operation} is a combination of comparison expressions.Boolean operations can only be used in conditional expressions.This table lists all comparison operators in order from highestprecedence to lowest.@table @code@item not @var{x}@itemx ! @var{x}True if @var{x} is false.@item @var{x} and @var{y}True if both @var{x} and @var{y} are true. The subexpression @var{y}is evaluated only if @var{x} is true.@item @var{x} or @var{y}True if at least one of @var{x} or @var{y} is true. The subexpression @var{y}is evaluated only if @var{x} is false.@end table@node Conversion Between Data Types@subsubsection Conversion Between Data Types@UNREVISED{}The unary negation operand is always converted to @code{integer} type:@smallexample@group-(1 + 1) @result{} -2-(127.0.0.1 + 2) @result{} -2130706435- ("1" + "1") @result{} -11- "text" @error{} cannot convert string to integer@end group@end smallexample@noindentThe unary @code{not} operand is converted using the following rules:@enumerate 1@item If the operand is @code{integer}, no conversion is performed.@item If the operand is @code{STRNUM} (@pxref{STRNUM}) or@code{ipaddr}, it is converted to integer.@item If the operand is @code{string} (but is not @code{STRNUM}), theresult of @code{not} is @code{true} only if the operand is an emptystring.@item If the operand is @code{avl}, the result of @code{not} is@code{true} if the list is empty.@end enumerateExamples:@smallexample@groupnot 0 @result{} 1not 10 @result{} 0not "23" @result{} 0not "0" @result{} 1not "text" @result{} 0not "" @result{} 1not 127.0.0.1 @result{} 0not 0.0.0.0 @result{} 1@end group@end smallexampleWhen operands of two different data types are used in a binaryoperation, one of the operands is converted (@dfn{cast}) to anotheroperand's type according to the following rules:@enumerate 1@item If one of the operands is literal, @command{radtest} attemtpsto convert another operand to the literal data type. If this attemptfails, it goes on to rule 2.@item If one of operands is @code{STRNUM} (@pxref{STRNUM}) and another is of numericdata type (i.e. either @code{integer} or @code{ipaddr}), the latter is convertedto string representation.@item If one of the operands is @code{ipaddr} and another is@code{integer}, the latter is converted to @code{ipaddr}.@item Otherwise, if one of the operands is string, the second operandis also converted to string.@item Otherwise, the two operands are incompatible. @command{Radtest}prints appropriate diagnostics and aborts execution of the currentstatement.@end enumerate@node Function Calls@subsubsection Function CallsA @dfn{function} is a name for a particular sequence of statements. Itis defined using special definition syntax (@pxref{Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -