Make your own free website on Tripod.com
 

...

class RadiusAttr
{

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Union Anonimo

 

 

 

Struct Anonimo

 

Union Anonimo

 

Struct Anonimo

 

 

 

 

 

 

public:

friend class RadiusPDU;

enum Constants {
/// max length of the attribute raw data
MaxLength = 255,
/// length of the attribute fixed header (Type+Length)
FixedHeaderLength = 2,
/// max length of the Value field
MaxValueLength = (MaxLength - FixedHeaderLength),
/// length of the fixed header for VSA
/// (standard header + VendorId field)
VsaFixedHeaderLength = FixedHeaderLength + 4,
/// max length of the VSA Value field
VsaMaxValueLength = (MaxLength - VsaFixedHeaderLength),
/// length of the fixed header for RFC2865 conformant VSA
/// (standard header + VendorId, VendorType and VendorLength fields)
VsaRfc2865FixedHeaderLength = VsaFixedHeaderLength + 2,
/// max length of the VSA RFC2865 conformant Value field
VsaMaxRfc2865ValueLength = (MaxLength - VsaRfc2865FixedHeaderLength)
};

/// Constants for RADIUS Attribute Type field
enum AttrTypes {
Invalid = 0, UserName, UserPassword, ChapPassword,
NasIpAddress = 4, NasPort, ServiceType, FramedProtocol,
FramedIpAddress = 8, FramedIpNetmask, FramedRouting, FilterId,
FramedMtu = 12, FramedCompression, LoginIpHost, LoginService,
LoginTcpPort = 16, OldPassword, ReplyMessage, CallbackNumber,
CallbackId = 20, Expiration, FramedRoute, FramedIpxNet,
State = 24, AttrTypeClass, VendorSpecific, SessionTimeout,
IdleTimeout = 28, TerminationAction, CalledStationId, CallingStationId,
NasIdentifier = 32, ProxyState, LoginLatService, LoginLatNode,
LoginLatGroup = 36, FramedAppleTalkLink, FramedAppleTalkNetwork, FramedAppleTalkZone,
AcctStatusType = 40, AcctDelayTime, AcctInputOctets, AcctOutputOctets,
AcctSessionId = 44, AcctAuthentic, AcctSessionTime, AcctInputPackets,
AcctOutputPackets = 48, AcctTerminateCause, AcctMultiSessionId, AcctLinkCount,
AcctInputGigawords = 52, AcctOutputGigawords, EventTimestamp = 55,
ChapChallenge = 60, NasPortType, PortLimit, LoginLatPort,
TunnelType = 64, TunnelMediumType, TunnelClientEndpoint, TunnelServerEndpoint,
AcctTunnelConnectionId = 68, TunnelPassword,
PasswordRetry = 75,
Prompt = 76, ConnectInfo, ConfigurationToken,
AcctInterimInterval = 85, AcctTunnelPacketsLost, NasPortId
};

/// Constants for Service-Type attribute values
enum ServiceTypes {
ST_Login = 1, ST_Framed, ST_CallbackLogin,
ST_CallbackFramed = 4, ST_Outbound, ST_Administrative,
ST_NasPrompt = 7,
ST_AuthenticateOnly = 8, ST_CallbackNasPrompt, ST_CallCheck,
ST_CallbackAdministrative = 9
};

/// Constants for Framed-Protocol attribute values
enum FramedProtocols {
FP_Ppp = 1,
FP_Slip
};

/// Constants for Framed-Compression attribute values
enum FramedCompressionTypes {
FC_None = 0,
FC_VJTcpIp,
FC_Ipx,
FC_StacLZS
};

/// Constants for Login-Service attribute values
enum LoginServiceTypes {
LS_Telnet = 0, LS_Rlogin, LS_TcpClear, LS_PortMaster,
LS_Lat, LS_X25_PAD, LS_X25_T3POS, LS_TcpClearQuiet
};

/// Constants for NAS-Port-Type attribute values
enum NASPortTypes {
NasPort_Asynchronous = 0, NasPort_Synchronous, NasPort_IsdnSynchronous,
NasPort_IsdnAsynchronousV120 = 3, NasPort_IsdnAsynchronousV110,
NasPort_Virtual = 5, NasPort_Piafs, NasPort_HdlcClearChannel,
NasPort_X25 = 8, NasPort_X75, NasPort_G3Fax, NasPort_SDSL,
NasPort_AdslCap = 12, NasPort_AdslDmt, NasPort_Idsl, NasPort_Ehternet,
NasPort_xDsl = 16, NasPort_Cable, NasPort_WirelessOther,
NasPort_WirelessIeee8021 = 19
};

/// Constants for Acct-Status-Type atribute values
enum AcctStatusTypes {
AcctStatus_Start = 1,
AcctStatus_Stop = 2,
AcctStatus_InterimUpdate = 3,
AcctStatus_AccountingOn = 7,
AcctStatus_AccountingOff = 8
};

/// Constants for VendorId VSA field
enum VendorIdentifiers {
CiscoVendorId = 9
};

/// Contants for Cisco VSA types
enum CiscoVSA {
CiscoVSA_AV_Pair = 1,
CiscoVSA_h323_remote_address = 23, CiscoVSA_h323_conf_id = 24,
CiscoVSA_h323_setup_time = 25, CiscoVSA_h323_call_origin = 26,
CiscoVSA_h323_call_type = 27, CiscoVSA_h323_connect_time = 28,
CiscoVSA_h323_disconnect_time = 29, CiscoVSA_h323_disconnect_cause = 30,
CiscoVSA_h323_voice_quality = 31, CiscoVSA_h323_gw_id = 33,
CiscoVSA_h323_incoming_conf_id = 35,

CiscoVSA_h323_credit_amount = 101, CiscoVSA_h323_credit_time = 102,
CiscoVSA_h323_return_code = 103, CiscoVSA_h323_redirect_number = 106,
CiscoVSA_h323_preferred_lang = 107,
CiscoVSA_h323_redirect_ip_address = 108,
CiscoVSA_h323_billing_model = 109, CiscoVSA_h323_currency = 110
};

/** Construct uninitialized attribute. It should be initialized
later by other means (operator=, etc.)
*/
RadiusAttr();

/** Create TLV RADIUS attribute of a given type,
initializing #value# field with 'attrLength' bytes
of data pointed to by 'attrValue'. In case of VSA,
#vsaVendorId# is read from the attribute's value data.
*/
RadiusAttr(
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
const void* attrValue, /// buffer with attribute Value data
PINDEX valueLength /// length of attribute Value data
);

/** Copy constructor for RADIUS Attribute. It simply does byte copy.
*/
RadiusAttr(
const RadiusAttr& attr /// atrribute to copy from
) { memcpy(m_data, attr.m_data, attr.m_length); }

/** Create TLV RADIUS attribute of a given type,
initializing #value# field with 'stringValue.GetLength()' bytes
from 'stringValue' string. In case of VSA,
#vsaVendorId# is extracted from data contained in the #value# field.
*/
RadiusAttr(
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
const PString& stringValue /// string to be stored in the attribute Value data
);

/** Create TLV RADIUS attribute of a given type,
initializing #value# field with an integer value passed
with 'intValue' parameter. This constructor should be also used
for attributes carrying 32-bit timestamps.
*/
RadiusAttr(
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
int intValue /// 32 bit integer to be stored in the attribute Value
);

/** Create TLV RADIUS attribute of a given type,
initializing #value# field with 32 bit IPv4 address
value passed with 'addressValue' parameter.
*/
RadiusAttr(
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
const PIPSocket::Address& addressValue /// IPv4 address to be stored in the attribute Value
);

/** Create TLV RADIUS vendor-specific (26) attribute of a given
vendor specific type, initializing #value# data with 'vendorId'
32 bit identifier, 'vendorType' vendor attribute type
and 'attrLength' bytes of data pointer to by 'attrValue'.
#vsaVendorId# is set to 'vendorId'.
*/
RadiusAttr(
const void* attrValue, /// buffer with data to be stored in the attribute Value
PINDEX valueLength, /// data length (bytes)
int vendorId, /// 32 bit vendor identifier
unsigned char vendorType /// vendor-specific attribute type
);

/** Create TLV RADIUS vendor-specific attribute of a given type,
initializing #value# data with 'vendorId' 32 bit identifier,
'vendorType' vendor attribute type
and 'stringValue.GetLength()' bytes (characters) of 'stringValue'
parameter. #vsaVendorId# is set to 'vendorId'.
*/
RadiusAttr(
const PString& stringValue, /// string to be stored in the attribute Value
int vendorId, /// 32 bit vendor identifier
unsigned char vendorType /// vendor-specific attribute type
);

/** Create TLV RADIUS vendor-specific attribute of a given type,
initializing #value# data with 'vendorId' 32 bit identifier,
'vendorType' vendor-specific attribute type
and 32 bit 'intValue' integer value. #vsaVendorId# is set to 'vendorId'.
*/
RadiusAttr(
int intValue, /// 32 bit integer to be stored in the attribute Value
int vendorId, /// 32 bit vendor identifier
unsigned char vendorType /// vendor-specific attribute type
);

/** Create TLV RADIUS vendor-specific attribute of a given type,
initializing #value# data with 'vendorId' 32 bit identifier,
'vendorType' vendor-specific attribute type
and 32 bit IPv6 address specified by 'addressValue' parameter.
#vsaVendorId# is set to 'vendorId'.
*/
RadiusAttr(
const PIPSocket::Address& addressValue, /// IPv4 address to be stored in the attribute Value
int vendorId, /// 32 bit vendor identifier
unsigned char vendorType /// vendor-specific attribute type
);

/** Create TLV RADIUS Cisco VSA attribute of a given type. If #vsaHack#
is false, then the attribute name is also embedded into the attribute
value (like 'h323-currency=USD').
*/
RadiusAttr(
unsigned char type, /// Cisco-specific attribute type
bool vsaHack, /// true to not prepend attribute name to its value
const PString& stringValue /// string to be stored in the attribute Value
);

/** Create TLV RADIUS attribute, reading raw data from the buffer
specified by 'rawData' parameter. Reading stops after full attribute
is reconstructed from the data or 'rawLength' bytes have been read.
Make sure to call #IsValid()# to check if the attribute has been
reconstructed successfully. Call #GetLength()# to obtain number of bytes
that have been actually read.
*/
RadiusAttr(
const void* rawData, /// buffer with the attribute raw data
PINDEX rawLength /// length (bytes) of the buffer
);

/** @return
Type of this attribute (see #enum AttrTypes#).
*/
unsigned char GetType() const { return m_type; }

/** @return
Vendor-specific type for this attribute, assuming this
attribute is a VSA that conforms to RFC 2865 guidelines for VSAs
(has vendorId, vendorType and vendorLength fields).
*/
unsigned char GetVsaType() const
{ return (m_length < VsaRfc2865FixedHeaderLength) ? 0 : m_vendorType; }

/** @return
Total length (bytes) of this attribute.
*/
PINDEX GetLength() const { return m_length; }

/** @return
Length of the Value field for this attribute.
*/
PINDEX GetValueLength() const
{
const PINDEX len = m_length;
const PINDEX headerLen = IsVsa() ? VsaFixedHeaderLength : FixedHeaderLength;

return (len <= headerLen) ? 0 : (len - headerLen);
}

/** @return
Length (bytes) of the Value field for this attribute,
assuming that it conforms to RFC 2865 guidelines for VSAs
(contains vendorId, vendorType and vendorLength fields).
*/
PINDEX GetVsaValueLength() const;

/** Fill the byte array with Value associated with this attribute.
The array is resized, if necessary, to contain the value.
Call #GetValueLength()# to determine number of bytes written
to the array
*/
bool GetValue(
PBYTEArray& val, /// array where data is to be stored
PINDEX offset = 0 /// offset into the array, where the data write starts
) const;

/** Fill the byte array with Value associated with this attribute,
assuming that this attribute is RFC 2865 guidelines conformant VSA.
The array is resized, if necessary, to contain the value.
Call #GetVsaValueLength()# to determine number of bytes written
to the array
*/
bool GetVsaValue(
PBYTEArray& val, /// array where data is to be stored
PINDEX offset = 0 /// offset into the array, where the data write starts
) const;

/** @return
True if this is a vendor-specific attribute (VSA).
*/
bool IsVsa() const { return (m_type == VendorSpecific); }

/** @return
32 bit vendor identifier for VSA. This call is valid only
for VSA attributes (see #IsVSA()#). Also ensure that this attribute
is valid (#IsValid()).
*/
int GetVsaVendorId() const;

/** Get attribute Value as a string. Be aware that the string
may contain embedded 0s. For VSA attributes this call will
build the string from data contained after vendorId field.
If RFC 2865 guidelines conformant VSA value is to be retrieved
use rather #AsVsaString()#.

@return
PString containing attribute Value.
If an error occurs an empty string is returned.
*/
PString AsString() const;

/** Get RFC 2865 guidelines conformant VSA Value as a string.
Be aware that the string may contain embedded 0s. This call will
build the string from data contained after vendorId, vendorType and
vendorLength fields.

@return
PString containing attribute Value.
If an error occurs an empty string is returned.
*/
PString AsVsaString() const;

/** Get Cisco's VSA value as a string, with attribute name removed,
if it is prepended to the string.

@return
PString containing attribute Value.
*/
PString AsCiscoString() const;

/** Get attribute Value as a 32 bit integer.
For VSA attributes this call will build the integer
from 4 bytes of data contained after vendorId field.
If RFC 2865 guidelines conformant VSA value is to be retrieved
use rather #AsVsaInteger()#.

@return
An integer representing attribute Value.
If an error occurs 0 is returned.
*/
int AsInteger() const;

/** Get RFC 2865 guidelines conformant VSA Value as a 32 bit integer.
This call will build the integer from 4 bytes of data contained
after vendorId, vendorType and vendorLength fields.

@return
An integer representing attribute Value.
If an error occurs 0 is returned.
*/
int AsVsaInteger() const;

/** Get attribute Value as a 32 bit timestamp.
For VSA attributes this call will build the timestamp
from 4 bytes of data contained after vendorId field.
If RFC 2865 guidelines conformant VSA value is to be retrieved
use rather #AsVsaTimestamp()#.

@return
PTime representing attribute Value. This timestamp
is interpreted as number of seconds passed since
*/
time_t AsTime() const { return (time_t)AsVsaInteger(); }

/** Get RFC 2865 guidelines conformant VSA Value as a 32 bit timestamp.
This call will build the timestamp from 4 bytes of data contained
after vendorId, vendorType and vendorLength fields.

@return
PTime representing attribute Value. This timestamp
is interpreted as number of seconds passed since
*/
time_t AsVsaTime() const { return (time_t)AsVsaInteger(); }

/** Get attribute Value as a 32 bit IPv4 address.
For VSA attributes this call will build the IPv4 address
from 4 bytes of data contained after vendorId field.
If RFC 2865 guidelines conformant VSA value is to be retrieved
use rather #AsVsaAddress()#.

@return
IPv4 address representing attribute Value.
*/
PIPSocket::Address AsAddress() const;

/** Get RFC 2865 guidelines conformant VSA Value as a 32 bit IPv4 address.
This call will build the IPv4 address from 4 bytes of data contained
after vendorId, vendorType and vendorLength fields.

@return
IPv4 address representing attribute Value.
*/
PIPSocket::Address AsVsaAddress() const;

/** Write this attribute to the buffer. The buffer is resized,
if necessary, to contain this attribute.

@return
True if successfully written (and 'written' receives number
of bytes written to the buffer).
*/
bool Write(
PBYTEArray& buffer, /// buffer the attribute data will be written to
PINDEX& written, /// number of bytes written (if successful return)
PINDEX offset = 0 /// offset into the buffer, where writting starts
) const;

/** Assign contents of the attribute 'attr' to this attribute.

@return
Reference to this attribute
*/
RadiusAttr& operator=(
const RadiusAttr& attr /// the attribute that contents will be assigned from
) { memcpy(m_data, attr.m_data, attr.m_length); return *this; }

/** Check whether this attribute contains valid data.

@return
Trye if this attribute is "valid".
*/
bool IsValid() const
{return ((PINDEX)m_length) >= ((m_type == VendorSpecific)
? VsaFixedHeaderLength : FixedHeaderLength
);
}

/** Output PDU to the stream. This is
primarily used by the standard #operator<<# function.
*/
void PrintOn(
ostream& strm /// Stream to print the object into.
) const;

friend ostream& operator<<(ostream& s, const RadiusAttr& attr)
{ attr.PrintOn(s); return s; }

protected:

/** Read attribute data from the raw buffer.

@return
TRUE if attribute has been sucessfully read.
Call #GetLength()# to determine how many bytes have been read.
*/
bool Read(
const void* rawData, /// raw buffer with attribute data
PINDEX rawLength /// length of the buffer
);

/** Read attribute data from the byte array.

@return
TRUE if attribute has been sucessfully read.
Call #GetLength()# to determine how many bytes have been read.
*/
bool Read(
const PBYTEArray& array, /// byte array with the attribute data
PINDEX offset = 0 /// offset into the buffer, where data starts
)
{
return (array.GetSize() > offset)
? Read(((const BYTE*)array) + offset, array.GetSize() - offset)
: false;
}

protected:

union {

/** Attribute raw data. The most important fields:
data[0] - attribute Type
data[1] - attribute Length (bytes)
*/
unsigned char m_data[MaxLength];
struct {

unsigned char m_type;
unsigned char m_length;
union {

unsigned char m_value[MaxLength - FixedHeaderLength];
struct {

unsigned char m_vendorId[4];
unsigned char m_vendorType;
unsigned char m_vendorLength;
unsigned char m_vendorValue[MaxLength - VsaRfc2865FixedHeaderLength];
};

};

};

};

 
 

};

...

 

El código fue extraido de la cabecera: " radproto.h ".

LAZ - 2006