Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/win/win_util.h" | 5 #include "base/win/win_util.h" |
| 6 | 6 |
| 7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 #include <shobjidl.h> // Must be before propkey. | 8 #include <shobjidl.h> // Must be before propkey. |
| 9 #include <propkey.h> | 9 #include <propkey.h> |
| 10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 if (!::ConvertSidToStringSid(user->User.Sid, &sid_string)) | 106 if (!::ConvertSidToStringSid(user->User.Sid, &sid_string)) |
| 107 return false; | 107 return false; |
| 108 | 108 |
| 109 *user_sid = sid_string; | 109 *user_sid = sid_string; |
| 110 | 110 |
| 111 ::LocalFree(sid_string); | 111 ::LocalFree(sid_string); |
| 112 | 112 |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool GetUserSidBase16Encoded(string16* encoded_sid) { | |
| 117 // Get the current token. | |
| 118 HANDLE token = NULL; | |
| 119 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) | |
| 120 return false; | |
| 121 base::win::ScopedHandle token_scoped(token); | |
| 122 | |
| 123 DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE; | |
| 124 scoped_array<BYTE> user_bytes(new BYTE[size]); | |
| 125 TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes.get()); | |
| 126 | |
| 127 if (!::GetTokenInformation(token, TokenUser, user, size, &size)) | |
| 128 return false; | |
| 129 | |
| 130 if (!user->User.Sid) | |
| 131 return false; | |
|
gab
2012/06/21 05:55:41
I would have preferred to copy this common functio
| |
| 132 | |
| 133 // This method and its callers assume the resulting encoding will be | |
| 134 // exactly 24 characters. | |
| 135 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
| |
| 136 static const size_t kExpectedEncodedLength = sizeof(SID) * 2; | |
| 137 encoded_sid->reserve(kExpectedEncodedLength); | |
| 138 | |
| 139 byte* p = static_cast<byte*>(user->User.Sid); | |
| 140 for (int i = 0; i < sizeof(SID); ++i, ++p) { | |
| 141 encoded_sid->push_back('A' + (*p & 0xf)); | |
| 142 encoded_sid->push_back('A' + ((*p & 0xf0) >> 4)); | |
| 143 } | |
| 144 | |
| 145 DCHECK_EQ(encoded_sid->length(), kExpectedEncodedLength); | |
| 146 | |
| 147 return true; | |
| 148 } | |
| 149 | |
| 116 bool IsShiftPressed() { | 150 bool IsShiftPressed() { |
| 117 return (::GetKeyState(VK_SHIFT) & 0x8000) == 0x8000; | 151 return (::GetKeyState(VK_SHIFT) & 0x8000) == 0x8000; |
| 118 } | 152 } |
| 119 | 153 |
| 120 bool IsCtrlPressed() { | 154 bool IsCtrlPressed() { |
| 121 return (::GetKeyState(VK_CONTROL) & 0x8000) == 0x8000; | 155 return (::GetKeyState(VK_CONTROL) & 0x8000) == 0x8000; |
| 122 } | 156 } |
| 123 | 157 |
| 124 bool IsAltPressed() { | 158 bool IsAltPressed() { |
| 125 return (::GetKeyState(VK_MENU) & 0x8000) == 0x8000; | 159 return (::GetKeyState(VK_MENU) & 0x8000) == 0x8000; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 | 280 |
| 247 #ifndef COPY_FILE_COPY_SYMLINK | 281 #ifndef COPY_FILE_COPY_SYMLINK |
| 248 #error You must install the Windows 2008 or Vista Software Development Kit and \ | 282 #error You must install the Windows 2008 or Vista Software Development Kit and \ |
| 249 set it as your default include path to build this library. You can grab it by \ | 283 set it as your default include path to build this library. You can grab it by \ |
| 250 searching for "download windows sdk 2008" in your favorite web search engine. \ | 284 searching for "download windows sdk 2008" in your favorite web search engine. \ |
| 251 Also make sure you register the SDK with Visual Studio, by selecting \ | 285 Also make sure you register the SDK with Visual Studio, by selecting \ |
| 252 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ | 286 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ |
| 253 menu (see Start - All Programs - Microsoft Windows SDK - \ | 287 menu (see Start - All Programs - Microsoft Windows SDK - \ |
| 254 Visual Studio Registration). | 288 Visual Studio Registration). |
| 255 #endif | 289 #endif |
| OLD | NEW |