Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: rlz/win/lib/process_info.cc

Issue 177843009: Make GetUserName() return more specific error code, so that we could know how the function failed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz/win/lib/process_info.cc
diff --git a/rlz/win/lib/process_info.cc b/rlz/win/lib/process_info.cc
index 2511f54ab76ab3cefb12035ba5893e8a92ee1816..b55f62c3170599f73cafb35a00aa3b119cf6cc95 100644
--- a/rlz/win/lib/process_info.cc
+++ b/rlz/win/lib/process_info.cc
@@ -23,6 +23,7 @@ HRESULT GetCurrentUser(std::wstring* name,
std::wstring* domain,
std::wstring* sid) {
DWORD err;
+ DWORD zero = 0;
// Get the current username & domain the hard way. (GetUserNameEx would be
// nice, but unfortunately requires connectivity to a domain controller.
@@ -33,8 +34,17 @@ HRESULT GetCurrentUser(std::wstring* name,
// In which case, search for and use the process handle of a running
// Explorer.exe.)
HANDLE token;
- if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token))
- return E_FAIL;
+
+ HANDLE process_handle = ::GetCurrentProcess();
+ if (!process_handle)
+ CHECK(process_handle);
+
+ if (!::OpenProcessToken(process_handle, TOKEN_QUERY, &token)) {
+ err = ::GetLastError();
+ // Check should fail.
+ CHECK_EQ(err, zero);
+ return err;
+ }
Roger Tawa OOO till Jul 10th 2014/02/28 19:34:00 From the docs, I don't believe getting a handle to
yao 2014/02/28 21:28:19 Done.
base::win::ScopedHandle scoped_process_token(token);
@@ -49,12 +59,18 @@ HRESULT GetCurrentUser(std::wstring* name,
CHECK(!result && err == ERROR_INSUFFICIENT_BUFFER);
token_user_bytes.reset(new char[token_user_size]);
- if (!token_user_bytes.get())
+ if (!token_user_bytes.get()) {
+ // Check should fail.
+ CHECK_EQ(E_OUTOFMEMORY, 0);
return E_OUTOFMEMORY;
+ }
Roger Tawa OOO till Jul 10th 2014/02/28 19:34:00 Can probably replace lines 62-66 with: CHECK(t
yao 2014/02/28 21:28:19 Done.
if (!::GetTokenInformation(token, TokenUser, token_user_bytes.get(),
token_user_size, &token_user_size2)) {
- return E_FAIL;
+ err = ::GetLastError();
+ // Check should fail.
+ CHECK_EQ(err, zero);
+ return err;
}
WCHAR user_name[UNLEN + 1]; // max username length
@@ -64,12 +80,19 @@ HRESULT GetCurrentUser(std::wstring* name,
SID_NAME_USE sid_type;
TOKEN_USER* token_user =
reinterpret_cast<TOKEN_USER*>(token_user_bytes.get());
- if (!token_user)
- return E_FAIL;
+ if (!token_user) {
+ err = ::GetLastError();
+ // Check should fail.
+ CHECK_EQ(err, zero);
+ return err;
+ }
PSID user_sid = token_user->User.Sid;
if (!::LookupAccountSidW(NULL, user_sid, user_name, &user_name_size,
domain_name, &domain_name_size, &sid_type)) {
- return E_FAIL;
+ err = ::GetLastError();
+ // Check should fail.
+ CHECK_EQ(err, zero);
+ return err;
}
if (name != NULL) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698