⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radtest.texi

📁 gnu 的radius服务器很好用的
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
Definitions}). Normally a function return some value. The way touse this value in an expression is with a @dfn{function call}expression, which consists of the function name followed by acomma-separated list of @dfn{arguments} inparentheses. The arguments are expressions which provide values forthe function call environment (@pxref{Positional Parameters}. Whenthere is more than one argument, they are separated by commas.@FIXME{Actually, commas in the argument list are optional. At least,now...} If there are no arguments, write just @samp{()} after thefunction name. Here are some examples:@smallexample@groupfoo()             no argumentsbar(1)            one argumentbar(1, "string")  two arguments@end group@end smallexample@node Precedence@subsubsection Operator Precedence (How Operators Nest)@dfn{Operator precedence} determines the order of executing operators,when different operators appear close by in one expression.  For example, @code{*} has higher precedence than @code{+}; thus,@code{a + b * c} means to multiply @code{b} and @code{c}, and then add@code{a} to the product.You can overrule the precedence of the operators by usingparentheses.  You can think of the precedence rules as saying wherethe parentheses are assumed to be if you do not write parenthesesyourself. Thus the above example is equivalent to @code{a + (b * c)}.When operators of equal precedence are used together, the leftmostoperator groups first. Thus, @code{a - b + c} groups as@code{(a - b) + c}.This table lists @code{radtest} operators in order from highestprecedence to the lowest:@table @code@item $Dereference.@item (@dots{})Grouping.@item + - not !Unary plus, minus. Unary boolean negation.@item * / %Multiplication, division, modulus.@item + -Addition, subtraction.@item < <= = != > >=Relational operators.@item andLogical @samp{and}.@item orLogical @samp{or}.@end table@node Function Definitions@subsection Function DefinitionsA @dfn{function} is a name for a particular sequence of statements.The syntax for the function definition is:@smallexample@var{name}begin  @dots{}end@end smallexample@noindentwhere @var{name} is function name and @samp{@dots{}} represent anon-empty list of valid @command{radtest} statements.Notice that newline characters are obligatory after @var{name},@code{begin} and before the final @code{end} keyword.If the function accepts arguments, these can be referenced in thefunction body using @code{$@var{n}} notation (@pxref{PositionalParameters}). To return the value from the function @code{return}statement is used.For example, here is a function that computes sum of the squaresof its two arguments:@smallexample@grouphypobegin        return $1*$1 + $2*$2end@end group@end smallexample   @node Interacting with Radius Servers@subsection Interacting with Radius Servers@command{Radtest} provides two commands for interaction with remote@RADIUS{} servers.Command @code{send} sends request to the server specified in@file{raddb/client.conf}. Its syntax is:@smallexamplesend [@var{flags}] @var{port-type} @var{code} [@var{expr-or-pair-list}]@end smallexampleOptional @var{flags} can be used for fine-tuning the internals of@code{send}. You will seldom need to use these, unless you aredeveloping GNU Radius. @xref{Built-in Primitives,send}, for the detailed description of these.The first obligatory argument, @var{port-type}, specifies which@RADIUS{} port to send the request to. Specifying @samp{auth} willsend the request to the authentication port (@pxref{client.conf,auth-port});specifying @samp{acct} will send it to the accounting port(@pxref{client.conf,acct-port}).Argument @var{code} gives the request code. It is either a number ora symbolic request code name (@pxref{Numeric Values}).The last argument, @var{expr-or-pair-list} is either a@command{radtest} expression evaluating to @code{avlist} or a listof @AVP{}s. These pairs will be included in the request.Here are several examples:@smallexample# Send a @code{Status-Server} request without attributes.send auth Status-Server# Send an @code{Access-Request} with two attributessend auth Access-Request User-Name = "foo" User-Password = "bar"# Send an Accounting-Request, taking attributes from the variable# @var{attr}send acct Accounting-Request $attr@end smallexampleCommand @code{send} stores the reply code into the variable@code{REPLY_CODE} and reply pairs into the variable @code{REPLY}(@pxref{Built-in Variables}).@FIXME{How do I know if @code{send} has failed?}Another primitive is @code{expect}. @code{Expect} takes at most twoarguments: a request code (either numeric or symbolic, (@pxref{Numeric Values})) and optionallist of @AVP{}s (similar to @code{send} @var{expr-or-pair-list}argument). @code{Expect} check if these match current@code{REPLY_CODE} and @code{REPLY} values and if so, printsthe string @samp{PASS}. Otherwise, it prints @samp{FAIL}. Thiscommand is designed primarily for use in GNU Radius testsuite.@code{Expect} is usually used right after @code{send}, as shownin the example below:@smallexample@groupsend auth Access-Request User-Name = "foo" User-Password = "bar"expect Access-Accept Reply-Message = "Access allowed"@end group@end smallexample@node Conditional Statements@subsection Conditional Statements@UNREVISED{}@command{Radtest} provides two kinds of conditional statements:@code{if} and @code{case}.@subheading If statementAn @code{if} statement in its simplest form is:@smallexampleif @var{cond} @var{stmt}@end smallexample@noindentwhere @var{cond} is a conditional expression and @var{stmt} is avalid @command{radtest} statement. Optional newline may be insertedbetween @var{cond} @var{stmt}.In this form, @code{if} evaluates the condition and if it yields true,executes the statement. For example:@smallexample@groupif $REPLY[NAS-IP-Address] = 127.0.0.1   print "Request from localhost"@end group@end smallexampleMore complex form of this statement allows to select between the twostatements:@smallexample@groupif @var{cond} @var{stmt-1} else @var{stmt-2} @end group@end smallexample@noindentHere, @var{stmt-1} will be executed if @var{cond} evaluates to true,and @var{stmt-2} will be executed if @var{cond} evaluates to false.Notice, that an optional newline is allowed between @var{cond} and@var{stmt-1} and right after @code{else} keyword. However, a newlinebefore @code{else} constitutes an error.If several statements should be executed in a branch of the @code{if}statement, use compound statement as in the example below:@smallexample@groupif $REPLY_CODE != Accounting-Responsebegin  print "Accounting failed.\n"  exit 1        end else  print "Accounting succeeded.\n"@end group@end smallexample@code{If} statements can be nested to any depth.@subheading Case statement@code{Case} statement allows select a statement based on whethera @code{string} expression matches given regular expression. Thesyntax of @code{case} statement is:@smallexample@groupcase @var{expr} in@var{expr-1} ) @var{stmt-1}@var{expr-2} ) @var{stmt-2}@dots{}@var{expr-n} ) @var{stmt-n}end@end group@end smallexample@noindentwhere @var{expr} is a control expression, @var{expr-1}, @var{expr-2}etc. are expressions evaluating to @emph{extended} POSIX regularexpressions (for the detailed description of these@pxref{Top,,Regular Expression Library,regex,Regular ExpressionLibrary}).@code{Case} statement first evaluates @var{expr} and converts it to@code{string} data type. Then it evaluates each @var{expr-n} in turnand tests if the resulting regular expression matches @var{expr}. Ifso, the statement @var{stmt-n} is executed and the execution of@code{case} statement finishes.The following example illustrates the concept:@smallexample@groupcase $COMMAND in"auth.*")       authenticate($LIST, no)"acct")         authenticate($LIST, yes)".*")           begin                  print "Unknown command."                  exit 1                endend@end group@end smallexample@code{Bourne shell} programmers should notice that:@itemize @bullet@item @code{Case} statement ends with @code{end}, not @code{esac}.@item There is no need to put @code{;;} at the end of each branch,@item Boolean operations are not allowed in @var{expr-n}.@end itemize@node Loops@subsection Loops@UNREVISEDTwo looping constructs are provided: @code{while} and@code{do...while}.@subheading While loopThe syntax of a while loop is:@smallexample@groupwhile @var{cond}  @var{stmt}@end group@end smallexample Newline after @var{cond} is obligatory.@subheading Do...while loop@smallexample@groupdo  @var{stmt}while @var{cond}@end group@end smallexample  As usual @code{do...while} loop differs from its @code{while}counterpart in that its @var{stmt} is executed at least once.The looping constructs can be nested to any depth.Two special statements are provided for branching within loopconstructs. These are @code{break} and @code{continue}.@code{Break} statement stops the execution of the currentloop statement and passes control to the statement immediatelyfollowing it@smallexample@groupwhile $x < 10begin  if $x < $y     break  @dots{}  x = $x + 1endprint "OK\n"@end group@end smallexample@noindentIn the example above, execution of @code{break} statement passescontrol to @code{print} statement.@code{Break} may also take an argument: a literal number representingthe number of nested loop statements to break from. For example, the@code{break} statement in the sample code below will exit from theoutermost @code{while}:@smallexample@groupwhile $y < 10begin  while $x < 10  begin    if $x < $y       break 2    @dots{}    x = $x + 1   end  @dots{}  y = $y + 1 end  print "OK\n"@end group@end smallexample@code{Continue} statement passes control to the condition of thecurrent looping construct. When used with a numeric argument, thelatter specifies the number of the nesting looping construct topass control to (as with @code{break}, the innermost loop isconsidered to have number 1, so @code{continue} is equivalentto @code{continue 1}).@node Built-in Primitives@subsection Built-in Primitives@deffn {Radtest built-in} getopt @var{optstring} [@var{opt} [@var{arg} [@var{ind}]]]@code{Getopt} is used to break up command line options forsubsequent parsing.The only mandatory argument, @var{optstring} is a list of short(one-character) options to be recognized. Each short option characterin @var{optstring} may be followed by one colon to indicate it has arequired argument, and by two colons to indicate it has an optionalargument.@FIXME{Document starting @samp{+} and @samp{-} chars.}Each subsequent invocation of @code{getopt} processes next commandline argument. @code{Getopt} returns true if the argument is anoption and returns false otherwise. It stores the retrieved option(always with a leading dash) in the variable @var{opt} (@code{OPTVAR}by default). If the option has an argument, the latter is storedin the variable @var{arg} (@code{OPTARG} by default). Index of thenext command line argument to be processed is preserved in thevariable @var{ind} (@code{OPTIND} by default).The usual way of processing command line options is by invoking@code{getopt} in a condition expression of @code{while} loop andanalyzing its return values within the loop. For example:@smallexample@groupwhile getopt "hf:"case $OPTVAR in"-h")  print "Got -h option\n""-f")  print "Got -f option. Argument is " $OPTARG "\n"".*")  begin          print "Unknown option: " $OPTVAR "\n"          exit 1       end  endend@end group@end smallexample@end deffn@deffn {Radtest statement} input [@var{expr} @var{name}]Evaluates @var{expr} and prints its result on standard output. Thenreads a line from standard input and assigns it to the variable@var{name}.If @var{expr} is given, @var{name} must also be present.If @var{name} is not given, variable @var{INPUT} is used by default.@end deffn@deffn {Radtest statement} set @var{options}Sets @command{radtest} command line options. @var{Options} shouldbe a valid @command{radtest} command line (@pxref{Invoking radtest}).@end deffn@deffn {Radtest statement} shift [@var{expr}]Shift positional parameters left by one, so that @code{$2} becomes@code{$1}, @code{$3} becomes @code{$2} etc. @code{$#} is decremented.@code{$0} is not affected.If @var{expr} is given, it is evaluated, converted to integer andused as shift value. Thus @code{shift 2} shifts all positionalparameters left by 2.@end deffn@deffn {Radtest statement} return [@var{expr}]Returns from the current function (@pxref{Function Definitions}). If@var{expr} is present, it is evaluated and the value thus obtainedbecomes the function return value.It is an error to use @code{return} outside of a function definition.@end deffn@deffn {Radtest statement} break [@var{n}]Exit from within a loop.If @var{n} is specified, break from @var{number}levels. @var{n} must be >= 1. If @var{n} is greater thanthe number of enclosing loops, an error message is issued.@xref{Loops}, for the detailed discussion of the subject.@end deffn@deffn {Radtest statement} continue [@var{n}]Resume the next iteration of the enclosing loop. If @var{n}is specified, resume at the @var{n}th enclosing loop. @var{n} must be>= 1. If @var{n} is greater than the number of enclosing loops, anerror message is issued.@xref{Loops}, for the detailed discussion of the subject.@end deffn@deffn {Radtest statement} exit [@var{expr}]Exit to the shell. If @var{expr} is specified, it is evaluated andused as exit code. Otherwise, 0 is returned to the shell.@end deffn@deffn {Radtest statement} print @var{expr-list}Evaluate and print expressions. @var{Expr-list} is whitespace orcomma-separated list of expressions. Each expression is evaluatedin turn and printed to the standard output.@end deffn@deffn {Radtest statement} send [@var{flags}] @var{port-type} @var{code} @var{expr-or-pair-list}Send a request to the @RADIUS{} server and wait for the reply. Storesreply code in the variable @code{REPLY_CODE} and reply @AVP{}s inthe variable @code{REPLY} (@pxref{Interacting with Radius Servers}).@anchor{send-flags}@var{flags} are a whitespace-separated list of variableassignments. Following variables are understood:@table @code@item repeat=@var{n}Unconditionally resend the request @var{n} times.@item id=@var{n}Specify the request ID.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -