OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/user_prefs/tracked/device_id.h" | 5 #include "components/user_prefs/tracked/device_id.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <sddl.h> // For ConvertSidToStringSidA. | 8 #include <sddl.h> // For ConvertSidToStringSidA. |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 | 14 |
14 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) { | 15 MachineIdStatus GetDeterministicMachineSpecificId(std::string* machine_id) { |
15 DCHECK(machine_id); | 16 DCHECK(machine_id); |
16 | 17 |
17 wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {}; | 18 wchar_t computer_name[MAX_COMPUTERNAME_LENGTH + 1] = {}; |
18 DWORD computer_name_size = arraysize(computer_name); | 19 DWORD computer_name_size = arraysize(computer_name); |
19 | 20 |
20 if (!::GetComputerNameW(computer_name, &computer_name_size)) | 21 if (!::GetComputerNameW(computer_name, &computer_name_size)) |
21 return MachineIdStatus::FAILURE; | 22 return MachineIdStatus::FAILURE; |
22 | 23 |
23 DWORD sid_size = SECURITY_MAX_SID_SIZE; | 24 DWORD sid_size = SECURITY_MAX_SID_SIZE; |
24 char sid_buffer[SECURITY_MAX_SID_SIZE]; | 25 char sid_buffer[SECURITY_MAX_SID_SIZE]; |
25 SID* sid = reinterpret_cast<SID*>(sid_buffer); | 26 SID* sid = reinterpret_cast<SID*>(sid_buffer); |
26 DWORD domain_size = 128; // Will expand below if needed. | 27 DWORD domain_size = 128; // Will expand below if needed. |
27 scoped_ptr<wchar_t[]> domain_buffer(new wchar_t[domain_size]); | 28 std::unique_ptr<wchar_t[]> domain_buffer(new wchar_t[domain_size]); |
28 SID_NAME_USE sid_name_use; | 29 SID_NAME_USE sid_name_use; |
29 | 30 |
30 // Although the fifth argument to |LookupAccountNameW()|, | 31 // Although the fifth argument to |LookupAccountNameW()|, |
31 // |ReferencedDomainName|, is annotated as |_Out_opt_|, if a null | 32 // |ReferencedDomainName|, is annotated as |_Out_opt_|, if a null |
32 // value is passed in, zero is returned and |GetLastError()| will | 33 // value is passed in, zero is returned and |GetLastError()| will |
33 // return |ERROR_INSUFFICIENT_BUFFER| (assuming that nothing else went | 34 // return |ERROR_INSUFFICIENT_BUFFER| (assuming that nothing else went |
34 // wrong). In order to ensure that the call to |LookupAccountNameW()| | 35 // wrong). In order to ensure that the call to |LookupAccountNameW()| |
35 // has succeeded, it is necessary to include the following logic and | 36 // has succeeded, it is necessary to include the following logic and |
36 // obtain the domain name. | 37 // obtain the domain name. |
37 if (!::LookupAccountNameW(nullptr, computer_name, sid, &sid_size, | 38 if (!::LookupAccountNameW(nullptr, computer_name, sid, &sid_size, |
(...skipping 24 matching lines...) Expand all Loading... |
62 | 63 |
63 char* sid_string = nullptr; | 64 char* sid_string = nullptr; |
64 if (!::ConvertSidToStringSidA(sid, &sid_string)) | 65 if (!::ConvertSidToStringSidA(sid, &sid_string)) |
65 return MachineIdStatus::FAILURE; | 66 return MachineIdStatus::FAILURE; |
66 | 67 |
67 *machine_id = sid_string; | 68 *machine_id = sid_string; |
68 ::LocalFree(sid_string); | 69 ::LocalFree(sid_string); |
69 | 70 |
70 return MachineIdStatus::SUCCESS; | 71 return MachineIdStatus::SUCCESS; |
71 } | 72 } |
OLD | NEW |