Main Page | Class List | File List | Class Members

RadiusAttribute Class Reference

Implementation of RADIUS attribute. More...

#include <RadiusAttribute.h>

List of all members.

Public Member Functions

 RadiusAttribute ()
 Constructor.
 ~RadiusAttribute ()
 Destructor.
void dump ()
 Dump attribute in readable text format to the STDOUT.
void init (RadiusPacket *p_packet, uint16_t p_offset)
 Init attribute.
RadiusPacketgetPacket (void)
 Get packet that this attribute belongs to.
uint16_t getOffset (void)
 Get attribute's offset inside the packet.
unsigned char getType (void)
 Get attribute type.
int setType (unsigned char p_type)
 Set attribute type.
const char * getTypeDescription (void)
 Get textual description of attribute type.
unsigned char getLength (void)
 Get attribute length.
int setLength (unsigned char p_length)
 Set attribute length.
int isValid (void)
 Attribute is valid?
uint32_t getNumber (void)
 Get value of the numeric attribute.
int setNumber (uint32_t p_value)
 Set value of the numeric attribute.
in_addr getIPAddress (void)
 Get value of the IP address attribute.
int setIPAddress (struct in_addr p_value)
 Set value of the IP address attribute.
int getString (const char *&p_data, uint16_t &p_length)
 Get value of the string attribute.
int setString (const char *p_data, uint16_t p_length=0)
 Set value of the string attribute.
uint32_t getVendorId (void)
 Get vendor ID of Vendor-Specific attribute.
int setVendorId (uint32_t p_vendorId)
 Set vendor ID of Vendor-Specific attribute.
int getVendorRawString (const char *&p_data, uint16_t &p_length)
 Get "raw" string data of Vendor-Specific attribute.
int setVendorRawString (const char *p_data, uint16_t p_length=0)
 Set "raw" string data of Vendor-Specific attribute.
unsigned char getVendorType ()
 Get vendor type of Vendor-Specific attribute.
int setVendorType (unsigned char p_value)
 Set vendor type of Vendor-Specific attribute.
unsigned char getVendorLength ()
 Get vendor length of Vendor-Specific attribute.
int setVendorLength (unsigned char p_length)
 Set vendor length of Vendor-Specific attribute.
uint32_t getVendorNumber ()
 Get value of the numeric Vendor-Specific attribute.
int setVendorNumber (uint32_t p_value)
 Set value of the numeric Vendor-Specific attribute.
in_addr getVendorIPAddress ()
 Get value of the IP address Vendor-Specific attribute.
int setVendorIPAddress (struct in_addr p_address)
 Set value of the IP address Vendor-Specific attribute.
int getVendorString (const char *&p_data, uint16_t &p_length)
 Get value of the string Vendor-Specific attribute.
int setVendorString (const char *p_data, uint16_t p_length=0)
 Set value of the string Vendor-Specific attribute.
int getUserPassword (char *p_data, uint16_t &p_length, RadiusSecret *p_secret=NULL)
 Get string data of User-Password attribute.
int setUserPassword (const char *p_data, uint16_t p_length=0)
 Set string data of User-Password attribute.
int getOldPassword (char *p_data, uint16_t &p_length, RadiusSecret *p_secret=NULL)
 Get string data of Old-Password attribute.
int setOldPassword (const char *p_data, uint16_t p_length=0)
 Set string data of Old-Password attribute.
unsigned char getChapIdentifier (void)
 Get CHAP identifier of CHAP-Password attribute.
int setChapIdentifier (unsigned char p_chapId)
 Set vendor ID of CHAP-Password attribute.
int getChapString (const char *&p_data, uint16_t &p_length)
 Get string data of CHAP-Password attribute.
int setChapString (const char *p_data, uint16_t p_length=0)
 Set string data of CHAP-Password attribute.

Private Member Functions

void dump (AttributeFormat_e p_format)


Detailed Description

Implementation of RADIUS attribute.

This class does not keep any data - instead it provides methods to properly access and encode data at specific offset inside the RADIUS packet raw data buffer.

This implementation minimizes the footprint of RADIUS stack and does not require dynamic memory allocations. It's also very fast (at least in the typical RADIUS applications) since the data is immediately encoded inside the packet.


Member Function Documentation

void RadiusAttribute::init RadiusPacket p_packet,
uint16_t  p_offset
 

Init attribute.

Set associated RADIUS packet and offset in it - this will effectively init the attribute. A special usage is to pass zero p_offset - this will mark attribute "invalid".

Parameters:
[in] p_packet - RADIUS packet
[in] p_offset - offset inside the packet's raw data

unsigned char RadiusAttribute::getType void   ) 
 

Get attribute type.

Returns:
attribute type

int RadiusAttribute::setType unsigned char  p_type  ) 
 

