ClearBox Server™ v1.2 Developer's Guide


Used by server extension to read and parse RADIUS attribute from a string. This helper function allows server extension to read radius attributes from any configuration files and pass to the server.

HRESULT ReadRADAttribute(
	[in] BSTR attrName,
	[in] BSTR attrValue,	
	[out] RADIUS_ATTRIBUTE* radAttr);


[in] Name of the RADIUS attribute which value is represented by attrValue. Names are case-insensitive strings from the RADIUS dictionary (may be found in <server installation path>/RadDict/radius.dct. May not be NULL.
[in] String representation of the attribute. Should not be NULL. See Remarks section to learn how this value is parsed by the server.
[out] Pointer to RADIUS attribute structure that server fills with attribute type, vendor information, value type and actual value if attrValue was parsed successfully.

Return Values

This method may return S_FALSE if attribute with attrName was not found or attrValue was not parsed successfully (see Remarks).

Thread Safety

This method can be called from any thread.

Memory Management

Server extension should allocate and free memory for attrName and attrValue parameters.

If the method succeeds and valType field of radAttr is RADSTR, then strValue is allocated by server and should be freed by server extension calling CoTaskMemFree if it is not NULL.

If the method succeeds and valType field of radAttr is RADTXT, then txtValue is allocated by server and should be freed by server extension calling SysFreeString if it is not NULL.


First, server remove all leading and ending spaces from attrValue string. Then, before parsing attrValue parameter, server determines value-type of the attrName attribute.

  • RADINT. If the attribute is not marked as 'enumerated' (when numeric values have string aliases), server simply tries to convert string to an integer number. If the result is 0, the method returns S_FALSE signaling about failure.
    If the attribute is enumerated, and attrValue is a valid number, attribute value is this number. Otherwise server finds in RADIUS dictionary a numeric value by the alias represented by attrValue. For example, if attrName is Framed-Protocol, and attrValue is 'PPP' then server finds in the dictionary that the attribute value is 1. If no alias (i.e. enumeration name) is found, S_FALSE is returned.
  • RADIP. Server tries to convert attrValue to a valid IP address. If it succeeds, dwValue of radAttr is set to this address as a 4 bytes long number. S_FALSE is returned if IP address is invalid.
  • RADDATE. ClearBox v1.2 always returns S_FALSE when finds attributes with such value type.
  • RADSTR. First, server removes leading and ending double-quotes ("). Then it checks if the attrValue string starts with '0x' meaning that this string is in hexadecimal form. If the string is hexadecimal but poorly formed (0-9, a-f or A-F are allowed, every byte should be represented by two characters), S_FALSE is returned, otherwise server allocates strValue array of radAttr and sets its size in strSize field. If the attrValue string is not hexadecimal, its value is copied to strValue field without any changes. For example, '0x001a5B' is valid and contains 3 bytes.
  • RADTXT. First, server removes leading and ending double-quotes ("). Then this string is copied to txtValue field of radAttr.

Example Code

This code uses m_pServer as IServer interface pointer stored in ICommonExtenderEx::InitializeEx implementation. In this example server reads and parses Class attribute.

IServer2* pS2=NULL;
//QueryInterface will always succeed

BSTR pName=SysAllocString(L" Class   "); // These spaces will be removed
BSTR pValue=SysAllocString(L"  0x12Affb78\""); // Spaces and quotes will be removed

HRESULT hr=pS2->ReadRADAttribute(pName,pValue,&attr);
if (hr==S_OK)
	// now 
	// attr.type is 25; //Class
	// attr.valType is RADSTR;
	// attr.dwValue  is undefined
	// attr.strSize is 4
	// attr.strValue points to an array of 4 bytes
	// attr.txtValue is undefined
	// attr.tag is undefined
	// attr.vendorID is 0
	// attr.vendorType is 0
	// attr.flags is 0x102
	BYTE buf[300];
	// use buf that contains 4 bytes
// Call to  pS2->Release() is not necessary 

See Also

IServer2, Server services

© 2001-2003 XPerience Technologies.

Created by chm2web html help conversion utility.