Use getpwuid(geteuid()) instead of getlogin()

This removes the dependency on a TTY and now does what is expected: gets
the (possibly impersonated) username of the current process/thread.

Implementation and tests updated, still uses reentrant versions where possible.
This commit is contained in:
Andrew Schwartzmeyer committed 2015-09-23 15:57:23 -07:00
1 parent 39174a0afb
commit 020a768c31
2 files changed
+33 -29

No files matched your search

+2 -1
View File
@@ -7,6 +7,7 @@
#include <unistd.h>
#include <gtest/gtest.h>
#include <unicode/unistr.h>
#include <pwd.h>
#include "getusername.h"
//! Test fixture for GetUserNameW
@@ -19,7 +20,7 @@ protected:
std::string expectedUsername;
DWORD expectedSize;
GetUserNameTest(): expectedUsername(std::string(getlogin())),
GetUserNameTest(): expectedUsername(std::string(getpwuid(geteuid())->pw_name)),
expectedSize(expectedUsername.length()+1)
{
}