Create TDI enpoint connection error, please help?

Home Forums Discussions General Create TDI enpoint connection error, please help?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4875
    rvd
    Participant

      Dear expert,

      I have a big problem that i have spent more time to solve it, but cannot solve it. My code below:

      NTSTATUS CreateConnection(PHANDLE Handle,
      PFILE_OBJECT *FileObject)
      {
      NTSTATUS status;
      UNICODE_STRING FullFileName;
      OBJECT_ATTRIBUTES ObjectAttributes;
      IO_STATUS_BLOCK ioStatus;
      PFILE_FULL_EA_INFORMATION eaInfo;
      ULONG dwSize;

      RtlInitUnicodeString(&FullFileName, L”\Device\Tcp”);
      InitializeObjectAttributes(&ObjectAttributes,&FullFileName, OBJ_CASE_INSENSITIVE,NULL,NULL);

      dwSize = sizeof(FILE_FULL_EA_INFORMATION) +
      strlen(TdiConnectionContext);

      eaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, dwSize);

      if(!eaInfo)
      {
      VLSDLogS(“VLSD: Failure of insufficient resources.”);
      return STATUS_INSUFFICIENT_RESOURCES;
      }

      RtlZeroMemory(eaInfo, dwSize);

      eaInfo->NextEntryOffset = 0;
      eaInfo->Flags = 0;
      eaInfo->EaNameLength = strlen(TdiConnectionContext);
      eaInfo->EaValueLength = 0;

      RtlCopyMemory(eaInfo->EaName, TdiConnectionContext, strlen(TdiConnectionContext) + 1);

      status = ZwCreateFile(Handle, FILE_READ_EA | FILE_WRITE_EA, &ObjectAttributes,
      &ioStatus,
      NULL,
      FILE_ATTRIBUTE_NORMAL,
      0,
      FILE_OPEN,
      0,
      eaInfo,
      dwSize) ;

      if (!NT_SUCCESS(status))
      {
      VLSDLogSL(“VLSD: Creating connection handle fail. Error number 0x”, status);
      return STATUS_INSUFFICIENT_RESOURCES;
      }

      status = ObReferenceObjectByHandle(*Handle,
      GENERIC_READ|GENERIC_WRITE,
      NULL,
      KernelMode,
      (PVOID *)FileObject,
      NULL);
      if(!NT_SUCCESS(status))
      ZwClose(*Handle);

      ExFreePool(eaInfo);

      return status;
      }

      Error always occur at function ZwCreateFile with status = 80000013 (system error code: 254 = ERROR_INVALID_EA_NAME) or status = 80000014 (255 = ERROR_EA_LIST_INCONSISTENT).

      Please help me, thanks in adv!

      VL.

      #5625
      Anton
      Participant

        1. You should set EaValue to ULONG “Connetion context”

        dwSize = FIELD_OFFSET( FILE_FULL_EA_INFORMATION, EaName[0] ) + TDI_CONNECTION_CONTEXT_LENGTH + 1 + sizeof(CONNECTION_CONTEXT);

        eaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(PagedPool, dwSize);

        eaInfo->NextEntryOffset = 0;
        eaInfo->Flags = 0;
        eaInfo->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
        eaInfo->EaValueLength = sizeof(CONNECTION_CONTEXT);

        RtlCopyMemory(
        eaInfo->EaName,
        TdiConnectionContext,
        TDI_CONNECTION_CONTEXT_LENGTH+1
        );

        RtlCopyMemory(
        &eaInfo->EaName[TDI_CONNECTION_CONTEXT_LENGTH+1],
        pConnectionContext,
        sizeof(CONNECTION_CONTEXT)
        );

        2. It’s better to open “connection endpoint” with the following attributes:
        ZwCreateFile(
        Handle, // Handle
        GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, // Desired Access
        &ObjectAttributes, // Object Attributes
        &IoStatusBlock, // Final I/O status block
        0, // Allocation Size
        FILE_ATTRIBUTE_NORMAL, // Normal attributes
        FILE_SHARE_READ, // Sharing attributes
        FILE_OPEN_IF, // Create disposition
        0, // CreateOptions
        pConnectionContextEa, // EA Buffer
        TransportEaBufferLength // EA length
        );

        #5626
        rvd
        Participant

          Dear Anton, thanks so much for your help. Thank you again. 😆

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.