### ms-dssp.idl
"""
RPC definitions for the following interfaces:
- dssetup (v0.0): 3919286a-b10c-11d0-9ba8-00c04fd92ef5
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRUnionField,
    register_dcerpc_interface,
)


class DSROLE_PRIMARY_DOMAIN_INFO_LEVEL(IntEnum):
    DsRolePrimaryDomainInfoBasic = 1
    DsRoleUpgradeStatus = 2
    DsRoleOperationState = 3


class DSROLE_MACHINE_ROLE(IntEnum):
    DsRole_RoleStandaloneWorkstation = 1
    DsRole_RoleMemberWorkstation = 2
    DsRole_RoleStandaloneServer = 3
    DsRole_RoleMemberServer = 4
    DsRole_RoleBackupDomainController = 5
    DsRole_RolePrimaryDomainController = 6


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


class DSROLER_PRIMARY_DOMAIN_INFO_BASIC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("MachineRole", 0, DSROLE_MACHINE_ROLE),
        NDRIntField("Flags", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainNameFlat", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainNameDns", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DomainForestName", ""), deferred=True
        ),
        NDRPacketField("DomainGuid", GUID(), GUID),
    ]


class DSROLE_SERVER_STATE(IntEnum):
    DsRoleServerUnknown = 0
    DsRoleServerPrimary = 1
    DsRoleServerBackup = 2


class DSROLE_UPGRADE_STATUS_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("OperationState", 0),
        NDRInt3264EnumField("PreviousServerState", 0, DSROLE_SERVER_STATE),
    ]


class DSROLE_OPERATION_STATE(IntEnum):
    DsRoleOperationIdle = 0
    DsRoleOperationActive = 1
    DsRoleOperationNeedReboot = 2


class DSROLE_OPERATION_STATE_INFO(NDRPacket):
    ALIGNMENT = (2, 4)
    fields_desc = [NDRInt3264EnumField("OperationState", 0, DSROLE_OPERATION_STATE)]


class DsRolerGetPrimaryDomainInformation_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("InfoLevel", 0, DSROLE_PRIMARY_DOMAIN_INFO_LEVEL)
    ]


class DsRolerGetPrimaryDomainInformation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRUnionField(
                [
                    (
                        NDRPacketField(
                            "DomainInfo",
                            DSROLER_PRIMARY_DOMAIN_INFO_BASIC(),
                            DSROLER_PRIMARY_DOMAIN_INFO_BASIC,
                        ),
                        (
                            (
                                lambda pkt: getattr(pkt, "InfoLevel", None)
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRolePrimaryDomainInfoBasic
                            ),
                            (
                                lambda _, val: val.tag
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRolePrimaryDomainInfoBasic
                            ),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "DomainInfo",
                            DSROLE_UPGRADE_STATUS_INFO(),
                            DSROLE_UPGRADE_STATUS_INFO,
                        ),
                        (
                            (
                                lambda pkt: getattr(pkt, "InfoLevel", None)
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRoleUpgradeStatus
                            ),
                            (
                                lambda _, val: val.tag
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRoleUpgradeStatus
                            ),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "DomainInfo",
                            DSROLE_OPERATION_STATE_INFO(),
                            DSROLE_OPERATION_STATE_INFO,
                        ),
                        (
                            (
                                lambda pkt: getattr(pkt, "InfoLevel", None)
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRoleOperationState
                            ),
                            (
                                lambda _, val: val.tag
                                == DSROLE_PRIMARY_DOMAIN_INFO_LEVEL.DsRoleOperationState
                            ),
                        ),
                    ),
                ],
                StrFixedLenField("DomainInfo", "", length=0),
                align=(2, 8),
                switch_fmt=("H", "I"),
            )
        ),
        NDRIntField("status", 0),
    ]


DSSETUP_OPNUMS = {
    0: DceRpcOp(
        DsRolerGetPrimaryDomainInformation_Request,
        DsRolerGetPrimaryDomainInformation_Response,
    ),
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    # 3: Opnum3NotUsedOnWire,
    # 4: Opnum4NotUsedOnWire,
    # 5: Opnum5NotUsedOnWire,
    # 6: Opnum6NotUsedOnWire,
    # 7: Opnum7NotUsedOnWire,
    # 8: Opnum8NotUsedOnWire,
    # 9: Opnum9NotUsedOnWire,
    # 10: Opnum10NotUsedOnWire,
    # 11: Opnum11NotUsedOnWire
}
register_dcerpc_interface(
    name="dssetup",
    uuid=uuid.UUID("3919286a-b10c-11d0-9ba8-00c04fd92ef5"),
    version="0.0",
    opnums=DSSETUP_OPNUMS,
)
