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.

122 lines
3.8 KiB

  1. //Copyright (c) 1998 - 2001 Microsoft Corporation
  2. #ifndef _WIN32_WINNT
  3. #define _WIN32_WINNT 0x0500
  4. #endif
  5. #include <windows.h>
  6. #include <wincrypt.h>
  7. #include <stdio.h>
  8. #include <tchar.h>
  9. #include "DigPid1.h"
  10. #include "PidGen.h"
  11. #include "ValidDP.h"
  12. #include "LicenseCodeLite.h"
  13. #include "SequenceRanges.h"
  14. #define GROUP12TXT _TEXT("06")
  15. #define GROUP14TXT _TEXT("07")
  16. #define GROUP0TXT _TEXT("00")
  17. DWORD GetLCProductType(TCHAR * tcLicenceCode, TCHAR ** tcProductType, DWORD * dwGroupID)
  18. {
  19. BOOL fOk = false; // success flag
  20. TCHAR *pszMpc= _TEXT("12345"); // 5 numeral Microsoft Product Code
  21. TCHAR szPid2[32]; // Microsoft Product ID
  22. BYTE abPid3[DIGITALPIDMAXLEN]; // new Digital Product ID
  23. DWORD dwSeq = 0; // 9 digit sequence number
  24. BOOL fOEM = FALSE; // [IN] Is this an OEM Product Key, default to Retail
  25. BOOL fCCP = FALSE; // [OUT] Compliance Checking Product (Is upgrade?)
  26. DWORD dwPge; // PidGenError
  27. DWORD dwSearchLoop;
  28. TCHAR * tcGroupId;
  29. DWORD dwRetVal = ERROR_SUCCESS;
  30. szPid2[0] = _TEXT('\0');
  31. // Must set the first DWORD of abPid3 to the total length of the
  32. // buffer. On return the first DWORD will be set the the length
  33. // actually used.
  34. *(LPDWORD)abPid3 = sizeof(abPid3);
  35. // Both Unicode and ANSI versions of PIDGenSimp are supported
  36. #ifdef UNICODE
  37. // return value is a PidGenError (see PidGen.h)
  38. dwPge = PIDGenStatic(
  39. tcLicenceCode, // [IN] 25-character Secure CD-Key (gets U-Cased)
  40. pszMpc, // [IN] 5-character Microsoft Product Code
  41. L"", // [IN] Stock Keeping Unit (formatted like 123-12345)
  42. NULL, // [IN] 4-character OEM ID or NULL
  43. NULL, // [IN] pointer to optional public key or NULL
  44. 0, // [IN] byte length of optional public key
  45. 0, // [IN] key pair index optional public key
  46. fOEM, // [IN] is this an OEM install?
  47. szPid2, // [OUT] PID 2.0, pass in ptr to 24 character array
  48. abPid3, // [IN/OUT] pointer to binary PID3 buffer.
  49. &dwSeq, // [OUT] optional ptr to sequence number (can be NULL)
  50. NULL); // [OUT] ptr to Compliance Checking flag or NULL
  51. #else
  52. // return value is a PidGenError (see PidGen.h)
  53. dwPge = PIDGenStatic(
  54. tcLicenceCode, // [IN] 25-character Secure CD-Key (gets U-Cased)
  55. pszMpc, // [IN] 5-character Microsoft Product Code
  56. "", // [IN] Stock Keeping Unit (formatted like 123-12345)
  57. NULL, // [IN] 4-character OEM ID or NULL
  58. fOEM, // [IN] is this an OEM install?
  59. szPid2, // [OUT] PID 2.0, pass in ptr to 24 character array
  60. abPid3, // [IN/OUT] pointer to binary PID3 buffer.
  61. &dwSeq, // [OUT] optional ptr to sequence number (can be NULL)
  62. NULL); // [OUT] ptr to Compliance Checking flag or NULL
  63. #endif
  64. if (pgeSuccess != dwPge)
  65. {
  66. dwRetVal = INVALID_PRODUCT_KEY;
  67. goto done;
  68. }
  69. //Using the PID2 object generated by PIDGen determine the GroupID
  70. //The ValidDP12.lib provides the PIDGen interface and is configured for only Group 12 and 0.
  71. tcGroupId = szPid2+18;
  72. if (!_tcsncmp( tcGroupId, GROUP12TXT, 2 ))
  73. {
  74. *dwGroupID = 12;
  75. }
  76. else if (!_tcsncmp( tcGroupId, GROUP0TXT, 2 ))
  77. {
  78. *dwGroupID = 0;
  79. }
  80. else if(!_tcsncmp( tcGroupId, GROUP14TXT, 2 ))
  81. {
  82. *dwGroupID = 14;
  83. }
  84. else
  85. {
  86. *dwGroupID = -1;
  87. dwRetVal = INVALID_GROUP_ID;
  88. goto done;
  89. }
  90. //Check if the sequence number falls into one of the predefined product type ranges.
  91. for (dwSearchLoop = 0; dwSearchLoop < RANGE_SIZE; dwSearchLoop++)
  92. {
  93. if (g_ProductTypeRanges[dwSearchLoop].dwRangeStart <= dwSeq &&
  94. g_ProductTypeRanges[dwSearchLoop].dwRangeEnd >= dwSeq)
  95. {
  96. *tcProductType = g_ProductTypeRanges[dwSearchLoop].szProductType;
  97. fOk = true;
  98. break;
  99. }
  100. }
  101. if (!fOk)
  102. dwRetVal = INVALID_SERIAL_NUMBER;
  103. done:
  104. return dwRetVal;
  105. }