Esempio n. 1
0
VOID
VmAfdTearDownStoreHashMap (
                            VOID
                          )
{
    DWORD dwIndex = 0;
    BOOLEAN bIsHoldingLock = FALSE;

    VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    for (; dwIndex < VECS_STOREHASH_MAP_SIZE; dwIndex++)
    {
        VECS_SRV_STORE_MAP storeMapEntry = gVecsGlobalStoreMap[dwIndex];

        VMAFD_SAFE_FREE_MEMORY (storeMapEntry.pStore);

        if (storeMapEntry.pSecurityDescriptor)
        {
            VmAfdFreeSecurityDescriptor (storeMapEntry.pSecurityDescriptor);
        }

        if (storeMapEntry.pStoreContextList)
        {
            VmAfdFreeContextList(storeMapEntry.pStoreContextList);
        }


        gVecsGlobalStoreMap[dwIndex].status = STORE_MAP_ENTRY_STATUS_EMPTY;
    }

    VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

}
Esempio n. 2
0
DWORD
VmAfdSetSecurityDescriptorForHandle (
                             PVECS_SRV_STORE_HANDLE pStore,
                             PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor
                             )
{
    DWORD dwError = 0;
    PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptorTmp = NULL;
    PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptorToClean = NULL;
    BOOL bIsHoldingLock = FALSE;

    if (!pStore ||
        !pSecurityDescriptor
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR (dwError);
    }

    dwError = VmAfdCopySecurityDescriptor (
                                            pSecurityDescriptor,
                                            &pSecurityDescriptorTmp
                                          );
    BAIL_ON_VMAFD_ERROR (dwError);


    VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    dwError = VecsDbSetSecurityDescriptor (
              gVecsGlobalStoreMap[pStore->dwStoreHandle].pStore->dwStoreId,
              pSecurityDescriptorTmp
              );
    BAIL_ON_VMAFD_ERROR (dwError);

    pSecurityDescriptorToClean =
      gVecsGlobalStoreMap[pStore->dwStoreHandle].pSecurityDescriptor;

    VmAfdCleanSecurityDescriptor (pSecurityDescriptorTmp);

    gVecsGlobalStoreMap[pStore->dwStoreHandle].pSecurityDescriptor =
                            pSecurityDescriptorTmp;

cleanup:
    if (pSecurityDescriptorToClean)
    {
        VmAfdFreeSecurityDescriptor(pSecurityDescriptorToClean);
    }

    VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    return dwError;

error:
    if (pSecurityDescriptorTmp)
    {
        VmAfdFreeSecurityDescriptor (pSecurityDescriptorTmp);
    }

    goto cleanup;
}
Esempio n. 3
0
DWORD
VmAfSrvPostHeartbeat(
    PCWSTR pwszServiceName,
    DWORD  dwPort
    )
{
    DWORD dwError  = 0;
    PVMAFD_HB_NODE pNode = NULL;
    BOOL bIsHoldingLock = FALSE;

    if (IsNullOrEmptyString(pwszServiceName))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfdFindNode(
                        pwszServiceName,
                        dwPort,
                        &pNode
                        );
    if (dwError == ERROR_OBJECT_NOT_FOUND)
    {
        dwError = VmAfdInsertNode(
                            pwszServiceName,
                            dwPort,
                            &pNode
                            );
    }
    BAIL_ON_VMAFD_ERROR(dwError);

    VMAFD_LOCK_MUTEX_EXCLUSIVE(&rwlockHeartbeatTable, bIsHoldingLock);

    pNode->tLastPing = time(NULL);

    VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock);

cleanup:

    VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock);
    return dwError;
