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.

162 lines
5.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Defines the function CheckLicense.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "stdafx.h"
  11. #include "CheckLicense.h"
  12. #include "iasapi.h"
  13. #include "iasdb.h"
  14. #include "iastrace.h"
  15. #include "simtable.h"
  16. namespace
  17. {
  18. // Selects the number of Remote RADIUS Server Groups.
  19. const wchar_t selectGroupCount[] =
  20. L"SELECT Count(*) AS NumGroups\n"
  21. L"FROM ((Objects INNER JOIN Objects AS Objects_1 ON Objects.Parent = Objects_1.Identity) INNER JOIN Objects AS Objects_2 ON Objects_1.Parent = Objects_2.Identity) INNER JOIN Objects AS Objects_3 ON Objects_2.Parent = Objects_3.Identity\n"
  22. L"WHERE (((Objects_1.Name)=\"RADIUS Server Groups\") AND ((Objects_2.Name)=\"Microsoft Internet Authentication Service\") AND ((Objects_3.Identity)=1));";
  23. // Selects the addresses of all the RADIUS Clients.
  24. const wchar_t selectClientAddresses[] =
  25. L"SELECT Properties.StrVal\n"
  26. L"FROM (((((Objects INNER JOIN Objects AS Objects_1 ON Objects.Parent = Objects_1.Identity) INNER JOIN Objects AS Objects_2 ON Objects_1.Parent = Objects_2.Identity) INNER JOIN Objects AS Objects_3 ON Objects_2.Parent = Objects_3.Identity) INNER JOIN Objects AS Objects_4 ON Objects_3.Parent = Objects_4.Identity) INNER JOIN Objects AS Objects_5 ON Objects_4.Parent = Objects_5.Identity) INNER JOIN Properties ON Objects.Identity = Properties.Bag\n"
  27. L"WHERE (((Objects_1.Name)=\"Clients\") AND ((Objects_2.Name)=\"Microsoft RADIUS Protocol\") AND ((Objects_3.Name)=\"Protocols\") AND ((Objects_4.Name)=\"Microsoft Internet Authentication Service\") AND ((Objects_5.Identity)=1) AND ((Properties.Name)=\"IP Address\"));";
  28. }
  29. void CheckLicense(
  30. const wchar_t* path,
  31. IAS_SHOW_TOKEN_LIST type
  32. )
  33. {
  34. using _com_util::CheckError;
  35. IASTraceInitializer traceInit;
  36. bool checkClients;
  37. bool checkGroups;
  38. // Determine which limits need to be checked based on the token type.
  39. switch (type)
  40. {
  41. case CONFIG:
  42. {
  43. checkClients = true;
  44. checkGroups = true;
  45. break;
  46. }
  47. case CLIENTS:
  48. {
  49. checkClients = true;
  50. checkGroups = false;
  51. break;
  52. }
  53. case CONNECTION_REQUEST_POLICIES:
  54. {
  55. checkClients = false;
  56. checkGroups = true;
  57. break;
  58. }
  59. case VERSION:
  60. case SERVER_SETTINGS:
  61. case LOGGING:
  62. case REMOTE_ACCESS_POLICIES:
  63. default:
  64. {
  65. // Nothing to do.
  66. return;
  67. }
  68. }
  69. // Determine the allowed limits for the platform.
  70. IAS_PRODUCT_LIMITS limits;
  71. DWORD error = IASGetProductLimits(0, &limits);
  72. if (error != NO_ERROR)
  73. {
  74. _com_issue_error(HRESULT_FROM_WIN32(error));
  75. }
  76. HRESULT hr;
  77. CComPtr<IUnknown> session;
  78. hr = IASOpenJetDatabase(path, TRUE, &session);
  79. CheckError(hr);
  80. // Do we have to check the number of remote RADIUS server groups?
  81. if (checkGroups && (limits.maxServerGroups < IAS_NO_LIMIT))
  82. {
  83. LONG numGroups;
  84. hr = IASExecuteSQLFunction(session, selectGroupCount, &numGroups);
  85. CheckError(hr);
  86. if (numGroups > limits.maxServerGroups)
  87. {
  88. IASTracePrintf(
  89. "License Violation: %ld Remote RADIUS Server Groups are "
  90. "configured, but only %lu are allowed for this product type.",
  91. numGroups,
  92. limits.maxServerGroups
  93. );
  94. _com_issue_error(IAS_E_LICENSE_VIOLATION);
  95. }
  96. }
  97. // Do we have to check the clients?
  98. if (checkClients &&
  99. ((limits.maxClients < IAS_NO_LIMIT) || !limits.allowSubnetSyntax))
  100. {
  101. CComPtr<IRowset> rowset;
  102. hr = IASExecuteSQLCommand(session, selectClientAddresses, &rowset);
  103. CheckError(hr);
  104. CSimpleTable addrs;
  105. hr = addrs.Attach(rowset);
  106. CheckError(hr);
  107. DWORD numClients = 0;
  108. while ((hr = addrs.MoveNext()) == S_OK)
  109. {
  110. ++numClients;
  111. if (numClients > limits.maxClients)
  112. {
  113. IASTracePrintf(
  114. "License Violation: Only %lu RADIUS Clients are allowed for "
  115. "this product type.",
  116. limits.maxClients
  117. );
  118. _com_issue_error(IAS_E_LICENSE_VIOLATION);
  119. }
  120. if (!limits.allowSubnetSyntax)
  121. {
  122. const wchar_t* address = static_cast<const wchar_t*>(
  123. addrs.GetValue(1)
  124. );
  125. if (IASIsStringSubNetW(address))
  126. {
  127. IASTraceString(
  128. "License Violation: At least one RADIUS Client uses sub-net "
  129. "syntax, which is not allowed for this product type."
  130. );
  131. _com_issue_error(IAS_E_LICENSE_VIOLATION);
  132. }
  133. }
  134. }
  135. CheckError(hr);
  136. }
  137. }