Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
8.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the class RadiusRequest
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef CONTROLBLOCK_H
  11. #define CONTROLBLOCK_H
  12. #pragma once
  13. #include "authif.h"
  14. #include "iastlutl.h"
  15. #include <vector>
  16. using namespace IASTL;
  17. // Binds a RADIUS_ATTRIBUTE to an ATTRIBUTEPOSITION. Any dynamically allocated
  18. // memory always belongs to the IASATTRIBUTE contained in the
  19. // ATTRIBUTEPOSITION. The RADIUS_ATTRIBUTE lpValue member simply references
  20. // this memory.
  21. class Attribute
  22. {
  23. public:
  24. // Create from an existing IAS attribute.
  25. Attribute(
  26. const ATTRIBUTEPOSITION& iasAttr,
  27. DWORD authIfId
  28. );
  29. // Create from an existing IAS attribute, but the caller controls the
  30. // conversion. Any memory referenced by authIfAttr is not copied and thus
  31. // must reference memory contained within the IAS attribute.
  32. Attribute(
  33. const ATTRIBUTEPOSITION& iasAttr,
  34. const RADIUS_ATTRIBUTE& authIfAttr
  35. ) throw ();
  36. // Create from a RADIUS_ATTRIBUTE specified by an extension DLL, allocating
  37. // a new IAS attribute in the process. Any memory referenced by authIfAttr
  38. // is copied.
  39. Attribute(
  40. const RADIUS_ATTRIBUTE& authIfAttr,
  41. DWORD flags,
  42. DWORD iasId
  43. );
  44. // Use compiler-generated versions.
  45. // Attribute(const Attribute&);
  46. // ~Attribute() throw ();
  47. // Attribute& operator=(const Attribute&);
  48. RADIUS_ATTRIBUTE* AsAuthIf() throw ();
  49. const RADIUS_ATTRIBUTE* AsAuthIf() const throw ();
  50. ATTRIBUTEPOSITION* AsIas() throw ();
  51. const ATTRIBUTEPOSITION* AsIas() const throw ();
  52. private:
  53. // Initialize the fields of 'authIf' from the fields of 'ias'.
  54. void LoadAuthIfFromIas(DWORD authIfId);
  55. // Returns true if the specified IAS has type IASTYPE_STRING.
  56. static bool IsIasString(DWORD iasId) throw ();
  57. RADIUS_ATTRIBUTE authIf;
  58. IASAttributePosition ias;
  59. };
  60. // Implements the RADIUS_ATTRIBUTE_ARRAY interface passed to extensions.
  61. class AttributeArray
  62. {
  63. public:
  64. AttributeArray(IASRequest& request);
  65. // Assign the attributes that will be managed by this array. The arrayName
  66. // is used solely for tracing. The arrayType determines which attributes
  67. // will be selected from the IASAttributeVector.
  68. void Assign(
  69. const char* arrayName,
  70. RADIUS_CODE arrayType,
  71. const IASAttributeVector& attrs
  72. );
  73. RADIUS_ATTRIBUTE_ARRAY* Get() throw ();
  74. private:
  75. // Determine which array type the attribute belongs to.
  76. static RADIUS_CODE Classify(const IASATTRIBUTE& attr) throw ();
  77. // Various dictionary functions.
  78. static DWORD ConvertIasToAuthIf(DWORD iasId) throw ();
  79. static DWORD ConvertAuthIfToIas(DWORD authIfId) throw ();
  80. static bool IsReadOnly(DWORD authIdId) throw ();
  81. // Append a new attribute to the array.
  82. void Append(
  83. const ATTRIBUTEPOSITION& attr,
  84. DWORD authIfId
  85. );
  86. // Some IAS attributes have to be special-cased.
  87. void AppendUserName(
  88. const IASAttributeVector& attrs,
  89. const ATTRIBUTEPOSITION& attr
  90. );
  91. void AppendPacketHeader(
  92. const IASAttributeVector& attrs,
  93. const ATTRIBUTEPOSITION& attr
  94. );
  95. // Convert extension structs to the implementation class.
  96. static const AttributeArray* Narrow(
  97. const RADIUS_ATTRIBUTE_ARRAY* p
  98. ) throw ();
  99. static AttributeArray* Narrow(
  100. RADIUS_ATTRIBUTE_ARRAY* p
  101. ) throw ();
  102. // Find an attribute based on the AuthIf ID.
  103. const Attribute* Find(DWORD authIfId) const throw ();
  104. // Convert between original and stripped user names.
  105. void StripUserNames() throw ();
  106. void UnstripUserNames() throw ();
  107. // The RADIUS_ATTRIBUTE_ARRAY interface.
  108. void Add(const RADIUS_ATTRIBUTE& attr);
  109. const RADIUS_ATTRIBUTE* AttributeAt(DWORD dwIndex) const throw ();
  110. DWORD GetSize() const throw ();
  111. void InsertAt(DWORD dwIndex, const RADIUS_ATTRIBUTE& attr);
  112. void RemoveAt(DWORD dwIndex);
  113. void SetAt(DWORD dwIndex, const RADIUS_ATTRIBUTE& attr);
  114. // Callback functions passed to extensions.
  115. static DWORD Add(
  116. RADIUS_ATTRIBUTE_ARRAY* This,
  117. const RADIUS_ATTRIBUTE *pAttr
  118. ) throw ();
  119. static const RADIUS_ATTRIBUTE* AttributeAt(
  120. const RADIUS_ATTRIBUTE_ARRAY* This,
  121. DWORD dwIndex
  122. ) throw ();
  123. static DWORD GetSize(
  124. const RADIUS_ATTRIBUTE_ARRAY* This
  125. ) throw ();
  126. static DWORD InsertAt(
  127. RADIUS_ATTRIBUTE_ARRAY* This,
  128. DWORD dwIndex,
  129. const RADIUS_ATTRIBUTE* pAttr
  130. ) throw ();
  131. static DWORD RemoveAt(
  132. RADIUS_ATTRIBUTE_ARRAY* This,
  133. DWORD dwIndex
  134. ) throw ();
  135. static DWORD SetAt(
  136. RADIUS_ATTRIBUTE_ARRAY* This,
  137. DWORD dwIndex,
  138. const RADIUS_ATTRIBUTE *pAttr
  139. ) throw ();
  140. // 'vtbl' must be the first member variable, so that we can cast from a
  141. // RADIUS_ATTRIBUTE_ARRAY* to an AttributeArray*.
  142. RADIUS_ATTRIBUTE_ARRAY vtbl;
  143. IASRequest source;
  144. const char* name;
  145. // Flags that will be used for new attributes.
  146. DWORD flags;
  147. std::vector<Attribute> array;
  148. // true if the username was cracked, i.e., it has been processed by the
  149. // names handler and contains IAS_ATTRIBUTE_NT4_ACCOUNT_NAME.
  150. bool wasCracked;
  151. };
  152. // Implements the RADIUS_EXTENSION_CONTROL_BLOCK interface passed to
  153. // extensions.
  154. class ControlBlock
  155. {
  156. public:
  157. ControlBlock(RADIUS_EXTENSION_POINT point, IASRequest& request);
  158. RADIUS_EXTENSION_CONTROL_BLOCK* Get() throw ();
  159. private:
  160. // Convert extension structs to the implementation class.
  161. static ControlBlock* Narrow(RADIUS_EXTENSION_CONTROL_BLOCK* p) throw ();
  162. // Add the Extension authentication type to the request.
  163. void AddAuthType();
  164. // The RADIUS_EXTENSION_CONTROL_BLOCK interface.
  165. RADIUS_ATTRIBUTE_ARRAY* GetRequest() throw ();
  166. RADIUS_ATTRIBUTE_ARRAY* GetResponse(RADIUS_CODE rcResponseType) throw ();
  167. DWORD SetResponseType(RADIUS_CODE rcResponseType) throw ();
  168. // Callback functions passed to extensions.
  169. static RADIUS_ATTRIBUTE_ARRAY* GetRequest(
  170. RADIUS_EXTENSION_CONTROL_BLOCK* This
  171. ) throw ();
  172. static RADIUS_ATTRIBUTE_ARRAY* GetResponse(
  173. RADIUS_EXTENSION_CONTROL_BLOCK* This,
  174. RADIUS_CODE rcResponseType
  175. ) throw ();
  176. static DWORD SetResponseType(
  177. RADIUS_EXTENSION_CONTROL_BLOCK* This,
  178. RADIUS_CODE rcResponseType
  179. ) throw ();
  180. RADIUS_EXTENSION_CONTROL_BLOCK ecb; // Must be the first member variable.
  181. IASRequest source;
  182. AttributeArray requestAttrs;
  183. AttributeArray acceptAttrs;
  184. AttributeArray rejectAttrs;
  185. AttributeArray challengeAttrs;
  186. };
  187. inline RADIUS_ATTRIBUTE* Attribute::AsAuthIf() throw ()
  188. {
  189. return &authIf;
  190. }
  191. inline const RADIUS_ATTRIBUTE* Attribute::AsAuthIf() const throw ()
  192. {
  193. return &authIf;
  194. }
  195. inline ATTRIBUTEPOSITION* Attribute::AsIas() throw ()
  196. {
  197. return &ias;
  198. }
  199. inline const ATTRIBUTEPOSITION* Attribute::AsIas() const throw ()
  200. {
  201. return &ias;
  202. }
  203. inline RADIUS_ATTRIBUTE_ARRAY* AttributeArray::Get() throw ()
  204. {
  205. return &vtbl;
  206. }
  207. inline RADIUS_EXTENSION_CONTROL_BLOCK* ControlBlock::Get() throw ()
  208. {
  209. return &ecb;
  210. }
  211. #endif // CONTROLBLOCK_H