### ms-raa.idl
"""
RPC definitions for the following interfaces:
- authzr (v0.0): 0b1c2170-5732-4e0e-8cd3-d9b16f3b84d7
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,
    NDRByteField,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRContextHandle,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


class AuthzrFreeContext_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle)
    ]


class AuthzrFreeContext_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


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


class RPC_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 LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("QuadPart", 0)]


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


class AuthzrInitializeContextFromSid_Request(NDRPacket):
    fields_desc = [
        NDRIntField("Flags", 0),
        NDRPacketField("Sid", RPC_SID(), RPC_SID),
        NDRFullPointerField(
            NDRPacketField("pExpirationTime", LARGE_INTEGER(), LARGE_INTEGER)
        ),
        NDRPacketField("Identifier", LUID(), LUID),
    ]


class AuthzrInitializeContextFromSid_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class AuthzrInitializeCompoundContext_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("UserContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("DeviceContextHandle", NDRContextHandle(), NDRContextHandle),
    ]


class AuthzrInitializeCompoundContext_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("CompoundContextHandle", NDRContextHandle(), NDRContextHandle),
        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 OBJECT_TYPE_LIST(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Level", 0),
        NDRIntField("Remaining", 0),
        NDRFullPointerField(NDRPacketField("ObjectType", GUID(), GUID), deferred=True),
    ]


class AUTHZR_ACCESS_REQUEST(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("DesiredAccess", 0),
        NDRFullPointerField(
            NDRPacketField("PrincipalSelfSid", RPC_SID(), RPC_SID), deferred=True
        ),
        NDRIntField("ObjectTypeListLength", None, size_of="ObjectTypeList"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ObjectTypeList",
                [],
                OBJECT_TYPE_LIST,
                size_is=lambda pkt: pkt.ObjectTypeListLength,
            ),
            deferred=True,
        ),
    ]


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


class AUTHZR_ACCESS_REPLY(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ResultListLength", None, size_of="Error"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "GrantedAccessMask",
                [],
                NDRIntField("GrantedAccessMask", 0),
                size_is=lambda pkt: pkt.ResultListLength,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfFieldListField(
                "Error",
                [],
                NDRIntField("Error", 0),
                size_is=lambda pkt: pkt.ResultListLength,
            ),
            deferred=True,
        ),
    ]


class AuthzrAccessCheck_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("Flags", 0),
        NDRPacketField("pRequest", AUTHZR_ACCESS_REQUEST(), AUTHZR_ACCESS_REQUEST),
        NDRIntField("SecurityDescriptorCount", None, size_of="pSecurityDescriptors"),
        NDRConfPacketListField(
            "pSecurityDescriptors",
            [],
            SR_SD,
            size_is=lambda pkt: pkt.SecurityDescriptorCount,
        ),
        NDRPacketField("pReply", AUTHZR_ACCESS_REPLY(), AUTHZR_ACCESS_REPLY),
    ]


class AuthzrAccessCheck_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pReply", AUTHZR_ACCESS_REPLY(), AUTHZR_ACCESS_REPLY),
        NDRIntField("status", 0),
    ]


class AUTHZ_CONTEXT_INFORMATION_CLASS(IntEnum):
    AuthzContextInfoUserSid = 1
    AuthzContextInfoGroupsSids = 2
    AuthzContextInfoRestrictedSids = 3
    ReservedEnumValue4 = 4
    ReservedEnumValue5 = 5
    ReservedEnumValue6 = 6
    ReservedEnumValue7 = 7
    ReservedEnumValue8 = 8
    ReservedEnumValue9 = 9
    ReservedEnumValue10 = 10
    ReservedEnumValue11 = 11
    AuthzContextInfoDeviceSids = 12
    AuthzContextInfoUserClaims = 13
    AuthzContextInfoDeviceClaims = 14
    ReservedEnumValue15 = 15
    ReservedEnumValue16 = 16


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


class AUTHZR_TOKEN_USER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("User", AUTHZR_SID_AND_ATTRIBUTES(), AUTHZR_SID_AND_ATTRIBUTES)
    ]


class AUTHZR_TOKEN_GROUPS(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["Groups"]
    fields_desc = [
        NDRIntField("GroupCount", None, size_of="Groups"),
        NDRConfPacketListField(
            "Groups",
            [],
            AUTHZR_SID_AND_ATTRIBUTES,
            size_is=lambda pkt: pkt.GroupCount,
            conformant_in_struct=True,
        ),
    ]


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


class AUTHZR_SECURITY_ATTRIBUTE_V1_VALUE(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRShortField("ValueType", 0),
        NDRUnionField(
            [
                (
                    NDRSignedLongField("AttributeUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRLongField("AttributeUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) in [2, 6]),
                        (lambda _, val: val.tag in [2, 6]),
                    ),
                ),
                (
                    NDRPacketField(
                        "AttributeUnion",
                        AUTHZR_SECURITY_ATTRIBUTE_STRING_VALUE(),
                        AUTHZR_SECURITY_ATTRIBUTE_STRING_VALUE,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("AttributeUnion", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "H"),
        ),
    ]


class AUTHZR_SECURITY_ATTRIBUTE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Length", None, size_of="Value"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16("Value", "", size_is=lambda pkt: pkt.Length),
            deferred=True,
        ),
        NDRShortField("ValueType", 0),
        NDRShortField("Reserved", 0),
        NDRIntField("Flags", 0),
        NDRIntField("ValueCount", None, size_of="Values"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Values",
                [],
                AUTHZR_SECURITY_ATTRIBUTE_V1_VALUE,
                size_is=lambda pkt: pkt.ValueCount,
            ),
            deferred=True,
        ),
    ]


class AUTHZR_SECURITY_ATTRIBUTES_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Version", 0),
        NDRShortField("Reserved", 0),
        NDRIntField("AttributeCount", None, size_of="Attributes"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Attributes",
                [],
                AUTHZR_SECURITY_ATTRIBUTE_V1,
                size_is=lambda pkt: pkt.AttributeCount,
            ),
            deferred=True,
        ),
    ]


class AUTHZR_CONTEXT_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("ValueType", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ContextInfoUnion", AUTHZR_TOKEN_USER(), AUTHZR_TOKEN_USER
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ContextInfoUnion",
                            AUTHZR_TOKEN_GROUPS(),
                            AUTHZR_TOKEN_GROUPS,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) in [2, 3, 12]),
                        (lambda _, val: val.tag in [2, 3, 12]),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "ContextInfoUnion",
                            AUTHZR_SECURITY_ATTRIBUTES_INFORMATION(),
                            AUTHZR_SECURITY_ATTRIBUTES_INFORMATION,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "ValueType", None) in [13, 14]),
                        (lambda _, val: val.tag in [13, 14]),
                    ),
                ),
            ],
            StrFixedLenField("ContextInfoUnion", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "H"),
        ),
    ]


class AuthzGetInformationFromContext_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRInt3264EnumField("InfoClass", 0, AUTHZ_CONTEXT_INFORMATION_CLASS),
    ]


class AuthzGetInformationFromContext_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppContextInformation",
                AUTHZR_CONTEXT_INFORMATION(),
                AUTHZR_CONTEXT_INFORMATION,
            )
        ),
        NDRIntField("status", 0),
    ]


class AUTHZ_SECURITY_ATTRIBUTE_OPERATION(IntEnum):
    AUTHZ_SECURITY_ATTRIBUTE_OPERATION_NONE = 0
    AUTHZ_SECURITY_ATTRIBUTE_OPERATION_REPLACE_ALL = 1
    AUTHZ_SECURITY_ATTRIBUTE_OPERATION_ADD = 2
    AUTHZ_SECURITY_ATTRIBUTE_OPERATION_DELETE = 3
    AUTHZ_SECURITY_ATTRIBUTE_OPERATION_REPLACE = 4


class AuthzrModifyClaims_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRInt3264EnumField("ClaimClass", 0, AUTHZ_CONTEXT_INFORMATION_CLASS),
        NDRIntField("OperationCount", None, size_of="pClaimOperations"),
        NDRConfFieldListField(
            "pClaimOperations",
            [],
            NDRInt3264EnumField(
                "pClaimOperations", 0, AUTHZ_SECURITY_ATTRIBUTE_OPERATION
            ),
            size_is=lambda pkt: pkt.OperationCount,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pClaims",
                AUTHZR_SECURITY_ATTRIBUTES_INFORMATION(),
                AUTHZR_SECURITY_ATTRIBUTES_INFORMATION,
            )
        ),
    ]


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


class AUTHZ_SID_OPERATION(IntEnum):
    AUTHZ_SID_OPERATION_NONE = 0
    AUTHZ_SID_OPERATION_REPLACE_ALL = 1
    AUTHZ_SID_OPERATION_ADD = 2
    AUTHZ_SID_OPERATION_DELETE = 3
    AUTHZ_SID_OPERATION_REPLACE = 4


class AuthzrModifySids_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContextHandle", NDRContextHandle(), NDRContextHandle),
        NDRInt3264EnumField("SidClass", 0, AUTHZ_CONTEXT_INFORMATION_CLASS),
        NDRIntField("OperationCount", None, size_of="pSidOperations"),
        NDRConfFieldListField(
            "pSidOperations",
            [],
            NDRInt3264EnumField("pSidOperations", 0, AUTHZ_SID_OPERATION),
            size_is=lambda pkt: pkt.OperationCount,
        ),
        NDRFullPointerField(
            NDRPacketField("pSids", AUTHZR_TOKEN_GROUPS(), AUTHZR_TOKEN_GROUPS)
        ),
    ]


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


AUTHZR_OPNUMS = {
    0: DceRpcOp(AuthzrFreeContext_Request, AuthzrFreeContext_Response),
    1: DceRpcOp(
        AuthzrInitializeContextFromSid_Request, AuthzrInitializeContextFromSid_Response
    ),
    2: DceRpcOp(
        AuthzrInitializeCompoundContext_Request,
        AuthzrInitializeCompoundContext_Response,
    ),
    3: DceRpcOp(AuthzrAccessCheck_Request, AuthzrAccessCheck_Response),
    4: DceRpcOp(
        AuthzGetInformationFromContext_Request, AuthzGetInformationFromContext_Response
    ),
    5: DceRpcOp(AuthzrModifyClaims_Request, AuthzrModifyClaims_Response),
    6: DceRpcOp(AuthzrModifySids_Request, AuthzrModifySids_Response),
}
register_dcerpc_interface(
    name="authzr",
    uuid=uuid.UUID("0b1c2170-5732-4e0e-8cd3-d9b16f3b84d7"),
    version="0.0",
    opnums=AUTHZR_OPNUMS,
)
