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.

207 lines
5.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: uihlpr.cpp
  8. //
  9. // History: Created - DSIE April 9, 2001
  10. //
  11. //--------------------------------------------------------------------------
  12. #include "global.hxx"
  13. //+-------------------------------------------------------------------------
  14. // Check to see if a specified URL is http scheme.
  15. //--------------------------------------------------------------------------
  16. BOOL
  17. WINAPI
  18. IsHttpUrlA(
  19. IN LPCTSTR pszUrlString
  20. )
  21. {
  22. BOOL bResult = FALSE;
  23. if (pszUrlString)
  24. {
  25. LPWSTR pwszUrlString = NULL;
  26. if (pwszUrlString = new WCHAR[strlen(pszUrlString) + 1])
  27. {
  28. MultiByteToWideChar(0, 0, (const char *) pszUrlString, -1, pwszUrlString, strlen(pszUrlString) + 1);
  29. bResult = IsHttpUrlW(pwszUrlString) ;
  30. delete [] pwszUrlString;
  31. }
  32. }
  33. return bResult;
  34. }
  35. BOOL
  36. WINAPI
  37. IsHttpUrlW(
  38. IN LPCWSTR pwszUrlString
  39. )
  40. {
  41. BOOL bResult = FALSE;
  42. if (pwszUrlString)
  43. {
  44. URL_COMPONENTSW urlComponents;
  45. ZeroMemory(&urlComponents, sizeof(urlComponents));
  46. urlComponents.dwStructSize = sizeof(urlComponents);
  47. if (InternetCrackUrlW(pwszUrlString, lstrlenW(pwszUrlString), 0, &urlComponents))
  48. {
  49. if (INTERNET_SCHEME_HTTP == urlComponents.nScheme || INTERNET_SCHEME_HTTPS == urlComponents.nScheme)
  50. {
  51. bResult = TRUE;
  52. }
  53. }
  54. }
  55. return bResult;
  56. }
  57. //+-------------------------------------------------------------------------
  58. // Check to see if a specified string should be formatted as link based on
  59. // severity of error code, and internet scheme of the string.
  60. //--------------------------------------------------------------------------
  61. BOOL
  62. WINAPI
  63. IsOKToFormatAsLinkA(
  64. IN LPSTR pszUrlString,
  65. IN DWORD dwErrorCode
  66. )
  67. {
  68. BOOL bResult = FALSE;
  69. if (pszUrlString)
  70. {
  71. LPWSTR pwszUrlString = NULL;
  72. if (pwszUrlString = new WCHAR[strlen(pszUrlString) + 1])
  73. {
  74. MultiByteToWideChar(0, 0, (const char *) pszUrlString, -1, pwszUrlString, strlen(pszUrlString) + 1);
  75. bResult = IsOKToFormatAsLinkW(pwszUrlString, dwErrorCode) ;
  76. delete [] pwszUrlString;
  77. }
  78. }
  79. return bResult;
  80. }
  81. BOOL
  82. WINAPI
  83. IsOKToFormatAsLinkW(
  84. IN LPWSTR pwszUrlString,
  85. IN DWORD dwErrorCode
  86. )
  87. {
  88. BOOL bResult = FALSE;
  89. switch (dwErrorCode)
  90. {
  91. case 0:
  92. case CERT_E_EXPIRED:
  93. case CERT_E_PURPOSE:
  94. case CERT_E_WRONG_USAGE:
  95. case CERT_E_CN_NO_MATCH:
  96. case CERT_E_INVALID_NAME:
  97. case CERT_E_INVALID_POLICY:
  98. case CERT_E_REVOCATION_FAILURE:
  99. case CRYPT_E_NO_REVOCATION_CHECK:
  100. case CRYPT_E_REVOCATION_OFFLINE:
  101. {
  102. #if (0)
  103. bResult = IsHttpUrlW(pwszUrlString);
  104. #else
  105. bResult = TRUE;
  106. #endif
  107. break;
  108. }
  109. }
  110. return bResult;
  111. }
  112. //+-------------------------------------------------------------------------
  113. // Return the display name for a cert. Caller must free the string by
  114. // free().
  115. //--------------------------------------------------------------------------
  116. LPWSTR
  117. WINAPI
  118. GetDisplayNameString(
  119. IN PCCERT_CONTEXT pCertContext,
  120. IN DWORD dwFlags
  121. )
  122. {
  123. DWORD cchNameString = 0;
  124. LPWSTR pwszNameString = NULL;
  125. DWORD DisplayTypes[] = {CERT_NAME_SIMPLE_DISPLAY_TYPE,
  126. CERT_NAME_FRIENDLY_DISPLAY_TYPE,
  127. CERT_NAME_EMAIL_TYPE,
  128. CERT_NAME_DNS_TYPE,
  129. CERT_NAME_UPN_TYPE};
  130. if (NULL == pCertContext)
  131. {
  132. goto InvalidArgError;
  133. }
  134. for (int i = 0; i < (sizeof(DisplayTypes) / sizeof(DisplayTypes[0])); i++)
  135. {
  136. cchNameString = 0;
  137. pwszNameString = NULL;
  138. cchNameString = CertGetNameStringW(pCertContext,
  139. DisplayTypes[i],
  140. dwFlags,
  141. NULL,
  142. pwszNameString,
  143. 0);
  144. if (1 < cchNameString)
  145. {
  146. if (NULL == (pwszNameString = (LPWSTR) malloc(cchNameString * sizeof(WCHAR))))
  147. {
  148. goto OutOfMemoryError;
  149. }
  150. ZeroMemory(pwszNameString, cchNameString * sizeof(WCHAR));
  151. CertGetNameStringW(pCertContext,
  152. DisplayTypes[i],
  153. dwFlags,
  154. NULL,
  155. pwszNameString,
  156. cchNameString);
  157. break;
  158. }
  159. }
  160. CommonReturn:
  161. return pwszNameString;
  162. ErrorReturn:
  163. if (NULL != pwszNameString)
  164. {
  165. free(pwszNameString);
  166. pwszNameString = NULL;
  167. }
  168. goto CommonReturn;
  169. SET_ERROR(InvalidArgError, E_INVALIDARG);
  170. SET_ERROR(OutOfMemoryError, E_OUTOFMEMORY);
  171. }