From 539ab9ce63b59b99e78fe04d3c752b5f89910308 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 11 Apr 2017 19:56:47 -0700 Subject: [PATCH] tst: passthrough-dotnet: remove EnableRestoreBackupPrivileges --- tst/passthrough-dotnet/Program.cs | 70 ------------------------------- 1 file changed, 70 deletions(-) diff --git a/tst/passthrough-dotnet/Program.cs b/tst/passthrough-dotnet/Program.cs index 55f8529a..8e2976f0 100644 --- a/tst/passthrough-dotnet/Program.cs +++ b/tst/passthrough-dotnet/Program.cs @@ -769,8 +769,6 @@ namespace passthrough if (null == PassThrough || null == MountPoint) throw new CommandLineUsageException(); - EnableBackupRestorePrivileges(); - if (null != DebugLogFile) if (0 > FileSystem.SetDebugLogFile(DebugLogFile)) throw new CommandLineUsageException("cannot open debug log file"); @@ -838,74 +836,6 @@ namespace passthrough throw new CommandLineUsageException(); } - /* - * Turns out there is no managed way to adjust privileges. - * So we have to write our own using P/Invoke. Joy! - * - * NOTE: The P/Invoke definitions below are not for general use. - */ - private struct LUID_AND_ATTRIBUTES - { - public UInt64 Luid; - public UInt32 Attributes; - } - [StructLayout(LayoutKind.Sequential)] - private struct TOKEN_PRIVILEGES - { - public UInt32 PrivilegeCount; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public LUID_AND_ATTRIBUTES[] Privileges; - } - [DllImport("advapi32.dll", SetLastError = true)] - private static extern Boolean OpenProcessToken( - IntPtr ProcessHandle, - UInt32 DesiredAccess, - out IntPtr TokenHandle); - [DllImport("kernel32.dll", SetLastError = true)] - private static extern Boolean CloseHandle( - IntPtr hObject); - [DllImport("advapi32.dll", SetLastError = true)] - private static extern Boolean LookupPrivilegeValueW( - [MarshalAs(UnmanagedType.LPWStr)] String lpSystemName, - [MarshalAs(UnmanagedType.LPWStr)] String lpName, - out UInt64 lpLuid); - [DllImport("advapi32.dll", SetLastError = true)] - private static extern Boolean AdjustTokenPrivileges( - IntPtr TokenHandle, - Boolean DisableAllPrivileges, - ref TOKEN_PRIVILEGES NewState, - UInt32 BufferLength, - IntPtr PreviousState, - IntPtr ReturnLength); - private static Int32 EnableBackupRestorePrivileges() - { - TOKEN_PRIVILEGES Privileges; - IntPtr Token; - - Privileges = default(TOKEN_PRIVILEGES); - Privileges.PrivilegeCount = 2; - Privileges.Privileges = new LUID_AND_ATTRIBUTES[2]; - Privileges.Privileges[0].Attributes = 2/*SE_PRIVILEGE_ENABLED*/; - Privileges.Privileges[1].Attributes = 2/*SE_PRIVILEGE_ENABLED*/; - - if (!LookupPrivilegeValueW(null, "SeBackupPrivilege", out Privileges.Privileges[0].Luid) || - !LookupPrivilegeValueW(null, "SeRestorePrivilege", out Privileges.Privileges[1].Luid)) - return Marshal.GetLastWin32Error(); - - if (!OpenProcessToken((IntPtr)(-1), 0x0020/*TOKEN_ADJUST_PRIVILEGES*/, out Token)) - return Marshal.GetLastWin32Error(); - - if (!AdjustTokenPrivileges(Token, false, ref Privileges, 0, IntPtr.Zero, IntPtr.Zero)) - { - CloseHandle(Token); - - return Marshal.GetLastWin32Error(); - } - - CloseHandle(Token); - - return 0; - } - private Ptfs _Ptfs; }