Skip to content

Commit e09a941

Browse files
Support Impersonation
1 parent 085064d commit e09a941

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Snaffler/SnaffleRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NLog;
1+
using NLog;
22
using NLog.Config;
33
using NLog.Layouts;
44
using NLog.Targets;
@@ -8,9 +8,10 @@
88
using System;
99
using System.Diagnostics;
1010
using System.IO;
11-
using System.Threading.Tasks;
11+
using System.Security.Principal;
1212
using System.Text.RegularExpressions;
1313
using System.Threading;
14+
using System.Threading.Tasks;
1415

1516
namespace Snaffler
1617
{
@@ -201,7 +202,14 @@ public void Run(string[] args)
201202

202203
var tokenSource = new CancellationTokenSource();
203204
var token = tokenSource.Token;
204-
Task thing = Task.Factory.StartNew(() => { controller.Execute(); }, token);
205+
206+
WindowsIdentity impersonatedUser = WindowsIdentity.GetCurrent();
207+
Task thing = Task.Factory.StartNew(() => {
208+
using (WindowsImpersonationContext ctx = impersonatedUser.Impersonate())
209+
{
210+
controller.Execute();
211+
}
212+
}, token);
205213
bool exit = false;
206214

207215
while (exit == false)

0 commit comments

Comments
 (0)