Set attribute type.

Set attribute type

Parameters:
[in] p_code - attribute code
Returns:
RC_SUCCESS or RC_FAIL

unsigned char RadiusAttribute::getLength void   ) 
 

Get attribute length.

Note that returned value is length of the attribute data block as encoded in raw RADIUS packet (in other words it's simply a value of Length octet in attribute data). You must take into account specific attribute type in order to calculate the "real data" length.

Returns:
attribute's length

int RadiusAttribute::setLength unsigned char  p_length  ) 
 

Set attribute length.

Set attribute's length - refer to getLength() description for details.

Parameters:
[in] p_length - attribute's length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::isValid void   ) 
 

Attribute is valid?

Returns:
TRUE or FALSE

uint32_t RadiusAttribute::getNumber void   ) 
 

Get value of the numeric attribute.

Returns:
value of numeric attribute in host order format

int RadiusAttribute::setNumber uint32_t  p_value  ) 
 

Set value of the numeric attribute.

Parameters:
[in] p_value - numeric value in host order format
Returns:
RC_SUCCESS if attribute is successfully encode; RC_FAIL otherwise

struct in_addr RadiusAttribute::getIPAddress void   ) 
 

Get value of the IP address attribute.

Returns:
value of IP address attribute

int RadiusAttribute::setIPAddress struct in_addr  p_value  ) 
 

Set value of the IP address attribute.

Parameters:
[in] p_value - IP address
Returns:
RC_SUCCESS if attribute is successfully encode; RC_FAIL otherwise

int RadiusAttribute::getString const char *&  p_data,
uint16_t &  p_length
 

Get value of the string attribute.

Note that string data may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence you should use returned p_length value to properly operate on it.

Parameters:
[out] p_data - pointer to the beginning of string data
[out] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::setString const char *  p_data,
uint16_t  p_length = 0
 

Set value of the string attribute.

Note that string data may contain both readable characters and non-readable binary data and in any case encoded string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded string length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length (optional)
Returns:
RC_SUCCESS or RC_FAIL

uint32_t RadiusAttribute::getVendorId void   ) 
 

Get vendor ID of Vendor-Specific attribute.

Returns:
vendor ID numeric value in host order format

int RadiusAttribute::setVendorId uint32_t  p_vendorId  ) 
 

Set vendor ID of Vendor-Specific attribute.

Parameters:
[in] p_vendorId - vendor ID numeric value in host order format
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::getVendorRawString const char *&  p_data,
uint16_t &  p_length
 

Get "raw" string data of Vendor-Specific attribute.

"Raw" string data of Vendor-Specific attribute typically contains Vendor Type, Vendor Length and Attribute-specific data. Therefore in most cases you should use getVendorType(), getVendorLength() and getVendorNumber() instead of this method.

Note that string data may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence yous should use returned p_length value to properly operate on it.

Parameters:
[out] p_data - pointer to the beginning of string data
[out] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::setVendorRawString const char *  p_data,
uint16_t  p_length = 0
 

Set "raw" string data of Vendor-Specific attribute.

"Raw" string data of Vendor-Specific attribute typically contains Vendor Type, Vendor Length and Attribute-specific data. Therefore in most cases you should use setVendorType(), setVendorLength() and setVendorNumber() instead of this method.

Note that string data may contain both readable characters and non-readable binary data and in any case encoded string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded string length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length (optional)
Returns:
RC_SUCCESS or RC_FAIL

unsigned char RadiusAttribute::getVendorType  ) 
 

Get vendor type of Vendor-Specific attribute.

Returns:
vendor type

int RadiusAttribute::setVendorType unsigned char  p_value  ) 
 

Set vendor type of Vendor-Specific attribute.

Parameters:
[in] p_value - vendor type value
Returns:
RC_SUCCESS or RC_FAIL

unsigned char RadiusAttribute::getVendorLength  ) 
 

Get vendor length of Vendor-Specific attribute.

Returns:
vendor length

int RadiusAttribute::setVendorLength unsigned char  p_length  ) 
 

Set vendor length of Vendor-Specific attribute.

Parameters:
[in] p_length - vendor length value
Returns:
RC_SUCCESS or RC_FAIL

uint32_t RadiusAttribute::getVendorNumber  ) 
 

Get value of the numeric Vendor-Specific attribute.

Returns:
value of numeric attribute in host order format

int RadiusAttribute::setVendorNumber uint32_t  p_value  ) 
 

Set value of the numeric Vendor-Specific attribute.

Parameters:
[in] p_value - numeric value in host order format
Returns:
RC_SUCCESS if attribute is successfully encode; RC_FAIL otherwise

struct in_addr RadiusAttribute::getVendorIPAddress  ) 
 

Get value of the IP address Vendor-Specific attribute.

