Exemplo n.º 1
0
VMREST_LOG_LEVEL
VmDirToCRestEngineLogLevel(
    VOID
    )
{
    VMDIR_LOG_LEVEL  vmdirLogLevel = VmDirLogGetLevel();
    VMREST_LOG_LEVEL cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;

    switch (vmdirLogLevel)
    {
    case VMDIR_LOG_ERROR:
        cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;
        break;

    case VMDIR_LOG_WARNING:
        cResetEngineLogLevel = VMREST_LOG_LEVEL_WARNING;
        break;

    case VMDIR_LOG_INFO:
        cResetEngineLogLevel = VMREST_LOG_LEVEL_INFO;
        break;

    case VMDIR_LOG_VERBOSE:
    case VMDIR_LOG_DEBUG:
        cResetEngineLogLevel = VMREST_LOG_LEVEL_DEBUG;
        break;

    default:
        cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;
    }

    return cResetEngineLogLevel;
}
Exemplo n.º 2
0
VMREST_LOG_LEVEL
VmDirToCRestEngineLogLevel(
    VOID
    )
{
    VMDIR_LOG_LEVEL  lwraftLogLevel = VmDirLogGetLevel();
    VMREST_LOG_LEVEL cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;

    if (gVmdirServerGlobals.dwRESTLogLevelOverride >= VMREST_LOG_LEVEL_ERROR &&
        gVmdirServerGlobals.dwRESTLogLevelOverride <= VMREST_LOG_LEVEL_DEBUG)
    {
        cResetEngineLogLevel = gVmdirServerGlobals.dwRESTLogLevelOverride;
    }
    else
    {
        switch (lwraftLogLevel)
        {
        case VMDIR_LOG_ERROR:
            cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;
            break;

        case VMDIR_LOG_WARNING:
            cResetEngineLogLevel = VMREST_LOG_LEVEL_WARNING;
            break;

        case VMDIR_LOG_INFO:
            cResetEngineLogLevel = VMREST_LOG_LEVEL_INFO;
            break;

        case VMDIR_LOG_VERBOSE:
        case VMDIR_LOG_DEBUG:
            cResetEngineLogLevel = VMREST_LOG_LEVEL_DEBUG;
            break;

        default:
            cResetEngineLogLevel = VMREST_LOG_LEVEL_ERROR;
        }
    }

    return cResetEngineLogLevel;
}
Exemplo n.º 3
0
int
VmDirPerformSearch(
    PVDIR_OPERATION   pOperation
    )
{
   ber_len_t     size = 0;
   SearchReq *   sr = &(pOperation->request.searchReq);
   int           retVal = LDAP_SUCCESS;
   BerValue*           pLberBerv = NULL;
   PSTR                pszLocalErrorMsg = NULL;
   BOOLEAN             bResultAlreadySent = FALSE;
   PVDIR_LDAP_RESULT   pResult = &(pOperation->ldapResult);

   // Parse base object, scope, deref alias, sizeLimit, timeLimit and typesOnly search parameters.
   if ( ber_scanf( pOperation->ber, "{miiiib", &(pOperation->reqDn.lberbv), &sr->scope, &sr->derefAlias, &sr->sizeLimit,
                   &sr->timeLimit, &sr->attrsOnly ) == LBER_ERROR )
   {
      VMDIR_LOG_ERROR( LDAP_DEBUG_ARGS, "PerformSearch: Decoding baseDN, ... attrsOnly error." );
      pResult->errCode = LDAP_PROTOCOL_ERROR;
      retVal = LDAP_NOTICE_OF_DISCONNECT;
      BAIL_ON_VMDIR_ERROR_WITH_MSG(   retVal, (pszLocalErrorMsg),
                                      "Decoding error while parsing baseDN, ... attrsOnly.");
   }

   VMDIR_LOG_VERBOSE( LDAP_DEBUG_ARGS, "Search Request: base: \"%s\", scope: %d, deref: %d, sizeLimit: %d, timeLimit: %d,"
             "attrsOnly: %d", pOperation->reqDn.lberbv.bv_val, sr->scope, sr->derefAlias, sr->sizeLimit, sr->timeLimit,
             sr->attrsOnly);

   if (sr->scope != LDAP_SCOPE_BASE && sr->scope != LDAP_SCOPE_ONELEVEL &&
       sr->scope != LDAP_SCOPE_SUBTREE)
   {
       pResult->errCode = retVal = LDAP_PROTOCOL_ERROR;
       BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Invalid scope" );
   }

   if (sr->sizeLimit < 0 || sr->sizeLimit > LDAP_MAXINT)
   {
       pResult->errCode = retVal = LDAP_PROTOCOL_ERROR;
       BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Invalid size limit: %d", sr->sizeLimit  );
   }

   if (sr->timeLimit < 0 || sr->timeLimit > LDAP_MAXINT)
   {
       pResult->errCode = retVal = LDAP_PROTOCOL_ERROR;
       BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Invalid time limit: %d", sr->timeLimit );
   }

   if (sr->derefAlias != LDAP_DEREF_NEVER && sr->derefAlias != LDAP_DEREF_SEARCHING &&
       sr->derefAlias != LDAP_DEREF_FINDING && sr->derefAlias != LDAP_DEREF_ALWAYS)
   {
      pResult->errCode = retVal = LDAP_PROTOCOL_ERROR;
      BAIL_ON_VMDIR_ERROR_WITH_MSG(   retVal, (pszLocalErrorMsg), "Invalid dereference alias parameter");
   }

   // Parse filter
   retVal = ParseFilter( pOperation, &sr->filter, pResult );
   BAIL_ON_VMDIR_ERROR(retVal);

   // Log String filter, if desired.
   if (VmDirLogGetLevel() >= VMDIR_LOG_VERBOSE && VmDirLogGetMask() & LDAP_DEBUG_ARGS)
   {
      VDIR_BERVALUE strFilter = VDIR_BERVALUE_INIT;
      FilterToStrFilter( sr->filter, &strFilter );
      VMDIR_LOG_VERBOSE( LDAP_DEBUG_ARGS, "    Filter: %s", strFilter.lberbv.bv_val );
      VmDirFreeBervalContent(&strFilter);
   }

   // Parse attributes. 'M' => attribute names point within (in-place) the ber.
   size = sizeof( BerValue ); // Size of the structure is passed-in, and number of attributes are returned back in
                              // the same parameter.
   if ( ber_scanf( pOperation->ber, "{M}}", &pLberBerv, &size, 0 ) == LBER_ERROR )
   {
      pResult->errCode = LDAP_PROTOCOL_ERROR;
      retVal = LDAP_NOTICE_OF_DISCONNECT;
      BAIL_ON_VMDIR_ERROR_WITH_MSG(   retVal, (pszLocalErrorMsg), "Decoding error while parsing required attributes.");
   }

   // copy pLberBerv content into sr->attrs
   if (pLberBerv && size > 0)
   {
       int iCnt = 0;

       if (VmDirAllocateMemory(sizeof(VDIR_BERVALUE) * (size+1), (PVOID*)&sr->attrs) != 0)
       {
           pResult->errCode = retVal = LDAP_OPERATIONS_ERROR;
           BAIL_ON_VMDIR_ERROR_WITH_MSG(   retVal, (pszLocalErrorMsg), "no memory");
       }

       for (iCnt = 0; iCnt < size; iCnt++)
       {
           sr->attrs[iCnt].lberbv.bv_val = pLberBerv[iCnt].bv_val;
           sr->attrs[iCnt].lberbv.bv_len = pLberBerv[iCnt].bv_len;
       }
   }

   // Log list of the required attributes, if desired.
   if (( VmDirLogGetMask() & LDAP_DEBUG_ARGS) && size > 0)
   {
       if (VmDirLogSearchRequest(sr, size) != 0)
       {
           pResult->errCode = retVal = LDAP_OPERATIONS_ERROR;
           BAIL_ON_VMDIR_ERROR_WITH_MSG(retVal, (pszLocalErrorMsg), "Error while logging search request");
       }
   }

   // Parse LDAP controls present (if any) in the request.
   retVal = ParseRequestControls(pOperation, pResult);  // ldapResult.errCode set inside
   BAIL_ON_VMDIR_ERROR( retVal );

   retVal = pResult->errCode = VmDirMLSearch( pOperation );
   bResultAlreadySent = TRUE;
   BAIL_ON_VMDIR_ERROR(retVal);

cleanup:

    VMDIR_SAFE_FREE_MEMORY(pLberBerv);
    VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg);

    return retVal;

