Beispiel #1
0
static
DWORD
CdcPurgeCache(
    VOID
    )
{
    DWORD dwError = 0;
    PCDC_DB_ENTRY_W pEntries = NULL;
    DWORD dwDCCount = 0;
    DWORD dwIndex = 0;
    UINT64 iStart = 0;
    UINT64 iEnd = 0;
    iStart = VmAfdGetTimeInMilliSec();

    dwError = CdcDbEnumDCEntries(
                        &pEntries,
                        &dwDCCount
                        );
    BAIL_ON_VMAFD_ERROR(dwError);

    if (dwDCCount)
    {
        for (; dwIndex<dwDCCount; ++dwIndex)
        {
            dwError = CdcDbDeleteDCEntry(pEntries[dwIndex].pszDCName);
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }

    iEnd = VmAfdGetTimeInMilliSec();

cleanup:

    if (pEntries)
    {
        VmAfdFreeCdcDbEntriesW(pEntries, dwDCCount);
    }
    return dwError;
error:

    (DWORD)VmAfdAddDBSuperLogEntry(
                                gVmafdGlobals.pLogger,
                                iStart,
                                iEnd,
                                pEntries,
                                dwError);

    goto cleanup;
}
Beispiel #2
0
static
DWORD
CdcPurgeCache(
    VOID
    )
{
    DWORD dwError = 0;
    PWSTR *ppszEntryNames = NULL;
    DWORD dwDCCount = 0;
    DWORD dwIndex = 0;

    dwError = CdcDbEnumDCEntries(
                        &ppszEntryNames,
                        &dwDCCount
                        );
    BAIL_ON_VMAFD_ERROR(dwError);

    if (dwDCCount)
    {
        for (; dwIndex<dwDCCount; ++dwIndex)
        {
            dwError = CdcDbDeleteDCEntry(ppszEntryNames[dwIndex]);
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }

cleanup:

    if (ppszEntryNames)
    {
        VmAfdFreeStringArrayW(ppszEntryNames, dwDCCount);
    }
    return dwError;
error:

    goto cleanup;
}
Beispiel #3
0
static
DWORD
CdcUpdateCache(
    BOOL bPurgeRefresh
    )
{

    DWORD dwError = 0;
    PWSTR *ppszDomainControllers = NULL;
    DWORD dwDCCount = 0;
    DWORD dwIndex = 0;

    time_t timeTaken = 0;
    DWORD dwPingResult = 0;

    PCDC_DB_ENTRY_W pCdcEntry = NULL;

    if (bPurgeRefresh)
    {
        dwError = CdcGetDomainControllers(
                              &ppszDomainControllers,
                              &dwDCCount
                              );
    }
    if (!bPurgeRefresh || dwError)
    {
        dwError = CdcDbEnumDCEntries(
                               &ppszDomainControllers,
                               &dwDCCount
                               );
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    if (dwDCCount)
    {
        dwError = VmAfdAllocateMemory(
                            sizeof(CDC_DB_ENTRY_W)*dwDCCount,
                            (PVOID *)&pCdcEntry
                            );
        BAIL_ON_VMAFD_ERROR(dwError);

        for (; dwIndex < dwDCCount; ++dwIndex)
        {
            dwError = VmAfdAllocateStringW(
                            ppszDomainControllers[dwIndex],
                            &pCdcEntry[dwIndex].pszDCName
                            );
            BAIL_ON_VMAFD_ERROR(dwError);

            dwError = CdcDCPing(
                          ppszDomainControllers[dwIndex],
                          NULL, //to accomodate multiple domains in future
                          &dwPingResult,
                          &timeTaken,
                          &pCdcEntry[dwIndex].pszSiteName
                          );

            pCdcEntry[dwIndex].dwPingTime = (DWORD) (timeTaken);

            if (!dwPingResult)
            {
                pCdcEntry[dwIndex].bIsAlive = TRUE;
            }

            pCdcEntry[dwIndex].dwLastPing = (DWORD)time(NULL);

            pCdcEntry[dwIndex].cdcEntryStatus =
                              bPurgeRefresh?CDC_DB_ENTRY_STATUS_NEW:
                              CDC_DB_ENTRY_STATUS_UPDATE;
        }

        dwError = CdcRefreshCache(bPurgeRefresh, pCdcEntry, dwDCCount);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

cleanup:

    if (pCdcEntry)
    {
       VmAfdFreeCdcDbEntryArrayW(pCdcEntry,dwDCCount);
    }
    if (ppszDomainControllers)
    {
        VmAfdFreeStringArrayW(
                    ppszDomainControllers,
                    dwDCCount
                    );
    }
    return dwError;
error:

    goto cleanup;
}
Beispiel #4
0
static
DWORD
CdcRefreshCache(
    BOOL bPurgeRefresh,
    PCDC_DB_ENTRY_W pCdcEntry,
    DWORD dwCount
    )
{
    //TODO: Or simply always purge and repopulate?
    DWORD dwError = 0;
    PWSTR *ppszDomainControllers = NULL;
    DWORD dwDBDCCount = 0;
    DWORD dwDbIndex = 0;
    DWORD dwIndex = 0;
    PWSTR pwszDomainName = NULL;

    if (!pCdcEntry)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfSrvGetDomainName(&pwszDomainName);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (bPurgeRefresh)
    {
        dwError = CdcDbEnumDCEntries(&ppszDomainControllers, &dwDBDCCount);
        BAIL_ON_VMAFD_ERROR(dwError);

        for (; dwDbIndex<dwDBDCCount; ++dwDbIndex)
        {
            BOOL bFoundDC = FALSE;
            for (dwIndex = 0;dwIndex < dwCount; ++dwIndex)
            {
               if (VmAfdStringIsEqualW(
                            ppszDomainControllers[dwDbIndex],
                            pCdcEntry[dwIndex].pszDCName,
                            FALSE
                     )
                  )
               {
                    pCdcEntry[dwIndex].cdcEntryStatus =
                                          CDC_DB_ENTRY_STATUS_UPDATE;
                    bFoundDC = TRUE;
                    break;
               }
            }

            if (!bFoundDC)
            {
               CdcDbDeleteDCEntry(ppszDomainControllers[dwDbIndex]);
            }
        }
    }

    for (dwIndex = 0; dwIndex < dwCount; ++dwIndex)
    {

        dwError = VmAfdAllocateStringW(
                                pwszDomainName,
                                &pCdcEntry[dwIndex].pszDomainName
                                );
        BAIL_ON_VMAFD_ERROR(dwError);

        switch (pCdcEntry[dwIndex].cdcEntryStatus)
        {
            case CDC_DB_ENTRY_STATUS_NEW:
                dwError = CdcDbAddDCEntry(&pCdcEntry[dwIndex]);
                break;

            case CDC_DB_ENTRY_STATUS_UPDATE:
                dwError = CdcDbUpdateDCEntry(&pCdcEntry[dwIndex]);
                break;

            default:
                dwError = ERROR_INVALID_PARAMETER;
                break;
        }
        BAIL_ON_VMAFD_ERROR(dwError);
    }

cleanup:

    if (ppszDomainControllers)
    {
        VmAfdFreeStringArrayW(ppszDomainControllers, dwDBDCCount);
    }
    VMAFD_SAFE_FREE_MEMORY(pwszDomainName);
    return dwError;
error:

    goto cleanup;
}
Beispiel #5
0
DWORD
CdcSrvEnumDCEntries(
    PWSTR **pppszEntryNames,
    PDWORD pdwCount
    )
{
    DWORD dwError = 0;
    DWORD dwCount = 0;
    DWORD dwIndex = 0;
    PWSTR* ppszEntryNames = NULL;
    PCDC_DB_ENTRY_W pCdcEntries = NULL;
    UINT64 iStart = 0;
    UINT64 iEnd = 0;

    if (!pppszEntryNames || !pdwCount)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    iStart = VmAfdGetTimeInMilliSec();

    dwError = CdcDbEnumDCEntries(&pCdcEntries, &dwCount);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (dwCount)
    {
        dwError = VmAfdAllocateMemory(
                            sizeof(PWSTR)*dwCount,
                            (PVOID)&ppszEntryNames
                            );
        BAIL_ON_VMAFD_ERROR(dwError);

        for (; dwIndex < dwCount; ++dwIndex)
        {
            dwError = VmAfdAllocateStringW(
                                  pCdcEntries[dwIndex].pszDCName,
                                  &ppszEntryNames[dwIndex]
                                  );
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }

    iEnd = VmAfdGetTimeInMilliSec();

    *pppszEntryNames = ppszEntryNames;
    *pdwCount = dwCount;

cleanup:

    if (pCdcEntries)
    {
        VmAfdFreeCdcDbEntriesW(pCdcEntries, dwCount);
    }
    return dwError;

error:

    (DWORD)VmAfdAddDBSuperLogEntry(
                               gVmafdGlobals.pLogger,
                               iStart,
                               iEnd,
                               pCdcEntries,
                               dwError);

    if (pppszEntryNames)
    {
        *pppszEntryNames = NULL;
    }
    if (ppszEntryNames)
    {
        VmAfdFreeStringArrayW(ppszEntryNames, dwCount);
    }
    goto cleanup;
}