Index: third_party/psutil/psutil/arch/mswindows/security.c |
diff --git a/third_party/psutil/psutil/arch/mswindows/security.c b/third_party/psutil/psutil/arch/mswindows/security.c |
index ee6ff9d0fce1a86c88a2711b8a99d09e18373e51..5a07df2f5553722448e8688d99bdc3d4f71435c6 100644 |
--- a/third_party/psutil/psutil/arch/mswindows/security.c |
+++ b/third_party/psutil/psutil/arch/mswindows/security.c |
@@ -1,5 +1,9 @@ |
/* |
- * $Id: security.c 772 2010-11-03 13:51:11Z g.rodola $ |
+ * $Id: security.c 1142 2011-10-05 18:45:49Z g.rodola $ |
+ * |
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
* |
* Security related functions for Windows platform (Set privileges such as |
* SeDebug), as well as security helper functions. |
@@ -26,7 +30,7 @@ token_from_handle(HANDLE hProcess) { |
/* |
* http://www.ddj.com/windows/184405986 |
* |
- * theres a way to determine whether were running under the Local System |
+ * There's a way to determine whether we're running under the Local System |
* account. However (you guessed it), we have to call more Win32 functions to |
* determine this. Backing up through the code listing, we need to make another |
* call to GetTokenInformation, but instead of passing through the TOKEN_USER |
@@ -171,7 +175,7 @@ int SetSeDebug() |
){ |
if (GetLastError() == ERROR_NO_TOKEN){ |
if (!ImpersonateSelf(SecurityImpersonation)){ |
- //Log2File("Error setting impersonation [SetSeDebug()]", L_DEBUG); |
+ CloseHandle(hToken); |
return 0; |
} |
if (!OpenThreadToken(GetCurrentThread(), |
@@ -179,7 +183,8 @@ int SetSeDebug() |
FALSE, |
&hToken) |
){ |
- //Log2File("Error Opening Thread Token", L_DEBUG); |
+ RevertToSelf(); |
+ CloseHandle(hToken); |
return 0; |
} |
} |
@@ -187,10 +192,12 @@ int SetSeDebug() |
// enable SeDebugPrivilege (open any process) |
if (! SetPrivilege(hToken, SE_DEBUG_NAME, TRUE)){ |
- //Log2File("Error setting SeDebug Privilege [SetPrivilege()]", L_WARN); |
+ RevertToSelf(); |
+ CloseHandle(hToken); |
return 0; |
} |
+ RevertToSelf(); |
CloseHandle(hToken); |
return 1; |
} |