示例#1
0
static
DWORD
CdcHandleNoDCList(
    VOID
    )
{
    DWORD dwError = 0;
    PWSTR pszDCName = NULL;
    DWORD dwPingResult = 0;
    PWSTR pszSiteName = NULL;
    time_t timeTaken = 0;

    dwError = VmAfSrvGetDCName(&pszDCName);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdTrimFQDNTrailingDot(pszDCName);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = CdcDCPing(
                    pszDCName,
                    NULL,
                    &dwPingResult,
                    &timeTaken,
                    &pszSiteName
                    );
    BAIL_ON_VMAFD_ERROR(dwError);

    if (!dwPingResult)
    {
        dwError = CdcUpdateCache(TRUE);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = CdcUpdateAffinitizedDC(pszDCName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = CdcSetClientSiteName(pszSiteName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = CdcStateTransition(CDC_DC_STATE_SITE_AFFINITIZED);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

cleanup:

    VMAFD_SAFE_FREE_MEMORY(pszDCName);
    return dwError;
error:
    goto cleanup;
}
示例#2
0
static
DWORD
CdcGetDomainControllers(
      PWSTR** ppszDomainControllers,
      PDWORD pdwCount
      )
{
      DWORD dwError       = 0;
      DWORD dwIndex       = 0;
      PWSTR pwszDomain    = NULL;
      PSTR  pszDomain     = NULL;
      PSTR  pszDCName     = NULL;

      PWSTR pwszAccount   = NULL;
      PSTR  pszAccount    = NULL;
      PWSTR pwszPassword  = NULL;
      PSTR  pszPassword   = NULL;
      PWSTR pwszAccountDN = NULL;
      PSTR  pszAccountDN  = NULL;
      PVMDNS_SERVER_CONTEXT pConnection  = NULL;
      PVMDNS_RECORD_ARRAY   pRecordArray = NULL;
      PWSTR* pszDomainControllers        = NULL;
      PCDC_DC_INFO_W pAffinitizedDC      = NULL;

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

      dwError = VmAfSrvGetMachineAccountInfo(
                            &pwszAccount,
                            &pwszPassword,
                            &pwszAccountDN,
                            NULL
                            );
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = VmAfdAllocateStringAFromW(
                                   pwszAccount,
                                   &pszAccount
                                   );
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = VmAfdAllocateStringAFromW(
                                  pwszPassword,
                                  &pszPassword
                                  );
      BAIL_ON_VMAFD_ERROR(dwError);

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

      dwError = VmAfdAllocateStringAFromW(
                                pwszDomain,
                                &pszDomain
                                );
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = CdcSrvGetDCName(pwszDomain,&pAffinitizedDC);
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = VmAfdAllocateStringAFromW(
                                pAffinitizedDC->pszDCName,
                                &pszDCName
                                );
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = VmDnsOpenServerA(
                          pszDCName,
                          pszAccount,
                          pszDomain,
                          pszPassword,
                          0,
                          NULL,
                          &pConnection);
      BAIL_ON_VMAFD_ERROR(dwError);

      dwError = VmDnsQueryRecordsA(
                          pConnection,
                          pszDomain,
                          "_ldap._tcp",
                          VMDNS_RR_TYPE_SRV,
                          0,
                          &pRecordArray);
      BAIL_ON_VMAFD_ERROR(dwError);

      if (pRecordArray->dwCount)
      {
          dwError = VmAfdAllocateMemory(
                            sizeof(PWSTR)*pRecordArray->dwCount,
                            (PVOID *)&pszDomainControllers
                            );
          BAIL_ON_VMAFD_ERROR(dwError);
      }

      for (; dwIndex < pRecordArray->dwCount; dwIndex++)
      {
          dwError = VmAfdAllocateStringWFromA(
                                  pRecordArray->Records[dwIndex].Data.SRV.pNameTarget,
                                  &pszDomainControllers[dwIndex]
                                  );
          BAIL_ON_VMAFD_ERROR(dwError);

          dwError = VmAfdTrimFQDNTrailingDot(pszDomainControllers[dwIndex]);
          BAIL_ON_VMAFD_ERROR(dwError);
      }

      dwIndex = 0;

      *ppszDomainControllers = pszDomainControllers;
      *pdwCount = pRecordArray->dwCount;

cleanup:
      VMAFD_SAFE_FREE_MEMORY(pwszDomain);
      VMAFD_SAFE_FREE_MEMORY(pszDomain);
      VMAFD_SAFE_FREE_MEMORY(pszDCName);
      VMAFD_SAFE_FREE_MEMORY(pwszAccount);
      VMAFD_SAFE_FREE_MEMORY(pszAccount);
      VMAFD_SAFE_FREE_MEMORY(pwszPassword);
      VMAFD_SAFE_FREE_MEMORY(pszPassword);
      VMAFD_SAFE_FREE_MEMORY(pwszAccountDN);
      VMAFD_SAFE_FREE_MEMORY(pszAccountDN);

      if (pAffinitizedDC)
      {
          VmAfdFreeDomainControllerInfoW(pAffinitizedDC);
      }
      if (pRecordArray)
      {
          VmDnsFreeRecordArray(pRecordArray);
      }
      if (pConnection)
      {
          VmDnsCloseServer(pConnection);
      }

      return dwError;

error:

      if (ppszDomainControllers)
      {
          *ppszDomainControllers = NULL;
      }
      if (pszDomainControllers)
      {
          VmAfdFreeStringArrayW(pszDomainControllers,pRecordArray->dwCount);
      }

      goto cleanup;
}
示例#3
0
DWORD
CdcSrvGetDCName(
    PCWSTR pszDomainName,
    PCDC_DC_INFO_W *ppAffinitizedDC
    )
{
    DWORD dwError = 0;
    PCDC_DC_INFO_W pAffinitizedDC = NULL;
    PCDC_DC_INFO_W pAffinitizedDCToFree = NULL;
    DWORD dwAffinitizedSince = 0;
    CDC_DB_ENUM_HA_MODE cdcHAMode = CDC_DB_ENUM_HA_MODE_UNDEFINED;
    PWSTR pszDomainToUse = NULL;
    UINT64 iStart = 0;
    UINT64 iEnd = 0;

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

    iStart = VmAfdGetTimeInMilliSec();
    dwError = VmAfSrvGetDomainName(&pszDomainToUse);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (!IsNullOrEmptyString(pszDomainName))
    {
        if (!VmAfdStringIsEqualW(
                            pszDomainName,
                            pszDomainToUse,
                            FALSE
                            )
           )
        {
            dwError = ERROR_INVALID_DOMAINNAME;
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }

    dwError = CdcRegDbGetHAMode(&cdcHAMode);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = CdcDbGetAffinitizedDC(
                          pszDomainToUse,
                          &dwAffinitizedSince,
                          &pAffinitizedDC
                          );
    if (cdcHAMode == CDC_DB_ENUM_HA_MODE_LEGACY || dwError)
    {
        pAffinitizedDCToFree = pAffinitizedDC;
        dwError = VmAfdAllocateMemory(
                                sizeof(CDC_DC_INFO_W),
                                (PVOID *)&pAffinitizedDC
                                );
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfSrvGetDCName(&pAffinitizedDC->pszDCName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfdTrimFQDNTrailingDot(pAffinitizedDC->pszDCName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfSrvGetDomainName(&pAffinitizedDC->pszDomainName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = CdcRegDbGetSiteName(&pAffinitizedDC->pszDcSiteName);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    iEnd = VmAfdGetTimeInMilliSec();
    *ppAffinitizedDC = pAffinitizedDC;

cleanup:

    VMAFD_SAFE_FREE_MEMORY(pszDomainToUse);
    if (pAffinitizedDCToFree)
    {
        VmAfdFreeDomainControllerInfoW(pAffinitizedDCToFree);
    }
    return dwError;
error:

    (DWORD)VmAfdAddDCSuperLogEntry(
                            gVmafdGlobals.pLogger,
                            iStart,
                            iEnd,
                            pAffinitizedDC,
                            dwError);

    if (ppAffinitizedDC)
    {
        *ppAffinitizedDC = NULL;
    }
    if (pAffinitizedDC)
    {
        VmAfdFreeDomainControllerInfoW(pAffinitizedDC);
    }

    goto cleanup;
}