Beispiel #1
0
VOID
VmDirLogTerminate(
    VOID
    )
{
    if ( _gpVmDirLogCtx )
    {
        if ( _gpVmDirLogCtx->pFile )
        {
            fclose( _gpVmDirLogCtx->pFile );
        }

        if ( _gpVmDirLogCtx->bSyslog )
        {
            if ( _gpVmDirLogCtx->pszSyslogDaemon )
            {
                closelog();
                VMDIR_SAFE_FREE_MEMORY( _gpVmDirLogCtx->pszSyslogDaemon);
            }
        }

        VMDIR_SAFE_FREE_MEMORY( _gpVmDirLogCtx->pszLogFileName );
        VMDIR_SAFE_FREE_MEMORY( _gpVmDirLogCtx );
    }

    return;

}
Beispiel #2
0
/*
 * Free a heap Attribute
 * (ATTENTION: if the pAttr is within a pEntry, only when pEntry is constructed as
 * ENTRY_STORAGE_FORMAT_NORMAL allocation type, its attribute can be freed using this function;
 * otherwise, an entry's attribute free is taken care of by 'pEntry->bvs'
 */
VOID
VmDirFreeAttribute(
    PVDIR_ATTRIBUTE pAttr
    )
{
    if (!pAttr)
    {
        return;
    }

    // pAttr->type is always store in place and has NO bvnorm_val.  no need to free here.
    if (!dequeIsEmpty(&pAttr->valueMetaDataToAdd))
    {
        VmDirFreeAttrValueMetaDataDequeueContent(&pAttr->valueMetaDataToAdd);
    }
    if (!dequeIsEmpty(&pAttr->valueMetaDataToDelete))
    {
        VmDirFreeAttrValueMetaDataDequeueContent(&pAttr->valueMetaDataToDelete);
    }

    VmDirFreeMetaData(pAttr->pMetaData);

    VmDirFreeBervalContent(&pAttr->type);
    VmDirFreeBervalArrayContent(pAttr->vals, pAttr->numVals);
    VMDIR_SAFE_FREE_MEMORY(pAttr->vals);
    VMDIR_SAFE_FREE_MEMORY(pAttr);
}
Beispiel #3
0
VOID
VmDirFreeUTDVectorCache(
    PVMDIR_UTDVECTOR_CACHE  pUTDVector
    )
{
    BOOLEAN bInLock = FALSE;

    if (!pUTDVector)
    {
        return;
    }

    VMDIR_RWLOCK_WRITELOCK(bInLock, pUTDVector->pUtdVectorLock, 0);

    if (pUTDVector->pUtdVectorMap)
    {
        LwRtlHashMapClear(pUTDVector->pUtdVectorMap, VmDirSimpleHashMapPairFreeKeyOnly, NULL);
        LwRtlFreeHashMap(&pUTDVector->pUtdVectorMap);
    }
    VMDIR_SAFE_FREE_MEMORY(pUTDVector->pszUtdVector);

    VMDIR_RWLOCK_UNLOCK(bInLock, pUTDVector->pUtdVectorLock);
    VMDIR_SAFE_FREE_RWLOCK(pUTDVector->pUtdVectorLock);

    VMDIR_SAFE_FREE_MEMORY(pUTDVector);
}
Beispiel #4
0
static
DWORD
_VmDirMDBInitializeDBEntry(
    const char *pszDBPath,
    PVDIR_MDB_DB *ppDB
    )
{
    DWORD dwError = 0;
    PVDIR_MDB_DB pDB = NULL;

    if (!pszDBPath || !ppDB)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirAllocateMemory (sizeof(VDIR_MDB_DB), ((PVOID*)&pDB));
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA (pszDBPath, &pDB->pszDBPath);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppDB = pDB;

cleanup:
    return dwError;

error:
    if (pDB)
    {
        VMDIR_SAFE_FREE_MEMORY(pDB->pszDBPath);
        VMDIR_SAFE_FREE_MEMORY(pDB);
    }
    goto cleanup;
}
Beispiel #5
0
VOID
VmDirFreeBervalContent(
    VDIR_BERVALUE* pBerv
    )
{
    if (!pBerv)
    {
        return;
    }

    if (pBerv->bvnorm_val != NULL &&
        pBerv->bvnorm_val != pBerv->lberbv.bv_val)
    {
        VMDIR_SAFE_FREE_MEMORY(pBerv->bvnorm_val);
    }

    if (pBerv->bOwnBvVal)
    {
        VMDIR_SAFE_FREE_MEMORY(pBerv->lberbv.bv_val);
    }

    memset(pBerv, 0, sizeof(*pBerv));

    return;
}
Beispiel #6
0
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;
}
Beispiel #7
0
/*
 * Free SASL related resources.
 */
