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.

328 lines
8.7 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // Computer naming tool
  4. //
  5. // 12-1-97 sburns
  6. #ifndef COMPUTER_HPP_INCLUDED
  7. #define COMPUTER_HPP_INCLUDED
  8. // An object representing the name, domain membership state, and other
  9. // interesting properties of a machine.
  10. class Computer
  11. {
  12. public:
  13. // Constructs a new instance. The new instance is not usable until the
  14. // Refresh method is called.
  15. //
  16. // name - name of the computer. May have leading backslashes. May be
  17. // an IP address, DNS, or NetBIOS computer name. empty means the local
  18. // computer.
  19. explicit
  20. Computer(const String& name = String());
  21. ~Computer();
  22. // Returns the NetBIOS name of the computer.
  23. String
  24. GetNetbiosName() const;
  25. // Returns the Fully-Qualified DNS name of the computer, taking into
  26. // account the policy-imposed DNS suffix (if any). Returns the empty
  27. // string if the computer does not have a DNS name (most likely because
  28. // TCP/IP is not installed or properly configured on the machine).
  29. String
  30. GetFullDnsName() const;
  31. // Returns the DNS name of the domain the computer is joined to, or the
  32. // empty string if the computer is not joined to a DS domain.
  33. String
  34. GetDomainDnsName() const;
  35. // Returns the NetBIOS name of the domain the computer is joined to, if
  36. // the computer is joined to a domain, or the NetBIOS name of the
  37. // workgroup the computer is joined to, if the computer is joined to a
  38. // workgroup. See IsJoinedToDomain(), IsJoinedToWorkgroup().
  39. String
  40. GetDomainNetbiosName() const;
  41. // Returns the name of the forest the machine is joined to, or the empty
  42. // string if the machine is not joined to a DS domain.
  43. //
  44. // (The forest name is the dns domain name of the first domain in the
  45. // forest.)
  46. String
  47. GetForestDnsName() const;
  48. // Returns the major version number of the operating system the machine is
  49. // running. For Windows NT 4, this is 4. For Windows 2000, this is 5.
  50. DWORD
  51. GetOsMajorVersion() const;
  52. // Returns the minor version number of the operating system the machine is
  53. // running.
  54. DWORD
  55. GetOsMinorVersion() const;
  56. enum Role
  57. {
  58. STANDALONE_WORKSTATION = DsRole_RoleStandaloneWorkstation,
  59. MEMBER_WORKSTATION = DsRole_RoleMemberWorkstation,
  60. STANDALONE_SERVER = DsRole_RoleStandaloneServer,
  61. MEMBER_SERVER = DsRole_RoleMemberServer,
  62. PRIMARY_CONTROLLER = DsRole_RolePrimaryDomainController,
  63. BACKUP_CONTROLLER = DsRole_RoleBackupDomainController
  64. };
  65. // Returns a value indicating the role of the computer. This value is
  66. // always the "true" role of the computer, regardless of the safe boot
  67. // mode of the computer.
  68. Role
  69. GetRole() const;
  70. // Returns true if the machine is a domain controller, false if not.
  71. bool
  72. IsDomainController() const;
  73. // Returns true if the instance refers to the local computer, false if
  74. // it refers to another computer on the network. "Local Computer" means
  75. // the computer on which this process is running.
  76. bool
  77. IsLocal() const;
  78. // Returns true if the machine is joined to any domain, false if not.
  79. // (Note that IsJoinedToWorgroup == !IsJoinedToDomain, and vice-versa).
  80. bool
  81. IsJoinedToDomain() const;
  82. // Returns true if the machine is joined to the given DS domain, false if
  83. // not -- the machine is joined to a non-DS domain, not joined to a domain,
  84. // or joined to a DS domain of another name.
  85. //
  86. // domainDnsName - DNS name of the domain to test membership against.
  87. bool
  88. IsJoinedToDomain(const String& domainDnsName) const;
  89. // Returns true if the machine is joined to any workgroup, false if not.
  90. // (Note that IsJoinedToWorgroup == !IsJoinedToDomain, and vice-versa).
  91. //
  92. // If this function returns true, then the name returned by
  93. // GetDomainNetbiosName is actually the name of the workgroup.
  94. bool
  95. IsJoinedToWorkgroup() const;
  96. // Re-evaluates all computer info. Returns S_OK if all info was refreshed,
  97. // or a standard error code if not. Typical errors include access denied
  98. // and network path not found.
  99. HRESULT
  100. Refresh();
  101. //
  102. // static functions
  103. //
  104. // Combines the hostname and suffix to form a fully-qualified DNS computer
  105. // name, and returns that result. E.g. hostname.dns.domain.suffix.com
  106. //
  107. // hostname - the hostname component of the name. This string should not
  108. // be empty.
  109. //
  110. // domainSuffix - the DNS domain suffix portion of the name. This portion
  111. // may be empty, in which case the hostname is considered to be in the root
  112. // domain ".". Or the suffix may be a single "." to indicate the root
  113. // domain. Or the suffix may be a more typical sequence of labels
  114. // separated by "."
  115. static
  116. String
  117. ComposeFullDnsComputerName(
  118. const String& hostname,
  119. const String& domainSuffix);
  120. // Retreives the netbios computer name that is currently in effect.
  121. static
  122. String
  123. GetActivePhysicalNetbiosName();
  124. // Retreives the fully-qualified DNS computer name that is currently in
  125. // effect. May return the empty string if no DNS name exists (e.g. tcp/ip
  126. // is not installed).
  127. static
  128. String
  129. GetActivePhysicalFullDnsName();
  130. // Retreives the netbios computer name that will take effect upon next
  131. // reboot, or the current active name if no name change is pending.
  132. static
  133. String
  134. GetFuturePhysicalNetbiosName();
  135. // Retreives the fully-qualified DNS computer name that will be in effect
  136. // when the computer is rebooted. If a future name is not set, then the
  137. // result is the current active name (as that will still be the name in the
  138. // future). Can return the empty string if the active name is not set
  139. // either (e.g. tcp/ip is not installed)
  140. static
  141. String
  142. GetFuturePhysicalFullDnsName();
  143. // Determine the safeboot option that the machine is currently running
  144. // under, or return 0 if the machine is running in normal boot mode.
  145. // Returns S_OK on success, or an error code on failure.
  146. //
  147. // regHKLM - HKEY previously opened to the HKEY_LOCAL_MACHINE hive of a
  148. // remote computer, or the special HKEY value of HKEY_LOCAL_MACHINE to
  149. // evaluate the result for the local computer.
  150. //
  151. // result - the safeboot option. See sdk\inc\safeboot.h for the possible
  152. // values.
  153. static
  154. HRESULT
  155. GetSafebootOption(HKEY regHKLM, DWORD& result);
  156. // Returns the product type like RtlGetNtProductType, except that the value
  157. // is read directly from the registry. This is preferred to
  158. // RtlGetNtProductType, because when booted in safe mode,
  159. // RtlGetNtProductType is caused to lie such that a DC returns a result as
  160. // though it were a normal server. Returns S_OK on success, or an error
  161. // code on failure.
  162. //
  163. // regHKLM - HKEY previously opened to the HKEY_LOCAL_MACHINE hive of a
  164. // remote computer, or the special HKEY value of HKEY_LOCAL_MACHINE to
  165. // evaluate the result for the local computer.
  166. //
  167. // result - the product type code.
  168. static
  169. HRESULT
  170. GetProductTypeFromRegistry(HKEY regHLKM, NT_PRODUCT_TYPE& result);
  171. // Determine if the Dns suffix portion of the local computer name is forced
  172. // to be a certain value by policy. If so, return true. If the
  173. // determination cannot be made, or if the policy is not in effect, return
  174. // false.
  175. //
  176. // policyDnsSuffix - out, if there is a policy in effect, this parameter
  177. // will receive the suffix (which may be the empty string).
  178. static
  179. bool
  180. IsDnsSuffixPolicyInEffect(String& policyDnsSuffix);
  181. // Removes the leading backslashes from a UNC-style computer name, if
  182. // present, and returns the result. For example, a name "\\mycomputer"
  183. // would be returned as "mycomputer".
  184. //
  185. // computerName - the name from which leading backslashes are to be
  186. // removed. If this name does not have leading backslashes, then this name
  187. // is returned.
  188. static
  189. String
  190. RemoveLeadingBackslashes(const String& computerName);
  191. private:
  192. // not implemented
  193. Computer(const Computer& c);
  194. const Computer& operator=(const Computer& c);
  195. friend struct ComputerState;
  196. String ctorName;
  197. bool isRefreshed;
  198. ComputerState* state;
  199. };
  200. #endif // COMPUTER_HPP_INCLUDED