📄 extensions.texi
字号:
@end deftypefn@deftypefn Function string request_code_string (integer @var{code})Converts integer RADIUS request code to its textual representation asper RFC 3575. This function is useful in logging hooks (@pxref{hooks}).@smallexamplerequest_code_string(4) @result{} "Accounting-Request"@end smallexample@end deftypefn@subheading Native Language SupportThe native language support is provided via the functions describedbelow. These functions are interfaces to GNU @code{gettext} library.For the information about general concepts and principles ofNative Language Support, please refer to@ref{Top,GNU @code{gettext} utilities,gettext,gettext,GNU @code{gettext} utilities}.The default current textual domain is @samp{radius}.@deftypefn Function string textdomain (string @var{domain})Sets the new value for the current textual domain. This domain is used bythe functions @code{gettext} and @code{ngettext}.Returns the name of the previously used domain. @end deftypefn@deftypefn Function string gettext (string @var{msgid})@deftypefnx Function string _ (string @var{msgid})The function returns the translation of the string @var{msgid} if itis available in the current domain. If it is not available, theargument itself is returned.The second form of this function provides a traditional shortcutnotation.For a detailed description of the GNU @code{gettext} interface, refer to @ref{Interface to gettext,,,gettext,GNU @code{gettext} utilities}.@end deftypefn@deftypefn Function string dgettext (string @var{domain}, string @var{msgid})Returns the translation of the string @var{msgid} if itis available in the domain @var{domain}. If it is not available, theargument itself is returned.@end deftypefn@deftypefn Function string ngettext (string @var{msgid_singular}, string @var{msgid_plural}, integer @var{number})The @code{ngettext} function is used to translate the messages thathave singular and plural forms. The @var{msgid_singular} parametermust contain the singular form of the string to be converted. It isalso used as the key for the search in the catalog. The@code{msgid_plural} parameter is the plural form. The parameter@var{number} is used to determine the plural form. If no messagecatalog is found @var{msgid_singular} is returned if@code{@var{number} == 1}, otherwise @var{msgid_plural}.For a detailed description of the GNU @code{gettext} interface for theplural translation, refer to @ref{Plural forms,,Additional functions for plural forms,gettext,GNU @code{gettext} utilities}.@end deftypefn@deftypefn Function string dngettext (string @var{domain}, string @var{msg_sing}, string @var{msg_plur}, integer @var{number})Similar to @code{ngettext}, but searches translation in the given @var{domain}.@end deftypefn@subheading Request AccessorsThe following functions are used to read some internal fields of a@RADIUS{} request.@deftypefn Function Integer request_source_ip ()Returns source @IP{} of the currently processed request. This functioncan be used to add @attr{NAS-IP-Address} attribute to the requestslacking one, e.g.:@smallexampleintegerrestore_nas_ip()@{ if (!*%[NAS-IP-Address]) %[NAS-IP-Address] = request_source_ip(); return 0;@}@end smallexample@end deftypefn@deftypefn Function Integer request_source_port ()Returns the source @sc{udp} port.@end deftypefn@deftypefn Function Integer request_id ()Returns the request identifier.@end deftypefn@deftypefn Function Integer request_code ()Returns the request code.@end deftypefn@comment *L1****************************************************************@node Guile@section Guile@cindex GuileThe name Guile stands for @dfn{GNU's Ubiquitous Intelligent Language forExtensions}. It provides a Scheme interpreter conforming to the R4RSlanguage specification. This section describes use of Guile as anextension language for GNU Radius. It assumes that the reader issufficiently familiar with the Scheme language. For information aboutthe language, refer to@ref{Top,,,r4rs,Revised(4) Report on the Algorithmic Language Scheme}.For more information about Guile, see @ref{Top,,Overview,guile,The Guile Reference Manual}.Scheme procedures can be called for processing both authenticationand accounting requests. The invocation of a Scheme procedure for anauthentication request is triggered by the @attr{Scheme-Procedure}attribute; the invocation for an accounting request is triggeredby the @attr{Scheme-Acct-Procedure} attribute. The following sectionsaddress these issues in more detail.@menu* Data Representation::* Authentication with Scheme::* Accounting with Scheme::* Radius-Specific Functions::@end menu@comment **L2***************************************************************@node Data Representation@subsection Data Representation@cindex Guile, representation of Radius data@AVP{} lists are the main object Scheme functions operate upon. Schemeis extremely convenient for representation of such objects. A Radius @AVP{}is represented by a Scheme pair; e.g.,@smallexample Session-Timeout = 10@end smallexample@noindentis represented in Guile as@smalllisp (cons "Session-Timeout" 10)@end smalllispThe @code{car} of the pair can contain either the attribute dictionaryname or the attribute number. Thus, the above pair may also bewritten in Scheme as@smalllisp (cons 27 10)@end smalllisp@noindent(because @attr{Session-Timeout} corresponds to attribute number 27).Lists of @AVP{}s are represented by Scheme lists. For example,the Radius pair list@smallexample@group User-Name = "jsmith", User-Password = "guessme", NAS-IP-Address = 10.10.10.1, NAS-Port-Id = 10@end group@end smallexample@noindentis written in Scheme as@smalllisp@group (list (cons "User-Name" "jsmith") (cons "User-Password" "guessme") (cons "NAS-IP-Address" "10.10.10.1") (cons "NAS-Port-Id" 10))@end group@end smalllisp @comment **L2***************************************************************@node Authentication with Scheme@subsection Authentication with Scheme@cindex Authentication with SchemeThe Scheme procedure used for authentication must be declared asfollows:@deffn {Function Template} auth-function request-list check-list reply-listIts arguments are:@table @var@item request-listThe list of @AVP{}s from the incoming request@item check-listThe list of @AVP{}s from the @LHS{} of the profile entry that matchedthe request@item reply-listThe list of @AVP{}s from the @RHS{} of the profile entry that matchedthe request@end table@end deffnThe function return value determines whether the authentication willsucceed. The function must return either a boolean value or a pair.The return of @code{#t} causes authentication to succeed. The returnof @code{#f} causes it to fail.For a function to add something to the reply @AVP{}s, itshould return a pair in the form@smalllisp (cons @var{return-code} @var{list})@end smalllisp@noindentwhere @var{return-code} is a boolean value of the same meaning asdescribed above. @var{list} is a list of @AVP{}s to be addedto the reply list. For example, the following function will alwaysdeny the authentication, returning an appropriate message to the user:@exindex Scheme authentication function@smalllisp@group(define (decline-auth request-list check-list reply-list) (cons #f (list (cons "Reply-Message" "\r\nSorry, you are not allowed to log in\r\n"))))@end group@end smalllispAs a more constructive example, let's consider a function thatallows the authentication only if a user name is found in itsinternal database:@smalllisp@group(define staff-data (list (list "scheme" (cons (list (cons "NAS-IP-Address" "127.0.0.1")) (list (cons "Framed-MTU" "8096"))) (cons '() (list (cons "Framed-MTU" "256")))))) (define (auth req check reply) (let* ((username (assoc "User-Name" req)) (reqlist (assoc username req)) (reply-list '())) (if username (let ((user-data (assoc (cdr username) staff-data))) (rad-log L_INFO (format #f "~A" user-data)) (if user-data (call-with-current-continuation (lambda (xx) (for-each (lambda (pair) (cond ((avl-match? req (car pair)) (set! reply-list (avl-merge reply-list (cdr pair))) (xx #t)))) (cdr user-data)) #f))))) (cons #t reply-list)))@end group@end smalllispTo trigger the invocation of the Scheme authentication function, assignits name to the @attr{Scheme-Procedure} attribute in the @RHS{} of acorresponding @file{raddb/users} profile. For example:@exindex Invoking Scheme authentication function@exindex Scheme authentication function, invocation@smallexample@groupDEFAULT Auth-Type = SQL Scheme-Procedure = "auth"@end group@end smallexample@comment **L2***************************************************************@node Accounting with Scheme@subsection Accounting with Scheme@cindex Accounting with SchemeThe Scheme accounting procedure must be declared as follows:@deffn {Function Template} acct-function-name request-listIts argument is:@table @var@item request-listThe list of @AVP{}s from the incoming request@end table@end deffnThe function must return a boolean value. The accounting succeeds onlyif it has returned @code{#t}.Here is an example of a Scheme accounting function. The function dumpsthe contents of the incoming request to a file:@exindex Scheme accounting function@smalllisp@group(define radius-acct-file "/var/log/acct/radius")(define (acct req) (call-with-output-file radius-acct-file (lambda (port) (for-each (lambda (pair) (display (car pair) port) (display "=" port) (display (cdr pair) port) (newline port)) req) (newline port))) #t)@end group@end smalllisp@comment **L2***************************************************************@node Radius-Specific Functions@subsection Radius-Specific Functions@cindex Radius-Specific Scheme Functions@deffn {Scheme Function} avl-delete av-list attrDelete from @var{av-list} the pairs with attribute @var{attr}.@end deffn@deffn {Scheme Function} avl-merge dst srcMerge @var{src} into @var{dst}.@end deffn@deffn {Scheme Function} avl-match? target listReturn @code{#t} if all pairs from @var{list} are present in @var{target}.@end deffn@deffn {Scheme Function} rad-dict-name->attr nameReturn a dictionary entry for the given attribute @var{name} or @code{#f} ifno such name was found in the dictionary.A dictionary entry is a list in the form@deffn {Scheme List} dict-entry name-string attr-number type-number vendor@noindentwhere the arguments are as follows:@table @var@item name-stringThe attribute name@item value-numberThe attribute number@item type-numberThe attribute type@item vendorThe vendor @acronym{PEC}, if the attribute is a vendor-specific one,or @code{#f} otherwise.@end table@end deffn@end deffn@deffn {Scheme Function} rad-dict-value->name attr valueReturns the dictionary name of the given @var{value} for an integer-typeattribute @var{attr}, which can be either an attribute numberor its dictionary name.@end deffn@deffn {Scheme Function} rad-dict-name->value attr valueConvert a symbolic attribute value name into its integer representation.@end deffn@deffn {Scheme Function} rad-dict-pec->vendor pecConvert a @acronym{PEC} to the vendor name.@end deffn@deffn {Scheme Function} rad-log-open prioOpen Radius logging to the severity level @var{prio}.@end deffn@deffn {Scheme Function} rad-log-closeClose a Radius logging channel opened by a previous call to @code{rad-log-open}.@end deffn@deffn {Scheme Function} rad-rewrite-execute-string stringInterpret @var{string} as an invocation of a function in Rewrite language andexecute it.Return value: return of the corresponding Rewrite call, translated tothe Scheme data type.@end deffn@deffn {Scheme Function} rad-rewrite-execute arglistExecute a Rewrite language function.@code{(car @var{arglist})} is interpreted as a name of the Rewritefunction to execute, and @code{(cdr @var{arglist})} as a list ofarguments to be passed to it.Return value: return of the corresponding Rewrite call, translated tothe Scheme data type.@end deffn@deffn {Scheme Function} rad-openlog ident option facilityScheme interface to the system @code{openlog()} call.@end deffn@deffn {Scheme Function} rad-syslog prio textScheme interface to the system @code{syslog()} call.@end deffn@deffn {Scheme Function} rad-closelogScheme interface to the system @code{closelog()} call.@end deffn@deffn {Scheme Function} rad-utmp-putent status delay list radutmp_file radwtmp_fileWrite the supplied data into the radutmp file. If @var{radwtmp_file} is not nil,the constructed entry is also appended to @var{wtmp_file}.@var{list} is:@deffn {Scheme List} utmp-entry user-name orig-name port-id port-type session-id caller-id framed-ip nas-ip proto@table @var@item user-nameThe user name@item orig-nameThe original user name from the request@item port-idThe value of the @attr{NAS-Port-Id} attribute@item port-typeA number or character indicating the port type@item session-idThe session @sc{id}@item caller-idThe value of the @attr{Calling-Station-Id} attribute from the request@item framed-ipThe framed IP assigned to the user@item nas-ipThe @NAS{} IP@item protoA number or character indicating the type of the connection@end table@end deffn@end deffn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -