Пример #1
0
DWORD
VMCARESTSetResponsePayload(
    PVMREST_HANDLE  pRESTHandle,
    PREST_RESPONSE* ppResponse,
    PSTR            pszRespPayload
    )
{
    DWORD   dwError = 0;
    DWORD   bytesWritten = 0;
    PSTR    pszPyldLen = NULL;
    size_t  pyldLen = 0;
    size_t  sentLen = 0;

    pyldLen = VMCAStringLenA(VMCA_SAFE_STRING(pszRespPayload));

    dwError = VMCAAllocateStringPrintfA(&pszPyldLen, "%ld", pyldLen);
    BAIL_ON_VMREST_ERROR(dwError);

    dwError = VmRESTSetDataLength(
            ppResponse,
            pyldLen > VMCARESTMAXPAYLOADLENGTH ? NULL : pszPyldLen);
    BAIL_ON_VMREST_ERROR(dwError);

    do
    {
        size_t chunkLen = pyldLen > VMCARESTMAXPAYLOADLENGTH ?
                VMCARESTMAXPAYLOADLENGTH : pyldLen;

        dwError = VmRESTSetData(
                pRESTHandle,
                ppResponse,
                VMCA_SAFE_STRING(pszRespPayload) + sentLen,
                chunkLen,
                &bytesWritten);

        sentLen += bytesWritten;
        pyldLen -= bytesWritten;
    }
    while (dwError == REST_ENGINE_MORE_IO_REQUIRED);
    BAIL_ON_VMREST_ERROR(dwError);

cleanup:
    VMCA_SAFE_FREE_MEMORY(pszPyldLen);
    return dwError;

error:
    goto cleanup;
}
Пример #2
0
/*
 *  Quick and dirty function to verify format - colons and digits/a-f/A-F only
 */
BOOLEAN
VMCAIsIPV6AddrFormat(
    PCSTR   pszAddr
    )
{
    BOOLEAN     bIsIPV6 = pszAddr ? TRUE : FALSE;
    size_t      iSize = 0;
    size_t      iCnt = 0;
    size_t      iColonCnt = 0;

    if ( pszAddr != NULL )
    {
        iSize = VMCAStringLenA(pszAddr);
        for (iCnt=0; bIsIPV6 && iCnt < iSize; iCnt++)
        {
            if ( pszAddr[iCnt] == ':' )
            {
                iColonCnt++;
            }
            else if ( VMCA_ASCII_DIGIT( pszAddr[iCnt] )
                      ||
                      VMCA_ASCII_aTof( pszAddr[iCnt] )
                      ||
                      VMCA_ASCII_AToF( pszAddr[iCnt] )
                    )
            {
            }
            else
            {
                bIsIPV6 = FALSE;
            }
        }

        // should not count on iColonCnt == 7
        if ( iColonCnt < 2 )
        {
            bIsIPV6 = FALSE;
        }
    }

    return bIsIPV6;
}
Пример #3
0
static
DWORD
_VMCAHttpsServiceStartup(
    VOID
    )
{
    DWORD dwError = 0;
    DWORD iter = 0;
    DWORD endPointCnt = 0;
    REST_CONF config = {0};
    PSTR  pszCert = NULL;
    PSTR  pszKey = NULL;
    DWORD dwPort = 0;
    PREST_PROCESSOR pHandlers = &sVmcaRestHandlers;
    PVMREST_HANDLE  pHTTPSHandle = NULL;

    (VOID)VMCAGetRegKeyValueDword(
                  VMCA_KEY_PARAMETERS,//VMCA_CONFIG_PARAMETER_KEY_PATH,
                  VMCA_HTTPS_PORT_REG_KEY,
                  &dwPort,
                  VMCA_HTTPS_PORT_NUM
                  );

    // port value '0' indicates don't start HTTPS service
    if (dwPort == 0)
    {
        goto cleanup;
    }

    config.serverPort = dwPort;
    config.connTimeoutSec = VMCA_REST_CONN_TIMEOUT_SEC;
    config.maxDataPerConnMB = VMCA_MAX_DATA_PER_CONN_MB;
    config.pSSLContext = NULL;
    config.nWorkerThr = VMCA_REST_WORKER_TH_CNT;
    config.nClientCnt = VMCA_REST_CLIENT_CNT;
    config.SSLCtxOptionsFlag = 0;
    config.pszSSLCertificate = NULL;
    config.pszSSLKey = NULL;
    config.pszSSLCipherList = NULL;
    config.pszDebugLogFile = NULL;
    config.pszDaemonName = VMCA_DAEMON_NAME;
    config.isSecure = TRUE;
    config.useSysLog = TRUE;
    config.debugLogLevel = VMREST_LOG_LEVEL_ERROR;

    //Get Certificate and Key from VECS and Set it to Rest Engine
    dwError = VMCAGetVecsMachineCert(&pszCert, &pszKey);
    BAIL_ON_VMREST_ERROR(dwError);

    dwError = VmRESTInit(&config, &pHTTPSHandle);
    BAIL_ON_VMREST_ERROR(dwError);

    dwError = VmRESTSetSSLInfo(pHTTPSHandle, pszCert, VMCAStringLenA(pszCert)+1, SSL_DATA_TYPE_CERT);
    BAIL_ON_VMREST_ERROR(dwError);

    dwError = VmRESTSetSSLInfo(pHTTPSHandle, pszKey, VMCAStringLenA(pszKey)+1, SSL_DATA_TYPE_KEY);
    BAIL_ON_VMREST_ERROR(dwError);

    endPointCnt = ARRAY_SIZE(restEndPoints);

    for (iter = 0; iter < endPointCnt; iter++)
    {
        dwError = VmRESTRegisterHandler(
                pHTTPSHandle,
                restEndPoints[iter],
                pHandlers,
                NULL);
        BAIL_ON_VMREST_ERROR(dwError);
    }

    dwError = VmRESTStart(pHTTPSHandle);
    BAIL_ON_VMREST_ERROR(dwError);

    gpVMCAHTTPSHandle = pHTTPSHandle;

cleanup:
    VMCA_SAFE_FREE_MEMORY(pszCert);
    VMCA_SAFE_FREE_MEMORY(pszKey);
    return dwError;

error:
    _VMCARestFreeHandle(pHTTPSHandle);
    VMCA_LOG_ERROR("%s: failure while starting REST HTTPS service, error: %d", __FUNCTION__, dwError);
    goto cleanup;
}