简体   繁体   English

需要AcquireCredentialsHandle win32 api函数的C#签名

[英]Need a C# signature for AcquireCredentialsHandle win32 api function

I have somehow come out with a signature for this api call, but the call does not work in the expected fashion. 我以某种方式为该api调用提供了签名,但是该调用无法以预期的方式工作。 Some vital data structures are not get populated properly hence I am not getting intended output. 一些重要的数据结构没有正确填充,因此我没有得到预期的输出。 The signature I've used is: 我使用的签名是:

[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);

Please ignore the comments. 请忽略评论。

The c-based function call I used for reference can be found here . 我用于参考的基于C的函数调用可以在此处找到。 I want to know what did I do wrong... 我想知道我做错了什么...

您是否在pinvoke.net尝试过此操作

The struct above doesn't seem correct as the API 1 the documentation states 上面的结构似乎不正确,因为文档说明了API 1

typedef struct _SecHandle {
  ULONG_PTR       dwLower;
  ULONG_PTR       dwUpper;
} SecHandle, * PSecHandle;

That means that the code above will work on 32bit but should be 这意味着上面的代码可以在32位上工作,但是应该

[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_HANDLE
{
    public IntPtr LowPart;
    public IntPtr HighPart;
    public SECURITY_HANDLE(int dummy)
    {
        LowPart = HighPart = IntPtr.Zero;
    }
};

This will work on both 32bit and 64bit modes. 这将适用于32位和64位模式。

The rest will be the same as previously 其余部分将与以前相同

[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

You should also be careful to free the handle as it is unmanaged. 您还应小心释放它,因为它是不受管理的。

From pInvoke.net pInvoke.net

[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM