示例#1
0
void client::DisableClientAffinity()
{
    DWORD dwError = 0;

    //This code would eventually move out of here
    //when other APIs become remotable

    PVMAFD_SERVER pServer = NULL;

    dwError = VmAfdOpenServerA(NULL,NULL,NULL,&pServer);
    BAIL_ON_ERROR(dwError);

    dwError = CdcDisableClientAffinity(pServer);
    BAIL_ON_ERROR(dwError);

cleanup:
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    return;

error:
    THROW_IF_NEEDED(dwError);
    goto cleanup;
}
示例#2
0
JNIEXPORT jint JNICALL
Java_com_vmware_identity_cdc_CdcAdapter_VmAfdCloseServer(
        JNIEnv  *env,
        jclass  clazz,
        jobject jpServer
        )
{
    DWORD dwError = 0;
    PVMAFD_SERVER pServer = NULL;

    if (jpServer == NULL) 
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_ERROR(dwError);
    }

    dwError = JniGetPointer(env, jpServer, (PVOID*)&pServer);
    BAIL_ON_ERROR(dwError);

    VmAfdCloseServer(pServer);
    pServer = NULL;

    dwError = JniSetPointer(env, jpServer, (PVOID)pServer);
    BAIL_ON_ERROR(dwError);

cleanup:
    return dwError;

