Exemplo n.º 1
0
static
VOID
VmAfdMoveOldDbFile(
                   VOID
                  )
{
    DWORD dwError = 0;
    PSTR pszDbPath = NULL;
    PSTR pszDbOldPath = NULL;
    BOOLEAN bOldFileExists = FALSE;
    BOOLEAN bNewFieExists = FALSE;

    dwError = VmAfdAllocateStringA(
                                    VMAFD_CERT_DB,
                                    &pszDbPath
                                  );
    BAIL_ON_VMAFD_ERROR (dwError);

    dwError = VmAfdAllocateStringA(
                                   VMAFD_OLD_CERT_DB,
                                   &pszDbOldPath
                                   );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdFileExists(pszDbOldPath,&bOldFileExists);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdFileExists(pszDbPath, &bNewFieExists);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (bOldFileExists && !bNewFieExists)
    {
        dwError = VmAfdCopyFile(pszDbOldPath, pszDbPath);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfdDeleteFile(pszDbOldPath);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

cleanup:

    VMAFD_SAFE_FREE_STRINGA(pszDbOldPath);
    VMAFD_SAFE_FREE_STRINGA(pszDbPath);
    return;

error:

    goto cleanup;
}
Exemplo n.º 2
0
static
DWORD
VmAfdGetDbPath(
                PSTR *ppszDbPath
               )
{
    DWORD dwError = 0;
    PSTR pszDbPath = NULL;

    VmAfdMoveOldDbFile();

    dwError = VmAfdAllocateStringA(
                                    VMAFD_CERT_DB,
                                    &pszDbPath
                                  );
    BAIL_ON_VMAFD_ERROR (dwError);

    *ppszDbPath = pszDbPath;

cleanup:
    return dwError;

error:
    if (ppszDbPath)
    {
        *ppszDbPath = NULL;
    }

    VMAFD_SAFE_FREE_STRINGA (pszDbPath);

    goto cleanup;
}
Exemplo n.º 3
0
static
DWORD
ReadPassword(
    PSTR* ppszPassword
    )
{
    DWORD dwError = ERROR_SUCCESS;
    struct termios orig, nonecho;
    sigset_t sig, osig;
    CHAR  szPassword[33] = "";
    PSTR  pszPassword = NULL;

    fprintf(stdout, "Password: "******"\n")] = '\0';

    if (IsNullOrEmptyString(szPassword))
    {
        dwError = ERROR_PASSWORD_RESTRICTION;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfdAllocateStringA(szPassword, &pszPassword);
    BAIL_ON_VMAFD_ERROR(dwError);

    *ppszPassword = pszPassword;

cleanup:

    tcsetattr(0, TCSANOW, &orig);
    sigprocmask(SIG_SETMASK,&osig,NULL);

    return dwError;

error:

    *ppszPassword = NULL;

    goto cleanup;
}
Exemplo n.º 4
0
static
DWORD
VmAfdCliLeaveVmDir(
    PVM_AFD_CLI_CONTEXT pContext
    )
{
    DWORD dwError = 0;
    PSTR pszAccount = NULL;
    PSTR pszPassword = NULL;

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

    if (!pContext->pszUserName || !pContext->pszPassword)
    {
        dwError = VmAfdGetMachineAccountInfoA(NULL, &pszAccount, &pszPassword);
    } else
    {
        dwError = VmAfdAllocateStringA(pContext->pszUserName, &pszAccount);
        BAIL_ON_VMAFD_ERROR(dwError);
        dwError = VmAfdAllocateStringA(pContext->pszPassword, &pszPassword);
    }
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdLeaveVmDirA(pContext->pszServerName, pszAccount, pszPassword, 0);
    BAIL_ON_VMAFD_ERROR(dwError);

cleanup:
    VMAFD_SAFE_FREE_MEMORY(pszAccount);
    VMAFD_SAFE_FREE_MEMORY(pszPassword);
    return dwError;

error:

    goto cleanup;
}
Exemplo n.º 5
0
DWORD
VmAfWinCfgReadStringValue(
    PVMAF_CFG_KEY       pKey,
    PCSTR               pszSubkey,
    PCSTR               pszName,
    PSTR*               ppszValue
    )
{
    DWORD dwError = 0;
    CHAR  szValue[VMAF_MAX_CONFIG_VALUE_BYTE_LENGTH] = {0};
    DWORD dwszValueSize = sizeof(szValue);
    PSTR  pszValue = NULL;

    dwError = RegGetValueA(
                    pKey->hKey,
                    pszSubkey,
                    pszName,
                    RRF_RT_REG_SZ,
                    NULL,
                    szValue,
                    &dwszValueSize);
    BAIL_ON_VMAFD_ERROR_NO_LOG(dwError);

    dwError = VmAfdAllocateStringA(szValue, &pszValue);
    BAIL_ON_VMAFD_ERROR(dwError);

    *ppszValue = pszValue;

cleanup:

    return dwError;

error:

    *ppszValue = NULL;

    if (pszValue)
    {
        VmAfdFreeStringA(pszValue);
    }

    goto cleanup;
}
Exemplo n.º 6
0
DWORD
VecsDbInitialize(
    PCSTR pszDbPath
    )
{
    DWORD dwError = 0;

    if (IsNullOrEmptyString(pszDbPath))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VECS_ERROR(dwError);
    }

    dwError = VecsDbDatabaseInitialize(pszDbPath);
    BAIL_ON_VECS_ERROR(dwError);

    dwError = VmAfdAllocateStringA(pszDbPath, &gVecsDbGlobals.pszDbPath);
    BAIL_ON_VECS_ERROR(dwError);

error:

    return dwError;
}
Exemplo n.º 7
0
static
DWORD
_VmAfdJsonResultPasswordCB(
    PVOID pUserData,
    PCSTR pszKey,
    PVM_JSON_RESULT_VALUE pValue
    )
{
    DWORD dwError = 0;
    PSTR *ppszPassword = NULL;
    PSTR pszPassword = NULL;

    if (!pUserData || !pszKey || !pValue)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    if (!VmAfdStringCompareA("password", pszKey, TRUE))
    {
        if (pValue->nType == JSON_RESULT_STRING)
        {
            dwError = VmAfdAllocateStringA(pValue->value.pszValue, &pszPassword);
            BAIL_ON_VMAFD_ERROR(dwError);

            ppszPassword = (PSTR *)pUserData;
            *ppszPassword = pszPassword;
        }
    }

cleanup:
    return dwError;

error:
    VMAFD_SAFE_FREE_MEMORY(pszPassword);
    goto cleanup;
}
Exemplo n.º 8
0
static
DWORD
VmAfdCliBeginOrEndUpgrade(
    PVM_AFD_CLI_CONTEXT pContext
    )
{
    DWORD dwError = 0;
    PSTR pszAccount = NULL;
    PSTR pszPassword = NULL;
    PSTR pszDomainName = NULL;
    BOOL bUsingIPC = FALSE;
    PVMAFD_SERVER pServer = NULL;

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

    dwError = VmAfdGetDomainNameA(NULL,&pszDomainName);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (IsNullOrEmptyString(pContext->pszServerName))
    {
        bUsingIPC = TRUE;
    }

    if (bUsingIPC && !IsNullOrEmptyString(pContext->pszUserName))
    {
        printf ("Getting heartbeat status of local system\n"
                "lightwave user-name will not be used\n"
               );
    }

    if (!bUsingIPC)
    {
      //Factor domain name as well into this equation
        if(IsNullOrEmptyString(pContext->pszUserName))
        {
            dwError = VmAfdGetMachineAccountInfoA(NULL, &pszAccount, &pszPassword);
        }
        else
        {
            if (VmAfdCaselessStrStrA(pContext->pszUserName, "@"))
            {
                dwError = VmAfdAllocateStringA(pContext->pszUserName, &pszAccount);
            }
            else
            {
                dwError = VmAfdAllocateStringPrintf(
                                                  &pszAccount,
                                                  "%s@%s",
                                                  pContext->pszUserName,
                                                  pszDomainName
                                                  );
            }
            BAIL_ON_VMAFD_ERROR(dwError);

            if (IsNullOrEmptyString(pContext->pszPassword))
            {
                dwError = GetPassword(&pszPassword);
            }
            else
            {
                dwError = VmAfdAllocateStringA(pContext->pszPassword, &pszPassword);
            }
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdOpenServerA(
                          pContext->pszServerName,
                          pszAccount,
                          pszPassword,
                          &pServer
                          );
    BAIL_ON_VMAFD_ERROR(dwError);

    if (pContext->action == VM_AFD_ACTION_BEGIN_UPGRADE)
    {
        dwError = VmAfdBeginUpgrade(pServer);
        BAIL_ON_VMAFD_ERROR(dwError);
        printf ("Begin upgrade state is set\n");
    }
    else if (pContext->action == VM_AFD_ACTION_END_UPGRADE)
    {
        dwError = VmAfdEndUpgrade(pServer);
        BAIL_ON_VMAFD_ERROR(dwError);
        printf ("End upgrade state is set\n");
    }

cleanup:
    VMAFD_SAFE_FREE_MEMORY(pszAccount);
    VMAFD_SAFE_FREE_MEMORY(pszPassword);
    VMAFD_SAFE_FREE_MEMORY(pszDomainName);
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }
    return dwError;

error:

    goto cleanup;
}
Exemplo n.º 9
0
static
DWORD
VmAfdCliGetHeartbeatStatus(
    PVM_AFD_CLI_CONTEXT pContext
    )
{
    DWORD dwError = 0;
    PSTR pszAccount = NULL;
    PSTR pszPassword = NULL;
    PSTR pszDomainName = NULL;
    BOOL bUsingIPC = FALSE;
    PVMAFD_HB_STATUS_A pHeartbeatStatus = NULL;
    PVMAFD_SERVER pServer = NULL;

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

    if (IsNullOrEmptyString(pContext->pszServerName))
    {
        bUsingIPC = TRUE;
    }

    if (bUsingIPC && !IsNullOrEmptyString(pContext->pszUserName))
    {
        printf ("Getting heartbeat status of local system\n"
                "lotus user-name will not be used\n"
               );
    }

    if (!bUsingIPC)
    {
      //Factor domain name as well into this equation
        if(!pContext->pszUserName)
        {
            dwError = VmAfdGetMachineAccountInfoA(NULL, &pszAccount, &pszPassword);
        }
        else if (pContext->pszUserName && pContext->pszPassword)
        {
            dwError = VmAfdAllocateStringA(pContext->pszUserName, &pszAccount);
            BAIL_ON_VMAFD_ERROR(dwError);
            dwError = VmAfdAllocateStringA(pContext->pszPassword, &pszPassword);
        }
        else if (pContext->pszUserName && !pContext->pszPassword)
        {
            //getPassword
        }
    }
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdOpenServerA(
                          pContext->pszServerName,
                          pszAccount,
                          pszPassword,
                          &pServer
                          );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdGetHeartbeatStatusA(
                                  pServer,
                                  &pHeartbeatStatus
                                  );
    BAIL_ON_VMAFD_ERROR(dwError);

    printf ("Current Status of the machine is :\t%d\n",pHeartbeatStatus->bIsAlive);

cleanup:
    VMAFD_SAFE_FREE_MEMORY(pszAccount);
    VMAFD_SAFE_FREE_MEMORY(pszPassword);
    VMAFD_SAFE_FREE_MEMORY(pszDomainName);
    return dwError;

error:

    goto cleanup;

}
Exemplo n.º 10
0
DWORD
VmAfWinCfgEnumKeys(
    PVMAF_CFG_CONNECTION pConnection,
    PVMAF_CFG_KEY        pKey,
    PSTR                 **pppszKeyNames,
    PDWORD                pdwKeyNameCount
    )
{
    DWORD dwError = 0;
    DWORD dwIndex = 0;
    DWORD dwCount = 0;
    PSTR  pszKeyName = NULL;
    PSTR  *ppszKeyNames = NULL;
    DWORD dwKeyNameSize = 0;


    while(1)
    {
        dwKeyNameSize = VMAF_REG_KEY_NAME_MAX_LENGTH;
        dwError = VmAfdAllocateMemory(
                                 dwKeyNameSize,
                                 (PVOID *)&pszKeyName
                                 );
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = RegEnumKeyExA(
                      (pKey ? pKey->hKey : NULL),
                      dwCount,
                      pszKeyName,
                      &dwKeyNameSize,
                      NULL,
                      NULL,
                      NULL,
                      NULL
                      );
        if (dwError == ERROR_NO_MORE_ITEMS)
        {
            dwError = 0;
            break;
        }
        BAIL_ON_VMAFD_ERROR(dwError);
        dwCount++;
        VMAFD_SAFE_FREE_MEMORY(pszKeyName);
    }

    if (dwCount)
    {

        dwError = VmAfdAllocateMemory(
                            sizeof(PSTR)*dwCount,
                            (PVOID *)&ppszKeyNames
                            );

        BAIL_ON_VMAFD_ERROR(dwError);
    }

    for (; dwIndex < dwCount; ++dwIndex)
    {
        dwKeyNameSize = VMAF_REG_KEY_NAME_MAX_LENGTH;
        dwError = VmAfdAllocateMemory(
                                dwKeyNameSize,
                                (PVOID *)&pszKeyName
                                );
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError  = RegEnumKeyExA(
                      (pKey ? pKey->hKey : NULL),
                      dwIndex,
                      pszKeyName,
                      &dwKeyNameSize,
                      NULL,
                      NULL,
                      NULL,
                      NULL
                      );
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfdAllocateStringA(
                                pszKeyName,
                                &ppszKeyNames[dwIndex]
                                );
        BAIL_ON_VMAFD_ERROR(dwError);
        VMAFD_SAFE_FREE_MEMORY(pszKeyName);
    }

    *pppszKeyNames = ppszKeyNames;
    *pdwKeyNameCount = dwCount;

cleanup:

    VMAFD_SAFE_FREE_MEMORY(pszKeyName);
    return dwError;

error:

    if (pppszKeyNames)
    {
        *pppszKeyNames = NULL;
    }
    if (pdwKeyNameCount)
    {
        *pdwKeyNameCount = 0;
    }
    if (ppszKeyNames)
    {
        VmAfdFreeStringArrayA(ppszKeyNames);
    }
    goto cleanup;
}
Exemplo n.º 11
0
int main(int argc, char* argv[])
{
    DWORD   dwError = 0;
    int    retCode = 0;
    PSTR   pszDomain = NULL;
    PSTR   pszDomainName = NULL;
    PSTR   pszUserName = NULL;
    PSTR   pszPassword = NULL;
    PSTR   pszPwdFile = NULL;
    PSTR   pszSiteName = NULL;
    PSTR   pszPartnerHostName = NULL;
    PSTR   pszLotusServerName = NULL;
    PSTR   pszPasswordBuf = NULL;
    FILE * fpPwdFile = NULL;
    PSTR   pszPath = NULL;
    PSTR   pszLogPathName = NULL;
    size_t dPwdLen = 0;
    BOOL   bLogInitialized = FALSE;
    PCSTR  pszErrorMsg = NULL;
    PSTR   pszErrorDesc = NULL;
    PCSTR  pszLocalhost = "localhost";
    PSTR   pszPnid = NULL;
    DNS_INIT_FLAG dnsInitFlag = DNS_NONE;
#ifdef _WIN32
    WSADATA wsaData = { 0 };
    BOOLEAN bWsaStartup = FALSE;
#endif

#ifndef _WIN32
    setlocale(LC_ALL, "");
#else
    dwError = WSAStartup(MAKEWORD(2, 2), &wsaData);
    BAIL_ON_VMAFD_ERROR(dwError);
    bWsaStartup = TRUE;
#endif

    dwError = VmAfCfgInit();
    BAIL_ON_VMAFD_ERROR(dwError);

#ifndef _WIN32
    dwError = VmAfdAllocateStringA(VMAFD_LOG_PATH, &pszLogPathName );
    BAIL_ON_VMAFD_ERROR(dwError);
#else
    dwError = VmAfdConfigGetString(VMAFD_SOFTWARE_KEY_PATH, VMAFD_LOGPATH_KEY_VALUE, &pszLogPathName);
    BAIL_ON_VMAFD_ERROR(dwError);
#endif

    dwError = VmAfdAllocateStringAVsnprintf( &pszPath, "%s%s", pszLogPathName, "vdcpromo.log"  );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdLogInitialize(pszPath, 0, 0);
    BAIL_ON_VMAFD_ERROR(dwError);
    bLogInitialized = TRUE;

    dwError = VmAfdParseArgs(argc,
                             argv,
                             &pszDomain,
                             &pszUserName,
                             &pszPassword,
                             &pszSiteName,
                             &pszPartnerHostName,
                             &pszLotusServerName,
                             &pszPwdFile,
                             &dnsInitFlag);
    if (dwError)
    {
        ShowUsage();
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    if (IsNullOrEmptyString(pszUserName))
    {
        VmAfdLog(VMAFD_DEBUG_ANY, "Username parameter is not valid");
    }
    else
    {
        VmAfdLog(VMAFD_DEBUG_ANY, "Username: \"%s\"", pszUserName);
    }

    if (!pszPwdFile && IsNullOrEmptyString(pszPassword))
    {
        VmAfdLog(VMAFD_DEBUG_ANY, "Password parameter is not valid");
    }

    if (IsNullOrEmptyString(pszDomain))
    {
        VmAfdLog(VMAFD_DEBUG_ANY, "Domain parameter is not valid");
    }
    else
    {
        VmAfdLog(VMAFD_DEBUG_ANY, "Domain: \"%s\"", pszDomain);
    }

    dwError = VmAfdAllocateMemory(VMAFD_MAX_PWD_LEN+1, (PVOID *)&pszPasswordBuf);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (pszPassword == NULL && pszPwdFile != NULL)
    {
        dwError = VmAfdOpenFilePath(pszPwdFile, "rb", &fpPwdFile);
        if (dwError != ERROR_SUCCESS)
        {
            printf("vdcpromo: cannot open password file %s (%u)\n", pszPwdFile, dwError);
            dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN;
            BAIL_ON_VMAFD_ERROR(dwError);
        }
        if ( (dPwdLen = fread(pszPasswordBuf, 1, VMAFD_MAX_PWD_LEN, fpPwdFile)) == 0)
        {
            dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_READ;
            printf("vdcpromo: Could not read password file\n");
            BAIL_ON_VMAFD_ERROR(dwError);
        }
        if (*pszPasswordBuf == '\0')
        {
            VmAfdLog(VMAFD_DEBUG_ANY, "password is empty");
            dwError = ERROR_LOCAL_PASSWORD_EMPTY;
            BAIL_ON_VMAFD_ERROR(dwError);
        }
    }
    else if (pszPassword != NULL && pszPwdFile == NULL)
    {
        dwError = VmAfdStringCpyA(pszPasswordBuf, VMAFD_MAX_PWD_LEN, pszPassword);
        BAIL_ON_VMAFD_ERROR(dwError);
    } else //no password nor password-file, read password from stdin
    {
        VmAfdReadString("password: "******"Warning: failed to initialize DNS. Error [%d]\n", dwError);
        }
        else
        {
            fprintf(stdout, "Successfully initialized DNS.\n");
        }
        BAIL_ON_VMAFD_ERROR(dwError);

        goto cleanup;
    }

    printf("Initializing Directory server instance ... \n");
    fflush(stdout);

    dwError = VmAfdPromoteVmDirA(
                  pszLotusServerName ? pszLotusServerName : pszLocalhost,
                  pszDomain,
                  pszUserName,
                  pszPasswordBuf,
                  pszSiteName,
                  pszPartnerHostName);
    BAIL_ON_VMAFD_ERROR(dwError);

    printf("Directory host instance created successfully\n");

cleanup:

    VmAfCfgShutdown();

    if (bLogInitialized)
    {
        VmAfdLogTerminate();
    }

#ifdef _WIN32
    if (bWsaStartup != FALSE)
    {
        WSACleanup();
    }
#endif
    VMAFD_SAFE_FREE_MEMORY(pszPnid);
    VMAFD_SAFE_FREE_MEMORY(pszPasswordBuf);
    VMAFD_SAFE_FREE_MEMORY(pszPath);
    VMAFD_SAFE_FREE_MEMORY(pszLogPathName);
    VMAFD_SAFE_FREE_MEMORY(pszErrorDesc);
    VMAFD_SAFE_FREE_MEMORY(pszDomainName);
    return retCode;

error:

    switch (dwError)
    {
    case ERROR_LOCAL_OPTION_UNKNOWN:
        retCode = 2;
        pszErrorMsg = "An unknown option was present on the command line.";
        break;
    case ERROR_LOCAL_OPTION_INVALID:
        retCode = 3;
        pszErrorMsg = "The options present on the command line are not valid.";
        break;
    case ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN:
        retCode = 4;
        pszErrorMsg = "Could not open password file.\nVerify the path is correct.";
        break;
    case ERROR_LOCAL_PASSWORDFILE_CANNOT_READ:
        retCode = 5;
        pszErrorMsg = "Problem reading password file.\nVerify contents of password file.";
        break;
    case ERROR_LOCAL_PASSWORD_EMPTY:
        retCode = 6;
        pszErrorMsg = "Invalid password; password cannot be empty.";
        break;
    case ERROR_CANNOT_CONNECT_VMAFD:
        retCode = 20;
        pszErrorMsg = "Could not connect to the local service VMware AFD.\nVerify VMware AFD is running.";
        break;
    case VMDIR_ERROR_CANNOT_CONNECT_VMDIR:
        retCode = 21;
        pszErrorMsg = "Could not connect to the local service VMware Directory Service.\nVerify VMware Directory Service is running.";
        break;
    case ERROR_INVALID_CONFIGURATION:
        retCode = 22;
        pszErrorMsg = "Configuration is not correct.\nFirst boot scripts need to be executed.";
        break;
    case VMDIR_ERROR_SERVER_DOWN:
        retCode = 23;
        pszErrorMsg = "Could not connect to VMware Directory Service via LDAP.\nVerify VMware Directory Service is running on the appropriate system and is reachable from this host.";
        break;
    case VMDIR_ERROR_USER_INVALID_CREDENTIAL:
        retCode = 24;
        pszErrorMsg = "Authentication to VMware Directory Service failed.\nVerify the username and password.";
        break;
    case ERROR_ACCESS_DENIED:
        retCode = 25;
        pszErrorMsg = "Authorization failed.\nVerify account has proper administrative privileges.";
        break;
    case VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE:
        retCode = 26;
        pszErrorMsg = "Could not join to the remote service VMWare Directory Service.\nThe remote schema is incompatible with the local schema.";
        break;
    default:
        retCode = 1;
    }

    if (bLogInitialized)
    {
        if (pszErrorMsg == NULL)
        {
            VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]", dwError);
        }
        else
        {
            VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]\n%s", dwError, pszErrorMsg);
        }
    }

    if (pszErrorMsg == NULL)
    {
        if (!VmAfdGetErrorString(dwError, &pszErrorDesc))
        {
            printf("Vdcpromo failed. Error %d: %s\n", dwError, pszErrorDesc);
        }
        else
        {
            printf("Vdcpromo failed. Error %d.\n", dwError);
        }
    }
    else
    {
        printf("Vdcpromo failed. Error[%d]\n%s\n", dwError, pszErrorMsg);
    }

    goto cleanup;
}
Exemplo n.º 12
0
static
DWORD
VmAfSrvCheckDC(
    PDNS_SERVER_INFO pServerInfo,
    PCSTR pszDomain,
    PCSTR pszUPN,
    PCSTR pszPassword,
    PSTR* ppszHostname,
    PSTR* ppszNetworkAddress
    )
{
    DWORD dwError = 0;
    PSTR  pszHostname = NULL;
    PSTR  pszNetworkAddress = NULL;
    PSTR  pszDomainOther = NULL;
    LDAP* pLd = NULL;

    dwError = VmAfdLDAPConnect(
                    pServerInfo->pszAddress,
                    0,
                    pszUPN,
                    pszPassword,
                    &pLd);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdGetDefaultDomainName(pLd, &pszDomainOther);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (VmAfdStringCompareA(pszDomain, pszDomainOther, FALSE) != 0)
    {
        dwError = ERROR_DC_NOT_FOUND;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfdAllocateStringA(pServerInfo->pszName, &pszHostname);
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdAllocateStringA(pServerInfo->pszAddress, &pszNetworkAddress);
    BAIL_ON_VMAFD_ERROR(dwError);

    *ppszHostname = pszHostname;
    *ppszNetworkAddress = pszNetworkAddress;

cleanup:

    if (pLd)
    {
        VmAfdLdapClose(pLd);
    }

    VMAFD_SAFE_FREE_MEMORY(pszDomainOther);

    return dwError;

error:

    *ppszNetworkAddress = NULL;
    *ppszHostname = NULL;

    VMAFD_SAFE_FREE_MEMORY(pszHostname);
    VMAFD_SAFE_FREE_MEMORY(pszNetworkAddress);

    goto cleanup;
}
Exemplo n.º 13
0
/*
 * If pszServerName is in IP format, use it as Lotus Server Name.
 * If pszServerName is NOT "localhost" which means caller specify a name they prefer, use it as the Lotus Server Name.
 *
 * Otherwise, derive FQDN based on existing network naming configuration.
 *   i.e. Call gethostname then perform forward+reverse lookup to derive the FQDN as Lotus Server Name.
 *        The forward+reverse look up is for kerberos naming consistency between server (Lotus) and clients, which
 *        could be Lotus or open sources, e.g. openldap.
 *        However, this auto name resolution is error-prone as system could have multiple IF(s) defined and
 *        we have no idea which IF we should pick to perform reverse lookup.
 *        Thus, the best chance to get Kerberos working is - customer provides proper FQDN as Lotus Server Name.
 */
static
DWORD
VmAfSrvGetLotusServerName(
    PCSTR   pszServerName,
    PSTR*   ppOutServerName
)
{
    DWORD dwError = 0;
    PSTR  pszHostnameCanon = NULL;
    PSTR  pszLocalHostName = NULL;
    PSTR  pszFQDN = NULL;

    if ( !pszServerName || !ppOutServerName )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    if ( VmAfdStringCompareA( pszServerName, "localhost", FALSE ) != 0 )
    {   // caller provides preferred Lotus Server Name or IP
        dwError = VmAfdAllocateStringA( pszServerName, &pszHostnameCanon );
        BAIL_ON_VMAFD_ERROR(dwError);
    }
    else
    {   // caller does NOT specify preferred Lotus Server Name, derives it ourselves.
        dwError = VmAfdGetHostName(&pszLocalHostName);
        BAIL_ON_VMAFD_ERROR(dwError);

        dwError = VmAfdGetCanonicalHostName(pszLocalHostName, &pszHostnameCanon);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    BAIL_ON_VMAFD_EMPTY_STRING(pszHostnameCanon, dwError);

    if (!VmAfdCheckIfIPV4AddressA(pszHostnameCanon) &&
            !VmAfdCheckIfIPV6AddressA(pszHostnameCanon) &&
            pszHostnameCanon[VmAfdStringLenA(pszHostnameCanon) - 1] != '.')
    {
        dwError = VmAfdAllocateStringPrintf(
                      &pszFQDN,
                      "%s.",
                      pszHostnameCanon);
        BAIL_ON_VMAFD_ERROR(dwError);
    }
    else
    {
        pszFQDN = pszHostnameCanon;
        pszHostnameCanon = NULL;
    }

    *ppOutServerName = pszFQDN;

    VmAfdLog(VMAFD_DEBUG_ANY, "Lotus server name: (%s)", *ppOutServerName);

cleanup:
    VMAFD_SAFE_FREE_MEMORY(pszHostnameCanon);
    return dwError;

error:
    VMAFD_SAFE_FREE_MEMORY(pszFQDN);
    VmAfdLog(VMAFD_DEBUG_ANY, "%s failed (%s). Error(%u)",
             __FUNCTION__, pszServerName, dwError);
    goto cleanup;
}
Exemplo n.º 14
0
DWORD
VmAfdGetDSERootAttribute(
    LDAP* pLotus,
    PSTR  pszAttribute,
    PSTR* ppAttrValue
    )
{
    DWORD dwError = 0; // LDAP_SUCCESS
    PCHAR pDcFilter = "(objectClass=*)";
    PCHAR pDcAttr[] = { pszAttribute, NULL };
    PSTR pAttribute = NULL;
    BerElement* pBer = NULL;
    BerValue** ppValue = NULL;
    LDAPMessage* pSearchResult = NULL;
    LDAPMessage* pResults = NULL;

    dwError = ldap_search_ext_s(
                  pLotus,
                  "",
                  LDAP_SCOPE_BASE,
                  pDcFilter,
                  pDcAttr,
                  0,
                  NULL,
                  NULL,
                  NULL,
                  0,
                  &pSearchResult);
    BAIL_ON_VMAFD_ERROR(dwError);

    if (ldap_count_entries(pLotus, pSearchResult) != 1)
    {
        dwError = ERROR_INVALID_STATE;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    pResults = ldap_first_entry(pLotus, pSearchResult);
    if (pResults == NULL)
    {
        ldap_get_option(pLotus, LDAP_OPT_ERROR_NUMBER, &dwError);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    pAttribute = ldap_first_attribute(pLotus,pResults,&pBer);
    if (pAttribute == NULL)
    {
        ldap_get_option(pLotus, LDAP_OPT_ERROR_NUMBER, &dwError);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    ppValue = ldap_get_values_len(pLotus, pResults, pAttribute);
    if (ppValue == NULL)
    {
        ldap_get_option(pLotus, LDAP_OPT_ERROR_NUMBER, &dwError);
        BAIL_ON_VMAFD_ERROR(dwError);
    }

    dwError = VmAfdAllocateStringA(ppValue[0]->bv_val, ppAttrValue);
    BAIL_ON_VMAFD_ERROR(dwError);

cleanup:

    if (ppValue != NULL)
    {
        ldap_value_free_len(ppValue);
    }
    if (pAttribute != NULL)
    {
        ldap_memfree(pAttribute);
    }
    if (pBer != NULL)
    {
        ber_free(pBer,0);
    }
    if (pSearchResult != NULL)
    {
        ldap_msgfree(pSearchResult);
    }

    return dwError;

error:

    *ppAttrValue = NULL;

    goto cleanup;
}