如何正确配置 AcquireCredentialsHandleA

how to configure the AcquireCredentialsHandleA correctly

我正在尝试设置一个 windows SSPI 程序来读取验证当前用户 (https://docs.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-acquirecredentialshandlea)。

奇怪的是它不工作并给我一个错误。

//ERROR DETAILS
// MessageId: SEC_E_INVALID_TOKEN
//
// MessageText:
//
// The token supplied to the function is invalid
//
#define SEC_E_INVALID_TOKEN HRESULT_TYPEDEF(0x80090308L)

我想出的代码如下。

    // Create an SSPI credential.
    Status = g_pSSPI->AcquireCredentialsHandleA(
    pN,                   // Name of principal          
    ppPackageInfo[2].Name,//sec_package_name.c_str,         
    SECPKG_CRED_OUTBOUND, // Flags indicating use
    NULL,                 // Pointer to logon ID
    cred_ptr,            // Package specific data
    NULL,                 // Pointer to GetKey() func
    NULL,                 // Value to pass to GetKey()
    phCreds,              // (out) Cred Handle
    &tsExpiry             // (out) Lifetime (optional)
);  

我不明白如何在此处提供凭据的详细信息。我想在这里使用kerberos。

cred_ptr 应该是指向 https://docs.microsoft.com/en-us/windows/win32/api/credssp/ns-credssp-credssp_cred 的指针 但是 MSDN 只是说

pSpnegoCred

A pointer to a set of Negotiate credentials.

如何准确填写??有没有人对此有更好的理解?

感谢您的宝贵时间。

如果使用 kerberos 提供程序,您传递 SEC_WINNT_AUTH_IDENTITY,而不是 CREDSSP_CRED。

看看 AcquireCredentialsHandle (Kerberos),您正在查看的页面是针对 CredSSP 的,但没有说清楚。