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.

216 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. scaven.c
  5. Abstract:
  6. Author:
  7. Arthur Hanson (arth) 06-Jan-1995
  8. Revision History:
  9. Jeff Parham (jeffparh) 05-Dec-1995
  10. o Added periodic logging of certificate agreement violations.
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <dsgetdc.h>
  17. #include "llsapi.h"
  18. #include "debug.h"
  19. #include "llsutil.h"
  20. #include "llssrv.h"
  21. #include "registry.h"
  22. #include "ntlsapi.h"
  23. #include "mapping.h"
  24. #include "msvctbl.h"
  25. #include "svctbl.h"
  26. #include "purchase.h"
  27. #include "perseat.h"
  28. #include "server.h"
  29. #include "repl.h"
  30. #include "llsevent.h"
  31. #include "llsrpc_s.h"
  32. #include "certdb.h"
  33. NTSTATUS LLSDataSave();
  34. #pragma warning (push)
  35. #pragma warning (disable : 4127) //while (TRUE), conditional expression is constant
  36. /////////////////////////////////////////////////////////////////////////
  37. VOID
  38. ScavengerThread (
  39. IN PVOID ThreadParameter
  40. )
  41. /*++
  42. Routine Description:
  43. Arguments:
  44. ThreadParameter - Indicates how many active threads there currently
  45. are.
  46. Return Value:
  47. None.
  48. --*/
  49. {
  50. ULONG i;
  51. ULONG Count = 0;
  52. UNREFERENCED_PARAMETER(ThreadParameter);
  53. //
  54. // Just wait around forver waiting to service things.
  55. //
  56. while (TRUE) {
  57. //
  58. // Wait 15 minutes before checking things out.
  59. //
  60. Sleep(900000L);
  61. #if DELAY_INITIALIZATION
  62. EnsureInitialized();
  63. #endif
  64. #if DBG
  65. if (TraceFlags & TRACE_FUNCTION_TRACE)
  66. dprintf(TEXT("LLS TRACE: ScavengerThread waking up\n"));
  67. #endif
  68. //
  69. // Update HighMark for local table
  70. //
  71. LocalServerServiceListHighMarkUpdate();
  72. //
  73. // Hmm, lets check replication...
  74. //
  75. ConfigInfoRegistryUpdate();
  76. RtlEnterCriticalSection(&ConfigInfoLock);
  77. if (ConfigInfo.Replicate) {
  78. //
  79. // If we are past replication time then do it
  80. //
  81. if (DateLocalGet() > ConfigInfo.NextReplication) {
  82. RtlLeaveCriticalSection(&ConfigInfoLock);
  83. NtSetEvent( ReplicationEvent, NULL );
  84. }
  85. else {
  86. RtlLeaveCriticalSection(&ConfigInfoLock);
  87. }
  88. }
  89. else {
  90. RtlLeaveCriticalSection(&ConfigInfoLock);
  91. }
  92. //
  93. // Now update our last used time
  94. //
  95. RtlAcquireResourceExclusive(&UserListLock, TRUE);
  96. LastUsedTime = DateSystemGet();
  97. RtlReleaseResource(&UserListLock);
  98. //
  99. // Check stuff every 6 hours (4 * 15 minutes)
  100. //
  101. Count++;
  102. if (Count > (6 * 4)) {
  103. // Reset counter
  104. Count = 0;
  105. //
  106. // Save out the data
  107. //
  108. LLSDataSave();
  109. //
  110. // Save HighMark to registry
  111. //
  112. LocalServiceListHighMarkSet();
  113. if (IsMaster) {
  114. //
  115. // Check for license compliance
  116. //
  117. RtlAcquireResourceShared(&MasterServiceListLock, TRUE);
  118. for (i = 0; i < MasterServiceListSize; i++) {
  119. if (MasterServiceList[i]->LicensesUsed > MasterServiceList[i]->Licenses) {
  120. LPWSTR SubString[1];
  121. //
  122. // Notify the system
  123. //
  124. SubString[0] = (LPWSTR) MasterServiceList[i]->Name;
  125. LogEvent(LLS_EVENT_PRODUCT_NO_LICENSE, 1, SubString, ERROR_SUCCESS);
  126. }
  127. }
  128. RtlReleaseResource(&MasterServiceListLock);
  129. // log certificate violations
  130. CertDbLogViolations();
  131. }
  132. }
  133. }
  134. } // ScavengerThread
  135. #pragma warning (pop) //4127
  136. /////////////////////////////////////////////////////////////////////////
  137. VOID
  138. ScavengerInit( )
  139. /*++
  140. Routine Description:
  141. Looks in registry for given service and sets values accordingly.
  142. Arguments:
  143. Return Value:
  144. None.
  145. --*/
  146. {
  147. HANDLE Thread;
  148. DWORD Ignore;
  149. //
  150. // Just dispatch our scavenger thread
  151. //
  152. Thread = CreateThread(
  153. NULL,
  154. 0L,
  155. (LPTHREAD_START_ROUTINE) ScavengerThread,
  156. 0L,
  157. 0L,
  158. &Ignore
  159. );
  160. if (NULL != Thread)
  161. CloseHandle(Thread);
  162. } // ScavengerInit