From d2ad11928e6eca9501c3dd58983784c98c850a23 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 25 Nov 2022 20:56:05 -0300 Subject: [PATCH 1/2] Fixed Windows 7 detection of named pipes. Fixes #215 --- src/gsudo/Rpc/NamedPipeUtils.cs | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/gsudo/Rpc/NamedPipeUtils.cs b/src/gsudo/Rpc/NamedPipeUtils.cs index fd9fc049..12d92bee 100644 --- a/src/gsudo/Rpc/NamedPipeUtils.cs +++ b/src/gsudo/Rpc/NamedPipeUtils.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using System.IO; - +using System.Linq; + namespace gsudo.Rpc { static class NamedPipeUtils @@ -31,24 +32,25 @@ public static List ListNamedPipes() public static bool ExistsNamedPipe(string name) { - var namedPipes = new List(); - Native.FileApi.WIN32_FIND_DATA lpFindFileData; - - var ptr = Native.FileApi.FindFirstFile($@"\\.\pipe\{GetRootFolder(name)}*", out lpFindFileData); - do - { - if (lpFindFileData.cFileName.EndsWith(name, StringComparison.Ordinal)) - { - Native.FileApi.FindClose(ptr); - Logger.Instance.Log($"Found Named Pipe \"{name}\".", LogLevel.Debug); - return true; - } + //Logger.Instance.Log($"Searching for {name}", LogLevel.Debug); + try + { + return System.IO.Directory.GetFiles("\\\\.\\\\pipe\\", name).Any(); + } + catch + { + // Windows 7 workaround + foreach (var pipe in System.IO.Directory.GetFiles("\\\\.\\\\pipe\\")) + { + if (pipe.EndsWith(name, StringComparison.Ordinal)) + { + //Logger.Instance.Log($"Found Named Pipe {name}", LogLevel.Debug); + return true; + } + } } - while (Native.FileApi.FindNextFile(ptr, out lpFindFileData)); - Native.FileApi.FindClose(ptr); return false; - } static string GetRootFolder(string path) From bb16b8b0f39b22088ffe7d00f1b679545c08e776 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 25 Nov 2022 21:45:28 -0300 Subject: [PATCH 2/2] docs: Updated README.md for Windows 7 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 399198e7..51045812 100644 --- a/README.md +++ b/README.md @@ -305,9 +305,9 @@ How to use, very briefly: No. `gsudo` reminds of the original sudo regarding user expectations. Many `sudo` features are `*nix` specific and could never have a `Windows` counterpart. Other features (such as `sudoers`) could potentially be implemented but are not at this point. -- Does it work in Windows 7/8? +- What are the requirements? Does it work in Windows 7/8? - Yes, it works from Win7 SP1 onwards, except the credentials cache. + It works on Win7 SP1 onwards. Some features may only work in Windows 10/11, like elevating as TrustedInstaller. - How do I return to the previous security level after using gsudo?