OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/window.h" | 5 #include "sandbox/win/src/window.h" |
6 | 6 |
7 #include <aclapi.h> | 7 #include <aclapi.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 ResultCode CreateAltWindowStation(HWINSTA* winsta) { | 37 ResultCode CreateAltWindowStation(HWINSTA* winsta) { |
38 // Get the security attributes from the current window station; we will | 38 // Get the security attributes from the current window station; we will |
39 // use this as the base security attributes for the new window station. | 39 // use this as the base security attributes for the new window station. |
40 SECURITY_ATTRIBUTES attributes = {0}; | 40 SECURITY_ATTRIBUTES attributes = {0}; |
41 if (!GetSecurityAttributes(::GetProcessWindowStation(), &attributes)) { | 41 if (!GetSecurityAttributes(::GetProcessWindowStation(), &attributes)) { |
42 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; | 42 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; |
43 } | 43 } |
44 | 44 |
45 // Create the window station using NULL for the name to ask the os to | 45 // Create the window station using NULL for the name to ask the os to |
46 // generate it. | 46 // generate it. |
47 // TODO(nsylvain): don't ask for WINSTA_ALL_ACCESS if we don't need to. | 47 *winsta = ::CreateWindowStationW( |
48 *winsta = ::CreateWindowStationW(NULL, 0, WINSTA_ALL_ACCESS, &attributes); | 48 NULL, 0, GENERIC_READ | WINSTA_CREATEDESKTOP, &attributes); |
49 LocalFree(attributes.lpSecurityDescriptor); | 49 LocalFree(attributes.lpSecurityDescriptor); |
50 | 50 |
51 if (*winsta) | 51 if (*winsta) |
52 return SBOX_ALL_OK; | 52 return SBOX_ALL_OK; |
53 | 53 |
54 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; | 54 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; |
55 } | 55 } |
56 | 56 |
57 ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { | 57 ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { |
58 base::string16 desktop_name = L"sbox_alternate_desktop_"; | 58 base::string16 desktop_name = L"sbox_alternate_desktop_"; |
(...skipping 18 matching lines...) Expand all Loading... |
77 if (winsta) { | 77 if (winsta) { |
78 // We need to switch to the alternate window station before creating the | 78 // We need to switch to the alternate window station before creating the |
79 // desktop. | 79 // desktop. |
80 if (!::SetProcessWindowStation(winsta)) { | 80 if (!::SetProcessWindowStation(winsta)) { |
81 ::LocalFree(attributes.lpSecurityDescriptor); | 81 ::LocalFree(attributes.lpSecurityDescriptor); |
82 return SBOX_ERROR_CANNOT_CREATE_DESKTOP; | 82 return SBOX_ERROR_CANNOT_CREATE_DESKTOP; |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 // Create the destkop. | 86 // Create the destkop. |
87 // TODO(nsylvain): don't ask for GENERIC_ALL if we don't need to. | 87 *desktop = ::CreateDesktop(desktop_name.c_str(), |
88 *desktop = ::CreateDesktop(desktop_name.c_str(), NULL, NULL, 0, GENERIC_ALL, | 88 NULL, |
| 89 NULL, |
| 90 0, |
| 91 DESKTOP_CREATEWINDOW | DESKTOP_READOBJECTS | |
| 92 READ_CONTROL | WRITE_DAC | WRITE_OWNER, |
89 &attributes); | 93 &attributes); |
90 ::LocalFree(attributes.lpSecurityDescriptor); | 94 ::LocalFree(attributes.lpSecurityDescriptor); |
91 | 95 |
92 if (winsta) { | 96 if (winsta) { |
93 // Revert to the right window station. | 97 // Revert to the right window station. |
94 if (!::SetProcessWindowStation(current_winsta)) { | 98 if (!::SetProcessWindowStation(current_winsta)) { |
95 return SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION; | 99 return SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (winsta) { | 152 if (winsta) { |
149 name = GetWindowObjectName(winsta); | 153 name = GetWindowObjectName(winsta); |
150 name += L'\\'; | 154 name += L'\\'; |
151 } | 155 } |
152 | 156 |
153 name += GetWindowObjectName(desktop); | 157 name += GetWindowObjectName(desktop); |
154 return name; | 158 return name; |
155 } | 159 } |
156 | 160 |
157 } // namespace sandbox | 161 } // namespace sandbox |
OLD | NEW |