Skip to content

Commit fb6acd6

Browse files
authored
Merge branch 'master' into snyk-upgrade-052f54cd8bc336d74b4f9bb4e0960612
2 parents 9831280 + c23b102 commit fb6acd6

7 files changed

+13
-74
lines changed

src/gsudo/AppSettings/Settings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Settings
8282

8383
public static RegistrySetting<string> ExceptionList { get; } =
8484
new RegistrySetting<string>(nameof(ExceptionList),
85-
defaultValue: "notepad.exe;powershell.exe;",
85+
defaultValue: "notepad.exe;powershell.exe;whoami.exe;",
8686
deserializer: (string s)=>s,
8787
scope: RegistrySettingScope.GlobalOnly);
8888

src/gsudo/Commands/AttachRunCommand.cs

-60
This file was deleted.

src/gsudo/Commands/RunCommand.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ private async Task<int> RunUsingService(ElevationRequest elevationRequest)
120120
serviceLocation = await ServiceHelper.WaitForNewService(callingPid).ConfigureAwait(false);
121121
}
122122

123+
if (serviceLocation==null)
124+
throw new ApplicationException("Unable to connect to the elevated service.");
125+
123126
if (!InputArguments.IntegrityLevel.HasValue)
124127
{
125128
// This is the edge case where user does `gsudo -u SomeOne` and we dont know if SomeOne can elevate or not.
126129
elevationRequest.IntegrityLevel = serviceLocation.IsHighIntegrity ? IntegrityLevel.High : IntegrityLevel.Medium;
127130
}
128131

129-
if (serviceLocation==null)
130-
throw new ApplicationException("Unable to connect to the elevated service.");
131-
132132
connection = await ServiceHelper.Connect(serviceLocation).ConfigureAwait(false);
133133
if (connection == null) // service is not running or listening.
134134
{

src/gsudo/Helpers/CommandLineParser.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private ICommand ParseOptions()
7979
if (c != null)
8080
return c;
8181
}
82+
else if (arg.In("-noninteractive")) { } // ignore due to gerardog/gsudo#305
8283
else if (arg.StartsWith("-", StringComparison.OrdinalIgnoreCase)
8384
&& arg.NotIn("-encodedCommand")) // -encodedCommand is not posix compliant, but is what powershell sends on: gsudo { script block }
8485
// So treat -encodedCommand as part of the CommandToRun, for gerardog/gsudo#160
@@ -273,9 +274,6 @@ private ICommand ParseVerb()
273274
if (arg.In("run"))
274275
return new RunCommand(commandToRun: args.ToArray());
275276

276-
if (arg.In("AttachRun"))
277-
return new AttachRunCommand(commandToRun: args.ToArray());
278-
279277
args.AddFirst(arg);
280278

281279
if (arg == "!!" || arg.StartsWith("!", StringComparison.InvariantCulture))

src/gsudo/Helpers/CommandToRunAdapter.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using gsudo.Native;
2-
using Microsoft.VisualBasic;
32
using System;
43
using System.Collections;
54
using System.Collections.Generic;
6-
using System.Globalization;
75
using System.IO;
86
using System.Linq;
97
using System.Security.AccessControl;
108
using System.Security.Principal;
119
using System.Text;
12-
using System.Threading.Tasks;
1310

1411
namespace gsudo.Helpers
1512
{
@@ -133,7 +130,7 @@ Running ./gsudo {command} should elevate the powershell command.
133130
if (!Settings.PowerShellLoadProfile)
134131
newArgs.Add("-NoProfile");
135132

136-
if (args[0] == "-encodedCommand")
133+
if (args[0].In("-encodedCommand", "-noninteractive"))
137134
{
138135
newArgs.AddRange(args);
139136
}

src/gsudo/Helpers/ServiceHelper.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ private static ServiceLocation FindServiceByIntegrity(int? clientPid, string use
7171
var anyIntegrity = InputArguments.UserName != null;
7272
var tryHighIntegrity = !InputArguments.IntegrityLevel.HasValue || InputArguments.IntegrityLevel.Value >= IntegrityLevel.High;
7373
var tryLowIntegrity = !InputArguments.IntegrityLevel.HasValue || InputArguments.IntegrityLevel.Value < IntegrityLevel.High;
74+
75+
var targetUserSid = InputArguments.RunAsSystem ? "S-1-5-18" : InputArguments.UserSid;
76+
7477
if (tryHighIntegrity)
7578
{
76-
var pipeName = NamedPipeClient.TryGetServicePipe(user, clientPid.Value, true);
79+
var pipeName = NamedPipeClient.TryGetServicePipe(user, clientPid.Value, true, null);
7780
if (pipeName != null)
7881
{
7982
return new ServiceLocation

src/gsudo/Rpc/NamedPipeNameFactory.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public static string GetPipeName(string allowedSid, int allowedPid, string targe
1313
if (allowedPid < 0) allowedPid = 0;
1414

1515
var ti = InputArguments.TrustedInstaller ? "_TI" : string.Empty;
16-
var admin = !isAdmin ? "_NonAdmin" : string.Empty;
16+
var s = InputArguments.RunAsSystem ? "_S" : string.Empty;
17+
var admin = !isAdmin ? "_NonAdmin" : string.Empty;
1718

18-
var data = $"{allowedSid}_{targetSid}_{allowedPid}_{ti}{admin}";
19+
var data = $"allowedSid-{allowedSid}_targetSid-{targetSid}{allowedPid}{s}{ti}{admin}";
1920
#if !DEBUG
2021
data = GetHash(data);
2122
#endif

0 commit comments

Comments
 (0)