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.

121 lines
3.7 KiB

  1. // RevokedUtil.cpp : Implementation of WMDMUtil library
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <oleAuto.h>
  6. #include <WMDMUtil.h>
  7. // BUGBUG Update this to the revocation site after the issues are resolved.
  8. #define REVOCATION_UPDATE_URL L"http://www.microsoft.com/isapi/redir.dll?prd=wmdm&pver=7&os=win"
  9. #define MAX_PARAMETERLEN sizeof(L"&SubjectID0=4294967295")
  10. #define MAX_LCIDLEN sizeof(L"&LCID=4294967295")
  11. #ifdef _M_IX86
  12. // Get the subject id out of an APPCERT
  13. DWORD GetSubjectIDFromAppCert( IN APPCERT appcert )
  14. {
  15. DWORD dwSubjectID;
  16. BYTE* pSubjectID = appcert.appcd.subject;
  17. dwSubjectID = pSubjectID[3]
  18. + pSubjectID[2] * 0x100
  19. + pSubjectID[1] * 0x10000
  20. + pSubjectID[0] * 0x1000000;
  21. return dwSubjectID;
  22. }
  23. #endif
  24. // Is this URL pointing to the Microsoft Revocatoin update server?
  25. BOOL IsMicrosoftRevocationURL( LPWSTR pszRevocationURL )
  26. {
  27. HRESULT hr = S_FALSE;
  28. BOOL bMSUrl = FALSE;
  29. int iBaseURLChars = (sizeof( REVOCATION_UPDATE_URL ) / sizeof(WCHAR)) -1;
  30. // Does the URL start with the MS base URL?
  31. if( pszRevocationURL && wcsncmp( REVOCATION_UPDATE_URL, pszRevocationURL, iBaseURLChars ) == 0 )
  32. {
  33. bMSUrl = TRUE;
  34. }
  35. return bMSUrl;
  36. }
  37. // Max posible length of update URL
  38. #define MAX_UPDATE_URL_LENGHT sizeof(REVOCATION_UPDATE_URL) + 3*MAX_PARAMETERLEN + MAX_LCIDLEN
  39. // Build the revocation update URL from base URL + SubjectID's as parameters
  40. // Revoked subject id's are passed in in an NULL-terminated array
  41. HRESULT BuildRevocationURL(IN DWORD* pdwSubjectIDs,
  42. IN OUT LPWSTR* ppwszRevocationURL,
  43. IN OUT DWORD* pdwBufferLen ) // Length in wchars of buffer (including 0 term)
  44. {
  45. HRESULT hr = S_OK;
  46. WCHAR pszOutURL[MAX_UPDATE_URL_LENGHT];
  47. int iStrPos = 0; // Were are we at in the string
  48. int iSubjectIDIndex = 0; // Looping throw all SubjectID's in the pdwSubjectIDs array
  49. if( ppwszRevocationURL == NULL || pdwBufferLen == NULL )
  50. {
  51. hr = E_POINTER;
  52. goto Error;
  53. }
  54. // Start creating the string by writing the base URL
  55. wcscpy( pszOutURL, REVOCATION_UPDATE_URL );
  56. iStrPos = (sizeof(REVOCATION_UPDATE_URL) /sizeof(WCHAR)) -1;
  57. // Add all subject id's as parameters to the URL
  58. for( iSubjectIDIndex = 0; pdwSubjectIDs[iSubjectIDIndex]; iSubjectIDIndex ++ )
  59. {
  60. int iCharsWritten;
  61. // Add subject id as parameter to URL
  62. iCharsWritten = swprintf( pszOutURL + iStrPos, L"&SubjectID%d=%d",
  63. iSubjectIDIndex,
  64. pdwSubjectIDs[iSubjectIDIndex] );
  65. iStrPos += iCharsWritten;
  66. }
  67. // Add LCID parameter to specify UI/component default language.
  68. {
  69. int iCharsWritten;
  70. DWORD dwLCID;
  71. dwLCID = (DWORD)GetSystemDefaultLCID();
  72. iCharsWritten = swprintf( pszOutURL + iStrPos, L"&LCID=%d", dwLCID );
  73. iStrPos += iCharsWritten;
  74. }
  75. // Do we need to reallocate the string buffer passed in?
  76. if( *pdwBufferLen < (DWORD)(iStrPos +1))
  77. {
  78. // Allocate bigger buffer
  79. *pdwBufferLen = (iStrPos +1);
  80. CoTaskMemFree( *ppwszRevocationURL );
  81. *ppwszRevocationURL = (LPWSTR)CoTaskMemAlloc( (iStrPos+1)*sizeof(WCHAR) );
  82. if( *ppwszRevocationURL == NULL )
  83. {
  84. hr = E_OUTOFMEMORY;
  85. goto Error;
  86. }
  87. }
  88. // Copy string into buffer
  89. wcscpy( *ppwszRevocationURL, pszOutURL );
  90. Error:
  91. return hr;
  92. }