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.

114 lines
2.7 KiB

  1. #include "precomp.h"
  2. extern BOOL g_fDemo, g_fKeyGood;
  3. extern BOOL g_fBranded, g_fIntranet;
  4. extern BOOL g_fSilent;
  5. extern int g_iKeyType;
  6. // Note: this function is also in ..\keymaker\keymake.c so make changes in both places
  7. void MakeKey(LPTSTR pszSeed, BOOL fCorp)
  8. {
  9. int i;
  10. DWORD dwKey;
  11. CHAR szKeyA[5];
  12. CHAR szSeedA[16];
  13. // always do the keycode create in ANSI
  14. T2Abux(pszSeed, szSeedA);
  15. i = lstrlenA(szSeedA);
  16. if (i < 6)
  17. {
  18. // extend the input seed to 6 characters
  19. for (; i < 6; i++)
  20. szSeedA[i] = (char)('0' + i);
  21. }
  22. // let's calculate the DWORD key used for the last 4 chars of keycode
  23. // multiply by my first name
  24. dwKey = szSeedA[0] * 'O' + szSeedA[1] * 'L' + szSeedA[2] * 'I' +
  25. szSeedA[3] * 'V' + szSeedA[4] * 'E' + szSeedA[5] * 'R';
  26. // multiply the result by JONCE
  27. dwKey *= ('J' + 'O' + 'N' + 'C' + 'E');
  28. dwKey %= 10000;
  29. if (fCorp)
  30. {
  31. // give a separate keycode based on corp flag or not
  32. // 9 is chosen because is is a multiplier such that for any x,
  33. // (x+214) * 9 != x + 10000y
  34. // we have 8x = 10000y - 1926 which when y=1 gives us 8x = 8074
  35. // since 8074 is not divisible by 8 where guaranteed to be OK since
  36. // the number on the right can only increase by 10000 increments which
  37. // are always divisible by 8
  38. dwKey += ('L' + 'E' + 'E');
  39. dwKey *= 9;
  40. dwKey %= 10000;
  41. }
  42. wsprintfA(szKeyA, "%04lu", dwKey);
  43. StrCpyA(&szSeedA[6], szKeyA);
  44. A2Tbux(szSeedA, pszSeed);
  45. }
  46. BOOL CheckKey(LPTSTR pszKey)
  47. {
  48. TCHAR szBaseKey[16];
  49. CharUpper(pszKey);
  50. StrCpy(szBaseKey, pszKey);
  51. g_fDemo = g_fKeyGood = FALSE;
  52. g_iKeyType = KEY_TYPE_STANDARD;
  53. // check for MS key code
  54. if (StrCmpI(pszKey, TEXT("MICROSO800")) == 0)
  55. {
  56. g_fKeyGood = TRUE;
  57. return TRUE;
  58. }
  59. // check for ISP key code
  60. MakeKey(szBaseKey, FALSE);
  61. if (StrCmpI(szBaseKey, pszKey) == 0)
  62. {
  63. g_iKeyType = KEY_TYPE_SUPER;
  64. g_fKeyGood = TRUE;
  65. g_fBranded = TRUE;
  66. g_fIntranet = g_fSilent = FALSE;
  67. return TRUE;
  68. }
  69. // check for a corp key code
  70. MakeKey(szBaseKey, TRUE);
  71. if (StrCmpI(szBaseKey, pszKey) == 0)
  72. {
  73. g_iKeyType = KEY_TYPE_SUPERCORP;
  74. g_fKeyGood = TRUE;
  75. g_fBranded = TRUE;
  76. g_fIntranet = TRUE;
  77. return TRUE;
  78. }
  79. // check for demo key code
  80. if (StrCmpNI(pszKey, TEXT("DEMO"), 4) == 0 && lstrlen(pszKey) > 9)
  81. {
  82. g_fDemo = TRUE;
  83. return TRUE;
  84. }
  85. return FALSE;
  86. }