VOID
VmDirSASLSessionClose(
    PVDIR_SASL_BIND_INFO    pSaslBindInfo
    )
{
    if (pSaslBindInfo)
    {
        if (pSaslBindInfo->pSaslCtx)
        {
            if (pSaslBindInfo->saslSSF > 0)
            {
                VmDirSASLSockbufRemove(pSaslBindInfo->pSockbuf);
            }

            sasl_dispose(&pSaslBindInfo->pSaslCtx);
            pSaslBindInfo->pSaslCtx = NULL;
        }

        VMDIR_SAFE_FREE_MEMORY(pSaslBindInfo->pSessionCB);
        VMDIR_SAFE_FREE_MEMORY(pSaslBindInfo->pszBindUserName);
        VmDirFreeBervalContent(&pSaslBindInfo->bvMechnism);
    }

    return;
}
VOID
VmDirDDVectorShutdown(
    VOID
    )
{
    BOOLEAN bInLock = FALSE;

    if (gVmdirServerGlobals.pReplDeadlockDetectionVector)
    {
        VMDIR_LOCK_MUTEX(bInLock, gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex);

        if (gVmdirServerGlobals.pReplDeadlockDetectionVector->pEmptyPageSentMap)
        {
            LwRtlHashMapClear(
                    gVmdirServerGlobals.pReplDeadlockDetectionVector->pEmptyPageSentMap,
                    VmDirSimpleHashMapPairFree,
                    NULL);
            LwRtlFreeHashMap(&gVmdirServerGlobals.pReplDeadlockDetectionVector->pEmptyPageSentMap);
        }

        VMDIR_SAFE_FREE_MEMORY(gVmdirServerGlobals.pReplDeadlockDetectionVector->pszInvocationId);

        VMDIR_UNLOCK_MUTEX(bInLock, gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex);
    }

    VMDIR_SAFE_FREE_MUTEX(gVmdirServerGlobals.pReplDeadlockDetectionVector->pMutex);
    VMDIR_SAFE_FREE_MEMORY(gVmdirServerGlobals.pReplDeadlockDetectionVector);
}
Beispiel #9
0
/*
 * When LdapSchema is created from file or subschema subentry, it contains
 * data which is no longer needed. Only relevant data should remain in order
 * to keep LdapSchema instance always consistent.
 */
