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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
6 | 6 |
7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 WTSINFO* wts_info = nullptr; | 841 WTSINFO* wts_info = nullptr; |
842 if (buffer_size < sizeof(*wts_info)) | 842 if (buffer_size < sizeof(*wts_info)) |
843 return base::Time(); | 843 return base::Time(); |
844 | 844 |
845 wts_info = reinterpret_cast<WTSINFO*>(buffer); | 845 wts_info = reinterpret_cast<WTSINFO*>(buffer); |
846 FILETIME filetime = {wts_info->LogonTime.u.LowPart, | 846 FILETIME filetime = {wts_info->LogonTime.u.LowPart, |
847 wts_info->LogonTime.u.HighPart}; | 847 wts_info->LogonTime.u.HighPart}; |
848 return base::Time::FromFileTime(filetime); | 848 return base::Time::FromFileTime(filetime); |
849 } | 849 } |
850 | 850 |
851 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | |
852 : is_enabled_(false) { | |
853 HANDLE temp_handle; | |
854 if (!::OpenProcessToken(::GetCurrentProcess(), | |
855 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | |
856 &temp_handle)) { | |
857 return; | |
858 } | |
859 token_.Set(temp_handle); | |
860 | |
861 LUID privilege_luid; | |
862 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { | |
863 token_.Close(); | |
864 return; | |
865 } | |
866 | |
867 // Adjust the token's privileges to enable |privilege_name|. If this privilege | |
868 // was already enabled, |previous_privileges_|.PrivilegeCount will be set to 0 | |
869 // and we then know not to disable this privilege upon destruction. | |
870 TOKEN_PRIVILEGES tp; | |
871 tp.PrivilegeCount = 1; | |
872 tp.Privileges[0].Luid = privilege_luid; | |
873 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
874 DWORD return_length; | |
875 if (!::AdjustTokenPrivileges(token_.Get(), FALSE, &tp, | |
876 sizeof(TOKEN_PRIVILEGES), | |
877 &previous_privileges_, &return_length)) { | |
878 token_.Close(); | |
879 return; | |
880 } | |
881 | |
882 is_enabled_ = true; | |
883 } | |
884 | |
885 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | |
886 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | |
887 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, | |
888 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | |
889 } | |
890 } | |
891 | |
892 } // namespace installer | 851 } // namespace installer |
OLD | NEW |