From c3144b1261840f38d57064641845d23da49bc94c Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 11 Nov 2022 10:11:56 -0300 Subject: [PATCH 1/8] Installer: Installing into %ProgramFiles (x86)%\gsudo\v2.x.x --- src/gsudo.Installer/Product.wxs | 36 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/gsudo.Installer/Product.wxs b/src/gsudo.Installer/Product.wxs index 5d019666..311c8f53 100644 --- a/src/gsudo.Installer/Product.wxs +++ b/src/gsudo.Installer/Product.wxs @@ -5,12 +5,17 @@ - + + + @@ -40,7 +45,9 @@ NOT Installed Installed AND NOT REINSTALL - + NOT Installed + Installed AND NOT REINSTALL + @@ -58,11 +65,12 @@ + + Value="[INSTALLFOLDER]Current" /> @@ -88,7 +96,8 @@ - + + @@ -96,17 +105,30 @@ + + + \ No newline at end of file From bce6013a78784fa760533981510f2ab87a1d166f Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 11 Nov 2022 12:51:24 -0300 Subject: [PATCH 2/8] Installer: Allow upgrade with gsudo.exe in use. Uninstall with file in use will also work, and remove from path, but will fail to delete the file in use. --- src/gsudo.Installer/Product.wxs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gsudo.Installer/Product.wxs b/src/gsudo.Installer/Product.wxs index 311c8f53..81bb459d 100644 --- a/src/gsudo.Installer/Product.wxs +++ b/src/gsudo.Installer/Product.wxs @@ -5,16 +5,11 @@ - - - - - @@ -43,10 +38,13 @@ + NOT Installed Installed AND NOT REINSTALL NOT Installed Installed AND NOT REINSTALL + + REMOVE AND NOT UPGRADINGPRODUCTCODE @@ -73,14 +71,14 @@ Value="[INSTALLFOLDER]Current" /> - + - + @@ -129,6 +127,12 @@ Execute="deferred" Return="ignore" Impersonate="no" /> + \ No newline at end of file From 5a8ad5f80ff01a777aecbc6959eeb05a40001960 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Wed, 23 Nov 2022 15:57:36 -0300 Subject: [PATCH 3/8] Feat: Choco package will now download and install .MSI file from GitHub. --- .github/workflows/release.yml | 11 +++-------- build/05-release-Chocolatey.ps1 | 8 ++------ .../{gsudo/tools => }/chocolateyinstall.ps1.template | 12 +++++++----- .../gsudo/Bin/{gsudo.exe.ignore => .donotdelete} | 0 build/Chocolatey/gsudo/Bin/sudo.exe.ignore | 0 5 files changed, 12 insertions(+), 19 deletions(-) rename build/Chocolatey/{gsudo/tools => }/chocolateyinstall.ps1.template (90%) rename build/Chocolatey/gsudo/Bin/{gsudo.exe.ignore => .donotdelete} (100%) delete mode 100644 build/Chocolatey/gsudo/Bin/sudo.exe.ignore diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1bc4046a..0e6e8b69 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,20 +46,15 @@ jobs: [IO.File]::WriteAllBytes("$env:cert_path", $pfx_cert_byte) - name: Code Sign run: ./build/03-sign.ps1 - - name: Upload build artifacts - uses: actions/upload-artifact@v3 - with: - name: Binaries - path: ./artifacts - name: Package for GitHub Release run: ./build/04-release-GitHub.ps1 - name: Remove the pfx run: Remove-Item -path $env:cert_path - - name: Upload installer artifacts + - name: Upload build artifacts uses: actions/upload-artifact@v3 with: - name: Installer - path: ./artifacts/gsudoSetup.msi + name: Binaries + path: ./artifacts - name: Create Release uses: ncipollo/release-action@v1.11.1 with: diff --git a/build/05-release-Chocolatey.ps1 b/build/05-release-Chocolatey.ps1 index ecacecbf..74680c49 100644 --- a/build/05-release-Chocolatey.ps1 +++ b/build/05-release-Chocolatey.ps1 @@ -24,18 +24,14 @@ if ($env:version) { "- Cleaning Choco template folder" git clean .\Build\Chocolatey\gsudo -xf -"- Adding Artifacts" -cp artifacts\x?? .\Build\Chocolatey\gsudo\tools -Recurse -Force -Exclude *.pdb -cp artifacts\arm64 .\Build\Chocolatey\gsudo\tools -Recurse -Force -Exclude *.pdb - Get-ChildItem .\build\Chocolatey\gsudo\tools\ -Recurse -Filter *.exe | % { ni "$($_.FullName).ignore" } > $null # Generate gsudo.nuspec (Get-Content Build\Chocolatey\gsudo.nuspec.template) -replace '#VERSION#', "$version" | Out-File -encoding UTF8 .\Build\Chocolatey\gsudo\gsudo.nuspec # Generate chocolateyinstall.ps1 -(Get-Content .\build\Chocolatey\gsudo\tools\chocolateyinstall.ps1.template) - -replace '#VERSION#', "$version" +(Get-Content .\build\Chocolatey\chocolateyinstall.ps1.template) ` + -replace '#VERSION#', "$version" ` -replace '#SHA#', (Get-FileHash .\artifacts\gsudoSetup.msi).Hash | Out-File -encoding UTF8 .\build\Chocolatey\gsudo\tools\chocolateyinstall.ps1 diff --git a/build/Chocolatey/gsudo/tools/chocolateyinstall.ps1.template b/build/Chocolatey/chocolateyinstall.ps1.template similarity index 90% rename from build/Chocolatey/gsudo/tools/chocolateyinstall.ps1.template rename to build/Chocolatey/chocolateyinstall.ps1.template index 2d1d1a40..50045be6 100644 --- a/build/Chocolatey/gsudo/tools/chocolateyinstall.ps1.template +++ b/build/Chocolatey/chocolateyinstall.ps1.template @@ -84,7 +84,7 @@ $packageArgs = @{ checksum64 = '#SHA#' checksumType64= 'sha256' - silentArgs = "" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0 + silentArgs = "/qn /norestart" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0 validExitCodes= @(0, 3010, 1641) } @@ -101,8 +101,10 @@ Install-ChocolateyPackage @packageArgs Update-SessionEnvironment if (Get-Module gsudoModule) { - if ((get-Module gsudoModule).Path) - " Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" + if ((Split-Path (Get-Module gsudoModule).Path -Parent) -ne (Split-Path (Get-Command gsudoModule.psd1). Source -Parent)) { + "IMPORTANT! Please update your `$PROFILE: Use the following gsudoModule path." + " Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" + } } else { & { "PowerShell users: To use enhanced gsudo and Invoke-Gsudo cmdlet, add the following line to your `$PROFILE" @@ -110,6 +112,6 @@ if (Get-Module gsudoModule) { "Or run: " " Get-Command gsudoModule.psd1 | % { Write-Output `"``nImport-Module ```"`$(`$_.Source)```"`" | Add-Content `$PROFILE }" } -Write-Output "`ngsudo successfully installed. Please restart your consoles to use gsudo.`n" - + +Write-Output "`nPlease restart your consoles to use gsudo.`n" } diff --git a/build/Chocolatey/gsudo/Bin/gsudo.exe.ignore b/build/Chocolatey/gsudo/Bin/.donotdelete similarity index 100% rename from build/Chocolatey/gsudo/Bin/gsudo.exe.ignore rename to build/Chocolatey/gsudo/Bin/.donotdelete diff --git a/build/Chocolatey/gsudo/Bin/sudo.exe.ignore b/build/Chocolatey/gsudo/Bin/sudo.exe.ignore deleted file mode 100644 index e69de29b..00000000 From 5da6cb29db62c421c6dd39c8be2d8a160b51da18 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Wed, 23 Nov 2022 18:12:22 -0300 Subject: [PATCH 4/8] Fixed uninstall --- build/Chocolatey/gsudo/tools/chocolateyuninstall.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Chocolatey/gsudo/tools/chocolateyuninstall.ps1 b/build/Chocolatey/gsudo/tools/chocolateyuninstall.ps1 index f17ad1c8..425b0c28 100644 --- a/build/Chocolatey/gsudo/tools/chocolateyuninstall.ps1 +++ b/build/Chocolatey/gsudo/tools/chocolateyuninstall.ps1 @@ -3,7 +3,7 @@ $packageName = 'gsudo' $softwareName = 'gsudo v*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique $installerType = 'MSI' -$silentArgs = '/qn /norestart' +$silentArgs = '/qb /norestart' # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx $validExitCodes = @(0, 3010, 1605, 1614, 1641) From 06ab046e94734722a44f8642ab4cd0d55b635e84 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Wed, 23 Nov 2022 21:23:55 -0300 Subject: [PATCH 5/8] Fix error message --- build/Chocolatey/chocolateyinstall.ps1.template | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/Chocolatey/chocolateyinstall.ps1.template b/build/Chocolatey/chocolateyinstall.ps1.template index 50045be6..3a31e3a0 100644 --- a/build/Chocolatey/chocolateyinstall.ps1.template +++ b/build/Chocolatey/chocolateyinstall.ps1.template @@ -100,12 +100,14 @@ Install-ChocolateyPackage @packageArgs Update-SessionEnvironment +$ErrorActionPreference = 'SilentlyContinue'; + if (Get-Module gsudoModule) { if ((Split-Path (Get-Module gsudoModule).Path -Parent) -ne (Split-Path (Get-Command gsudoModule.psd1). Source -Parent)) { "IMPORTANT! Please update your `$PROFILE: Use the following gsudoModule path." " Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" } -} else { +} elseif (Get-Command gsudoModule.psd1) { & { "PowerShell users: To use enhanced gsudo and Invoke-Gsudo cmdlet, add the following line to your `$PROFILE" " Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" From 305bb0183dcc90fa06804ae7a57372fe0f633a03 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 25 Nov 2022 18:26:51 -0300 Subject: [PATCH 6/8] Use junction for gsudo\Current instead of Symlink for Win7 compatibility --- src/gsudo.Installer/Product.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gsudo.Installer/Product.wxs b/src/gsudo.Installer/Product.wxs index 81bb459d..b58541e1 100644 --- a/src/gsudo.Installer/Product.wxs +++ b/src/gsudo.Installer/Product.wxs @@ -117,7 +117,7 @@ From 6fe6bd9059e706dcb13ce9e99d78c81264a314e1 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 25 Nov 2022 20:56:05 -0300 Subject: [PATCH 7/8] 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 90f986b1ed77e93e46c8f782cc5fdec87a103ec1 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Fri, 25 Nov 2022 21:45:28 -0300 Subject: [PATCH 8/8] 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 f4002e8f..7dff9d33 100644 --- a/README.md +++ b/README.md @@ -306,9 +306,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?