### ms-w32t.idl
"""
RPC definitions for the following interfaces:
- W32Time (v4.1): 8fb6d884-2388-11d0-8c35-00c04fda2795
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfPacketListField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


class W32TimeSync_Request(NDRPacket):
    fields_desc = [NDRIntField("uWait", 0), NDRIntField("ulFlags", 0)]


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


class W32TimeGetNetlogonServiceBits_Request(NDRPacket):
    fields_desc = []


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


class PW32TIME_NTP_PEER_INFO(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulResolveAttempts", 0),
        NDRLongField("u64TimeRemaining", 0),
        NDRLongField("u64LastSuccessfulSync", 0),
        NDRIntField("ulLastSyncError", 0),
        NDRIntField("ulLastSyncErrorMsgId", 0),
        NDRIntField("ulValidDataCounter", 0),
        NDRIntField("ulAuthTypeMsgId", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszUniqueName", ""), deferred=True
        ),
        NDRByteField("ulMode", 0),
        NDRByteField("ulStratum", 0),
        NDRByteField("ulReachability", 0),
        NDRByteField("ulPeerPollInterval", 0),
        NDRByteField("ulHostPollInterval", 0),
    ]


class W32TIME_NTP_PROVIDER_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulError", 0),
        NDRIntField("ulErrorMsgId", 0),
        NDRIntField("cPeerInfo", None, size_of="pPeerInfo"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pPeerInfo",
                [PW32TIME_NTP_PEER_INFO()],
                PW32TIME_NTP_PEER_INFO,
                size_is=lambda pkt: pkt.cPeerInfo,
            ),
            deferred=True,
        ),
    ]


class W32TIME_HARDWARE_PROVIDER_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulError", 0),
        NDRIntField("ulErrorMsgId", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszReferenceIdentifier", ""), deferred=True
        ),
    ]


class PW32TIME_PROVIDER_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulProviderType", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ProviderData",
                            W32TIME_NTP_PROVIDER_DATA(),
                            W32TIME_NTP_PROVIDER_DATA,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ulProviderType", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ProviderData",
                            W32TIME_HARDWARE_PROVIDER_DATA(),
                            W32TIME_HARDWARE_PROVIDER_DATA,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ulProviderType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
            ],
            StrFixedLenField("ProviderData", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class W32TimeQueryProviderStatus_Request(NDRPacket):
    fields_desc = [
        NDRIntField("ulFlags", 0),
        NDRConfVarStrNullFieldUtf16("pwszProvider", ""),
    ]


class W32TimeQueryProviderStatus_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "pProviderInfo", PW32TIME_PROVIDER_INFO(), PW32TIME_PROVIDER_INFO
            )
        ),
        NDRIntField("status", 0),
    ]


class W32TimeQuerySource_Request(NDRPacket):
    fields_desc = []


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


class PW32TIME_ENTRY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszName", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszValue", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszHelp", ""), deferred=True),
    ]


class PW32TIME_NTPCLIENT_PROVIDER_CONFIG_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulAllowNonstandardModeCombinations", 0),
        NDRIntField("ulCrossSiteSyncFlags", 0),
        NDRIntField("ulResolvePeerBackoffMinutes", 0),
        NDRIntField("ulResolvePeerBackoffMaxTimes", 0),
        NDRIntField("ulCompatibilityFlags", 0),
        NDRIntField("ulEventLogFlags", 0),
        NDRIntField("ulLargeSampleSkew", 0),
        NDRIntField("ulSpecialPollInterval", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszType", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszNtpServer", ""), deferred=True
        ),
        NDRIntField("ulAllowNonstandardModeCombinationsFlag", 0),
        NDRIntField("ulCrossSiteSyncFlagsFlag", 0),
        NDRIntField("ulResolvePeerBackoffMinutesFlag", 0),
        NDRIntField("ulResolvePeerBackoffMaxTimesFlag", 0),
        NDRIntField("ulCompatibilityFlagsFlag", 0),
        NDRIntField("ulEventLogFlagsFlag", 0),
        NDRIntField("ulLargeSampleSkewFlag", 0),
        NDRIntField("ulSpecialPollIntervalFlag", 0),
        NDRIntField("ulTypeFlag", 0),
        NDRIntField("ulNtpServerFlag", 0),
        NDRIntField("cEntries", None, size_of="pEntries"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pEntries",
                [PW32TIME_ENTRY()],
                PW32TIME_ENTRY,
                size_is=lambda pkt: pkt.cEntries,
            ),
            deferred=True,
        ),
    ]


class PW32TIME_NTPSERVER_PROVIDER_CONFIG_DATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulAllowNonstandardModeCombinations", 0),
        NDRIntField("ulAllowNonstandardModeCombinationsFlag", 0),
        NDRIntField("ulEventLogFlags", 0),
        NDRIntField("ulEventLogFlagsFlag", 0),
        NDRIntField("cEntries", None, size_of="pEntries"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pEntries",
                [PW32TIME_ENTRY()],
                PW32TIME_ENTRY,
                size_is=lambda pkt: pkt.cEntries,
            ),
            deferred=True,
        ),
    ]


class PW32TIME_PROVIDER_CONFIG(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulProviderType", 0),
        NDRFullPointerField(
            NDRUnionField(
                [
                    (
                        NDRFullPointerField(
                            NDRPacketField(
                                "pProviderConfigData",
                                PW32TIME_NTPCLIENT_PROVIDER_CONFIG_DATA(),
                                PW32TIME_NTPCLIENT_PROVIDER_CONFIG_DATA,
                            ),
                            deferred=True,
                        ),
                        (
                            (lambda pkt: getattr(pkt, "ulProviderType", None) == 0),
                            (lambda _, val: val.tag == 0),
                        ),
                    ),
                    (
                        NDRFullPointerField(
                            NDRPacketField(
                                "pProviderConfigData",
                                PW32TIME_NTPSERVER_PROVIDER_CONFIG_DATA(),
                                PW32TIME_NTPSERVER_PROVIDER_CONFIG_DATA,
                            ),
                            deferred=True,
                        ),
                        (
                            (lambda pkt: getattr(pkt, "ulProviderType", None) == 1),
                            (lambda _, val: val.tag == 1),
                        ),
                    ),
                ],
                StrFixedLenField("pProviderConfigData", "", length=0),
                align=(4, 8),
                switch_fmt=("L", "L"),
            ),
            deferred=True,
        ),
    ]


class PW32TIME_CONFIGURATION_PROVIDER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulInputProvider", 0),
        NDRIntField("ulEnabled", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszDllName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszProviderName", ""), deferred=True
        ),
        NDRIntField("ulDllNameFlag", 0),
        NDRIntField("ulProviderNameFlag", 0),
        NDRIntField("ulInputProviderFlag", 0),
        NDRIntField("ulEnabledFlag", 0),
        NDRFullPointerField(
            NDRPacketField(
                "pProviderConfig", PW32TIME_PROVIDER_CONFIG(), PW32TIME_PROVIDER_CONFIG
            ),
            deferred=True,
        ),
    ]


class W32TimeQueryProviderConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRIntField("ulFlags", 0),
        NDRConfVarStrNullFieldUtf16("pwszProvider", ""),
    ]


class W32TimeQueryProviderConfiguration_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "pConfigurationProviderInfo",
                PW32TIME_CONFIGURATION_PROVIDER(),
                PW32TIME_CONFIGURATION_PROVIDER,
            )
        ),
        NDRIntField("status", 0),
    ]


class W32TIME_CONFIGURATION_BASIC(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulEventLogFlags", 0),
        NDRIntField("ulAnnounceFlags", 0),
        NDRIntField("ulTimeJumpAuditOffset", 0),
        NDRIntField("ulMinPollInterval", 0),
        NDRIntField("ulMaxPollInterval", 0),
        NDRIntField("ulMaxNegPhaseCorrection", 0),
        NDRIntField("ulMaxPosPhaseCorrection", 0),
        NDRIntField("ulMaxAllowedPhaseOffset", 0),
        NDRIntField("ulEventLogFlagsFlag", 0),
        NDRIntField("ulAnnounceFlagsFlag", 0),
        NDRIntField("ulTimeJumpAuditOffsetFlag", 0),
        NDRIntField("ulMinPollIntervalFlag", 0),
        NDRIntField("ulMaxPollIntervalFlag", 0),
        NDRIntField("ulMaxNegPhaseCorrectionFlag", 0),
        NDRIntField("ulMaxPosPhaseCorrectionFlag", 0),
        NDRIntField("ulMaxAllowedPhaseOffsetFlag", 0),
    ]


class W32TIME_CONFIGURATION_ADVANCED(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("ulFrequencyCorrectRate", 0),
        NDRIntField("ulPollAdjustFactor", 0),
        NDRIntField("ulLargePhaseOffset", 0),
        NDRIntField("ulSpikeWatchPeriod", 0),
        NDRIntField("ulLocalClockDispersion", 0),
        NDRIntField("ulHoldPeriod", 0),
        NDRIntField("ulPhaseCorrectRate", 0),
        NDRIntField("ulUpdateInterval", 0),
        NDRIntField("ulFrequencyCorrectRateFlag", 0),
        NDRIntField("ulPollAdjustFactorFlag", 0),
        NDRIntField("ulLargePhaseOffsetFlag", 0),
        NDRIntField("ulSpikeWatchPeriodFlag", 0),
        NDRIntField("ulLocalClockDispersionFlag", 0),
        NDRIntField("ulHoldPeriodFlag", 0),
        NDRIntField("ulPhaseCorrectRateFlag", 0),
        NDRIntField("ulUpdateIntervalFlag", 0),
    ]


class W32TIME_CONFIGURATION_DEFAULT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszFileLogName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszFileLogEntries", ""), deferred=True
        ),
        NDRIntField("ulFileLogSize", 0),
        NDRIntField("ulFileLogFlags", 0),
        NDRIntField("ulFileLogNameFlag", 0),
        NDRIntField("ulFileLogEntriesFlag", 0),
        NDRIntField("ulFileLogSizeFlag", 0),
        NDRIntField("ulFileLogFlagsFlag", 0),
    ]


class PW32TIME_CONFIGURATION_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRPacketField(
            "basicConfig", W32TIME_CONFIGURATION_BASIC(), W32TIME_CONFIGURATION_BASIC
        ),
        NDRPacketField(
            "advancedConfig",
            W32TIME_CONFIGURATION_ADVANCED(),
            W32TIME_CONFIGURATION_ADVANCED,
        ),
        NDRPacketField(
            "defaultConfig",
            W32TIME_CONFIGURATION_DEFAULT(),
            W32TIME_CONFIGURATION_DEFAULT,
        ),
        NDRIntField("cProviderConfig", None, size_of="pProviderConfig"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pProviderConfig",
                [],
                PW32TIME_CONFIGURATION_PROVIDER,
                size_is=lambda pkt: pkt.cProviderConfig,
                ptr_pack=True,
            ),
            deferred=True,
        ),
        NDRIntField("cEntries", None, size_of="pEntries"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pEntries",
                [PW32TIME_ENTRY()],
                PW32TIME_ENTRY,
                size_is=lambda pkt: pkt.cEntries,
            ),
            deferred=True,
        ),
    ]


class W32TimeQueryConfiguration_Request(NDRPacket):
    fields_desc = []


class W32TimeQueryConfiguration_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "pConfigurationInfo",
                PW32TIME_CONFIGURATION_INFO(),
                PW32TIME_CONFIGURATION_INFO,
            )
        ),
        NDRIntField("status", 0),
    ]


class PW32TIME_STATUS_INFO(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("ulSize", 0),
        NDRIntField("eLeapIndicator", 0),
        NDRIntField("nStratum", 0),
        NDRSignedIntField("nPollInterval", 0),
        NDRIntField("refidSource", 0),
        NDRLongField("qwLastSyncTicks", 0),
        NDRSignedLongField("toRootDelay", 0),
        NDRLongField("tpRootDispersion", 0),
        NDRSignedIntField("nClockPrecision", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszSource", ""), deferred=True
        ),
        NDRSignedLongField("toSysPhaseOffset", 0),
        NDRIntField("ulLcState", 0),
        NDRIntField("ulTSFlags", 0),
        NDRIntField("ulClockRate", 0),
        NDRIntField("ulNetlogonServiceBits", 0),
        NDRIntField("eLastSyncResult", 0),
        NDRLongField("tpTimeLastGoodSync", 0),
        NDRIntField("cEntries", None, size_of="pEntries"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pEntries",
                [PW32TIME_ENTRY()],
                PW32TIME_ENTRY,
                size_is=lambda pkt: pkt.cEntries,
            ),
            deferred=True,
        ),
    ]


class W32TimeQueryStatus_Request(NDRPacket):
    fields_desc = []


class W32TimeQueryStatus_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pStatusInfo", PW32TIME_STATUS_INFO(), PW32TIME_STATUS_INFO)
        ),
        NDRIntField("status", 0),
    ]


class W32TimeLog_Request(NDRPacket):
    fields_desc = []


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


W32TIME_OPNUMS = {
    0: DceRpcOp(W32TimeSync_Request, W32TimeSync_Response),
    1: DceRpcOp(
        W32TimeGetNetlogonServiceBits_Request, W32TimeGetNetlogonServiceBits_Response
    ),
    2: DceRpcOp(
        W32TimeQueryProviderStatus_Request, W32TimeQueryProviderStatus_Response
    ),
    3: DceRpcOp(W32TimeQuerySource_Request, W32TimeQuerySource_Response),
    4: DceRpcOp(
        W32TimeQueryProviderConfiguration_Request,
        W32TimeQueryProviderConfiguration_Response,
    ),
    5: DceRpcOp(W32TimeQueryConfiguration_Request, W32TimeQueryConfiguration_Response),
    6: DceRpcOp(W32TimeQueryStatus_Request, W32TimeQueryStatus_Response),
    7: DceRpcOp(W32TimeLog_Request, W32TimeLog_Response),
}
register_dcerpc_interface(
    name="W32Time",
    uuid=uuid.UUID("8fb6d884-2388-11d0-8c35-00c04fda2795"),
    version="4.1",
    opnums=W32TIME_OPNUMS,
)
