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.

165 lines
4.0 KiB

  1. #include <windows.h>
  2. #include <assert.h>
  3. #include <stdio.h>
  4. #include "radclnt.h"
  5. DWORD TestAuthenticateProc(DWORD dwValid);
  6. DWORD TestAccountingProc(DWORD dwValid);
  7. /*
  8. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR lpszCmd, int CmdShow)
  9. {
  10. RAS_AuthInitialize();
  11. RAS_AuthSetup();
  12. return (0);
  13. }
  14. */
  15. // ================================== main =============================
  16. int main(int argc, char *argv[])
  17. {
  18. DWORD dwTID, cClients = 1, iClient;
  19. HANDLE hrgThread[1000];
  20. if (argc > 1)
  21. cClients = atoi(argv[1]);
  22. RAS_AuthInitialize();
  23. for (iClient = 0; iClient < cClients; iClient ++)
  24. {
  25. if (rand() % 2)
  26. hrgThread[iClient] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestAccountingProc, (LPVOID) (iClient % 2), 0, &dwTID);
  27. else
  28. hrgThread[iClient] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TestAuthenticateProc, (LPVOID) (iClient % 2), 0, &dwTID);
  29. }
  30. for (iClient = 0; iClient < cClients; iClient ++)
  31. {
  32. WaitForSingleObject(hrgThread[iClient], 30000);
  33. CloseHandle(hrgThread[iClient]);
  34. }
  35. RAS_AuthTerminate();
  36. return (0);
  37. } // main()
  38. // ============================= TestAuthenticateProc ============================
  39. DWORD TestAuthenticateProc(DWORD dwValid)
  40. {
  41. BYTE szTemp[1024];
  42. PAUTH_ATTRIBUTE prgAttr;
  43. BOOL fAuthenticated;
  44. prgAttr = (PAUTH_ATTRIBUTE) szTemp;
  45. prgAttr->dwType = atUserName;
  46. lstrcpy((PSTR) (prgAttr + 1), "[email protected]");
  47. prgAttr->dwLength = lstrlen((PSTR) (prgAttr + 1));
  48. /// lstrcpy((PSTR) (prgAttr + 1), "dondu");
  49. /// prgAttr->bLength = lstrlen((PSTR) (prgAttr + 1));
  50. prgAttr = (PAUTH_ATTRIBUTE) ((PBYTE) prgAttr + prgAttr->dwLength);
  51. prgAttr ++;
  52. prgAttr->dwType = atUserPassword;
  53. if (dwValid)
  54. lstrcpy((PSTR) (prgAttr + 1), "Password");
  55. else
  56. lstrcpy((PSTR) (prgAttr + 1), "Passwork");
  57. prgAttr->dwLength = lstrlen((PSTR) (prgAttr + 1));
  58. prgAttr = (PAUTH_ATTRIBUTE) ((PBYTE) prgAttr + prgAttr->dwLength);
  59. prgAttr ++;
  60. prgAttr->dwType = atMinimum;
  61. if (RAS_Autenticate((PAUTH_ATTRIBUTE) szTemp, &prgAttr, &fAuthenticated) == ERROR_SUCCESS)
  62. {
  63. LocalFree(prgAttr);
  64. if (dwValid)
  65. assert(fAuthenticated == TRUE);
  66. else
  67. assert(fAuthenticated == FALSE);
  68. switch (fAuthenticated)
  69. {
  70. case TRUE:
  71. printf("Access Accept\n");
  72. break;
  73. case FALSE:
  74. printf("Access Reject\n");
  75. break;
  76. default:
  77. printf("Unknown Packet Type\n");
  78. break;
  79. }
  80. }
  81. else
  82. {
  83. TCHAR szBuffer[MAX_PATH];
  84. szBuffer[0] = 0;
  85. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, szBuffer, MAX_PATH, NULL);
  86. printf("Packet Lost = %s", szBuffer);
  87. }
  88. return (0);
  89. } // TestAuthenticateProc()
  90. // ============================= TestAccountingProc ============================
  91. DWORD TestAccountingProc(DWORD dwValid)
  92. {
  93. BYTE szTemp[1024];
  94. PAUTH_ATTRIBUTE prgAttr;
  95. BOOL fSent;
  96. prgAttr = (PAUTH_ATTRIBUTE) szTemp;
  97. prgAttr->dwType = atUserName;
  98. lstrcpy((PSTR) (prgAttr + 1), "[email protected]");
  99. prgAttr->dwLength = lstrlen((PSTR) (prgAttr + 1));
  100. prgAttr = (PAUTH_ATTRIBUTE) ((PBYTE) prgAttr + prgAttr->dwLength);
  101. prgAttr ++;
  102. prgAttr->dwType = atNASIPAddress;
  103. *((PDWORD) (prgAttr + 1)) = inet_addr("206.63.141.134");
  104. prgAttr->dwLength = 4;
  105. prgAttr = (PAUTH_ATTRIBUTE) ((PBYTE) prgAttr + prgAttr->dwLength);
  106. prgAttr ++;
  107. prgAttr->dwType = atMinimum;
  108. if (RAS_StartAccounting((PAUTH_ATTRIBUTE) szTemp, &prgAttr, &fSent) == ERROR_SUCCESS)
  109. {
  110. LocalFree(prgAttr);
  111. switch (fSent)
  112. {
  113. case TRUE:
  114. printf("Accounting Response\n");
  115. break;
  116. case FALSE:
  117. printf("NO RESPONSE\n");
  118. break;
  119. default:
  120. printf("Unknown Packet Type\n");
  121. break;
  122. }
  123. }
  124. else
  125. {
  126. TCHAR szBuffer[MAX_PATH];
  127. szBuffer[0] = 0;
  128. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, szBuffer, MAX_PATH, NULL);
  129. printf("Packet Lost = %s", szBuffer);
  130. }
  131. return (0);
  132. } // TestAccountingProc()