[RADIATOR] Define a global array

Steve Phillips steve at focb.co.nz
Tue Apr 1 19:56:08 CDT 2014


Hey Hugh,

Yep, had a look through there but can't see how you'd use this to set an 
array variable, or would &main::setVariable allow you to set a complex 
variable (a hashed array for example) as opposed to a simple singular 
variable?

I've sort of got this working to set a value based on what was listed in 
the hooks.txt and fudging something together using a loop, the keys 
directive and setting a prefix to the key so I end up with

&main::setVariable(global_steve.message1,"value")
&main::setVariable(global_steve.message2,"value2")

And then referencing it with

my $string = "Test: " . &main::getVariable('global_steve.'.$myMessage);

(which doesn't work :-( )

(I'm trying to do &main::log($main::LOG_INFO, 
&main::getVariable($blerg)); where $blerg is defined as;

my $blerg = "global_steve.$someAttribute";

and $someAttribute is either message1 or message2

)

I'm also picking that &main::setVariable(global_steve{message1}) isn't 
going to work either, but I guess I'll try that next.

Is there any way at all to get a hashed array available globally?

Of interest, when I set the variable in the first hook as follows

foreach my $key (keys %columns) {

   &main::log($main::LOG_DEBUG,"setVariable $varName.$key = 
$columns{$key}");
   &main::setVariable($varName.$key, $columns{$key});
   &main::log($main::LOG_DEBUG,&main::setVariable($varName.$key, 
$columns{$key}));

}

It seems to print out to the logs the expected values, but when I use 
the exact same &main::log line in the PreHandler hook it doesn't, it's 
almost as if it's forgotten the variable set in the previous startup hook?

-- 
Steve.



On 2/04/2014 11:24 am, Hugh Irvine wrote:
>
> Hello Steve -
>
> What you describe makes perfect sense - and this is exactly what globals are for.
>
> See the hooks in “goodies/hooks.txt” for lots of examples.
>
> regards
>
> Hugh
>
>
> On 2 Apr 2014, at 10:59, Steve Phillips <steve at focb.co.nz> wrote:
>
>> Hi there,
>>
>> I am trying to setup a system that, on startup reads a DB table into a
>> hashed array and then makes this available to the rest of the hooks. A
>> later hook then takes this hashed array and parses it to add a value to
>> a custom attribute which is then used for later processing within a handler.
>>
>> While I understand that globals are bad and should never be used, I
>> believe that making a DB request on every radius packet would have more
>> of an impact on performance for something that rarely changes (maybe
>> once a week or so) and so the positives outweigh the negatives.
>>
>> What I had which doesn't seem to work was something along these lines.
>>
>> <from radius.cfg>
>>
>> # Hooks
>> StartupHook file:"%D/hooks/StartupHook-SetupGlobals.pl"
>>
>> .
>> .
>> <Client>
>>    Secret blah
>>    PreHandlerHook file:"$D/hooks/AddAttribute.pl"
>> </Client>
>>
>> <Handler MyAtttribute = /something/>
>> .
>>   Do Stuff
>> </Handler>
>>
>> in the SetupGlobals file I have something like;
>>
>> # Define a global (obviously, there is where I'd read in the DB table)
>> our %global_steve = (
>>    'message1' => 'Steve was here',
>>    'message2' => 'woot'
>> );
>>
>> and then, when trying to reference it I have in the PreHandler hook
>>
>> sub {
>>    &main::log($main::LOG_INFO, "Test: $main::global_steve{'messsage1'}");
>> }
>>
>> Which ends up printing out a blank.
>>
>> Does anyone know of either, a way to get this going, or a way to read in
>> a db table of data and cache it for use in later hooks without having
>> each radius request generate another database call?
>>
>> Thanks in advance,
>>
>> --
>> Steve.
>>
>>
>> _______________________________________________
>> radiator mailing list
>> radiator at open.com.au
>> http://www.open.com.au/mailman/listinfo/radiator
>
>
> --
>
> Hugh Irvine
> hugh at open.com.au
>
> Radiator: the most portable, flexible and configurable RADIUS server
> anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald,
> Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS,
> TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP,
> DIAMETER etc.
> Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
>



More information about the radiator mailing list