Exemple #1
0
VOID
VmDnsSockWinFreeIoBuffer(
    PVM_SOCK_IO_BUFFER     pIoBuffer
    )
{
    PVM_SOCK_IO_CONTEXT pIoContext = CONTAINING_RECORD(pIoBuffer, VM_SOCK_IO_CONTEXT, IoBuffer);
    VMDNS_LOG_INFO("Freeing Io Buffer - Address: %p, Event: %d, Size: %d", (DWORD)pIoBuffer, pIoContext->eventType, pIoBuffer->dwCurrentSize);
    VMDNS_SAFE_FREE_MEMORY(pIoContext);
}
Exemple #2
0
DWORD
VmDnsSockWinAllocateIoBuffer(
    VM_SOCK_EVENT_TYPE      eventType,
    PVM_SOCK_EVENT_CONTEXT      pEventContext,
    PFN_SOCK_EVENT_CONTEXT_FREE pfnEventContextFree,
    DWORD                   dwSize,
    PVM_SOCK_IO_BUFFER*     ppIoBuffer
    )
{
    DWORD dwError = 0;
    PVM_SOCK_IO_CONTEXT pIoContext = NULL;

    if (!ppIoBuffer)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDNS_ERROR(dwError);
    }

    dwError = VmDnsAllocateMemory(sizeof(VM_SOCK_IO_CONTEXT) + dwSize, (PVOID*)&pIoContext);
    BAIL_ON_VMDNS_ERROR(dwError);

    pIoContext->eventType = eventType;
    pIoContext->IoBuffer.dwExpectedSize = dwSize;
    pIoContext->IoBuffer.pData = pIoContext->DataBuffer;

    VMDNS_LOG_INFO("Buffer Allocated - Address: %p, Event: %d, Size: %d", 
        (DWORD)&pIoContext->IoBuffer, 
        pIoContext->eventType, 
        pIoContext->IoBuffer.dwExpectedSize);

    *ppIoBuffer = &(pIoContext->IoBuffer);

cleanup:

    return dwError;

error:

    if (ppIoBuffer)
    {
        *ppIoBuffer = NULL;
    }

    if (pIoContext)
    {
        VmDnsSockWinFreeIoBuffer(&pIoContext->IoBuffer);
    }

    goto cleanup;
}
Exemple #3
0
static
DWORD
VmDnsCacheRefreshThread(
    PVOID   pArgs
    )
{
    DWORD dwError = 0;
    DWORD newUSN = 0;
    PVMDNS_CACHE_CONTEXT pCacheContext = (PVMDNS_CACHE_CONTEXT)pArgs;
    pCacheContext->bRunning = TRUE;
    pCacheContext->dwLastUSN = 0;
    dwError = VmDnsStoreGetReplicationStatus(&(pCacheContext->dwLastUSN));

    while (!pCacheContext->bShutdown)
    {
        if (VMDNS_READY != VmDnsSrvGetState())
        {
            dwError = VmDnsCacheLoadInitialData(pCacheContext);
            if (dwError)
            {
                VMDNS_LOG_DEBUG("DnsCacheRefreshThread loading initial data failed with %u...Retrying", dwError);
                goto wait;
            }
            else
            {
                VMDNS_LOG_INFO("DnsCacheRefreshThread loaded initial data, setting VMDNS state to READY.");
                VmDnsSrvSetState(VMDNS_READY);
            }
        }

        newUSN = 0;
        VmDnsStoreGetReplicationStatus(&newUSN);
        if (pCacheContext->dwLastUSN != 0)
        {
            // Refresh LRU, Cache etc.
            dwError = VmDnsCacheSyncZones(
                            pCacheContext->dwLastUSN,
                            pCacheContext
                            );
            if (dwError)
            {
                VMDNS_LOG_ERROR("DnsCacheRefreshThread zone synchronization failed with %u.", dwError);
            }
        }
        else
        {
            VMDNS_LOG_ERROR("DnsCacheRefreshThread failed to get replication status %u.", dwError);
        }

        if (newUSN != 0)
        {
            pCacheContext->dwLastUSN = newUSN;

            dwError = VmDnsCachePurgeLRU(pCacheContext);
            if (dwError)
            {
                VMDNS_LOG_ERROR("DnsCacheRefreshThread failed to purge LRU cache with %u.", dwError);
            }
        }

wait:
        if (!pCacheContext->bShutdown)
        {
            dwError = VmDnsConditionTimedWait(
                                pCacheContext->pRefreshEvent,
                                pCacheContext->pThreadLock,
                                5 * 1000
                                );
            if (dwError != ETIMEDOUT &&
                dwError != WSAETIMEDOUT &&
                dwError != ERROR_SUCCESS)
            {
                VMDNS_LOG_ERROR("DnsCacheRefreshThread failed to wait with %u. Thread DIEING.", dwError);
                BAIL_ON_VMDNS_ERROR(dwError);
            }
        }
    }

cleanup:
    pCacheContext->bRunning = FALSE;
    return dwError;

error:
    goto cleanup;
}
Exemple #4
0
DWORD
VmDnsLdapAccessCheck(
    PCSTR szAuthPrinc,
    VMDNS_USER_TYPE userType
    )
{
    DWORD dwError = ERROR_SUCCESS;
    PVMDNS_DIR_CONTEXT pLd = NULL;
    PSTR* ppszMemberships = NULL;
    PSTR szGroupName = NULL;
    PSTR pszDomainName = NULL;
    DWORD dwMemberships = 0;

    if (IsNullOrEmptyString(szAuthPrinc) ||
        (userType != VMDNS_ADMINISTRATORS))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDNS_ERROR(dwError);
    }

    dwError = VmDnsDirConnect("localhost", &pLd);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsLdapGetMemberships(
                    pLd,
                    szAuthPrinc,
                    &ppszMemberships,
                    &dwMemberships
                    );
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsGetDefaultDomainName(pLd, &pszDomainName);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsAllocateStringPrintfA(
                &szGroupName,
                "%s,%s",
                VMDNS_ADMINISTRATORS_GROUP,
                pszDomainName);
    BAIL_ON_VMDNS_ERROR(dwError);

    VMDNS_LOG_INFO("Checking upn: %s against DNS admin group: %s ",
                    szGroupName, szAuthPrinc);

    if (!VmDnsIsMemberOf(
                    ppszMemberships,
                    dwMemberships,
                    szGroupName
                    ))
    {
        dwError = ERROR_ACCESS_DENIED;
        BAIL_ON_VMDNS_ERROR(dwError);
    }

cleanup:
    VMDNS_SAFE_FREE_STRINGA(pszDomainName);
    VMDNS_SAFE_FREE_STRINGA(szGroupName);

    if (ppszMemberships)
    {
        VmDnsFreeMemberShips(ppszMemberships, dwMemberships);
        ppszMemberships = NULL;
    }

    if (pLd)
    {
        VmDnsDirClose(pLd);
        pLd = NULL;
    }

    return dwError;
error:
    goto cleanup;
}