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.

238 lines
4.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // radutil.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // Declarations that are shared across the proxy and server components.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/14/2000 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef RADSHARE_H
  19. #define RADSHARE_H
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif
  23. //////////
  24. // RADIUS port types
  25. //////////
  26. enum RadiusPortType
  27. {
  28. portAuthentication,
  29. portAccounting
  30. };
  31. //////////
  32. // RADIUS protocol events
  33. //////////
  34. enum RadiusEventType
  35. {
  36. eventNone,
  37. eventInvalidAddress,
  38. eventAccessRequest,
  39. eventAccessAccept,
  40. eventAccessReject,
  41. eventAccessChallenge,
  42. eventAccountingRequest,
  43. eventAccountingResponse,
  44. eventMalformedPacket,
  45. eventBadAuthenticator,
  46. eventBadSignature,
  47. eventMissingSignature,
  48. eventTimeout,
  49. eventUnknownType,
  50. eventUnexpectedResponse,
  51. eventLateResponse,
  52. eventRoundTrip,
  53. eventSendError,
  54. eventReceiveError,
  55. eventServerAvailable,
  56. eventServerUnavailable
  57. };
  58. ///////////////////////////////////////////////////////////////////////////////
  59. //
  60. // STRUCT
  61. //
  62. // RadiusEvent
  63. //
  64. // DESCRIPTION
  65. //
  66. // Used for reporting events from the RADIUS protocol layer.
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. struct RadiusEvent
  70. {
  71. RadiusPortType portType;
  72. RadiusEventType eventType;
  73. PVOID context;
  74. ULONG ipAddress;
  75. USHORT ipPort;
  76. const BYTE* packet;
  77. ULONG packetLength;
  78. ULONG data;
  79. };
  80. ///////////////////////////////////////////////////////////////////////////////
  81. //
  82. // CLASS
  83. //
  84. // RadiusString
  85. //
  86. // DESCRIPTION
  87. //
  88. // Simple wrapper around a read-only string.
  89. //
  90. ///////////////////////////////////////////////////////////////////////////////
  91. class RadiusString
  92. {
  93. public:
  94. RadiusString(PCWSTR p)
  95. { alloc(p); }
  96. RadiusString(const RadiusString& x)
  97. { alloc(x.value); }
  98. RadiusString& operator=(const RadiusString& x)
  99. {
  100. if (this != &x)
  101. {
  102. delete[] value;
  103. value = NULL;
  104. alloc(x.value);
  105. }
  106. return *this;
  107. }
  108. ~RadiusString() throw ()
  109. { delete[] value; }
  110. operator PCWSTR() const throw ()
  111. { return value; }
  112. bool operator==(const RadiusString& s) const throw ()
  113. { return !wcscmp(value, s.value); }
  114. private:
  115. PWSTR value;
  116. void alloc(PCWSTR p)
  117. { value = wcscpy(new WCHAR[wcslen(p) + 1], p); }
  118. };
  119. ///////////////////////////////////////////////////////////////////////////////
  120. //
  121. // STRUCT
  122. //
  123. // RadiusRawOctets
  124. //
  125. // DESCRIPTION
  126. //
  127. // Plain ol' data.
  128. //
  129. ///////////////////////////////////////////////////////////////////////////////
  130. struct RadiusRawOctets
  131. {
  132. BYTE* value;
  133. ULONG len;
  134. };
  135. ///////////////////////////////////////////////////////////////////////////////
  136. //
  137. // CLASS
  138. //
  139. // RadiusOctets
  140. //
  141. // DESCRIPTION
  142. //
  143. // Simple wrapper around a read-only octet string.
  144. //
  145. ///////////////////////////////////////////////////////////////////////////////
  146. class RadiusOctets : private RadiusRawOctets
  147. {
  148. public:
  149. RadiusOctets() throw ()
  150. { value = 0; len = 0; }
  151. RadiusOctets(const BYTE* buf, ULONG buflen)
  152. { alloc(buf, buflen); }
  153. RadiusOctets(const RadiusRawOctets& x)
  154. { alloc(x.value, x.len); }
  155. RadiusOctets(const RadiusOctets& x)
  156. { alloc(x.value, x.len); }
  157. RadiusOctets& operator=(const RadiusOctets& x)
  158. {
  159. assign(x.value, x.len);
  160. return *this;
  161. }
  162. ~RadiusOctets() throw ()
  163. { delete[] value; }
  164. void assign(const BYTE* buf, ULONG buflen)
  165. {
  166. if (value != buf)
  167. {
  168. delete[] value;
  169. value = 0;
  170. alloc(buf, buflen);
  171. }
  172. }
  173. const RadiusRawOctets& get() const throw ()
  174. { return *this; }
  175. ULONG length() const throw ()
  176. { return len; }
  177. operator const BYTE*() const throw ()
  178. { return value; }
  179. bool operator==(const RadiusOctets& o) const throw ()
  180. { return len == o.len && !memcmp(value, o.value, len); }
  181. private:
  182. void alloc(const BYTE* buf, ULONG buflen)
  183. {
  184. value = (PBYTE)memcpy(new BYTE[buflen], buf, buflen);
  185. len = buflen;
  186. }
  187. };
  188. //////////
  189. // Macro to add reference counting to a class definition.
  190. //////////
  191. #define DECLARE_REFERENCE_COUNT() \
  192. private: \
  193. Count refCount; \
  194. public: \
  195. void AddRef() throw () \
  196. { ++refCount; } \
  197. void Release() throw () \
  198. { if (--refCount == 0) delete this; }
  199. //////////
  200. // Helper function to get system time as 64-bit integer.
  201. //////////
  202. inline ULONG64 GetSystemTime64() throw ()
  203. {
  204. ULONG64 val;
  205. GetSystemTimeAsFileTime((FILETIME*)&val);
  206. return val;
  207. }
  208. #endif // RADSHARE_H