1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Winsock 2 SPI
 * FILE:        lib/mswsock/lib/init.c
 * PURPOSE:     DLL Initialization
 */

#include "precomp.h"

#include <ndk/iofuncs.h>
#include <ndk/rtltypes.h>

/* FUNCTIONS *****************************************************************/

BOOLEAN
WINAPI
AcsHlpSendCommand(IN PAUTODIAL_COMMAND Command)
{
    UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"\\Device\\RasAcd");
    NTSTATUS Status;
    HANDLE DriverHandle;
    HANDLE EventHandle = NULL;
    OBJECT_ATTRIBUTES ObjectAttributes;
    IO_STATUS_BLOCK IoStatusBlock;

    /* Initialize the object attributes */
    InitializeObjectAttributes(&ObjectAttributes,
                               &DriverName,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);

    /* Open a handle to it */
    Status = NtCreateFile(&DriverHandle,
                          FILE_READ_DATA | FILE_WRITE_DATA,
                          &ObjectAttributes,
                          &IoStatusBlock,
                          NULL,
                          FILE_ATTRIBUTE_NORMAL,
                          FILE_SHARE_READ | FILE_SHARE_WRITE,
                          FILE_OPEN_IF,
                          0,
                          NULL,
                          0);
    if (!NT_SUCCESS(Status)) return FALSE;

    /* Create an event */
    EventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!EventHandle)
    {
        /* Event failed, fail us */
        CloseHandle(DriverHandle);
        return FALSE;
    }

    /* Connect to the driver */
    Status = NtDeviceIoControlFile(DriverHandle,
                                   EventHandle,
                                   NULL,
                                   NULL,
                                   &IoStatusBlock,
                                   IOCTL_ACD_CONNECT_ADDRESS,
                                   Command,
                                   sizeof(AUTODIAL_COMMAND),
                                   NULL,
                                   0);

    /* Check if we need to wait */
    if (Status == STATUS_PENDING)
    {
        /* Wait for the driver */
        Status = WaitForSingleObject(EventHandle, INFINITE);<--- Status is assigned

        /* Update status */
        Status = IoStatusBlock.Status;<--- Status is overwritten
    }

    /* Close handles and return */
    CloseHandle(EventHandle);
    CloseHandle(DriverHandle);
    return NT_SUCCESS(Status);
}

/*
 * @implemented
 */
BOOLEAN
WINAPI
AcsHlpAttemptConnection(IN PAUTODIAL_ADDR ConnectionAddress)
{
    AUTODIAL_COMMAND Command;

    /* Clear the command packet */
    RtlZeroMemory(&Command, sizeof(AUTODIAL_COMMAND));

    /* Copy the address into the command packet */
    RtlCopyMemory(&Command.Address, ConnectionAddress, sizeof(AUTODIAL_ADDR));

    /* Send it to the driver */
    return AcsHlpSendCommand(&Command);
}

/*
 * @implemented
 */
BOOLEAN
WINAPI
AcsHlpNoteNewConnection(IN PAUTODIAL_ADDR ConnectionAddress,
                        IN PAUTODIAL_CONN Connection)
{
    AUTODIAL_COMMAND Command;

    /* Copy the address into the command packet */
    RtlCopyMemory(&Command.Address, ConnectionAddress, sizeof(AUTODIAL_ADDR));

    /* Set the New Connection flag and copy the connection data */
    Command.NewConnection = TRUE;
    RtlCopyMemory(&Command.Connection, Connection, sizeof(AUTODIAL_CONN));

    /* Send it to the driver */
    return AcsHlpSendCommand(&Command);
}