Exemplo n.º 1
0
static LWMsgStatus
fserv_close_srv(
    LWMsgCall* call,
    const LWMsgParams* in,
    LWMsgParams* out,
    void* data
    )
{
    LWMsgStatus status = LWMSG_STATUS_SUCCESS;
    LWMsgSession* session = lwmsg_call_get_session(call);
    FileHandle* handle = NULL;
    StatusReply* sreply = NULL;

    LOG("fserv_close() on fd %i for session %p\n", handle->fd, session);

    /* Get our internal handle from the lwmsg handle */
    status = lwmsg_session_get_handle_data(
        session,
        (LWMsgHandle*) in->data,
        (void**)(void*) &handle);
    if (status)
    {
        goto error;
    }

    /* Unregister the handle no matter what */
    status = lwmsg_session_unregister_handle(session, (LWMsgHandle*) in->data);
    if (status)
    {
        goto error;
    }
    
    if (close(handle->fd) == -1)
    {
        sreply = malloc(sizeof(*sreply));
        
        if (!sreply)
        {
            status = LWMSG_STATUS_MEMORY;
            goto error;
        }

        sreply->err = errno;
        out->tag = FSERV_ERROR_RES;
        out->data = sreply;
    }
    else
    {
        out->tag = FSERV_VOID_RES;
        out->data = NULL;
    }

error:

    return status;
}
Exemplo n.º 2
0
static LWMsgStatus
fserv_write_srv(
    LWMsgCall* call,
    const LWMsgParams* in,
    LWMsgParams* out,
    void* data
    )
{
    LWMsgStatus status = LWMSG_STATUS_SUCCESS;
    WriteRequest* req = (WriteRequest*) in->data;
    StatusReply* sreply = NULL;
    FileHandle* handle = NULL;
    int fd = -1;
    LWMsgSession* session = lwmsg_call_get_session(call);
    
    /* Get our internal handle from the lwmsg handle */
    status = lwmsg_session_get_handle_data(
        session,
        req->handle,
        (void**)(void*) &handle);
    if (status)
    {
        goto error;
    }

    fd = handle->fd;

    LOG("fserv_write() of %lu bytes to fd %i on session %p\n",
        (unsigned long) req->size, fd, session);

    if (write(fd, req->data, req->size) == -1)
    {
        sreply = malloc(sizeof(*sreply));
        
        if (!sreply)
        {
            status = LWMSG_STATUS_MEMORY;
            goto error;
        }

        sreply->err = errno;
        out->tag = FSERV_ERROR_RES;
        out->data = sreply;
    }
    else
    {
        out->tag = FSERV_VOID_RES;
        out->data = NULL;
    }

    out->data = (void*) sreply;

error:
    
    return status;
}
Exemplo n.º 3
0
static
NTSTATUS
RegSrvIpcGetHandleData(
    LWMsgCall* pCall,
    LWMsgHandle* pHandle,
    HKEY* phKey
    )
{
    LWMsgSession* pSession = lwmsg_call_get_session(pCall);
    return MAP_LWMSG_ERROR(lwmsg_session_get_handle_data(pSession, pHandle, OUT_PPVOID(phKey)));
}
Exemplo n.º 4
0
static
NTSTATUS
RegSrvIpcGetHandleData(
    LWMsgCall* pCall,
    LWMsgHandle* pHandle,
    HKEY* phKey
    )
{
    LWMsgSession* pSession = lwmsg_call_get_session(pCall);
    LWMsgStatus status = lwmsg_session_get_handle_data(pSession, pHandle, OUT_PPVOID(phKey));

    if (status == LWMSG_STATUS_INVALID_HANDLE)
    {
        return STATUS_INVALID_HANDLE;
    }
    else
    {
        return MAP_LWMSG_ERROR(status);
    }
}
Exemplo n.º 5
0
static LWMsgStatus
fserv_read_srv(
    LWMsgCall* call,
    const LWMsgParams* in,
    LWMsgParams* out,
    void* data
    )
{
    LWMsgStatus status = LWMSG_STATUS_SUCCESS;
    ReadRequest* req = (ReadRequest*) in->data;
    StatusReply* sreply = NULL;
    ReadReply* rreply = NULL;
    FileHandle* handle = NULL;
    int fd = -1;
    int ret = 0;
    LWMsgSession* session = lwmsg_call_get_session(call);
    
    /* Get our internal handle from the lwmsg handle */
    status = lwmsg_session_get_handle_data(
        session,
        req->handle,
        (void**)(void*) &handle);
    if (status)
    {
        goto error;
    }

    fd = handle->fd;

    LOG("fserv_read() of %lu bytes from fd %i on session %p\n",
        (unsigned long) req->size, fd, session);

    rreply = malloc(sizeof(*rreply));

    if (!rreply)
    {
        status = LWMSG_STATUS_MEMORY;
        goto error;
    }

    rreply->data = malloc(req->size);
    
    if (!rreply->data)
    {
        status = LWMSG_STATUS_MEMORY;
        goto error;
    }

    ret = read(fd, rreply->data, req->size);

    if (ret == -1)
    {
        int err = errno;

        free(rreply->data);
        free(rreply);

        sreply = malloc(sizeof(*sreply));

        if (!sreply)
        {
            status = LWMSG_STATUS_MEMORY;
            goto error;
        }

        sreply->err = err;
        out->tag = FSERV_ERROR_RES;
        out->data = (void*) sreply;
    }
    else if (ret == 0)
    {
        free(rreply->data);
        rreply->data = NULL;
        rreply->size = 0;
        out->tag = FSERV_READ_RES;
        out->data = (void*) rreply;
    }
    else
    {
        rreply->size = ret;
        out->tag = FSERV_READ_RES;
        out->data = (void*) rreply;
    }

error:
    
    return status;
}