887 lines
30 KiB
Text
887 lines
30 KiB
Text
$NetBSD: patch-ab,v 1.1 2005/03/16 12:55:02 rillig Exp $
|
|
|
|
--- radproto.cxx.orig Tue Aug 10 01:32:11 2004
|
|
+++ radproto.cxx Wed Mar 16 12:38:12 2005
|
|
@@ -238,16 +238,20 @@ unsigned GetRadiusInteger(
|
|
} // anonymous namespace
|
|
|
|
|
|
-RadiusAttr::RadiusAttr() : m_type(0), m_length(0)
|
|
+RadiusAttr::RadiusAttr()
|
|
{
|
|
+ s.m_type = 0;
|
|
+ s.m_length = 0;
|
|
}
|
|
|
|
RadiusAttr::RadiusAttr(
|
|
unsigned char attrType, /// type of the attribute
|
|
const void* attrValue, /// actual attribute value data
|
|
PINDEX valueLength /// length for the attribute value
|
|
- ) : m_type(attrType), m_length(FixedHeaderLength)
|
|
+ )
|
|
{
|
|
+ s.m_type = attrType;
|
|
+ s.m_length = FixedHeaderLength;
|
|
if (valueLength > 0)
|
|
PAssertNULL(attrValue);
|
|
|
|
@@ -259,9 +263,9 @@ RadiusAttr::RadiusAttr(
|
|
valueLength = MaxValueLength;
|
|
|
|
if (valueLength > 0) {
|
|
- m_length = m_length + (unsigned char)valueLength;
|
|
+ s.m_length = s.m_length + (unsigned char)valueLength;
|
|
if (attrValue != NULL)
|
|
- memcpy(m_value, attrValue, valueLength);
|
|
+ memcpy(s.m_value, attrValue, valueLength);
|
|
}
|
|
}
|
|
|
|
@@ -270,10 +274,13 @@ RadiusAttr::RadiusAttr(
|
|
PINDEX valueLength, /// data length (bytes)
|
|
int vendorId, /// 32 bit vendor identifier
|
|
unsigned char vendorType /// vendor-specific attribute type
|
|
- ) : m_type(VendorSpecific), m_length(VsaRfc2865FixedHeaderLength),
|
|
- m_vendorType(vendorType), m_vendorLength(2)
|
|
+ )
|
|
{
|
|
- SetRadiusInteger(m_vendorId, vendorId);
|
|
+ s.m_type = VendorSpecific;
|
|
+ s.m_length = VsaRfc2865FixedHeaderLength;
|
|
+ s.s.m_vendorType = vendorType;
|
|
+ s.s.m_vendorLength = 2;
|
|
+ SetRadiusInteger(s.s.m_vendorId, vendorId);
|
|
|
|
if (valueLength > 0)
|
|
PAssertNULL(attrValue);
|
|
@@ -286,18 +293,20 @@ RadiusAttr::RadiusAttr(
|
|
valueLength = VsaMaxRfc2865ValueLength;
|
|
|
|
if (valueLength > 0) {
|
|
- m_length = m_length + (unsigned char)valueLength;
|
|
- m_vendorLength = m_vendorLength + (unsigned char)valueLength;
|
|
+ s.m_length = s.m_length + (unsigned char)valueLength;
|
|
+ s.s.m_vendorLength = s.s.m_vendorLength + (unsigned char)valueLength;
|
|
if (attrValue != NULL)
|
|
- memcpy(m_vendorValue, attrValue, valueLength);
|
|
+ memcpy(s.s.m_vendorValue, attrValue, valueLength);
|
|
}
|
|
}
|
|
|
|
RadiusAttr::RadiusAttr(
|
|
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
|
|
const PString& stringValue /// string to be stored in the attribute Value data
|
|
- ) : m_type(attrType), m_length(FixedHeaderLength)
|
|
+ )
|
|
{
|
|
+ s.m_type = attrType;
|
|
+ s.m_length = FixedHeaderLength;
|
|
if (attrType == VendorSpecific)
|
|
PAssertAlways(PInvalidParameter);
|
|
|
|
@@ -307,46 +316,53 @@ RadiusAttr::RadiusAttr(
|
|
attrLength = MaxValueLength;
|
|
|
|
if (attrLength > 0) {
|
|
- m_length = m_length + (unsigned char)attrLength;
|
|
- memcpy(m_value, (const char*)stringValue, attrLength);
|
|
+ s.m_length = s.m_length + (unsigned char)attrLength;
|
|
+ memcpy(s.m_value, (const char*)stringValue, attrLength);
|
|
}
|
|
}
|
|
|
|
RadiusAttr::RadiusAttr(
|
|
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
|
|
int intValue /// 32 bit integer to be stored in the attribute Value
|
|
- ) : m_type(attrType), m_length(FixedHeaderLength + 4)
|
|
+ )
|
|
{
|
|
+ s.m_type = attrType;
|
|
+ s.m_length = FixedHeaderLength + 4;
|
|
if (attrType == VendorSpecific)
|
|
PAssertAlways(PInvalidParameter);
|
|
|
|
- SetRadiusInteger(m_value, intValue);
|
|
+ SetRadiusInteger(s.m_value, intValue);
|
|
}
|
|
|
|
RadiusAttr::RadiusAttr(
|
|
unsigned char attrType, /// Attribute Type (see #enum AttrTypes#)
|
|
const PIPSocket::Address& addressValue /// IPv4 address to be stored in the attribute Value
|
|
- ) : m_type(attrType), m_length(FixedHeaderLength + 4)
|
|
+ )
|
|
{
|
|
+ s.m_type = attrType;
|
|
+ s.m_length = FixedHeaderLength + 4;
|
|
if (attrType == VendorSpecific)
|
|
PAssertAlways(PInvalidParameter);
|
|
|
|
const DWORD addr = (DWORD)addressValue;
|
|
|
|
- m_value[0] = ((const BYTE*)&addr)[0];
|
|
- m_value[1] = ((const BYTE*)&addr)[1];
|
|
- m_value[2] = ((const BYTE*)&addr)[2];
|
|
- m_value[3] = ((const BYTE*)&addr)[3];
|
|
+ s.m_value[0] = ((const BYTE*)&addr)[0];
|
|
+ s.m_value[1] = ((const BYTE*)&addr)[1];
|
|
+ s.m_value[2] = ((const BYTE*)&addr)[2];
|
|
+ s.m_value[3] = ((const BYTE*)&addr)[3];
|
|
}
|
|
|
|
RadiusAttr::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
|
|
- ) : m_type(VendorSpecific), m_length(VsaRfc2865FixedHeaderLength),
|
|
- m_vendorType(vendorType), m_vendorLength(2)
|
|
+ )
|
|
{
|
|
- SetRadiusInteger(m_vendorId, vendorId);
|
|
+ s.m_type = VendorSpecific;
|
|
+ s.m_length = VsaRfc2865FixedHeaderLength;
|
|
+ s.s.m_vendorType = vendorType;
|
|
+ s.s.m_vendorLength = 2;
|
|
+ SetRadiusInteger(s.s.m_vendorId, vendorId);
|
|
|
|
PINDEX vsaLength = stringValue.GetLength();
|
|
|
|
@@ -357,9 +373,9 @@ RadiusAttr::RadiusAttr(
|
|
vsaLength = VsaMaxRfc2865ValueLength;
|
|
|
|
if (vsaLength > 0) {
|
|
- m_length = m_length + (unsigned char)vsaLength;
|
|
- m_vendorLength = m_vendorLength + (unsigned char)vsaLength;
|
|
- memcpy(m_vendorValue, (const char*)stringValue, vsaLength);
|
|
+ s.m_length = s.m_length + (unsigned char)vsaLength;
|
|
+ s.s.m_vendorLength = s.s.m_vendorLength + (unsigned char)vsaLength;
|
|
+ memcpy(s.s.m_vendorValue, (const char*)stringValue, vsaLength);
|
|
}
|
|
}
|
|
|
|
@@ -367,71 +383,82 @@ RadiusAttr::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
|
|
- ) : m_type(VendorSpecific), m_length(VsaRfc2865FixedHeaderLength + 4),
|
|
- m_vendorType(vendorType), m_vendorLength(2 + 4)
|
|
+ )
|
|
{
|
|
- SetRadiusInteger(m_vendorId, vendorId);
|
|
- SetRadiusInteger(m_vendorValue, intValue);
|
|
+ s.m_type=VendorSpecific;
|
|
+ s.m_length=VsaRfc2865FixedHeaderLength + 4;
|
|
+ s.s.m_vendorType=vendorType;
|
|
+ s.s.m_vendorLength=2 + 4;
|
|
+ SetRadiusInteger(s.s.m_vendorId, vendorId);
|
|
+ SetRadiusInteger(s.s.m_vendorValue, intValue);
|
|
}
|
|
|
|
RadiusAttr::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
|
|
- ) : m_type(VendorSpecific), m_length(VsaRfc2865FixedHeaderLength + 4),
|
|
- m_vendorType(vendorType), m_vendorLength(2 + 4)
|
|
+ )
|
|
{
|
|
- SetRadiusInteger(m_vendorId, vendorId);
|
|
+ s.m_type = VendorSpecific;
|
|
+ s.m_length = VsaRfc2865FixedHeaderLength + 4;
|
|
+ s.s.m_vendorType = vendorType;
|
|
+ s.s.m_vendorLength = 2 + 4;
|
|
+ SetRadiusInteger(s.s.m_vendorId, vendorId);
|
|
|
|
const DWORD addr = (DWORD)addressValue;
|
|
|
|
- m_vendorValue[0] = ((BYTE*)&addr)[0];
|
|
- m_vendorValue[1] = ((BYTE*)&addr)[1];
|
|
- m_vendorValue[2] = ((BYTE*)&addr)[2];
|
|
- m_vendorValue[3] = ((BYTE*)&addr)[3];
|
|
+ s.s.m_vendorValue[0] = ((BYTE*)&addr)[0];
|
|
+ s.s.m_vendorValue[1] = ((BYTE*)&addr)[1];
|
|
+ s.s.m_vendorValue[2] = ((BYTE*)&addr)[2];
|
|
+ s.s.m_vendorValue[3] = ((BYTE*)&addr)[3];
|
|
}
|
|
|
|
RadiusAttr::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
|
|
- ) : m_type(VendorSpecific), m_length(VsaRfc2865FixedHeaderLength),
|
|
- m_vendorType(type), m_vendorLength(2)
|
|
+ )
|
|
{
|
|
- SetRadiusInteger(m_vendorId, CiscoVendorId);
|
|
+ s.m_type = VendorSpecific;
|
|
+ s.m_length = VsaRfc2865FixedHeaderLength;
|
|
+ s.s.m_vendorType = type;
|
|
+ s.s.m_vendorLength = 2;
|
|
+ SetRadiusInteger(s.s.m_vendorId, CiscoVendorId);
|
|
if (!vsaHack) {
|
|
int i = 0;
|
|
while (CiscoAttrNames[i].m_name != NULL)
|
|
if (CiscoAttrNames[i].m_type == type) {
|
|
- memcpy(m_vendorValue, CiscoAttrNames[i].m_name, CiscoAttrNames[i].m_nameLen);
|
|
- m_length = m_length + (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
- m_vendorLength = m_vendorLength + (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
- m_data[m_length++] = '=';
|
|
- m_vendorLength++;
|
|
+ memcpy(s.s.m_vendorValue, CiscoAttrNames[i].m_name, CiscoAttrNames[i].m_nameLen);
|
|
+ s.m_length = s.m_length + (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
+ s.s.m_vendorLength = s.s.m_vendorLength + (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
+ m_data[s.m_length++] = '=';
|
|
+ s.s.m_vendorLength++;
|
|
break;
|
|
} else
|
|
i++;
|
|
}
|
|
const PINDEX len = stringValue.GetLength();
|
|
- if (((PINDEX)m_length + len) > MaxLength)
|
|
+ if (((PINDEX)s.m_length + len) > MaxLength)
|
|
return;
|
|
|
|
- memcpy(m_data + (PINDEX)m_length, (const char*)stringValue, len);
|
|
- m_length = m_length + (unsigned char)len;
|
|
- m_vendorLength = m_vendorLength + (unsigned char)len;
|
|
+ memcpy(m_data + (PINDEX)s.m_length, (const char*)stringValue, len);
|
|
+ s.m_length = s.m_length + (unsigned char)len;
|
|
+ s.s.m_vendorLength = s.s.m_vendorLength + (unsigned char)len;
|
|
}
|
|
|
|
RadiusAttr::RadiusAttr(
|
|
const void* rawData, /// buffer with the attribute raw data
|
|
PINDEX rawLength /// length (bytes) of the buffer
|
|
- ) : m_type(0), m_length(0)
|
|
+ )
|
|
{
|
|
+ s.m_type = 0;
|
|
+ s.m_length = 0;
|
|
Read(rawData, rawLength);
|
|
}
|
|
|
|
int RadiusAttr::GetVsaVendorId() const
|
|
{
|
|
- return GetRadiusInteger(m_vendorId);
|
|
+ return GetRadiusInteger(s.s.m_vendorId);
|
|
}
|
|
|
|
bool RadiusAttr::Write(
|
|
@@ -446,7 +473,7 @@ bool RadiusAttr::Write(
|
|
if (offset == P_MAX_INDEX)
|
|
offset = buffer.GetSize();
|
|
|
|
- const PINDEX len = m_length;
|
|
+ const PINDEX len = s.m_length;
|
|
memcpy(buffer.GetPointer(offset + len) + offset, m_data, len);
|
|
written = len;
|
|
|
|
@@ -455,7 +482,7 @@ bool RadiusAttr::Write(
|
|
|
|
bool RadiusAttr::Read(const void* rawData, PINDEX rawLength)
|
|
{
|
|
- m_type = m_length = 0;
|
|
+ s.m_type = s.m_length = 0;
|
|
|
|
#ifdef _DEBUG
|
|
PAssertNULL(rawData);
|
|
@@ -483,9 +510,9 @@ void RadiusAttr::PrintOn(
|
|
|
|
if (!IsValid()) {
|
|
strm << "(Invalid) {\n";
|
|
- if (m_length > 0) {
|
|
+ if (s.m_length > 0) {
|
|
const _Ios_Fmtflags flags = strm.flags();
|
|
- const PBYTEArray value((const BYTE*)m_data, m_length, FALSE);
|
|
+ const PBYTEArray value((const BYTE*)m_data, s.m_length, FALSE);
|
|
|
|
strm << hex << setfill('0') << resetiosflags(ios::floatfield)
|
|
<< setprecision(indent) << setw(16);
|
|
@@ -508,12 +535,12 @@ void RadiusAttr::PrintOn(
|
|
strm << "{\n";
|
|
|
|
#if PTRACING
|
|
- strm << setw(indent+7) << "type = " << (unsigned)m_type
|
|
- << " (" << PMAP_ATTR_TYPE_TO_NAME(m_type) << ")\n";
|
|
+ strm << setw(indent+7) << "type = " << (unsigned)s.m_type
|
|
+ << " (" << PMAP_ATTR_TYPE_TO_NAME(s.m_type) << ")\n";
|
|
#else
|
|
- strm << setw(indent+7) << "type = " << (unsigned)m_type << '\n';
|
|
+ strm << setw(indent+7) << "type = " << (unsigned)s.m_type << '\n';
|
|
#endif
|
|
- const PINDEX totalLen = m_length;
|
|
+ const PINDEX totalLen = s.m_length;
|
|
|
|
strm << setw(indent+9) << "length = " << totalLen << " octets\n";
|
|
|
|
@@ -521,7 +548,7 @@ void RadiusAttr::PrintOn(
|
|
const _Ios_Fmtflags flags = strm.flags();
|
|
const PINDEX valueLen = (totalLen <= FixedHeaderLength)
|
|
? 0 : (totalLen - FixedHeaderLength);
|
|
- const PBYTEArray value((const BYTE*)m_value, valueLen, FALSE);
|
|
+ const PBYTEArray value((const BYTE*)s.m_value, valueLen, FALSE);
|
|
|
|
strm << setw(indent+8) << "value = " << value.GetSize() << " octets {\n";
|
|
strm << hex << setfill('0') << resetiosflags(ios::floatfield)
|
|
@@ -552,9 +579,9 @@ void RadiusAttr::PrintOn(
|
|
valueLen -= 2;
|
|
headerLen += 2;
|
|
strm << setw(indent+13) << "vendorType = "
|
|
- << (unsigned)m_vendorType << '\n';
|
|
+ << (unsigned)s.s.m_vendorType << '\n';
|
|
strm << setw(indent+15) << "vendorLength = "
|
|
- << (unsigned)m_vendorLength << '\n';
|
|
+ << (unsigned)s.s.m_vendorLength << '\n';
|
|
}
|
|
|
|
const PBYTEArray value((const BYTE*)(m_data + headerLen), valueLen, FALSE);
|
|
@@ -582,13 +609,13 @@ void RadiusAttr::PrintOn(
|
|
|
|
PINDEX RadiusAttr::GetVsaValueLength() const
|
|
{
|
|
- PINDEX len = m_length;
|
|
+ PINDEX len = s.m_length;
|
|
len = (len <= VsaRfc2865FixedHeaderLength)
|
|
? 0 : (len - VsaRfc2865FixedHeaderLength);
|
|
|
|
PINDEX len2 = 0;
|
|
if (len > 0) {
|
|
- len2 = m_vendorLength;
|
|
+ len2 = s.s.m_vendorLength;
|
|
len2 = (len2 <= 2) ? 0 : (len2 - 2);
|
|
}
|
|
if (len2 < len)
|
|
@@ -626,7 +653,7 @@ bool RadiusAttr::GetVsaValue(PBYTEArray&
|
|
offset = buffer.GetSize();
|
|
|
|
if (len > 0)
|
|
- memcpy(buffer.GetPointer(len + offset) + offset, m_vendorValue, len);
|
|
+ memcpy(buffer.GetPointer(len + offset) + offset, s.s.m_vendorValue, len);
|
|
|
|
return true;
|
|
}
|
|
@@ -636,8 +663,8 @@ PString RadiusAttr::AsString() const
|
|
if (!IsValid())
|
|
return PString();
|
|
|
|
- const PINDEX len = m_length;
|
|
- const PINDEX headerLen = (m_type == VendorSpecific)
|
|
+ const PINDEX len = s.m_length;
|
|
+ const PINDEX headerLen = (s.m_type == VendorSpecific)
|
|
? VsaFixedHeaderLength : FixedHeaderLength;
|
|
|
|
if (len <= headerLen)
|
|
@@ -648,52 +675,52 @@ PString RadiusAttr::AsString() const
|
|
|
|
int RadiusAttr::AsInteger() const
|
|
{
|
|
- if (m_length < (FixedHeaderLength+4) || m_type == VendorSpecific)
|
|
+ if (s.m_length < (FixedHeaderLength+4) || s.m_type == VendorSpecific)
|
|
return 0;
|
|
|
|
- return GetRadiusInteger(m_value);
|
|
+ return GetRadiusInteger(s.m_value);
|
|
}
|
|
|
|
PIPSocket::Address RadiusAttr::AsAddress() const
|
|
{
|
|
- if (m_length < (FixedHeaderLength+4) || m_type == VendorSpecific)
|
|
+ if (s.m_length < (FixedHeaderLength+4) || s.m_type == VendorSpecific)
|
|
return 0;
|
|
|
|
DWORD addr = 0;
|
|
-
|
|
- ((BYTE*)&addr)[0] = m_value[0];
|
|
- ((BYTE*)&addr)[1] = m_value[1];
|
|
- ((BYTE*)&addr)[2] = m_value[2];
|
|
- ((BYTE*)&addr)[3] = m_value[3];
|
|
+
|
|
+ ((BYTE*)&addr)[0] = s.m_value[0];
|
|
+ ((BYTE*)&addr)[1] = s.m_value[1];
|
|
+ ((BYTE*)&addr)[2] = s.m_value[2];
|
|
+ ((BYTE*)&addr)[3] = s.m_value[3];
|
|
|
|
return addr;
|
|
}
|
|
|
|
PString RadiusAttr::AsVsaString() const
|
|
{
|
|
- if (!IsValid() || m_type != VendorSpecific)
|
|
+ if (!IsValid() || s.m_type != VendorSpecific)
|
|
return PString();
|
|
|
|
- const PINDEX len = m_length;
|
|
+ const PINDEX len = s.m_length;
|
|
|
|
if (len <= VsaRfc2865FixedHeaderLength)
|
|
return PString();
|
|
else
|
|
- return PString((const char*)m_vendorValue, len - VsaRfc2865FixedHeaderLength);
|
|
+ return PString((const char*)s.s.m_vendorValue, len - VsaRfc2865FixedHeaderLength);
|
|
}
|
|
|
|
PString RadiusAttr::AsCiscoString() const
|
|
{
|
|
- if (!IsValid() || m_type != VendorSpecific
|
|
- || GetRadiusInteger(m_vendorId) != CiscoVendorId)
|
|
+ if (!IsValid() || s.m_type != VendorSpecific
|
|
+ || GetRadiusInteger(s.s.m_vendorId) != CiscoVendorId)
|
|
return PString();
|
|
|
|
- const PINDEX len = m_length;
|
|
+ const PINDEX len = s.m_length;
|
|
PINDEX offset = VsaRfc2865FixedHeaderLength;
|
|
|
|
int i = 0;
|
|
while (CiscoAttrNames[i].m_name != NULL)
|
|
- if (CiscoAttrNames[i].m_type == m_vendorType) {
|
|
+ if (CiscoAttrNames[i].m_type == s.s.m_vendorType) {
|
|
if (CiscoAttrNames[i].m_nameLen < (size_t)(len - offset))
|
|
if (memcmp(m_data + offset, CiscoAttrNames[i].m_name,
|
|
CiscoAttrNames[i].m_nameLen) == 0
|
|
@@ -711,30 +738,32 @@ PString RadiusAttr::AsCiscoString() cons
|
|
|
|
int RadiusAttr::AsVsaInteger() const
|
|
{
|
|
- if (m_length < (VsaRfc2865FixedHeaderLength+4) || m_type != VendorSpecific)
|
|
+ if (s.m_length < (VsaRfc2865FixedHeaderLength+4) || s.m_type != VendorSpecific)
|
|
return 0;
|
|
|
|
- return GetRadiusInteger(m_vendorValue);
|
|
+ return GetRadiusInteger(s.s.m_vendorValue);
|
|
}
|
|
|
|
PIPSocket::Address RadiusAttr::AsVsaAddress() const
|
|
{
|
|
- if (m_length < (VsaRfc2865FixedHeaderLength+4) || m_type != VendorSpecific)
|
|
+ if (s.m_length < (VsaRfc2865FixedHeaderLength+4) || s.m_type != VendorSpecific)
|
|
return 0;
|
|
|
|
DWORD addr = 0;
|
|
|
|
- ((BYTE*)&addr)[0] = m_vendorValue[0];
|
|
- ((BYTE*)&addr)[1] = m_vendorValue[1];
|
|
- ((BYTE*)&addr)[2] = m_vendorValue[2];
|
|
- ((BYTE*)&addr)[3] = m_vendorValue[3];
|
|
+ ((BYTE*)&addr)[0] = s.s.m_vendorValue[0];
|
|
+ ((BYTE*)&addr)[1] = s.s.m_vendorValue[1];
|
|
+ ((BYTE*)&addr)[2] = s.s.m_vendorValue[2];
|
|
+ ((BYTE*)&addr)[3] = s.s.m_vendorValue[3];
|
|
|
|
return addr;
|
|
}
|
|
|
|
|
|
-RadiusPDU::RadiusPDU() : m_code(Invalid), m_id(0)
|
|
+RadiusPDU::RadiusPDU()
|
|
{
|
|
+ s.m_code = 0;
|
|
+ s.m_id = 0;
|
|
SetLength(FixedHeaderLength);
|
|
}
|
|
|
|
@@ -748,8 +777,10 @@ RadiusPDU::RadiusPDU(
|
|
RadiusPDU::RadiusPDU(
|
|
unsigned char packetCode, /// code - see #Codes enum#
|
|
unsigned char packetId /// packet id (sequence number)
|
|
- ) : m_code(packetCode), m_id(packetId)
|
|
+ )
|
|
{
|
|
+ s.m_code = packetCode;
|
|
+ s.m_id = packetId;
|
|
SetLength(FixedHeaderLength);
|
|
}
|
|
|
|
@@ -759,7 +790,7 @@ RadiusPDU::RadiusPDU(
|
|
)
|
|
{
|
|
if (!Read(rawData, rawLength)) {
|
|
- m_code = m_id = Invalid;
|
|
+ s.m_code = s.m_id = Invalid;
|
|
SetLength(FixedHeaderLength);
|
|
}
|
|
}
|
|
@@ -773,16 +804,16 @@ void RadiusPDU::PrintOn(
|
|
strm << ((!IsValid()) ? "(Invalid) {\n" : "{\n");
|
|
|
|
#if PTRACING
|
|
- strm << setw(indent+7) << "code = " << (unsigned)m_code
|
|
- << " (" << PMAP_CODE_TO_NAME(m_code) << ")\n";
|
|
+ strm << setw(indent+7) << "code = " << (unsigned)s.m_code
|
|
+ << " (" << PMAP_CODE_TO_NAME(s.m_code) << ")\n";
|
|
#else
|
|
- strm << setw(indent+7) << "code = " << (unsigned)m_code << '\n';
|
|
+ strm << setw(indent+7) << "code = " << (unsigned)s.m_code << '\n';
|
|
#endif
|
|
- strm << setw(indent+5) << "id = " << (unsigned)m_id << '\n';
|
|
+ strm << setw(indent+5) << "id = " << (unsigned)s.m_id << '\n';
|
|
strm << setw(indent+9) << "length = " << GetLength() << " octets\n";
|
|
|
|
const _Ios_Fmtflags flags = strm.flags();
|
|
- const PBYTEArray value((const BYTE*)m_authenticator, AuthenticatorLength, FALSE);
|
|
+ const PBYTEArray value((const BYTE*)s.m_authenticator, AuthenticatorLength, FALSE);
|
|
|
|
strm << setw(indent+28) << "authenticator = 16 octets {\n";
|
|
strm << hex << setfill('0') << resetiosflags(ios::floatfield)
|
|
@@ -816,7 +847,7 @@ void RadiusPDU::PrintOn(
|
|
|
|
bool RadiusPDU::IsValid() const
|
|
{
|
|
- if (m_code == Invalid)
|
|
+ if (s.m_code == Invalid)
|
|
return false;
|
|
|
|
const PINDEX len = GetLength();
|
|
@@ -842,7 +873,7 @@ void RadiusPDU::GetAuthenticator(PBYTEAr
|
|
if (offset == P_MAX_INDEX)
|
|
offset = vector.GetSize();
|
|
memcpy(vector.GetPointer(offset + AuthenticatorLength) + offset,
|
|
- m_authenticator, AuthenticatorLength
|
|
+ s.m_authenticator, AuthenticatorLength
|
|
);
|
|
}
|
|
|
|
@@ -855,7 +886,7 @@ bool RadiusPDU::SetAuthenticator(const P
|
|
len -= offset;
|
|
|
|
if (len > 0)
|
|
- memcpy(m_authenticator, ((const BYTE*)vector)+offset,
|
|
+ memcpy(s.m_authenticator, ((const BYTE*)vector)+offset,
|
|
(len < AuthenticatorLength) ? len : AuthenticatorLength
|
|
);
|
|
|
|
@@ -870,32 +901,32 @@ bool RadiusPDU::SetAuthenticator(const v
|
|
if (data == NULL)
|
|
return false;
|
|
|
|
- memcpy(m_authenticator, data, AuthenticatorLength);
|
|
+ memcpy(s.m_authenticator, data, AuthenticatorLength);
|
|
return true;
|
|
}
|
|
|
|
void RadiusPDU::SetAuthenticator(PRandom& random)
|
|
{
|
|
DWORD r = (DWORD)random;
|
|
- m_authenticator[0] = ((const BYTE*)&r)[0];
|
|
- m_authenticator[1] = ((const BYTE*)&r)[1];
|
|
- m_authenticator[2] = ((const BYTE*)&r)[2];
|
|
- m_authenticator[3] = ((const BYTE*)&r)[3];
|
|
+ s.m_authenticator[0] = ((const BYTE*)&r)[0];
|
|
+ s.m_authenticator[1] = ((const BYTE*)&r)[1];
|
|
+ s.m_authenticator[2] = ((const BYTE*)&r)[2];
|
|
+ s.m_authenticator[3] = ((const BYTE*)&r)[3];
|
|
r = (DWORD)random;
|
|
- m_authenticator[4] = ((const BYTE*)&r)[0];
|
|
- m_authenticator[5] = ((const BYTE*)&r)[1];
|
|
- m_authenticator[6] = ((const BYTE*)&r)[2];
|
|
- m_authenticator[7] = ((const BYTE*)&r)[3];
|
|
+ s.m_authenticator[4] = ((const BYTE*)&r)[0];
|
|
+ s.m_authenticator[5] = ((const BYTE*)&r)[1];
|
|
+ s.m_authenticator[6] = ((const BYTE*)&r)[2];
|
|
+ s.m_authenticator[7] = ((const BYTE*)&r)[3];
|
|
r = (DWORD)random;
|
|
- m_authenticator[8] = ((const BYTE*)&r)[0];
|
|
- m_authenticator[9] = ((const BYTE*)&r)[1];
|
|
- m_authenticator[10] = ((const BYTE*)&r)[2];
|
|
- m_authenticator[11] = ((const BYTE*)&r)[3];
|
|
+ s.m_authenticator[8] = ((const BYTE*)&r)[0];
|
|
+ s.m_authenticator[9] = ((const BYTE*)&r)[1];
|
|
+ s.m_authenticator[10] = ((const BYTE*)&r)[2];
|
|
+ s.m_authenticator[11] = ((const BYTE*)&r)[3];
|
|
r = (DWORD)random;
|
|
- m_authenticator[12] = ((const BYTE*)&r)[0];
|
|
- m_authenticator[13] = ((const BYTE*)&r)[1];
|
|
- m_authenticator[14] = ((const BYTE*)&r)[2];
|
|
- m_authenticator[15] = ((const BYTE*)&r)[3];
|
|
+ s.m_authenticator[12] = ((const BYTE*)&r)[0];
|
|
+ s.m_authenticator[13] = ((const BYTE*)&r)[1];
|
|
+ s.m_authenticator[14] = ((const BYTE*)&r)[2];
|
|
+ s.m_authenticator[15] = ((const BYTE*)&r)[3];
|
|
}
|
|
|
|
void RadiusPDU::SetAuthenticator(
|
|
@@ -903,11 +934,11 @@ void RadiusPDU::SetAuthenticator(
|
|
PMessageDigest5& md5
|
|
)
|
|
{
|
|
- if (m_code == AccountingRequest) {
|
|
+ if (s.m_code == AccountingRequest) {
|
|
const PINDEX pduLength = GetLength();
|
|
const PINDEX secretLength = secret.GetLength();
|
|
|
|
- memset(m_authenticator, 0, AuthenticatorLength);
|
|
+ memset(s.m_authenticator, 0, AuthenticatorLength);
|
|
|
|
md5.Start();
|
|
md5.Process(m_data, pduLength);
|
|
@@ -916,7 +947,7 @@ void RadiusPDU::SetAuthenticator(
|
|
|
|
PMessageDigest::Result digest;
|
|
md5.CompleteDigest(digest);
|
|
- memcpy(m_authenticator, digest.GetPointer(), AuthenticatorLength);
|
|
+ memcpy(s.m_authenticator, digest.GetPointer(), AuthenticatorLength);
|
|
} else {
|
|
PRandom random;
|
|
SetAuthenticator(random);
|
|
@@ -950,9 +981,9 @@ bool RadiusPDU::AppendAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = attrType;
|
|
- attr->m_length = attrLen;
|
|
- memcpy(attr->m_value, attrValue, valueLength);
|
|
+ attr->s.m_type = attrType;
|
|
+ attr->s.m_length = attrLen;
|
|
+ memcpy(attr->s.m_value, attrValue, valueLength);
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -969,9 +1000,9 @@ bool RadiusPDU::AppendAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = attrType;
|
|
- attr->m_length = attrLen;
|
|
- memcpy(attr->m_value, (const char*)stringValue, stringValue.GetLength());
|
|
+ attr->s.m_type = attrType;
|
|
+ attr->s.m_length = attrLen;
|
|
+ memcpy(attr->s.m_value, (const char*)stringValue, stringValue.GetLength());
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -988,9 +1019,9 @@ bool RadiusPDU::AppendAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = attrType;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_value, intValue);
|
|
+ attr->s.m_type = attrType;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.m_value, intValue);
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1008,12 +1039,12 @@ bool RadiusPDU::AppendAttr(
|
|
|
|
const DWORD addr = (DWORD)addressValue;
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = attrType;
|
|
- attr->m_length = attrLen;
|
|
- attr->m_value[0] = ((const BYTE*)&addr)[0];
|
|
- attr->m_value[1] = ((const BYTE*)&addr)[1];
|
|
- attr->m_value[2] = ((const BYTE*)&addr)[2];
|
|
- attr->m_value[3] = ((const BYTE*)&addr)[3];
|
|
+ attr->s.m_type = attrType;
|
|
+ attr->s.m_length = attrLen;
|
|
+ attr->s.m_value[0] = ((const BYTE*)&addr)[0];
|
|
+ attr->s.m_value[1] = ((const BYTE*)&addr)[1];
|
|
+ attr->s.m_value[2] = ((const BYTE*)&addr)[2];
|
|
+ attr->s.m_value[3] = ((const BYTE*)&addr)[3];
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1032,12 +1063,12 @@ bool RadiusPDU::AppendVsaAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = RadiusAttr::VendorSpecific;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_vendorId, vendorId);
|
|
- attr->m_vendorType = vendorType;
|
|
- attr->m_vendorLength = valueLength + 2;
|
|
- memcpy(attr->m_vendorValue, attrValue, valueLength);
|
|
+ attr->s.m_type = RadiusAttr::VendorSpecific;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorId, vendorId);
|
|
+ attr->s.s.m_vendorType = vendorType;
|
|
+ attr->s.s.m_vendorLength = valueLength + 2;
|
|
+ memcpy(attr->s.s.m_vendorValue, attrValue, valueLength);
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1056,12 +1087,12 @@ bool RadiusPDU::AppendVsaAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = RadiusAttr::VendorSpecific;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_vendorId, vendorId);
|
|
- attr->m_vendorType = vendorType;
|
|
- attr->m_vendorLength = valueLen + 2;
|
|
- memcpy(attr->m_vendorValue, (const char*)stringValue, valueLen);
|
|
+ attr->s.m_type = RadiusAttr::VendorSpecific;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorId, vendorId);
|
|
+ attr->s.s.m_vendorType = vendorType;
|
|
+ attr->s.s.m_vendorLength = valueLen + 2;
|
|
+ memcpy(attr->s.s.m_vendorValue, (const char*)stringValue, valueLen);
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1079,12 +1110,12 @@ bool RadiusPDU::AppendVsaAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = RadiusAttr::VendorSpecific;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_vendorId, vendorId);
|
|
- attr->m_vendorType = vendorType;
|
|
- attr->m_vendorLength = 4 + 2;
|
|
- SetRadiusInteger(attr->m_vendorValue, intValue);
|
|
+ attr->s.m_type = RadiusAttr::VendorSpecific;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorId, vendorId);
|
|
+ attr->s.s.m_vendorType = vendorType;
|
|
+ attr->s.s.m_vendorLength = 4 + 2;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorValue, intValue);
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1103,15 +1134,15 @@ bool RadiusPDU::AppendVsaAttr(
|
|
|
|
const DWORD addr = (DWORD)addressValue;
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = RadiusAttr::VendorSpecific;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_vendorId, vendorId);
|
|
- attr->m_vendorType = vendorType;
|
|
- attr->m_vendorLength = 4 + 2;
|
|
- attr->m_vendorValue[0] = ((const BYTE*)&addr)[0];
|
|
- attr->m_vendorValue[1] = ((const BYTE*)&addr)[1];
|
|
- attr->m_vendorValue[2] = ((const BYTE*)&addr)[2];
|
|
- attr->m_vendorValue[3] = ((const BYTE*)&addr)[3];
|
|
+ attr->s.m_type = RadiusAttr::VendorSpecific;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorId, vendorId);
|
|
+ attr->s.s.m_vendorType = vendorType;
|
|
+ attr->s.s.m_vendorLength = 4 + 2;
|
|
+ attr->s.s.m_vendorValue[0] = ((const BYTE*)&addr)[0];
|
|
+ attr->s.s.m_vendorValue[1] = ((const BYTE*)&addr)[1];
|
|
+ attr->s.s.m_vendorValue[2] = ((const BYTE*)&addr)[2];
|
|
+ attr->s.s.m_vendorValue[3] = ((const BYTE*)&addr)[3];
|
|
SetLength(len + attrLen);
|
|
|
|
return true;
|
|
@@ -1130,11 +1161,11 @@ bool RadiusPDU::AppendCiscoAttr(
|
|
return false;
|
|
|
|
RadiusAttr* const attr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- attr->m_type = RadiusAttr::VendorSpecific;
|
|
- attr->m_length = attrLen;
|
|
- SetRadiusInteger(attr->m_vendorId, RadiusAttr::CiscoVendorId);
|
|
- attr->m_vendorType = vendorType;
|
|
- attr->m_vendorLength = 2;
|
|
+ attr->s.m_type = RadiusAttr::VendorSpecific;
|
|
+ attr->s.m_length = attrLen;
|
|
+ SetRadiusInteger(attr->s.s.m_vendorId, RadiusAttr::CiscoVendorId);
|
|
+ attr->s.s.m_vendorType = vendorType;
|
|
+ attr->s.s.m_vendorLength = 2;
|
|
|
|
if (!vsaHack) {
|
|
int i = 0;
|
|
@@ -1143,26 +1174,26 @@ bool RadiusPDU::AppendCiscoAttr(
|
|
attrLen += CiscoAttrNames[i].m_nameLen + 1;
|
|
if ((len + attrLen) > MaxPduLength)
|
|
return false;
|
|
- memcpy(attr->m_vendorValue, CiscoAttrNames[i].m_name, CiscoAttrNames[i].m_nameLen);
|
|
- attr->m_length = attr->m_length
|
|
+ memcpy(attr->s.s.m_vendorValue, CiscoAttrNames[i].m_name, CiscoAttrNames[i].m_nameLen);
|
|
+ attr->s.m_length = attr->s.m_length
|
|
+ (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
- attr->m_vendorLength = attr->m_vendorLength
|
|
+ attr->s.s.m_vendorLength = attr->s.s.m_vendorLength
|
|
+ (unsigned char)CiscoAttrNames[i].m_nameLen;
|
|
- attr->m_data[attr->m_length++] = '=';
|
|
- attr->m_vendorLength++;
|
|
+ attr->m_data[attr->s.m_length++] = '=';
|
|
+ attr->s.s.m_vendorLength++;
|
|
break;
|
|
} else
|
|
i++;
|
|
}
|
|
const PINDEX strLen = stringValue.GetLength();
|
|
attrLen += strLen;
|
|
- if (((PINDEX)attr->m_length + strLen) > RadiusAttr::MaxLength
|
|
+ if (((PINDEX)attr->s.m_length + strLen) > RadiusAttr::MaxLength
|
|
|| (len + attrLen) > MaxPduLength)
|
|
return false;
|
|
|
|
- memcpy(attr->m_data + (PINDEX)attr->m_length, (const char*)stringValue, strLen);
|
|
- attr->m_length = attr->m_length + (unsigned char)strLen;
|
|
- attr->m_vendorLength = attr->m_vendorLength + (unsigned char)strLen;
|
|
+ memcpy(attr->m_data + (PINDEX)attr->s.m_length, (const char*)stringValue, strLen);
|
|
+ attr->s.m_length = attr->s.m_length + (unsigned char)strLen;
|
|
+ attr->s.s.m_vendorLength = attr->s.s.m_vendorLength + (unsigned char)strLen;
|
|
|
|
SetLength(len + attrLen);
|
|
return true;
|
|
@@ -1247,7 +1278,7 @@ bool RadiusPDU::Read(const void* rawData
|
|
PAssert(rawLength >= MinPduLength, PInvalidParameter);
|
|
#endif
|
|
|
|
- m_code = m_id = Invalid;
|
|
+ s.m_code = s.m_id = Invalid;
|
|
SetLength(FixedHeaderLength);
|
|
|
|
if (rawData == NULL || rawLength < MinPduLength)
|
|
@@ -1260,13 +1291,13 @@ bool RadiusPDU::Read(const void* rawData
|
|
|
|
const PINDEX length = GetLength();
|
|
if (length > rawLength || length < MinPduLength || length > MaxPduLength) {
|
|
- m_code = m_id = Invalid;
|
|
+ s.m_code = s.m_id = Invalid;
|
|
SetLength(FixedHeaderLength);
|
|
return false;
|
|
}
|
|
|
|
if (length > FixedHeaderLength) {
|
|
- memcpy(m_attributes, buffptr, length - FixedHeaderLength);
|
|
+ memcpy(s.m_attributes, buffptr, length - FixedHeaderLength);
|
|
}
|
|
|
|
return true;
|
|
@@ -1291,13 +1322,13 @@ void RadiusPDU::CopyContents(const Radiu
|
|
|
|
const PINDEX len = GetLength();
|
|
if (len < MinPduLength || len > MaxPduLength) {
|
|
- m_code = m_id = Invalid;
|
|
+ s.m_code = s.m_id = Invalid;
|
|
SetLength(FixedHeaderLength);
|
|
return;
|
|
}
|
|
|
|
if (len > FixedHeaderLength)
|
|
- memcpy(m_attributes, pdu.m_attributes, len - FixedHeaderLength);
|
|
+ memcpy(s.m_attributes, pdu.s.m_attributes, len - FixedHeaderLength);
|
|
}
|
|
|
|
bool RadiusPDU::EncryptPasswords(
|
|
@@ -1316,7 +1347,7 @@ bool RadiusPDU::EncryptPasswords(
|
|
md5.Start();
|
|
if (secretLength > 0)
|
|
md5.Process((const char*)secret, secretLength);
|
|
- md5.Process(m_authenticator, AuthenticatorLength);
|
|
+ md5.Process(s.m_authenticator, AuthenticatorLength);
|
|
md5.CompleteDigest(digest);
|
|
|
|
// calculate length of the new and the old User-Password value
|
|
@@ -1330,14 +1361,14 @@ bool RadiusPDU::EncryptPasswords(
|
|
|
|
// the encrypted password attribute will be appended as the last attribute
|
|
RadiusAttr* const encPwdAttr = reinterpret_cast<RadiusAttr*>(m_data + len);
|
|
- encPwdAttr->m_type = RadiusAttr::UserPassword;
|
|
- encPwdAttr->m_length = encPwdLength + RadiusAttr::FixedHeaderLength;
|
|
- memset(encPwdAttr->m_value, 0, encPwdLength);
|
|
+ encPwdAttr->s.m_type = RadiusAttr::UserPassword;
|
|
+ encPwdAttr->s.m_length = encPwdLength + RadiusAttr::FixedHeaderLength;
|
|
+ memset(encPwdAttr->s.m_value, 0, encPwdLength);
|
|
if (origPwdLength > 0)
|
|
- memcpy(encPwdAttr->m_value, pwdAttr->m_value, origPwdLength);
|
|
+ memcpy(encPwdAttr->s.m_value, pwdAttr->s.m_value, origPwdLength);
|
|
|
|
// encrypt first 16 bytes of the password
|
|
- DWORD* buf1ptr = reinterpret_cast<DWORD*>(encPwdAttr->m_value);
|
|
+ DWORD* buf1ptr = reinterpret_cast<DWORD*>(encPwdAttr->s.m_value);
|
|
const DWORD* buf2ptr = reinterpret_cast<const DWORD*>(digest.GetPointer());
|
|
|
|
// XOR either byte-wise or dword-wise (if the memory block is aligned properly)
|