#BUGFIX by stefan
class: Win32OperatingSystem class
added: #primGetComputerName:
changed:
#getDomainName
#getHostName
anser 'unknown' for unknown domain name (as described in the comment)
--- a/Win32OperatingSystem.st Thu Feb 20 08:59:29 2020 +0100
+++ b/Win32OperatingSystem.st Fri Feb 21 12:01:56 2020 +0100
@@ -8968,42 +8968,28 @@
getDomainName
"return the DNS domain this host is in.
Notice:
- not all systems support this; on some, 'unknown' is returned."
-
- |domainName idx hostName|
+ not all systems support this; on some, 'unknown' is returned."
+
+ |domainName|
DomainName notNil ifTrue:[
- ^ DomainName
- ].
-
- "/ sometimes, we can extract the domainName from the hostName ...
- hostName := self getHostName.
- hostName notEmptyOrNil ifTrue:[
- idx := hostName indexOf:$..
- idx ~~ 0 ifTrue:[
- domainName := hostName copyFrom:idx+1.
- ]
- ].
-
- domainName isNil ifTrue:[
- domainName := self getEnvironment:'DOMAIN'.
- domainName isNil ifTrue:[
- domainName := self getEnvironment:'DOMAINNAME'.
- ].
-
- domainName isNil ifTrue:[
- "/ ok, search the registry ...
- "/ under NT and later, it is found there ...
- domainName := RegistryEntry
- key:'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'
- valueNamed:'Domain'.
- ].
-
- domainName isNil ifTrue:[
- ^ 'unknown'.
- ].
- DomainName := domainName. "cache only, if it is fixed"
- ].
+ ^ DomainName
+ ].
+
+ domainName := self primGetComputerName:2.
+
+ domainName isEmptyOrNil ifTrue:[
+ domainName := self getEnvironment:'DOMAIN'.
+ domainName isNil ifTrue:[
+ domainName := self getEnvironment:'DOMAINNAME'.
+ ].
+ ].
+
+ domainName isEmptyOrNil ifTrue:[
+ ^ 'unknown'.
+ ].
+ DomainName := domainName. "cache only, if it is fixed"
+
^ domainName
"
@@ -9012,8 +8998,8 @@
OperatingSystem getHostName
"
- "Modified: / 26-04-1996 / 10:04:54 / stefan"
"Modified: / 16-05-2019 / 18:11:23 / Stefan Vogel"
+ "Modified: / 20-02-2020 / 21:40:23 / stefan"
!
getEnvironment
@@ -9129,34 +9115,15 @@
getHostName
"return the hostname we are running on
- - if possible, the fully qualified host name."
-
- |hostName|
-
-%{ /* STACK: 2048 */
-#if defined(__MINGW32__)
- char bufferA[512];
- DWORD buffSize = sizeof(bufferA);
-#else
- WCHAR buffer[512];
- DWORD buffSize = sizeof(buffer)/sizeof(buffer[0]);
-#endif
-
- // Note: GetComputerNameExA can fail in certain locales!
-#if defined(__MINGW32__)
- if (GetComputerNameA(bufferA, &buffSize) == TRUE) {
- RETURN(__MKSTRING_L(bufferA, buffSize));
- }
-#else
- if (GetComputerNameExW(ComputerNameDnsFullyQualified, buffer, &buffSize) == TRUE) {
- RETURN(__mkStringOrU16String_maxlen(buffer, buffSize));
- }
-#endif
-%}.
+ - if possible (usually not), the fully qualified host name."
+
+ ^ self primGetComputerName:3
"
OperatingSystem getHostName
"
+
+ "Modified: / 20-02-2020 / 21:34:21 / stefan"
!
getLanguage
@@ -10327,6 +10294,48 @@
"Modified: 20.6.1997 / 17:37:26 / cg"
!
+primGetComputerName:whatEnum
+ "return the domain or hostname we are running on:
+ typedef enum _COMPUTER_NAME_FORMAT {
+ ComputerNameNetBIOS, // 0
+ ComputerNameDnsHostname, // 1
+ ComputerNameDnsDomain, // 2
+ ComputerNameDnsFullyQualified, // 3
+ ComputerNamePhysicalNetBIOS,
+ ComputerNamePhysicalDnsHostname,
+ ComputerNamePhysicalDnsDomain,
+ ComputerNamePhysicalDnsFullyQualified,
+ ComputerNameMax // 7
+ } COMPUTER_NAME_FORMAT; "
+
+%{ /* STACK: 2048 */
+ // Note: GetComputerNameExA can fail in certain locales!
+#if 0 && defined(__MINGW32__)
+ char bufferA[512];
+ DWORD buffSize = sizeof(bufferA);
+
+ if (GetComputerNameA(bufferA, &buffSize) == TRUE) {
+ RETURN(__MKSTRING_L(bufferA, buffSize));
+ }
+#else
+ WCHAR buffer[512];
+ DWORD buffSize = sizeof(buffer)/sizeof(buffer[0]);
+
+ if (GetComputerNameExW((COMPUTER_NAME_FORMAT)__intVal(whatEnum), buffer, &buffSize) == TRUE) {
+ RETURN(__mkStringOrU16String_maxlen(buffer, buffSize));
+ }
+#endif
+%}.
+
+ "
+ 0 to: 7 collect:[:i|
+ OperatingSystem primGetComputerName:i
+ ]
+ "
+
+ "Modified: / 20-02-2020 / 21:50:38 / stefan"
+!
+
randomBytesInto:bufferOrInteger
"If bufferOrInteger is a String or a ByteArray,
fill a given buffer with random bytes from the RtlGenRandom function