Source code of Windows XP (NT5)
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.

211 lines
4.0 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. /////////////////////////////////////////////////////////////////////////
  35. VOID
  36. ScavengerThread (
  37. IN PVOID ThreadParameter
  38. )
  39. /*++
  40. Routine Description:
  41. Arguments:
  42. ThreadParameter - Indicates how many active threads there currently
  43. are.
  44. Return Value:
  45. None.
  46. --*/
  47. {
  48. ULONG i;
  49. ULONG Count = 0;
  50. //
  51. // Just wait around forver waiting to service things.
  52. //
  53. while (TRUE) {
  54. //
  55. // Wait 15 minutes before checking things out.
  56. //
  57. Sleep(900000L);
  58. #if DELAY_INITIALIZATION
  59. EnsureInitialized();
  60. #endif
  61. #if DBG
  62. if (TraceFlags & TRACE_FUNCTION_TRACE)
  63. dprintf(TEXT("LLS TRACE: ScavengerThread waking up\n"));
  64. #endif
  65. //
  66. // Update HighMark for local table
  67. //
  68. LocalServerServiceListHighMarkUpdate();
  69. //
  70. // Hmm, lets check replication...
  71. //
  72. ConfigInfoRegistryUpdate();
  73. RtlEnterCriticalSection(&ConfigInfoLock);
  74. if (ConfigInfo.Replicate) {
  75. //
  76. // If we are past replication time then do it
  77. //
  78. if (DateLocalGet() > ConfigInfo.NextReplication) {
  79. RtlLeaveCriticalSection(&ConfigInfoLock);
  80. NtSetEvent( ReplicationEvent, NULL );
  81. }
  82. else {
  83. RtlLeaveCriticalSection(&ConfigInfoLock);
  84. }
  85. }
  86. else {
  87. RtlLeaveCriticalSection(&ConfigInfoLock);
  88. }
  89. //
  90. // Now update our last used time
  91. //
  92. RtlAcquireResourceExclusive(&UserListLock, TRUE);
  93. LastUsedTime = DateSystemGet();
  94. RtlReleaseResource(&UserListLock);
  95. //
  96. // Check stuff every 6 hours (4 * 15 minutes)
  97. //
  98. Count++;
  99. if (Count > (6 * 4)) {
  100. // Reset counter
  101. Count = 0;
  102. //
  103. // Save out the data
  104. //
  105. LLSDataSave();
  106. //
  107. // Save HighMark to registry
  108. //
  109. LocalServiceListHighMarkSet();
  110. if (IsMaster) {
  111. //
  112. // Check for license compliance
  113. //
  114. RtlAcquireResourceShared(&MasterServiceListLock, TRUE);
  115. for (i = 0; i < MasterServiceListSize; i++) {
  116. if (MasterServiceList[i]->LicensesUsed > MasterServiceList[i]->Licenses) {
  117. LPWSTR SubString[1];
  118. //
  119. // Notify the system
  120. //
  121. SubString[0] = (LPWSTR) MasterServiceList[i]->Name;
  122. LogEvent(LLS_EVENT_PRODUCT_NO_LICENSE, 1, SubString, ERROR_SUCCESS);
  123. }
  124. }
  125. RtlReleaseResource(&MasterServiceListLock);
  126. // log certificate violations
  127. CertDbLogViolations();
  128. }
  129. }
  130. }
  131. } // ScavengerThread
  132. /////////////////////////////////////////////////////////////////////////
  133. VOID
  134. ScavengerInit( )
  135. /*++
  136. Routine Description:
  137. Looks in registry for given service and sets values accordingly.
  138. Arguments:
  139. Return Value:
  140. None.
  141. --*/
  142. {
  143. HANDLE Thread;
  144. DWORD Ignore;
  145. //
  146. // Just dispatch our scavenger thread
  147. //
  148. Thread = CreateThread(
  149. NULL,
  150. 0L,
  151. (LPTHREAD_START_ROUTINE) ScavengerThread,
  152. 0L,
  153. 0L,
  154. &Ignore
  155. );
  156. if (NULL != Thread)
  157. CloseHandle(Thread);
  158. } // ScavengerInit