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.

181 lines
5.0 KiB

  1. // PropShellExt.cpp : Implementation of CW3extApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "w3ext.h"
  4. #include "PropShellExt.h"
  5. #include "StrFn.h"
  6. /////////////////////////////////////////////////////////////////////////////
  7. //
  8. // IShellExtInit Implementation.
  9. STDMETHODIMP
  10. CPropShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID)
  11. {
  12. if (pDataObj == NULL)
  13. {
  14. ATLASSERT(FALSE);
  15. return (E_INVALIDARG);
  16. }
  17. FORMATETC f = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  18. STGMEDIUM m;
  19. HRESULT hr = pDataObj->GetData(&f, &m);
  20. if (FAILED(hr))
  21. {
  22. return(hr);
  23. }
  24. hr = E_FAIL;
  25. if (1 == DragQueryFile((HDROP)m.hGlobal, (UINT)(-1), NULL,0))
  26. {
  27. TCHAR szFileName[MAX_PATH];
  28. DragQueryFile((HDROP)m.hGlobal, 0, szFileName, sizeof(szFileName) / sizeof(TCHAR));
  29. SHFILEINFO shfi;
  30. SHGetFileInfo(szFileName, 0, &shfi, sizeof(SHFILEINFO), SHGFI_ATTRIBUTES);
  31. if ( (shfi.dwAttributes & (SFGAO_LINK | SFGAO_REMOVABLE)) == 0
  32. && (shfi.dwAttributes & SFGAO_FILESYSTEM) != 0
  33. )
  34. {
  35. int drive_number, drive_type;
  36. TCHAR szRoot[4];
  37. if ( -1 != (drive_number = PathGetDriveNumber(szFileName))
  38. && NULL != PathBuildRoot(szRoot, drive_number)
  39. && DRIVE_REMOTE != (drive_type = GetDriveType(szRoot))
  40. && DRIVE_NO_ROOT_DIR != drive_type
  41. )
  42. {
  43. StrCpy(m_szFileName, szFileName);
  44. hr = S_OK;
  45. }
  46. }
  47. }
  48. ReleaseStgMedium(&m);
  49. return hr;
  50. }
  51. STDMETHODIMP
  52. CPropShellExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  53. {
  54. // We only add the page if the user has admin priviliges in the metabase.
  55. // The only way to check it now is to try to write something.
  56. // Test key is /LM/W3SVC.
  57. CMetabasePath path(SZ_MBN_WEB);
  58. CMetaKey key(LOCAL_KEY, path,
  59. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE
  60. );
  61. if (key.Succeeded() && SUCCEEDED(key.SetValue(MD_ISM_ACCESS_CHECK, 0x0000FFFF)))
  62. {
  63. m_psW3ShellExtProp.SetParentExt(this);
  64. HPROPSHEETPAGE hpage = m_psW3ShellExtProp.Create();
  65. ASSERT(hpage != NULL);
  66. if (NULL != hpage)
  67. {
  68. AddRef();
  69. if (!lpfnAddPage(hpage, lParam))
  70. {
  71. DestroyPropertySheetPage(hpage);
  72. }
  73. }
  74. }
  75. return key.QueryResult();
  76. }
  77. STDMETHODIMP
  78. CPropShellExt::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  79. {
  80. return E_FAIL;
  81. }
  82. BOOL
  83. RecursiveCheckVRoots(CMetaEnumerator& en, LPCTSTR meta_path, LPCTSTR folder_path)
  84. {
  85. BOOL shared = FALSE;
  86. CString vrpath, csPathMunged;
  87. BOOL bInheritOverride = FALSE;
  88. if (SUCCEEDED(en.QueryValue(MD_VR_PATH, vrpath, &bInheritOverride, meta_path)))
  89. {
  90. // vrpath could be a "special" path
  91. // like \\?\c:\temp\mydir
  92. // we need to munge it before compareing it.
  93. GetSpecialPathRealPath(vrpath,csPathMunged);
  94. if (csPathMunged.CompareNoCase(folder_path) == 0)
  95. {
  96. return TRUE;
  97. }
  98. }
  99. CString vdir;
  100. while (SUCCEEDED(en.Next(vdir, meta_path)) && !shared)
  101. {
  102. CString next_vdir;
  103. if (meta_path != NULL)
  104. next_vdir += meta_path;
  105. next_vdir += vdir;
  106. next_vdir += SZ_MBN_SEP_STR;
  107. en.Push();
  108. en.Reset();
  109. shared = RecursiveCheckVRoots(en, next_vdir, folder_path);
  110. en.Pop();
  111. }
  112. return shared;
  113. }
  114. BOOL IsFolderShared(LPCTSTR path)
  115. {
  116. BOOL shared = FALSE;
  117. CMetaEnumerator en(LOCAL_KEY, CMetabasePath(SZ_MBN_WEB));
  118. if (en.Succeeded())
  119. {
  120. DWORD di;
  121. int i = -1;
  122. CString inst;
  123. HRESULT hr = S_OK;
  124. while (SUCCEEDED(hr) && !shared)
  125. {
  126. if (SUCCEEDED(hr = en.Next(di, inst)))
  127. {
  128. CMetabasePath meta_path(TRUE, SZ_MBN_WEB, inst, SZ_MBN_ROOT);
  129. CMetaEnumerator en(LOCAL_KEY, meta_path);
  130. ASSERT(en.Succeeded());
  131. if (en.Succeeded())
  132. {
  133. shared = RecursiveCheckVRoots(en, NULL, path);
  134. }
  135. }
  136. }
  137. }
  138. return shared;
  139. }
  140. UINT
  141. CPropShellExt::CopyCallback(
  142. HWND hwnd,
  143. UINT wFunc,
  144. UINT wFlags,
  145. LPCTSTR pszSrcFile,
  146. DWORD dwSrcAttribs,
  147. LPCTSTR pszDestFile,
  148. DWORD dwDestAttribs
  149. )
  150. {
  151. UINT rc = IDYES;
  152. if ((dwSrcAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0)
  153. {
  154. switch (wFunc)
  155. {
  156. case FO_DELETE:
  157. case FO_MOVE:
  158. case FO_RENAME:
  159. if (IsFolderShared(pszSrcFile))
  160. {
  161. CString cap, msg;
  162. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  163. msg.Format(_Module.GetResourceInstance(), IDS_CONFIRM_OPERATION, pszSrcFile);
  164. rc = MessageBox(hwnd, msg, cap, MB_YESNOCANCEL|MB_ICONQUESTION);
  165. }
  166. break;
  167. }
  168. }
  169. return rc;
  170. }