Authenticate windows commands. Untested.
This commit is contained in:
@@ -58,14 +58,14 @@
|
||||
- (void)extractZip:(NSArray *)args
|
||||
{
|
||||
// Todo: check if we can write to the requested dir, escalate priviledges if required.
|
||||
NSArray *a = [NSArray arrayWithObjects:@"--extract-zip", [args objectAtIndex:2], [args objectAtIndex:3], nil];
|
||||
NSArray *a = [NSArray arrayWithObjects:@"--extract-zip-inner", [args objectAtIndex:2], [args objectAtIndex:3], nil];
|
||||
[self runUtilityWithArgs:a];
|
||||
}
|
||||
|
||||
- (void)installRAPackages:(NSArray *)args
|
||||
{
|
||||
// Todo: check if we can write to the requested dir, escalate priviledges if required.
|
||||
NSArray *a = [NSArray arrayWithObjects:@"--install-ra-packages", [args objectAtIndex:2], nil];
|
||||
NSArray *a = [NSArray arrayWithObjects:@"--install-ra-packages-inner", [args objectAtIndex:2], nil];
|
||||
[self runUtilityWithArgs:a];
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -172,5 +172,20 @@ namespace OpenRA.Utility
|
||||
|
||||
Console.WriteLine(n.Value);
|
||||
}
|
||||
|
||||
public static void AuthenticateAndExtractZip(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--extract-zip \"{0}\" \"{1}\"".F(args[1], args[2]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallRAPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-ra-packages \"{0}\"".F(args[1]));
|
||||
}
|
||||
|
||||
public static void AuthenticateAndInstallCncPackages(string[] args)
|
||||
{
|
||||
Util.CallWithAdmin("--install-cnc-packages \"{0}\"".F(args[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,14 @@ namespace OpenRA.Utility
|
||||
static void Main(string[] args)
|
||||
{
|
||||
argCallbacks = new Dictionary<string, ArgCallback>();
|
||||
argCallbacks.Add("--extract-zip", Command.ExtractZip);
|
||||
argCallbacks.Add("--install-ra-packages", Command.InstallRAPackages);
|
||||
argCallbacks.Add("--install-cnc-packages", Command.InstallCncPackages);
|
||||
argCallbacks.Add("--extract-zip-inner", Command.ExtractZip);
|
||||
argCallbacks.Add("--install-ra-packages-inner", Command.InstallRAPackages);
|
||||
argCallbacks.Add("--install-cnc-packages-inner", Command.InstallCncPackages);
|
||||
argCallbacks.Add("--display-filepicker", Command.DisplayFilepicker);
|
||||
argCallbacks.Add("--settings-value", Command.Settings);
|
||||
argCallbacks.Add("--install-ra-packages", Command.AuthenticateAndInstallRAPackages);
|
||||
argCallbacks.Add("--install-cnc-packages", Command.AuthenticateAndInstallCncPackages);
|
||||
argCallbacks.Add("--extract-zip", Command.AuthenticateAndExtractZip);
|
||||
|
||||
if (args.Length == 0) { PrintUsage(); return; }
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using OpenRA.FileFormats;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO.Pipes;
|
||||
|
||||
namespace OpenRA.Utility
|
||||
{
|
||||
@@ -61,5 +64,39 @@ namespace OpenRA.Utility
|
||||
}
|
||||
z.Close();
|
||||
}
|
||||
|
||||
public static string GetPipeName()
|
||||
{
|
||||
return "OpenRA.Utility" + Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
public static void CallWithAdmin(string command)
|
||||
{
|
||||
string pipename = Util.GetPipeName();
|
||||
var p = new Process();
|
||||
p.StartInfo.FileName = "OpenRA.Utility.exe";
|
||||
p.StartInfo.Arguments = command + " --pipe=" + pipename;
|
||||
p.StartInfo.Verb = "runas";
|
||||
|
||||
try
|
||||
{
|
||||
p.Start();
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
|
||||
var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In);
|
||||
pipe.Connect();
|
||||
|
||||
using (var reader = new StreamReader(pipe))
|
||||
{
|
||||
while (!p.HasExited)
|
||||
Console.Write(reader.ReadLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user