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.

157 lines
3.8 KiB

  1. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. //
  3. // S H L K M G R . C P P
  4. //
  5. // HTTP 1.1/DAV 1.0 request handling via ISAPI
  6. //
  7. // This file contains the CSharedLockMgr class that handles the shared
  8. // memory mapped file implementation of the lock cache. It is used by
  9. // HTTPEXT only.
  10. //
  11. // Copyright 2000 Microsoft Corporation, All Rights Reserved
  12. //
  13. #include <_davfs.h>
  14. #include <xlock.h>
  15. #include "_shlkmgr.h"
  16. HRESULT HrGetUsableHandle(HANDLE hFile, DWORD dwProcessID, HANDLE * phFile)
  17. {
  18. HRESULT hr = S_OK;
  19. HANDLE hFileT;
  20. Assert(phFile);
  21. *phFile = NULL;
  22. {
  23. safe_revert_self s;
  24. auto_handle<HANDLE> a_hProcT;
  25. a_hProcT = OpenProcess(PROCESS_DUP_HANDLE, FALSE, dwProcessID);
  26. if (NULL == a_hProcT.get())
  27. {
  28. hr = HRESULT_FROM_WIN32(GetLastError());
  29. goto ret;
  30. }
  31. if (!DuplicateHandle(a_hProcT.get(),
  32. hFile,
  33. GetCurrentProcess(),
  34. &hFileT,
  35. 0,
  36. FALSE,
  37. DUPLICATE_SAME_ACCESS))
  38. {
  39. hr = HRESULT_FROM_WIN32(GetLastError());
  40. goto ret;
  41. }
  42. }
  43. *phFile = hFileT;
  44. ret:
  45. return hr;
  46. }
  47. // ========================================================================
  48. // CLASS CSharedLockMgr (Public Functions - inherited from ILockCache)
  49. // =========================================================================
  50. //
  51. // Print out all lock token information for locks of this type on this resource.
  52. // If the fEmitXML is false, just return if there are any locks.
  53. //
  54. BOOL CSharedLockMgr::FGetLockOnError( IMethUtil * pmu,
  55. LPCWSTR pwszResource,
  56. DWORD dwLockType,
  57. BOOL fEmitXML,
  58. CXMLEmitter * pemitter,
  59. CXNode * pxnParent)
  60. {
  61. BOOL fRet = FALSE;
  62. HRESULT hr = S_OK;
  63. CEmitterNode enLockDiscovery;
  64. DWORD dw = 0;
  65. DWORD dwLocksFound = 0;
  66. auto_co_task_mem<SNewLockData> a_pNewLockDatas;
  67. auto_co_task_mem<LPWSTR> a_ppwszLockTokens;
  68. {
  69. safe_revert sr(pmu->HitUser());
  70. hr = m_pFileHandleCache->HrGetAllLockDataForName(pwszResource,
  71. dwLockType,
  72. &dwLocksFound,
  73. a_pNewLockDatas.load(),
  74. a_ppwszLockTokens.load());
  75. if (FAILED(hr))
  76. {
  77. goto ret;
  78. }
  79. }
  80. if (fEmitXML)
  81. {
  82. for (dw = 0; dw < dwLocksFound; dw++)
  83. {
  84. // Construct the 'DAV:lockdiscovery' node
  85. //
  86. hr = enLockDiscovery.ScConstructNode (*pemitter, pxnParent, gc_wszLockDiscovery);
  87. if (FAILED(hr))
  88. {
  89. goto ret;
  90. }
  91. // Add the 'DAV:activelock' property for this plock.
  92. //$HACK:ROSEBUD_TIMEOUT_HACK
  93. // For the bug where rosebud waits until the last second
  94. // before issueing the refresh. Need to filter out this check with
  95. // the user agent string. The hack is to increase the timeout
  96. // by 30 seconds and return the actual timeout. So we
  97. // need the ecb/pmu to findout the user agent. At this point
  98. // we do not know. So we pass NULL. If we remove this
  99. // hack ever (I doubt if we can ever do that), then
  100. // change the interface of ScLockDiscoveryFromSNewLockData.
  101. //
  102. hr = ScLockDiscoveryFromSNewLockData(pmu,
  103. *pemitter,
  104. enLockDiscovery,
  105. a_pNewLockDatas.get() + dw,
  106. *(a_ppwszLockTokens.get() + dw));
  107. //$HACK:END ROSEBUD_TIMEOUT_HACK
  108. //
  109. if (FAILED(hr))
  110. {
  111. goto ret;
  112. }
  113. hr = enLockDiscovery.ScDone();
  114. if (FAILED(hr))
  115. {
  116. goto ret;
  117. }
  118. }
  119. }
  120. fRet = (0 != dwLocksFound);
  121. ret:
  122. if (dwLocksFound)
  123. {
  124. for (dw = 0; dw < dwLocksFound; dw++)
  125. {
  126. SNewLockData * pnld = a_pNewLockDatas.get() + dw;
  127. CoTaskMemFree(pnld->m_pwszResourceString);
  128. CoTaskMemFree(pnld->m_pwszOwnerComment);
  129. CoTaskMemFree(*(a_ppwszLockTokens.get() + dw));
  130. }
  131. }
  132. return fRet;
  133. }