error:

    goto cleanup;
}
Esempio n. 4
0
VOID
VmAfdReleaseStoreHandle (
                          PVECS_SRV_STORE_HANDLE pStoreHandle
                        )
{
    if (
        pStoreHandle
        )
    {
       BOOLEAN bIsHoldingLock = FALSE;

       VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

        VmAfdReleaseStoreEntry (pStoreHandle->dwStoreHandle);

        VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
    }
}
Esempio n. 5
0
VOID
VmAfdCloseStoreHandle (
                        PVECS_SRV_STORE_HANDLE pStoreHandle,
                        PVM_AFD_SECURITY_CONTEXT pSecurityContext
                      )
{
    if (pStoreHandle)
    {
        BOOLEAN bIsHoldingLock = FALSE;
        VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
        VmAfdCloseStoreInstance (
                                 pStoreHandle->dwStoreHandle,
                                 pSecurityContext,
                                 pStoreHandle->dwClientInstance
                                );
        VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
        VMAFD_SAFE_FREE_MEMORY (pStoreHandle);
    }
}
Esempio n. 6
0
VOID
VmAfdDeleteStoreEntry (
                        PVECS_SRV_STORE_HANDLE pStoreHandle
                      )
{
    DWORD dwStoreMapIndex = 0;
    if (pStoreHandle)
    {
        BOOLEAN bIsHoldingLock = FALSE;
        dwStoreMapIndex = pStoreHandle->dwStoreHandle;

        VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

        VMAFD_SAFE_FREE_MEMORY (
                            gVecsGlobalStoreMap[dwStoreMapIndex].pStore
                            );

        VmAfdFreeSecurityDescriptor (
                            gVecsGlobalStoreMap[dwStoreMapIndex].pSecurityDescriptor
                            );

        gVecsGlobalStoreMap[dwStoreMapIndex].pSecurityDescriptor = NULL;

        VmAfdFreeContextList (
                            gVecsGlobalStoreMap[dwStoreMapIndex].pStoreContextList
                            );
        gVecsGlobalStoreMap[dwStoreMapIndex].pStoreContextList = NULL;

        gVecsGlobalStoreMap[dwStoreMapIndex].status = STORE_MAP_ENTRY_STATUS_EMPTY;

        VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    }

    VMAFD_SAFE_FREE_MEMORY (pStoreHandle);
}
Esempio n. 7
0
PVECS_SRV_STORE_HANDLE
VmAfdAcquireStoreHandle (
                          PVECS_SRV_STORE_HANDLE pStoreHandle
                        )
{
    if (
        pStoreHandle &&
        gVecsGlobalStoreMap[pStoreHandle->dwStoreHandle].pStore
       )
    {
        PVECS_SERV_STORE pStore = NULL;
        BOOLEAN bIsHoldingLock = FALSE;

        VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

        pStore =
          gVecsGlobalStoreMap[pStoreHandle->dwStoreHandle].pStore;

        pStore = VecsSrvAcquireCertStore (pStore);
        VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
    }

    return pStoreHandle;
}
Esempio n. 8
0
static
DWORD
VmAfdInsertNode(
    PCWSTR pwszServiceName,
    DWORD  dwPort,
    PVMAFD_HB_NODE *ppNode
    )
{
    DWORD dwError = 0;
    PVMAFD_HB_NODE pNode = NULL;
    BOOL bIsHoldingLock = FALSE;

    if (IsNullOrEmptyString(pwszServiceName) ||
        !ppNode
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfdAllocateMemory(
                            sizeof(VMAFD_HB_NODE),
                            (PVOID *)&pNode
                            );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdAllocateStringW(
                            pwszServiceName,
                            &pNode->pszServiceName
                            );
    BAIL_ON_VMAFD_ERROR(dwError);

    pNode->dwPort = dwPort;

    *ppNode = pNode;

    VMAFD_LOCK_MUTEX_EXCLUSIVE(&rwlockHeartbeatTable, bIsHoldingLock);

    if (gHeartbeatTable.dwNextAvailableIndex == VMAFD_HEARTBEAT_TABLE_COUNT)
    {
        dwError = ERROR_OUTOFMEMORY;
        BAIL_ON_VMAFD_ERROR(dwError);
    }
    gHeartbeatTable.pEntries[gHeartbeatTable.dwNextAvailableIndex] = pNode;

    VmAfdUpdateAvailableIndex();

    VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock);

cleanup:

    VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock);
    return dwError;
error:

    if (ppNode)
    {
        *ppNode = NULL;
    }
    if (pNode)
    {
        VmAfdFreeHbNode(pNode);
    }
    goto cleanup;
}
Esempio n. 9
0
DWORD
VmAfdGetStoreHandle (
                      PWSTR pszStoreName,
                      PWSTR pszPassword,
                      PVM_AFD_SECURITY_CONTEXT pSecurityContext,
                      PVECS_SRV_STORE_HANDLE *ppStore
                    )
{
    DWORD dwError = 0;
    PVECS_SRV_STORE_HANDLE pStore = NULL;
    BOOL bIsHoldingLock = FALSE;

    DWORD dwStoreId = 0;

    DWORD dwHashedIndx = -1;
    DWORD dwClientInstance = 0;

    if (IsNullOrEmptyString (pszStoreName) ||
        !pSecurityContext ||
        !ppStore
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR (dwError);
    }


    dwError = VecsDbGetCertStore(
                                  pszStoreName,
                                  pszPassword,
                                  &dwStoreId
                                );

    BAIL_ON_VMAFD_ERROR (dwError);

    dwError = VmAfdComputeStoreMapHash(
                                        dwStoreId,
                                        &dwHashedIndx
                                      );

    BAIL_ON_VMAFD_ERROR (dwError);

    VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    if (gVecsGlobalStoreMap[dwHashedIndx].status ==
                                 STORE_MAP_ENTRY_STATUS_EMPTY)
    {
        dwError = VmAfdInitializeStoreEntry (
                                              dwStoreId,
                                              pSecurityContext,
                                              dwHashedIndx
                                            );

        BAIL_ON_VMAFD_ERROR (dwError);
        dwClientInstance = 1;
    }

    else
    {
        dwError = VmAfdCreateNewClientInstance (
                                                 pSecurityContext,
                                                 dwHashedIndx,
                                                 &dwClientInstance
                                               );

        BAIL_ON_VMAFD_ERROR (dwError);


        gVecsGlobalStoreMap[dwHashedIndx].pStore =
           VecsSrvAcquireCertStore (gVecsGlobalStoreMap[dwHashedIndx].pStore);

    }


    gVecsGlobalStoreMap[dwHashedIndx].status =
                                       STORE_MAP_ENTRY_STATUS_OPEN;

    VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    dwError = VmAfdAllocateMemory (
                                   sizeof (VECS_SRV_STORE_HANDLE),
                                   (PVOID *) &pStore
                                  );
    BAIL_ON_VMAFD_ERROR (dwError);


    pStore->dwStoreHandle = dwHashedIndx;
    pStore->dwClientInstance = dwClientInstance;

    pStore->dwStoreSessionID =
      gVecsGlobalStoreMap[dwHashedIndx].dwStoreSessionID;

    *ppStore = pStore;

cleanup:

    VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);

    return dwError;

error:
    if (ppStore)
    {
        *ppStore = NULL;
    }
    if (dwHashedIndx != -1 &&
        dwClientInstance &&
        pSecurityContext
       )
    {
        VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
        VmAfdCloseStoreInstance (
                                  dwHashedIndx,
                                  pSecurityContext,
                                  dwClientInstance
                                );
        VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock);
    }
    VMAFD_SAFE_FREE_MEMORY (pStore);

    goto cleanup;
}