### ms-nrpc.idl
"""
RPC definitions for the following interfaces:
- logon (v1.0): 12345678-1234-ABCD-EF00-01234567CFFB
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import PacketListField, StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFieldListField,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


class PNETLOGON_VALIDATION_UAS_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("usrlog1_eff_name", ""), deferred=True
        ),
        NDRIntField("usrlog1_priv", 0),
        NDRIntField("usrlog1_auth_flags", 0),
        NDRIntField("usrlog1_num_logons", 0),
        NDRIntField("usrlog1_bad_pw_count", 0),
        NDRIntField("usrlog1_last_logon", 0),
        NDRIntField("usrlog1_last_logoff", 0),
        NDRIntField("usrlog1_logoff_time", 0),
        NDRIntField("usrlog1_kickoff_time", 0),
        NDRIntField("usrlog1_password_age", 0),
        NDRIntField("usrlog1_pw_can_change", 0),
        NDRIntField("usrlog1_pw_must_change", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("usrlog1_computer", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("usrlog1_domain", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("usrlog1_script_path", ""), deferred=True
        ),
        NDRIntField("usrlog1_reserved1", 0),
    ]


class NetrLogonUasLogon_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("UserName", ""),
        NDRConfVarStrNullFieldUtf16("Workstation", ""),
    ]


class NetrLogonUasLogon_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ValidationInformation",
                PNETLOGON_VALIDATION_UAS_INFO(),
                PNETLOGON_VALIDATION_UAS_INFO,
            )
        ),
        NDRIntField("status", 0),
    ]


class PNETLOGON_LOGOFF_UAS_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("Duration", 0), NDRShortField("LogonCount", 0)]


class NetrLogonUasLogoff_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("UserName", ""),
        NDRConfVarStrNullFieldUtf16("Workstation", ""),
    ]


class NetrLogonUasLogoff_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "LogoffInformation", PNETLOGON_LOGOFF_UAS_INFO(), PNETLOGON_LOGOFF_UAS_INFO
        ),
        NDRIntField("status", 0),
    ]


class NETLOGON_CREDENTIAL(NDRPacket):
    fields_desc = [StrFixedLenField("data", "", length=8)]


class PNETLOGON_AUTHENTICATOR(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("Credential", NETLOGON_CREDENTIAL(), NETLOGON_CREDENTIAL),
        NDRIntField("Timestamp", 0),
    ]


class NETLOGON_LOGON_INFO_CLASS(IntEnum):
    NetlogonInteractiveInformation = 1
    NetlogonNetworkInformation = 2
    NetlogonServiceInformation = 3
    NetlogonGenericInformation = 4
    NetlogonInteractiveTransitiveInformation = 5
    NetlogonNetworkTransitiveInformation = 6
    NetlogonServiceTransitiveInformation = 7


class RPC_UNICODE_STRING(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
        NDRShortField(
            "MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
        ),
        NDRFullPointerField(
            NDRConfVarStrLenFieldUtf16(
                "Buffer",
                "",
                size_is=lambda pkt: (pkt.MaximumLength // 2),
                length_is=lambda pkt: (pkt.Length // 2),
            ),
            deferred=True,
        ),
    ]


class OLD_LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("LowPart", 0), NDRSignedIntField("HighPart", 0)]


class NETLOGON_LOGON_IDENTITY_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("LogonDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("ParameterControl", 0),
        NDRPacketField("Reserved", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("UserName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("Workstation", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
    ]


class CYPHER_BLOCK(NDRPacket):
    fields_desc = [StrFixedLenField("data", "", length=8)]


class LM_OWF_PASSWORD(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class NT_OWF_PASSWORD(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class PNETLOGON_INTERACTIVE_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "Identity", NETLOGON_LOGON_IDENTITY_INFO(), NETLOGON_LOGON_IDENTITY_INFO
        ),
        NDRPacketField("LmOwfPassword", LM_OWF_PASSWORD(), LM_OWF_PASSWORD),
        NDRPacketField("NtOwfPassword", NT_OWF_PASSWORD(), NT_OWF_PASSWORD),
    ]


class PNETLOGON_SERVICE_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "Identity", NETLOGON_LOGON_IDENTITY_INFO(), NETLOGON_LOGON_IDENTITY_INFO
        ),
        NDRPacketField("LmOwfPassword", LM_OWF_PASSWORD(), LM_OWF_PASSWORD),
        NDRPacketField("NtOwfPassword", NT_OWF_PASSWORD(), NT_OWF_PASSWORD),
    ]


class LM_CHALLENGE(NDRPacket):
    fields_desc = [StrFixedLenField("data", "", length=8)]


class STRING(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Length", None, size_of="Buffer"),
        NDRShortField("MaximumLength", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfVarStrLenField(
                "Buffer",
                "",
                size_is=lambda pkt: pkt.MaximumLength,
                length_is=lambda pkt: pkt.Length,
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_NETWORK_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "Identity", NETLOGON_LOGON_IDENTITY_INFO(), NETLOGON_LOGON_IDENTITY_INFO
        ),
        NDRPacketField("LmChallenge", LM_CHALLENGE(), LM_CHALLENGE),
        NDRPacketField("NtChallengeResponse", STRING(), STRING),
        NDRPacketField("LmChallengeResponse", STRING(), STRING),
    ]


class PNETLOGON_GENERIC_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "Identity", NETLOGON_LOGON_IDENTITY_INFO(), NETLOGON_LOGON_IDENTITY_INFO
        ),
        NDRPacketField("PackageName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DataLength", None, size_of="LogonData"),
        NDRFullPointerField(
            NDRConfStrLenField("LogonData", "", size_is=lambda pkt: pkt.DataLength),
            deferred=True,
        ),
    ]


class NETLOGON_VALIDATION_INFO_CLASS(IntEnum):
    NetlogonValidationUasInfo = 1
    NetlogonValidationSamInfo = 2
    NetlogonValidationSamInfo2 = 3
    NetlogonValidationGenericInfo = 4
    NetlogonValidationGenericInfo2 = 5
    NetlogonValidationSamInfo4 = 6


class PGROUP_MEMBERSHIP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("RelativeId", 0), NDRIntField("Attributes", 0)]


class USER_SESSION_KEY(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class RPC_SID_IDENTIFIER_AUTHORITY(NDRPacket):
    fields_desc = [StrFixedLenField("Value", "", length=6)]


class PRPC_SID(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["SubAuthority"]
    fields_desc = [
        NDRByteField("Revision", 0),
        NDRByteField("SubAuthorityCount", None, size_of="SubAuthority"),
        NDRPacketField(
            "IdentifierAuthority",
            RPC_SID_IDENTIFIER_AUTHORITY(),
            RPC_SID_IDENTIFIER_AUTHORITY,
        ),
        NDRConfFieldListField(
            "SubAuthority",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.SubAuthorityCount,
            conformant_in_struct=True,
        ),
    ]


class PNETLOGON_VALIDATION_SAM_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("LogonTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LogoffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("KickOffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordLastSet", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordCanChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordMustChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("EffectiveName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("FullName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonScript", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ProfilePath", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectory", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectoryDrive", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRShortField("LogonCount", 0),
        NDRShortField("BadPasswordCount", 0),
        NDRIntField("UserId", 0),
        NDRIntField("PrimaryGroupId", 0),
        NDRIntField("GroupCount", None, size_of="GroupIds"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "GroupIds",
                [PGROUP_MEMBERSHIP()],
                PGROUP_MEMBERSHIP,
                size_is=lambda pkt: pkt.GroupCount,
            ),
            deferred=True,
        ),
        NDRIntField("UserFlags", 0),
        NDRPacketField("UserSessionKey", USER_SESSION_KEY(), USER_SESSION_KEY),
        NDRPacketField("LogonServer", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRFullPointerField(
            NDRPacketField("LogonDomainId", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRFieldListField(
            "ExpansionRoom", [], NDRIntField("", 0), length_is=lambda _: 10
        ),
    ]


class PNETLOGON_SID_AND_ATTRIBUTES(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("Sid", PRPC_SID(), PRPC_SID), deferred=True),
        NDRIntField("Attributes", 0),
    ]


class PNETLOGON_VALIDATION_SAM_INFO2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("LogonTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LogoffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("KickOffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordLastSet", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordCanChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordMustChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("EffectiveName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("FullName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonScript", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ProfilePath", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectory", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectoryDrive", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRShortField("LogonCount", 0),
        NDRShortField("BadPasswordCount", 0),
        NDRIntField("UserId", 0),
        NDRIntField("PrimaryGroupId", 0),
        NDRIntField("GroupCount", None, size_of="GroupIds"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "GroupIds",
                [PGROUP_MEMBERSHIP()],
                PGROUP_MEMBERSHIP,
                size_is=lambda pkt: pkt.GroupCount,
            ),
            deferred=True,
        ),
        NDRIntField("UserFlags", 0),
        NDRPacketField("UserSessionKey", USER_SESSION_KEY(), USER_SESSION_KEY),
        NDRPacketField("LogonServer", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRFullPointerField(
            NDRPacketField("LogonDomainId", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRFieldListField(
            "ExpansionRoom", [], NDRIntField("", 0), length_is=lambda _: 10
        ),
        NDRIntField("SidCount", None, size_of="ExtraSids"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ExtraSids",
                [PNETLOGON_SID_AND_ATTRIBUTES()],
                PNETLOGON_SID_AND_ATTRIBUTES,
                size_is=lambda pkt: pkt.SidCount,
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_VALIDATION_GENERIC_INFO2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("DataLength", None, size_of="ValidationData"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "ValidationData", "", size_is=lambda pkt: pkt.DataLength
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_VALIDATION_SAM_INFO4(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("LogonTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LogoffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("KickOffTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordLastSet", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordCanChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("PasswordMustChange", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("EffectiveName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("FullName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonScript", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ProfilePath", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectory", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectoryDrive", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRShortField("LogonCount", 0),
        NDRShortField("BadPasswordCount", 0),
        NDRIntField("UserId", 0),
        NDRIntField("PrimaryGroupId", 0),
        NDRIntField("GroupCount", None, size_of="GroupIds"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "GroupIds",
                [PGROUP_MEMBERSHIP()],
                PGROUP_MEMBERSHIP,
                size_is=lambda pkt: pkt.GroupCount,
            ),
            deferred=True,
        ),
        NDRIntField("UserFlags", 0),
        NDRPacketField("UserSessionKey", USER_SESSION_KEY(), USER_SESSION_KEY),
        NDRPacketField("LogonServer", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LogonDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRFullPointerField(
            NDRPacketField("LogonDomainId", PRPC_SID(), PRPC_SID), deferred=True
        ),
        StrFixedLenField("LMKey", "", length=8),
        NDRIntField("UserAccountControl", 0),
        NDRIntField("SubAuthStatus", 0),
        NDRPacketField("LastSuccessfulILogon", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LastFailedILogon", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRIntField("FailedILogonCount", 0),
        NDRFieldListField("Reserved4", [], NDRIntField("", 0), length_is=lambda _: 1),
        NDRIntField("SidCount", None, size_of="ExtraSids"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ExtraSids",
                [PNETLOGON_SID_AND_ATTRIBUTES()],
                PNETLOGON_SID_AND_ATTRIBUTES,
                size_is=lambda pkt: pkt.SidCount,
            ),
            deferred=True,
        ),
        NDRPacketField("DnsLogonDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("Upn", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString5", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString6", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString7", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString8", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString9", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ExpansionString10", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
    ]


class NetrLogonSamLogon_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("LogonServer", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(
            NDRPacketField(
                "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRInt3264EnumField("LogonLevel", 0, NETLOGON_LOGON_INFO_CLASS),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_GENERIC_INFO(),
                            PNETLOGON_GENERIC_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                    ),
                ),
            ],
            StrFixedLenField("LogonInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRInt3264EnumField("ValidationLevel", 0, NETLOGON_VALIDATION_INFO_CLASS),
    ]


class NetrLogonSamLogon_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO(),
                            PNETLOGON_VALIDATION_SAM_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO2(),
                            PNETLOGON_VALIDATION_SAM_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_GENERIC_INFO2(),
                            PNETLOGON_VALIDATION_GENERIC_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO4(),
                            PNETLOGON_VALIDATION_SAM_INFO4,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                    ),
                ),
            ],
            StrFixedLenField("ValidationInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRByteField("Authoritative", 0),
        NDRIntField("status", 0),
    ]


class NetrLogonSamLogoff_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("LogonServer", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(
            NDRPacketField(
                "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRInt3264EnumField("LogonLevel", 0, NETLOGON_LOGON_INFO_CLASS),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_GENERIC_INFO(),
                            PNETLOGON_GENERIC_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                    ),
                ),
            ],
            StrFixedLenField("LogonInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class NetrLogonSamLogoff_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRIntField("status", 0),
    ]


class PNETLOGON_CREDENTIAL(NDRPacket):
    fields_desc = [StrFixedLenField("data", "", length=8)]


class NetrServerReqChallenge_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField("ClientChallenge", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL),
    ]


class NetrServerReqChallenge_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ServerChallenge", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL),
        NDRIntField("status", 0),
    ]


class NETLOGON_SECURE_CHANNEL_TYPE(IntEnum):
    NullSecureChannel = 0
    MsvApSecureChannel = 1
    WorkstationSecureChannel = 2
    TrustedDnsDomainSecureChannel = 3
    TrustedDomainSecureChannel = 4
    UasServerSecureChannel = 5
    ServerSecureChannel = 6
    CdcServerSecureChannel = 7


class NetrServerAuthenticate_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "ClientCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
    ]


class NetrServerAuthenticate_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ServerCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
        NDRIntField("status", 0),
    ]


class PENCRYPTED_NT_OWF_PASSWORD(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class NetrServerPasswordSet_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "UasNewPassword", PENCRYPTED_NT_OWF_PASSWORD(), PENCRYPTED_NT_OWF_PASSWORD
        ),
    ]


class NetrServerPasswordSet_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("status", 0),
    ]


class PNLPR_MODIFIED_COUNT(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("ModifiedCount", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER)
    ]


class NETLOGON_DELTA_TYPE(IntEnum):
    AddOrChangeDomain = 1
    AddOrChangeGroup = 2
    DeleteGroup = 3
    RenameGroup = 4
    AddOrChangeUser = 5
    DeleteUser = 6
    RenameUser = 7
    ChangeGroupMembership = 8
    AddOrChangeAlias = 9
    DeleteAlias = 10
    RenameAlias = 11
    ChangeAliasMembership = 12
    AddOrChangeLsaPolicy = 13
    AddOrChangeLsaTDomain = 14
    DeleteLsaTDomain = 15
    AddOrChangeLsaAccount = 16
    DeleteLsaAccount = 17
    AddOrChangeLsaSecret = 18
    DeleteLsaSecret = 19
    DeleteGroupByName = 20
    DeleteUserByName = 21
    SerialNumberSkip = 22


class PNETLOGON_DELTA_DOMAIN(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("DomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("OemInformation", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ForceLogoff", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRShortField("MinPasswordLength", 0),
        NDRShortField("PasswordHistoryLength", 0),
        NDRPacketField("MaxPasswordAge", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("MinPasswordAge", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("DomainModifiedCount", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("DomainCreationTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField(
            "DomainLockoutInformation", RPC_UNICODE_STRING(), RPC_UNICODE_STRING
        ),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("PasswordProperties", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_GROUP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("Name", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("RelativeId", 0),
        NDRIntField("Attributes", 0),
        NDRPacketField("AdminComment", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_RENAME_GROUP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("OldName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("NewName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class NLPR_LOGON_HOURS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField(
            "UnitsPerWeek",
            None,
            size_of="LogonHours",
            adjust=lambda _, x: ((x * 8) - 7),
        ),
        NDRFullPointerField(
            NDRConfVarStrLenField(
                "LogonHours",
                "",
                size_is=lambda pkt: 1260,
                length_is=lambda pkt: ((pkt.UnitsPerWeek + 7) // 8),
            ),
            deferred=True,
        ),
    ]


class ENCRYPTED_NT_OWF_PASSWORD(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class ENCRYPTED_LM_OWF_PASSWORD(NDRPacket):
    fields_desc = [PacketListField("data", [], CYPHER_BLOCK, count_from=lambda _: 2)]


class NLPR_USER_PRIVATE_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRByteField("SensitiveData", 0),
        NDRIntField("DataLength", None, size_of="Data"),
        NDRFullPointerField(
            NDRConfStrLenField("Data", "", size_is=lambda pkt: pkt.DataLength),
            deferred=True,
        ),
    ]


class PNETLOGON_DELTA_USER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("UserName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("FullName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("UserId", 0),
        NDRIntField("PrimaryGroupId", 0),
        NDRPacketField("HomeDirectory", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("HomeDirectoryDrive", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("ScriptPath", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("AdminComment", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("WorkStations", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("LastLogon", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LastLogoff", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("LogonHours", NLPR_LOGON_HOURS(), NLPR_LOGON_HOURS),
        NDRShortField("BadPasswordCount", 0),
        NDRShortField("LogonCount", 0),
        NDRPacketField("PasswordLastSet", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("AccountExpires", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRIntField("UserAccountControl", 0),
        NDRPacketField(
            "EncryptedNtOwfPassword",
            ENCRYPTED_NT_OWF_PASSWORD(),
            ENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRPacketField(
            "EncryptedLmOwfPassword",
            ENCRYPTED_LM_OWF_PASSWORD(),
            ENCRYPTED_LM_OWF_PASSWORD,
        ),
        NDRByteField("NtPasswordPresent", 0),
        NDRByteField("LmPasswordPresent", 0),
        NDRByteField("PasswordExpired", 0),
        NDRPacketField("UserComment", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("Parameters", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRShortField("CountryCode", 0),
        NDRShortField("CodePage", 0),
        NDRPacketField("PrivateData", NLPR_USER_PRIVATE_INFO(), NLPR_USER_PRIVATE_INFO),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("ProfilePath", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_RENAME_USER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("OldName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("NewName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_GROUP_MEMBER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfFieldListField(
                "Members",
                [],
                NDRIntField("Members", 0),
                size_is=lambda pkt: pkt.MemberCount,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfFieldListField(
                "Attributes",
                [],
                NDRIntField("Attributes", 0),
                size_is=lambda pkt: pkt.MemberCount,
            ),
            deferred=True,
        ),
        NDRIntField("MemberCount", None, size_of="Attributes"),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_ALIAS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("Name", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("RelativeId", 0),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("Comment", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_RENAME_ALIAS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("OldName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("NewName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNLPR_SID_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("SidPointer", PRPC_SID(), PRPC_SID), deferred=True
        )
    ]


class NLPR_SID_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Count", None, size_of="Sids"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Sids",
                [PNLPR_SID_INFORMATION()],
                PNLPR_SID_INFORMATION,
                size_is=lambda pkt: pkt.Count,
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_DELTA_ALIAS_MEMBER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("Members", NLPR_SID_ARRAY(), NLPR_SID_ARRAY),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class NLPR_QUOTA_LIMITS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("PagedPoolLimit", 0),
        NDRIntField("NonPagedPoolLimit", 0),
        NDRIntField("MinimumWorkingSetSize", 0),
        NDRIntField("MaximumWorkingSetSize", 0),
        NDRIntField("PagefileLimit", 0),
        NDRPacketField("Reserved", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
    ]


class PNETLOGON_DELTA_POLICY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("MaximumLogSize", 0),
        NDRPacketField("AuditRetentionPeriod", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRByteField("AuditingMode", 0),
        NDRIntField(
            "MaximumAuditEventCount",
            None,
            size_of="EventAuditingOptions",
            adjust=lambda _, x: (x - 1),
        ),
        NDRFullPointerField(
            NDRConfFieldListField(
                "EventAuditingOptions",
                [],
                NDRIntField("EventAuditingOptions", 0),
                size_is=lambda pkt: (pkt.MaximumAuditEventCount + 1),
            ),
            deferred=True,
        ),
        NDRPacketField("PrimaryDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRFullPointerField(
            NDRPacketField("PrimaryDomainSid", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRPacketField("QuotaLimits", NLPR_QUOTA_LIMITS(), NLPR_QUOTA_LIMITS),
        NDRPacketField("ModifiedId", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("DatabaseCreationTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PRPC_UNICODE_STRING(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
        NDRShortField(
            "MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
        ),
        NDRFullPointerField(
            NDRConfVarStrLenFieldUtf16(
                "Buffer",
                "",
                size_is=lambda pkt: (pkt.MaximumLength // 2),
                length_is=lambda pkt: (pkt.Length // 2),
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_DELTA_TRUSTED_DOMAINS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("DomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("NumControllerEntries", None, size_of="ControllerNames"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ControllerNames",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.NumControllerEntries,
            ),
            deferred=True,
        ),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("TrustedPosixOffset", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_ACCOUNTS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("PrivilegeEntries", None, size_of="PrivilegeNames"),
        NDRIntField("PrivilegeControl", 0),
        NDRFullPointerField(
            NDRConfFieldListField(
                "PrivilegeAttributes",
                [],
                NDRIntField("PrivilegeAttributes", 0),
                size_is=lambda pkt: pkt.PrivilegeEntries,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "PrivilegeNames",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.PrivilegeEntries,
            ),
            deferred=True,
        ),
        NDRPacketField("QuotaLimits", NLPR_QUOTA_LIMITS(), NLPR_QUOTA_LIMITS),
        NDRIntField("SystemAccessFlags", 0),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class NLPR_CR_CIPHER_VALUE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Length", None, size_of="Buffer"),
        NDRIntField("MaximumLength", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfVarStrLenField(
                "Buffer",
                "",
                size_is=lambda pkt: pkt.MaximumLength,
                length_is=lambda pkt: pkt.Length,
            ),
            deferred=True,
        ),
    ]


class PNETLOGON_DELTA_SECRET(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("CurrentValue", NLPR_CR_CIPHER_VALUE(), NLPR_CR_CIPHER_VALUE),
        NDRPacketField("CurrentValueSetTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRPacketField("OldValue", NLPR_CR_CIPHER_VALUE(), NLPR_CR_CIPHER_VALUE),
        NDRPacketField("OldValueSetTime", OLD_LARGE_INTEGER(), OLD_LARGE_INTEGER),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SecuritySize", None, size_of="SecurityDescriptor"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "SecurityDescriptor", "", size_is=lambda pkt: pkt.SecuritySize
            ),
            deferred=True,
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_DELETE_GROUP(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("AccountName", ""), deferred=True
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_DELETE_USER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("AccountName", ""), deferred=True
        ),
        NDRPacketField("DummyString1", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DELTA_ENUM(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("DeltaType", 0, NETLOGON_DELTA_TYPE),
        NDRUnionField(
            [
                (
                    NDRIntField("DeltaID", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeDomain,
                                NETLOGON_DELTA_TYPE.AddOrChangeGroup,
                                NETLOGON_DELTA_TYPE.DeleteGroup,
                                NETLOGON_DELTA_TYPE.RenameGroup,
                                NETLOGON_DELTA_TYPE.AddOrChangeUser,
                                NETLOGON_DELTA_TYPE.DeleteUser,
                                NETLOGON_DELTA_TYPE.RenameUser,
                                NETLOGON_DELTA_TYPE.ChangeGroupMembership,
                                NETLOGON_DELTA_TYPE.AddOrChangeAlias,
                                NETLOGON_DELTA_TYPE.DeleteAlias,
                                NETLOGON_DELTA_TYPE.RenameAlias,
                                NETLOGON_DELTA_TYPE.ChangeAliasMembership,
                                NETLOGON_DELTA_TYPE.DeleteGroupByName,
                                NETLOGON_DELTA_TYPE.DeleteUserByName,
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeDomain,
                                NETLOGON_DELTA_TYPE.AddOrChangeGroup,
                                NETLOGON_DELTA_TYPE.DeleteGroup,
                                NETLOGON_DELTA_TYPE.RenameGroup,
                                NETLOGON_DELTA_TYPE.AddOrChangeUser,
                                NETLOGON_DELTA_TYPE.DeleteUser,
                                NETLOGON_DELTA_TYPE.RenameUser,
                                NETLOGON_DELTA_TYPE.ChangeGroupMembership,
                                NETLOGON_DELTA_TYPE.AddOrChangeAlias,
                                NETLOGON_DELTA_TYPE.DeleteAlias,
                                NETLOGON_DELTA_TYPE.RenameAlias,
                                NETLOGON_DELTA_TYPE.ChangeAliasMembership,
                                NETLOGON_DELTA_TYPE.DeleteGroupByName,
                                NETLOGON_DELTA_TYPE.DeleteUserByName,
                            ]
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("DeltaID", PRPC_SID(), PRPC_SID), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaPolicy,
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaTDomain,
                                NETLOGON_DELTA_TYPE.DeleteLsaTDomain,
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaAccount,
                                NETLOGON_DELTA_TYPE.DeleteLsaAccount,
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaPolicy,
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaTDomain,
                                NETLOGON_DELTA_TYPE.DeleteLsaTDomain,
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaAccount,
                                NETLOGON_DELTA_TYPE.DeleteLsaAccount,
                            ]
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRConfVarStrNullFieldUtf16("DeltaID", ""), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaSecret,
                                NETLOGON_DELTA_TYPE.DeleteLsaSecret,
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                NETLOGON_DELTA_TYPE.AddOrChangeLsaSecret,
                                NETLOGON_DELTA_TYPE.DeleteLsaSecret,
                            ]
                        ),
                    ),
                ),
            ],
            StrFixedLenField("DeltaID", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_DOMAIN(),
                            PNETLOGON_DELTA_DOMAIN,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeDomain
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeDomain
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion", PNETLOGON_DELTA_GROUP(), PNETLOGON_DELTA_GROUP
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeGroup
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeGroup
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_RENAME_GROUP(),
                            PNETLOGON_DELTA_RENAME_GROUP,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.RenameGroup
                        ),
                        (lambda _, val: val.tag == NETLOGON_DELTA_TYPE.RenameGroup),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion", PNETLOGON_DELTA_USER(), PNETLOGON_DELTA_USER
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeUser
                        ),
                        (lambda _, val: val.tag == NETLOGON_DELTA_TYPE.AddOrChangeUser),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_RENAME_USER(),
                            PNETLOGON_DELTA_RENAME_USER,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.RenameUser
                        ),
                        (lambda _, val: val.tag == NETLOGON_DELTA_TYPE.RenameUser),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_GROUP_MEMBER(),
                            PNETLOGON_DELTA_GROUP_MEMBER,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.ChangeGroupMembership
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.ChangeGroupMembership
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion", PNETLOGON_DELTA_ALIAS(), PNETLOGON_DELTA_ALIAS
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeAlias
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeAlias
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_RENAME_ALIAS(),
                            PNETLOGON_DELTA_RENAME_ALIAS,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.RenameAlias
                        ),
                        (lambda _, val: val.tag == NETLOGON_DELTA_TYPE.RenameAlias),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_ALIAS_MEMBER(),
                            PNETLOGON_DELTA_ALIAS_MEMBER,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.ChangeAliasMembership
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.ChangeAliasMembership
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_POLICY(),
                            PNETLOGON_DELTA_POLICY,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaPolicy
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaPolicy
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_TRUSTED_DOMAINS(),
                            PNETLOGON_DELTA_TRUSTED_DOMAINS,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaTDomain
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaTDomain
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_ACCOUNTS(),
                            PNETLOGON_DELTA_ACCOUNTS,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaAccount
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaAccount
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_SECRET(),
                            PNETLOGON_DELTA_SECRET,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaSecret
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.AddOrChangeLsaSecret
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_DELETE_GROUP(),
                            PNETLOGON_DELTA_DELETE_GROUP,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.DeleteGroupByName
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.DeleteGroupByName
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion",
                            PNETLOGON_DELTA_DELETE_USER(),
                            PNETLOGON_DELTA_DELETE_USER,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.DeleteUserByName
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.DeleteUserByName
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DeltaUnion", PNLPR_MODIFIED_COUNT(), PNLPR_MODIFIED_COUNT
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "DeltaType", None)
                            == NETLOGON_DELTA_TYPE.SerialNumberSkip
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_DELTA_TYPE.SerialNumberSkip
                        ),
                    ),
                ),
            ],
            StrFixedLenField("DeltaUnion", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class PNETLOGON_DELTA_ENUM_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("CountReturned", None, size_of="Deltas"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Deltas",
                [PNETLOGON_DELTA_ENUM()],
                PNETLOGON_DELTA_ENUM,
                size_is=lambda pkt: pkt.CountReturned,
            ),
            deferred=True,
        ),
    ]


class NetrDatabaseDeltas_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("PrimaryName", ""),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("DatabaseID", 0),
        NDRPacketField(
            "DomainModifiedCount", PNLPR_MODIFIED_COUNT(), PNLPR_MODIFIED_COUNT
        ),
        NDRIntField("PreferredMaximumLength", 0),
    ]


class NetrDatabaseDeltas_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "DomainModifiedCount", PNLPR_MODIFIED_COUNT(), PNLPR_MODIFIED_COUNT
        ),
        NDRFullPointerField(
            NDRPacketField(
                "DeltaArray", PNETLOGON_DELTA_ENUM_ARRAY(), PNETLOGON_DELTA_ENUM_ARRAY
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrDatabaseSync_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("PrimaryName", ""),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("DatabaseID", 0),
        NDRIntField("SyncContext", 0),
        NDRIntField("PreferredMaximumLength", 0),
    ]


class NetrDatabaseSync_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("SyncContext", 0),
        NDRFullPointerField(
            NDRPacketField(
                "DeltaArray", PNETLOGON_DELTA_ENUM_ARRAY(), PNETLOGON_DELTA_ENUM_ARRAY
            )
        ),
        NDRIntField("status", 0),
    ]


class PUAS_INFO_0(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        StrFixedLenField("ComputerName", "", length=16),
        NDRIntField("TimeCreated", 0),
        NDRIntField("SerialNumber", 0),
    ]


class NetrAccountDeltas_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField("RecordId", PUAS_INFO_0(), PUAS_INFO_0),
        NDRIntField("Count", 0),
        NDRIntField("Level", 0),
        NDRIntField("BufferSize", 0),
    ]


class NetrAccountDeltas_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRConfStrLenField("Buffer", "", size_is=lambda pkt: pkt.BufferSize),
        NDRIntField("CountReturned", 0),
        NDRIntField("TotalEntries", 0),
        NDRPacketField("NextRecordId", PUAS_INFO_0(), PUAS_INFO_0),
        NDRIntField("status", 0),
    ]


class NetrAccountSync_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("Reference", 0),
        NDRIntField("Level", 0),
        NDRIntField("BufferSize", 0),
    ]


class NetrAccountSync_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRConfStrLenField("Buffer", "", size_is=lambda pkt: pkt.BufferSize),
        NDRIntField("CountReturned", 0),
        NDRIntField("TotalEntries", 0),
        NDRIntField("NextReference", 0),
        NDRPacketField("LastRecordId", PUAS_INFO_0(), PUAS_INFO_0),
        NDRIntField("status", 0),
    ]


class NetrGetDCName_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("ServerName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
    ]


class NetrGetDCName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Buffer", "")),
        NDRIntField("status", 0),
    ]


class PNETLOGON_INFO_1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("netlog1_flags", 0),
        NDRIntField("netlog1_pdc_connection_status", 0),
    ]


class PNETLOGON_INFO_2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("netlog2_flags", 0),
        NDRIntField("netlog2_pdc_connection_status", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("netlog2_trusted_dc_name", ""), deferred=True
        ),
        NDRIntField("netlog2_tc_connection_status", 0),
    ]


class PNETLOGON_INFO_3(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("netlog3_flags", 0),
        NDRIntField("netlog3_logon_attempts", 0),
        NDRIntField("netlog3_reserved1", 0),
        NDRIntField("netlog3_reserved2", 0),
        NDRIntField("netlog3_reserved3", 0),
        NDRIntField("netlog3_reserved4", 0),
        NDRIntField("netlog3_reserved5", 0),
    ]


class PNETLOGON_INFO_4(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("netlog4_trusted_dc_name", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("netlog4_trusted_domain_name", ""),
            deferred=True,
        ),
    ]


class NetrLogonControl_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("FunctionCode", 0),
        NDRIntField("QueryLevel", 0),
    ]


class NetrLogonControl_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_1(), PNETLOGON_INFO_1)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_2(), PNETLOGON_INFO_2)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_3(), PNETLOGON_INFO_3)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_4(), PNETLOGON_INFO_4)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
            ],
            StrFixedLenField("Buffer", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class NetrGetAnyDCName_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
    ]


class NetrGetAnyDCName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Buffer", "")),
        NDRIntField("status", 0),
    ]


class NetrLogonControl2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("FunctionCode", 0),
        NDRIntField("QueryLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Data", "")),
                    (
                        (
                            lambda pkt: getattr(pkt, "FunctionCode", None)
                            in [5, 6, 9, 10]
                        ),
                        (lambda _, val: val.tag in [5, 6, 9, 10]),
                    ),
                ),
                (
                    NDRIntField("Data", 0),
                    (
                        (lambda pkt: getattr(pkt, "FunctionCode", None) == 65534),
                        (lambda _, val: val.tag == 65534),
                    ),
                ),
                (
                    NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Data", "")),
                    (
                        (lambda pkt: getattr(pkt, "FunctionCode", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
            ],
            StrFixedLenField("Data", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class NetrLogonControl2_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_1(), PNETLOGON_INFO_1)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_2(), PNETLOGON_INFO_2)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_3(), PNETLOGON_INFO_3)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_4(), PNETLOGON_INFO_4)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
            ],
            StrFixedLenField("Buffer", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class NetrServerAuthenticate2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "ClientCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
        NDRIntField("NegotiateFlags", 0),
    ]


class NetrServerAuthenticate2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ServerCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
        NDRIntField("NegotiateFlags", 0),
        NDRIntField("status", 0),
    ]


class SYNC_STATE(IntEnum):
    NormalState = 0
    DomainState = 1
    GroupState = 2
    UasBuiltInGroupState = 3
    UserState = 4
    GroupMemberState = 5
    AliasState = 6
    AliasMemberState = 7
    SamDoneState = 8


class NetrDatabaseSync2_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("PrimaryName", ""),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("DatabaseID", 0),
        NDRInt3264EnumField("RestartState", 0, SYNC_STATE),
        NDRIntField("SyncContext", 0),
        NDRIntField("PreferredMaximumLength", 0),
    ]


class NetrDatabaseSync2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("SyncContext", 0),
        NDRFullPointerField(
            NDRPacketField(
                "DeltaArray", PNETLOGON_DELTA_ENUM_ARRAY(), PNETLOGON_DELTA_ENUM_ARRAY
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrDatabaseRedo_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("PrimaryName", ""),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRConfStrLenField(
            "ChangeLogEntry", "", size_is=lambda pkt: pkt.ChangeLogEntrySize
        ),
        NDRIntField("ChangeLogEntrySize", None, size_of="ChangeLogEntry"),
    ]


class NetrDatabaseRedo_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRFullPointerField(
            NDRPacketField(
                "DeltaArray", PNETLOGON_DELTA_ENUM_ARRAY(), PNETLOGON_DELTA_ENUM_ARRAY
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonControl2Ex_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("FunctionCode", 0),
        NDRIntField("QueryLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Data", "")),
                    (
                        (
                            lambda pkt: getattr(pkt, "FunctionCode", None)
                            in [5, 6, 9, 10]
                        ),
                        (lambda _, val: val.tag in [5, 6, 9, 10]),
                    ),
                ),
                (
                    NDRIntField("Data", 0),
                    (
                        (lambda pkt: getattr(pkt, "FunctionCode", None) == 65534),
                        (lambda _, val: val.tag == 65534),
                    ),
                ),
                (
                    NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Data", "")),
                    (
                        (lambda pkt: getattr(pkt, "FunctionCode", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
            ],
            StrFixedLenField("Data", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class NetrLogonControl2Ex_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_1(), PNETLOGON_INFO_1)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_2(), PNETLOGON_INFO_2)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_3(), PNETLOGON_INFO_3)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("Buffer", PNETLOGON_INFO_4(), PNETLOGON_INFO_4)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
            ],
            StrFixedLenField("Buffer", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class PDOMAIN_NAME_BUFFER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("DomainNameByteCount", None, size_of="DomainNames"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "DomainNames", "", size_is=lambda pkt: pkt.DomainNameByteCount
            ),
            deferred=True,
        ),
    ]


class NetrEnumerateTrustedDomains_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", ""))]


class NetrEnumerateTrustedDomains_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("DomainNameBuffer", PDOMAIN_NAME_BUFFER(), PDOMAIN_NAME_BUFFER),
        NDRIntField("status", 0),
    ]


class GUID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Data1", 0),
        NDRShortField("Data2", 0),
        NDRShortField("Data3", 0),
        StrFixedLenField("Data4", "", length=8),
    ]


class PDOMAIN_CONTROLLER_INFOW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainControllerName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainControllerAddress", ""), deferred=True
        ),
        NDRIntField("DomainControllerAddressType", 0),
        NDRPacketField("DomainGuid", GUID(), GUID),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsForestName", ""), deferred=True
        ),
        NDRIntField("Flags", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DcSiteName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ClientSiteName", ""), deferred=True
        ),
    ]


class DsrGetDcName_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
        NDRFullPointerField(NDRPacketField("DomainGuid", GUID(), GUID)),
        NDRFullPointerField(NDRPacketField("SiteGuid", GUID(), GUID)),
        NDRIntField("Flags", 0),
    ]


class DsrGetDcName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "DomainControllerInfo",
                PDOMAIN_CONTROLLER_INFOW(),
                PDOMAIN_CONTROLLER_INFOW,
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonGetCapabilities_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("ServerName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("QueryLevel", 0),
    ]


class NetrLogonGetCapabilities_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRUnionField(
            [
                (
                    NDRIntField("ServerCapabilities", 0),
                    (
                        (lambda pkt: getattr(pkt, "QueryLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("ServerCapabilities", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonSetServiceBits_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("ServiceBitsOfInterest", 0),
        NDRIntField("ServiceBits", 0),
    ]


class NetrLogonSetServiceBits_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class NetrLogonGetTrustRid_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
    ]


class NetrLogonGetTrustRid_Response(NDRPacket):
    fields_desc = [NDRIntField("Rid", 0), NDRIntField("status", 0)]


class NetrLogonComputeServerDigest_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("Rid", 0),
        NDRConfStrLenField("Message", "", size_is=lambda pkt: pkt.MessageSize),
        NDRIntField("MessageSize", None, size_of="Message"),
    ]


class NetrLogonComputeServerDigest_Response(NDRPacket):
    fields_desc = [
        StrFixedLenField("NewMessageDigest", "", length=16),
        StrFixedLenField("OldMessageDigest", "", length=16),
        NDRIntField("status", 0),
    ]


class NetrLogonComputeClientDigest_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
        NDRConfStrLenField("Message", "", size_is=lambda pkt: pkt.MessageSize),
        NDRIntField("MessageSize", None, size_of="Message"),
    ]


class NetrLogonComputeClientDigest_Response(NDRPacket):
    fields_desc = [
        StrFixedLenField("NewMessageDigest", "", length=16),
        StrFixedLenField("OldMessageDigest", "", length=16),
        NDRIntField("status", 0),
    ]


class NetrServerAuthenticate3_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "ClientCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
        NDRIntField("NegotiateFlags", 0),
    ]


class NetrServerAuthenticate3_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ServerCredential", PNETLOGON_CREDENTIAL(), PNETLOGON_CREDENTIAL
        ),
        NDRIntField("NegotiateFlags", 0),
        NDRIntField("AccountRid", 0),
        NDRIntField("status", 0),
    ]


class DsrGetDcNameEx_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
        NDRFullPointerField(NDRPacketField("DomainGuid", GUID(), GUID)),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", "")),
        NDRIntField("Flags", 0),
    ]


class DsrGetDcNameEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "DomainControllerInfo",
                PDOMAIN_CONTROLLER_INFOW(),
                PDOMAIN_CONTROLLER_INFOW,
            )
        ),
        NDRIntField("status", 0),
    ]


class DsrGetSiteName_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", ""))]


class DsrGetSiteName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", "")),
        NDRIntField("status", 0),
    ]


class NETLOGON_LSA_POLICY_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("LsaPolicySize", None, size_of="LsaPolicy"),
        NDRFullPointerField(
            NDRConfStrLenField("LsaPolicy", "", size_is=lambda pkt: pkt.LsaPolicySize),
            deferred=True,
        ),
    ]


class PNETLOGON_WORKSTATION_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "LsaPolicy", NETLOGON_LSA_POLICY_INFO(), NETLOGON_LSA_POLICY_INFO
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsHostName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Dummy1", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Dummy2", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Dummy3", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Dummy4", ""), deferred=True),
        NDRPacketField("OsVersion", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("OsName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("WorkstationFlags", 0),
        NDRIntField("KerberosSupportedEncryptionTypes", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class NETLOGON_ONE_DOMAIN_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("DomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DnsDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DnsForestName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DomainGuid", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField("DomainSid", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRPacketField("TrustExtension", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_ONE_DOMAIN_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("DomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DnsDomainName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DnsForestName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DomainGuid", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField("DomainSid", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRPacketField("TrustExtension", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("DummyLong1", 0),
        NDRIntField("DummyLong2", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_DOMAIN_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "PrimaryDomain", NETLOGON_ONE_DOMAIN_INFO(), NETLOGON_ONE_DOMAIN_INFO
        ),
        NDRIntField("TrustedDomainCount", None, size_of="TrustedDomains"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "TrustedDomains",
                [PNETLOGON_ONE_DOMAIN_INFO()],
                PNETLOGON_ONE_DOMAIN_INFO,
                size_is=lambda pkt: pkt.TrustedDomainCount,
            ),
            deferred=True,
        ),
        NDRPacketField(
            "LsaPolicy", NETLOGON_LSA_POLICY_INFO(), NETLOGON_LSA_POLICY_INFO
        ),
        NDRPacketField("DnsHostNameInDs", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString2", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString3", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("DummyString4", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRIntField("WorkstationFlags", 0),
        NDRIntField("SupportedEncTypes", 0),
        NDRIntField("DummyLong3", 0),
        NDRIntField("DummyLong4", 0),
    ]


class PNETLOGON_LSA_POLICY_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("LsaPolicySize", None, size_of="LsaPolicy"),
        NDRFullPointerField(
            NDRConfStrLenField("LsaPolicy", "", size_is=lambda pkt: pkt.LsaPolicySize),
            deferred=True,
        ),
    ]


class NetrLogonGetDomainInfo_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("ServerName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("Level", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "WkstaBuffer",
                            PNETLOGON_WORKSTATION_INFO(),
                            PNETLOGON_WORKSTATION_INFO,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "WkstaBuffer",
                            PNETLOGON_WORKSTATION_INFO(),
                            PNETLOGON_WORKSTATION_INFO,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("WkstaBuffer", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class NetrLogonGetDomainInfo_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DomBuffer", PNETLOGON_DOMAIN_INFO(), PNETLOGON_DOMAIN_INFO
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "DomBuffer",
                            PNETLOGON_LSA_POLICY_INFO(),
                            PNETLOGON_LSA_POLICY_INFO,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("DomBuffer", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class PNL_TRUST_PASSWORD(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        StrFixedLenFieldUtf16("Buffer", "", length=256 * 2),
        NDRIntField("Length", 0),
    ]


class NetrServerPasswordSet2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField("ClearNewPassword", PNL_TRUST_PASSWORD(), PNL_TRUST_PASSWORD),
    ]


class NetrServerPasswordSet2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("status", 0),
    ]


class NetrServerPasswordGet_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("AccountType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
    ]


class NetrServerPasswordGet_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "EncryptedNtOwfPassword",
            PENCRYPTED_NT_OWF_PASSWORD(),
            PENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonSendToSam_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("PrimaryName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRConfStrLenField(
            "OpaqueBuffer", "", size_is=lambda pkt: pkt.OpaqueBufferSize
        ),
        NDRIntField("OpaqueBufferSize", None, size_of="OpaqueBuffer"),
    ]


class NetrLogonSendToSam_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("status", 0),
    ]


class PNL_SOCKET_ADDRESS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpSockaddr", "", size_is=lambda pkt: pkt.iSockaddrLength
            ),
            deferred=True,
        ),
        NDRIntField("iSockaddrLength", None, size_of="lpSockaddr"),
    ]


class PNL_SITE_NAME_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntryCount", None, size_of="SiteNames"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "SiteNames",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.EntryCount,
            ),
            deferred=True,
        ),
    ]


class DsrAddressToSiteNamesW_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRIntField("EntryCount", None, size_of="SocketAddresses"),
        NDRConfPacketListField(
            "SocketAddresses",
            [PNL_SOCKET_ADDRESS()],
            PNL_SOCKET_ADDRESS,
            size_is=lambda pkt: pkt.EntryCount,
        ),
    ]


class DsrAddressToSiteNamesW_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("SiteNames", PNL_SITE_NAME_ARRAY(), PNL_SITE_NAME_ARRAY)
        ),
        NDRIntField("status", 0),
    ]


class DsrGetDcNameEx2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("AccountName", "")),
        NDRIntField("AllowableAccountControlBits", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
        NDRFullPointerField(NDRPacketField("DomainGuid", GUID(), GUID)),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", "")),
        NDRIntField("Flags", 0),
    ]


class DsrGetDcNameEx2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "DomainControllerInfo",
                PDOMAIN_CONTROLLER_INFOW(),
                PDOMAIN_CONTROLLER_INFOW,
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonGetTimeServiceParentDomain_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", ""))]


class NetrLogonGetTimeServiceParentDomain_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainName", "")),
        NDRSignedIntField("PdcSameSite", 0),
        NDRIntField("status", 0),
    ]


class PDS_DOMAIN_TRUSTSW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NetbiosDomainName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsDomainName", ""), deferred=True
        ),
        NDRIntField("Flags", 0),
        NDRIntField("ParentIndex", 0),
        NDRIntField("TrustType", 0),
        NDRIntField("TrustAttributes", 0),
        NDRFullPointerField(
            NDRPacketField("DomainSid", PRPC_SID(), PRPC_SID), deferred=True
        ),
        NDRPacketField("DomainGuid", GUID(), GUID),
    ]


class PNETLOGON_TRUSTED_DOMAIN_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("DomainCount", None, size_of="Domains"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Domains",
                [PDS_DOMAIN_TRUSTSW()],
                PDS_DOMAIN_TRUSTSW,
                size_is=lambda pkt: pkt.DomainCount,
            ),
            deferred=True,
        ),
    ]


class NetrEnumerateTrustedDomainsEx_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", ""))]


class NetrEnumerateTrustedDomainsEx_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "Domains", PNETLOGON_TRUSTED_DOMAIN_ARRAY(), PNETLOGON_TRUSTED_DOMAIN_ARRAY
        ),
        NDRIntField("status", 0),
    ]


class PNL_SITE_NAME_EX_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntryCount", None, size_of="SubnetNames"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "SiteNames",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.EntryCount,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "SubnetNames",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.EntryCount,
            ),
            deferred=True,
        ),
    ]


class DsrAddressToSiteNamesExW_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRIntField("EntryCount", None, size_of="SocketAddresses"),
        NDRConfPacketListField(
            "SocketAddresses",
            [PNL_SOCKET_ADDRESS()],
            PNL_SOCKET_ADDRESS,
            size_is=lambda pkt: pkt.EntryCount,
        ),
    ]


class DsrAddressToSiteNamesExW_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "SiteNames", PNL_SITE_NAME_EX_ARRAY(), PNL_SITE_NAME_EX_ARRAY
            )
        ),
        NDRIntField("status", 0),
    ]


class DsrGetDcSiteCoverageW_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", ""))]


class DsrGetDcSiteCoverageW_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("SiteNames", PNL_SITE_NAME_ARRAY(), PNL_SITE_NAME_ARRAY)
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonSamLogonEx_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("LogonServer", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRInt3264EnumField("LogonLevel", 0, NETLOGON_LOGON_INFO_CLASS),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_GENERIC_INFO(),
                            PNETLOGON_GENERIC_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                    ),
                ),
            ],
            StrFixedLenField("LogonInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRInt3264EnumField("ValidationLevel", 0, NETLOGON_VALIDATION_INFO_CLASS),
        NDRIntField("ExtraFlags", 0),
    ]


class NetrLogonSamLogonEx_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO(),
                            PNETLOGON_VALIDATION_SAM_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO2(),
                            PNETLOGON_VALIDATION_SAM_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_GENERIC_INFO2(),
                            PNETLOGON_VALIDATION_GENERIC_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO4(),
                            PNETLOGON_VALIDATION_SAM_INFO4,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                    ),
                ),
            ],
            StrFixedLenField("ValidationInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRByteField("Authoritative", 0),
        NDRIntField("ExtraFlags", 0),
        NDRIntField("status", 0),
    ]


class DsrEnumerateDomainTrusts_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRIntField("Flags", 0),
    ]


class DsrEnumerateDomainTrusts_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "Domains", PNETLOGON_TRUSTED_DOMAIN_ARRAY(), PNETLOGON_TRUSTED_DOMAIN_ARRAY
        ),
        NDRIntField("status", 0),
    ]


class DsrDeregisterDnsHostRecords_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DnsDomainName", "")),
        NDRFullPointerField(NDRPacketField("DomainGuid", GUID(), GUID)),
        NDRFullPointerField(NDRPacketField("DsaGuid", GUID(), GUID)),
        NDRConfVarStrNullFieldUtf16("DnsHostName", ""),
    ]


class DsrDeregisterDnsHostRecords_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class NetrServerTrustPasswordsGet_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("TrustedDcName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
    ]


class NetrServerTrustPasswordsGet_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "EncryptedNewOwfPassword",
            PENCRYPTED_NT_OWF_PASSWORD(),
            PENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRPacketField(
            "EncryptedOldOwfPassword",
            PENCRYPTED_NT_OWF_PASSWORD(),
            PENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRIntField("status", 0),
    ]


class LSA_FOREST_TRUST_RECORD_TYPE(IntEnum):
    ForestTrustTopLevelName = 0
    ForestTrustTopLevelNameEx = 1
    ForestTrustDomainInfo = 2
    ForestTrustRecordTypeLast = ForestTrustDomainInfo


class LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("QuadPart", 0)]


class LSA_FOREST_TRUST_DOMAIN_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("Sid", PRPC_SID(), PRPC_SID), deferred=True),
        NDRPacketField("DnsName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
        NDRPacketField("NetbiosName", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
    ]


class LSA_FOREST_TRUST_BINARY_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Length", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfStrLenField("Buffer", "", size_is=lambda pkt: pkt.Length),
            deferred=True,
        ),
    ]


class PLSA_FOREST_TRUST_RECORD(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("Flags", 0),
        NDRInt3264EnumField("ForestTrustType", 0, LSA_FOREST_TRUST_RECORD_TYPE),
        NDRPacketField("Time", LARGE_INTEGER(), LARGE_INTEGER),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "ForestTrustData", RPC_UNICODE_STRING(), RPC_UNICODE_STRING
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ForestTrustType", None)
                            in [
                                LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelName,
                                LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelNameEx,
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelName,
                                LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelNameEx,
                            ]
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "ForestTrustData",
                        LSA_FOREST_TRUST_DOMAIN_INFO(),
                        LSA_FOREST_TRUST_DOMAIN_INFO,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ForestTrustType", None)
                            == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustDomainInfo
                        ),
                        (
                            lambda _, val: val.tag
                            == LSA_FOREST_TRUST_RECORD_TYPE.ForestTrustDomainInfo
                        ),
                    ),
                ),
            ],
            NDRPacketField(
                "ForestTrustData",
                LSA_FOREST_TRUST_BINARY_DATA(),
                LSA_FOREST_TRUST_BINARY_DATA,
            ),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class PLSA_FOREST_TRUST_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("RecordCount", None, size_of="Entries"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Entries",
                [],
                PLSA_FOREST_TRUST_RECORD,
                size_is=lambda pkt: pkt.RecordCount,
                ptr_pack=True,
            ),
            deferred=True,
        ),
    ]


class DsrGetForestTrustInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("TrustedDomainName", "")),
        NDRIntField("Flags", 0),
    ]


class DsrGetForestTrustInformation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ForestTrustInfo",
                PLSA_FOREST_TRUST_INFORMATION(),
                PLSA_FOREST_TRUST_INFORMATION,
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrGetForestTrustInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("Flags", 0),
    ]


class NetrGetForestTrustInformation_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRFullPointerField(
            NDRPacketField(
                "ForestTrustInfo",
                PLSA_FOREST_TRUST_INFORMATION(),
                PLSA_FOREST_TRUST_INFORMATION,
            )
        ),
        NDRIntField("status", 0),
    ]


class NetrLogonSamLogonWithFlags_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("LogonServer", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ComputerName", "")),
        NDRFullPointerField(
            NDRPacketField(
                "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRInt3264EnumField("LogonLevel", 0, NETLOGON_LOGON_INFO_CLASS),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_INTERACTIVE_INFO(),
                            PNETLOGON_INTERACTIVE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_SERVICE_INFO(),
                            PNETLOGON_SERVICE_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonServiceTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_NETWORK_INFO(),
                            PNETLOGON_NETWORK_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonNetworkTransitiveInformation
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "LogonInformation",
                            PNETLOGON_GENERIC_INFO(),
                            PNETLOGON_GENERIC_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "LogonLevel", None)
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_LOGON_INFO_CLASS.NetlogonGenericInformation
                        ),
                    ),
                ),
            ],
            StrFixedLenField("LogonInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRInt3264EnumField("ValidationLevel", 0, NETLOGON_VALIDATION_INFO_CLASS),
        NDRIntField("ExtraFlags", 0),
    ]


class NetrLogonSamLogonWithFlags_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ReturnAuthenticator",
                PNETLOGON_AUTHENTICATOR(),
                PNETLOGON_AUTHENTICATOR,
            )
        ),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO(),
                            PNETLOGON_VALIDATION_SAM_INFO,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO2(),
                            PNETLOGON_VALIDATION_SAM_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_GENERIC_INFO2(),
                            PNETLOGON_VALIDATION_GENERIC_INFO2,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationGenericInfo2
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ValidationInformation",
                            PNETLOGON_VALIDATION_SAM_INFO4(),
                            PNETLOGON_VALIDATION_SAM_INFO4,
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "ValidationLevel", None)
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                        (
                            lambda _, val: val.tag
                            == NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
                        ),
                    ),
                ),
            ],
            StrFixedLenField("ValidationInformation", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
        NDRByteField("Authoritative", 0),
        NDRIntField("ExtraFlags", 0),
        NDRIntField("status", 0),
    ]


class PNL_GENERIC_RPC_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("UlongEntryCount", None, size_of="UlongData"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "UlongData",
                [],
                NDRIntField("UlongData", 0),
                size_is=lambda pkt: pkt.UlongEntryCount,
            ),
            deferred=True,
        ),
        NDRIntField("UnicodeStringEntryCount", None, size_of="UnicodeStringData"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "UnicodeStringData",
                [PRPC_UNICODE_STRING()],
                PRPC_UNICODE_STRING,
                size_is=lambda pkt: pkt.UnicodeStringEntryCount,
            ),
            deferred=True,
        ),
    ]


class NetrServerGetTrustInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("TrustedDcName", "")),
        NDRConfVarStrNullFieldUtf16("AccountName", ""),
        NDRInt3264EnumField("SecureChannelType", 0, NETLOGON_SECURE_CHANNEL_TYPE),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
    ]


class NetrServerGetTrustInfo_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "EncryptedNewOwfPassword",
            PENCRYPTED_NT_OWF_PASSWORD(),
            PENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRPacketField(
            "EncryptedOldOwfPassword",
            PENCRYPTED_NT_OWF_PASSWORD(),
            PENCRYPTED_NT_OWF_PASSWORD,
        ),
        NDRFullPointerField(
            NDRPacketField("TrustInfo", PNL_GENERIC_RPC_DATA(), PNL_GENERIC_RPC_DATA)
        ),
        NDRIntField("status", 0),
    ]


class OpnumUnused47_Request(NDRPacket):
    fields_desc = []


class OpnumUnused47_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class PNL_DNS_NAME_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Type", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsDomainInfo", ""), deferred=True
        ),
        NDRIntField("DnsDomainInfoType", 0),
        NDRIntField("Priority", 0),
        NDRIntField("Weight", 0),
        NDRIntField("Port", 0),
        NDRByteField("Register", 0),
        NDRIntField("Status", 0),
    ]


class PNL_DNS_NAME_INFO_ARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntryCount", None, size_of="DnsNamesInfo"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "DnsNamesInfo",
                [PNL_DNS_NAME_INFO()],
                PNL_DNS_NAME_INFO,
                size_is=lambda pkt: pkt.EntryCount,
            ),
            deferred=True,
        ),
    ]


class DsrUpdateReadOnlyServerDnsRecords_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("ComputerName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", "")),
        NDRIntField("DnsTtl", 0),
        NDRPacketField("DnsNames", PNL_DNS_NAME_INFO_ARRAY(), PNL_DNS_NAME_INFO_ARRAY),
    ]


class DsrUpdateReadOnlyServerDnsRecords_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField("DnsNames", PNL_DNS_NAME_INFO_ARRAY(), PNL_DNS_NAME_INFO_ARRAY),
        NDRIntField("status", 0),
    ]


class NL_OSVERSIONINFO_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwOSVersionInfoSize", 0),
        NDRIntField("dwMajorVersion", 0),
        NDRIntField("dwMinorVersion", 0),
        NDRIntField("dwBuildNumber", 0),
        NDRIntField("dwPlatformId", 0),
        StrFixedLenFieldUtf16("szCSDVersion", "", length=128 * 2),
        NDRShortField("wServicePackMajor", 0),
        NDRShortField("wServicePackMinor", 0),
        NDRShortField("wSuiteMask", 0),
        NDRByteField("wProductType", 0),
        NDRByteField("wReserved", 0),
    ]


class NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ClientDnsHostName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField(
                "OsVersionInfo_V1", NL_OSVERSIONINFO_V1(), NL_OSVERSIONINFO_V1
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("OsName", ""), deferred=True),
    ]


class NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("HubName", ""), deferred=True),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRConfVarStrNullFieldUtf16("OldDnsHostName", ""), deferred=True
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("SupportedEncTypes", 0), deferred=True),
    ]


class NetrChainSetClientAttributes_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("PrimaryName", ""),
        NDRConfVarStrNullFieldUtf16("ChainedFromServerName", ""),
        NDRConfVarStrNullFieldUtf16("ChainedForClientName", ""),
        NDRPacketField(
            "Authenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES_V1(),
                        NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1(),
                        NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class NetrChainSetClientAttributes_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "ReturnAuthenticator", PNETLOGON_AUTHENTICATOR(), PNETLOGON_AUTHENTICATOR
        ),
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1(),
                        NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


LOGON_OPNUMS = {
    0: DceRpcOp(NetrLogonUasLogon_Request, NetrLogonUasLogon_Response),
    1: DceRpcOp(NetrLogonUasLogoff_Request, NetrLogonUasLogoff_Response),
    2: DceRpcOp(NetrLogonSamLogon_Request, NetrLogonSamLogon_Response),
    3: DceRpcOp(NetrLogonSamLogoff_Request, NetrLogonSamLogoff_Response),
    4: DceRpcOp(NetrServerReqChallenge_Request, NetrServerReqChallenge_Response),
    5: DceRpcOp(NetrServerAuthenticate_Request, NetrServerAuthenticate_Response),
    6: DceRpcOp(NetrServerPasswordSet_Request, NetrServerPasswordSet_Response),
    7: DceRpcOp(NetrDatabaseDeltas_Request, NetrDatabaseDeltas_Response),
    8: DceRpcOp(NetrDatabaseSync_Request, NetrDatabaseSync_Response),
    9: DceRpcOp(NetrAccountDeltas_Request, NetrAccountDeltas_Response),
    10: DceRpcOp(NetrAccountSync_Request, NetrAccountSync_Response),
    11: DceRpcOp(NetrGetDCName_Request, NetrGetDCName_Response),
    12: DceRpcOp(NetrLogonControl_Request, NetrLogonControl_Response),
    13: DceRpcOp(NetrGetAnyDCName_Request, NetrGetAnyDCName_Response),
    14: DceRpcOp(NetrLogonControl2_Request, NetrLogonControl2_Response),
    15: DceRpcOp(NetrServerAuthenticate2_Request, NetrServerAuthenticate2_Response),
    16: DceRpcOp(NetrDatabaseSync2_Request, NetrDatabaseSync2_Response),
    17: DceRpcOp(NetrDatabaseRedo_Request, NetrDatabaseRedo_Response),
    18: DceRpcOp(NetrLogonControl2Ex_Request, NetrLogonControl2Ex_Response),
    19: DceRpcOp(
        NetrEnumerateTrustedDomains_Request, NetrEnumerateTrustedDomains_Response
    ),
    20: DceRpcOp(DsrGetDcName_Request, DsrGetDcName_Response),
    21: DceRpcOp(NetrLogonGetCapabilities_Request, NetrLogonGetCapabilities_Response),
    22: DceRpcOp(NetrLogonSetServiceBits_Request, NetrLogonSetServiceBits_Response),
    23: DceRpcOp(NetrLogonGetTrustRid_Request, NetrLogonGetTrustRid_Response),
    24: DceRpcOp(
        NetrLogonComputeServerDigest_Request, NetrLogonComputeServerDigest_Response
    ),
    25: DceRpcOp(
        NetrLogonComputeClientDigest_Request, NetrLogonComputeClientDigest_Response
    ),
    26: DceRpcOp(NetrServerAuthenticate3_Request, NetrServerAuthenticate3_Response),
    27: DceRpcOp(DsrGetDcNameEx_Request, DsrGetDcNameEx_Response),
    28: DceRpcOp(DsrGetSiteName_Request, DsrGetSiteName_Response),
    29: DceRpcOp(NetrLogonGetDomainInfo_Request, NetrLogonGetDomainInfo_Response),
    30: DceRpcOp(NetrServerPasswordSet2_Request, NetrServerPasswordSet2_Response),
    31: DceRpcOp(NetrServerPasswordGet_Request, NetrServerPasswordGet_Response),
    32: DceRpcOp(NetrLogonSendToSam_Request, NetrLogonSendToSam_Response),
    33: DceRpcOp(DsrAddressToSiteNamesW_Request, DsrAddressToSiteNamesW_Response),
    34: DceRpcOp(DsrGetDcNameEx2_Request, DsrGetDcNameEx2_Response),
    35: DceRpcOp(
        NetrLogonGetTimeServiceParentDomain_Request,
        NetrLogonGetTimeServiceParentDomain_Response,
    ),
    36: DceRpcOp(
        NetrEnumerateTrustedDomainsEx_Request, NetrEnumerateTrustedDomainsEx_Response
    ),
    37: DceRpcOp(DsrAddressToSiteNamesExW_Request, DsrAddressToSiteNamesExW_Response),
    38: DceRpcOp(DsrGetDcSiteCoverageW_Request, DsrGetDcSiteCoverageW_Response),
    39: DceRpcOp(NetrLogonSamLogonEx_Request, NetrLogonSamLogonEx_Response),
    40: DceRpcOp(DsrEnumerateDomainTrusts_Request, DsrEnumerateDomainTrusts_Response),
    41: DceRpcOp(
        DsrDeregisterDnsHostRecords_Request, DsrDeregisterDnsHostRecords_Response
    ),
    42: DceRpcOp(
        NetrServerTrustPasswordsGet_Request, NetrServerTrustPasswordsGet_Response
    ),
    43: DceRpcOp(
        DsrGetForestTrustInformation_Request, DsrGetForestTrustInformation_Response
    ),
    44: DceRpcOp(
        NetrGetForestTrustInformation_Request, NetrGetForestTrustInformation_Response
    ),
    45: DceRpcOp(
        NetrLogonSamLogonWithFlags_Request, NetrLogonSamLogonWithFlags_Response
    ),
    46: DceRpcOp(NetrServerGetTrustInfo_Request, NetrServerGetTrustInfo_Response),
    47: DceRpcOp(OpnumUnused47_Request, OpnumUnused47_Response),
    48: DceRpcOp(
        DsrUpdateReadOnlyServerDnsRecords_Request,
        DsrUpdateReadOnlyServerDnsRecords_Response,
    ),
    49: DceRpcOp(
        NetrChainSetClientAttributes_Request, NetrChainSetClientAttributes_Response
    ),
}
register_dcerpc_interface(
    name="logon",
    uuid=uuid.UUID("12345678-1234-ABCD-EF00-01234567CFFB"),
    version="1.0",
    opnums=LOGON_OPNUMS,
)