error:
    goto cleanup;
}
示例#3
0
std::string client::GetCdcState()
{
    CDC_DC_STATE cdcState = CDC_DC_STATE_UNDEFINED;
    DWORD dwError = 0;
    std::string result;
    //This code would eventually move out of here
    //when other APIs become remotable
    PVMAFD_SERVER pServer = NULL;

    dwError = VmAfdOpenServerA(NULL,NULL,NULL,&pServer);
    BAIL_ON_ERROR(dwError);


    dwError = CdcGetCurrentState(pServer, &cdcState);
    BAIL_ON_ERROR(dwError);

    switch (cdcState)
    {
      case CDC_DC_STATE_NO_DC_LIST:
        result.assign("NO_DC_LIST");
        break;
      case CDC_DC_STATE_SITE_AFFINITIZED:
        result.assign("SITE_AFFINITIZED");
        break;
      case CDC_DC_STATE_OFF_SITE:
        result.assign("OFF_SITE");
        break;
      case CDC_DC_STATE_NO_DCS_ALIVE:
        result.assign("NO_DCS_ALIVE");
        break;
      case CDC_DC_STATE_LEGACY:
        result.assign("DISABLED");
        break;
      default:
        result.assign("UNKNOWN");
        break;
    }

cleanup:
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    return result;

error:
    THROW_IF_NEEDED(dwError);
    goto cleanup;
}
示例#4
0
bpl::list client::EnumDCEntries()
{
    DWORD dwError = 0;
    bpl::list result;
    DWORD dwCount = 0;
    DWORD dwIndex = 0;
    PSTR pszDCEntry = NULL;
    PSTR *ppszDCEntries = NULL;
    //This code would eventually move out of here
    //when other APIs become remotable
    PVMAFD_SERVER pServer = NULL;

    dwError = VmAfdOpenServerA(NULL,NULL,NULL,&pServer);
    BAIL_ON_ERROR(dwError);

    dwError = CdcEnumDCEntriesA(
                            pServer,
                            &ppszDCEntries,
                            &dwCount);
    if (dwError == 0 && dwCount > 0)
    {
        for (dwIndex=0; dwIndex<dwCount; dwIndex++)
        {
            if (ppszDCEntries[dwIndex])
            {
                std::string st(ppszDCEntries[dwIndex]);
                result.append(st);
            }
        }
    }
    BAIL_ON_ERROR(dwError);

cleanup:
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    if (ppszDCEntries)
    {
        CdcFreeStringArrayA(ppszDCEntries, dwCount);
    }

    return result;

error:
    THROW_IF_NEEDED(dwError);
    goto cleanup;
}
示例#5
0
std::string client::GetAffinitizedDC(std::string DomainName, bool bForceRefresh)
{
    PSTR pszAffinitizedDC = NULL;
    DWORD dwError = 0;
    std::string result;
    PCDC_DC_INFO_A pDomainControllerInfo = NULL;
    //This code would eventually move out of here
    //when other APIs become remotable
    PVMAFD_SERVER pServer = NULL;

    dwError = VmAfdOpenServerA(NULL,NULL,NULL,&pServer);
    BAIL_ON_ERROR(dwError);

    dwError = CdcGetDCNameA(
                         pServer,
                         (PSTR)DomainName.c_str(),
                         NULL,
                         NULL,
                         bForceRefresh,
                         &pDomainControllerInfo);
    BAIL_ON_ERROR(dwError);

    result.assign(pDomainControllerInfo->pszDCName);

cleanup:
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    if (pDomainControllerInfo)
    {
        CdcFreeDomainControllerInfoA(pDomainControllerInfo);
    }

    return result;

error:
    THROW_IF_NEEDED(dwError);
    goto cleanup;
}
示例#6
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;
}
示例#7
0
static
DWORD
VecsCliExecEntryRequest(
    int   argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    PSTR  pszStoreName = NULL;
    PSTR  pszPassword = NULL;
    PSTR  pszAlias = NULL;
    PSTR  pszCertFilePath = NULL;
    PSTR  pszKeyFilePath = NULL;
    PSTR  pszOutputFilePath = NULL;
    PSTR  pszServerName = NULL;
    PSTR  pszUPN = NULL;
    PSTR  pszLotusPassword = NULL;
    DWORD dwFormatAsText = 0;
    DWORD idx = 0;
    DWORD dwAliasesOnly = 0;
    DWORD dwForceDelete = 0;
    VECS_COMMAND command = VECS_COMMAND_UNKNOWN;
    typedef enum
    {
        PARSE_MODE_OPEN = 0,
        PARSE_MODE_CREATE,
        PARSE_MODE_LIST,
        PARSE_MODE_GET_ENTRY,
        PARSE_MODE_DELETE
    } PARSE_MODE;
    typedef enum
    {
        PARSE_SUB_MODE_OPEN = 0,
        PARSE_SUB_MODE_NAME,
        PARSE_SUB_MODE_ALIAS,
        PARSE_SUB_MODE_CERT_PATH,
        PARSE_SUB_MODE_KEY_PATH,
        PARSE_SUB_MODE_SERVER,
        PARSE_SUB_MODE_UPN
    } PARSE_SUB_MODE;
    PARSE_MODE mode = PARSE_MODE_OPEN;
    PARSE_SUB_MODE submode = PARSE_SUB_MODE_OPEN;
    PVMAFD_SERVER pServer = NULL;

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

    for (; idx < argc; idx++)
    {
        PSTR pszArg = argv[idx];

        switch (mode)
        {
            case PARSE_MODE_OPEN:

                if (!strcmp(pszArg, "create"))
                {
                    command = VECS_COMMAND_ENTRY_CREATE;
                    mode = PARSE_MODE_CREATE;
                }
                else if (!strcmp(pszArg, "list"))
                {
                    command = VECS_COMMAND_ENTRY_LIST;
                    mode = PARSE_MODE_LIST;
                }
                else if (!strcmp(pszArg, "delete"))
                {
                    command = VECS_COMMAND_ENTRY_DELETE;
                    mode = PARSE_MODE_DELETE;
                }
                else if (!strcmp(pszArg, "getcert"))
                {
                    command = VECS_COMMAND_ENTRY_GETCERT;
                    mode = PARSE_MODE_GET_ENTRY;
                }
                else if (!strcmp(pszArg, "getkey"))
                {
                    command = VECS_COMMAND_ENTRY_GETKEY;
                    mode = PARSE_MODE_GET_ENTRY;
                }
                else
                {
                    dwError = ERROR_INVALID_PARAMETER;
                    BAIL_ON_VMAFD_ERROR(dwError);
                }
                break;

            case PARSE_MODE_CREATE:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:
                      if (!strcmp(pszArg, "--store"))
                      {
                          submode = PARSE_SUB_MODE_NAME;
                      }
                      else if (!strcmp(pszArg, "--alias"))
                      {
                          submode = PARSE_SUB_MODE_ALIAS;
                      }
                      else if (!strcmp(pszArg, "--cert"))
                      {
                          submode = PARSE_SUB_MODE_CERT_PATH;
                      }
                      else if (!strcmp(pszArg, "--key"))
                      {
                          submode = PARSE_SUB_MODE_KEY_PATH;
                      }
                      else if (!strcmp(pszArg, "--server"))
                      {
                          submode = PARSE_SUB_MODE_SERVER;
                      }
                      else if (!strcmp(pszArg, "--upn"))
                      {
                          submode = PARSE_SUB_MODE_UPN;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }
                      break;

                    case PARSE_SUB_MODE_NAME:
                      if (!pszStoreName)
                      {
                          pszStoreName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;
                      break;
                    case PARSE_SUB_MODE_ALIAS:
                      if (!pszAlias)
                      {
                          pszAlias = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;
                    case PARSE_SUB_MODE_CERT_PATH:
                      if (!pszCertFilePath)
                      {
                          pszCertFilePath = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_KEY_PATH:
                      if (!pszKeyFilePath)
                      {
                          pszKeyFilePath = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_SERVER:
                      if (!pszServerName)
                      {
                          pszServerName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_UPN:
                      if (!pszUPN)
                      {
                          pszUPN = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

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

                break;

            case PARSE_MODE_LIST:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                        if (!strcmp(pszArg, "--store"))
                        {
                            submode = PARSE_SUB_MODE_NAME;
                        }
                        else if (!strcmp(pszArg, "--text"))
                        {
                            dwFormatAsText = 1;
                            submode = PARSE_SUB_MODE_OPEN;
                        }
                        else if (!strcmp(pszArg, "--aliases"))
                        {
                            dwAliasesOnly = 1;
                            submode = PARSE_SUB_MODE_OPEN;
                        }
                        else if (!strcmp(pszArg, "--server"))
                        {
                            submode = PARSE_SUB_MODE_SERVER;
                        }
                        else if (!strcmp(pszArg, "--upn"))
                        {
                            submode = PARSE_SUB_MODE_UPN;
                        }
                        else
                        {
                            dwError = ERROR_INVALID_PARAMETER;
                            BAIL_ON_VMAFD_ERROR(dwError);
                        }
                        break;

                    case PARSE_SUB_MODE_NAME:
                        if (!pszStoreName)
                        {

                            pszStoreName = pszArg;

                        }

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_SERVER:
                        if (!pszServerName)
                        {
                            pszServerName = pszArg;
                        }

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_UPN:
                        if (!pszUPN)
                        {
                            pszUPN = pszArg;
                        }

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    default:

                        dwError = ERROR_INVALID_PARAMETER;
                        BAIL_ON_VMAFD_ERROR(dwError);

                        break;
                }

                break;

            case PARSE_MODE_GET_ENTRY:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                      if (!strcmp(pszArg, "--store"))
                      {
                          submode = PARSE_SUB_MODE_NAME;
                      }
                      else if(!strcmp(pszArg, "--alias"))
                      {
                          submode = PARSE_SUB_MODE_ALIAS;
                      }
                      else if(!strcmp(pszArg, "--output"))
                      {
                          submode = PARSE_SUB_MODE_CERT_PATH;
                      }
                      else if(!strcmp(pszArg, "--text"))
                      {
                          submode = PARSE_SUB_MODE_OPEN;
                          dwFormatAsText = 1;
                      }
                      else if (!strcmp(pszArg, "--server"))
                      {
                          submode = PARSE_SUB_MODE_SERVER;
                      }
                      else if (!strcmp(pszArg, "--upn"))
                      {
                          submode = PARSE_SUB_MODE_UPN;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }
                      break;

                    case PARSE_SUB_MODE_NAME:
                      if (!pszStoreName)
                      {
                          pszStoreName = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_ALIAS:
                      if (!pszAlias)
                      {
                          pszAlias = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_CERT_PATH:
                      if (!pszOutputFilePath)
                      {
                          pszOutputFilePath = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_SERVER:
                      if (!pszServerName)
                      {
                          pszServerName = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_UPN:
                      if (!pszUPN)
                      {
                          pszUPN = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;

                    default:
                      dwError = ERROR_INVALID_PARAMETER;
                      BAIL_ON_VMAFD_ERROR(dwError);

                }

                break;


            case PARSE_MODE_DELETE:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                      if (!strcmp(pszArg, "--store"))
                      {
                          submode = PARSE_SUB_MODE_NAME;
                      }
                      else if (!strcmp(pszArg, "--alias"))
                      {
                          submode = PARSE_SUB_MODE_ALIAS;
                      }
                      else if (!strcmp(pszArg, "-y"))
                      {
                          dwForceDelete = 1;
                          submode = PARSE_SUB_MODE_OPEN;
                      }
                      else if (!strcmp(pszArg, "--server"))
                      {
                          submode = PARSE_SUB_MODE_SERVER;
                      }
                      else if (!strcmp(pszArg, "--upn"))
                      {
                          submode = PARSE_SUB_MODE_UPN;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }
                      break;

                    case PARSE_SUB_MODE_NAME:
                      if (!pszStoreName)
                      {
                          pszStoreName = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;

                      break;
                    case PARSE_SUB_MODE_ALIAS:
                      if (!pszAlias)
                      {
                          pszAlias = pszArg;
                      }
                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_SERVER:
                      if (!pszServerName)
                      {
                          pszServerName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;
                    case PARSE_SUB_MODE_UPN:
                      if (!pszUPN)
                      {
                          pszUPN = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;
                    default:

                      dwError = ERROR_INVALID_PARAMETER;
                      BAIL_ON_VMAFD_ERROR (dwError);

                      break;
                }
                break;
        }
    }

    if (submode != PARSE_SUB_MODE_OPEN)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR (dwError);
    }

    if (IsNullOrEmptyString(pszServerName) ^
        IsNullOrEmptyString(pszUPN)
       )
    {
        dwError = ERROR_INVALID_STATE;
        BAIL_ON_VECS_CLI_ERROR (
                        dwError,
                        "Error: You have to provide both server and upn \n"
                        );
    }

    if (!IsNullOrEmptyString(pszServerName))
    {
        fprintf (
            stdout,
            "Enter password:\t"
            );

        dwError = GetPassword(&pszLotusPassword);

        BAIL_ON_VECS_CLI_ERROR(
                          dwError,
                          "Failed to get password from user \n"
                          );

        fprintf (stdout, "\n");
    }

    dwError = VmAfdOpenServerA(
                  pszServerName,
                  pszUPN,
                  pszLotusPassword,
                  &pServer);
    BAIL_ON_VECS_CLI_ERROR (
                            dwError,
                            "Failed to establish connection to remote server \n"
                           );

    switch (command)
    {
        case VECS_COMMAND_ENTRY_CREATE:

            dwError = VecsCliAddEntryA(
                              pServer,
                              pszStoreName,
                              pszPassword,
                              pszAlias,
                              pszCertFilePath,
                              pszKeyFilePath
                              );
            break;

        case VECS_COMMAND_ENTRY_LIST:

            dwError = VecsCliListEntriesA(
                              pServer,
                              pszStoreName,
                              pszPassword,
                              dwFormatAsText,
                              dwAliasesOnly
                              );

            break;

        case VECS_COMMAND_ENTRY_GETCERT:
            dwError = VecsCliGetCertificateA(
                              pServer,
                              pszStoreName,
                              pszPassword,
                              pszAlias,
                              pszOutputFilePath,
                              dwFormatAsText
                              );
            break;

        case VECS_COMMAND_ENTRY_GETKEY:
            dwError = VecsCliGetKeyA(
                              pServer,
                              pszStoreName,
                              pszPassword,
                              pszAlias,
                              pszOutputFilePath,
                              dwFormatAsText
                              );
            break;

        case VECS_COMMAND_ENTRY_DELETE:

            if (!dwForceDelete)
            {
                char input = 0;
                fprintf (stdout,
                         "Warning: This operation will delete entry [%s] from store [%s]\n"
                         "Do you wish to continue? Y/N [N] \n",
                         pszAlias,
                         pszStoreName
                        );
                scanf (
                        "%c",
                        &input
                        );

                if (input == 'Y' || input == 'y')
                {
                    dwForceDelete = 1;
                }
            }

            if (dwForceDelete)
            {

                dwError = VecsCliDeleteEntryA(
                              pServer,
                              pszStoreName,
                              pszPassword,
                              pszAlias
                              );
            }

            break;

        default:

            dwError = ERROR_INVALID_STATE;

            break;
    }
    BAIL_ON_VMAFD_ERROR(dwError);

cleanup:

    VMAFD_SAFE_FREE_STRINGA(pszLotusPassword);

    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    return dwError;

error:

    goto cleanup;
}
示例#8
0
static
DWORD
VecsCliExecStoreRequest(
    int   argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    PSTR  pszStoreName = NULL;
    PSTR  pszPassword = NULL;
    PSTR  pszUserName = NULL;
    PSTR  pszServerName = NULL;
    PSTR  pszUPN = NULL;
    PSTR  pszLotusPassword = NULL;
    DWORD idx = 0;
    DWORD dwForceDelete = 0;
    DWORD dwAccessMask = 0;
    VECS_COMMAND command = VECS_COMMAND_UNKNOWN;
    VECS_PERMISSION_MODE permMode = VECS_PERMISSION_MODE_UNKNOWN;
    typedef enum
    {
        PARSE_MODE_OPEN = 0,
        PARSE_MODE_CREATE,
        PARSE_MODE_DELETE,
        PARSE_MODE_LIST,
        PARSE_MODE_PERMISSIONS,
        PARSE_MODE_GET_PERMISSIONS
    } PARSE_MODE;
    typedef enum
    {
        PARSE_SUB_MODE_OPEN = 0,
        PARSE_SUB_MODE_NAME,
        PARSE_SUB_MODE_PASSWORD,
        PARSE_SUB_MODE_USER,
        PARSE_SUB_MODE_MASK,
        PARSE_SUB_MODE_SERVER,
        PARSE_SUB_MODE_UPN
    } PARSE_SUB_MODE;
    PARSE_MODE mode = PARSE_MODE_OPEN;
    PARSE_SUB_MODE submode = PARSE_SUB_MODE_OPEN;
    PVMAFD_SERVER pServer = NULL;

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

    for (; idx < argc; idx++)
    {
        PSTR pszArg = argv[idx];

        switch (mode)
        {
            case PARSE_MODE_OPEN:

                if (!strcmp(pszArg, "create"))
                {
                    command = VECS_COMMAND_STORE_CREATE;
                    mode = PARSE_MODE_CREATE;
                }
                else if (!strcmp(pszArg, "list"))
                {
                    command = VECS_COMMAND_STORE_LIST;
                    mode = PARSE_MODE_LIST;
                }
                else if (!strcmp(pszArg, "delete"))
                {
                    command = VECS_COMMAND_STORE_DELETE;
                    mode = PARSE_MODE_DELETE;
                }
                else if (!strcmp(pszArg, "permission"))
                {
                    command = VECS_COMMAND_STORE_PERMISSION;
                    mode = PARSE_MODE_PERMISSIONS;
                }
                else if (!strcmp(pszArg, "get-permissions"))
                {
                    command = VECS_COMMAND_STORE_GET_PERMISSIONS;
                    mode = PARSE_MODE_GET_PERMISSIONS;
                }
                else
                {
                    dwError = ERROR_INVALID_PARAMETER;
                    BAIL_ON_VMAFD_ERROR(dwError);
                }
                break;

            case PARSE_MODE_CREATE:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                        if (!strcmp(pszArg, "--name"))
                        {
                            submode = PARSE_SUB_MODE_NAME;
                        }
                        else if (!strcmp(pszArg, "--server"))
                        {
                            submode = PARSE_SUB_MODE_SERVER;
                        }
                        else if (!strcmp(pszArg, "--upn"))
                        {
                            submode = PARSE_SUB_MODE_UPN;
                        }
                        else
                        {
                            dwError = ERROR_INVALID_PARAMETER;
                            BAIL_ON_VMAFD_ERROR(dwError);
                        }
                        break;

                    case PARSE_SUB_MODE_NAME:

                        pszStoreName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_SERVER:

                        pszServerName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_UPN:

                        pszUPN = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    default:

                        dwError = ERROR_INVALID_PARAMETER;

                        BAIL_ON_VMAFD_ERROR (dwError);

                        break;
                }

                break;

            case PARSE_MODE_DELETE:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                        if (!strcmp(pszArg, "--name"))
                        {
                            submode = PARSE_SUB_MODE_NAME;
                        }
                        else if (!strcmp(pszArg, "-y"))
                        {
                            dwForceDelete = 1;
                            submode = PARSE_SUB_MODE_OPEN;
                        }
                        else if (!strcmp(pszArg, "--server"))
                        {
                            submode = PARSE_SUB_MODE_SERVER;
                        }
                        else if (!strcmp(pszArg, "--upn"))
                        {
                            submode = PARSE_SUB_MODE_UPN;
                        }
                        else
                        {
                            dwError = ERROR_INVALID_PARAMETER;
                            BAIL_ON_VMAFD_ERROR(dwError);
                        }
                        break;

                    case PARSE_SUB_MODE_NAME:

                        pszStoreName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_SERVER:

                        pszServerName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_UPN:

                        pszUPN = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    default:

                        dwError = ERROR_INVALID_STATE;
                        BAIL_ON_VMAFD_ERROR(dwError);

                        break;
                }

                break;

            case PARSE_MODE_LIST:
                switch(submode)
                {
                    case PARSE_SUB_MODE_OPEN:
                      if (!strcmp(pszArg, "--server"))
                      {
                          submode = PARSE_SUB_MODE_SERVER;
                      }
                      else if (!strcmp(pszArg, "--upn"))
                      {
                          submode = PARSE_SUB_MODE_UPN;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }
                      break;

                    case PARSE_SUB_MODE_SERVER:
                      if (!pszServerName)
                      {
                          pszServerName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;

                    case PARSE_SUB_MODE_UPN:
                      if (!pszUPN)
                      {
                          pszUPN = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;

                    default:
                      dwError = ERROR_INVALID_PARAMETER;
                      BAIL_ON_VMAFD_ERROR (dwError);

                      break;
                }

                break;

            case PARSE_MODE_PERMISSIONS:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                      if (!strcmp(pszArg, "--name"))
                      {
                          submode = PARSE_SUB_MODE_NAME;
                      }
                      else if (!strcmp(pszArg, "--grant"))
                      {
                          if (permMode != VECS_PERMISSION_MODE_UNKNOWN)
                          {
                              dwError = ERROR_INVALID_PARAMETER;
                              BAIL_ON_VMAFD_ERROR (dwError);
                          }
                          permMode = VECS_PERMISSION_MODE_GRANT;
                          submode = PARSE_SUB_MODE_MASK;
                      }
                      else if (!strcmp(pszArg, "--revoke"))
                      {
                          if (permMode != VECS_PERMISSION_MODE_UNKNOWN)
                          {
                              dwError = ERROR_INVALID_PARAMETER;
                              BAIL_ON_VMAFD_ERROR (dwError);
                          }
                          permMode = VECS_PERMISSION_MODE_REVOKE;
                          submode = PARSE_SUB_MODE_MASK;
                      }
                      else if (!strcmp (pszArg, "--user"))
                      {
                          submode = PARSE_SUB_MODE_USER;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }
                      break;

                    case PARSE_SUB_MODE_NAME:

                      if (!pszStoreName)
                      {
                          pszStoreName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;

                    case PARSE_SUB_MODE_MASK:

                      if (!strcmp(pszArg, "read"))
                      {
                          dwAccessMask = dwAccessMask |
                                          READ_STORE;
                      }
                      else if (!strcmp (pszArg, "write"))
                      {
                          dwAccessMask = dwAccessMask |
                                         WRITE_STORE;
                      }
                      else
                      {
                          dwError = ERROR_INVALID_PARAMETER;
                          BAIL_ON_VMAFD_ERROR (dwError);
                      }

                      submode = PARSE_SUB_MODE_OPEN;
                      break;

                    case PARSE_SUB_MODE_USER:

                      if (!pszUserName)
                      {
                          pszUserName = pszArg;
                      }

                      submode = PARSE_SUB_MODE_OPEN;

                      break;

                    default:

                      dwError = ERROR_INVALID_PARAMETER;
                      BAIL_ON_VMAFD_ERROR (dwError);
                      break;

                }
                break;

            case PARSE_MODE_GET_PERMISSIONS:

                switch (submode)
                {
                    case PARSE_SUB_MODE_OPEN:

                        if (!strcmp(pszArg, "--name"))
                        {
                            submode = PARSE_SUB_MODE_NAME;
                        }
                        else if (!strcmp(pszArg, "--server"))
                        {
                            submode = PARSE_SUB_MODE_SERVER;
                        }
                        else if (!strcmp(pszArg, "--upn"))
                        {
                            submode = PARSE_SUB_MODE_UPN;
                        }
                        else
                        {
                            dwError = ERROR_INVALID_PARAMETER;
                            BAIL_ON_VMAFD_ERROR(dwError);
                        }
                        break;

                    case PARSE_SUB_MODE_NAME:

                        pszStoreName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_SERVER:

                        pszServerName = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    case PARSE_SUB_MODE_UPN:

                        pszUPN = pszArg;

                        submode = PARSE_SUB_MODE_OPEN;

                        break;

                    default:

                        dwError = ERROR_INVALID_STATE;
                        BAIL_ON_VMAFD_ERROR(dwError);

                        break;
                }

                break;
        }
    }

    if (IsNullOrEmptyString(pszServerName) ^
        IsNullOrEmptyString(pszUPN)
       )
    {
        dwError = ERROR_INVALID_STATE;
        BAIL_ON_VECS_CLI_ERROR (
                        dwError,
                        "Error: You have to provide both server and upn \n"
                        );
    }

    if (!IsNullOrEmptyString(pszServerName))
    {
        fprintf (
            stdout,
            "Enter password:\t"
            );

        dwError = GetPassword(&pszLotusPassword);
        BAIL_ON_VECS_CLI_ERROR(
                          dwError,
                          "Failed to get password from user \n"
                          );
        fprintf (stdout, "\n");
    }

    dwError = VmAfdOpenServerA(
                  pszServerName,
                  pszUPN,
                  pszLotusPassword,
                  &pServer);
    BAIL_ON_VECS_CLI_ERROR(
                          dwError,
                          "Failed to establish connection to remote server \n"
                          );

    switch (command)
    {
        case VECS_COMMAND_STORE_CREATE:

            dwError = VecsCliCreateStoreA(pServer, pszStoreName);

            break;

        case VECS_COMMAND_STORE_LIST:

            dwError = VecsCliListStoreA(pServer);

            break;

        case VECS_COMMAND_STORE_DELETE:

            if (!dwForceDelete)
            {
                char input = 0;
                fprintf (stdout,
                         "Warning: This operation will delete store [%s]\n"
                         "Do you wish to continue? Y/N [N] \n",
                         pszStoreName
                        );
                scanf (
                        "%c",
                        &input
                        );

                if (input == 'Y' || input == 'y')
                {
                    dwForceDelete = 1;
                }
            }

            if (dwForceDelete)
            {
                dwError = VecsCliDeleteStoreA(pServer, pszStoreName, pszPassword);
            }

            break;

        case VECS_COMMAND_STORE_PERMISSION:

            dwError = VecsCliSetPermissionA (
                                      pszStoreName,
                                      pszUserName,
                                      permMode,
                                      dwAccessMask
                                      );
            break;

        case VECS_COMMAND_STORE_GET_PERMISSIONS:

            dwError = VecsCliGetPermissionsA (
                                     pServer,
                                     pszStoreName
                                     );
            break;

        default:

            dwError = ERROR_INVALID_STATE;

            break;
    }
    BAIL_ON_VMAFD_ERROR(dwError);

cleanup:

    VMAFD_SAFE_FREE_STRINGA(pszLotusPassword);

    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    return dwError;

error:

    goto cleanup;
}
示例#9
0
static
DWORD
CdcVmafdHeartbeatPing(
    PWSTR pwszDCName,
    PWSTR pwszAccount,
    PWSTR pwszPassword,
    PWSTR pwszDomainName,
    PBOOL pbIsAlive
    )
{
    DWORD dwError = 0;
    PSTR pszUPN = NULL;
    PSTR pszAccount = NULL;
    PSTR pszDomainName = NULL;
    PWSTR pwszUPN = NULL;
    BOOL bIsAlive = FALSE;

    PVMAFD_SERVER pServer = NULL;
    PVMAFD_HB_STATUS_W pHeartbeatStatus = NULL;

    if (IsNullOrEmptyString(pwszDCName) ||
        IsNullOrEmptyString(pwszAccount) ||
        IsNullOrEmptyString(pwszPassword) ||
        IsNullOrEmptyString(pwszDomainName) ||
        !pbIsAlive
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMAFD_ERROR(dwError);
    }

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

    dwError = VmAfdAllocateStringAFromW(
                                  pwszDomainName,
                                  &pszDomainName
                                  );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdAllocateStringPrintf(
                                  &pszUPN,
                                  "%s@%s",
                                  pszAccount,
                                  pszDomainName
                                  );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdAllocateStringWFromA(
                                 pszUPN,
                                 &pwszUPN
                                 );
    BAIL_ON_VMAFD_ERROR(dwError);

    dwError = VmAfdOpenServerW(
                         pwszDCName,
                         pwszUPN,
                         pwszPassword,
                         &pServer
                         );
    BAIL_ON_VMAFD_ERROR(dwError);

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

    bIsAlive = pHeartbeatStatus->bIsAlive? TRUE: FALSE;

    *pbIsAlive = bIsAlive;

cleanup:

    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }
    if (pHeartbeatStatus)
    {
        VmAfdFreeHeartbeatStatusW(pHeartbeatStatus);
    }
    VMAFD_SAFE_FREE_MEMORY(pszUPN);
    VMAFD_SAFE_FREE_MEMORY(pwszUPN);
    VMAFD_SAFE_FREE_MEMORY(pszAccount);
    VMAFD_SAFE_FREE_MEMORY(pszDomainName);

    return dwError;
error:

    if (pbIsAlive)
    {
        *pbIsAlive = FALSE;
    }
    VmAfdLog(VMAFD_DEBUG_ANY,
             "Failed to get heartbeat Status due to Error: %d",
             dwError
            );
    goto cleanup;
}
示例#10
0
JNIEXPORT jint JNICALL
Java_com_vmware_identity_cdc_CdcAdapter_VmAfdOpenServerW(
        JNIEnv  *env,
        jobject clazz,
        jstring jServerName,
        jstring jUserName,
        jstring jPassword,
        jobject jpServer
        )
{
    DWORD dwError = 0;
    PVMAFD_SERVER pServer = NULL;
    PCWSTR pwszServerName = NULL;
    PCWSTR pwszUserName = NULL;
    PCWSTR pwszPassword = NULL;

#ifndef _WIN32
    setlocale (LC_ALL, "");
#endif


    if (jpServer == NULL)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_ERROR(dwError);
    }

    if (jServerName != NULL)
    {
        pwszServerName = (*env)->GetStringChars(env, jServerName, NULL);
    }

    if (jUserName != NULL)
    {
       pwszUserName = (*env)->GetStringChars(env, jUserName, NULL);
    }

    if (jPassword != NULL)
    {
        pwszPassword = (*env)->GetStringChars(env, jPassword, NULL);
    }

    dwError = VmAfdOpenServerW(
            pwszServerName,
            pwszUserName,
            pwszPassword,
            &pServer
            );
    BAIL_ON_ERROR(dwError);

    dwError = JniSetPointer(env, jpServer, (PVOID)pServer);
    BAIL_ON_ERROR(dwError);

cleanup:
    if (pwszServerName)
    {
        (*env)->ReleaseStringChars(env, jServerName, pwszServerName);
    }
    if (pwszUserName)
    {
        (*env)->ReleaseStringChars(env, jUserName, pwszUserName);
    }
    if (pwszPassword)
    {
        (*env)->ReleaseStringChars(env, jPassword, pwszPassword);
    }

    return dwError;

error:
    if (pServer)
    {
        VmAfdCloseServer(pServer);
    }

    goto cleanup;
}