Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/shared/Utils.cpp

Issue 6308231068516352: Fix issues with security tokens (Enhanced Protected Mode, Protected Mode etc) (Closed)
Left Patch Set: Created Nov. 15, 2013, 7:22 p.m.
Right Patch Set: Slaying the comments Created March 4, 2014, 10:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« src/shared/Communication.cpp ('K') | « src/shared/Utils.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <memory> 1 #include <memory>
2 #include <stdexcept> 2 #include <stdexcept>
3 #include <vector> 3 #include <vector>
4 4
5 #include <Windows.h> 5 #include <Windows.h>
6 #include <ShlObj.h> 6 #include <ShlObj.h>
7 7
8 #include "Utils.h" 8 #include "Utils.h"
9 9
10 namespace 10 namespace
11 { 11 {
12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx 12 // See http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx
13 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 13 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
14 14
15 std::wstring appDataPath; 15 std::wstring appDataPath;
16 16
17 } 17 }
18 18
19 bool IsWindowsVistaOrLater() 19 bool IsWindowsVistaOrLater()
20 { 20 {
21 OSVERSIONINFOEX osvi; 21 OSVERSIONINFOEX osvi;
22 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 22 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
23 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 23 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
24 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi)); 24 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi));
25 return osvi.dwMajorVersion >= 6; 25 return osvi.dwMajorVersion >= 6;
26 } 26 }
27 27
28 bool IsWindows8() 28 bool IsAppContainersSupported()
Felix Dahlke 2013/12/10 16:46:36 Shouldn't this be "isWindows8OrLater"?
29 { 29 {
30 OSVERSIONINFOEX osvi; 30 //Try to allocate SID of AppContainer and see if it's succesful
31 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 31 PSID allAppContainersSid = 0;
32 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 32 SID_IDENTIFIER_AUTHORITY applicationAuthority = SECURITY_APP_PACKAGE_AUTHORITY ;
33 GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&osvi)); 33 BOOL res = AllocateAndInitializeSid(&applicationAuthority,
34 return osvi.dwMajorVersion == 6 & osvi.dwMinorVersion >= 2; 34 SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT,
35 SECURITY_APP_PACKAGE_BASE_RID,
36 SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE,
37 0, 0, 0, 0, 0, 0,
38 &allAppContainersSid);
39
40 if (res == FALSE)
Felix Dahlke 2014/06/24 15:30:39 I'd prefer !res here, but may just be me.
41 {
42 return false;
43 }
44 else
Felix Dahlke 2014/06/24 15:30:39 From the Mozilla coding style which ours is based
45 {
46 FreeSid(allAppContainersSid);
47 return true;
48 }
35 } 49 }
36 50
37 std::string ToUtf8String(const std::wstring& str) 51 std::string ToUtf8String(const std::wstring& str)
38 { 52 {
39 int length = static_cast<int>(str.size()); 53 int length = static_cast<int>(str.size());
40 if (length == 0) 54 if (length == 0)
41 return std::string(); 55 return std::string();
42 56
43 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0); 57 int utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0);
44 if (utf8StringLength == 0) 58 if (utf8StringLength == 0)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 135 }
122 136
123 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement) 137 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st d::wstring replacement)
124 { 138 {
125 size_t replaceStart = input.find(placeholder); 139 size_t replaceStart = input.find(placeholder);
126 if (replaceStart != std::string::npos) 140 if (replaceStart != std::string::npos)
127 { 141 {
128 input.replace(replaceStart, placeholder.length(), replacement); 142 input.replace(replaceStart, placeholder.length(), replacement);
129 } 143 }
130 } 144 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld