DWORD VmDirComputeMessageDigest( const EVP_MD* digestMethod, const unsigned char* pData, size_t dataSize, unsigned char** ppMD, size_t* pMDSize ) { DWORD dwError = 0; EVP_MD_CTX mdCtx = {0}; unsigned char md[EVP_MAX_MD_SIZE] = {0}; unsigned int mdSize = 0; unsigned char* pMD = NULL; if (!digestMethod || !pData || !ppMD || !pMDSize) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } EVP_MD_CTX_init(&mdCtx); if (EVP_DigestInit_ex(&mdCtx, digestMethod, NULL) == 0) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: EVP_DigestInit_ex returned 0", __FUNCTION__); BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_SSL); } if (EVP_DigestUpdate(&mdCtx, pData, dataSize) == 0) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: EVP_DigestUpdate returned 0", __FUNCTION__); BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_SSL); } if (EVP_DigestFinal_ex(&mdCtx, md, &mdSize) == 0) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: EVP_DigestFinal_ex returned 0", __FUNCTION__); BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_SSL); } dwError = VmDirAllocateAndCopyMemory(md, mdSize, (PVOID*)&pMD); BAIL_ON_VMDIR_ERROR(dwError); *ppMD = pMD; *pMDSize = mdSize; cleanup: EVP_MD_CTX_cleanup(&mdCtx); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed with error (%d)", __FUNCTION__, dwError); VMDIR_SAFE_FREE_MEMORY(pMD); goto cleanup; }
int VmDirPerformRename( PVDIR_OPERATION pOperation ) { ModifyReq * modReq = &(pOperation->request.modifyReq); int retVal = LDAP_SUCCESS; PVDIR_LDAP_RESULT pResult = &(pOperation->ldapResult); ber_len_t size = 0; PSTR pszLocalErrorMsg = NULL; if (!_VmDirIsRenameSupported()) { pResult->errCode = retVal = LDAP_UNWILLING_TO_PERFORM; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, pszLocalErrorMsg, "Operation is not enabled on this server or is not supported at this domain fuctional level."); } // Get entry DN. 'm' => reqDn.bv_val points to DN within (in-place) ber if ( ber_scanf( pOperation->ber, "{mmb", &modReq->dn, &modReq->newrdn, &modReq->bDeleteOldRdn) == LBER_ERROR ) { VMDIR_LOG_ERROR( LDAP_DEBUG_ARGS, "VmDirPerformRename: ber_scanf failed" ); pResult->errCode = LDAP_PROTOCOL_ERROR; retVal = LDAP_NOTICE_OF_DISCONNECT; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Decoding error while parsing the target DN"); } if (ber_peek_tag(pOperation->ber, &size) == LDAP_TAG_NEWSUPERIOR) { if ( ber_scanf(pOperation->ber, "m", &modReq->newSuperior ) == LBER_ERROR ) { pResult->errCode = LDAP_PROTOCOL_ERROR; retVal = LDAP_NOTICE_OF_DISCONNECT; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Decoding error while parsing newSuperior"); } } if ( ber_scanf( pOperation->ber, "}") == LBER_ERROR ) { VMDIR_LOG_ERROR( LDAP_DEBUG_ARGS, "PerformRename: ber_scanf failed" ); pResult->errCode = LDAP_PROTOCOL_ERROR; retVal = LDAP_NOTICE_OF_DISCONNECT; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Decoding error while parsing the end of message."); } retVal = pResult->errCode = VmDirMLModify( pOperation ); BAIL_ON_VMDIR_ERROR(retVal); cleanup: if (retVal != LDAP_NOTICE_OF_DISCONNECT) { VmDirSendLdapResult( pOperation ); } VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg); return retVal; error: VMDIR_APPEND_ERROR_MSG(pResult->pszErrMsg, pszLocalErrorMsg); goto cleanup; }
DWORD VmDirWriteQueuePush( PVDIR_BACKEND_CTX pBECtx, PVMDIR_WRITE_QUEUE pWriteQueue, PVMDIR_WRITE_QUEUE_ELEMENT pWriteQueueEle ) { int dbRetVal = 0; USN localUsn = 0; DWORD dwError = 0; BOOLEAN bInLock = FALSE; if (!pBECtx || !pWriteQueue || !pWriteQueueEle) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } if (pBECtx->wTxnUSN != 0) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s: acquiring multiple usn in same operation context, USN: %" PRId64, __FUNCTION__, pBECtx->wTxnUSN); BAIL_WITH_VMDIR_ERROR(dwError, LDAP_OPERATIONS_ERROR); } VMDIR_LOCK_MUTEX(bInLock, gVmDirServerOpsGlobals.pMutex); if ((dbRetVal = pBECtx->pBE->pfnBEGetNextUSN(pBECtx, &localUsn)) != 0) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s: pfnBEGetNextUSN failed with error code: %d", __FUNCTION__, dbRetVal); BAIL_WITH_VMDIR_ERROR(dwError, LDAP_OPERATIONS_ERROR); } pWriteQueueEle->usn = localUsn; dwError = VmDirLinkedListInsertTail( pWriteQueue->pList, (PVOID) pWriteQueueEle, NULL); BAIL_ON_VMDIR_ERROR(dwError); VMDIR_LOG_INFO(LDAP_DEBUG_WRITE_QUEUE, "%s: usn: %"PRId64, __FUNCTION__, localUsn); cleanup: VMDIR_UNLOCK_MUTEX(bInLock, gVmDirServerOpsGlobals.pMutex); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d) localUsn %"PRId64, dwError, localUsn); goto cleanup; }
int WritePagedSearchDoneControl( VDIR_OPERATION * op, BerElement * ber ) { int retVal = LDAP_OPERATIONS_ERROR; BerElementBuffer ctrlValBerbuf; BerElement * ctrlValBer = (BerElement *) &ctrlValBerbuf; VDIR_BERVALUE bvCtrlVal = VDIR_BERVALUE_INIT; if (!op || !op->showPagedResultsCtrl) { retVal = LDAP_PROTOCOL_ERROR; BAIL_ON_VMDIR_ERROR( retVal ); } if ( op->showPagedResultsCtrl) { VDIR_PAGED_RESULT_CONTROL_VALUE* prCtrlVal = &op->showPagedResultsCtrl->value.pagedResultCtrlVal; VMDIR_LOG_DEBUG( LDAP_DEBUG_TRACE, "WritePagedSearchDoneControl: Paged Search Done Control Value: pageSize[%d] cookie[%s]", prCtrlVal->pageSize, prCtrlVal->cookie ); (void) memset( (char *)&ctrlValBerbuf, '\0', sizeof( BerElementBuffer )); ber_init2( ctrlValBer, NULL, LBER_USE_DER ); if (ber_printf( ctrlValBer, "{is}", 0, prCtrlVal->cookie) == -1 ) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "SendLdapResult: ber_printf (to print Paged Search Done Control ...) failed" ); retVal = LDAP_OPERATIONS_ERROR; BAIL_ON_VMDIR_ERROR( retVal ); } bvCtrlVal.lberbv.bv_val = ctrlValBer->ber_buf; bvCtrlVal.lberbv.bv_len = ctrlValBer->ber_ptr - ctrlValBer->ber_buf; if (ber_printf(ber, "t{{sO}}", LDAP_TAG_CONTROLS, LDAP_CONTROL_PAGEDRESULTS, &bvCtrlVal.lberbv ) == -1) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "WritePagedSearchDoneControl: ber_printf (to print Search Done Control ...) failed" ); retVal = LDAP_OPERATIONS_ERROR; BAIL_ON_VMDIR_ERROR( retVal ); } } retVal = LDAP_SUCCESS; cleanup: ber_free_buf( ctrlValBer ); return retVal; error: goto cleanup; }
DWORD VmDirLogSearchRequest( SearchReq* pSReq, ber_len_t iNumAttr ) { DWORD dwError = 0; PSTR pszLogMsg = NULL; size_t currLen = 0; size_t msgSize = 0; int iCnt = 0; assert(pSReq); for ( iCnt = 0, msgSize = 0; iCnt<iNumAttr; iCnt++ ) { msgSize += pSReq->attrs[iCnt].lberbv.bv_len + 2 /* for a ',' and ' ' */; } dwError = VmDirAllocateMemory( msgSize + 1, (PVOID *)&pszLogMsg ); BAIL_ON_VMDIR_ERROR(dwError); for ( iCnt = 0, currLen = 0; iCnt<iNumAttr; iCnt++ ) { VmDirStringNPrintFA( pszLogMsg + currLen, (msgSize + 1 - currLen), msgSize, "%s, ", pSReq->attrs[iCnt].lberbv.bv_val); currLen += pSReq->attrs[iCnt].lberbv.bv_len + 2; } pszLogMsg[currLen - 2] = '\0'; VMDIR_LOG_VERBOSE( LDAP_DEBUG_ARGS, " Required attributes: %s", pszLogMsg ); cleanup: VMDIR_SAFE_FREE_MEMORY( pszLogMsg ); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "VmDirLogSearchRequest: dwError: %lu, msgSize: %lu, iNumAttr: %lu", dwError, msgSize, iNumAttr); for ( iCnt = 0; iCnt<iNumAttr; iCnt++ ) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, " attr[%d] len: %lu, val: \"%.*s\"", iCnt, pSReq->attrs[iCnt].lberbv.bv_len, 256, VDIR_SAFE_STRING(pSReq->attrs[iCnt].lberbv.bv_val)); } goto cleanup; }
/* Generates the LdapControl to be communicated to the client in the case of Strong Consistency Write task */ int WriteConsistencyWriteDoneControl( VDIR_OPERATION * pOp, BerElement * pBer ) { int retVal = LDAP_OPERATIONS_ERROR; BerElementBuffer ctrlValBerbuf; BerElement * pCtrlValBer = (BerElement *) &ctrlValBerbuf; VDIR_BERVALUE bvCtrlVal = VDIR_BERVALUE_INIT; DWORD dwStatus = 0; PSTR pControlsString = NULL; if (pOp == NULL || pBer == NULL) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "WriteConsistencyWriteDoneControl: VDIR_OPERATION or BerElement is NULL failed"); BAIL_ON_VMDIR_ERROR(retVal); } (void) memset((char *)&ctrlValBerbuf, '\0', sizeof(BerElementBuffer)); ber_init2(pCtrlValBer, NULL, LBER_USE_DER); dwStatus = pOp->strongConsistencyWriteCtrl->value.scwDoneCtrlVal.status; pControlsString = pOp->strongConsistencyWriteCtrl->type; if (ber_printf(pCtrlValBer, "{i}", dwStatus) == -1) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "WriteConsistencyWriteDoneControl: ber_printf (to print status...) failed"); BAIL_ON_VMDIR_ERROR(retVal); } bvCtrlVal.lberbv.bv_val = pCtrlValBer->ber_buf; bvCtrlVal.lberbv.bv_len = pCtrlValBer->ber_ptr - pCtrlValBer->ber_buf; if (ber_printf(pBer, "t{{sO}}", LDAP_TAG_CONTROLS, pControlsString, &bvCtrlVal.lberbv) == -1) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "WriteConsistencyWriteDoneControl: ber_printf (to print ldapControl...) failed"); BAIL_ON_VMDIR_ERROR(retVal); } retVal = LDAP_SUCCESS; cleanup: ber_free_buf(pCtrlValBer); return retVal; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "WriteConsistencyWriteDoneControl: failed"); goto cleanup; }
DWORD VmDirRESTAuthTokenInit( PVDIR_REST_AUTH_TOKEN* ppAuthToken ) { DWORD dwError = 0; PVDIR_REST_AUTH_TOKEN pAuthToken = NULL; if (!ppAuthToken) { dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } dwError = VmDirAllocateMemory( sizeof(VDIR_REST_AUTH_TOKEN), (PVOID*)&pAuthToken); BAIL_ON_VMDIR_ERROR(dwError); *ppAuthToken = pAuthToken; cleanup: return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError); VmDirFreeRESTAuthToken(pAuthToken); goto cleanup; }
static DWORD _VmDirDeadlockDetectionVectorPairToStr( LW_HASHMAP_PAIR pair, BOOLEAN bStart, PSTR* ppOutStr ) { PSTR pszTempStr = NULL; DWORD dwError = 0; VMDIR_LOG_INFO(LDAP_DEBUG_REPL, "%s: key: %s value: %d", (PSTR)pair.pKey, *(PDWORD)pair.pValue); if (bStart) { dwError = VmDirAllocateStringPrintf(&pszTempStr, "vector:%s:%d", pair.pKey, *(PDWORD)pair.pValue); BAIL_ON_VMDIR_ERROR(dwError); } else { dwError = VmDirAllocateStringPrintf(&pszTempStr, ",%s:%d", pair.pKey, *(PDWORD)pair.pValue); BAIL_ON_VMDIR_ERROR(dwError); } *ppOutStr = pszTempStr; pszTempStr = NULL; cleanup: VMDIR_SAFE_FREE_MEMORY(pszTempStr); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirDDVectorInit( VOID ) { DWORD dwError = 0; dwError = VmDirAllocateMemory( sizeof(VMDIR_REPL_DEADLOCKDETECTION_VECTOR), (PVOID*)&gVmdirServerGlobals.pReplDeadlockDetectionVector); BAIL_ON_VMDIR_ERROR(dwError); dwError = LwRtlCreateHashMap( &gVmdirServerGlobals.pReplDeadlockDetectionVector->pEmptyPageSentMap, LwRtlHashDigestPstrCaseless, LwRtlHashEqualPstrCaseless, NULL); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateMutex( &gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex); BAIL_ON_VMDIR_ERROR(dwError); cleanup: return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
static VOID _VmDirCollectBindSuperLog( PVDIR_CONNECTION pConn, PVDIR_OPERATION pOp ) { DWORD dwError = 0; pConn->SuperLogRec.iEndTime = VmDirGetTimeInMilliSec(); if (pOp->reqDn.lberbv.bv_val) // TODO, for failed SASL bind scenario, we need DN/UPN a well. { dwError = VmDirAllocateStringA(pOp->reqDn.lberbv.bv_val, &(pConn->SuperLogRec.pszBindID)); BAIL_ON_VMDIR_ERROR(dwError); } VmDirLogOperation(gVmdirGlobals.pLogger, LDAP_REQ_BIND, pConn, pOp->ldapResult.errCode); // // Flush times once we log. // pConn->SuperLogRec.iStartTime = pConn->SuperLogRec.iEndTime = 0; cleanup: return; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s failed, error code %d", __FUNCTION__, dwError); goto cleanup; }
DWORD VmDirDDVectorUpdate( PCSTR pszInvocationId, DWORD dwValue ) { DWORD dwError = 0; BOOLEAN bInLock = FALSE; dwError = VmDirAllocateStringA( pszInvocationId, &gVmdirServerGlobals.pReplDeadlockDetectionVector->pszInvocationId); BAIL_ON_VMDIR_ERROR(dwError); VMDIR_LOCK_MUTEX(bInLock, gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex); dwError = _VmDirDDVectorUpdateInLock(dwValue); BAIL_ON_VMDIR_ERROR(dwError); cleanup: VMDIR_UNLOCK_MUTEX(bInLock, gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirIndexUpdateAbort( PVDIR_INDEX_UPD pIndexUpd ) { DWORD dwError = 0; if (!pIndexUpd) { dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } if (pIndexUpd->bHasBETxn) { PVDIR_BACKEND_INTERFACE pBE = pIndexUpd->pBECtx->pBE; dwError = pBE->pfnBETxnAbort(pIndexUpd->pBECtx); BAIL_ON_VMDIR_ERROR(dwError); pIndexUpd->bHasBETxn = FALSE; } VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "%s succeeded", __FUNCTION__ ); cleanup: VmDirIndexUpdFree(pIndexUpd); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError ); goto cleanup; }
/* * API to backup database at the server side */ DWORD VmDirBackupDB( PVMDIR_SERVER_CONTEXT hServer, PCSTR pszBackupPath ) { DWORD dwError = 0; if (!hServer || !hServer->hBinding || IsNullOrEmptyString(pszBackupPath)) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = _VmDirBackupDBRInternal(hServer, pszBackupPath); BAIL_ON_VMDIR_ERROR(dwError); cleanup: return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s failed. Error[%d]\n", __FUNCTION__, dwError); goto cleanup; }
/* VmDirMDBDNToEntry: For a given entry DN, reads an entry from the entry DB. * * Returns: BE error - BACKEND_ERROR, BACKEND OPERATIONS, BACKEND_ENTRY_NOTFOUND * */ DWORD VmDirMDBDNToEntry( PVDIR_BACKEND_CTX pBECtx, PVDIR_SCHEMA_CTX pSchemaCtx, VDIR_BERVALUE* pDn, PVDIR_ENTRY pEntry, VDIR_BACKEND_ENTRY_LOCKTYPE entryLockType) { DWORD dwError = LDAP_SUCCESS; ENTRYID eId = {0}; // make sure we look up normalized dn value dwError = VmDirNormalizeDN( pDn, pSchemaCtx ); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirMDBDNToEntryId( pBECtx, pDn, &eId ); BAIL_ON_VMDIR_ERROR( dwError ); dwError = VmDirMDBEIdToEntry( pBECtx, pSchemaCtx, eId, pEntry, entryLockType ); BAIL_ON_VMDIR_ERROR( dwError ); cleanup: return dwError; error: VMDIR_LOG_ERROR( LDAP_DEBUG_BACKEND, "BEDNToEntry DN (%s) failed, (%u)(%s)", VDIR_SAFE_STRING( pDn->bvnorm_val), dwError, VDIR_SAFE_STRING(pBECtx->pszBEErrorMsg) ); VMDIR_SET_BACKEND_ERROR(dwError); // if dwError no in BE space, set to ERROR_BACKEND_ERROR goto cleanup; }
DWORD VmDirLdapOcAreCompat( PVDIR_LDAP_OBJECT_CLASS pPrevOc, PVDIR_LDAP_OBJECT_CLASS pNewOc ) { DWORD dwError = 0; if (!pPrevOc || !pNewOc) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } if (!VMDIR_TWO_STRING_COMPATIBLE( pNewOc->pszName, pPrevOc->pszName) || !VMDIR_TWO_STRING_COMPATIBLE( pNewOc->pszSup, pPrevOc->pszSup) || !VmDirIsStrArrayIdentical( pNewOc->ppszMust, pPrevOc->ppszMust) || !VmDirIsStrArraySuperSet( pNewOc->ppszMay, pPrevOc->ppszMay) || pNewOc->type != pPrevOc->type) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: cannot accept backward incompatible defn (%s).", __FUNCTION__, pPrevOc->pszName); dwError = VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE; BAIL_ON_VMDIR_ERROR(dwError); } error: return dwError; }
DWORD VmDirWriteQueueElementAllocate( PVMDIR_WRITE_QUEUE_ELEMENT* ppWriteQueueEle ) { DWORD dwError = 0; PVMDIR_WRITE_QUEUE_ELEMENT pWriteQueueEleLocal = NULL; if (!ppWriteQueueEle) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirAllocateMemory(sizeof(VMDIR_WRITE_QUEUE_ELEMENT), (PVOID)&pWriteQueueEleLocal); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateCondition(&pWriteQueueEleLocal->pCond); BAIL_ON_VMDIR_ERROR(dwError); *ppWriteQueueEle = pWriteQueueEleLocal; pWriteQueueEleLocal = NULL; cleanup: return dwError; error: VmDirWriteQueueElementFree(pWriteQueueEleLocal); pWriteQueueEleLocal = NULL; VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirMetricsInitialize( VOID ) { DWORD dwError = 0; dwError = VmMetricsInit(&pmContext); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLdapMetricsInit(); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirReplMetricsInit(); BAIL_ON_VMDIR_ERROR(dwError); dwError = _VmDirRpcMetricsInit(); BAIL_ON_VMDIR_ERROR(dwError); cleanup: return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "VmDirMetricsInitialize failed (%d)", dwError); goto cleanup; }
static DWORD VmDirSetEnvironment( VOID ) { DWORD dwError = 0; PSTR pszKrb5Conf = NULL; dwError = VmDirRegReadKrb5Conf(&pszKrb5Conf); if (dwError) { dwError = VmDirAllocateStringA(VMDIR_DEFAULT_KRB5_CONF, &pszKrb5Conf); BAIL_ON_VMDIR_ERROR(dwError); } if (-1 == setenv("KRB5_CONFIG", pszKrb5Conf, 1)) { dwError = ERROR_NO_MEMORY; BAIL_ON_VMDIR_ERROR(dwError); } cleanup: VMDIR_SAFE_FREE_STRINGA(pszKrb5Conf); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "VmDirSetEnvironment failed (%u)", dwError); goto cleanup; }
static DWORD _VmDirUTDVectorStrToPair( PSTR pszKey, PSTR pszValue, LW_HASHMAP_PAIR* pPair ) { PSTR pszDupKey = NULL; DWORD dwError = 0; USN Usn = 0; dwError = VmDirAllocateStringA(pszKey, &pszDupKey); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirStringToINT64(pszValue, NULL, &Usn); BAIL_ON_VMDIR_ERROR(dwError); pPair->pKey = (PVOID) pszDupKey; pPair->pValue = (PVOID) Usn; pszDupKey = NULL; cleanup: VMDIR_SAFE_FREE_MEMORY(pszDupKey); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
static DWORD _VmDirUTDVectorPairToStr( LW_HASHMAP_PAIR pair, BOOLEAN bFirst, PSTR* ppOutStr ) { PSTR pszTempStr = NULL; DWORD dwError = 0; dwError = VmDirAllocateStringPrintf(&pszTempStr, "%s:%"PRId64",", pair.pKey, (USN)pair.pValue); BAIL_ON_VMDIR_ERROR(dwError); *ppOutStr = pszTempStr; pszTempStr = NULL; cleanup: VMDIR_SAFE_FREE_MEMORY(pszTempStr); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirUTDVectorCacheLookup( PVMDIR_UTDVECTOR_CACHE pUTDVector, PCSTR pszInvocationId, USN* pUsn ) { DWORD dwError = 0; BOOLEAN bInLock = FALSE; uintptr_t usn = 0; PVMDIR_UTDVECTOR_CACHE pCache = pUTDVector; if (IsNullOrEmptyString(pszInvocationId) || !pUsn || !pUTDVector) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } VMDIR_RWLOCK_READLOCK(bInLock, pCache->pUtdVectorLock, 0); dwError = LwRtlHashMapFindKey(pCache->pUtdVectorMap, (PVOID*)&usn, pszInvocationId); BAIL_ON_VMDIR_ERROR(dwError); *pUsn = (USN)usn; cleanup: VMDIR_RWLOCK_UNLOCK(bInLock, pCache->pUtdVectorLock); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirUTDVectorCacheToString( PVMDIR_UTDVECTOR_CACHE pUTDVector, PSTR* ppszUTDVector ) { DWORD dwError = 0; BOOLEAN bInLock = FALSE; PSTR pszUTDVector = NULL; if (!pUTDVector || !ppszUTDVector) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } VMDIR_RWLOCK_READLOCK(bInLock, pUTDVector->pUtdVectorLock, 0); dwError = VmDirAllocateStringA(pUTDVector->pszUtdVector, &pszUTDVector); BAIL_ON_VMDIR_ERROR(dwError); *ppszUTDVector = pszUTDVector; cleanup: VMDIR_RWLOCK_UNLOCK(bInLock, pUTDVector->pUtdVectorLock); return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirRESTCacheInit( PVDIR_REST_HEAD_CACHE* ppRestCache ) { DWORD dwError = 0; PVDIR_REST_HEAD_CACHE pRestCache = NULL; if (!ppRestCache) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirAllocateMemory( sizeof(VDIR_REST_HEAD_CACHE), (PVOID*)&pRestCache); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateRWLock(&pRestCache->pRWLock); BAIL_ON_VMDIR_ERROR(dwError); *ppRestCache = pRestCache; cleanup: return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError); VmDirFreeRESTCache(pRestCache); goto cleanup; }
int ParseSyncStateControlVal( BerValue * controlValue, // Input: control value encoded as ber, int * entryState) // Output { int retVal = LDAP_SUCCESS; BerElementBuffer berbuf; BerElement * ber = (BerElement *)&berbuf; VMDIR_LOG_DEBUG( LDAP_DEBUG_TRACE, "ParseSyncStateControlVal: Begin." ); ber_init2( ber, controlValue, LBER_USE_DER ); if (ber_scanf( ber, "{i}", entryState ) == -1 ) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "ParseSyncStateControlVal: ber_scanf to read entryState failed" ); retVal = LDAP_OPERATIONS_ERROR; BAIL_ON_VMDIR_ERROR( retVal ); } cleanup: VMDIR_LOG_DEBUG( LDAP_DEBUG_TRACE, "ParseSyncStateControlVal: Begin." ); return retVal; error: goto cleanup; }
DWORD VmDirLdapAtAreCompat( PVDIR_LDAP_ATTRIBUTE_TYPE pPrevAt, PVDIR_LDAP_ATTRIBUTE_TYPE pNewAt ) { DWORD dwError = 0; if (!pPrevAt || !pNewAt) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } if (!VMDIR_TWO_STRING_COMPATIBLE( pNewAt->pszName, pPrevAt->pszName) || !VMDIR_TWO_STRING_COMPATIBLE( pNewAt->pszSyntaxOid, pPrevAt->pszSyntaxOid) || !VMDIR_TWO_BOOL_COMPATILBE_T2F( pNewAt->bSingleValue, pPrevAt->bSingleValue) || pNewAt->bNoUserMod != pPrevAt->bNoUserMod || (pPrevAt->usage && pNewAt->usage != pPrevAt->usage)) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: cannot accept backward incompatible defn (%s).", __FUNCTION__, pPrevAt->pszName); dwError = VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE; BAIL_ON_VMDIR_ERROR(dwError); } error: return dwError; }
DWORD VmDirMetaDataSerialize( PVMDIR_ATTRIBUTE_METADATA pMetadata, PSTR pszMetadata ) { DWORD dwError = 0; if (VmDirMetaDataIsEmpty(pMetadata) || !pszMetadata) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirStringPrintFA( pszMetadata, VMDIR_MAX_ATTR_META_DATA_LEN, "%"PRId64":%"PRId64":%s:%s:%"PRId64, pMetadata->localUsn, pMetadata->version, pMetadata->pszOrigInvoId, pMetadata->pszOrigTime, pMetadata->origUsn); BAIL_ON_VMDIR_ERROR(dwError); cleanup: return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
DWORD VmDirLdapCrAreCompat( PVDIR_LDAP_CONTENT_RULE pPrevCr, PVDIR_LDAP_CONTENT_RULE pNewCr ) { DWORD dwError = 0; if (!pPrevCr || !pNewCr) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } if (!VMDIR_TWO_STRING_COMPATIBLE( pNewCr->pszName, pPrevCr->pszName) || !VmDirIsStrArrayIdentical( pNewCr->ppszMust, pPrevCr->ppszMust) || !VmDirIsStrArraySuperSet( pNewCr->ppszMay, pPrevCr->ppszMay) || !VmDirIsStrArraySuperSet( pNewCr->ppszAux, pPrevCr->ppszAux)) { VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: cannot accept backward incompatible defn (%s).", __FUNCTION__, pPrevCr->pszName); dwError = VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE; BAIL_ON_VMDIR_ERROR(dwError); } error: return dwError; }
static DWORD _VmDirMkdir( PCSTR path, int mode ) { DWORD dwError = 0; #ifdef _WIN32 if(CreateDirectory(path, NULL)==0) { errno = WSAGetLastError(); dwError = VMDIR_ERROR_IO; goto error; } #else if(mkdir(path, mode)!=0) { dwError = VMDIR_ERROR_IO; goto error; } #endif cleanup: return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "_VmDirMkdir on dir %s failed (%u) errno: (%d)", path, dwError, errno); goto cleanup; }
DWORD VmDirMetaDataCopyContent( PVMDIR_ATTRIBUTE_METADATA pSrcMetaData, PVMDIR_ATTRIBUTE_METADATA pDestMetaData ) { DWORD dwError = 0; if (VmDirMetaDataIsEmpty(pSrcMetaData) || !pDestMetaData) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } pDestMetaData->localUsn = pSrcMetaData->localUsn; pDestMetaData->version = pSrcMetaData->version; VMDIR_SAFE_FREE_MEMORY(pDestMetaData->pszOrigInvoId); dwError = VmDirAllocateStringA(pSrcMetaData->pszOrigInvoId, &pDestMetaData->pszOrigInvoId); BAIL_ON_VMDIR_ERROR(dwError); VMDIR_SAFE_FREE_MEMORY(pDestMetaData->pszOrigTime); dwError = VmDirAllocateStringA(pSrcMetaData->pszOrigTime, &pDestMetaData->pszOrigTime); BAIL_ON_VMDIR_ERROR(dwError); pDestMetaData->origUsn = pSrcMetaData->origUsn; cleanup: return dwError; error: VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
/* last_pgno and max_pgs are logged. If last_pgno + pages for adding new data > max_pgs, mdb_put will fail with error MDB_MAP_FULL. Mdb first tries to reuse released pages before trying to get new pages from the free list. Thus even if an operation request new pages failed (last_pgno + pages > max_pgs), adding smaller data may still succeeded if the there are enough pages in the released pages. Max memory can be calculated from max_pgs * page size which is the same as the OS page size. */ void VmDirLogDBStats( PVDIR_MDB_DB pDB ) { MDB_envinfo env_stats = {0}; MDB_stat db_stats = {0}; assert(pDB); if (mdb_env_info(pDB->mdbEnv, &env_stats) != MDB_SUCCESS || mdb_env_stat(pDB->mdbEnv, &db_stats)!= MDB_SUCCESS) { goto error; } VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "mdb stats: last_pgno %llu, max_pgs %lld", env_stats.me_last_pgno, env_stats.me_mapsize/db_stats.ms_psize); cleanup: return; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "Error retrieving MDB statistics"); goto cleanup; }