ドメイン コントローラーに対して一連の資格情報を検証したいと考えています。例えば:
Username: joel
Password: splotchy
Domain: STACKOVERFLOW
.NET 3.5 以降では、PrincipalContext.ValidateCredentials(username, password)
.
そうでなければ、あなたは困っています。
Microsoft ナレッジ ベースの記事How to validate user credentials on Microsoft operating systemsのコードに従って、次のように呼び出しますAcceptSecurityContext
。
ss = AcceptSecurityContext(
@pAS._hcred, //[in]CredHandle structure
phContext, //[in,out]CtxtHandle structure
@InBuffDesc, //[in]SecBufferDesc structure
0, //[in]context requirement flags
SECURITY_NATIVE_DREP, //[in]target data representation
@pAS._hctxt, //[in,out]CtxtHandle strcture
@OutBuffDesc, //[in,out]SecBufferDesc structure
ContextAttributes, //[out]Context attribute flags
@Lifetime); //[out]Timestamp struture
ただし、関数は次のエラーで失敗します。
SEC_E_NO_AUTHENTICATING_AUTHORITY
(0x80090311)関数が失敗しました。認証のために権限に接続できませんでした。これは、次の条件が原因である可能性があります。
- 認証側のドメイン名が正しくありません。
- ドメインが利用できません。
- 信頼関係に失敗しました。
これは、次を使用して .NET 3.5 から同じ資格情報を検証できることを除いて、有用なエラーです。
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, domain))
{
valid = context.ValidateCredentials(username, password);
}
ネイティブ コードではできないのに、.NET では一連の資格情報を検証できるようにするために何が起こっているのでしょうか?
更新:LogonUser
も失敗します:
LogonUser("joel@stackoverflow.com", null, "splotchy",
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_WINNT50, out token);
と
1311 - There are currently no logon servers available to service the logon request
更新 2Negotiate
: 優先プロバイダーと、Windows NT4 の従来の "NTLM" プロバイダーの両方を試しました。
String package = "Negotiate"; //"NTLM"
QuerySecurityPackageInfo(package, [out] packageInfo);
...
AcquireCredentialsHandle(
null, //[in] principle
package, //[in] package
SECPKG_CRED_OUTBOUND, //[in] credential use
null, //[in] LogonID
pAuthIdentity, //[in] authData
null, //[in] GetKeyFn, not used and should be null
null, //[in] GetKeyArgument, not used and should be null
credHandle, //[out] CredHandle structure
expires); //[out] expiration TimeStamp structure