大佬教程收集整理的这篇文章主要介绍了windows – 如何正确调用LsaLogonUser进行交互式登录?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我还尝试使用MSV1.0而不是Kerberos,MSV1_0_INTERACTIVE_logoN用于身份验证结构,MSV1_0_PACKAGE_NAME用作包名,但是使用STATUS_BAD_VALIDATION_CLASS(0xc00000a7)失败.
谁能告诉我这里做错了什么?这是代码,大部分错误处理都被剥离了.显然,这不是生产质量;我只想尝试一个工作样本.
// see below for deFinitions of these size_t wcsByteLen( const wchar_t* str ); void InitUnicodeString( UNICODE_StriNG& str,const wchar_t* value,BYTE* buffer,size_t& offset ); int main( int argc,char * argv[] ) { // connect to the LSA HANDLE lsa; LsaConnectUntrusted( &lsa ); const wchar_t* domain = L"mydomain"; const wchar_t* user = L"someuser"; const wchar_t* password = L"scaryplaintextpassword"; // prepare the authentication info ULONG authInfoSize = sizeof(KERB_INTERACTIVE_logoN) + wcsByteLen( domain ) + wcsByteLen( user ) + wcsByteLen( password ); BYTE* authInfoBuf = new BYTE[authInfoSize]; KERB_INTERACTIVE_logoN* authInfo = (KERB_INTERACTIVE_logoN*)authInfoBuf; authInfo->messageType = KerbInteractivelogon; size_t offset = sizeof(KERB_INTERACTIVE_logoN); InitUnicodeString( authInfo->logonDomainName,domain,authInfoBuf,offset ); InitUnicodeString( authInfo->UserName,user,offset ); InitUnicodeString( authInfo->password,password,offset ); // find the Kerberos security package char packagenameRaw[] = MICROSOFT_KERBEROS_NAME_A; LSA_StriNG packagename; packagename.buffer = packagenameRaw; packagename.Length = packagename.MaximumLength = (USHORT)strlen( packagename.buffer ); ULONG packagEID; LsaLookupAuthenticationPackage( lsa,&packagename,&packagEID ); // create a dummy origin and token source LSA_StriNG origin = {}; origin.buffer = _strdup( "TestAppFoo" ); origin.Length = (USHORT)strlen( origin.buffer ); origin.MaximumLength = origin.Length; TOKEN_sourcE source = {}; strcpy( source.sourcename,"foobar" ); AllocateLocallyUniquEID( &source.sourcEIDentifier ); void* profileBuffer; DWORD profileBufLen; LUID luid; HANDLE token; QUOTA_LIMITS qlimits; NTSTATUS subStatus; NTSTATUS status = LsalogonUser( lsa,&origin,Interactive,packagEID,&authInfo,authInfoSize,&source,&profileBuffer,&profileBufLen,&luid,&token,&qlimits,&subStatus ); if( status != ERROR_succesS ) { ULONG err = LsaNtStatusToWinError( status ); printf( "LsalogonUser Failed: %x\n",status ); return 1; } } size_t wcsByteLen( const wchar_t* str ) { return wcslen( str ) * sizeof(wchar_t); } void InitUnicodeString( UNICODE_StriNG& str,size_t& offset ) { size_t size = wcsByteLen( value ); str.Length = str.MaximumLength = (USHORT)size; str.buffer = (PWSTR)(buffer + offset); memcpy( str.buffer,value,size ); offset += size; }
以上是大佬教程为你收集整理的windows – 如何正确调用LsaLogonUser进行交互式登录?全部内容,希望文章能够帮你解决windows – 如何正确调用LsaLogonUser进行交互式登录?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。