Exemplo n.º 1
0
DWORD
VmDirPrepareSwapDBInfo(
    PCSTR                   pszHostName,    // partner server object cn
    PVMDIR_SWAP_DB_INFO*    ppSwapDBInfo
    )
{
    DWORD       dwError = 0;
    PVMDIR_SWAP_DB_INFO pLocalSwapDBInfo = NULL;

    if (!ppSwapDBInfo)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirAllocateMemory(sizeof(VMDIR_SWAP_DB_INFO), (PVOID*)&pLocalSwapDBInfo);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (pszHostName)
    {
        dwError = VmDirAllocateStringA(pszHostName, &pLocalSwapDBInfo->pszPartnerServerName);
        BAIL_ON_VMDIR_ERROR(dwError);

        VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "My partner %s", pLocalSwapDBInfo->pszPartnerServerName);
    }

    dwError = VmDirInternalGetDSERootServerCN(&pLocalSwapDBInfo->pszOrgDBServerName);
    BAIL_ON_VMDIR_ERROR(dwError);

    VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "DB was from %s", pLocalSwapDBInfo->pszOrgDBServerName);

    dwError = _VmDirComposeUtdVector(pLocalSwapDBInfo);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (!pLocalSwapDBInfo->pszPartnerServerName ||      // no partner, DR case
        VmDirStringCompareA(                            // DB copied from joining partner
            pLocalSwapDBInfo->pszPartnerServerName,
            pLocalSwapDBInfo->pszOrgDBServerName,
            FALSE) == 0)
    {
        dwError = VmDirAllocateStringA(pLocalSwapDBInfo->pszOrgDBMaxUSN, &pLocalSwapDBInfo->pszMyHighWaterMark);
        BAIL_ON_VMDIR_ERROR(dwError);
    }
    else
    {   // DB from one node but join to another
        dwError = _VmDirComposeHighWaterMark(pLocalSwapDBInfo);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "My High Water Mark %s", pLocalSwapDBInfo->pszMyHighWaterMark);

    *ppSwapDBInfo = pLocalSwapDBInfo;

cleanup:
    return dwError;

error:
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, " error (%u)", dwError);
    VmDirFreeSwapDBInfo(pLocalSwapDBInfo);
    goto cleanup;
}
Exemplo n.º 2
0
DWORD
_VdcAddCopiesToHashTable(
    PLW_HASHMAP pHashMap,
    PCSTR pszKey,
    PCSTR pszValue
    )
{
    DWORD dwError = 0;
    PSTR pszKeyCopy = NULL;
    PSTR pszValueCopy = NULL;

    dwError = VmDirAllocateStringA(pszKey, &pszKeyCopy);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(pszValue, &pszValueCopy);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = LwRtlHashMapInsert(pHashMap, pszKeyCopy, pszValueCopy, NULL);
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    return dwError;

error:
    VMDIR_SAFE_FREE_STRINGA(pszKeyCopy);
    VMDIR_SAFE_FREE_STRINGA(pszValueCopy);
    goto cleanup;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
//pszMetadata: <local USN>:<version no>:<originating server ID>:<originating time>:<originating USN>
DWORD
VmDirMetaDataDeserialize(
    PCSTR                        pszMetaData,
    PVMDIR_ATTRIBUTE_METADATA*   ppMetaData
    )
{
    DWORD                 dwError = 0;
    PCSTR                 pDelimiter = ":";
    PVMDIR_STRING_LIST    pStrList = NULL;
    PVMDIR_ATTRIBUTE_METADATA    pMetaData = NULL;

    if (!pszMetaData || !ppMetaData)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirStringToTokenList(pszMetaData, pDelimiter, &pStrList);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (pStrList->dwCount != 5)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_BACKEND_INVALID_METADATA);
    }

    dwError = VmDirAllocateMemory(sizeof(VMDIR_ATTRIBUTE_METADATA), (PVOID*) &pMetaData);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringToINT64(pStrList->pStringList[0], NULL, &pMetaData->localUsn);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringToUINT64(pStrList->pStringList[1], NULL, &pMetaData->version);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(pStrList->pStringList[2], &pMetaData->pszOrigInvoId);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(pStrList->pStringList[3], &pMetaData->pszOrigTime);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringToINT64(pStrList->pStringList[4], NULL, &pMetaData->origUsn);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppMetaData = pMetaData;

