[英]Need a C# signature for AcquireCredentialsHandle win32 api function
我以某種方式為該api調用提供了簽名,但是該調用無法以預期的方式工作。 一些重要的數據結構沒有正確填充,因此我沒有得到預期的輸出。 我使用的簽名是:
[DllImport("secur32.dll", SetLastError = true)]
static extern ulong AcquireCredentialsHandle(
string pszPrincipal,
string pszPackage,
ulong fCredentialsUse,
IntPtr pvLogonID,
ref SEC_WINNT_AUTH_IDENTITY pAuthData,
//IntPtr pAuthData,
IntPtr pGetKeyFn,
IntPtr pGetArgumentKey,
//ref SecHandle phCredential,
IntPtr phCredential,
ref TimeStamp ptsExpiry);
請忽略評論。
我用於參考的基於C的函數調用可以在此處找到。 我想知道我做錯了什么...
您是否在pinvoke.net嘗試過此操作 ?
上面的結構似乎不正確,因為文檔說明了API 1
typedef struct _SecHandle {
ULONG_PTR dwLower;
ULONG_PTR dwUpper;
} SecHandle, * PSecHandle;
這意味着上面的代碼可以在32位上工作,但是應該
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_HANDLE
{
public IntPtr LowPart;
public IntPtr HighPart;
public SECURITY_HANDLE(int dummy)
{
LowPart = HighPart = IntPtr.Zero;
}
};
這將適用於32位和64位模式。
其余部分將與以前相同
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_INTEGER
{
public uint LowPart;
public int HighPart;
public SECURITY_INTEGER(int dummy)
{
LowPart = 0;
HighPart = 0;
}
};
[DllImport("secur32.dll", SetLastError=true)]
static extern int AcquireCredentialsHandle(
string pszPrincipal, //SEC_CHAR*
string pszPackage, //SEC_CHAR* //"Kerberos","NTLM","Negotiative"
int fCredentialUse,
IntPtr PAuthenticationID,//_LUID AuthenticationID,//pvLogonID,//PLUID
IntPtr pAuthData,//PVOID
int pGetKeyFn, //SEC_GET_KEY_FN
IntPtr pvGetKeyArgument, //PVOID
ref SECURITY_HANDLE phCredential, //SecHandle //PCtxtHandle ref
ref SECURITY_INTEGER ptsExpiry); //PTimeStamp //TimeStamp ref
您還應小心釋放它,因為它是不受管理的。
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_INTEGER
{
public uint LowPart;
public int HighPart;
public SECURITY_INTEGER(int dummy)
{
LowPart = 0;
HighPart = 0;
}
};
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_HANDLE
{
public uint LowPart;
public uint HighPart;
public SECURITY_HANDLE(int dummy)
{
LowPart = HighPart = 0;
}
};
[DllImport("secur32.dll", SetLastError=true)]
static extern int AcquireCredentialsHandle(
string pszPrincipal, //SEC_CHAR*
string pszPackage, //SEC_CHAR* //"Kerberos","NTLM","Negotiative"
int fCredentialUse,
IntPtr PAuthenticationID,//_LUID AuthenticationID,//pvLogonID, //PLUID
IntPtr pAuthData,//PVOID
int pGetKeyFn, //SEC_GET_KEY_FN
IntPtr pvGetKeyArgument, //PVOID
ref SECURITY_HANDLE phCredential, //SecHandle //PCtxtHandle ref
ref SECURITY_INTEGER ptsExpiry); //PTimeStamp //TimeStamp ref
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.