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 "remoting/host/win/security_descriptor.h" | 5 #include "remoting/host/win/security_descriptor.h" |
6 | 6 |
7 #include <sddl.h> | 7 #include <sddl.h> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 | 11 |
12 namespace remoting { | 12 namespace remoting { |
13 | 13 |
14 ScopedSd ConvertSddlToSd(const std::string& sddl) { | 14 ScopedSd ConvertSddlToSd(const std::string& sddl) { |
15 PSECURITY_DESCRIPTOR raw_sd = NULL; | 15 PSECURITY_DESCRIPTOR raw_sd = nullptr; |
16 ULONG length = 0; | 16 ULONG length = 0; |
17 if (!ConvertStringSecurityDescriptorToSecurityDescriptor( | 17 if (!ConvertStringSecurityDescriptorToSecurityDescriptor( |
18 base::UTF8ToUTF16(sddl).c_str(), SDDL_REVISION_1, &raw_sd, &length)) { | 18 base::UTF8ToUTF16(sddl).c_str(), SDDL_REVISION_1, &raw_sd, &length)) { |
19 return ScopedSd(); | 19 return ScopedSd(); |
20 } | 20 } |
21 | 21 |
22 ScopedSd sd(length); | 22 ScopedSd sd(length); |
23 memcpy(sd.get(), raw_sd, length); | 23 memcpy(sd.get(), raw_sd, length); |
24 | 24 |
25 LocalFree(raw_sd); | 25 LocalFree(raw_sd); |
26 return sd.Pass(); | 26 return sd.Pass(); |
27 } | 27 } |
28 | 28 |
29 // Converts a SID into a text string. | 29 // Converts a SID into a text string. |
30 std::string ConvertSidToString(SID* sid) { | 30 std::string ConvertSidToString(SID* sid) { |
31 base::char16* c_sid_string = NULL; | 31 base::char16* c_sid_string = nullptr; |
32 if (!ConvertSidToStringSid(sid, &c_sid_string)) | 32 if (!ConvertSidToStringSid(sid, &c_sid_string)) |
33 return std::string(); | 33 return std::string(); |
34 | 34 |
35 base::string16 sid_string(c_sid_string); | 35 base::string16 sid_string(c_sid_string); |
36 LocalFree(c_sid_string); | 36 LocalFree(c_sid_string); |
37 return base::UTF16ToUTF8(sid_string); | 37 return base::UTF16ToUTF8(sid_string); |
38 } | 38 } |
39 | 39 |
40 // Returns the logon SID of a token. Returns NULL if the token does not specify | 40 // Returns the logon SID of a token. Returns nullptr if the token does not |
41 // a logon SID or in case of an error. | 41 // specify a logon SID or in case of an error. |
42 ScopedSid GetLogonSid(HANDLE token) { | 42 ScopedSid GetLogonSid(HANDLE token) { |
43 DWORD length = 0; | 43 DWORD length = 0; |
44 if (GetTokenInformation(token, TokenGroups, NULL, 0, &length) || | 44 if (GetTokenInformation(token, TokenGroups, nullptr, 0, &length) || |
45 GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | 45 GetLastError() != ERROR_INSUFFICIENT_BUFFER) { |
46 return ScopedSid(); | 46 return ScopedSid(); |
47 } | 47 } |
48 | 48 |
49 TypedBuffer<TOKEN_GROUPS> groups(length); | 49 TypedBuffer<TOKEN_GROUPS> groups(length); |
50 if (!GetTokenInformation(token, TokenGroups, groups.get(), length, &length)) | 50 if (!GetTokenInformation(token, TokenGroups, groups.get(), length, &length)) |
51 return ScopedSid(); | 51 return ScopedSid(); |
52 | 52 |
53 for (uint32 i = 0; i < groups->GroupCount; ++i) { | 53 for (uint32 i = 0; i < groups->GroupCount; ++i) { |
54 if ((groups->Groups[i].Attributes & SE_GROUP_LOGON_ID) == | 54 if ((groups->Groups[i].Attributes & SE_GROUP_LOGON_ID) == |
(...skipping 16 matching lines...) Expand all Loading... |
71 ScopedSid* group, | 71 ScopedSid* group, |
72 ScopedSid* owner, | 72 ScopedSid* owner, |
73 ScopedAcl* sacl) { | 73 ScopedAcl* sacl) { |
74 // Get buffer sizes. | 74 // Get buffer sizes. |
75 DWORD absolute_sd_size = 0; | 75 DWORD absolute_sd_size = 0; |
76 DWORD dacl_size = 0; | 76 DWORD dacl_size = 0; |
77 DWORD group_size = 0; | 77 DWORD group_size = 0; |
78 DWORD owner_size = 0; | 78 DWORD owner_size = 0; |
79 DWORD sacl_size = 0; | 79 DWORD sacl_size = 0; |
80 if (MakeAbsoluteSD(relative_sd.get(), | 80 if (MakeAbsoluteSD(relative_sd.get(), |
81 NULL, | 81 nullptr, |
82 &absolute_sd_size, | 82 &absolute_sd_size, |
83 NULL, | 83 nullptr, |
84 &dacl_size, | 84 &dacl_size, |
85 NULL, | 85 nullptr, |
86 &sacl_size, | 86 &sacl_size, |
87 NULL, | 87 nullptr, |
88 &owner_size, | 88 &owner_size, |
89 NULL, | 89 nullptr, |
90 &group_size) || | 90 &group_size) || |
91 GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | 91 GetLastError() != ERROR_INSUFFICIENT_BUFFER) { |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 // Allocate buffers. | 95 // Allocate buffers. |
96 ScopedSd local_absolute_sd(absolute_sd_size); | 96 ScopedSd local_absolute_sd(absolute_sd_size); |
97 ScopedAcl local_dacl(dacl_size); | 97 ScopedAcl local_dacl(dacl_size); |
98 ScopedSid local_group(group_size); | 98 ScopedSid local_group(group_size); |
99 ScopedSid local_owner(owner_size); | 99 ScopedSid local_owner(owner_size); |
(...skipping 16 matching lines...) Expand all Loading... |
116 | 116 |
117 absolute_sd->Swap(local_absolute_sd); | 117 absolute_sd->Swap(local_absolute_sd); |
118 dacl->Swap(local_dacl); | 118 dacl->Swap(local_dacl); |
119 group->Swap(local_group); | 119 group->Swap(local_group); |
120 owner->Swap(local_owner); | 120 owner->Swap(local_owner); |
121 sacl->Swap(local_sacl); | 121 sacl->Swap(local_sacl); |
122 return true; | 122 return true; |
123 } | 123 } |
124 | 124 |
125 } // namespace remoting | 125 } // namespace remoting |
OLD | NEW |