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.

132 lines
3.4 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // Tab state helper
  4. //
  5. // 3-12-98 sburns
  6. #include "precomp.h"
  7. #include "headers.hxx"
  8. #include "settings.h"
  9. #include "resource.h"
  10. #include "common.h"
  11. // Caller needs to delete info with ::DsRoleFreeMemory.
  12. static DWORD myDsRoleGetPrimaryDomainInformation(
  13. DSROLE_PRIMARY_DOMAIN_INFO_BASIC*& info)
  14. {
  15. TRACE_FUNCTION(myDsRoleGetPrimaryDomainInformation);
  16. BYTE* buffer = 0;
  17. info = 0;
  18. TRACE(TEXT("Calling DsRoleGetPrimaryDomainInformation"));
  19. DWORD err =
  20. ::DsRoleGetPrimaryDomainInformation(
  21. 0, // this server
  22. DsRolePrimaryDomainInfoBasic,
  23. &buffer);
  24. TRACE(String::format(TEXT("Error 0x%1!X! (!0 => error)"), err));
  25. if (err == NO_ERROR)
  26. {
  27. info = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC*) buffer;
  28. assert(info);
  29. TRACE(String::format(TEXT("MachineRole : %1!d!"), info->MachineRole));
  30. TRACE(String::format(TEXT("Flags : 0x%1!X!"), info->Flags));
  31. TRACE(String::format(TEXT("DomainNameFlat: %1"), info->DomainNameFlat));
  32. TRACE(String::format(TEXT("DomainNameDns : %1"), info->DomainNameDns));
  33. TRACE(String::format(TEXT("DomainTreeName: %1"), info->DomainTreeName));
  34. }
  35. return err;
  36. }
  37. void Settings::Refresh()
  38. {
  39. String unknown = String::load(IDS_UNKNOWN);
  40. ComputerPrimaryDomainDNSName = unknown;
  41. DomainDNSName = unknown;
  42. FullComputerName = unknown;
  43. NetBIOSComputerName = unknown;
  44. NetBIOSDomainName = unknown;
  45. ShortComputerName = unknown;
  46. SyncDNSNames = true; // @@ read from registry
  47. JoinedToWorkgroup = true;
  48. DSROLE_PRIMARY_DOMAIN_INFO_BASIC* info = 0;
  49. DWORD err = myDsRoleGetPrimaryDomainInformation(info);
  50. if (err == NO_ERROR)
  51. {
  52. // this is the workgroup name iff JoinedToWorkgroup == true
  53. NetBIOSDomainName = info->DomainNameFlat;
  54. DomainDNSName = info->DomainNameDns;
  55. switch (info->MachineRole)
  56. {
  57. case DsRole_RoleBackupDomainController:
  58. case DsRole_RolePrimaryDomainController:
  59. {
  60. machine_is_dc = true;
  61. JoinedToWorkgroup = false;
  62. break;
  63. }
  64. case DSRole_RoleStandaloneWorkstation:
  65. case DsRole_RoleStandaloneServer:
  66. {
  67. machine_is_dc = false;
  68. JoinedToWorkgroup = true;
  69. if (NetBIOSDomainName.empty())
  70. {
  71. NetBIOSDomainName =
  72. String::load(IDS_DEFAULT_WORKGROUP);
  73. }
  74. break;
  75. }
  76. case DsRole_RoleMemberWorkstation:
  77. case DsRole_RoleMemberServer:
  78. {
  79. machine_is_dc = false;
  80. JoinedToWorkgroup = false;
  81. break;
  82. }
  83. default:
  84. {
  85. assert(false);
  86. break;
  87. }
  88. }
  89. ::DsRoleFreeMemory(info);
  90. }
  91. else
  92. {
  93. AppError(0, HRESULT_FROM_WIN32(err),
  94. String::load(IDS_ERROR_READING_MEMBERSHIP));
  95. }
  96. // @@ call GetComputerNameEx here...
  97. NetBIOSComputerName = Win::GetComputerNameFromRegistry();
  98. ShortComputerName = NetBIOSComputerName;
  99. if (!JoinedToWorkgroup)
  100. {
  101. ComputerPrimaryDomainDNSName = DomainDNSName;
  102. FullComputerName =
  103. ShortComputerName
  104. + TEXT(".")
  105. + ComputerPrimaryDomainDNSName;
  106. }
  107. }