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.

Thanks,
Heikki


--
Heikki Vatiainen <[email protected]>

Radiator: the most portable, flexible and configurable RADIUS server
anywhere. SQL, proxy, DBM, files, LDAP, TACACS+, PAM, Active Directory,
EAP, TLS, TTLS, PEAP, WiMAX, RSA, Vasco, Yubikey, HOTP, TOTP,
DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, etc.
_______________________________________________
radiator mailing list
[email protected]
https://lists.open.com.au/mailman/listinfo/radiator

Reply via email to