Index: base/win/win_util.cc |
diff --git a/base/win/win_util.cc b/base/win/win_util.cc |
index 2f2e7dc76214ca9ad8b4b2fae993f2688b1cb649..8ce89c212b049e84fcb8eb1af126ad6f7b6d74c8 100644 |
--- a/base/win/win_util.cc |
+++ b/base/win/win_util.cc |
@@ -113,6 +113,40 @@ bool GetUserSidString(std::wstring* user_sid) { |
return true; |
} |
+bool GetUserSidBase16Encoded(string16* encoded_sid) { |
+ // Get the current token. |
+ HANDLE token = NULL; |
+ if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) |
+ return false; |
+ base::win::ScopedHandle token_scoped(token); |
+ |
+ DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE; |
+ scoped_array<BYTE> user_bytes(new BYTE[size]); |
+ TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes.get()); |
+ |
+ if (!::GetTokenInformation(token, TokenUser, user, size, &size)) |
+ return false; |
+ |
+ if (!user->User.Sid) |
+ return false; |
gab
2012/06/21 05:55:41
I would have preferred to copy this common functio
|
+ |
+ // This method and its callers assume the resulting encoding will be |
+ // exactly 24 characters. |
+ COMPILE_ASSERT(sizeof(SID) == 12, size_of_SID_struct_is_not_as_expected_); |
gab
2012/06/21 05:55:41
This seems safe, but I'll need to read documentati
|
+ static const size_t kExpectedEncodedLength = sizeof(SID) * 2; |
+ encoded_sid->reserve(kExpectedEncodedLength); |
+ |
+ byte* p = static_cast<byte*>(user->User.Sid); |
+ for (int i = 0; i < sizeof(SID); ++i, ++p) { |
+ encoded_sid->push_back('A' + (*p & 0xf)); |
+ encoded_sid->push_back('A' + ((*p & 0xf0) >> 4)); |
+ } |
+ |
+ DCHECK_EQ(encoded_sid->length(), kExpectedEncodedLength); |
+ |
+ return true; |
+} |
+ |
bool IsShiftPressed() { |
return (::GetKeyState(VK_SHIFT) & 0x8000) == 0x8000; |
} |