我已经以某种方式出现了这个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的函数调用here。我想知道我做错了什么......
答案 0 :(得分:2)
你试过this at pinvoke.net吗?
答案 1 :(得分:2)
上面的结构似乎不正确,因为文档声明的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
你也应该小心释放句柄,因为它是不受管理的。
答案 2 :(得分:1)
[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