|
@@ -46,6 +46,8 @@ namespace SMBLibrary.Win32.Security
|
|
|
|
|
|
private const uint SEC_WINNT_AUTH_IDENTITY_ANSI = 1;
|
|
|
private const uint SEC_WINNT_AUTH_IDENTITY_UNICODE = 2;
|
|
|
+
|
|
|
+ private const uint SECPKG_ATTR_ACCESS_TOKEN = 18;
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
private struct SECURITY_INTEGER
|
|
@@ -135,6 +137,12 @@ namespace SMBLibrary.Win32.Security
|
|
|
out uint pfContextAttr,
|
|
|
out SECURITY_INTEGER ptsTimeStamp);
|
|
|
|
|
|
+ [DllImport("secur32.Dll", SetLastError = true)]
|
|
|
+ private static extern int QueryContextAttributes(
|
|
|
+ ref SecHandle phContext,
|
|
|
+ uint ulAttribute,
|
|
|
+ out IntPtr pBuffer);
|
|
|
+
|
|
|
[DllImport("Secur32.dll")]
|
|
|
private extern static int FreeContextBuffer(
|
|
|
IntPtr pvContextBuffer
|
|
@@ -367,5 +375,19 @@ namespace SMBLibrary.Win32.Security
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static IntPtr GetAccessToken(SecHandle serverContext)
|
|
|
+ {
|
|
|
+ IntPtr pBuffer;
|
|
|
+ int result = QueryContextAttributes(ref serverContext, SECPKG_ATTR_ACCESS_TOKEN, out pBuffer);
|
|
|
+ if (result == SEC_E_OK)
|
|
|
+ {
|
|
|
+ return pBuffer;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return IntPtr.Zero;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|