DWORD
VmDirLdapSchemaRemoveNoopData(
    PVDIR_LDAP_SCHEMA   pSchema
    )
{
    DWORD dwError = 0;
    LW_HASHMAP_ITER atIter = LW_HASHMAP_ITER_INIT;
    LW_HASHMAP_ITER crIter = LW_HASHMAP_ITER_INIT;
    LW_HASHMAP_PAIR pair = {NULL, NULL};

    if (!pSchema)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    while (LwRtlHashMapIterate(pSchema->attributeTypes, &atIter, &pair))
    {
        PVDIR_LDAP_ATTRIBUTE_TYPE pAt = (PVDIR_LDAP_ATTRIBUTE_TYPE)pair.pValue;
        VMDIR_SAFE_FREE_MEMORY(pAt->pSource->at_equality_oid);
        VMDIR_SAFE_FREE_MEMORY(pAt->pSource->at_ordering_oid);
        VMDIR_SAFE_FREE_MEMORY(pAt->pSource->at_substr_oid);
        VMDIR_SAFE_FREE_MEMORY(pAt->pSource->at_sup_oid);
        pAt->pSource->at_syntax_len = 0;
    }

    while (LwRtlHashMapIterate(pSchema->contentRules, &crIter, &pair))
    {
        PVDIR_LDAP_CONTENT_RULE pCr = (PVDIR_LDAP_CONTENT_RULE)pair.pValue;
        VMDIR_SAFE_FREE_MEMORY(pCr->pSource->cr_desc);
    }

error:
    return dwError;
}
Beispiel #10
0
VOID
VmDirFreeBervalArrayContent(
    PVDIR_BERVALUE pBervs,
    USHORT  usSize
    )
{
    USHORT usCnt = 0;

    if (pBervs != NULL)
    {
        for (usCnt = 0; usCnt < usSize; usCnt++)
        {
            if (pBervs[usCnt].bvnorm_val != NULL &&
                pBervs[usCnt].bvnorm_val != pBervs[usCnt].lberbv.bv_val)
            {
                VMDIR_SAFE_FREE_MEMORY(pBervs[usCnt].bvnorm_val);
            }

            if (pBervs[usCnt].bOwnBvVal)
            {
                VMDIR_SAFE_FREE_MEMORY(pBervs[usCnt].lberbv.bv_val);
            }

        }

        memset(pBervs, 0, sizeof(*pBervs) * usSize);
    }
}
Beispiel #11
0
VOID
VmDirMDBIndexIteratorFree(
    PVDIR_BACKEND_INDEX_ITERATOR    pIterator
    )
{
    PVDIR_MDB_INDEX_ITERATOR    pMdbIterator = NULL;

    if (pIterator)
    {
        pMdbIterator = (PVDIR_MDB_INDEX_ITERATOR)pIterator->pIterator;
        if (pMdbIterator)
        {
            if (pMdbIterator->pCursor)
            {
                mdb_cursor_close(pMdbIterator->pCursor);
            }
            if (pMdbIterator->pTxn)
            {
                if (pMdbIterator->bAbort)
                {
                    mdb_txn_abort(pMdbIterator->pTxn);
                }
                else
                {
                    mdb_txn_commit(pMdbIterator->pTxn);
                }
            }
            VMDIR_SAFE_FREE_MEMORY(pMdbIterator->pszVal);
            VMDIR_SAFE_FREE_MEMORY(pMdbIterator);
        }
        VMDIR_SAFE_FREE_MEMORY(pIterator);
    }
}
Beispiel #12
0
static
DWORD
_VmDirRidSyncThr(
    PVOID    pArg
    )
{
    DWORD               dwError = 0;
    BOOLEAN             bInLock = FALSE;
    PVDIR_THREAD_INFO   pThrInfo = (PVDIR_THREAD_INFO)pArg;
    PVMDIR_SID_GEN_STACK_NODE pSidGenStackNode = NULL;

    VMDIR_LOG_VERBOSE( VMDIR_LOG_MASK_ALL, "_VmDirRidSyc thr started" );

    while (1)
    {
        if (VmDirdState() == VMDIRD_STATE_SHUTDOWN)
        {
            goto cleanup;
        }

        VMDIR_SAFE_FREE_MEMORY(pSidGenStackNode);
        while (VmDirPopTSStack(gSidGenState.pStack, (PVOID*)&pSidGenStackNode) == 0 &&
               pSidGenStackNode != NULL)
        {
            (VOID)VmDirSyncRIDSeqToDB(
                    pSidGenStackNode->pszDomainDn,
                    pSidGenStackNode->dwDomainRidSequence);

            if (VmDirdState() == VMDIRD_STATE_SHUTDOWN)
            {
                //
                // Any pending updates will be performed by VmDirVmAclShutdown.
                //
                goto cleanup;
            }

            VMDIR_SAFE_FREE_MEMORY(pSidGenStackNode);
        }

        VMDIR_LOCK_MUTEX(bInLock, pThrInfo->mutexUsed);

        VmDirConditionTimedWait(
            pThrInfo->conditionUsed,
            pThrInfo->mutexUsed,
            3 * 1000);          // time wait 3 seconds
        // ignore error

        VMDIR_UNLOCK_MUTEX(bInLock, pThrInfo->mutexUsed);
    }

cleanup:

    VMDIR_LOG_VERBOSE( VMDIR_LOG_MASK_ALL, "_VmDirRidSyc thr stopped (%d)", dwError );

    VMDIR_SAFE_FREE_MEMORY(pSidGenStackNode);

    return dwError;
}
Beispiel #13
0
VOID
VdcHashMapFreeStringPair(
    PLW_HASHMAP_PAIR pPair,
    LW_PVOID pUserData
    )
{
    VMDIR_SAFE_FREE_MEMORY(pPair->pKey);
    VMDIR_SAFE_FREE_MEMORY(pPair->pValue);
}
Beispiel #14
0
static
DWORD
_VmGetHighestCommittedUSN(
    PSTR*   ppszHighestCommittedUSN
    )
{
    DWORD               dwError = 0;
    USN                 usn = 0;
    USN                 nextUSN = 0;
    VDIR_ENTRY_ARRAY    entryArray = {0};
    PSTR                pszUSN = NULL;
    VDIR_BACKEND_CTX    beCtx = {0};

    beCtx.pBE = VmDirBackendSelect(NULL);
    assert(beCtx.pBE);

    dwError = beCtx.pBE->pfnBEGetNextUSN(&beCtx, &nextUSN);
    BAIL_ON_VMDIR_ERROR(dwError);

    for (usn=nextUSN; usn > 1LL; usn--)
    {
        VMDIR_SAFE_FREE_MEMORY(pszUSN);
        VmDirFreeEntryArrayContent(&entryArray);

        dwError = VmDirAllocateStringPrintf(&pszUSN, "%" PRId64, usn);
        BAIL_ON_VMDIR_ERROR(dwError);

        dwError = VmDirSimpleEqualFilterInternalSearch(
                    "", LDAP_SCOPE_SUBTREE, ATTR_USN_CHANGED, pszUSN, &entryArray);
        BAIL_ON_VMDIR_ERROR(dwError);

        if (entryArray.iSize == 1 )
        {
            break;
        }
    }

    if (usn == 0)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_STATE);
    }

    *ppszHighestCommittedUSN = pszUSN;
    pszUSN = NULL;

