Source code of Windows XP (NT5)
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.

142 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1998-99 Microsoft Corporation
  3. Module Name:
  4. wincelic.h
  5. Abstract:
  6. Author:
  7. Fred Chong (FredCh) 7/1/1998
  8. Environment:
  9. Notes:
  10. --*/
  11. #include <dbgapi.h>
  12. #define assert(x) ASSERT(x)
  13. #define MAX_COMPUTERNAME_LENGTH 15
  14. #ifdef HARDCODED_USER_NAME
  15. #define WBT_USER_NAME "Windows Term"
  16. #define WBT_USER_NAME_LEN (sizeof(WBT_USER_NAME))
  17. #else
  18. #include <winsock.h>
  19. #include <license.h>
  20. #include <cryptkey.h>
  21. // Two hex characters for each byte, plus null terminator
  22. #define HWID_STR_LEN (sizeof(HWID) * 2 + 1)
  23. #define BAD_HARDCODED_NAME1 "WBT"
  24. #define BAD_HARDCODED_NAME2 "WinCE"
  25. #endif
  26. static BOOL GetUserName(
  27. LPSTR lpBuffer, // address of name buffer
  28. LPDWORD nSize // address of size of name buffer
  29. )
  30. {
  31. #ifdef HARDCODED_USER_NAME
  32. if (*nSize < WBT_USER_NAME_LEN) {
  33. *nSize = WBT_USER_NAME_LEN;
  34. return FALSE;
  35. }
  36. *nSize = WBT_USER_NAME_LEN;
  37. strcpy(lpBuffer, WBT_USER_NAME);
  38. return TRUE;
  39. #else
  40. CHAR achHostName[MAX_PATH+1];
  41. BOOL fReturn = FALSE;
  42. HWID hwid;
  43. DWORD cchName;
  44. // get the host name of the device
  45. if (0 == gethostname( achHostName, sizeof(achHostName) ))
  46. {
  47. // Check for bad hardcoded values
  48. if ((0 == strcmp(achHostName,BAD_HARDCODED_NAME1))
  49. || (0 == strcmp(achHostName,BAD_HARDCODED_NAME2)))
  50. {
  51. goto use_uuid;
  52. }
  53. // gethostname success
  54. cchName = strlen(achHostName);
  55. if (*nSize <= cchName)
  56. {
  57. *nSize = (cchName + 1);
  58. return FALSE;
  59. }
  60. strcpy(lpBuffer,achHostName);
  61. return TRUE;
  62. }
  63. use_uuid:
  64. // Can't get hostname
  65. if (*nSize >= HWID_STR_LEN)
  66. {
  67. // Use UUID instead
  68. if (LICENSE_STATUS_OK == GenerateClientHWID(&hwid))
  69. {
  70. sprintf(lpBuffer,
  71. "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
  72. (hwid.dwPlatformID & 0xFF000000) >> 24,
  73. (hwid.dwPlatformID & 0x00FF0000) >> 16,
  74. (hwid.dwPlatformID & 0x0000FF00) >> 8,
  75. hwid.dwPlatformID & 0x000000FF,
  76. (hwid.Data1 & 0xFF000000) >> 24,
  77. (hwid.Data1 & 0x00FF0000) >> 16,
  78. (hwid.Data1 & 0x0000FF00) >> 8,
  79. hwid.Data1 & 0x000000FF,
  80. (hwid.Data2 & 0xFF000000) >> 24,
  81. (hwid.Data2 & 0x00FF0000) >> 16,
  82. (hwid.Data2 & 0x0000FF00) >> 8,
  83. hwid.Data2 & 0x000000FF,
  84. (hwid.Data3 & 0xFF000000) >> 24,
  85. (hwid.Data3 & 0x00FF0000) >> 16,
  86. (hwid.Data3 & 0x0000FF00) >> 8,
  87. hwid.Data3 & 0x000000FF,
  88. (hwid.Data4 & 0xFF000000) >> 24,
  89. (hwid.Data4 & 0x00FF0000) >> 16,
  90. (hwid.Data4 & 0x0000FF00) >> 8,
  91. hwid.Data4 & 0x000000FF
  92. );
  93. fReturn = TRUE;
  94. }
  95. }
  96. *nSize = HWID_STR_LEN;
  97. return fReturn;
  98. #endif
  99. }
  100. #define GetComputerName GetUserName