@nativestudio/cli 0.3.0-rc.14 → 0.3.0-rc.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPATIBILITY.json +11 -11
- package/components/runtime.json +7 -7
- package/components/runtime.tgz +0 -0
- package/dist/_chunks/{chunk-2AI3WF2O.js → chunk-5UJEP7FY.js} +1 -1
- package/dist/_chunks/chunk-AAGFHT2D.js +1 -0
- package/dist/_chunks/{chunk-ROBBF33U.js → chunk-BBTZJB2G.js} +1 -1
- package/dist/_chunks/chunk-BX2SNMA4.js +1 -0
- package/dist/_chunks/chunk-CFZNDURD.js +1 -0
- package/dist/_chunks/{chunk-3AVC742O.js → chunk-FX5UVDTH.js} +1 -1
- package/dist/_chunks/{chunk-U7ECMITP.js → chunk-H6EZKOYR.js} +1 -1
- package/dist/_chunks/chunk-I5KYSPUJ.js +1 -0
- package/dist/_chunks/chunk-KOCUZ3AE.js +1 -0
- package/dist/_chunks/{chunk-RDIMORUT.js → chunk-NPDLPC5B.js} +1 -1
- package/dist/_chunks/{chunk-RK2P3UVF.js → chunk-NQVUVPW5.js} +1 -1
- package/dist/_chunks/{chunk-VD3OQ743.js → chunk-O47YYPL7.js} +1 -1
- package/dist/_chunks/{chunk-6LY4JYSG.js → chunk-OVIR77ET.js} +1 -1
- package/dist/_chunks/{chunk-VDNNFVTZ.js → chunk-OW6R4MAQ.js} +1 -1
- package/dist/_chunks/{chunk-VKLS4QK5.js → chunk-PB2HLRXG.js} +1 -1
- package/dist/_chunks/chunk-RUPH3HZ2.js +1 -0
- package/dist/_chunks/chunk-SAPEOZ2V.js +1 -0
- package/dist/_chunks/chunk-SKAVQ4UW.js +1 -0
- package/dist/_chunks/{chunk-C62JAWRQ.js → chunk-TTB7CYC5.js} +1 -1
- package/dist/_chunks/chunk-U5FT4VBR.js +1 -0
- package/dist/_chunks/chunk-VOGKKZQH.js +1 -0
- package/dist/_chunks/chunk-YV447AB5.js +1 -0
- package/dist/_chunks/{chunk-W6C63ZN7.js → chunk-ZADAXKKY.js} +1 -1
- package/dist/_chunks/{chunk-S74X4KIC.js → chunk-ZOODOQBH.js} +1 -1
- package/dist/_chunks/{connect-6UH7ZFAC.js → connect-RIODOO3C.js} +1 -1
- package/dist/_chunks/{device-management-H3NIDIPY.js → device-management-VECG3RA4.js} +1 -1
- package/dist/_chunks/{device-preflight-LHFLPVAB.js → device-preflight-73KVSHZG.js} +1 -1
- package/dist/_chunks/{devices-inventory-I2E3Q4DA.js → devices-inventory-E6TE4H7T.js} +1 -1
- package/dist/_chunks/{devices-main-VV2VYU4T.js → devices-main-7JHMJNGV.js} +1 -1
- package/dist/_chunks/{files-TTIQ7LYJ.js → files-72BEXD7E.js} +1 -1
- package/dist/_chunks/{host-main-3JFGVU5P.js → host-main-KDORT44Q.js} +1 -1
- package/dist/_chunks/http-profile-QINBH2FP.js +1 -0
- package/dist/_chunks/{library-main-CTBW7DAI.js → library-main-AWUEMZFQ.js} +1 -1
- package/dist/_chunks/local-main-BNFNAPRG.js +1 -0
- package/dist/_chunks/{local-mcp-XB6E3V2W.js → local-mcp-HU6MII3G.js} +1 -1
- package/dist/_chunks/main-BSMCHALI.js +2 -0
- package/dist/_chunks/mcp-3VZZFXNG.js +1 -0
- package/dist/_chunks/oauth-QBJ62PIA.js +1 -0
- package/dist/_chunks/observe-entry-D7F6OQ7Y.js +1 -0
- package/dist/_chunks/remote-client-XIJ6RQLU.js +1 -0
- package/dist/_chunks/{render-main-VTM6WGFP.js → render-main-O3IN6EFV.js} +1 -1
- package/dist/_chunks/{source-import-KKV2UWJO.js → source-import-Y2Z3BVWY.js} +1 -1
- package/dist/_chunks/src-3S6CAUSJ.js +1 -0
- package/dist/_chunks/{stdio-main-Y7N4NVKU.js → stdio-main-T4WMBNKB.js} +1 -1
- package/dist/_chunks/workspace-main-KWFTVTZG.js +1 -0
- package/dist/_types/cli/local/desktop-contract.d.ts +1 -1
- package/dist/_types/cli/local/desktop-device-contract.d.ts +2 -2
- package/dist/_types/cli/local/desktop-device-owner.d.ts +1 -1
- package/dist/_types/cli/local/desktop-owner.d.ts +1 -1
- package/dist/_types/contracts/index.d.ts +2 -0
- package/dist/_types/contracts/lifecycle-event-projections.d.ts +15 -0
- package/dist/_types/contracts/lifecycle-events.d.ts +53 -1
- package/dist/_types/contracts/production-feedback.d.ts +452 -0
- package/dist/_types/contracts/shares.d.ts +135 -0
- package/dist/_types/contracts/workspace.d.ts +21 -0
- package/dist/entry.js +1 -1
- package/dist/local-management.js +1 -1
- package/dist/local-navigation.js +1 -1
- package/dist/native/helper.exe +0 -0
- package/dist/native/helper.json +1 -0
- package/package.json +1 -1
- package/dist/_chunks/chunk-5DY7LSZZ.js +0 -1
- package/dist/_chunks/chunk-6LU6GJKW.js +0 -1
- package/dist/_chunks/chunk-77IAHNM2.js +0 -1
- package/dist/_chunks/chunk-FU3524Z6.js +0 -1
- package/dist/_chunks/chunk-HY7NXJYX.js +0 -1
- package/dist/_chunks/chunk-KB2GVAN7.js +0 -1
- package/dist/_chunks/chunk-PUNG4ND7.js +0 -1
- package/dist/_chunks/chunk-SV3NF7GO.js +0 -1
- package/dist/_chunks/chunk-TLPI6P7L.js +0 -1
- package/dist/_chunks/chunk-ZRSYOFMX.js +0 -1
- package/dist/_chunks/http-profile-NIQDCFPU.js +0 -1
- package/dist/_chunks/local-main-227MNGEC.js +0 -1
- package/dist/_chunks/main-W6NNZFLK.js +0 -2
- package/dist/_chunks/mcp-EXQ5UAHB.js +0 -1
- package/dist/_chunks/oauth-HC6TI7HB.js +0 -1
- package/dist/_chunks/src-OIY5TBQT.js +0 -1
- package/dist/_chunks/workspace-main-Y7ZVBRJJ.js +0 -1
- package/dist/native/Bootstrap.ps1 +0 -90
- package/dist/native/JobNative.cs +0 -137
- package/dist/native/JobRunner.cs +0 -381
- package/dist/native/NativeMain.cs +0 -161
- package/dist/native/PipeBridge.cs +0 -260
- package/dist/native/PrivateAccess.cs +0 -152
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.IO;
|
|
3
|
-
using System.IO.Pipes;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.Collections.Concurrent;
|
|
6
|
-
using System.Runtime.InteropServices;
|
|
7
|
-
using System.Threading;
|
|
8
|
-
using Microsoft.Win32.SafeHandles;
|
|
9
|
-
namespace NativeStudio.Platform
|
|
10
|
-
{
|
|
11
|
-
public static class PipeBridge
|
|
12
|
-
{
|
|
13
|
-
sealed class Client
|
|
14
|
-
{
|
|
15
|
-
public NamedPipeServerStream Pipe;
|
|
16
|
-
public readonly ManualResetEventSlim Flow = new ManualResetEventSlim(true);
|
|
17
|
-
public readonly BlockingCollection<byte[]> Writes = new BlockingCollection<byte[]>(8);
|
|
18
|
-
}
|
|
19
|
-
static readonly Dictionary<string, Client> Clients = new Dictionary<string, Client>();
|
|
20
|
-
static readonly object Sync = new object();
|
|
21
|
-
static NamedPipeServerStream waiting;
|
|
22
|
-
static volatile bool closed;
|
|
23
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
24
|
-
struct SecurityAttributes
|
|
25
|
-
{
|
|
26
|
-
public int length; public IntPtr descriptor; public int inherit;
|
|
27
|
-
}
|
|
28
|
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool ConvertStringSecurityDescriptorToSecurityDescriptor(string s, uint revision, out IntPtr sd, out uint length);
|
|
29
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern SafePipeHandle CreateNamedPipe(string name, uint access, uint mode, uint max, uint output, uint input, uint timeout, ref SecurityAttributes sa);
|
|
30
|
-
[DllImport("kernel32.dll")] static extern IntPtr LocalFree(IntPtr p);
|
|
31
|
-
static NamedPipeServerStream Create(string path, bool first)
|
|
32
|
-
{
|
|
33
|
-
IntPtr sd;
|
|
34
|
-
uint length;
|
|
35
|
-
if (!ConvertStringSecurityDescriptorToSecurityDescriptor("O:" + PrivateAccess.User.Value + "D:P(D;;GA;;;NU)(A;;GA;;;" + PrivateAccess.User.Value + ")", 1, out sd, out length))
|
|
36
|
-
throw new Exception("PIPE_SECURITY");
|
|
37
|
-
try
|
|
38
|
-
{
|
|
39
|
-
var attributes = new SecurityAttributes { length = Marshal.SizeOf(typeof(SecurityAttributes)), descriptor = sd, inherit = 0 };
|
|
40
|
-
var handle = CreateNamedPipe(path, 3U | 0x40000000U | (first ? 0x80000U : 0U), 8, 16, 65536, 65536, 0, ref attributes);
|
|
41
|
-
if (handle.IsInvalid)
|
|
42
|
-
{
|
|
43
|
-
handle.Dispose();
|
|
44
|
-
throw new Exception("PIPE_IN_USE");
|
|
45
|
-
}
|
|
46
|
-
return new NamedPipeServerStream(PipeDirection.InOut, true, false, handle);
|
|
47
|
-
}
|
|
48
|
-
finally { LocalFree(sd); }
|
|
49
|
-
}
|
|
50
|
-
static void End(string id)
|
|
51
|
-
{
|
|
52
|
-
Client client;
|
|
53
|
-
lock (Sync)
|
|
54
|
-
{
|
|
55
|
-
if (!Clients.TryGetValue(id, out client))
|
|
56
|
-
return;
|
|
57
|
-
Clients.Remove(id);
|
|
58
|
-
}
|
|
59
|
-
lock (client)
|
|
60
|
-
client.Writes.CompleteAdding();
|
|
61
|
-
client.Flow.Set();
|
|
62
|
-
client.Pipe.Dispose();
|
|
63
|
-
NativeMain.Send(new
|
|
64
|
-
{
|
|
65
|
-
kind = "close",
|
|
66
|
-
id = id
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
static void Write(Client client, string id)
|
|
70
|
-
{
|
|
71
|
-
try
|
|
72
|
-
{
|
|
73
|
-
foreach (var bytes in client.Writes.GetConsumingEnumerable())
|
|
74
|
-
{
|
|
75
|
-
var task = client.Pipe.WriteAsync(bytes, 0, bytes.Length);
|
|
76
|
-
if (!task.Wait(2000))
|
|
77
|
-
{
|
|
78
|
-
// Closing this owned pipe cancels the pending overlapped write.
|
|
79
|
-
task.ContinueWith(t => GC.KeepAlive(t.Exception), System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
NativeMain.Send(new
|
|
83
|
-
{
|
|
84
|
-
kind = "written",
|
|
85
|
-
id = id
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
using (var timeout = new Timer(delegate
|
|
89
|
-
{
|
|
90
|
-
End(id);
|
|
91
|
-
}, null, 2000, Timeout.Infinite))
|
|
92
|
-
client.Pipe.WaitForPipeDrain();
|
|
93
|
-
}
|
|
94
|
-
catch { }
|
|
95
|
-
finally { End(id); }
|
|
96
|
-
}
|
|
97
|
-
static void Accept(string path)
|
|
98
|
-
{
|
|
99
|
-
bool first = true;
|
|
100
|
-
try
|
|
101
|
-
{
|
|
102
|
-
while (!closed)
|
|
103
|
-
{
|
|
104
|
-
lock (Sync)
|
|
105
|
-
{
|
|
106
|
-
if (Clients.Count >= 15)
|
|
107
|
-
{
|
|
108
|
-
Monitor.Wait(Sync, 100);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
waiting = Create(path, first);
|
|
113
|
-
if (first)
|
|
114
|
-
{
|
|
115
|
-
NativeMain.Send(new
|
|
116
|
-
{
|
|
117
|
-
kind = "ready"
|
|
118
|
-
});
|
|
119
|
-
first = false;
|
|
120
|
-
}
|
|
121
|
-
var pipe = waiting;
|
|
122
|
-
pipe.WaitForConnection();
|
|
123
|
-
waiting = null;
|
|
124
|
-
if (closed)
|
|
125
|
-
{
|
|
126
|
-
pipe.Dispose();
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
var id = Guid.NewGuid().ToString();
|
|
130
|
-
var client = new Client { Pipe = pipe };
|
|
131
|
-
lock (Sync)
|
|
132
|
-
Clients.Add(id, client);
|
|
133
|
-
NativeMain.Send(new
|
|
134
|
-
{
|
|
135
|
-
kind = "open",
|
|
136
|
-
id = id
|
|
137
|
-
});
|
|
138
|
-
var writer = new Thread(delegate ()
|
|
139
|
-
{
|
|
140
|
-
Write(client, id);
|
|
141
|
-
});
|
|
142
|
-
writer.IsBackground = true;
|
|
143
|
-
writer.Start();
|
|
144
|
-
ThreadPool.QueueUserWorkItem(delegate
|
|
145
|
-
{
|
|
146
|
-
try
|
|
147
|
-
{
|
|
148
|
-
var buffer = new byte[4096];
|
|
149
|
-
int count;
|
|
150
|
-
while (!closed)
|
|
151
|
-
{
|
|
152
|
-
if (!client.Flow.Wait(65000))
|
|
153
|
-
break;
|
|
154
|
-
count = pipe.Read(buffer, 0, buffer.Length);
|
|
155
|
-
if (count <= 0)
|
|
156
|
-
break;
|
|
157
|
-
NativeMain.Send(new
|
|
158
|
-
{
|
|
159
|
-
kind = "data",
|
|
160
|
-
id = id,
|
|
161
|
-
data = Convert.ToBase64String(buffer, 0, count)
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch { }
|
|
166
|
-
finally { End(id); }
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch { if (!closed) Environment.Exit(1); }
|
|
171
|
-
}
|
|
172
|
-
public static void Run(string path)
|
|
173
|
-
{
|
|
174
|
-
if (!System.Text.RegularExpressions.Regex.IsMatch(path, @"^\\\\\.\\pipe\\nvs-[0-9a-f]{64}$"))
|
|
175
|
-
throw new Exception("PIPE");
|
|
176
|
-
var thread = new Thread(delegate ()
|
|
177
|
-
{
|
|
178
|
-
Accept(path);
|
|
179
|
-
});
|
|
180
|
-
thread.IsBackground = true;
|
|
181
|
-
thread.Start();
|
|
182
|
-
try
|
|
183
|
-
{
|
|
184
|
-
for (; ; )
|
|
185
|
-
{
|
|
186
|
-
var line = NativeMain.Line(65536);
|
|
187
|
-
if (line == null)
|
|
188
|
-
break;
|
|
189
|
-
Dictionary<string, object> r;
|
|
190
|
-
lock (NativeMain.Json)
|
|
191
|
-
r = NativeMain.Json.Deserialize<Dictionary<string, object>>(line);
|
|
192
|
-
var id = NativeMain.Text(r, "id");
|
|
193
|
-
var kind = NativeMain.Text(r, "kind");
|
|
194
|
-
if (kind == "close")
|
|
195
|
-
{
|
|
196
|
-
End(id);
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
if (kind == "finish")
|
|
200
|
-
{
|
|
201
|
-
Client selected;
|
|
202
|
-
lock (Sync)
|
|
203
|
-
Clients.TryGetValue(id, out selected);
|
|
204
|
-
if (selected != null)
|
|
205
|
-
lock (selected)
|
|
206
|
-
selected.Writes.CompleteAdding();
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (kind == "pause" || kind == "resume")
|
|
210
|
-
{
|
|
211
|
-
Client selected;
|
|
212
|
-
lock (Sync)
|
|
213
|
-
Clients.TryGetValue(id, out selected);
|
|
214
|
-
if (selected != null)
|
|
215
|
-
{
|
|
216
|
-
if (kind == "pause")
|
|
217
|
-
selected.Flow.Reset();
|
|
218
|
-
else
|
|
219
|
-
selected.Flow.Set();
|
|
220
|
-
}
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
if (kind != "data")
|
|
224
|
-
throw new Exception("FRAME");
|
|
225
|
-
var bytes = Convert.FromBase64String(NativeMain.Text(r, "data"));
|
|
226
|
-
if (bytes.Length > 16384)
|
|
227
|
-
throw new Exception("FRAME");
|
|
228
|
-
Client client;
|
|
229
|
-
lock (Sync)
|
|
230
|
-
Clients.TryGetValue(id, out client);
|
|
231
|
-
if (client != null)
|
|
232
|
-
{
|
|
233
|
-
bool full;
|
|
234
|
-
lock (client)
|
|
235
|
-
full = !client.Writes.IsAddingCompleted && !client.Writes.TryAdd(bytes);
|
|
236
|
-
if (full)
|
|
237
|
-
End(id);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
finally
|
|
242
|
-
{
|
|
243
|
-
closed = true;
|
|
244
|
-
if (waiting != null)
|
|
245
|
-
waiting.Dispose();
|
|
246
|
-
lock (Sync)
|
|
247
|
-
{
|
|
248
|
-
foreach (var client in Clients.Values)
|
|
249
|
-
{
|
|
250
|
-
lock (client)
|
|
251
|
-
client.Writes.CompleteAdding();
|
|
252
|
-
client.Flow.Set();
|
|
253
|
-
client.Pipe.Dispose();
|
|
254
|
-
}
|
|
255
|
-
Clients.Clear();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.IO;
|
|
3
|
-
using System.ComponentModel;
|
|
4
|
-
using System.Runtime.InteropServices;
|
|
5
|
-
using System.Security.AccessControl;
|
|
6
|
-
using System.Security.Principal;
|
|
7
|
-
using Microsoft.Win32.SafeHandles;
|
|
8
|
-
namespace NativeStudio.Platform
|
|
9
|
-
{
|
|
10
|
-
public static class PrivateAccess
|
|
11
|
-
{
|
|
12
|
-
public static readonly SecurityIdentifier User = WindowsIdentity.GetCurrent().User;
|
|
13
|
-
static readonly string Installer = ((SecurityIdentifier)new NTAccount("NT SERVICE", "TrustedInstaller").Translate(typeof(SecurityIdentifier))).Value;
|
|
14
|
-
static bool Privileged(string sid)
|
|
15
|
-
{
|
|
16
|
-
return sid == User.Value || sid == "S-1-5-18" || sid == "S-1-5-32-544" || sid == Installer;
|
|
17
|
-
}
|
|
18
|
-
public static string PathOf(string path)
|
|
19
|
-
{
|
|
20
|
-
if (String.IsNullOrEmpty(path) || !System.Text.RegularExpressions.Regex.IsMatch(path, @"^[A-Za-z]:[\\/]") || path.StartsWith("\\\\") || path.IndexOf(':', 2) >= 0)
|
|
21
|
-
throw new Exception("PATH");
|
|
22
|
-
var full = Path.GetFullPath(path);
|
|
23
|
-
var drive = new DriveInfo(Path.GetPathRoot(full));
|
|
24
|
-
if (drive.DriveType != DriveType.Fixed || drive.DriveFormat != "NTFS")
|
|
25
|
-
throw new Exception("PRIVATE_NTFS_REQUIRED");
|
|
26
|
-
return full;
|
|
27
|
-
}
|
|
28
|
-
static void Rules(FileSystemSecurity acl, bool privacy)
|
|
29
|
-
{
|
|
30
|
-
if (privacy && acl.GetOwner(typeof(SecurityIdentifier)).Value != User.Value)
|
|
31
|
-
throw new Exception("OWNER");
|
|
32
|
-
foreach (FileSystemAccessRule rule in acl.GetAccessRules(true, true, typeof(SecurityIdentifier)))
|
|
33
|
-
{
|
|
34
|
-
if ((rule.PropagationFlags & PropagationFlags.InheritOnly) != 0 || rule.AccessControlType != AccessControlType.Allow || Privileged(rule.IdentityReference.Value))
|
|
35
|
-
continue;
|
|
36
|
-
const FileSystemRights write = FileSystemRights.Write | FileSystemRights.Delete | FileSystemRights.DeleteSubdirectoriesAndFiles | FileSystemRights.ChangePermissions | FileSystemRights.TakeOwnership;
|
|
37
|
-
if (privacy || (rule.FileSystemRights & write) != 0)
|
|
38
|
-
throw new Exception("ACL");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
static void Ancestors(string path)
|
|
42
|
-
{
|
|
43
|
-
var parent = new DirectoryInfo(Path.GetDirectoryName(path));
|
|
44
|
-
while (parent != null && parent.Parent != null)
|
|
45
|
-
{
|
|
46
|
-
if ((parent.Attributes & FileAttributes.ReparsePoint) != 0)
|
|
47
|
-
throw new Exception("REPARSE");
|
|
48
|
-
Rules(parent.GetAccessControl(), false);
|
|
49
|
-
parent = parent.Parent;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
public static void Directory(string path)
|
|
53
|
-
{
|
|
54
|
-
path = PathOf(path);
|
|
55
|
-
if (!System.IO.Directory.Exists(path))
|
|
56
|
-
{
|
|
57
|
-
var parent = Path.GetDirectoryName(path);
|
|
58
|
-
if (!System.IO.Directory.Exists(parent))
|
|
59
|
-
Directory(parent);
|
|
60
|
-
Ancestors(path);
|
|
61
|
-
var acl = new DirectorySecurity();
|
|
62
|
-
acl.SetOwner(User);
|
|
63
|
-
acl.SetAccessRuleProtection(true, false);
|
|
64
|
-
acl.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
|
|
65
|
-
System.IO.Directory.CreateDirectory(path, acl);
|
|
66
|
-
}
|
|
67
|
-
Check(path, "directory", true);
|
|
68
|
-
}
|
|
69
|
-
public static void Check(string path, string kind, bool privacy)
|
|
70
|
-
{
|
|
71
|
-
if (kind == "pipe")
|
|
72
|
-
{
|
|
73
|
-
CheckPipe(path);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
path = PathOf(path);
|
|
77
|
-
Ancestors(path);
|
|
78
|
-
var attributes = File.GetAttributes(path);
|
|
79
|
-
if ((attributes & FileAttributes.ReparsePoint) != 0 || ((attributes & FileAttributes.Directory) != 0) != (kind == "directory"))
|
|
80
|
-
throw new Exception("KIND");
|
|
81
|
-
Rules(kind == "directory" ? (FileSystemSecurity)new DirectoryInfo(path).GetAccessControl() : new FileInfo(path).GetAccessControl(), privacy);
|
|
82
|
-
}
|
|
83
|
-
public static void Move(string source, string target, bool exclusive)
|
|
84
|
-
{
|
|
85
|
-
source = PathOf(source);
|
|
86
|
-
target = PathOf(target);
|
|
87
|
-
if (!String.Equals(Path.GetDirectoryName(source), Path.GetDirectoryName(target), StringComparison.OrdinalIgnoreCase))
|
|
88
|
-
throw new Exception("PATH");
|
|
89
|
-
Check(source, "file", true);
|
|
90
|
-
Check(Path.GetDirectoryName(source), "directory", true);
|
|
91
|
-
if (File.Exists(target))
|
|
92
|
-
{
|
|
93
|
-
if (exclusive)
|
|
94
|
-
throw new Exception("EXISTS");
|
|
95
|
-
Check(target, "file", true);
|
|
96
|
-
}
|
|
97
|
-
if (!MoveFileEx(source, target, 8U | (exclusive ? 0U : 1U)))
|
|
98
|
-
{
|
|
99
|
-
int error = Marshal.GetLastWin32Error();
|
|
100
|
-
if (error == 80 || error == 183)
|
|
101
|
-
throw new Exception("EXISTS");
|
|
102
|
-
throw new Win32Exception(error);
|
|
103
|
-
}
|
|
104
|
-
Check(target, "file", true);
|
|
105
|
-
}
|
|
106
|
-
static void CheckPipe(string path)
|
|
107
|
-
{
|
|
108
|
-
if (!System.Text.RegularExpressions.Regex.IsMatch(path, @"^\\\\\.\\pipe\\nvs-[0-9a-f]{64}$"))
|
|
109
|
-
throw new Exception("PIPE");
|
|
110
|
-
using (var handle = OpenPipe(path))
|
|
111
|
-
{
|
|
112
|
-
if (handle.IsInvalid)
|
|
113
|
-
throw new Win32Exception(Marshal.GetLastWin32Error());
|
|
114
|
-
IntPtr owner, group, dacl, sacl, descriptor;
|
|
115
|
-
uint result = GetSecurityInfo(handle, 1, 5, out owner, out group, out dacl, out sacl, out descriptor);
|
|
116
|
-
if (result != 0)
|
|
117
|
-
throw new Win32Exception((int)result);
|
|
118
|
-
try
|
|
119
|
-
{
|
|
120
|
-
uint length = GetSecurityDescriptorLength(descriptor);
|
|
121
|
-
var bytes = new byte[length];
|
|
122
|
-
Marshal.Copy(descriptor, bytes, 0, bytes.Length);
|
|
123
|
-
var acl = new FileSecurity();
|
|
124
|
-
acl.SetSecurityDescriptorBinaryForm(bytes);
|
|
125
|
-
Rules(acl, true);
|
|
126
|
-
}
|
|
127
|
-
finally { LocalFree(descriptor); }
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
static SafeFileHandle OpenPipe(string path)
|
|
131
|
-
{
|
|
132
|
-
for (int attempt = 0; attempt < 4; attempt++)
|
|
133
|
-
{
|
|
134
|
-
var handle = CreateFile(path, 0x20000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero);
|
|
135
|
-
if (!handle.IsInvalid)
|
|
136
|
-
return handle;
|
|
137
|
-
int error = Marshal.GetLastWin32Error();
|
|
138
|
-
handle.Dispose();
|
|
139
|
-
// Bounded readiness observation only; no authenticated request is retried.
|
|
140
|
-
if (error != 231 || attempt == 3 || !WaitNamedPipe(path, 250))
|
|
141
|
-
throw new Win32Exception(error);
|
|
142
|
-
}
|
|
143
|
-
throw new Exception("PIPE_BUSY");
|
|
144
|
-
}
|
|
145
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool MoveFileEx(string source, string target, uint flags);
|
|
146
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern SafeFileHandle CreateFile(string path, uint access, uint share, IntPtr sa, uint creation, uint flags, IntPtr template);
|
|
147
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool WaitNamedPipe(string path, uint milliseconds);
|
|
148
|
-
[DllImport("advapi32.dll", SetLastError = true)] static extern uint GetSecurityInfo(SafeFileHandle h, int type, uint info, out IntPtr owner, out IntPtr group, out IntPtr dacl, out IntPtr sacl, out IntPtr sd);
|
|
149
|
-
[DllImport("advapi32.dll")] static extern uint GetSecurityDescriptorLength(IntPtr sd);
|
|
150
|
-
[DllImport("kernel32.dll")] static extern IntPtr LocalFree(IntPtr p);
|
|
151
|
-
}
|
|
152
|
-
}
|