Ejemplo n.º 1
0
        public bool PurgeTicket(Ticket ticket)
        {
            byte[] bytes1       = Encoding.Unicode.GetBytes(ticket.ServerName + "\0");
            byte[] bytes2       = Encoding.Unicode.GetBytes(ticket.RealmName + "\0");
            int    cb           = 28 + bytes1.Length + bytes2.Length;
            IntPtr num          = Marshal.AllocHGlobal(cb);
            IntPtr destination1 = new IntPtr(num.ToInt64() + 28L);
            IntPtr destination2 = new IntPtr(num.ToInt64() + 28L + (long)bytes1.Length);

            Marshal.Copy(bytes1, 0, destination1, bytes1.Length);
            Marshal.Copy(bytes2, 0, destination2, bytes2.Length);
            UNICODE_STRING unicodeString1;

            unicodeString1.Length        = (ushort)(bytes1.Length - 2);
            unicodeString1.MaximumLength = (ushort)bytes1.Length;
            unicodeString1.Buffer        = destination1;
            UNICODE_STRING unicodeString2;

            unicodeString2.Length        = (ushort)(bytes2.Length - 2);
            unicodeString2.MaximumLength = (ushort)bytes2.Length;
            unicodeString2.Buffer        = destination2;
            KERB_PURGE_TKT_CACHE_REQUEST purgeTktCacheRequest;

            purgeTktCacheRequest.MessageType = KERB_PROTOCOL_MESSAGE_TYPE.KerbPurgeTicketCacheMessage;
            purgeTktCacheRequest.ServerName  = unicodeString1;
            purgeTktCacheRequest.RealmName   = unicodeString2;
            purgeTktCacheRequest.LogonId     = 0L;
            Marshal.StructureToPtr((object)purgeTktCacheRequest, num, false);
            uint           ProtocolStatus;
            WinStatusCodes winStatusCodes = Lsa.LsaPurgeTickets(this._lsaHandle, this._kerberosPackageId, num, (uint)cb, out IntPtr _, out uint _, out ProtocolStatus);

            Marshal.FreeHGlobal(num);
            if (winStatusCodes != WinStatusCodes.STATUS_SUCCESS)
            {
                throw new Exception("LsaCallAuthenticationPackage (LsaGetTickets) failed with NTSTATUS code: " + (object)winStatusCodes + " (0x" + winStatusCodes.ToString("x8") + ")");
            }
            return(ProtocolStatus == 0U);
        }