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.

337 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: linkutil.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. //////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. //////////////////////////////////////////////////////////////////////////////////////
  16. void CryptuiGoLink(HWND hwndParent, char *pszWhere, BOOL fNoCOM)
  17. {
  18. HCURSOR hcursPrev = NULL;
  19. HMODULE hURLMon = NULL;
  20. BOOL fCallCoUnInit = FALSE;
  21. //
  22. // since we're a model dialog box, we want to go behind IE once it comes up!!!
  23. //
  24. SetWindowPos(hwndParent, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  25. hcursPrev = SetCursor(LoadCursor(NULL, IDC_WAIT));
  26. __try
  27. {
  28. hURLMon = (HMODULE)LoadLibraryU(L"urlmon.dll");
  29. if (!(hURLMon) || fNoCOM)
  30. {
  31. //
  32. // The hyperlink module is unavailable, go to fallback plan
  33. //
  34. //
  35. // This works in test cases, but causes deadlock problems when used from withing
  36. // the Internet Explorer itself. The dialog box is up (that is, IE is in a modal
  37. // dialog loop) and in comes this DDE request...).
  38. //
  39. ShellExecute(hwndParent, "open", pszWhere, NULL, NULL, SW_SHOWNORMAL);
  40. }
  41. else
  42. {
  43. //
  44. // The hyperlink module is there. Use it
  45. //
  46. if (SUCCEEDED(CoInitialize(NULL))) // Init OLE if no one else has
  47. {
  48. fCallCoUnInit = TRUE;
  49. //
  50. // allow com to fully init...
  51. //
  52. MSG msg;
  53. PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); // peek but not remove
  54. typedef void (WINAPI *pfnHlinkSimpleNavigateToString)(LPCWSTR, LPCWSTR, LPCWSTR, IUnknown *,
  55. IBindCtx *, IBindStatusCallback *,
  56. DWORD, DWORD);
  57. pfnHlinkSimpleNavigateToString pProcAddr;
  58. pProcAddr = (pfnHlinkSimpleNavigateToString)GetProcAddress(hURLMon, TEXT("HlinkSimpleNavigateToString"));
  59. if (pProcAddr)
  60. {
  61. WCHAR *pwszWhere;
  62. IBindCtx *pbc;
  63. pwszWhere = new WCHAR[strlen(pszWhere) + 1];
  64. if (pwszWhere == NULL)
  65. {
  66. return;
  67. }
  68. MultiByteToWideChar(0, 0, (const char *)pszWhere, -1, pwszWhere, strlen(pszWhere) + 1);
  69. pbc = NULL;
  70. CreateBindCtx( 0, &pbc );
  71. (*pProcAddr)(pwszWhere, NULL, NULL, NULL, pbc, NULL, HLNF_OPENINNEWWINDOW, NULL);
  72. if (pbc)
  73. {
  74. pbc->Release();
  75. }
  76. delete [] pwszWhere;
  77. }
  78. CoUninitialize();
  79. }
  80. FreeLibrary(hURLMon);
  81. }
  82. SetCursor(hcursPrev);
  83. }
  84. __except(EXCEPTION_EXECUTE_HANDLER)
  85. {
  86. if (hURLMon != NULL)
  87. {
  88. FreeLibrary(hURLMon);
  89. }
  90. if (fCallCoUnInit)
  91. {
  92. CoUninitialize();
  93. }
  94. if (hcursPrev != NULL)
  95. {
  96. SetCursor(hcursPrev);
  97. }
  98. }
  99. }
  100. //////////////////////////////////////////////////////////////////////////////////////
  101. //
  102. //////////////////////////////////////////////////////////////////////////////////////
  103. BOOL AllocAndGetIssuerURL(LPSTR *ppURLString, PCCERT_CONTEXT pCertContext)
  104. {
  105. PCERT_EXTENSION pExt = NULL;
  106. PSPC_SP_AGENCY_INFO pInfo = NULL;
  107. DWORD cbInfo = 0;
  108. PCERT_ALT_NAME_ENTRY pAltName = NULL;
  109. DWORD cbAltName = 0;
  110. *ppURLString = NULL;
  111. //
  112. // first look for the Agency Info extension and see if it has an URL
  113. //
  114. if ((pExt = CertFindExtension(SPC_SP_AGENCY_INFO_OBJID, pCertContext->pCertInfo->cExtension,
  115. pCertContext->pCertInfo->rgExtension)))
  116. {
  117. CryptDecodeObject(X509_ASN_ENCODING, SPC_SP_AGENCY_INFO_STRUCT,
  118. pExt->Value.pbData, pExt->Value.cbData, 0, NULL,
  119. &cbInfo);
  120. if (!(pInfo = (PSPC_SP_AGENCY_INFO) malloc(cbInfo)))
  121. {
  122. return FALSE;
  123. }
  124. if (!(CryptDecodeObject(X509_ASN_ENCODING, SPC_SP_AGENCY_INFO_STRUCT,
  125. pExt->Value.pbData, pExt->Value.cbData, 0, pInfo,
  126. &cbInfo)))
  127. {
  128. free(pInfo);
  129. return FALSE;
  130. }
  131. if (!(pInfo->pPolicyInformation))
  132. {
  133. free(pInfo);
  134. return FALSE;
  135. }
  136. switch (pInfo->pPolicyInformation->dwLinkChoice)
  137. {
  138. case SPC_URL_LINK_CHOICE:
  139. if (NULL != (*ppURLString =
  140. (LPSTR) malloc(wcslen(pInfo->pPolicyInformation->pwszUrl)+1)))
  141. {
  142. WideCharToMultiByte(
  143. 0,
  144. 0,
  145. pInfo->pPolicyInformation->pwszUrl,
  146. -1,
  147. *ppURLString,
  148. wcslen(pInfo->pPolicyInformation->pwszUrl)+1,
  149. NULL,
  150. NULL);
  151. free(pInfo);
  152. return TRUE;
  153. }
  154. else
  155. {
  156. free(pInfo);
  157. return FALSE;
  158. }
  159. break;
  160. case SPC_FILE_LINK_CHOICE:
  161. if (NULL != (*ppURLString =
  162. (LPSTR) malloc(wcslen(pInfo->pPolicyInformation->pwszFile)+1)))
  163. {
  164. WideCharToMultiByte(
  165. 0,
  166. 0,
  167. pInfo->pPolicyInformation->pwszFile,
  168. -1,
  169. *ppURLString,
  170. wcslen(pInfo->pPolicyInformation->pwszFile)+1,
  171. NULL,
  172. NULL);
  173. return TRUE;
  174. }
  175. else
  176. {
  177. free(pInfo);
  178. return FALSE;
  179. }
  180. break;
  181. }
  182. free(pInfo);
  183. }
  184. //
  185. // if there was no Agency Info extension or it didn't contain an URL,
  186. // look for the Authority Info Access Syntax extension
  187. //
  188. /*if ((pExt = CertFindExtension(SPC_SP_AGENCY_INFO_OBJID, pCertContext->pCertInfo->cExtension,
  189. pCertContext->pCertInfo->rgExtension)))
  190. {
  191. FIX FIX
  192. }*/
  193. //
  194. // finally, if there was no Agency Info and no Authority Info Access Syntax
  195. // check to see if there is an Alternate Name extension
  196. //
  197. if ((pExt = CertFindExtension(szOID_ISSUER_ALT_NAME, pCertContext->pCertInfo->cExtension,
  198. pCertContext->pCertInfo->rgExtension)))
  199. {
  200. CryptDecodeObject(X509_ASN_ENCODING, szOID_ISSUER_ALT_NAME,
  201. pExt->Value.pbData, pExt->Value.cbData, 0, NULL,
  202. &cbAltName);
  203. if (!(pAltName = (PCERT_ALT_NAME_ENTRY) malloc(cbAltName)))
  204. {
  205. return FALSE;
  206. }
  207. if (!(CryptDecodeObject(X509_ASN_ENCODING, szOID_ISSUER_ALT_NAME,
  208. pExt->Value.pbData, pExt->Value.cbData, 0, pAltName,
  209. &cbAltName)))
  210. {
  211. free(pAltName);
  212. return FALSE;
  213. }
  214. if (pAltName->dwAltNameChoice == CERT_ALT_NAME_URL)
  215. {
  216. if (NULL != (*ppURLString = (LPSTR) malloc(wcslen(pAltName->pwszURL)+1)))
  217. {
  218. WideCharToMultiByte(
  219. 0,
  220. 0,
  221. pAltName->pwszURL,
  222. -1,
  223. *ppURLString,
  224. wcslen(pAltName->pwszURL)+1,
  225. NULL,
  226. NULL);
  227. free(pAltName);
  228. return TRUE;
  229. }
  230. }
  231. free(pAltName);
  232. }
  233. return FALSE;
  234. }
  235. //////////////////////////////////////////////////////////////////////////////////////
  236. //
  237. //////////////////////////////////////////////////////////////////////////////////////
  238. BOOL AllocAndGetSubjectURL(LPSTR *ppURLString, PCCERT_CONTEXT pCertContext)
  239. {
  240. PCERT_EXTENSION pExt = NULL;
  241. PCERT_ALT_NAME_ENTRY pAltName = NULL;
  242. DWORD cbAltName = 0;
  243. *ppURLString = NULL;
  244. //
  245. // check to see if there is an Alternate Name extension
  246. //
  247. if ((pExt = CertFindExtension(szOID_SUBJECT_ALT_NAME, pCertContext->pCertInfo->cExtension,
  248. pCertContext->pCertInfo->rgExtension)))
  249. {
  250. CryptDecodeObject(X509_ASN_ENCODING, szOID_SUBJECT_ALT_NAME,
  251. pExt->Value.pbData, pExt->Value.cbData, 0, NULL,
  252. &cbAltName);
  253. if (!(pAltName = (PCERT_ALT_NAME_ENTRY) malloc(cbAltName)))
  254. {
  255. return FALSE;
  256. }
  257. if (!(CryptDecodeObject(X509_ASN_ENCODING, szOID_SUBJECT_ALT_NAME,
  258. pExt->Value.pbData, pExt->Value.cbData, 0, pAltName,
  259. &cbAltName)))
  260. {
  261. free(pAltName);
  262. return FALSE;
  263. }
  264. if (pAltName->dwAltNameChoice == CERT_ALT_NAME_URL)
  265. {
  266. if (NULL != (*ppURLString = (LPSTR) malloc(wcslen(pAltName->pwszURL)+1)))
  267. {
  268. WideCharToMultiByte(
  269. 0,
  270. 0,
  271. pAltName->pwszURL,
  272. -1,
  273. *ppURLString,
  274. wcslen(pAltName->pwszURL)+1,
  275. NULL,
  276. NULL);
  277. free(pAltName);
  278. return TRUE;
  279. }
  280. }
  281. free(pAltName);
  282. }
  283. return FALSE;
  284. }