On 10.3.2023 6.12, Stefan Paetow (OpenSource) via radiator wrote:

Currently, we get "1<domain>", which is the 'old' (or 'correct') format for Wi-Fi networks, so I'm looking at a hook to replace the 1 with a 4 as a first step. I assume I do that in the PreClientHook or the PreProcessingHook?

I was thinking that this code would work:

sub {\
my $p = ${$_[0]}; my $oname=$p->get_attr('Operator-Name');\
$oname =~ s/1(.*)$/4\1/g; $p->change_attr('Operator-Name',$oname);\
&main::log($main::LOG_DEBUG,"Operator-Name:$oname, ");\
}

Do I have that right?

Looks good. See below for a slightly updated regexp.

You can use that hook as global PreClientHook, global ClientHook, ClientHook within a <Client ...> clause and as a PreProcessingHook within a <Handler>. They all use reference to the current request as their first argument. PreProcessingHook also gets current reply which can be ignored in this case.

I'd simplify the regexp a little if it only needs to swap a leading 1 to 4. Here's an idea of a tester:

<Client DEFAULT>
        Secret  mysecret
</Client>

<Handler>
        PreProcessingHook sub {\
             my $p = ${$_[0]}; my $oname=$p->get_attr('Operator-Name');\
             $oname =~ s/^1/4/s; $p->change_attr('Operator-Name',$oname);\
             main::log($main::LOG_DEBUG,"Operator-Name:$oname, ");\
             }
        <AuthBy INTERNAL>
                DefaultResult REJECT
        </AuthBy>
        AddToReply Reply-Message=%{Request:Operator-Name}
</Handler>



Testing with radpwtst:
% radpwtst -trace 4 -noacct Operator-Name=1operator:country

Should return a reply with the default and additional Reply-Message:


Fri Mar 10 16:28:31 2023: DEBUG: Packet dump:
*** Received from 127.0.0.1 port 1645 ....
Code:       Access-Reject
Identifier: 233
Authentic:  <243>2<235>H<17>!7<254>><15>W<0>_c}<185>
Attributes:
        Reply-Message = "Request Denied"
        Reply-Message = "4operator:country"

Rejected: Request Denied


Note that only PreClientHook runs before log level 4 packet dump. Therefore the updated Operator-Name is not visible in the log with the other hooks.

Thanks,
Heikki

--
Heikki Vatiainen
OSC, makers of Radiator
Visit radiatorsoftware.com for Radiator AAA server software
_______________________________________________
radiator mailing list
[email protected]
https://lists.open.com.au/mailman/listinfo/radiator

Reply via email to