### ms-irp.idl
"""
RPC definitions for the following interfaces:
- inetinfo (v2.0): 82ad4280-036b-11cf-972c-00aa006887b0
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

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


class R_InetInfoGetVersion_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwReserved", 0),
    ]


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


class LPINET_LOG_CONFIGURATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("inetLogType", 0),
        NDRIntField("ilPeriod", 0),
        StrFixedLenFieldUtf16("rgchLogFileDirectory", "", length=260 * 2),
        NDRIntField("cbSizeForTruncation", 0),
        StrFixedLenFieldUtf16("rgchDataSource", "", length=260 * 2),
        StrFixedLenFieldUtf16("rgchTableName", "", length=30 * 2),
        StrFixedLenFieldUtf16("rgchUserName", "", length=257 * 2),
        StrFixedLenFieldUtf16("rgchPassword", "", length=257 * 2),
    ]


class INET_INFO_IP_SEC_ENTRY(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwMask", 0), NDRIntField("dwNetwork", 0)]


class LPINET_INFO_IP_SEC_LIST(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["aIPSecEntry"]
    fields_desc = [
        NDRIntField("cEntries", None, size_of="aIPSecEntry"),
        NDRConfPacketListField(
            "aIPSecEntry",
            [],
            INET_INFO_IP_SEC_ENTRY,
            size_is=lambda pkt: pkt.cEntries,
            conformant_in_struct=True,
        ),
    ]


class INET_INFO_VIRTUAL_ROOT_ENTRY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszRoot", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAddress", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszDirectory", ""), deferred=True
        ),
        NDRIntField("dwMask", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAccountName", ""), deferred=True
        ),
        StrFixedLenFieldUtf16("AccountPassword", "", length=257 * 2),
        NDRIntField("dwError", 0),
    ]


class LPINET_INFO_VIRTUAL_ROOT_LIST(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["aVirtRootEntry"]
    fields_desc = [
        NDRIntField("cEntries", None, size_of="aVirtRootEntry"),
        NDRConfPacketListField(
            "aVirtRootEntry",
            [],
            INET_INFO_VIRTUAL_ROOT_ENTRY,
            size_is=lambda pkt: pkt.cEntries,
            conformant_in_struct=True,
        ),
    ]


class LPINET_INFO_CONFIG_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("FieldControl", 0),
        NDRIntField("dwConnectionTimeout", 0),
        NDRIntField("dwMaxConnections", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAdminName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAdminEmail", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszServerComment", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField(
                "lpLogConfig", LPINET_LOG_CONFIGURATION(), LPINET_LOG_CONFIGURATION
            ),
            deferred=True,
        ),
        NDRShortField("LangId", 0),
        NDRIntField("LocalId", 0),
        StrFixedLenField("ProductId", "", length=64),
        NDRSignedIntField("fLogAnonymous", 0),
        NDRSignedIntField("fLogNonAnonymous", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAnonUserName", ""), deferred=True
        ),
        StrFixedLenFieldUtf16("szAnonPassword", "", length=257 * 2),
        NDRIntField("dwAuthentication", 0),
        NDRSignedShortField("sPort", 0),
        NDRFullPointerField(
            NDRPacketField(
                "DenyIPList", LPINET_INFO_IP_SEC_LIST(), LPINET_INFO_IP_SEC_LIST
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "GrantIPList", LPINET_INFO_IP_SEC_LIST(), LPINET_INFO_IP_SEC_LIST
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "VirtualRoots",
                LPINET_INFO_VIRTUAL_ROOT_LIST(),
                LPINET_INFO_VIRTUAL_ROOT_LIST,
            ),
            deferred=True,
        ),
    ]


class R_InetInfoGetAdminInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
    ]


class R_InetInfoGetAdminInformation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppConfig", LPINET_INFO_CONFIG_INFO(), LPINET_INFO_CONFIG_INFO
            )
        ),
        NDRIntField("status", 0),
    ]


class INET_INFO_SITE_ENTRY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszComment", ""), deferred=True
        ),
        NDRIntField("dwInstance", 0),
    ]


class LPINET_INFO_SITE_LIST(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["aSiteEntry"]
    fields_desc = [
        NDRIntField("cEntries", None, size_of="aSiteEntry"),
        NDRConfPacketListField(
            "aSiteEntry",
            [],
            INET_INFO_SITE_ENTRY,
            size_is=lambda pkt: pkt.cEntries,
            conformant_in_struct=True,
        ),
    ]


class R_InetInfoGetSites_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
    ]


class R_InetInfoGetSites_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppSites", LPINET_INFO_SITE_LIST(), LPINET_INFO_SITE_LIST)
        ),
        NDRIntField("status", 0),
    ]


class INET_INFO_CONFIG_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("FieldControl", 0),
        NDRIntField("dwConnectionTimeout", 0),
        NDRIntField("dwMaxConnections", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAdminName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAdminEmail", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszServerComment", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField(
                "lpLogConfig", LPINET_LOG_CONFIGURATION(), LPINET_LOG_CONFIGURATION
            ),
            deferred=True,
        ),
        NDRShortField("LangId", 0),
        NDRIntField("LocalId", 0),
        StrFixedLenField("ProductId", "", length=64),
        NDRSignedIntField("fLogAnonymous", 0),
        NDRSignedIntField("fLogNonAnonymous", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszAnonUserName", ""), deferred=True
        ),
        StrFixedLenFieldUtf16("szAnonPassword", "", length=257 * 2),
        NDRIntField("dwAuthentication", 0),
        NDRSignedShortField("sPort", 0),
        NDRFullPointerField(
            NDRPacketField(
                "DenyIPList", LPINET_INFO_IP_SEC_LIST(), LPINET_INFO_IP_SEC_LIST
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "GrantIPList", LPINET_INFO_IP_SEC_LIST(), LPINET_INFO_IP_SEC_LIST
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "VirtualRoots",
                LPINET_INFO_VIRTUAL_ROOT_LIST(),
                LPINET_INFO_VIRTUAL_ROOT_LIST,
            ),
            deferred=True,
        ),
    ]


class R_InetInfoSetAdminInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
        NDRPacketField("pConfig", INET_INFO_CONFIG_INFO(), INET_INFO_CONFIG_INFO),
    ]


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


class LPINET_INFO_GLOBAL_CONFIG_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("FieldControl", 0),
        NDRIntField("BandwidthLevel", 0),
        NDRIntField("cbMemoryCacheSize", 0),
    ]


class R_InetInfoGetGlobalAdminInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
    ]


class R_InetInfoGetGlobalAdminInformation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppConfig",
                LPINET_INFO_GLOBAL_CONFIG_INFO(),
                LPINET_INFO_GLOBAL_CONFIG_INFO,
            )
        ),
        NDRIntField("status", 0),
    ]


class INET_INFO_GLOBAL_CONFIG_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("FieldControl", 0),
        NDRIntField("BandwidthLevel", 0),
        NDRIntField("cbMemoryCacheSize", 0),
    ]


class R_InetInfoSetGlobalAdminInformation_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
        NDRPacketField(
            "pConfig", INET_INFO_GLOBAL_CONFIG_INFO(), INET_INFO_GLOBAL_CONFIG_INFO
        ),
    ]


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


class INETA_CACHE_STATISTICS(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("FilesCached", 0),
        NDRIntField("TotalFilesCached", 0),
        NDRIntField("FileHits", 0),
        NDRIntField("FileMisses", 0),
        NDRIntField("FileFlushes", 0),
        NDRLongField("CurrentFileCacheSize", 0),
        NDRLongField("MaximumFileCacheSize", 0),
        NDRIntField("FlushedEntries", 0),
        NDRIntField("TotalFlushed", 0),
        NDRIntField("URICached", 0),
        NDRIntField("TotalURICached", 0),
        NDRIntField("URIHits", 0),
        NDRIntField("URIMisses", 0),
        NDRIntField("URIFlushes", 0),
        NDRIntField("TotalURIFlushed", 0),
        NDRIntField("BlobCached", 0),
        NDRIntField("TotalBlobCached", 0),
        NDRIntField("BlobHits", 0),
        NDRIntField("BlobMisses", 0),
        NDRIntField("BlobFlushes", 0),
        NDRIntField("TotalBlobFlushed", 0),
    ]


class INETA_ATQ_STATISTICS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("TotalBlockedRequests", 0),
        NDRIntField("TotalRejectedRequests", 0),
        NDRIntField("TotalAllowedRequests", 0),
        NDRIntField("CurrentBlockedRequests", 0),
        NDRIntField("MeasuredBandwidth", 0),
    ]


class LPINET_INFO_STATISTICS_0(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("CacheCtrs", INETA_CACHE_STATISTICS(), INETA_CACHE_STATISTICS),
        NDRPacketField("AtqCtrs", INETA_ATQ_STATISTICS(), INETA_ATQ_STATISTICS),
        NDRIntField("nAuxCounters", 0),
        NDRFieldListField("rgCounters", [], NDRIntField("", 0), length_is=lambda _: 20),
    ]


class R_InetInfoQueryStatistics_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("Level", 0),
        NDRIntField("dwServerMask", 0),
    ]


class R_InetInfoQueryStatistics_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "StatsInfo",
                            LPINET_INFO_STATISTICS_0(),
                            LPINET_INFO_STATISTICS_0,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                )
            ],
            StrFixedLenField("StatsInfo", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class R_InetInfoClearStatistics_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
    ]


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


class R_InetInfoFlushMemoryCache_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServerMask", 0),
    ]


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


class LPINET_INFO_CAP_FLAGS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("Flag", 0), NDRIntField("Mask", 0)]


class LPINET_INFO_CAPABILITIES_STRUCT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("CapVersion", 0),
        NDRIntField("ProductType", 0),
        NDRIntField("MajorVersion", 0),
        NDRIntField("MinorVersion", 0),
        NDRIntField("BuildNumber", 0),
        NDRIntField("NumCapFlags", None, size_of="CapFlags"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "CapFlags",
                [LPINET_INFO_CAP_FLAGS()],
                LPINET_INFO_CAP_FLAGS,
                size_is=lambda pkt: pkt.NumCapFlags,
            ),
            deferred=True,
        ),
    ]


class R_InetInfoGetServerCapabilities_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwReserved", 0),
    ]


class R_InetInfoGetServerCapabilities_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppCap",
                LPINET_INFO_CAPABILITIES_STRUCT(),
                LPINET_INFO_CAPABILITIES_STRUCT,
            )
        ),
        NDRIntField("status", 0),
    ]


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


class LPW3_STATISTICS_1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("TotalBytesSent", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("TotalBytesReceived", LARGE_INTEGER(), LARGE_INTEGER),
        NDRIntField("TotalFilesSent", 0),
        NDRIntField("TotalFilesReceived", 0),
        NDRIntField("CurrentAnonymousUsers", 0),
        NDRIntField("CurrentNonAnonymousUsers", 0),
        NDRIntField("TotalAnonymousUsers", 0),
        NDRIntField("TotalNonAnonymousUsers", 0),
        NDRIntField("MaxAnonymousUsers", 0),
        NDRIntField("MaxNonAnonymousUsers", 0),
        NDRIntField("CurrentConnections", 0),
        NDRIntField("MaxConnections", 0),
        NDRIntField("ConnectionAttempts", 0),
        NDRIntField("LogonAttempts", 0),
        NDRIntField("TotalOptions", 0),
        NDRIntField("TotalGets", 0),
        NDRIntField("TotalPosts", 0),
        NDRIntField("TotalHeads", 0),
        NDRIntField("TotalPuts", 0),
        NDRIntField("TotalDeletes", 0),
        NDRIntField("TotalTraces", 0),
        NDRIntField("TotalMove", 0),
        NDRIntField("TotalCopy", 0),
        NDRIntField("TotalMkcol", 0),
        NDRIntField("TotalPropfind", 0),
        NDRIntField("TotalProppatch", 0),
        NDRIntField("TotalSearch", 0),
        NDRIntField("TotalLock", 0),
        NDRIntField("TotalUnlock", 0),
        NDRIntField("TotalOthers", 0),
        NDRIntField("TotalCGIRequests", 0),
        NDRIntField("TotalBGIRequests", 0),
        NDRIntField("TotalNotFoundErrors", 0),
        NDRIntField("TotalLockedErrors", 0),
        NDRIntField("CurrentCalAuth", 0),
        NDRIntField("MaxCalAuth", 0),
        NDRIntField("TotalFailedCalAuth", 0),
        NDRIntField("CurrentCalSsl", 0),
        NDRIntField("MaxCalSsl", 0),
        NDRIntField("TotalFailedCalSsl", 0),
        NDRIntField("CurrentCGIRequests", 0),
        NDRIntField("CurrentBGIRequests", 0),
        NDRIntField("MaxCGIRequests", 0),
        NDRIntField("MaxBGIRequests", 0),
        NDRIntField("CurrentBlockedRequests", 0),
        NDRIntField("TotalBlockedRequests", 0),
        NDRIntField("TotalAllowedRequests", 0),
        NDRIntField("TotalRejectedRequests", 0),
        NDRIntField("MeasuredBw", 0),
        NDRIntField("ServiceUptime", 0),
        NDRIntField("TimeOfLastClear", 0),
        NDRIntField("nAuxCounters", 0),
        NDRFieldListField("rgCounters", [], NDRIntField("", 0), length_is=lambda _: 20),
    ]


class R_W3QueryStatistics2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwLevel", 0),
        NDRIntField("dwInstance", 0),
        NDRIntField("dwReserved", 0),
    ]


class R_W3QueryStatistics2_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "InfoStruct", LPW3_STATISTICS_1(), LPW3_STATISTICS_1
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwLevel", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                )
            ],
            StrFixedLenField("InfoStruct", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class R_W3ClearStatistics2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwInstance", 0),
    ]


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


class LPFTP_STATISTICS_0(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("TotalBytesSent", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("TotalBytesReceived", LARGE_INTEGER(), LARGE_INTEGER),
        NDRIntField("TotalFilesSent", 0),
        NDRIntField("TotalFilesReceived", 0),
        NDRIntField("CurrentAnonymousUsers", 0),
        NDRIntField("CurrentNonAnonymousUsers", 0),
        NDRIntField("TotalAnonymousUsers", 0),
        NDRIntField("TotalNonAnonymousUsers", 0),
        NDRIntField("MaxAnonymousUsers", 0),
        NDRIntField("MaxNonAnonymousUsers", 0),
        NDRIntField("CurrentConnections", 0),
        NDRIntField("MaxConnections", 0),
        NDRIntField("ConnectionAttempts", 0),
        NDRIntField("LogonAttempts", 0),
        NDRIntField("ServiceUptime", 0),
        NDRIntField("TotalAllowedRequests", 0),
        NDRIntField("TotalRejectedRequests", 0),
        NDRIntField("TotalBlockedRequests", 0),
        NDRIntField("CurrentBlockedRequests", 0),
        NDRIntField("MeasuredBandwidth", 0),
        NDRIntField("TimeOfLastClear", 0),
    ]


class R_FtpQueryStatistics2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwLevel", 0),
        NDRIntField("dwInstance", 0),
        NDRIntField("dwReserved", 0),
    ]


class R_FtpQueryStatistics2_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "InfoStruct", LPFTP_STATISTICS_0(), LPFTP_STATISTICS_0
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwLevel", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                )
            ],
            StrFixedLenField("InfoStruct", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class R_FtpClearStatistics2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwInstance", 0),
    ]


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


class LPIIS_USER_INFO_1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("idUser", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszUser", ""), deferred=True),
        NDRSignedIntField("fAnonymous", 0),
        NDRIntField("inetHost", 0),
        NDRIntField("tConnect", 0),
    ]


class LPIIS_USER_INFO_1_CONTAINER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntriesRead", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Buffer",
                [LPIIS_USER_INFO_1()],
                LPIIS_USER_INFO_1,
                size_is=lambda pkt: pkt.EntriesRead,
            ),
            deferred=True,
        ),
    ]


class LPIIS_USER_ENUM_STRUCT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Level", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ConfigInfo",
                            LPIIS_USER_INFO_1_CONTAINER(),
                            LPIIS_USER_INFO_1_CONTAINER,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("ConfigInfo", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class R_IISEnumerateUsers_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServiceId", 0),
        NDRIntField("dwInstance", 0),
        NDRPacketField("InfoStruct", LPIIS_USER_ENUM_STRUCT(), LPIIS_USER_ENUM_STRUCT),
    ]


class R_IISEnumerateUsers_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("InfoStruct", LPIIS_USER_ENUM_STRUCT(), LPIIS_USER_ENUM_STRUCT),
        NDRIntField("status", 0),
    ]


class R_IISDisconnectUser_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszServer", "")),
        NDRIntField("dwServiceId", 0),
        NDRIntField("dwInstance", 0),
        NDRIntField("dwIdUser", 0),
    ]


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


INETINFO_OPNUMS = {
    0: DceRpcOp(R_InetInfoGetVersion_Request, R_InetInfoGetVersion_Response),
    1: DceRpcOp(
        R_InetInfoGetAdminInformation_Request, R_InetInfoGetAdminInformation_Response
    ),
    2: DceRpcOp(R_InetInfoGetSites_Request, R_InetInfoGetSites_Response),
    3: DceRpcOp(
        R_InetInfoSetAdminInformation_Request, R_InetInfoSetAdminInformation_Response
    ),
    4: DceRpcOp(
        R_InetInfoGetGlobalAdminInformation_Request,
        R_InetInfoGetGlobalAdminInformation_Response,
    ),
    5: DceRpcOp(
        R_InetInfoSetGlobalAdminInformation_Request,
        R_InetInfoSetGlobalAdminInformation_Response,
    ),
    6: DceRpcOp(R_InetInfoQueryStatistics_Request, R_InetInfoQueryStatistics_Response),
    7: DceRpcOp(R_InetInfoClearStatistics_Request, R_InetInfoClearStatistics_Response),
    8: DceRpcOp(
        R_InetInfoFlushMemoryCache_Request, R_InetInfoFlushMemoryCache_Response
    ),
    9: DceRpcOp(
        R_InetInfoGetServerCapabilities_Request,
        R_InetInfoGetServerCapabilities_Response,
    ),
    10: DceRpcOp(R_W3QueryStatistics2_Request, R_W3QueryStatistics2_Response),
    11: DceRpcOp(R_W3ClearStatistics2_Request, R_W3ClearStatistics2_Response),
    12: DceRpcOp(R_FtpQueryStatistics2_Request, R_FtpQueryStatistics2_Response),
    13: DceRpcOp(R_FtpClearStatistics2_Request, R_FtpClearStatistics2_Response),
    14: DceRpcOp(R_IISEnumerateUsers_Request, R_IISEnumerateUsers_Response),
    15: DceRpcOp(R_IISDisconnectUser_Request, R_IISDisconnectUser_Response),
    # 16: Opnum16NotUsedOnWire,
    # 17: Opnum17NotUsedOnWire
}
register_dcerpc_interface(
    name="inetinfo",
    uuid=uuid.UUID("82ad4280-036b-11cf-972c-00aa006887b0"),
    version="2.0",
    opnums=INETINFO_OPNUMS,
)