cleanup:
    VmDirStringListFree(pStrList);
    return dwError;

error:
    VmDirFreeMetaData(pMetaData);
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError);
    goto cleanup;
}
Exemplo n.º 5
0
/*
 * BDB configuration are done in two stages -
 * 1. startup stage for fix DB (i.e. non configurable one like ENTRY)
 *    in InitBdbConfig()
 * 2. cn=indices stage to open all index DB
 *    in InitializeBDBIndexDB
 *
 */
DWORD
InitBdbConfig()
{
    DWORD   dwError = 0;

   VmDirLog( LDAP_DEBUG_TRACE, "InitBdbConfig: Begin" );

   // Initialize entry database
   dwError = VmDirAllocateMemory(
           sizeof(VDIR_CFG_BDB_DATAFILE_DESC) * 1,
           (PVOID)&gVdirBdbGlobals.bdbEntryDB.pBdbDataFiles);
   BAIL_ON_VMDIR_ERROR(dwError);

   gVdirBdbGlobals.bdbEntryDB.usNumDataFiles = 1;

   gVdirBdbGlobals.bdbEntryDB.pBdbDataFiles[0].bIsUnique = TRUE;

   dwError = VmDirAllocateStringA(
           VMDIR_ENTRY_DB,
           &gVdirBdbGlobals.bdbEntryDB.pBdbDataFiles[0].pszDBName);
   BAIL_ON_VMDIR_ERROR(dwError);

   dwError = VmDirAllocateStringA(
           VMDIR_DB_FILE_NAME,
           &gVdirBdbGlobals.bdbEntryDB.pBdbDataFiles[0].pszDBFile);
   BAIL_ON_VMDIR_ERROR(dwError);

   gVdirBdbGlobals.bdbEntryDB.btKeyCmpFcn = NULL;

   // Set hard limit of MAX index attribute
   //TODO, could make this configurable
   gVdirBdbGlobals.bdbIndexDBs.usMaxSize = BDB_MAX_INDEX_ATTRIBUTE;

   dwError = VmDirAllocateMemory(
           sizeof(VDIR_BDB_INDEX_DATABASE) * BDB_MAX_INDEX_ATTRIBUTE,
           (PVOID)&gVdirBdbGlobals.bdbIndexDBs.pIndexDBs);
   BAIL_ON_VMDIR_ERROR(dwError);

   VmDirLog( LDAP_DEBUG_TRACE, "InitBdbConfig: End" );

cleanup:

    return dwError;

error:

    goto cleanup;
}
Exemplo n.º 6
0
static
DWORD
_VmDirReplDCConnectInit(
    PVMDIR_REPLICATION_AGREEMENT    pReplAgr
    )
{
    DWORD   dwError = 0;

    pReplAgr->dcConn.connType = DC_CONNECTION_TYPE_REPL;
    pReplAgr->dcConn.creds.bUseDCAccountCreds = TRUE;
    pReplAgr->dcConn.dwConnectTimeoutSec = gVmdirGlobals.dwLdapConnectTimeoutSec;

    dwError = VmDirAllocateStringA(pReplAgr->pszHostname, &pReplAgr->dcConn.pszHostname);
    BAIL_ON_VMDIR_ERROR(dwError);

    // spawn background thread to handle connection
    VmDirInitDCConnThread(&pReplAgr->dcConn);

cleanup:
    return dwError;

error:
    pReplAgr->isDeleted = TRUE;

    VMDIR_LOG_ERROR(
            VMDIR_LOG_MASK_ALL,
            "%s: %s error code (%d)",
            __FUNCTION__,
            VDIR_SAFE_STRING(pReplAgr->ldapURI),
            dwError);

    goto cleanup;
}
Exemplo n.º 7
0
DWORD
VmDirSrvCreateAccessToken(
    PCSTR pszUPN,
    PVMDIR_SRV_ACCESS_TOKEN* ppAccessToken
    )
{
    DWORD dwError = 0;
    PVMDIR_SRV_ACCESS_TOKEN pAccessToken = NULL;

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

    pAccessToken->refCount = 1;

    dwError = VmDirAllocateStringA(pszUPN, &pAccessToken->pszUPN);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppAccessToken = pAccessToken;

cleanup:

    return dwError;

error:

    *ppAccessToken = NULL;

    if (pAccessToken)
    {
        VmDirSrvReleaseAccessToken(pAccessToken);
    }

    goto cleanup;
}
Exemplo n.º 8
0
DWORD
VmDirStringListAddStrClone(
    PCSTR               pszStr,
    PVMDIR_STRING_LIST  pStrList
    )
{
    DWORD   dwError = 0;
    PSTR    pszLocalStr = NULL;

    if (!pszStr || !pStrList)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirAllocateStringA(pszStr, &pszLocalStr);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringListAdd(pStrList, pszLocalStr);
    BAIL_ON_VMDIR_ERROR(dwError);
    pszLocalStr = NULL;

cleanup:
    VMDIR_SAFE_FREE_MEMORY(pszLocalStr);
    return dwError;

error:
    goto cleanup;
}
Exemplo n.º 9
0
static
DWORD
_VmDirGetDCCredsFromRegistry(
    PVMDIR_CONNECTION_CREDS pDCCreds
    )
{
    DWORD   dwError = 0;

    VmDirFreeConnCredContent(pDCCreds);

    dwError = VmDirAllocateStringA(
        gVmdirServerGlobals.dcAccountUPN.lberbv.bv_val,
        &pDCCreds->pszUPN);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirReadDCAccountPassword(&pDCCreds->pszPassword);
    BAIL_ON_VMDIR_ERROR(dwError);

    VmDirReadDCAccountOldPassword(&pDCCreds->pszOldPassword);  // ignore error

cleanup:
    return dwError;

error:
    goto cleanup;
}
Exemplo n.º 10
0
DWORD
_VdcGetAttributeFromEntry(
    LDAP *pLd,
    LDAPMessage* pEntry,
    PSTR pszAttributeName,
    PSTR *ppszAttributeValue
    )
{
    DWORD dwError = 0;
    PSTR pszAttributeValue = NULL;
    BerValue** ppBerValues = NULL;

    ppBerValues = ldap_get_values_len(pLd, pEntry, pszAttributeName);
    if (ppBerValues != NULL && ldap_count_values_len(ppBerValues) > 0)
    {
        dwError = VmDirAllocateStringA(ppBerValues[0][0].bv_val, &pszAttributeValue);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    *ppszAttributeValue = pszAttributeValue;

cleanup:
    if (ppBerValues)
    {
        ldap_value_free_len(ppBerValues);
        ppBerValues = NULL;
    }

    return dwError;

error:
    VMDIR_SAFE_FREE_STRINGA(pszAttributeValue);
    goto cleanup;
}
Exemplo n.º 11
0
/*
 * Allocate string into pDupBerval
 */
DWORD
VmDirStringToBervalContent(
    PCSTR              pszBerval,
    PVDIR_BERVALUE     pDupBerval
    )
{
    DWORD    dwError = 0;

    VmDirFreeBervalContent(pDupBerval);

    dwError = VmDirAllocateStringA(pszBerval, &pDupBerval->lberbv.bv_val);
    BAIL_ON_VMDIR_ERROR(dwError);

    pDupBerval->bOwnBvVal = TRUE;

    pDupBerval->lberbv.bv_len = VmDirStringLenA(pDupBerval->lberbv.bv_val);

cleanup:

    return dwError;

error:

    VmDirFreeBervalContent(pDupBerval);

    goto cleanup;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
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;
}
Exemplo n.º 18
0
static
int
_ParseCondWriteControlVal(
    VDIR_OPERATION *                        pOp,
    BerValue *                              pControlBer,    // Input: control value encoded as ber
    VDIR_CONDWRITE_CONTROL_VALUE *          pCtrlVal,       // Output
    VDIR_LDAP_RESULT *                      pLdapResult     // Output
    )
{
    int                 retVal = LDAP_SUCCESS;
    BerElementBuffer    berbuf;
    BerElement *        ber = (BerElement *)&berbuf;
    PSTR                pszLocalErrorMsg = NULL;
    PSTR                pszCondFilter = NULL;

    if (!pOp)
    {
        retVal = LDAP_PROTOCOL_ERROR;
        BAIL_ON_VMDIR_ERROR( retVal );
    }

    ber_init2( ber, pControlBer, LBER_USE_DER );

    /*
     * https://confluence.eng.vmware.com/display/LIG/Conditional+LDAP+Write+Operation
     *
     * The ConditionalWriteControl is a null terminated STRING wrapping the BER-encoded version of the following SEQUENCE:
     *
     * ControlValue ::= SEQUENCE {
     *        ConditionalWriteFilter            OCTET STRING
     *  }
     */

    if (ber_scanf(ber, "{a}", &pszCondFilter) == LBER_ERROR)
    {
        VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s: ber_scanf failed while parsing filter value", __FUNCTION__);
        pLdapResult->errCode = LDAP_PROTOCOL_ERROR;
        retVal = LDAP_NOTICE_OF_DISCONNECT;
        BAIL_ON_VMDIR_ERROR_WITH_MSG(   retVal, (pszLocalErrorMsg),
                                        "Error in reading conditional write control filter");
    }

    retVal = VmDirAllocateStringA(pszCondFilter, &(pCtrlVal->pszFilter));
    BAIL_ON_VMDIR_ERROR(retVal);

cleanup:
    if (pszCondFilter)
    {
        ber_memfree(pszCondFilter);
    }
    VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg);

    return retVal;

error:
    VMDIR_APPEND_ERROR_MSG(pLdapResult->pszErrMsg, pszLocalErrorMsg);
    goto cleanup;
}
Exemplo n.º 19
0
DWORD
VmDirMetaDataCreate(
    USN                           localUsn,
    UINT64                        version,
    PCSTR                         pszOrigInvoId,
    PCSTR                         pszOrigTimeStamp,
    USN                           origUsn,
    PVMDIR_ATTRIBUTE_METADATA*    ppMetaData
    )
{
    DWORD    dwError = 0;
    PVMDIR_ATTRIBUTE_METADATA   pMetaData = NULL;

    if (!ppMetaData        ||
        IsNullOrEmptyString(pszOrigInvoId) ||
        IsNullOrEmptyString(pszOrigTimeStamp))
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirAllocateMemory(sizeof(VMDIR_ATTRIBUTE_METADATA), (PVOID*) &pMetaData);
    BAIL_ON_VMDIR_ERROR(dwError);

    pMetaData->localUsn = localUsn;
    pMetaData->version = version;

    dwError = VmDirAllocateStringA(pszOrigInvoId, &pMetaData->pszOrigInvoId);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateStringA(pszOrigTimeStamp, &pMetaData->pszOrigTime);
    BAIL_ON_VMDIR_ERROR(dwError);

    pMetaData->origUsn = origUsn;

    *ppMetaData = pMetaData;

cleanup:
    return dwError;

error:
    VmDirFreeMetaData(pMetaData);
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError);
    goto cleanup;
}
Exemplo n.º 20
0
static
DWORD
_convertHashMapToSuperlogTable(
        PLW_HASHMAP pHashMap,
        PVMDIR_SUPERLOG_TABLE_COLUMN_SET pCols,
        PVMDIR_SUPERLOG_TABLE *ppTable
        )
{
    DWORD                   dwError = 0;
    DWORD                   dwCount = 0;
    PVMDIR_SUPERLOG_TABLE   pTable  = NULL;

    LW_HASHMAP_ITER iter = LW_HASHMAP_ITER_INIT;
    LW_HASHMAP_PAIR pair = {NULL, NULL};
    unsigned int i = 0;
    unsigned int j;

    PVMDIR_SUPERLOG_TABLE_ROW pSrcRow = NULL;
    PVMDIR_SUPERLOG_TABLE_ROW pDstRow = NULL;

    dwCount = LwRtlHashMapGetCount(pHashMap);

    dwError = _allocateSuperlogTable(dwCount, pCols, &pTable);
    BAIL_ON_VMDIR_ERROR(dwError);

    while (LwRtlHashMapIterate(pHashMap, &iter, &pair))
    {
        pSrcRow = pair.pValue;
        pDstRow = (PVMDIR_SUPERLOG_TABLE_ROW)&pTable->rows[i++];
        pDstRow->count = pSrcRow->count;
        pDstRow->totalTime = pSrcRow->totalTime;
        for (j = 0; j < VMDIR_SUPERLOG_TABLE_COL_NUM; j++)
        {
            if (pSrcRow->colVals[j])
            {
                dwError = VmDirAllocateStringA(pSrcRow->colVals[j], &pDstRow->colVals[j]);
                BAIL_ON_VMDIR_ERROR(dwError);
            }
        }
        dwError = VmDirAllocateStringPrintf(
                &pDstRow->colVals[AVG_TIME],
                "%lu",
                pDstRow->totalTime / pDstRow->count
                );
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    *ppTable = pTable;

cleanup:
    return dwError;

error:
    VmDirFreeSuperLogTable(pTable);
    goto cleanup;
}
Exemplo n.º 21
0
static
DWORD
schemaInitFillAttrFromCache(
    PVDIR_SCHEMA_CTX    pCtx,
    PSTR*    ppszValues,
    USHORT   dwValueSize,
    PSTR     pszAttrName,
    PVDIR_ENTRY   pEntry
    )
{
    DWORD dwError = 0;
    DWORD dwCnt = 0;
    VDIR_ATTRIBUTE* pAttr = NULL;

    dwError = VmDirAttributeAllocate(
            pszAttrName,
            dwValueSize,
            pCtx,
            &pAttr);
    BAIL_ON_VMDIR_ERROR(dwError);

    for (dwCnt = 0; dwCnt < dwValueSize; dwCnt++)
    {
        char* pszStr = &ppszValues[dwCnt][0];

        //ignore leading spaces
        while (*pszStr == ' ') pszStr++;

        dwError = VmDirAllocateStringA(
                ppszValues[dwCnt],
                &pAttr->vals[dwCnt].lberbv.bv_val);
        BAIL_ON_VMDIR_ERROR(dwError);

        pAttr->vals[dwCnt].bOwnBvVal = TRUE;
        pAttr->vals[dwCnt].lberbv.bv_len = VmDirStringLenA(pAttr->vals[dwCnt].lberbv.bv_val);
    }

    dwError = VmDirEntryAddAttribute(
            pEntry,
            pAttr);
    BAIL_ON_VMDIR_ERROR(dwError);
    pAttr = NULL;

cleanup:

    return dwError;

error:

    if (pAttr)
    {
        VmDirFreeAttribute(pAttr);
    }

    goto cleanup;
}
Exemplo n.º 22
0
VOID
_Test_VmdirAllocateStringA_NullDestinationString(
    VOID
)
{
    DWORD dwError = 0;

    dwError = VmDirAllocateStringA("test", NULL);
    ASSERT(dwError == 0);
}
Exemplo n.º 23
0
DWORD
VmDirSchemaAttrIdMapAddNewAttr(
    PVDIR_SCHEMA_ATTR_ID_MAP    pAttrIdMap,
    PSTR                        pszAttrName,
    USHORT                      usAttrId    // optional
    )
{
    DWORD   dwError = 0;
    PSTR    pszKey = 0;

    if (!pAttrIdMap || IsNullOrEmptyString(pszAttrName))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    if (VmDirSchemaAttrIdMapGetAttrId(pAttrIdMap, pszAttrName, NULL) == 0)
    {
        dwError = ERROR_ALREADY_EXISTS;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirAllocateStringA(pszAttrName, &pszKey);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (usAttrId)
    {
        dwError = LwRtlHashMapInsert(pAttrIdMap->pNewIds,
                pszKey, (PVOID)(uintptr_t)usAttrId, NULL);
        BAIL_ON_VMDIR_ERROR(dwError);

        if (usAttrId >= pAttrIdMap->usNextId)
        {
            pAttrIdMap->usNextId = usAttrId + 1;
        }
    }
    else
    {
        dwError = LwRtlHashMapInsert(pAttrIdMap->pNewIds,
                pszKey, (PVOID)(uintptr_t)pAttrIdMap->usNextId, NULL);
        BAIL_ON_VMDIR_ERROR(dwError);

        pAttrIdMap->usNextId++;
    }

cleanup:
    return dwError;

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

    VMDIR_SAFE_FREE_MEMORY(pszKey);
    goto cleanup;
}
Exemplo n.º 24
0
static
DWORD
_VmDirSchemaAttrReplaceValue(
    PVDIR_ATTRIBUTE pAttr,
    PCSTR           pszMatchSubstr,
    PCSTR           pszValue
    )
{
#define MAX_BUF_SIZE_256    256

    DWORD       dwError = 0;
    unsigned    iCnt = 0;
    CHAR        pszBuf[MAX_BUF_SIZE_256] = {0};

    dwError = VmDirStringPrintFA( pszBuf, MAX_BUF_SIZE_256 -1 , "NAME '%s' ", pszMatchSubstr );
    BAIL_ON_VMDIR_ERROR(dwError);

    for (iCnt = 0; iCnt < pAttr->numVals; iCnt++)
    {
        if ( VmDirCaselessStrStrA( pAttr->vals[iCnt].lberbv_val, pszBuf ) != NULL )
        {
            if ( VmDirStringCompareA( VDIR_SAFE_STRING(pAttr->vals[iCnt].lberbv_val),
                                      pszValue,
                                      FALSE ) != 0
                                      )
            {
                VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Merge schema, replace old - %s",
                                VDIR_SAFE_STRING(pAttr->vals[iCnt].lberbv_val));
                VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Merge schema, replace new - %s", pszValue );
            }

            VMDIR_LOG_DEBUG( VMDIR_LOG_MASK_ALL, "Merge schema, replace old - %s",
                             VDIR_SAFE_STRING(pAttr->vals[iCnt].lberbv_val));
            VmDirFreeBervalContent( &(pAttr->vals[iCnt]) );

            dwError = VmDirAllocateStringA( pszValue, &(pAttr->vals[iCnt].lberbv_val) );
            BAIL_ON_VMDIR_ERROR(dwError);
            pAttr->vals[iCnt].lberbv_len = VmDirStringLenA( pszValue );
            pAttr->vals[iCnt].bOwnBvVal = TRUE;

            VMDIR_LOG_DEBUG( VMDIR_LOG_MASK_ALL, "Merge schema, replace new - %s",
                             VDIR_SAFE_STRING(pAttr->vals[iCnt].lberbv_val));

            break;
        }
    }

cleanup:

    return dwError;

error:

    goto cleanup;
}
Exemplo n.º 25
0
static
DWORD
_VmDirSchemaComputeAllowedChildClassesEffective(
    PVDIR_ENTRY         pEntry,
    PVDIR_ATTRIBUTE*    ppOutAttr
    )
{
    DWORD                   dwError = 0;
    PVDIR_SCHEMA_OC_DESC    pStructureOCDesc = NULL;
    PVDIR_ATTRIBUTE         pLocalAttr = NULL;
    int                     iCnt = 0;

    dwError = VmDirSchemaGetEntryStructureOCDesc( pEntry,
                                                   &pStructureOCDesc );
    BAIL_ON_VMDIR_ERROR(dwError);
    if ( !pStructureOCDesc )
    {
        dwError = ERROR_INVALID_ENTRY;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    for (iCnt = 0; pStructureOCDesc->ppszAllowedChildOCs && pStructureOCDesc->ppszAllowedChildOCs[iCnt]; iCnt++) {}

    if (iCnt > 0)
    {
        dwError = VmDirAttributeAllocate( ATTR_ALLOWD_CHILD_CLASSES_EFFECTIVE,
                                          iCnt,
                                          pEntry->pSchemaCtx,
                                          &pLocalAttr);
        BAIL_ON_VMDIR_ERROR(dwError);

        for (iCnt = 0; pStructureOCDesc->ppszAllowedChildOCs[iCnt]; iCnt++)
        {
            dwError = VmDirAllocateStringA( pStructureOCDesc->ppszAllowedChildOCs[iCnt],
                                            &(pLocalAttr->vals[iCnt].lberbv_val));
            BAIL_ON_VMDIR_ERROR(dwError);

            pLocalAttr->vals[iCnt].lberbv_len = VmDirStringLenA(pLocalAttr->vals[iCnt].lberbv_val);
            pLocalAttr->vals[iCnt].bOwnBvVal = TRUE;
        }
    }

    *ppOutAttr = pLocalAttr;

cleanup:

    return dwError;

error:

    VmDirFreeAttribute( pLocalAttr );

    goto cleanup;
}
Exemplo n.º 26
0
DWORD
VdcSchemaConnValidateAndSetDefault(
    PVDC_SCHEMA_CONN    pConn
    )
{
    DWORD   dwError = 0;

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

    // domain is mandatory
    if (!pConn->pszDomain)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // default host is "localhost"
    if (!pConn->pszHostName)
    {
        dwError = VmDirAllocateStringA("localhost", &pConn->pszHostName);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // default user is "administrator"
    if (!pConn->pszUserName)
    {
        dwError = VmDirAllocateStringA("administrator", &pConn->pszUserName);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirAllocateStringPrintf(
            &pConn->pszUPN, "%s@%s", pConn->pszUserName, pConn->pszDomain);
    BAIL_ON_VMDIR_ERROR(dwError);

error:
    return dwError;
}
Exemplo n.º 27
0
VOID
_Test_VmdirAllocateStringA_EmptySourceString(
    VOID
)
{
    DWORD dwError = 0;
    PSTR pszString = NULL;

    dwError = VmDirAllocateStringA("", &pszString);
    ASSERT(dwError == 0);
    ASSERT(*pszString == '\0');
}
Exemplo n.º 28
0
static
DWORD
_VmDirSimpleEntryCreateInBEWithGuid(
    PVDIR_BACKEND_INTERFACE pBE,
    PVDIR_SCHEMA_CTX        pSchemaCtx,
    PSTR*                   ppszEntryInitializer,
    PSTR                    pszDN,
    ENTRYID                 ulEntryId,
    PSTR                    pszGuid /* Optional */
    )
{
    DWORD                   dwError = 0;
    VDIR_OPERATION          ldapOp = {0};

    dwError = VmDirInitStackOperation( &ldapOp,
                                       VDIR_OPERATION_TYPE_INTERNAL,
                                       LDAP_REQ_ADD,
                                       pSchemaCtx );
    BAIL_ON_VMDIR_ERROR(dwError);

    ldapOp.pBEIF = pBE;
    assert(ldapOp.pBEIF);

    ldapOp.reqDn.lberbv.bv_val = pszDN;
    ldapOp.reqDn.lberbv.bv_len = VmDirStringLenA(pszDN);

    dwError = AttrListToEntry(
            pSchemaCtx,
            pszDN,
            ppszEntryInitializer,
            ldapOp.request.addReq.pEntry);
    BAIL_ON_VMDIR_ERROR(dwError);

    ldapOp.request.addReq.pEntry->eId = ulEntryId;

    if (!IsNullOrEmptyString(pszGuid))
    {
        dwError = VmDirAllocateStringA(pszGuid, &ldapOp.request.addReq.pEntry->pszGuid);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirInternalAddEntry(&ldapOp);
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    VmDirFreeOperationContent(&ldapOp);

    return dwError;

error:

    goto cleanup;
}
Exemplo n.º 29
0
VOID
_Test_VmdirAllocateStringA_CallShouldSucceed(
    VOID
)
{
    DWORD dwError = 0;
    PSTR pszString = NULL;

    dwError = VmDirAllocateStringA("Hello, world!", &pszString);
    ASSERT(dwError == 0);
    ASSERT(strcmp(pszString, "Hello, world!") == 0);
}
Exemplo n.º 30
0
VOID
_Test_VmdirAllocateStringA_NullSourceString(
    VOID
)
{
    DWORD dwError = 0;
    PSTR pszString = (PSTR)0xDEADBEEF;

    dwError = VmDirAllocateStringA(NULL, &pszString);
    ASSERT(dwError == 0);
    ASSERT(pszString == NULL);
}