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.

264 lines
8.7 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #include <mshtml.h>
  4. // let the shell dispatch objects know where to get their type lib
  5. // (this stuff lives here for no better reason than it must be in some cpp file)
  6. EXTERN_C GUID g_guidLibSdspatch = LIBID_Shell32;
  7. EXTERN_C USHORT g_wMajorVerSdspatch = 1;
  8. EXTERN_C USHORT g_wMinorVerSdspatch = 0;
  9. // This isn't a typical delay load since it's called only if wininet
  10. // is already loaded in memory. Otherwise the call is dropped on the floor.
  11. // Defview did it this way I assume to keep WININET out of first boot time.
  12. BOOL MyInternetSetOption(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2)
  13. {
  14. BOOL bRet = FALSE;
  15. HMODULE hmod = GetModuleHandle(TEXT("wininet.dll"));
  16. if (hmod)
  17. {
  18. typedef BOOL (*PFNINTERNETSETOPTIONA)(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2);
  19. PFNINTERNETSETOPTIONA fp = (PFNINTERNETSETOPTIONA)GetProcAddress(hmod, "InternetSetOptionA");
  20. if (fp)
  21. {
  22. bRet = fp(h, dw1, lpv, dw2);
  23. }
  24. }
  25. return bRet;
  26. }
  27. // REVIEW: maybe just check (hwnd == GetShellWindow())
  28. STDAPI_(BOOL) IsDesktopWindow(HWND hwnd)
  29. {
  30. TCHAR szName[80];
  31. GetClassName(hwnd, szName, ARRAYSIZE(szName));
  32. if (!lstrcmp(szName, TEXT(STR_DESKTOPCLASS)))
  33. {
  34. return hwnd == GetShellWindow();
  35. }
  36. return FALSE;
  37. }
  38. // returns:
  39. // S_OK returned if the .htt (web view template) file associated with the folder we're viewing is trusted
  40. // S_FALSE or
  41. // E_ACCESSDENIED bad... don't expose local machine access
  42. STDAPI IsSafePage(IUnknown *punkSite)
  43. {
  44. // Return S_FALSE if we don't have a host site since we have no way of doing a
  45. // security check. This is as far as VB 5.0 apps get.
  46. if (!punkSite)
  47. return S_FALSE;
  48. HRESULT hr = E_ACCESSDENIED;
  49. // There are two safe cases:
  50. // 1) we are contained by a signed MD5 hashed defview template.
  51. // 2) we are contained by a .html file that's on the Local Zone
  52. //
  53. // Case 1) find the template path from webview...
  54. VARIANT vPath = {0};
  55. hr = IUnknown_QueryServiceExec(punkSite, SID_DefView, &CGID_DefView, DVCMDID_GETTEMPLATEDIRNAME, 0, NULL, &vPath);
  56. if (SUCCEEDED(hr))
  57. {
  58. if (vPath.vt == VT_BSTR && vPath.bstrVal)
  59. {
  60. WCHAR wszPath[MAX_PATH];
  61. DWORD cchPath = ARRAYSIZE(wszPath);
  62. if (S_OK != PathCreateFromUrlW(vPath.bstrVal, wszPath, &cchPath, 0))
  63. {
  64. // it might not be an URL, in this case it is a file path
  65. StrCpyNW(wszPath, vPath.bstrVal, ARRAYSIZE(wszPath));
  66. }
  67. // it might not be an URL, in this case it is a file path
  68. // allow intranet if this is hosted under defview
  69. hr = SHRegisterValidateTemplate(wszPath, SHRVT_VALIDATE | SHRVT_ALLOW_INTRANET | SHRVT_PROMPTUSER | SHRVT_REGISTERIFPROMPTOK);
  70. }
  71. VariantClear(&vPath);
  72. }
  73. else
  74. {
  75. IUnknown* punkToFree = NULL;
  76. // Case 2) ask the browser, for example we are in a .HTM doc
  77. BOOL fFound = FALSE;
  78. do
  79. {
  80. IBrowserService* pbs;
  81. hr = IUnknown_QueryService(punkSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &pbs));
  82. if (SUCCEEDED(hr))
  83. {
  84. LPITEMIDLIST pidl;
  85. hr = pbs->GetPidl(&pidl);
  86. if (SUCCEEDED(hr))
  87. {
  88. WCHAR wszPath[MAX_PATH];
  89. DWORD dwAttribs = SFGAO_FOLDER;
  90. hr = SHGetNameAndFlagsW(pidl, SHGDN_FORPARSING, wszPath, ARRAYSIZE(wszPath), &dwAttribs);
  91. if (dwAttribs & SFGAO_FOLDER)
  92. {
  93. // A folder is not a .HTM file, so continue on up...
  94. ATOMICRELEASE(punkToFree);
  95. hr = IUnknown_GetSite(pbs, IID_PPV_ARG(IUnknown, &punkToFree)); // gotta start with pbs's parent (otherwise you'll get the same pbs again)
  96. if (FAILED(hr)) // to get by the weboc you need to explicitly ask for the oc's parent:
  97. {
  98. hr = IUnknown_QueryService(pbs, SID_QIClientSite, IID_PPV_ARG(IUnknown, &punkToFree));
  99. }
  100. punkSite = punkToFree;
  101. }
  102. else
  103. {
  104. // Found the nearest containing non-folder object.
  105. fFound = TRUE;
  106. hr = LocalZoneCheckPath(wszPath, punkSite); // check for local zone
  107. }
  108. ILFree(pidl);
  109. }
  110. pbs->Release();
  111. }
  112. } while (SUCCEEDED(hr) && !fFound);
  113. ATOMICRELEASE(punkToFree);
  114. }
  115. if (S_OK != hr)
  116. {
  117. hr = E_ACCESSDENIED;
  118. }
  119. return hr;
  120. }
  121. HRESULT HrSHGetValue(IN HKEY hKey, IN LPCTSTR pszSubKey, OPTIONAL IN LPCTSTR pszValue, OPTIONAL OUT LPDWORD pdwType,
  122. OPTIONAL OUT LPVOID pvData, OPTIONAL OUT LPDWORD pcbData)
  123. {
  124. DWORD dwError = SHGetValue(hKey, pszSubKey, pszValue, pdwType, pvData, pcbData);
  125. return HRESULT_FROM_WIN32(dwError);
  126. }
  127. STDAPI SHPropertyBag_WritePunk(IN IPropertyBag * pPropertyPage, IN LPCWSTR pwzPropName, IN IUnknown * punk)
  128. {
  129. HRESULT hr = E_INVALIDARG;
  130. if (pPropertyPage && pwzPropName)
  131. {
  132. VARIANT va;
  133. va.vt = VT_UNKNOWN;
  134. va.punkVal = punk;
  135. hr = pPropertyPage->Write(pwzPropName, &va);
  136. }
  137. return hr;
  138. }
  139. BOOL _GetRegValueString(HKEY hKey, LPCTSTR pszValName, LPTSTR pszString, int cchSize)
  140. {
  141. DWORD cbSize = sizeof(pszString[0]) * cchSize;
  142. DWORD dwType;
  143. DWORD dwError = SHQueryValueEx(hKey, pszValName, NULL, &dwType, (LPBYTE)pszString, &cbSize);
  144. return (ERROR_SUCCESS == dwError);
  145. }
  146. //------------------------------------------------------------------------------------
  147. //
  148. // IconSet/GetRegValueString()
  149. //
  150. // Versions of Get/SetRegValueString that go to the user classes section.
  151. //
  152. // Returns: success of string setting / retrieval
  153. //
  154. //------------------------------------------------------------------------------------
  155. BOOL IconSetRegValueString(const CLSID* pclsid, LPCTSTR lpszSubKey, LPCTSTR lpszValName, LPCTSTR lpszValue)
  156. {
  157. HKEY hkey;
  158. if (SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, TRUE, TRUE, &hkey)))
  159. {
  160. DWORD dwRet = SHRegSetPath(hkey, NULL, lpszValName, lpszValue, 0);
  161. RegCloseKey(hkey);
  162. return (dwRet == ERROR_SUCCESS);
  163. }
  164. return FALSE;
  165. }
  166. BOOL _IconGetRegValueString(BOOL fDisplayName, const CLSID* pclsid, LPCTSTR lpszSubKey, LPCTSTR lpszValName, LPTSTR lpszValue, int cchValue)
  167. {
  168. HKEY hkey;
  169. if (SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, TRUE, FALSE, &hkey)) ||
  170. SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, FALSE, FALSE, &hkey)))
  171. {
  172. BOOL fRet;
  173. if (fDisplayName)
  174. {
  175. fRet = SUCCEEDED(SHLoadLegacyRegUIString(hkey, NULL, lpszValue, cchValue));
  176. }
  177. else
  178. {
  179. fRet = _GetRegValueString(hkey, lpszValName, lpszValue, cchValue);
  180. }
  181. RegCloseKey(hkey);
  182. return fRet;
  183. }
  184. return FALSE;
  185. }
  186. BOOL IconGetRegNameString(const CLSID* pclsid, LPTSTR lpszValue, int cchValue)
  187. {
  188. return _IconGetRegValueString(TRUE, pclsid, NULL, NULL, lpszValue, cchValue);
  189. }
  190. // lpszValName is used if there are multiple icons ("full" and "empty" for recycle bin)
  191. BOOL IconGetRegIconString(const CLSID* pclsid, LPCTSTR lpszValName, LPTSTR lpszValue, int cchValue)
  192. {
  193. return _IconGetRegValueString(FALSE, pclsid, TEXT("DefaultIcon"), lpszValName, lpszValue, cchValue);
  194. }
  195. BOOL CALLBACK Cabinet_RefreshEnum(HWND hwnd, LPARAM lParam)
  196. {
  197. if (IsFolderWindow(hwnd) || IsExplorerWindow(hwnd))
  198. {
  199. PostMessage(hwnd, WM_COMMAND, FCIDM_REFRESH, lParam);
  200. }
  201. return(TRUE);
  202. }
  203. BOOL CALLBACK Cabinet_UpdateWebViewEnum(HWND hwnd, LPARAM lParam)
  204. {
  205. if (IsFolderWindow(hwnd) || IsExplorerWindow(hwnd))
  206. {
  207. // A value of -1L for lParam will force a refresh by loading the View window
  208. // with the new VID as specified in the global DefFolderSettings.
  209. PostMessage(hwnd, WM_COMMAND, SFVIDM_MISC_SETWEBVIEW, lParam);
  210. }
  211. return(TRUE);
  212. }
  213. void Cabinet_RefreshAll(WNDENUMPROC lpEnumFunc, LPARAM lParam)
  214. {
  215. HWND hwnd = FindWindowEx(NULL, NULL, TEXT(STR_DESKTOPCLASS), NULL);
  216. if (hwnd)
  217. PostMessage(hwnd, WM_COMMAND, FCIDM_REFRESH, 0L);
  218. hwnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
  219. if (hwnd)
  220. PostMessage(hwnd, TM_REFRESH, 0, 0L);
  221. EnumWindows(lpEnumFunc, lParam);
  222. }