From 5650853485b2fce29f24eb847b4a8b11f0bcbe9f Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Wed, 1 Mar 2000 05:55:19 +0000 Subject: [PATCH] not part of the build yet. --- xpfe/appshell/src/nsUserInfoUnix.cpp | 70 ++++++++++++++++--- .../components/startup/src/nsUserInfoUnix.cpp | 70 ++++++++++++++++--- 2 files changed, 122 insertions(+), 18 deletions(-) diff --git a/xpfe/appshell/src/nsUserInfoUnix.cpp b/xpfe/appshell/src/nsUserInfoUnix.cpp index 8d1d4ec2f60e..35ad8d87ccce 100644 --- a/xpfe/appshell/src/nsUserInfoUnix.cpp +++ b/xpfe/appshell/src/nsUserInfoUnix.cpp @@ -27,7 +27,10 @@ #include #include #include +#include + #include "nsString.h" +#include "nsXPIDLString.h" nsUserInfo::nsUserInfo() { @@ -45,12 +48,14 @@ nsUserInfo::GetFullname(PRUnichar **aFullname) { struct passwd *pw = nsnull; - pw = getpwuid (geteuid ()); + pw = getpwuid (geteuid()); + + // do I need to free pw? if (!pw || !pw->pw_gecos) return NS_ERROR_FAILURE; #ifdef DEBUG_sspitzer - printf("name = %s\n", pw->pw_gecos); + printf("fullname = %s\n", pw->pw_gecos); #endif nsAutoString fullname(pw->pw_gecos); @@ -63,18 +68,65 @@ nsUserInfo::GetFullname(PRUnichar **aFullname) return NS_ERROR_FAILURE; } -NS_IMETHODIMP GetEmailAddress(char * *aEmailAddress) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP GetUsername(char * *aUsername) { - return NS_ERROR_NOT_IMPLEMENTED; + struct passwd *pw = nsnull; + + pw = getpwuid(geteuid()); + + // do I need to free pw? + + if (!pw || !pw->pw_name) return NS_ERROR_FAILURE; + +#ifdef DEBUG_sspitzer + printf("username = %s\n", pw->pw_name); +#endif + + *aUsername = nsCRT::strdup(pw->pw_name); + + return NS_OK; } NS_IMETHODIMP GetDomain(char * *aDomain) { - return NS_ERROR_NOT_IMPLEMENTED; + struct utsname buf; + + if (uname(&buf)) { + return NS_ERROR_FAILURE; + } + + *aDomain = nsCRT::strdup(buf.__domainname); + + return NS_OK; +} + +NS_IMETHODIMP GetEmailAddress(char * *aEmailAddress) +{ + // use username + "@" + domain for the email address + + nsresult rv; + + nsCAutoString emailAddress; + nsXPIDLCString username; + nsXPIDLCString domain; + + rv = GetUsername(getter_Copies(username)); + if (NS_FAILED(rv)) return rv; + + rv = GetDomain(getter_Copies(domain)); + if (NS_FAILED(rv)) return rv; + + if ((const char *)username && (const char*)domain && nsCRT::strlen((const char *)username) && nsCRT::strlen((const char *)domain)) { + emailAddress = (const char *)username; + emailAddress += "@"; + emailAddress += (const char *)domain; + } + else { + return NS_ERROR_FAILURE; + } + + *aEmailAddress = nsCRT::strdup((const char *)emailAddress); + + return NS_OK; } diff --git a/xpfe/components/startup/src/nsUserInfoUnix.cpp b/xpfe/components/startup/src/nsUserInfoUnix.cpp index 8d1d4ec2f60e..35ad8d87ccce 100644 --- a/xpfe/components/startup/src/nsUserInfoUnix.cpp +++ b/xpfe/components/startup/src/nsUserInfoUnix.cpp @@ -27,7 +27,10 @@ #include #include #include +#include + #include "nsString.h" +#include "nsXPIDLString.h" nsUserInfo::nsUserInfo() { @@ -45,12 +48,14 @@ nsUserInfo::GetFullname(PRUnichar **aFullname) { struct passwd *pw = nsnull; - pw = getpwuid (geteuid ()); + pw = getpwuid (geteuid()); + + // do I need to free pw? if (!pw || !pw->pw_gecos) return NS_ERROR_FAILURE; #ifdef DEBUG_sspitzer - printf("name = %s\n", pw->pw_gecos); + printf("fullname = %s\n", pw->pw_gecos); #endif nsAutoString fullname(pw->pw_gecos); @@ -63,18 +68,65 @@ nsUserInfo::GetFullname(PRUnichar **aFullname) return NS_ERROR_FAILURE; } -NS_IMETHODIMP GetEmailAddress(char * *aEmailAddress) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP GetUsername(char * *aUsername) { - return NS_ERROR_NOT_IMPLEMENTED; + struct passwd *pw = nsnull; + + pw = getpwuid(geteuid()); + + // do I need to free pw? + + if (!pw || !pw->pw_name) return NS_ERROR_FAILURE; + +#ifdef DEBUG_sspitzer + printf("username = %s\n", pw->pw_name); +#endif + + *aUsername = nsCRT::strdup(pw->pw_name); + + return NS_OK; } NS_IMETHODIMP GetDomain(char * *aDomain) { - return NS_ERROR_NOT_IMPLEMENTED; + struct utsname buf; + + if (uname(&buf)) { + return NS_ERROR_FAILURE; + } + + *aDomain = nsCRT::strdup(buf.__domainname); + + return NS_OK; +} + +NS_IMETHODIMP GetEmailAddress(char * *aEmailAddress) +{ + // use username + "@" + domain for the email address + + nsresult rv; + + nsCAutoString emailAddress; + nsXPIDLCString username; + nsXPIDLCString domain; + + rv = GetUsername(getter_Copies(username)); + if (NS_FAILED(rv)) return rv; + + rv = GetDomain(getter_Copies(domain)); + if (NS_FAILED(rv)) return rv; + + if ((const char *)username && (const char*)domain && nsCRT::strlen((const char *)username) && nsCRT::strlen((const char *)domain)) { + emailAddress = (const char *)username; + emailAddress += "@"; + emailAddress += (const char *)domain; + } + else { + return NS_ERROR_FAILURE; + } + + *aEmailAddress = nsCRT::strdup((const char *)emailAddress); + + return NS_OK; }