error:

    VMDIR_APPEND_ERROR_MSG(pResult->pszErrMsg, pszLocalErrorMsg);
    if (retVal != LDAP_NOTICE_OF_DISCONNECT && bResultAlreadySent == FALSE)
    {
        VmDirSendLdapResult( pOperation );
    }

    goto cleanup;
}
Exemplo n.º 4
0
static
DWORD
_VmDirLogSearchParameters(
    PVDIR_OPERATION pOperation
    )
{
    DWORD dwError = 0;
    PVDIR_CONNECTION pConn = pOperation->conn;
    SearchReq sr = pOperation->request.searchReq;
    VDIR_BERVALUE strFilter = VDIR_BERVALUE_INIT;
    static PCSTR pcszScopeStr[] = { "BASE", "ONE", "SUB" };

    dwError = FilterToStrFilter(sr.filter, &strFilter);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(
            VDIR_SAFE_STRING(strFilter.lberbv.bv_val),
            &pConn->SuperLogRec.pszOperationParameters);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(
            VDIR_SAFE_STRING(pOperation->reqDn.lberbv.bv_val),
            &pConn->SuperLogRec.opInfo.searchInfo.pszBaseDN);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(
            VDIR_SAFE_STRING(pOperation->pszFilters),
            &pConn->SuperLogRec.opInfo.searchInfo.pszIndexResults);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (sr.scope < 0 || sr.scope > 2)
    {
        VMDIR_LOG_ERROR( LDAP_DEBUG_ARGS, "_VmDirLogSearchParameters: Unknown search scope (%d)", sr.scope );
        dwError = ERROR_INVALID_PARAMETER;
    }
    else
    {
        dwError = VmDirAllocateStringA(
                pcszScopeStr[sr.scope],
                &pConn->SuperLogRec.opInfo.searchInfo.pszScope);
    }
    BAIL_ON_VMDIR_ERROR(dwError);

    pConn->SuperLogRec.opInfo.searchInfo.dwReturned = pOperation->dwSentEntries;
    if (pOperation->request.searchReq.filter->candidates)
    {
        pConn->SuperLogRec.opInfo.searchInfo.dwScanned = sr.filter->candidates->size;
    }

    if (VmDirLogGetLevel() >= VMDIR_LOG_VERBOSE && VmDirLogGetMask() & LDAP_DEBUG_ARGS)
    {
        VMDIR_LOG_VERBOSE(LDAP_DEBUG_ARGS, "    Filter: %s", pConn->SuperLogRec.pszOperationParameters);
    }

cleanup:
    VmDirFreeBervalContent(&strFilter);
    return dwError;

error:
    goto cleanup;
}