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.

312 lines
7.8 KiB

  1. // IEInstallCtrl.cpp : Implementation of CIEInstallCtrl
  2. #include "stdafx.h"
  3. #include "ieinst.h"
  4. #include "IEInstallCtrl.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CIEInstallCtrl
  7. HRESULT CIEInstallCtrl::OnDraw(ATL_DRAWINFO& di)
  8. {
  9. RECT& rc = *(RECT*)di.prcBounds;
  10. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  11. DrawText(di.hdcDraw, _T("ATL 2.0"), -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  12. return S_OK;
  13. }
  14. BOOL ChrCmpA_inline(WORD w1, WORD wMatch)
  15. {
  16. /* Most of the time this won't match, so test it first for speed.
  17. */
  18. if (LOBYTE(w1) == LOBYTE(wMatch))
  19. {
  20. if (IsDBCSLeadByte(LOBYTE(w1)))
  21. {
  22. return(w1 != wMatch);
  23. }
  24. return FALSE;
  25. }
  26. return TRUE;
  27. }
  28. LPSTR FAR ANSIStrChr(LPCSTR lpStart, WORD wMatch)
  29. {
  30. for ( ; *lpStart; lpStart = CharNext(lpStart))
  31. {
  32. // (ChrCmp returns FALSE when characters match)
  33. if (!ChrCmpA_inline(*(UNALIGNED WORD FAR *)lpStart, wMatch))
  34. return((LPSTR)lpStart);
  35. }
  36. return (NULL);
  37. }
  38. LPSTR FAR ANSIStrRChr(LPCSTR lpStart, WORD wMatch)
  39. {
  40. LPCSTR lpFound = NULL;
  41. for ( ; *lpStart; lpStart = CharNext(lpStart))
  42. {
  43. // (ChrCmp returns FALSE when characters match)
  44. if (!ChrCmpA_inline(*(UNALIGNED WORD FAR *)lpStart, wMatch))
  45. lpFound = lpStart;
  46. }
  47. return ((LPSTR)lpFound);
  48. }
  49. PathRemoveFileSpec(
  50. LPSTR pFile)
  51. {
  52. LPSTR pT;
  53. LPSTR pT2 = pFile;
  54. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  55. if (*pT2 == '\\')
  56. pT = pT2; // last "\" found, (we will strip here)
  57. else if (*pT2 == ':') { // skip ":\" so we don't
  58. if (pT2[1] =='\\') // strip the "\" from "C:\"
  59. pT2++;
  60. pT = pT2 + 1;
  61. }
  62. }
  63. if (*pT == 0)
  64. return FALSE; // didn't strip anything
  65. //
  66. // handle the \foo case
  67. //
  68. else if ((pT == pFile) && (*pT == '\\')) {
  69. // Is it just a '\'?
  70. if (*(pT+1) != '\0') {
  71. // Nope.
  72. *(pT+1) = '\0';
  73. return TRUE; // stripped something
  74. }
  75. else {
  76. // Yep.
  77. return FALSE;
  78. }
  79. }
  80. else {
  81. *pT = 0;
  82. return TRUE; // stripped something
  83. }
  84. }
  85. void Strip(LPSTR pszUrl)
  86. {
  87. char szTemp[MAX_PATH] ;
  88. int tempPtr=0, pathPtr=0 ;
  89. while (pszUrl[pathPtr])
  90. {
  91. if (pszUrl[pathPtr] == '%')
  92. {
  93. int value = 0 ;
  94. pathPtr++ ;
  95. while (pszUrl[pathPtr] && ((pszUrl[pathPtr] >= '0') && (pszUrl[pathPtr] <= '9')))
  96. {
  97. value = (value * 0x10) + (pszUrl[pathPtr] - '0') ;
  98. pathPtr++ ;
  99. }
  100. szTemp[tempPtr++] = (char)value;
  101. }
  102. else
  103. {
  104. szTemp[tempPtr++] = pszUrl[pathPtr++] ;
  105. }
  106. }
  107. szTemp[tempPtr] = pszUrl[pathPtr] ;
  108. lstrcpy(pszUrl, szTemp) ;
  109. }
  110. BOOL CompareDirs(LPCSTR pcszDir1, LPCSTR pcszDir2)
  111. {
  112. char szDir1[MAX_PATH];
  113. char szDir2[MAX_PATH];
  114. if (GetShortPathName(pcszDir1, szDir1, sizeof(szDir1)) && GetShortPathName(pcszDir2, szDir2, sizeof(szDir2))
  115. && (lstrcmpi(szDir1, szDir2) == 0))
  116. return TRUE;
  117. return FALSE;
  118. }
  119. BOOL CheckSignupDir(LPCSTR pcszFile)
  120. {
  121. char szIEPath[MAX_PATH];
  122. char szFilePath[MAX_PATH];
  123. DWORD dwSize;
  124. HKEY hkAppPaths;
  125. dwSize = sizeof(szIEPath);
  126. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe",
  127. 0, KEY_READ, &hkAppPaths) != ERROR_SUCCESS)
  128. return FALSE;
  129. if (RegQueryValueEx(hkAppPaths, "Path", 0, NULL, (LPBYTE)&szIEPath, &dwSize) != ERROR_SUCCESS)
  130. {
  131. RegCloseKey(hkAppPaths);
  132. return FALSE;
  133. }
  134. RegCloseKey(hkAppPaths);
  135. if (szIEPath[lstrlen(szIEPath)-1] == ';')
  136. szIEPath[lstrlen(szIEPath)-1] = '\0';
  137. if (szIEPath[lstrlen(szIEPath)-1] == '\\')
  138. szIEPath[lstrlen(szIEPath)-1] = '\0';
  139. lstrcat(szIEPath, "\\signup");
  140. lstrcpy(szFilePath, pcszFile);
  141. PathRemoveFileSpec(szFilePath);
  142. // check that we are writing to a file in the signup dir
  143. if (!CompareDirs(szIEPath, szFilePath))
  144. return FALSE;
  145. return TRUE;
  146. }
  147. STDMETHODIMP CIEInstallCtrl::SetInterfaceSafetyOptions(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
  148. {
  149. CComBSTR strURL;
  150. char szURL[INTERNET_MAX_URL_LENGTH];
  151. char cBack;
  152. LPSTR pPtr, pSlash;
  153. ATLTRACE(_T("IObjectSafetyImpl::SetInterfaceSafetyOptions\n"));
  154. USES_CONVERSION;
  155. // check to make sure it's a file://<drive letter> URL that we're being hosted on
  156. CComPtr<IOleContainer> spContainer;
  157. m_spClientSite->GetContainer(&spContainer);
  158. CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spDoc(spContainer);
  159. if (spDoc)
  160. spDoc->get_URL(&strURL);
  161. else
  162. return E_NOINTERFACE;
  163. lstrcpy(szURL, OLE2A(strURL));
  164. Strip(szURL);
  165. cBack = szURL[7];
  166. szURL[7] = '\0';
  167. if (lstrcmpi(szURL, "file://") != 0)
  168. return E_NOINTERFACE;
  169. szURL[7] = cBack;
  170. pPtr = &szURL[7];
  171. while (*pPtr == '/')
  172. pPtr++;
  173. pSlash = pPtr;
  174. while (pSlash = ANSIStrChr(pSlash, '/'))
  175. *pSlash = '\\';
  176. if (!CheckSignupDir(pPtr))
  177. return E_FAIL;
  178. // If we're being asked to set our safe for scripting option then oblige
  179. if (riid == IID_IDispatch )
  180. {
  181. // Store our current safety level to return in GetInterfaceSafetyOptions
  182. m_dwSafety = dwEnabledOptions & dwOptionSetMask;
  183. return S_OK;
  184. }
  185. return E_NOINTERFACE;
  186. }
  187. STDMETHODIMP CIEInstallCtrl::Insert(BSTR Header, BSTR Name, BSTR Value, BSTR InsFilename, long *lRet)
  188. {
  189. char szFile[MAX_PATH];
  190. char szHeader[128];
  191. char szValueName[128];
  192. char szValue[256];
  193. LPSTR pszPtr;
  194. USES_CONVERSION;
  195. lstrcpyn(szFile, OLE2A(InsFilename), MAX_PATH);
  196. // check for .ins extension
  197. if (!(pszPtr = ANSIStrRChr(szFile, '.')) || lstrcmpi(pszPtr, ".ins"))
  198. return E_FAIL;
  199. for (pszPtr = szFile; *pszPtr; pszPtr++)
  200. {
  201. if (*pszPtr == '/')
  202. *pszPtr = '\\';
  203. }
  204. if (!CheckSignupDir(szFile))
  205. return E_FAIL;
  206. lstrcpyn(szFile, OLE2A(InsFilename), MAX_PATH);
  207. // only write to existing ins files
  208. if (GetFileAttributes(szFile) == 0xFFFFFFFF)
  209. return E_FAIL;
  210. for (pszPtr = szFile; *pszPtr; pszPtr++)
  211. {
  212. if (*pszPtr == '/')
  213. *pszPtr = '\\';
  214. }
  215. lstrcpyn(szHeader, OLE2A(Header), 128);
  216. lstrcpyn(szValueName, OLE2A(Name), 128);
  217. lstrcpyn(szValue, OLE2A(Value), 256 - lstrlen(szValueName));
  218. *lRet = WritePrivateProfileString(szHeader, szValueName, szValue, szFile);
  219. return S_OK;
  220. }
  221. STDMETHODIMP CIEInstallCtrl::WorkingDir(BSTR bstrPath, BSTR *bstrDir)
  222. {
  223. char cBack;
  224. char szPath[MAX_PATH];
  225. char szURL[MAX_PATH*2];
  226. LPSTR pPath, pSlash, pUrl;
  227. USES_CONVERSION;
  228. lstrcpyn(szURL, OLE2A(bstrPath), MAX_PATH);
  229. Strip(szURL);
  230. cBack = szURL[7];
  231. szURL[7] = '\0';
  232. if (lstrcmpi(szURL, "file://") != 0)
  233. szPath[0] = '\0';
  234. else
  235. {
  236. szURL[7] = cBack;
  237. pUrl = &szURL[7];
  238. while (*pUrl == '/')
  239. pUrl++;
  240. if (ANSIStrChr(pUrl, ':') || (pUrl[0] == '\\'))
  241. lstrcpyn(szPath, pUrl, MAX_PATH);
  242. else
  243. {
  244. lstrcpy(szPath, "\\\\");
  245. pPath = &szPath[2];
  246. lstrcpyn(pPath, pUrl, MAX_PATH - 2);
  247. }
  248. pSlash = szPath;
  249. while (pSlash = ANSIStrChr(pSlash, '/'))
  250. *pSlash = '\\';
  251. PathRemoveFileSpec(szPath);
  252. }
  253. *bstrDir = A2BSTR(szPath);
  254. return S_OK;
  255. }