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.

167 lines
3.7 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: NT/OLE Security
  6. File: NTSec.cpp
  7. Owner: AndrewS
  8. This file contains code related to NT security on Desktops
  9. BUG 87164: This whole code path is unused. I'm leaving this around
  10. in case we ever need it.
  11. ===================================================================*/
  12. #include "denpre.h"
  13. #pragma hdrstop
  14. #include "ntsec.h"
  15. // Globals
  16. HDESK ghDesktop = NULL;
  17. HDESK ghdeskPrev = NULL;
  18. // Local Defines
  19. // Note: This name is deliberately obscure so no one will guess it
  20. #define SZ_DEN_DESKTOP "__A8D9S1_42_D"
  21. #define DESKTOP_ALL (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | \
  22. DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | \
  23. DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK | \
  24. DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | \
  25. DESKTOP_SWITCHDESKTOP | STANDARD_RIGHTS_REQUIRED)
  26. /*===================================================================
  27. InitDesktop
  28. Create a desktop for ASP threads to use & tells Viper to call
  29. us back on every thread create so we can set the desktop
  30. Parameters:
  31. Returns:
  32. HRESULT S_OK on success
  33. Side effects
  34. Sets global variables
  35. ===================================================================*/
  36. HRESULT InitDesktop()
  37. {
  38. HRESULT hr = S_OK;
  39. DWORD err;
  40. HDESK hDesktop = NULL;
  41. // Only applies to NT
  42. if (!Glob(fWinNT))
  43. return(S_OK);
  44. // Save the old desktop because we might need it later for an obscure error condition
  45. if ((ghdeskPrev = GetThreadDesktop(GetCurrentThreadId())) == NULL)
  46. goto LErr;
  47. // Create a desktop for denali to use
  48. if ((hDesktop = CreateDesktop(SZ_DEN_DESKTOP, NULL, NULL, 0, DESKTOP_ALL, NULL)) == NULL)
  49. goto LErr;
  50. // store this handle in the global
  51. ghDesktop = hDesktop;
  52. #ifdef UNUSED
  53. hr = SetViperThreadEvents();
  54. Assert(SUCCEEDED(hr));
  55. #endif
  56. return(hr);
  57. LErr:
  58. Assert(FALSE);
  59. if (hDesktop != NULL)
  60. CloseDesktop(hDesktop);
  61. err = GetLastError();
  62. hr = HRESULT_FROM_WIN32(err);
  63. return(hr);
  64. }
  65. /*===================================================================
  66. UnInitDesktop
  67. Destroy the ASP desktop
  68. Parameters:
  69. None
  70. Returns:
  71. Nothing
  72. Side effects
  73. Sets global variables
  74. ===================================================================*/
  75. VOID UnInitDesktop()
  76. {
  77. BOOL fClosed;
  78. if (ghDesktop != NULL)
  79. {
  80. BOOL fRetried = FALSE;
  81. LRetry:
  82. Assert(ghDesktop != NULL);
  83. fClosed = CloseDesktop(ghDesktop);
  84. // If this fails, it probably means that we are in the obscure case where
  85. // IIS's CacheExtensions registry setting is 0. In this case, we are shutting
  86. // down in a worker thread. This worker thread is using the desktop, so
  87. // it cant be closed. In this case, attempt to set the desktop back to the
  88. // original IIS desktop, and then retry closing the desktop. Only retry once.
  89. if (!fClosed && !fRetried)
  90. {
  91. fRetried = TRUE;
  92. if (!SetThreadDesktop(ghdeskPrev))
  93. Assert(FALSE);
  94. goto LRetry;
  95. }
  96. // BUG 86775: Begning assert
  97. // Assert(fClosed);
  98. ghDesktop = NULL;
  99. }
  100. return;
  101. }
  102. /*===================================================================
  103. SetDesktop
  104. Set the desktop for the calling thread
  105. Parameters:
  106. None
  107. Returns:
  108. S_OK on success
  109. Side effects:
  110. Sets desktop
  111. ===================================================================*/
  112. HRESULT SetDesktop()
  113. {
  114. DWORD err;
  115. if (Glob(fWinNT) && ghDesktop != NULL)
  116. {
  117. if (!SetThreadDesktop(ghDesktop))
  118. goto LErr;
  119. }
  120. return(S_OK);
  121. LErr:
  122. Assert(FALSE);
  123. err = GetLastError();
  124. return(HRESULT_FROM_WIN32(err));
  125. }