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

Unified Diff: base/win/win_util.cc

Issue 10617002: Use a better registration suffix that will always be unique while respecting the MSDN rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
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;
}

Powered by Google App Engine
This is Rietveld 408576698