cleanup:
    VMDIR_SAFE_FREE_MEMORY(pszUSN);
    VmDirFreeEntryArrayContent(&entryArray);
    VmDirBackendCtxContentFree(&beCtx);

    return dwError;

error:
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "error (%u), start USN %" PRId64, dwError, nextUSN);
    goto cleanup;
}
Beispiel #15
0
DWORD
VmDirIndexUpdateCommit(
    PVDIR_INDEX_UPD     pIndexUpd
    )
{
    DWORD   dwError = 0;
    LW_HASHMAP_ITER iter = LW_HASHMAP_ITER_INIT;
    LW_HASHMAP_PAIR pair = {NULL, NULL};
    PSTR            pszStatus = NULL;

    if (!pIndexUpd)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    while (LwRtlHashMapIterate(pIndexUpd->pUpdIndexCfgMap, &iter, &pair))
    {
        PVDIR_INDEX_CFG pIndexCfg = (PVDIR_INDEX_CFG)pair.pValue;

        dwError = VmDirIndexCfgRecordProgress(pIndexUpd->pBECtx, pIndexCfg);
        BAIL_ON_VMDIR_ERROR(dwError);

        VMDIR_SAFE_FREE_MEMORY(pszStatus);
        dwError = VmDirIndexCfgStatusStringfy(pIndexCfg, &pszStatus);
        BAIL_ON_VMDIR_ERROR(dwError);

        VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, pszStatus );
    }

    if (pIndexUpd->bHasBETxn)
    {
        PVDIR_BACKEND_INTERFACE pBE = pIndexUpd->pBECtx->pBE;

        dwError = pBE->pfnBETxnCommit(pIndexUpd->pBECtx);
        BAIL_ON_VMDIR_ERROR(dwError);
        pIndexUpd->bHasBETxn = FALSE;
    }

    VmDirIndexUpdFree(gVdirIndexGlobals.pIndexUpd);
    gVdirIndexGlobals.pIndexUpd = pIndexUpd;

    VmDirConditionSignal(gVdirIndexGlobals.cond);

    VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "%s succeeded", __FUNCTION__ );

