OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "sandbox/win/src/sid.h" | 5 #include "sandbox/win/src/sid.h" |
6 | 6 |
| 7 #include <objbase.h> |
| 8 #include <sddl.h> |
| 9 |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 | 11 |
9 namespace sandbox { | 12 namespace sandbox { |
10 | 13 |
11 Sid::Sid(const SID *sid) { | 14 Sid::Sid(const SID *sid) |
| 15 : unique_sub_auth_sid_(NULL) { |
12 ::CopySid(SECURITY_MAX_SID_SIZE, sid_, const_cast<SID*>(sid)); | 16 ::CopySid(SECURITY_MAX_SID_SIZE, sid_, const_cast<SID*>(sid)); |
13 }; | 17 }; |
14 | 18 |
15 Sid::Sid(WELL_KNOWN_SID_TYPE type) { | 19 Sid::Sid(WELL_KNOWN_SID_TYPE type) |
| 20 : unique_sub_auth_sid_(NULL) { |
16 DWORD size_sid = SECURITY_MAX_SID_SIZE; | 21 DWORD size_sid = SECURITY_MAX_SID_SIZE; |
17 BOOL result = ::CreateWellKnownSid(type, NULL, sid_, &size_sid); | 22 BOOL result = ::CreateWellKnownSid(type, NULL, sid_, &size_sid); |
18 DCHECK(result); | 23 DCHECK(result); |
19 DBG_UNREFERENCED_LOCAL_VARIABLE(result); | 24 DBG_UNREFERENCED_LOCAL_VARIABLE(result); |
20 } | 25 } |
21 | 26 |
22 const SID *Sid::GetPSID() const { | 27 const SID *Sid::GetPSID() const { |
23 return reinterpret_cast<SID*>(const_cast<BYTE*>(sid_)); | 28 return reinterpret_cast<SID*>(const_cast<BYTE*>(sid_)); |
24 } | 29 } |
25 | 30 |
| 31 void Sid::GenerateUniqueSubAuthoritySid(std::wstring* unique_sid) { |
| 32 SID_IDENTIFIER_AUTHORITY authority = SECURITY_APP_PACKAGE_AUTHORITY; |
| 33 GUID guid = { 0 }; |
| 34 ::CoCreateGuid(&guid); |
| 35 unsigned long* guid_long = reinterpret_cast<unsigned long*>(&guid); |
| 36 PSID sid = NULL; |
| 37 DWORD sub_auth = *GetSidSubAuthority(reinterpret_cast<SID*>(sid_), 0); |
| 38 ::AllocateAndInitializeSid(&authority, |
| 39 8, |
| 40 sub_auth, |
| 41 guid_long[0], |
| 42 guid_long[1], |
| 43 guid_long[2], |
| 44 guid_long[3], |
| 45 1, |
| 46 1, |
| 47 1, |
| 48 &sid); |
| 49 LPWSTR sid_string = NULL; |
| 50 ::ConvertSidToStringSid(sid, &sid_string); |
| 51 *unique_sid = sid_string; |
| 52 ::FreeSid(sid); |
| 53 ::LocalFree(sid_string); |
| 54 } |
| 55 |
26 } // namespace sandbox | 56 } // namespace sandbox |
OLD | NEW |