📄 radtest.texi
字号:
@c This is part of the Radius manual.@c Copyright (C) 2004 Free Software Foundation, Inc.@c Written by Sergey Poznyakoff@c See file radius.texi for copying conditions.@comment *******************************************************************@node radtest@section radtest@pindex radtest@command{Radtest} is a radius client shell, providing a simple andconvenient language for sending requests to @RADIUS{} servers andanalyzing their reply packets.@menu* Invoking radtest::* Literal Values::* Reserved Keywords::* Variables in radtest::* Positional Parameters::* Expressions in radtest::* Function Definitions::* Interacting with Radius Servers::* Conditional Statements::* Loops::* Built-in Primitives::* Sample Radtest Program::@end menu@node Invoking radtest@subsection Invoking radtest@UNREVISED{}@table @option@item -a @var{variable}=@var{value}@itemx --assign=@var{variable}=@var{value}Assign a @var{value} to @var{variable}. @xref{Assignment Options}, fora detailed discussion.@item -f @var{file}@itemx --file=@var{file}Read input from @var{file}. Stops further processing of the command line.@item -i@itemx --no-interactiveDisable interactive mode.@item -n@itemx --dry-runCheck the input file syntax and exit.@item -q@itemx --quickDo not read the configuration file.@FIXME{}@item -r @var{number}@itemx --retry=@var{number}Set number of retries.@item -s @var{server}@itemx --server=@var{server}Set radius server parameters.@item -t @var{number}@itemx --timeout=@var{number}Set timeout@item -v@itemx --verboseVerbose mode@item -x @var{debugspec}@item --debug=@var{debugspec}Set debugging level@item -d @var{dir}@itemx --directory @var{dir}Specify alternate configuration directory. Default is @file{@value{RADDB}}.@item -L@itemx --licensePrint license and exit.@item -?@itemx --helpPrint short usage summary@item --usagePrint even shorter usage summary.@item -V@itemx --versionPrint program version.@end table@node Literal Values@subsection Literal ValuesThere are four basic data types in @command{radtest} language: @code{integer},@code{ipaddr}, @code{string} and @code{avlist}.@menu* Numeric Values:: Integers and IP addresses.* Strings:: Character Strings.* Avlists:: Lists of A/V pairs.@end menu@node Numeric Values@subsubsection Numeric Values@dfn{Integer} means a signed integer value in the range-2147483648..2147483647.@dfn{Ipaddr} is an unsigned integer value suitable for representing@sc{ip}v4 addresses. These can be input either as decimal numbers oras @IP{}s in usual ``dotted-quad'' notation.As a convenience measure, @RADIUS{} request code names can be usedin integer context. The following table lists currently definedrequest names with their integer codes:@multitable @columnfractions .40 .20@item Access-Request @tab 1@item Access-Accept @tab 2 @item Access-Reject @tab 3@item Accounting-Request @tab 4@item Accounting-Response @tab 5@item Accounting-Status @tab 6@item Password-Request @tab 7@item Password-Ack @tab 8@item Password-Reject @tab 9@item Accounting-Message @tab 10@item Access-Challenge @tab 11@item Status-Server @tab 12@item Status-Client @tab 13 @item Ascend-Terminate-Session @tab 31@item Ascend-Event-Request @tab 33@item Ascend-Event-Response @tab 34@item Ascend-Allocate-IP @tab 51@item Ascend-Release-IP @tab 52@end multitable @node Strings@subsubsection Character Strings@dfn{String} is an arbitrary string of characters. Any input tokenconsisting of letters of Latin alphabet, decimal digits, underscoresdashes and dots and starting with a Latin alphabet letter orunderscores is considered a string. To input strings containing otherletters, surround them by double quotes. The following are valid strings:@smallexample@groupA-string"String, containing white space"@end group@end smallexampleThe double quote character @samp{"} must be preceeded by a backslash@samp{\} if it is part of a string:@smallexample"Always quote \" character"@end smallexampleGenerally speaking, @samp{\} is an @dfn{escape character}, thatalters the meaning of the immediately following character. If it islocated at the end of the line, it allows to input newlinecharacter to strings:@smallexample@group"This string contains a \newline character."@end group@end smallexampleOther special escape sequences are:@table @asis@item \aAudible bell character (ASCII 7)@item \bBackspace (ASCII 8)@item \eEscape character (ASCII 27)@item \fForm feed (ASCII 12)@item \nNewline (ASCII 10)@item \rCarriage return (ASCII 13)@item \tHorizontal tab (ASCII 9)@item \\Backslash@item \ooo(@samp{o} represents an octal digit)A character whose ASCII value is represented by the octal number @samp{ooo}.@item \xHH@itemx \XHH(@samp{H} represents a hex digit)A character whose ASCII value is represented by the hex number @samp{HH}.@end tableIf the character following the backslash is not one of thosespecified, the backslash is ignored.@anchor{STRNUM}An important variant of @code{string} is a @dfn{numeric string},or @dfn{STRNUM} for short. A numeric string is a string thatcan be converted to a number, for example @code{"+2"}. This conceptis used for type conversion between @code{integer} and @code{string}values.Another way to represent strings is using @dfn{here document} syntax.Its format is as follows:@smallexample@group<<[-]@var{delimiter} @var{text}@var{delimiter}@end group@end smallexample@noindent@var{Delimiter} is any word you choose to delimit the text, @var{text}represent the text of the string. If @var{delimiter} is prepended by adash, any leading tabulation characters will be removed from @var{text}. Thisallows for natural indentation of @samp{here document} constructs.The @samp{here document} construct is especially useful to represent stringscontaining embedded newlines, as shown in the example below:@smallexample@groupprint <<EOTusage: foo [OPTIONS] [NAME...]OPTIONS are: -h Print this help list.EOT@end group@end smallexample @node Avlists@subsubsection Lists of A/V pairs@dfn{Avlist} are whitespace or comma-separated lists of@RADIUS{} attribute-value pairs. A syntax for @AVP{} is@example@var{name} @var{op} @var{value}@end example@noindentwhere @var{name} is attribute name, @var{op} is a comparisonoperator (@samp{=}, @samp{!=}, @samp{<}, @samp{<=}, @samp{>},@samp{>=}), and @var{value} is any valid @command{radtest} dataor expression.An @AVP{} list must be enclosed in parentheses. This is anexample of an @AVP{} list consisting of two pairs:@smallexample@group( User-Name = "test" NAS-IP-Address = 10.10.10.1 )@end group@end smallexample@noindentAn empty pair list is represented by a pair of parentheses: @code{()}.@node Reserved Keywords@subsection Reserved KeywordsThe following keywords are reserved in @command{radtest}:@smallexample@groupacct, and, auth, begin, break, case, continue, do, else, end, exit, expect, getopt, if, in, input, not, or, print, return, send, set, shift, while @end group@end smallexampleThe reserved keywords may be used as variable names, provided thatthe following requrements are met:@itemize @bullet@item In assignment, these names are quoted using single quotes.@smallexample'case' = 1@end smallexample@item When dereferencing, the use of curly braces is obligatory:@smallexample$@{case@} + 2@end smallexample@end itemize@node Variables in radtest@subsection VariablesVariables are means of storing data values at one point of yourprogram for using them in another parts of it. Variables can beassigned either in the program itself, or from the @command{radtest}command line.@menu* Using Variables::* Variable Assignments::* Dereferencing Variables::* Accessing Elements of A/V Pair Lists::* Assignment Options::* Built-in Variables::@end menu@node Using Variables@subsubsection Using VariablesThe name of a variable must be a sequence of letters, digits,underscores and dashes, but it may not begin with a digit or dash. Notice,that in contrast to the majority of programming languages, use ofdashes (minus signs) is allowed in user names. This is becausetraditionally @RADIUS{} attribute names contain dashes, soextending this practice to variable names makes @code{radtest}programs more consistent. On the other hand, this means that youshould be careful when using minus sign as a subtractionoperator (@pxref{minus-ambiguity}). Case is significant in variable names:@code{a} and @code{A} are different variables. A name of a variable may coincide with one of @code{radtest} reservedkeywords. @xref{Reserved Keywords}, for description on how to use suchvariables.A few variables have special built-in meanings (@pxref{Built-in Variables}). Suchvariables can be assigned and accessed just as any other ones. Allbuilt-in variables names are entirely upper-case.Variables are never declared, they spring into existence whenan assignment is made to them. The type of a variable is determinedby the type of the value assigned to it. @node Variable Assignments@subsubsection Variable AssignmentsAn @dfn{assignment} stores a new value into a variable. It's syntaxis quite straightforward:@smallexample@var{variable} = @var{expression}@end smallexample@noindentAs a result of the assignment, the @var{expression} is evaluated andits value is assigned to @var{variable}. If @var{variable} did notexist before the assignment, it is created. Otherwise, whatever oldvalue it had before the assignment is forgotten.It is important to notice that variables do @emph{not} havepermanent types. The type of a variable is the type of whatevervalue it currently holds. For example:@smallexample@groupfoo = 1print $foo @result{} 1foo = "bar"print $foo @result{} barfoo = ( User-Name = "antonius" NAS-IP-Address = 127.0.0.1 )print $foo @result{} ( User-Name = "antonius" NAS-IP-Address = 127.0.0.1 )@end group@end smallexampleAnother important point is that in @command{radtest}, assignment isnot an expression, as it is in many other programming languages. So@code{C} programmers should resist temptation to use assignments inexpressions. The following is @emph{not} correct:@smallexamplex = y = 1@end smallexampleFinally, if the variable name coincides with one of @command{radtest}keywords, it must be enclosed in single quotes:@smallexample'case' = 1@end smallexample@node Dereferencing Variables@subsubsection Dereferencing Variables@dfn{Dereferencing} a variable means accessing its value. Thesimplest form of dereferencing is by prepending a dollar signto the variable name:@smallexample@groupfoo = 1print foo @result{} fooprint $foo @result{} 1@end group@end smallexample@noindentNotice, that in the example above, the first @code{print} statementunderstands @code{foo} as a literal string, whereas the second oneprints the value of the variable.Dereferencing an undefined variable produces error message:@smallexampleprint $x @error{} variable `x' used before definition@end smallexampleOptionally, the variable name may be surrounded by curly braces.Both @code{$foo} and @code{$@{foo@}} are equivalent. The use ofthe latter form is obligatory only when the variable name coincideswith one of the reserved keywords (@pxref{Reserved Keywords}).@anchor{minus-ambiguity}It also can be used to resolve ambiguity between using dash asa part of user name and as a subtraction operator:@smallexample@grouplong-name = 2$long-name @result{} 2$long-name-1 @error{} variable `long-name-1' used before definition$@{long-name@}-1 @result{} 1$long-name - 1 @result{} 1@end group@end smallexampleWe recommend to always surround @samp{-} with whitespace when it isused as arithmetic operator.The @code{$@{@}} notation also permits some operations similar toshell variable substitution.@table @asis@item $@{variable:-text@}Use default values. If @var{variable} is unset, return @var{text},otherwise return the value of the @var{variable}.@smallexample@group$x @error{} variable `x' used before definition$@{x:-1@} @result{} 1x = 2$@{x:-1@} @result{} 2@end group@end smallexample@item $@{variable:=text@}Assign default values. If @var{variable} is unset, @var{text} isassigned to it. The expression always returns the value of thevariable.@smallexample@group$x @error{} variable `x' used before definition$@{x:=1@} @result{} 1$x @result{} 1@end group@end smallexample@item $@{variable:?text@}Display error if unset. If @var{variable} is unset, @var{text} iswritten to the standard error (if @var{text} is empty, the defaultdiagnostic message is used) and further execution of the program isaborted. Otherwise, the value of @var{variable}is returned. @smallexample@group$x @error{} variable `x' used before definition$@{x:?@} @error{} x: variable unset$@{x:?foobar@} @error{} foobar@end group@end smallexample@item $@{variable::text@}Prompt for the value if unset. If @var{variable} is unset,@command{radtest} prints @var{text} (or a default message, if itis empty), reads the standard input up to the newline characterand returns the value read. Otherwise, the value of the variableis returned. This notation provides a convenient way for askinguser to supply default values.@smallexample@group
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -