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.

432 lines
12 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1985-1998 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: radclnt.h
  7. //
  8. // Description:
  9. //
  10. // History: Feb 11,1998 NarenG Created original version.
  11. //
  12. #ifndef RADCLNT_H
  13. #define RADCLNT_H
  14. #include <winsock.h>
  15. #include <rasauth.h>
  16. #include <raserror.h>
  17. #include <mprerror.h>
  18. #include <rtutils.h>
  19. #include <wincrypt.h>
  20. #define PSZAUTHRADIUSSERVERS \
  21. TEXT("SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Authentication\\Providers\\{1AA7F83F-C7F5-11D0-A376-00C04FC9DA04}\\Servers")
  22. #define PSZACCTRADIUSSERVERS \
  23. TEXT("SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Accounting\\Providers\\{1AA7F840-C7F5-11D0-A376-00C04FC9DA04}\\Servers")
  24. #define PSZTIMEOUT TEXT("Timeout")
  25. #define PSZAUTHPORT TEXT("AuthPort")
  26. #define PSZACCTPORT TEXT("AcctPort")
  27. #define PSZENABLEACCTONOFF TEXT("EnableAccountingOnOff")
  28. #define PSZSCORE TEXT("Score")
  29. #define PSZRETRIES TEXT("Retries")
  30. #define PSZSENDSIGNATURE TEXT("SendSignature")
  31. #define PSZNASIPADDRESS "NASIPAddress"
  32. //
  33. // Matches max RADIUS packet size
  34. //
  35. #define MAXBUFFERSIZE 4096
  36. //
  37. // defines for perfmon
  38. //
  39. #define RADIUS_CLIENT_COUNTER_OBJECT 0
  40. // ADD
  41. #define AUTHREQSENT 2
  42. #define AUTHREQFAILED 4
  43. #define AUTHREQSUCCEDED 6
  44. #define AUTHREQTIMEOUT 8
  45. #define ACCTREQSENT 10
  46. #define ACCTBADPACK 12
  47. #define ACCTREQSUCCEDED 14
  48. #define ACCTREQTIMEOUT 16
  49. #define AUTHBADPACK 18
  50. //
  51. // Trace flags
  52. //
  53. #define TRACE_PACKETS (0x00020000|TRACE_USE_MASK|TRACE_USE_MSEC|TRACE_USE_DATE)
  54. #define TRACE_RADIUS (0x00080000|TRACE_USE_MASK|TRACE_USE_MSEC|TRACE_USE_DATE)
  55. extern DWORD g_dwTraceID;
  56. extern HANDLE g_hLogEvents;
  57. #define RADIUS_TRACE(a) TracePrintfExA(g_dwTraceID,TRACE_RADIUS,a)
  58. #define RADIUS_TRACE1(a,b) TracePrintfExA(g_dwTraceID,TRACE_RADIUS,a,b)
  59. #define RADIUS_TRACE2(a,b,c) TracePrintfExA(g_dwTraceID,TRACE_RADIUS,a,b,c)
  60. #define RADIUS_TRACE3(a,b,c,d) TracePrintfExA(g_dwTraceID,TRACE_RADIUS,a,b,c,d)
  61. #define TraceSendPacket(pbBuffer, cbLength) \
  62. TraceDumpExA(g_dwTraceID, TRACE_PACKETS, pbBuffer, cbLength, 1, FALSE, "<")
  63. #define TraceRecvPacket(pbBuffer, cbLength) \
  64. TraceDumpExA(g_dwTraceID, TRACE_PACKETS, pbBuffer, cbLength, 1, FALSE, ">")
  65. //
  66. // Event Logging macros
  67. //
  68. #define RadiusLogWarning( LogId, NumStrings, lpwsSubStringArray ) \
  69. RouterLogWarning( g_hLogEvents, LogId, \
  70. NumStrings, lpwsSubStringArray, 0 )
  71. #define RadiusLogWarningString(LogId,NumStrings,lpwsSubStringArray,dwRetCode,\
  72. dwPos ) \
  73. RouterLogWarningString( g_hLogEvents, LogId, NumStrings, \
  74. lpwsSubStringArray, dwRetCode, dwPos )
  75. #define RadiusLogError( LogId, NumStrings, lpwsSubStringArray, dwRetCode ) \
  76. RouterLogError( g_hLogEvents, LogId, \
  77. NumStrings, lpwsSubStringArray, dwRetCode )
  78. #define RadiusLogErrorString(LogId,NumStrings,lpwsSubStringArray,dwRetCode, \
  79. dwPos ) \
  80. RouterLogErrorString( g_hLogEvents, LogId, NumStrings, \
  81. lpwsSubStringArray, dwRetCode, dwPos )
  82. #define RadiusLogInformation( LogId, NumStrings, lpwsSubStringArray ) \
  83. RouterLogInformation( g_hLogEvents, \
  84. LogId, NumStrings, lpwsSubStringArray, 0 )
  85. //
  86. // Enumeration of RADIUS codes
  87. //
  88. typedef enum
  89. {
  90. ptMinimum = 0,
  91. ptAccessRequest = 1,
  92. ptAccessAccept = 2,
  93. ptAccessReject = 3,
  94. ptAccountingRequest = 4,
  95. ptAccountingResponse = 5,
  96. ptAccessChallenge = 11,
  97. ptStatusServer = 12,
  98. ptStatusClient = 13,
  99. ptAcctStatusType = 40,
  100. ptMaximum = 255,
  101. } RADIUS_PACKETTYPE;
  102. //
  103. // Enumeration of (some of the) attribute types.
  104. //
  105. typedef enum
  106. {
  107. atStart = 1,
  108. atStop = 2,
  109. atInterimUpdate = 3,
  110. atAccountingOn = 7,
  111. atAccountingOff = 8,
  112. atInvalid = 255
  113. } RADIUS_ACCOUNTINGTYPE;
  114. //
  115. // Use BYTE alignment
  116. //
  117. #pragma pack(push, 1)
  118. #define MAX_AUTHENTICATOR 16
  119. typedef struct
  120. {
  121. BYTE bCode; // Indicates type of packet. Request, Accept, Reject...
  122. BYTE bIdentifier; // Unique identifier for the packet.
  123. WORD wLength; // length of packet including header in network byte
  124. // order
  125. BYTE rgAuthenticator[MAX_AUTHENTICATOR];
  126. } RADIUS_PACKETHEADER, *PRADIUS_PACKETHEADER;
  127. typedef struct
  128. {
  129. BYTE bType; // Indicates type of attribute. UserName, UserPassword, ...
  130. BYTE bLength; // length of attribute
  131. // Variable length Value
  132. } RADIUS_ATTRIBUTE, *PRADIUS_ATTRIBUTE;
  133. #pragma pack(pop)
  134. //
  135. // 5 seconds for default timeout to server requests
  136. //
  137. #define DEFTIMEOUT 5
  138. #define DEFAUTHPORT 1812
  139. #define DEFACCTPORT 1813
  140. #define MAXSCORE 30
  141. #define INCSCORE 3
  142. #define DECSCORE 2
  143. #define MINSCORE 0
  144. typedef struct RadiusServer
  145. {
  146. LIST_ENTRY ListEntry;
  147. DWORD cbSecret; // length of multibyte secret password
  148. struct timeval Timeout; // recv timeout in seconds
  149. INT cScore; // Score indicating functioning power
  150. // of server.
  151. BOOL fSendSignature; // Send signature attribute or not
  152. DWORD AuthPort; // Authentication port number
  153. DWORD AcctPort; // Accounting port number
  154. BOOL fAccountingOnOff; // Enable accounting On/Off messages
  155. BYTE bIdentifier; // Unique ID for packet
  156. LONG lPacketID; // Global Packet ID across all servers
  157. BOOL fDelete; // Flag indicates this should be removed
  158. DWORD nboNASIPAddress; // IP Address to bind to
  159. DWORD nboBestIf; // Src IP used to communicate with server
  160. SOCKADDR_IN NASIPAddress; // IP Address to bind to
  161. SOCKADDR_IN IPAddress; // IP Address of radius server
  162. WCHAR wszName[MAX_PATH+1]; // Name of radius server
  163. WCHAR wszSecret[MAX_PATH+1]; // secret password to encrypt packets
  164. CHAR szSecret[MAX_PATH+1]; // multibyte secret password
  165. } RADIUSSERVER, *PRADIUSSERVER;
  166. VOID
  167. InitializeRadiusServerList(
  168. IN BOOL fAuthentication
  169. );
  170. VOID
  171. FreeRadiusServerList(
  172. IN BOOL fAuthentication
  173. );
  174. DWORD
  175. AddRadiusServerToList(
  176. IN RADIUSSERVER * pRadiusServer,
  177. IN BOOL fAuthentication
  178. );
  179. RADIUSSERVER *
  180. ChooseRadiusServer(
  181. IN RADIUSSERVER * pRadiusServer,
  182. IN BOOL fAccounting,
  183. IN LONG lPacketID
  184. );
  185. VOID
  186. ValidateRadiusServer(
  187. IN RADIUSSERVER * pServer,
  188. IN BOOL fResponding,
  189. IN BOOL fAuthentication
  190. );
  191. DWORD
  192. ReloadConfig(
  193. IN BOOL fAuthentication
  194. );
  195. DWORD
  196. LoadRadiusServers(
  197. IN BOOL fAuthenticationServers
  198. );
  199. BOOL
  200. NotifyServer(
  201. IN BOOL fStart,
  202. IN RADIUSSERVER * pServer
  203. );
  204. DWORD
  205. Router2Radius(
  206. RAS_AUTH_ATTRIBUTE * prgRouter,
  207. RADIUS_ATTRIBUTE UNALIGNED * prgRadius,
  208. RADIUSSERVER UNALIGNED * pRadiusServer,
  209. RADIUS_PACKETHEADER UNALIGNED * pHeader,
  210. BYTE bSubCode,
  211. DWORD dwRetryCount,
  212. PBYTE * ppSignature,
  213. DWORD * pAttrLength
  214. );
  215. DWORD
  216. Radius2Router(
  217. IN RADIUS_PACKETHEADER UNALIGNED * pRecvHeader,
  218. IN RADIUSSERVER UNALIGNED * pRadiusServer,
  219. IN PBYTE pRequestAuthenticator,
  220. IN DWORD dwNumAttributes,
  221. OUT DWORD * pdwExtError,
  222. OUT PRAS_AUTH_ATTRIBUTE * pprgRouter,
  223. OUT BOOL * fEapMessageReceived
  224. );
  225. DWORD
  226. SendData2ServerWRetry(
  227. IN PRAS_AUTH_ATTRIBUTE prgInAttributes,
  228. IN PRAS_AUTH_ATTRIBUTE *pprgOutAttributes,
  229. OUT BYTE * pbCode,
  230. IN BYTE bSubCode,
  231. OUT BOOL * pfEapMessageReceived
  232. );
  233. DWORD
  234. RetrievePrivateData(
  235. WCHAR *pszServerName,
  236. WCHAR *pszSecret,
  237. DWORD cbSecretSize
  238. );
  239. DWORD
  240. VerifyPacketIntegrity(
  241. IN DWORD cbPacketLength,
  242. IN RADIUS_PACKETHEADER UNALIGNED * pRecvHeader,
  243. IN RADIUS_PACKETHEADER UNALIGNED * pSendHeader,
  244. IN RADIUSSERVER * pRadiusServer,
  245. IN BYTE bCode,
  246. OUT DWORD * pdwExtError,
  247. OUT DWORD * lpdwNumAttributes
  248. );
  249. DWORD
  250. EncryptPassword(
  251. IN RAS_AUTH_ATTRIBUTE * prgRouter,
  252. IN RADIUS_ATTRIBUTE UNALIGNED * prgRadius,
  253. IN RADIUSSERVER UNALIGNED * pRadiusServer,
  254. IN RADIUS_PACKETHEADER UNALIGNED * pHeader,
  255. IN BYTE bSubCode
  256. );
  257. DWORD
  258. DecryptMPPEKeys(
  259. IN RADIUSSERVER UNALIGNED * pRadiusServer,
  260. IN PBYTE pRequestAuthenticator,
  261. IN OUT PBYTE pEncryptionKeys
  262. );
  263. DWORD
  264. DecryptMPPESendRecvKeys(
  265. IN RADIUSSERVER UNALIGNED * pRadiusServer,
  266. IN PBYTE pRequestAuthenticator,
  267. IN DWORD dwLength,
  268. IN OUT PBYTE pEncryptionKeys
  269. );
  270. //
  271. // globals
  272. //
  273. #ifdef ALLOCATE_GLOBALS
  274. #define GLOBALS
  275. #define EXTERN
  276. #else
  277. #define EXTERN extern
  278. #endif
  279. EXTERN
  280. LONG g_lPacketID
  281. #ifdef GLOBALS
  282. = 0
  283. #endif
  284. ;
  285. EXTERN
  286. DWORD g_dwTraceID
  287. #ifdef GLOBALS
  288. = INVALID_TRACEID
  289. #endif
  290. ;
  291. EXTERN
  292. HANDLE g_hLogEvents
  293. #ifdef GLOBALS
  294. = INVALID_HANDLE_VALUE
  295. #endif
  296. ;
  297. EXTERN
  298. BOOL fWinsockInitialized
  299. #ifdef GLOBALS
  300. = FALSE
  301. #endif
  302. ;
  303. EXTERN
  304. RAS_AUTH_ATTRIBUTE * g_pServerAttributes
  305. #ifdef GLOBALS
  306. = NULL
  307. #endif
  308. ;
  309. EXTERN
  310. HCRYPTPROV g_hCryptProv
  311. #ifdef GLOBALS
  312. = 0
  313. #endif
  314. ;
  315. EXTERN
  316. LIST_ENTRY g_AuthServerListHead; // Linked list of valid radius servers
  317. EXTERN
  318. CRITICAL_SECTION g_csAuth; // used to prevent multiple access to
  319. EXTERN
  320. LIST_ENTRY g_AcctServerListHead; // Linked list of valid radius servers
  321. WCHAR * g_pszCurrentServer; // current radius server being used
  322. WCHAR *g_pszCurrentAcctServer;
  323. EXTERN
  324. DWORD g_cAuthRetries // #of times to resend packets
  325. #ifdef GLOBALS
  326. = 2
  327. #endif
  328. ;
  329. EXTERN
  330. DWORD g_cAcctRetries // #of times to resend packets
  331. #ifdef GLOBALS
  332. = 2
  333. #endif
  334. ;
  335. EXTERN
  336. CRITICAL_SECTION g_csAcct; // used to prevent multiple access to
  337. extern LONG g_cAuthReqSent; // Auth Requests Sent
  338. extern LONG g_cAuthReqFailed; // Auth Requests Failed
  339. extern LONG g_cAuthReqSucceded; // Auth Requests Succeded
  340. extern LONG g_cAuthReqTimeout; // Auth Requests timeouts
  341. extern LONG g_cAcctReqSent; // Acct Requests Sent
  342. extern LONG g_cAcctBadPack; // Acct Bad Packets
  343. extern LONG g_cAcctReqSucceded; // Acct Requests Succeded
  344. extern LONG g_cAcctReqTimeout; // Acct Requests timeouts
  345. extern LONG g_cAuthBadPack; // Auth bad Packets
  346. #endif // RADCLNT_H