Ejemplo n.º 1
0
VOID
LwRtlFreeThreadPool(
    PLW_THREAD_POOL* ppPool
    )
{
    PLW_THREAD_POOL pPool = *ppPool;
    PEPOLL_THREAD pThread = NULL;
    int i = 0;

    if (pPool)
    {
        LOCK_POOL(pPool);
        pPool->bShutdown = TRUE;
        pthread_cond_broadcast(&pPool->Event);
        UNLOCK_POOL(pPool);

        if (pPool->pEventThreads)
        {
            for (i = 0; i < pPool->ulEventThreadCount; i++)
            {
                pThread = &pPool->pEventThreads[i];
                LOCK_THREAD(pThread);
                pThread->bShutdown = TRUE;
                SignalThread(pThread);
                UNLOCK_THREAD(pThread);
                pthread_join(pThread->Thread, NULL);
                DestroyEventThread(pThread);
            }

            RtlMemoryFree(pPool->pEventThreads);
        }

        if (pPool->pDelegate)
        {
            ReleaseDelegatePool(&pPool->pDelegate);
        }

        pthread_cond_destroy(&pPool->Event);

        pthread_mutex_destroy(&pPool->Lock);

        DestroyWorkThreads(&pPool->WorkThreads);

        RtlMemoryFree(pPool);

        *ppPool = NULL;
    }
}
Ejemplo n.º 2
0
static
VOID
TaskDelete(
    PEPOLL_TASK pTask
    )
{
    RTL_FREE(&pTask->pUnixSignal);
    RtlMemoryFree(pTask);
}
Ejemplo n.º 3
0
LW_NTSTATUS
LwFileInfoMarshalGetInfoInParameters(
    PFILE_INFO_GET_INFO_IN_PARAMS pParams,
    PBYTE*                        ppBuffer,
    ULONG*                        pulBufferSize
    )
{
    NTSTATUS ntStatus = 0;
    VOID* pBuffer = NULL;
    size_t ulBufferSize = 0;
    LWMsgDataContext* pDataContext = NULL;

    ntStatus = LwSrvInfoAcquireDataContext(&pDataContext);
    BAIL_ON_NT_STATUS(ntStatus);

    ntStatus = MAP_LWMSG_STATUS(
        lwmsg_data_marshal_flat_alloc(
            pDataContext,
            gFileInfoGetInParamsSpec,
            pParams,
            &pBuffer,
            &ulBufferSize));
    BAIL_ON_NT_STATUS(ntStatus);

    *ppBuffer = pBuffer;
    *pulBufferSize = (ULONG) ulBufferSize;

cleanup:

    LwSrvInfoReleaseDataContext(pDataContext);

    return ntStatus;

error:

    *ppBuffer = NULL;
    *pulBufferSize = 0;

    if (pBuffer)
    {
        RtlMemoryFree(pBuffer);
    }

    goto cleanup;
}
Ejemplo n.º 4
0
VOID
DestroyWorkThreads(
    PLW_WORK_THREADS pThreads
    )
{
    size_t i = 0;

    if (pThreads->pWorkThreads)
    {
        WaitWorkItems(pThreads);

        LOCK_THREADS(pThreads);
        pThreads->bShutdown = TRUE;
        pthread_cond_broadcast(&pThreads->Event);
        
        for (i = 0; i < pThreads->ulWorkThreadCount; i++)
        {
            if (pThreads->pWorkThreads[i].Thread != INVALID_THREAD_HANDLE)
            {
                /* We must pthread_join() outside of the lock */
                UNLOCK_THREADS(pThreads);
                pthread_join(pThreads->pWorkThreads[i].Thread, NULL);
                LOCK_THREADS(pThreads);
            }
        }
        UNLOCK_THREADS(pThreads);

        RtlMemoryFree(pThreads->pWorkThreads);
    }

    if (pThreads->bDestroyLock)
    {        
        pthread_mutex_destroy(&pThreads->Lock);
    }

    if (pThreads->bDestroyEvent)
    {
        pthread_cond_destroy(&pThreads->Event);
    }
}
Ejemplo n.º 5
0
VOID
LwRtlFreeTaskGroup(
    PLW_TASK_GROUP* ppGroup
    )
{
    PLW_TASK_GROUP pGroup = *ppGroup;

    if (pGroup)
    {
        if (pGroup->bLockInit)
        {
            pthread_mutex_destroy(&pGroup->Lock);
        }

        if (pGroup->bEventInit)
        {
            pthread_cond_destroy(&pGroup->Event);
        }

        RtlMemoryFree(pGroup);

        *ppGroup = NULL;
    }
}
Ejemplo n.º 6
0
static
DWORD
test_access_token(
    PCSTR pszUpn)
{
    PTOKEN_USER              pUser  = NULL;
    PTOKEN_GROUPS            pGroups = NULL;
    PACCESS_TOKEN            pAccessToken = NULL;
    PSTR                     pszUserSid = NULL;
    PSTR                     pszGroupSid = NULL;
    PLW_MAP_SECURITY_CONTEXT pMapSecurityContext = NULL;
    DWORD                    ulBufLen = 0;
    DWORD                    dwError = 0;
    DWORD                    dwIndex = 0;

    dwError = LwMapSecurityCreateContext(&pMapSecurityContext);
    BAIL_ON_VMDIR_ERROR(dwError);

    printf("Creating access token for UPN: %s\n", pszUpn);

    dwError = LwMapSecurityCreateAccessTokenFromCStringUsername(
                  pMapSecurityContext,
                  &pAccessToken,
                  pszUpn);
    BAIL_ON_VMDIR_ERROR(dwError);

    // get user sid
    dwError = RtlQueryAccessTokenInformation(
                  pAccessToken,
                  TokenUser,
                  NULL,
                  0,
                  &ulBufLen);
    dwError = LwNtStatusToWin32Error(dwError);
    BAIL_ON_VMDIR_ERROR(dwError != ERROR_INSUFFICIENT_BUFFER);

    pUser = RtlMemoryAllocate(ulBufLen, TRUE);
    if (!pUser)
    {
        dwError = ERROR_NOT_ENOUGH_MEMORY;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = RtlQueryAccessTokenInformation(
                  pAccessToken,
                  TokenUser,
                  pUser,
                  ulBufLen,
                  &ulBufLen);
    dwError = LwNtStatusToWin32Error(dwError);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = RtlAllocateCStringFromSid(
                  &pszUserSid,
                  pUser->User.Sid);
    BAIL_ON_VMDIR_ERROR(dwError);

    printf("User SID: %s\n", pszUserSid);

    dwError = RtlQueryAccessTokenInformation(
                  pAccessToken,
                  TokenGroups,
                  NULL,
                  0,
                  &ulBufLen);
    dwError = LwNtStatusToWin32Error(dwError);
    BAIL_ON_VMDIR_ERROR(dwError != ERROR_INSUFFICIENT_BUFFER);

    pGroups = RtlMemoryAllocate(ulBufLen, TRUE);
    if (!pGroups)
    {
        dwError = ERROR_NOT_ENOUGH_MEMORY;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = RtlQueryAccessTokenInformation(
                  pAccessToken,
                  TokenGroups,
                  pGroups,
                  ulBufLen,
                  &ulBufLen);
    dwError = LwNtStatusToWin32Error(dwError);
    BAIL_ON_VMDIR_ERROR(dwError);

    for (dwIndex = 0; dwIndex < pGroups->GroupCount; dwIndex++)
    {
        dwError = RtlAllocateCStringFromSid(
                      &pszGroupSid,
                      pGroups->Groups[dwIndex].Sid);
        BAIL_ON_VMDIR_ERROR(dwError);

        printf("Group SID: %s\n", pszGroupSid);
    }

cleanup:
    if (pMapSecurityContext)
    {
        LwMapSecurityFreeContext(&pMapSecurityContext);
    }
    if (pAccessToken)
    {
        RtlReleaseAccessToken(&pAccessToken);
    }
    if (pszUserSid)
    {
        RtlMemoryFree(pszUserSid);
    }
    if (pGroups)
    {
        RtlMemoryFree(pGroups);
    }
    if (pUser)
    {
        RtlMemoryFree(pUser);
    }

    return dwError;

error:
    goto cleanup;
}
Ejemplo n.º 7
0
LW_NTSTATUS
LwFileInfoUnmarshalGetInfoOutParameters(
    PBYTE             pBuffer,
    ULONG             ulBufferSize,
    DWORD             dwInfoLevel,
    PFILE_INFO_UNION* ppFileInfo
    )
{
    NTSTATUS Status = STATUS_SUCCESS;
    LWMsgBuffer mbuf   =
        {
            .base   = pBuffer,
            .end    = pBuffer + ulBufferSize,
            .cursor = pBuffer,
            .wrap   = NULL
        };
    PFILE_INFO_UNION  pFileInfo    = NULL;
    LWMsgDataContext* pDataContext = NULL;

    Status = LwSrvInfoAcquireDataContext(&pDataContext);
    BAIL_ON_NT_STATUS(Status);

    Status = MAP_LWMSG_STATUS(
                lwmsg_data_alloc_memory(
                    pDataContext,
                    sizeof(FILE_INFO_UNION),
                    OUT_PPVOID(&pFileInfo)));
    BAIL_ON_NT_STATUS(Status);

    switch (dwInfoLevel)
    {
        case 2:

            Status = MAP_LWMSG_STATUS(
                        lwmsg_data_alloc_memory(
                            pDataContext,
                            sizeof(FILE_INFO_2),
                            OUT_PPVOID(&pFileInfo->p2)));
            BAIL_ON_NT_STATUS(Status);

            Status = MAP_LWMSG_STATUS(
                        lwmsg_data_unmarshal_into(
                            pDataContext,
                            gFileInfo2Spec,
                            &mbuf,
                            pFileInfo->p2,
                            sizeof(FILE_INFO_2)));

            break;

        case 3:

            Status = MAP_LWMSG_STATUS(
                        lwmsg_data_alloc_memory(
                            pDataContext,
                            sizeof(FILE_INFO_3),
                            OUT_PPVOID(&pFileInfo->p3)));
            BAIL_ON_NT_STATUS(Status);

            Status = MAP_LWMSG_STATUS(
                        lwmsg_data_unmarshal_into(
                            pDataContext,
                            gFileInfo3Spec,
                            &mbuf,
                            pFileInfo->p3,
                            sizeof(FILE_INFO_3)));

            break;

        default:

            Status = STATUS_INVALID_INFO_CLASS;

            break;
    }
    BAIL_ON_NT_STATUS(Status);

    *ppFileInfo = pFileInfo;

cleanup:

    LwSrvInfoReleaseDataContext(pDataContext);

    return Status;

error:

    *ppFileInfo = NULL;

    if (pFileInfo)
    {
        LwFileInfoFreeInternal(
            pDataContext,
            dwInfoLevel,
            1,
            pFileInfo);
    }

    goto cleanup;
}

LW_NTSTATUS
LwFileInfoMarshalCloseParameters(
    PFILE_INFO_CLOSE_PARAMS pParams,
    PBYTE*                  ppBuffer,
    ULONG*                  pulBufferSize
    )
{
    NTSTATUS Status = STATUS_SUCCESS;
    VOID* pBuffer = NULL;
    size_t ulBufferSize = 0;
    LWMsgDataContext* pDataContext = NULL;

    Status = LwSrvInfoAcquireDataContext(&pDataContext);
    BAIL_ON_NT_STATUS(Status);

    Status = MAP_LWMSG_STATUS(
        lwmsg_data_marshal_flat_alloc(
            pDataContext,
            gFileInfoCloseParamsSpec,
            pParams,
            &pBuffer,
            &ulBufferSize));
    BAIL_ON_NT_STATUS(Status);

    *ppBuffer = pBuffer;
    *pulBufferSize = (ULONG) ulBufferSize;

cleanup:

    LwSrvInfoReleaseDataContext(pDataContext);

    return Status;

error:
    *ppBuffer = NULL;
    *pulBufferSize = 0;

    if (pBuffer)
    {
        RtlMemoryFree(pBuffer);
    }

    goto cleanup;
}