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.

168 lines
4.7 KiB

  1. #include <windows.h>
  2. #include <userenv.h>
  3. #include "events.h"
  4. //
  5. // This is a simple client side extension that reads its return value from the
  6. // registry and exits. The registry value it reads is controlled via the gpext.adm
  7. // file in this directory.
  8. //
  9. #define GPEXT_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\{febf1209-8aff-11d2-a8a1-00c04fbbcfa2}")
  10. #define GPEXT_NAME TEXT("Sample CSE")
  11. BOOL WINAPI LibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  12. {
  13. switch (dwReason)
  14. {
  15. case DLL_PROCESS_ATTACH:
  16. {
  17. DisableThreadLibraryCalls (hInstance);
  18. }
  19. break;
  20. }
  21. return TRUE;
  22. }
  23. DWORD ProcessGroupPolicy ( DWORD dwFlags,
  24. HANDLE hToken,
  25. HKEY hKeyRoot,
  26. PGROUP_POLICY_OBJECT pDeletedGPOList,
  27. PGROUP_POLICY_OBJECT pChangedGPOList,
  28. ASYNCCOMPLETIONHANDLE pHandle,
  29. BOOL* pbAbort,
  30. PFNSTATUSMESSAGECALLBACK pStatusCallback )
  31. {
  32. HKEY hKey;
  33. DWORD dwResult = ERROR_SUCCESS, dwSize, dwType;
  34. TCHAR szMsg[100] = {0};
  35. TCHAR szMsg2[100] = {0};
  36. HANDLE hEventLog;
  37. LPTSTR szStrings[2] = {0,0};
  38. if (RegOpenKeyEx (hKeyRoot, TEXT("Software\\Policies\\Microsoft\\Windows\\SampleCSE"),
  39. 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  40. {
  41. dwSize = sizeof(dwResult);
  42. RegQueryValueEx (hKey, TEXT("ReturnValue"), NULL, &dwType, (LPBYTE) &dwResult, &dwSize);
  43. if (dwResult != ERROR_SUCCESS)
  44. {
  45. dwSize = sizeof(szMsg);
  46. RegQueryValueEx (hKey, TEXT("EventMsg1"), NULL, &dwType, (LPBYTE) szMsg, &dwSize);
  47. dwSize = sizeof(szMsg2);
  48. RegQueryValueEx (hKey, TEXT("EventMsg2"), NULL, &dwType, (LPBYTE) szMsg2, &dwSize);
  49. }
  50. RegCloseKey (hKey);
  51. }
  52. if (dwResult != ERROR_SUCCESS)
  53. {
  54. //
  55. // Put message in event log
  56. //
  57. hEventLog = RegisterEventSource(NULL, TEXT("gpext"));
  58. if (hEventLog)
  59. {
  60. szStrings[0] = szMsg;
  61. ReportEvent(hEventLog, EVENTLOG_ERROR_TYPE, 0, EVENT_ERROR, NULL, 1, 0,
  62. szStrings, NULL);
  63. szStrings[0] = szMsg2;
  64. ReportEvent(hEventLog, EVENTLOG_ERROR_TYPE, 0, EVENT_ERROR, NULL, 1, 0,
  65. szStrings, NULL);
  66. DeregisterEventSource(hEventLog);
  67. }
  68. }
  69. wsprintf (szMsg, TEXT("SampleCSE: returning 0x%x\r\n"), dwResult);
  70. OutputDebugString (szMsg);
  71. return dwResult;
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // DllRegisterServer - Adds entries to the system registry
  75. STDAPI DllRegisterServer(void)
  76. {
  77. HKEY hKey;
  78. LONG lResult;
  79. DWORD dwDisp, dwValue;
  80. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPEXT_PATH, 0, NULL,
  81. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  82. &hKey, &dwDisp);
  83. if (lResult != ERROR_SUCCESS)
  84. {
  85. return lResult;
  86. }
  87. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)GPEXT_NAME,
  88. (lstrlen(GPEXT_NAME) + 1) * sizeof(TCHAR));
  89. RegSetValueEx (hKey, TEXT("ProcessGroupPolicy"), 0, REG_SZ, (LPBYTE)TEXT("ProcessGroupPolicy"),
  90. (lstrlen(TEXT("ProcessGroupPolicy")) + 1) * sizeof(TCHAR));
  91. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("gpext.dll"),
  92. (lstrlen(TEXT("gpext.dll")) + 1) * sizeof(TCHAR));
  93. dwValue = 1;
  94. RegSetValueEx (hKey, TEXT("NoGPOListChanges"), 0, REG_DWORD, (LPBYTE)&dwValue,
  95. sizeof(dwValue));
  96. RegCloseKey (hKey);
  97. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\gpext"), 0, NULL,
  98. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  99. &hKey, &dwDisp);
  100. if (lResult != ERROR_SUCCESS)
  101. {
  102. return lResult;
  103. }
  104. RegSetValueEx (hKey, TEXT("EventMessageFile"), 0, REG_SZ, (LPBYTE)TEXT("gpext.dll"),
  105. (lstrlen(TEXT("gpext.dll")) + 1) * sizeof(TCHAR));
  106. dwValue = 7;
  107. RegSetValueEx (hKey, TEXT("TypesSupported"), 0, REG_DWORD, (LPBYTE)&dwValue,
  108. sizeof(dwValue));
  109. RegCloseKey (hKey);
  110. return S_OK;
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // DllUnregisterServer - Removes entries from the system registry
  114. STDAPI DllUnregisterServer(void)
  115. {
  116. RegDeleteKey (HKEY_LOCAL_MACHINE, GPEXT_PATH);
  117. RegDeleteKey (HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\gpext"));
  118. return S_OK;
  119. }