[RADIATOR] Getting attributes in hooks

Heikki Vatiainen hvn at open.com.au
Tue Aug 20 09:48:52 UTC 2019

On 16/08/2019 23.10, David Rose wrote:

> For example I found these for getting user names:
> - $p->getUserName
> - $p->get_attr('User-Name')
> - $p->getAttrByNum($Radius::Radius::USER_NAME)
> All seem to be capable of doing the same thing. Even in our hooks there 
> are differences in which is used and I would prefer to change this so 
> that our hooks are at least consistent (unless there is reason not to do 
> so).

For user name, I recommend using getUserName just as Frank suggested. 
User-Name is often rewritten and modified and thus has its own helper 
function. Related functions are getOriginalUserName and changeUserName. 
If you need to update User-Name, changeUserName should be used.

> Are there reasons to use one over the other? For example, do some have 
> better performance or take up fewer resources? Perhaps there are 
> specific use cases when one should be used over another? Or maybe some 
> are decprecated and should be avoided?

getAttrByNum Hugh mentioned works for the limited number of attributed 
listed by their numbers in Radius.pm. A cache is looked up first. If 
there's a miss then number is resolved to name before doing 
get_attr('Attrib-Name') and caching the value.

In short, $p->get_attr('Attrib-Name') for any attribute is the most 
consistent method. It works for getting the value or values of all 
standard and vendor-specific attributes.

The exception is User-Name which should be modified and accessed as above.

Some attribute lookups, such as Acct-Session-Id and Acct-Status-Type can 
get looked up multiple times during processing and caching can be useful 
for those. The *AttrByNum call, for example get_attr(), but they also 
maintain the cached values.

If you need to add new attributes, use add_attr(). If you need to change 
or delete existing the attribues listed in Radius.pm and accessed by any 
of *AttrByNum functions, then more care is needed. Those should be 
changed and deleted with the respective *AttrByNum functions. Modifying 
these may not often be needed in hooks, except of User-Name which has 
its own accessors.

> I just want to make sure that I make the best choices while cleaning up 
> our own code and couldn't find anything documenting the differences. 
> Thank you in advance for any information you provide.

I hope the above and what the others wrote clarifies this.


Heikki Vatiainen <hvn at open.com.au>

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, TACACS+, PAM, Active Directory,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, etc.

More information about the radiator mailing list