Returns:
value of IP address attribute

int RadiusAttribute::setVendorIPAddress struct in_addr  p_address  ) 
 

Set value of the IP address Vendor-Specific attribute.

Parameters:
[in] p_value - IP address
Returns:
RC_SUCCESS if attribute is successfully encode; RC_FAIL otherwise

int RadiusAttribute::getVendorString const char *&  p_data,
uint16_t &  p_length
 

Get value of the string Vendor-Specific attribute.

Note that string data may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence you should use returned p_length value to properly operate on it.

Parameters:
[out] p_data - pointer to the beginning of string data
[out] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::setVendorString const char *  p_data,
uint16_t  p_length = 0
 

Set value of the string Vendor-Specific attribute.

Note that string data may contain both readable characters and non-readable binary data. In any case string should not be null-terminated.

Note that string data may contain both readable characters and non-readable binary data and in any case encoded string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded string length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length (optional)
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::getUserPassword char *  p_data,
uint16_t &  p_length,
RadiusSecret p_secret = NULL
 

Get string data of User-Password attribute.

Password is decoded from the packet using secret key and presented in it's "original" form.

Note that password may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence you should use returned p_length value to properly operate on it.

Parameters:
[in] p_data - pointer to local buffer allocated by application where the decoded password will be stored
[out] p_length - string length
[in] p_secret - secret key (if NULL, stack's secret key is taken)
Returns:
RC_SUCCESS or RC_FAIL
IMPORTANT: allocate the buffer of size D_USER_PASSWORD_MAX_LENGTH for storing decoded password data and pass it as p_data

int RadiusAttribute::setUserPassword const char *  p_data,
uint16_t  p_length = 0
 

Set string data of User-Password attribute.

Password is encoded into the packet using secret key. The actual encoding is performed when packet is transmitted to the network (using the secret key of current connection) - therefore if you "dump" packet beforehand you won't see any data encoded.

Note that the password may contain both readable characters and non-readable binary data. In any case encoded string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded password length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::getOldPassword char *  p_data,
uint16_t &  p_length,
RadiusSecret p_secret = NULL
 

Get string data of Old-Password attribute.

Password is decoded from the packet using secret key and presented in it's "original" form.

Note that string data may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence you should use returned p_length value to properly operate on it.

Parameters:
[in] p_data - pointer to local buffer allocated by application where the decoded password will be stored
[out] p_length - string length
[in] p_secret - secret key (if NULL, stack's secret key is taken)
Returns:
RC_SUCCESS or RC_FAIL
IMPORTANT: allocate the buffer of size D_USER_PASSWORD_MAX_LENGTH for storing decoded password data and pass it as p_data

int RadiusAttribute::setOldPassword const char *  p_data,
uint16_t  p_length = 0
 

Set string data of Old-Password attribute.

Password is encoded into the packet using secret key. The actual encoding is performed when packet is transmitted to the network (using the secret key of current connection) - therefore if you "dump" packet beforehand you won't see any data encoded.

The application must add User-Password attribute prior to adding Old-Password, since encrypted User-Password data is used instead of shared authenticator for encoding

Note that the password may contain both readable characters and non-readable binary data. In any case encoded string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded password length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

unsigned char RadiusAttribute::getChapIdentifier void   ) 
 

Get CHAP identifier of CHAP-Password attribute.

Returns:
CHAP identifier

int RadiusAttribute::setChapIdentifier unsigned char  p_chapId  ) 
 

Set vendor ID of CHAP-Password attribute.

Parameters:
[in] p_chapIdentifier - CHAP identifier value
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::getChapString const char *&  p_data,
uint16_t &  p_length
 

Get string data of CHAP-Password attribute.

Note that string data may contain both readable characters and non-readable binary data. In any case string will not be null-terminated, hence you should use returned p_length value to properly operate on it.

Parameters:
[out] p_data - pointer to the beginning of string data
[out] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

int RadiusAttribute::setChapString const char *  p_data,
uint16_t  p_length = 0
 

Set string data of CHAP-Password attribute.

Note that string data may contain both readable characters and non-readable binary data. In any case string should not be null-terminated.

You have two options:

  • provide a "raw" buffer and its length
  • provide NULL-terminated string and leave the p_length parameter unspecified (in this case strlen() will be used to determine encoded password length)

Parameters:
[in] p_data - pointer to the beginning of string data
[in] p_length - string length
Returns:
RC_SUCCESS or RC_FAIL

void RadiusAttribute::dump AttributeFormat_e  p_format  )  [private]
 

Parameters:
[in] p_format - attribute format;


The documentation for this class was generated from the following files:
Generated on Tue Aug 11 18:35:07 2009 for ace-radius by doxygen 1.3.7-20040704