cleanup:
    VMDIR_SAFE_FREE_MEMORY(pszStatus);
    return dwError;

error:
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL,
            "%s failed, error (%d)", __FUNCTION__, dwError );

    goto cleanup;
}
Beispiel #16
0
static
VOID
_FreeSearchInformation(
        PVMDIR_SUPERLOG_ENTRY_LDAPOPERATION pEntry)
{
    VMDIR_SAFE_FREE_MEMORY(pEntry->opInfo.searchInfo.pwszAttributes);
    VMDIR_SAFE_FREE_MEMORY(pEntry->opInfo.searchInfo.pwszBaseDN);
    VMDIR_SAFE_FREE_MEMORY(pEntry->opInfo.searchInfo.pwszScope);
    VMDIR_SAFE_FREE_MEMORY(pEntry->opInfo.searchInfo.pwszIndexResults);
}
Beispiel #17
0
static
VOID
_FreeStringPair(
    PLW_HASHMAP_PAIR pPair,
    LW_PVOID pUnused
    )
{
    VMDIR_SAFE_FREE_MEMORY(pPair->pKey);
    VMDIR_SAFE_FREE_MEMORY(pPair->pValue);
}
Beispiel #18
0
static
PVOID
ThreadFunction(
    PVOID pArgs
    )
{
    DWORD dwError = ERROR_SUCCESS;
    PVMDIR_START_ROUTINE pThreadStart = NULL;
    PVOID pThreadArgs = NULL;
    PVMDIR_THREAD_LOG_CONTEXT   pLogCtx = NULL;
    PVMDIR_THREAD_TXN_CONTEXT   pTxnCtx = NULL;

    union
    {
        DWORD dwError;
        PVOID pvRet;
    } retVal;

    memset(&retVal, 0, sizeof(retVal));
    if( pArgs == NULL)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    pThreadStart = ((PVMDIR_THREAD_START_INFO)pArgs)->pStartRoutine;
    pThreadArgs = ((PVMDIR_THREAD_START_INFO)pArgs)->pArgs;

    if( pThreadStart == NULL )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    VMDIR_SAFE_FREE_MEMORY( pArgs );

    // set thread log context so error logs will show function name and line number
    dwError = VmDirAllocAndSetThrLogCtx(&pLogCtx);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocAndSetThrTxnCtx(&pTxnCtx);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = pThreadStart( pThreadArgs );
    BAIL_ON_VMDIR_ERROR(dwError);

error:
    VmDirUnsetAndFreeThrLogCtx(pLogCtx);
    VmDirUnsetAndFreeThrTxnCtx(pTxnCtx);

    VMDIR_SAFE_FREE_MEMORY( pArgs );

    retVal.dwError = dwError;
    return retVal.pvRet;
}
Beispiel #19
0
DWORD
VmDirUPNToAccountDN(
    PCSTR       pszUPNName,
    PCSTR       pszAccountRDNAttr,
    PCSTR       pszAccountRDNValue,
    PSTR*       ppszAccountDN
    )
{
    DWORD       dwError = 0;
    PSTR        pszRealm = NULL;
    PSTR        pszLocalDomainDN = NULL;
    PSTR        pszLocalAccountDN = NULL;

    if (    IsNullOrEmptyString(pszUPNName)                 ||
            IsNullOrEmptyString(pszAccountRDNAttr)          ||
            IsNullOrEmptyString(pszAccountRDNValue)         ||
            (ppszAccountDN == NULL)
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    pszRealm = VmDirStringRChrA(pszUPNName, VMDIR_UPN_REALM_SEPARATOR);
    if (pszRealm == NULL || pszRealm[1] == '\0')
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirFQDNToDN(pszRealm+1, &pszLocalDomainDN);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringAVsnprintf(
                    &pszLocalAccountDN,
                    "%s=%s,%s,%s",
                    pszAccountRDNAttr,
                    pszAccountRDNValue,
                    DEFAULT_USER_CONTAINER_RDN,
                    pszLocalDomainDN);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppszAccountDN = pszLocalAccountDN;

cleanup:

    VMDIR_SAFE_FREE_MEMORY(pszLocalDomainDN);

    return dwError;

error:

    VMDIR_SAFE_FREE_MEMORY(pszLocalAccountDN);
    goto cleanup;
}
Beispiel #20
0
static
DWORD
_VmDirGetReplicateStatusCycle(
    PCSTR   pszHostName,
    PCSTR   pszUserName,
    PCSTR   pszPassword
    )
{
    DWORD   dwError = 0;
    PSTR    pszDomainName = NULL;
    PSTR    pszURI = NULL;
    DWORD   dwCycleCount = 0;
    PVMDIR_CONNECTION pConnection = NULL;

    if ( VmDirIsIPV6AddrFormat( pszHostName ) )
    {
        dwError = VmDirAllocateStringPrintf( &pszURI, "ldap://[%s]", pszHostName );
        BAIL_ON_VMDIR_ERROR(dwError);
    }
    else
    {
        dwError = VmDirAllocateStringPrintf( &pszURI, "ldap://%s", pszHostName );
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirGetDomainName( pszHostName, &pszDomainName );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirConnectionOpen( pszURI, pszDomainName, pszUserName, pszPassword, &pConnection );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirGetReplicationCycleCount( pConnection, &dwCycleCount );
    BAIL_ON_VMDIR_ERROR(dwError);

    if (dwCycleCount == 0)
    {
        printf("First replication cycle done: FALSE\n");
    }
    else
    {
        printf("First replication cycle done: TRUE\n");
    }

cleanup:
    VMDIR_SAFE_FREE_MEMORY( pszURI );
    VMDIR_SAFE_FREE_MEMORY( pszDomainName );
    VmDirConnectionClose( pConnection );

    return dwError;

error:
    printf("First replication cycle done: UNKNOWN, error code (%u)\n", dwError);
    goto cleanup;
}
Beispiel #21
0
void
VmDirModificationFree(
    PVDIR_MODIFICATION pMod
    )
{
    if (pMod != NULL)
    {
        VmDirFreeBervalArrayContent( pMod->attr.vals, pMod->attr.numVals );
        VMDIR_SAFE_FREE_MEMORY( pMod->attr.vals );
        VMDIR_SAFE_FREE_MEMORY( pMod );
    }
}
Beispiel #22
0
VOID
VmDirFreeMetaDataContent(
    PVMDIR_ATTRIBUTE_METADATA    pMetaData
    )
{
    if (pMetaData)
    {
        VMDIR_SAFE_FREE_MEMORY(pMetaData->pszOrigInvoId);
        VMDIR_SAFE_FREE_MEMORY(pMetaData->pszOrigTime);
        memset(pMetaData, 0, sizeof(VMDIR_ATTRIBUTE_METADATA));
    }
}
Beispiel #23
0
DWORD
VmDirSchemaBervalSyntaxCheck(
    PVDIR_SCHEMA_CTX        pCtx,
    PVDIR_SCHEMA_AT_DESC    pATDesc,
    PVDIR_BERVALUE                 pBerv
    )
{
    DWORD dwError = 0;

    if (!pCtx || !pATDesc || !pBerv)
    {
        if (pCtx)
        {
            pCtx->dwErrorCode = ERROR_INVALID_PARAMETER;

            VMDIR_SAFE_FREE_MEMORY(pCtx->pszErrorMsg);
            dwError = VmDirAllocateStringA(
                    "No descriptor or value",
                    &pCtx->pszErrorMsg);
        }

        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    //TODO, if NO pSyntax, i.e. this syntax is NOT supported yet.
    // just bypass checking and move on.
    if (pATDesc->pSyntax &&
        pATDesc->pSyntax->pValidateFunc(pBerv) == FALSE)
    {
        pCtx->dwErrorCode = ERROR_INVALID_SYNTAX;

        VMDIR_SAFE_FREE_MEMORY(pCtx->pszErrorMsg);
        dwError = VmDirAllocateStringAVsnprintf(
                &pCtx->pszErrorMsg,
                "%s value (%s) is not a valid (%s) syntax",
                pATDesc->pszName,
                VDIR_SAFE_STRING(pBerv->lberbv.bv_val),
                VDIR_SAFE_STRING(pATDesc->pszSyntaxName));

        dwError = ERROR_INVALID_SYNTAX;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

cleanup:

    return dwError;

error:

    goto cleanup;
}
Beispiel #24
0
VOID
VmDirFreeThreadLogContext(
    PVMDIR_THREAD_LOG_CONTEXT pThreadLogContext
    )
{
    if (pThreadLogContext)
    {
        VMDIR_SAFE_FREE_MEMORY(pThreadLogContext->pszRequestId);
        VMDIR_SAFE_FREE_MEMORY(pThreadLogContext->pszSessionId);
        VMDIR_SAFE_FREE_MEMORY(pThreadLogContext->pszUserId);
        VMDIR_SAFE_FREE_MEMORY(pThreadLogContext);
    }
}
Beispiel #25
0
static
VOID
_VmDirFreeThreadTxnContext(
    PVMDIR_THREAD_TXN_CONTEXT pThreadTxnContext
    )
{
    if (pThreadTxnContext)
    {
        assert(pThreadContext->threadTxnContext);
        pthread_setspecific(pThreadContext->threadTxnContext, NULL);
        VMDIR_SAFE_FREE_MEMORY(pThreadTxnContext->mainDbTxnCtx.pszTxnId);
        VMDIR_SAFE_FREE_MEMORY(pThreadTxnContext);
    }
}
Beispiel #26
0
/* *************************************************************
 * if success, pAttr takes ownership of pBervs and its contents
 * *************************************************************
 * Assume pBervs itself is from ONE memory allocate.
 */
static
DWORD
AttributeAppendBervArray(
    PVDIR_ATTRIBUTE  pAttr,
    PVDIR_BERVALUE     pBervs,
    USHORT      usBervSize
    )
{
    DWORD   dwError = 0;
    PVDIR_BERVALUE pNewBerv = NULL;

    if (!pAttr || !pBervs)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // add one more BerValue in size as bdb-store/entry.c needs that.
    dwError = VmDirReallocateMemoryWithInit(
            pAttr->vals,
            (PVOID*) &pNewBerv,
            sizeof(VDIR_BERVALUE) * (pAttr->numVals + usBervSize + 1),
            sizeof(VDIR_BERVALUE) * (pAttr->numVals));
    BAIL_ON_VMDIR_ERROR(dwError);

    // takes over BerValue contents (i.e. lberbv.bv_val and lberbv.bv_len)
    dwError = VmDirCopyMemory(
        pNewBerv + pAttr->numVals,
        sizeof(VDIR_BERVALUE) * (pAttr->numVals + usBervSize + 1),
        pBervs,
        sizeof(VDIR_BERVALUE) * usBervSize
    );
    BAIL_ON_VMDIR_ERROR(dwError);

    // free array of BerValue itself
    VMDIR_SAFE_FREE_MEMORY(pBervs);

    pAttr->numVals += usBervSize;
    pAttr->vals = pNewBerv;

cleanup:

    return dwError;

error:

    VMDIR_SAFE_FREE_MEMORY(pNewBerv);

    goto cleanup;
}
Beispiel #27
0
static
DWORD
_OpenLdapConnection(
        PCSTR pszFQDomainName,
        PCSTR pszUsername,
        PCSTR pszPassword,
        PCSTR pszReplURI,
        LDAP **ppLd
        )
{
    DWORD dwError = 0;
    PSTR pszPartnerHostName = NULL;
    PSTR pszUPN = NULL;
    LDAP *pLd = NULL;

    dwError = VmDirReplURIToHostname((PSTR)pszReplURI, &pszPartnerHostName);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringPrintf(
            &pszUPN,
            "%s@%s",
            pszUsername,
            pszFQDomainName);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirSafeLDAPBind(
            &pLd,
            pszPartnerHostName,
            pszUPN,
            pszPassword);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppLd = pLd;

cleanup:
    VMDIR_SAFE_FREE_MEMORY(pszPartnerHostName);
    VMDIR_SAFE_FREE_MEMORY(pszUPN);
    return dwError;

error:
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL,
            "%s,%d failed, error(%d)", __FUNCTION__, __LINE__, dwError );

    if (pLd)
    {
        ldap_unbind_ext_s(pLd,NULL,NULL);
    }
    goto cleanup;
}
Beispiel #28
0
static
DWORD
_allocateSuperlogTable(
        DWORD tableSize,
        PVMDIR_SUPERLOG_TABLE_COLUMN_SET pCols,
        PVMDIR_SUPERLOG_TABLE *ppTable
        )
{
    DWORD dwError = 0;
    PVMDIR_SUPERLOG_TABLE pTable = NULL;

    dwError = VmDirAllocateMemory(
            sizeof(VMDIR_SUPERLOG_TABLE),
            (PVOID*)&pTable
            );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateAndCopyMemory(
            pCols,
            sizeof(VMDIR_SUPERLOG_TABLE_COLUMN_SET),
            (PVOID*)&pTable->cols
            );
    BAIL_ON_VMDIR_ERROR(dwError);

    pTable->numRows = tableSize;

    if (tableSize > 0)
    {
        dwError = VmDirAllocateMemory(
                sizeof(VMDIR_SUPERLOG_TABLE_ROW)*tableSize,
                (PVOID*)&pTable->rows
                );
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    *ppTable = pTable;

cleanup:
    return dwError;

error:
    if (pTable)
    {
        VMDIR_SAFE_FREE_MEMORY(pTable->rows);
        VMDIR_SAFE_FREE_MEMORY(pTable->cols);
        VMDIR_SAFE_FREE_MEMORY(pTable);
    }
    goto cleanup;
}
Beispiel #29
0
/*
 * Free a heap Attribute
 * (ATTENTION: if the pAttr is within a pEntry, only when pEntry is constructed as
 * ENTRY_STORAGE_FORMAT_NORMAL allocation type, its attribute can be freed using this function;
 * otherwise, an entry's attribute free is taken care of by 'pEntry->bvs'
 */
VOID
VmDirFreeAttribute(
    PVDIR_ATTRIBUTE pAttr
    )
{
    if (!pAttr)
    {
        return;
    }

    VmDirFreeBervalContent(&pAttr->type);
    VmDirFreeBervalArrayContent(pAttr->vals, pAttr->numVals);
    VMDIR_SAFE_FREE_MEMORY(pAttr->vals);
    VMDIR_SAFE_FREE_MEMORY(pAttr);
}
Beispiel #30
0
/*
 * Free a heap Attribute
 * (ATTENTION: if the pAttr is within a pEntry, only when pEntry is constructed as
 * ENTRY_STORAGE_FORMAT_NORMAL allocation type, its attribute can be freed using this function;
 * otherwise, an entry's attribute free is taken care of by 'pEntry->bvs'
 */
VOID
VmDirFreeAttribute(
    PVDIR_ATTRIBUTE pAttr
    )
{
    if (!pAttr)
    {
        return;
    }

    // pAttr->type is always store in place and has NO bvnorm_val.  no need to free here.
    VmDirFreeBervalArrayContent(pAttr->vals, pAttr->numVals);
    VMDIR_SAFE_FREE_MEMORY(pAttr->vals);
    VMDIR_SAFE_FREE_MEMORY(pAttr);
}