@ciandt-flow/cli 1.4.1-beta.172 → 1.4.1-beta.176
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/dist/index.js +29 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,26 +8,26 @@ using System.Runtime.InteropServices;
|
|
|
8
8
|
using System.Text;
|
|
9
9
|
|
|
10
10
|
public class FlowCredManager {
|
|
11
|
-
[StructLayout(LayoutKind.Sequential
|
|
11
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
12
12
|
private struct CREDENTIAL {
|
|
13
13
|
public int Flags;
|
|
14
14
|
public int Type;
|
|
15
|
-
public
|
|
16
|
-
public
|
|
15
|
+
public IntPtr TargetName;
|
|
16
|
+
public IntPtr Comment;
|
|
17
17
|
public long LastWritten;
|
|
18
18
|
public int CredentialBlobSize;
|
|
19
19
|
public IntPtr CredentialBlob;
|
|
20
20
|
public int Persist;
|
|
21
21
|
public int AttributeCount;
|
|
22
22
|
public IntPtr Attributes;
|
|
23
|
-
public
|
|
24
|
-
public
|
|
23
|
+
public IntPtr TargetAlias;
|
|
24
|
+
public IntPtr UserName;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
28
28
|
private static extern bool CredRead(string target, int type, int flags, out IntPtr credential);
|
|
29
29
|
|
|
30
|
-
[DllImport("advapi32.dll", SetLastError = true
|
|
30
|
+
[DllImport("advapi32.dll", SetLastError = true)]
|
|
31
31
|
private static extern bool CredWrite(ref CREDENTIAL credential, int flags);
|
|
32
32
|
|
|
33
33
|
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
@@ -48,22 +48,31 @@ public class FlowCredManager {
|
|
|
48
48
|
|
|
49
49
|
public static string Write(string target, string secret, string userName) {
|
|
50
50
|
byte[] bytes = Encoding.Unicode.GetBytes(secret);
|
|
51
|
+
IntPtr targetPtr = Marshal.StringToHGlobalUni(target);
|
|
52
|
+
IntPtr userPtr = Marshal.StringToHGlobalUni(userName);
|
|
51
53
|
int[] persistLevels = new int[] { ${Rl}, ${Ml}, ${Ll} };
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
int lastErr = 0;
|
|
55
|
+
try {
|
|
56
|
+
foreach (int persist in persistLevels) {
|
|
57
|
+
IntPtr blobPtr = Marshal.AllocHGlobal(bytes.Length);
|
|
58
|
+
try {
|
|
59
|
+
Marshal.Copy(bytes, 0, blobPtr, bytes.Length);
|
|
60
|
+
var cred = new CREDENTIAL();
|
|
61
|
+
cred.Type = ${kn};
|
|
62
|
+
cred.TargetName = targetPtr;
|
|
63
|
+
cred.CredentialBlobSize = bytes.Length;
|
|
64
|
+
cred.CredentialBlob = blobPtr;
|
|
65
|
+
cred.Persist = persist;
|
|
66
|
+
cred.UserName = userPtr;
|
|
67
|
+
if (CredWrite(ref cred, 0)) return "OK:" + persist;
|
|
68
|
+
lastErr = Marshal.GetLastWin32Error();
|
|
69
|
+
} finally { Marshal.FreeHGlobal(blobPtr); }
|
|
70
|
+
}
|
|
71
|
+
return "ERR:" + lastErr;
|
|
72
|
+
} finally {
|
|
73
|
+
Marshal.FreeHGlobal(targetPtr);
|
|
74
|
+
Marshal.FreeHGlobal(userPtr);
|
|
64
75
|
}
|
|
65
|
-
int err = Marshal.GetLastWin32Error();
|
|
66
|
-
return "ERR:" + err;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
public static bool Delete(string target) {
|