【问题标题】:Need a C# signature for AcquireCredentialsHandle win32 api functionAcquireCredentialsHandle win32 api 函数需要 C# 签名
【发布时间】:2009-08-07 11:39:31
【问题描述】:

不知何故,我为这个 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);

请忽略 cmets。

我用作参考的基于 c 的函数调用可以在 here 找到。我想知道我做错了什么...

【问题讨论】:

    标签: c# winapi sspi


    【解决方案1】:

    你试过this at pinvoke.net吗?

    【讨论】:

      【解决方案2】:

      API1 文档指出,上面的结构似乎不正确

      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
      

      您还应该小心释放句柄,因为它是非托管的。

      【讨论】:

        【解决方案3】:

        来自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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-01-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-07
          • 2011-09-23
          相关资源
          最近更新 更多