3.27.11. PostAuthHook Previous topic Parent topic Child topic Next topic

This optional parameter allows you to define a Perl function that is called during packet processing. PostAuthHook is called for each request after it has been passed to all the AuthBy clauses. A reference to the current request is passed as the first argument, and a reference to the reply packet currently being constructed is passed as the second argument. The third argument is a reference to the result of the authentication ($main::ACCEPT, $main::REJECT and so on). The fourth argument is a reference to a string variable holding the reason for a reject, or undefined if none is available. To change the type of reply, set the reference to third argument.
The hook code is compiled by Perl when Radiator starts up. Compilation errors in your hook code are reported to the log file at start-up time. Runtime errors in your hook are also reported to the log file when your hook is executed. Multiline hooks, with trailing backslashes (\), are parsed by Radiator into a one long line. Therefore do not use trailing comments in your hook.
PostAuthHook can be an arbitrarily complicated Perl function, that might run external processes, consult databases, change the contents of the current request or many other things.
# Add some reply attributes to the reply message
# if it is a REJECT and there is 1 or fewer there already
PostAuthHook sub { ${$_[1]}->add_attr('test-attr', \
      'test-value') \
      if ${$_[2]} == $main::REJECT \
      && ${$_[1]}->attr_count() <= 1; }