1414
1515using NtApiDotNet . Win32 . SafeHandles ;
1616using NtApiDotNet . Win32 . Security . Authentication ;
17+ using NtApiDotNet . Win32 . Security . Authentication . Kerberos ;
1718using NtApiDotNet . Win32 . Security . Native ;
1819using NtApiDotNet . Win32 . Security . Policy ;
1920using System ;
@@ -152,6 +153,36 @@ public static NtToken Logon(string user, string domain, string password, Securit
152153 }
153154 }
154155
156+ /// <summary>
157+ /// Logon user using Kerberos Ticket.
158+ /// </summary>
159+ /// <param name="type">The type of logon token.</param>
160+ /// <param name="service_ticket">The service ticket.</param>
161+ /// <param name="tgt_ticket">Optional TGT.</param>
162+ /// <param name="throw_on_error">True to throw on error.</param>
163+ /// <returns>The logged on token.</returns>
164+ public static NtResult < NtToken > LsaLogonTicket ( SecurityLogonType type , KerberosTicket service_ticket , KerberosCredential tgt_ticket , bool throw_on_error )
165+ {
166+ if ( service_ticket is null )
167+ {
168+ throw new ArgumentNullException ( nameof ( service_ticket ) ) ;
169+ }
170+
171+ return LsaLogonTicket ( type , service_ticket . TicketData , tgt_ticket ? . ToArray ( ) , throw_on_error ) ;
172+ }
173+
174+ /// <summary>
175+ /// Logon user using Kerberos Ticket.
176+ /// </summary>
177+ /// <param name="type">The type of logon token.</param>
178+ /// <param name="service_ticket">The service ticket.</param>
179+ /// <param name="tgt_ticket">Optional TGT.</param>
180+ /// <returns>The logged on token.</returns>
181+ public static NtToken LsaLogonTicket ( SecurityLogonType type , KerberosTicket service_ticket , KerberosCredential tgt_ticket )
182+ {
183+ return LsaLogonTicket ( type , service_ticket , tgt_ticket , true ) . Result ;
184+ }
185+
155186 /// <summary>
156187 /// Logon user using Kerberos Ticket.
157188 /// </summary>
@@ -466,10 +497,10 @@ private static NtResult<NtToken> LsaLogonUser(SecurityLogonType type, string aut
466497 var hlsa = list . AddResource ( SafeLsaLogonHandle . Connect ( throw_on_error ) ) ;
467498 if ( ! hlsa . IsSuccess )
468499 return hlsa . Cast < NtToken > ( ) ;
469- NtStatus status = SecurityNativeMethods . LsaLookupAuthenticationPackage (
470- hlsa . Result , new LsaString ( auth_package ) , out uint auth_pkg ) ;
471- if ( ! status . IsSuccess ( ) )
472- return status . CreateResultFromError < NtToken > ( throw_on_error ) ;
500+
501+ var auth_pkg = hlsa . Result . LookupAuthPackage ( auth_package , throw_on_error ) ;
502+ if ( ! auth_pkg . IsSuccess )
503+ return auth_pkg . Cast < NtToken > ( ) ;
473504
474505 var groups = local_groups == null ? SafeTokenGroupsBuffer . Null
475506 : list . AddResource ( SafeTokenGroupsBuffer . Create ( local_groups ) ) ;
@@ -478,7 +509,7 @@ private static NtResult<NtToken> LsaLogonUser(SecurityLogonType type, string aut
478509 SecurityNativeMethods . AllocateLocallyUniqueId ( out tokenSource . SourceIdentifier ) ;
479510 QUOTA_LIMITS quota_limits = new QUOTA_LIMITS ( ) ;
480511 return SecurityNativeMethods . LsaLogonUser ( hlsa . Result , new LsaString ( origin_name ) ,
481- type , auth_pkg , buffer , buffer . GetLength ( ) , groups ,
512+ type , auth_pkg . Result , buffer , buffer . GetLength ( ) , groups ,
482513 tokenSource , out SafeLsaReturnBufferHandle profile ,
483514 out int cbProfile , out Luid logon_id , out SafeKernelObjectHandle token_handle ,
484515 quota_limits , out NtStatus subStatus ) . CreateResult ( throw_on_error , ( ) =>
0 commit comments