From d3c33f2bc8e77d768a8c5afee3b589fb1a761ce9 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Wed, 1 Mar 2000 19:03:33 +0000 Subject: [PATCH] not part of the build yet. --- xpfe/appshell/src/nsUserInfoUnix.cpp | 27 ++++++++++++++++--- .../components/startup/src/nsUserInfoUnix.cpp | 27 ++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/xpfe/appshell/src/nsUserInfoUnix.cpp b/xpfe/appshell/src/nsUserInfoUnix.cpp index b0a15691d6c..93c7a42c70d 100644 --- a/xpfe/appshell/src/nsUserInfoUnix.cpp +++ b/xpfe/appshell/src/nsUserInfoUnix.cpp @@ -91,15 +91,34 @@ nsUserInfo::GetUsername(char * *aUsername) NS_IMETHODIMP nsUserInfo::GetDomain(char * *aDomain) { + nsresult rv = NS_ERROR_FAILURE; + struct utsname buf; if (uname(&buf)) { - return NS_ERROR_FAILURE; + return rv; } - *aDomain = nsCRT::strdup(buf.__domainname); - - return NS_OK; + + if (buf.__domainname && nsCRT::strlen(buf.__domainname)) { + *aDomain = nsCRT::strdup(buf.__domainname); + rv = NS_OK; + } + else { + // try to get the hostname from the nodename + // on machines that use DHCP, domainname may not be set + // but the nodename might. + if (buf.nodename && nsCRT::strlen(buf.nodename)) { + // if the nodename is foo.bar.org, use bar.org as the domain + char *pos = strchr(buf.nodename,'.'); + if (pos) { + *aDomain = nsCRT::strdup(pos+1); + rv = NS_OK; + } + } + } + + return rv; } NS_IMETHODIMP diff --git a/xpfe/components/startup/src/nsUserInfoUnix.cpp b/xpfe/components/startup/src/nsUserInfoUnix.cpp index b0a15691d6c..93c7a42c70d 100644 --- a/xpfe/components/startup/src/nsUserInfoUnix.cpp +++ b/xpfe/components/startup/src/nsUserInfoUnix.cpp @@ -91,15 +91,34 @@ nsUserInfo::GetUsername(char * *aUsername) NS_IMETHODIMP nsUserInfo::GetDomain(char * *aDomain) { + nsresult rv = NS_ERROR_FAILURE; + struct utsname buf; if (uname(&buf)) { - return NS_ERROR_FAILURE; + return rv; } - *aDomain = nsCRT::strdup(buf.__domainname); - - return NS_OK; + + if (buf.__domainname && nsCRT::strlen(buf.__domainname)) { + *aDomain = nsCRT::strdup(buf.__domainname); + rv = NS_OK; + } + else { + // try to get the hostname from the nodename + // on machines that use DHCP, domainname may not be set + // but the nodename might. + if (buf.nodename && nsCRT::strlen(buf.nodename)) { + // if the nodename is foo.bar.org, use bar.org as the domain + char *pos = strchr(buf.nodename,'.'); + if (pos) { + *aDomain = nsCRT::strdup(pos+1); + rv = NS_OK; + } + } + } + + return rv; } NS_IMETHODIMP