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 <windows.h> | 5 #include <windows.h> |
6 #include <Sddl.h> // For ConvertSidToStringSidW. | 6 #include <Sddl.h> // For ConvertSidToStringSidW. |
| 7 |
| 8 #include <memory> |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
12 #include "rlz/lib/assert.h" | 13 #include "rlz/lib/assert.h" |
13 | 14 |
14 namespace rlz_lib { | 15 namespace rlz_lib { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 bool GetSystemVolumeSerialNumber(int* number) { | 19 bool GetSystemVolumeSerialNumber(int* number) { |
19 if (!number) | 20 if (!number) |
20 return false; | 21 return false; |
(...skipping 14 matching lines...) Expand all Loading... |
35 NULL, 0)) | 36 NULL, 0)) |
36 return false; | 37 return false; |
37 | 38 |
38 *number = number_local; | 39 *number = number_local; |
39 return true; | 40 return true; |
40 } | 41 } |
41 | 42 |
42 bool GetComputerSid(const wchar_t* account_name, SID* sid, DWORD sid_size) { | 43 bool GetComputerSid(const wchar_t* account_name, SID* sid, DWORD sid_size) { |
43 static const DWORD kStartDomainLength = 128; // reasonable to start with | 44 static const DWORD kStartDomainLength = 128; // reasonable to start with |
44 | 45 |
45 scoped_ptr<wchar_t[]> domain_buffer(new wchar_t[kStartDomainLength]); | 46 std::unique_ptr<wchar_t[]> domain_buffer(new wchar_t[kStartDomainLength]); |
46 DWORD domain_size = kStartDomainLength; | 47 DWORD domain_size = kStartDomainLength; |
47 DWORD sid_dword_size = sid_size; | 48 DWORD sid_dword_size = sid_size; |
48 SID_NAME_USE sid_name_use; | 49 SID_NAME_USE sid_name_use; |
49 | 50 |
50 BOOL success = ::LookupAccountNameW(NULL, account_name, sid, | 51 BOOL success = ::LookupAccountNameW(NULL, account_name, sid, |
51 &sid_dword_size, domain_buffer.get(), | 52 &sid_dword_size, domain_buffer.get(), |
52 &domain_size, &sid_name_use); | 53 &domain_size, &sid_name_use); |
53 if (!success && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | 54 if (!success && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
54 // We could have gotten the insufficient buffer error because | 55 // We could have gotten the insufficient buffer error because |
55 // one or both of sid and szDomain was too small. Check for that | 56 // one or both of sid and szDomain was too small. Check for that |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 *volume_id = 0; | 99 *volume_id = 0; |
99 if (!GetSystemVolumeSerialNumber(volume_id)) { | 100 if (!GetSystemVolumeSerialNumber(volume_id)) { |
100 ASSERT_STRING("GetMachineId: Failed to retrieve volume serial number"); | 101 ASSERT_STRING("GetMachineId: Failed to retrieve volume serial number"); |
101 *volume_id = 0; | 102 *volume_id = 0; |
102 } | 103 } |
103 | 104 |
104 return true; | 105 return true; |
105 } | 106 } |
106 | 107 |
107 } // namespace rlz_lib | 108 } // namespace rlz_lib |
OLD | NEW |