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.

162 lines
4.2 KiB

  1. #include "gptext.h"
  2. #include <initguid.h>
  3. #include <devioctl.h>
  4. #define GPEXT_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\{426031c0-0b47-4852-b0ca-ac3d37bfcb39}")
  5. #define DriverName TEXT("\\\\.\\PSCHED")
  6. #define IOCTL_PSCHED_ZAW_EVENT CTL_CODE( \
  7. FILE_DEVICE_NETWORK, \
  8. 20, \
  9. METHOD_BUFFERED, \
  10. FILE_ANY_ACCESS \
  11. )
  12. HRESULT
  13. RegisterPSCHED(void)
  14. {
  15. HKEY hKey;
  16. LONG lResult;
  17. DWORD dwDisp, dwValue;
  18. TCHAR szBuffer[512];
  19. lResult = RegCreateKeyEx (
  20. HKEY_LOCAL_MACHINE,
  21. GPEXT_PATH,
  22. 0,
  23. NULL,
  24. REG_OPTION_NON_VOLATILE,
  25. KEY_WRITE,
  26. NULL,
  27. &hKey,
  28. &dwDisp
  29. );
  30. if (lResult != ERROR_SUCCESS)
  31. {
  32. return lResult;
  33. }
  34. LoadString (g_hInstance, IDS_PSCHED_NAME, szBuffer, ARRAYSIZE(szBuffer));
  35. RegSetValueEx (
  36. hKey,
  37. NULL,
  38. 0,
  39. REG_SZ,
  40. (LPBYTE)szBuffer,
  41. (lstrlen(szBuffer) + 1) * sizeof(TCHAR)
  42. );
  43. RegSetValueEx (
  44. hKey,
  45. TEXT("ProcessGroupPolicy"),
  46. 0,
  47. REG_SZ,
  48. (LPBYTE)TEXT("ProcessPSCHEDPolicy"),
  49. (lstrlen(TEXT("ProcessPSCHEDPolicy")) + 1) * sizeof(TCHAR)
  50. );
  51. szBuffer[0] = L'\0';
  52. wcscpy(szBuffer, L"gptext.dll");
  53. RegSetValueEx (
  54. hKey,
  55. TEXT("DllName"),
  56. 0,
  57. REG_EXPAND_SZ,
  58. (LPBYTE)szBuffer,
  59. (lstrlen(szBuffer) + 1) * sizeof(TCHAR)
  60. );
  61. dwValue = 1;
  62. RegSetValueEx (
  63. hKey,
  64. TEXT("NoUserPolicy"),
  65. 0,
  66. REG_DWORD,
  67. (LPBYTE)&dwValue,
  68. sizeof(dwValue));
  69. RegSetValueEx (
  70. hKey,
  71. TEXT("NoGPOListChanges"),
  72. 0,
  73. REG_DWORD,
  74. (LPBYTE)&dwValue,
  75. sizeof(dwValue));
  76. RegCloseKey (hKey);
  77. return S_OK;
  78. }
  79. HRESULT
  80. UnregisterPSCHED(void)
  81. {
  82. RegDeleteKey (HKEY_LOCAL_MACHINE, GPEXT_PATH);
  83. return S_OK;
  84. }
  85. VOID
  86. PingPsched()
  87. {
  88. HANDLE PschedDriverHandle;
  89. ULONG BytesReturned;
  90. BOOL IOStatus;
  91. PschedDriverHandle = CreateFile(
  92. DriverName,
  93. GENERIC_READ | GENERIC_WRITE,
  94. FILE_SHARE_READ | FILE_SHARE_WRITE,
  95. NULL,
  96. OPEN_EXISTING,
  97. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
  98. NULL
  99. );
  100. if (PschedDriverHandle != INVALID_HANDLE_VALUE) {
  101. IOStatus = DeviceIoControl(
  102. PschedDriverHandle,
  103. IOCTL_PSCHED_ZAW_EVENT,
  104. NULL,
  105. 0,
  106. NULL,
  107. 0,
  108. &BytesReturned,
  109. NULL
  110. );
  111. CloseHandle(PschedDriverHandle);
  112. }
  113. }
  114. DWORD WINAPI
  115. ProcessPSCHEDPolicy(
  116. IN DWORD dwFlags, // GPO_INFO_FLAGS
  117. IN HANDLE hToken, // User or machine token
  118. IN HKEY hKeyRoot, // Root of registry
  119. IN PGROUP_POLICY_OBJECT pDeletedGPOList, // Linked list of deleted GPOs
  120. IN PGROUP_POLICY_OBJECT pChangedGPOList, // Linked list of changed GPOs
  121. IN ASYNCCOMPLETIONHANDLE pHandle, // For asynchronous completion
  122. IN BOOL *pbAbort, // If true, then abort GPO processing
  123. IN PFNSTATUSMESSAGECALLBACK pStatusCallback // Callback function for displaying status messages
  124. )
  125. {
  126. HRESULT hr = S_OK;
  127. if (pDeletedGPOList || pChangedGPOList)
  128. {
  129. PingPsched();
  130. }
  131. return(ERROR_SUCCESS);
  132. }