开发者

AcquireCredentialsHandleW failing

I have a piece of code that attempts to acquire the credentials for a user on a remote computer which I cant get working. currently this produces an access violation error (0xc0000005) when run:


SEC_WINNT_AUTH_IDENTITY_W identity;
ZeroMemory(&identity, sizeof(identity));

identity.Domain = (unsigned short *)_T("DOMAIN");
identity.DomainLength = lstrlenW(_T("DOMAIN"));
identity.User = (unsigned short *)_T("USER");
identity.UserLength = lstrlenW(_T("USER"));
identity.Password = (unsigned short *)_T("PASS");
identity.PasswordLength = lstrlenW(_T("PASS"));
identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;

PCredHandle credentials = NULL;
PTimeStamp credentialsExpiry = NULL;

SECURITY_STATUS result = AcquireCredentialsHandleW(_T开发者_如何转开发("USER"), _T("NTLM"), SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, credentials, credentialsExpiry);

and i have no idea why. any assistance would be very welcome.


You need to change the last section of code to look like this:

CredHandle credentials;
TimeStamp credentialsExpiry;

SECURITY_STATUS result = AcquireCredentialsHandleW(_T("USER"), _T("NTLM"), 
    SECPKG_CRED_OUTBOUND, NULL, &identity, NULL, NULL, 
    &credentials, &credentialsExpiry);

Per MSDN docs, the pointers in the last 2 parameters are not optional on your call:

phCredential [out]

A pointer to a CredHandle structure to receive the credential handle.

ptsExpiry [out]

A pointer to a TimeStamp structure that receives the time at which the returned credentials expire. The value returned in this TimeStamp structure depends on the security package. The security package must return this value in local time.

This parameter is set to a constant maximum time. There is no expiration time for Digest security contexts or credentials or when using the Digest SSP.

When using the Schannel SSP, this parameter is optional. When the credential to be used for authentication is a certificate, this parameter receives the expiration time for that certificate. If no certificate was supplied, then a maximum time value is returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