Exemplo n.º 1
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.º 2
0
DWORD
VmDirAllocateMutex(
    PVMDIR_MUTEX* ppMutex
    )
{
    DWORD dwError = ERROR_SUCCESS;
    PVMDIR_MUTEX pVmDirMutex = NULL;

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

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

    dwError = VmDirInitializeMutexContent( pVmDirMutex );
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppMutex = pVmDirMutex;
    pVmDirMutex = NULL;

error:

    VMDIR_SAFE_FREE_MUTEX( pVmDirMutex );

    return dwError;
}
Exemplo n.º 3
0
DWORD
VmDirQueueInit(
    PVDIR_QUEUE*    ppQueue
    )
{
    DWORD       dwError = 0;
    PVDIR_QUEUE pQueue = NULL;

    if (!ppQueue)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, ERROR_INVALID_PARAMETER);
    }

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

    dwError = VmDirAllocateMutex(&pQueue->pMutex);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateCondition(&pQueue->pCond);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppQueue = pQueue;

cleanup:
    return dwError;

error:
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError);
    VmDirQueueFree(pQueue);
    goto cleanup;
}
Exemplo n.º 4
0
DWORD
VmDirAllocateRWLock(
    PVMDIR_RWLOCK*  ppLock
    )
{
    DWORD dwError = 0;
    PVMDIR_RWLOCK pLock = NULL;

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

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

    dwError = VmDirInitializeRWLockContent(pLock);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppLock = pLock;
    pLock = NULL;

error:
    VmDirFreeRWLock(pLock);
    return dwError;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
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.º 8
0
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;
}
Exemplo n.º 9
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.º 10
0
DWORD
VmDirAllocateAndCopyMemory(
    PVOID   pBlob,
    size_t  iBlobSize,
    PVOID*  ppOutBlob
    )
{
    DWORD   dwError = 0;
    PVOID   pMemory = NULL;

    if (!pBlob || !ppOutBlob || iBlobSize < 1)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // add 1 for safety (VMDIR assuem bervalue is NULL terminated for string value)
    dwError = VmDirAllocateMemory(iBlobSize + 1, &pMemory);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirCopyMemory(pMemory, iBlobSize, pBlob, iBlobSize);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppOutBlob = pMemory;

cleanup:

    return dwError;

error:

    VMDIR_SAFE_FREE_MEMORY(pMemory);

    goto cleanup;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
int wmain(int argc, wchar_t* argv[])
{
    DWORD dwError = 0;
    PSTR* ppszArgs = NULL;
    int   iArg = 0;

    dwError = VmDirAllocateMemory(sizeof(PSTR) * argc, (PVOID*)&ppszArgs);
    BAIL_ON_VMDIR_ERROR(dwError);

    for (; iArg < argc; iArg++)
    {
        dwError = VmDirAllocateStringAFromW(argv[iArg], &ppszArgs[iArg]);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirMain(argc, ppszArgs);
    BAIL_ON_VMDIR_ERROR(dwError);

error:

    if (ppszArgs)
    {
        for (iArg = 0; iArg < argc; iArg++)
        {
            VMDIR_SAFE_FREE_MEMORY(ppszArgs[iArg]);
        }
        VmDirFreeMemory(ppszArgs);
    }

    return dwError;
}
Exemplo n.º 13
0
DWORD
VmDirAllocateCondition(
    PVMDIR_COND* ppCondition
    )
{
    DWORD dwError = ERROR_SUCCESS;
    PVMDIR_COND pVmDirCond = NULL;

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

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

    dwError = VmDirInitializeConditionContent( pVmDirCond );
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppCondition = pVmDirCond;
    pVmDirCond = NULL;

error:

    VMDIR_SAFE_FREE_CONDITION( pVmDirCond );

    return dwError;
}
Exemplo n.º 14
0
DWORD
VmDirGetKrbMasterKey(
    PSTR        pszFQDN, // [in] FQDN
    PBYTE*      ppKeyBlob,
    DWORD*      pSize
)
{
    DWORD       dwError = 0;
    PBYTE       pRetMasterKey = NULL;

    if (IsNullOrEmptyString(pszFQDN)
        || !ppKeyBlob
        || !pSize
       )
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // Currently, we only support single krb realm.
    // Global cache gVmdirKrbGlobals is initialized during startup stage.

    if (VmDirStringCompareA( pszFQDN, VDIR_SAFE_STRING(gVmdirKrbGlobals.pszRealm), FALSE) != 0)
    {
        dwError = VMDIR_ERROR_INVALID_REALM;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirAllocateMemory(
                    gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len,
                    (PVOID*)&pRetMasterKey
                    );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirCopyMemory (
                    pRetMasterKey,
                    gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len,
                    gVmdirKrbGlobals.bervMasterKey.lberbv.bv_val,
                    gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len
                    );
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppKeyBlob = pRetMasterKey;
    *pSize     = (DWORD) gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len;
    pRetMasterKey = NULL;

cleanup:

    return dwError;

error:

    VMDIR_LOG_ERROR( LDAP_DEBUG_RPC, "VmDirGetKrbMasterKey failed. (%u)(%s)",
                                     dwError, VDIR_SAFE_STRING(pszFQDN));
    VMDIR_SAFE_FREE_MEMORY(pRetMasterKey);

    goto cleanup;

}
Exemplo n.º 15
0
/*
 * Convenient function to add a single attribute to pEntry.
 */
DWORD
VmDirEntryAddSingleValueAttribute(
    PVDIR_ENTRY pEntry,
    PCSTR pszAttrName,
    PCSTR pszAttrValue,
    size_t   iAttrValueLen
    )
{
    DWORD dwError = 0;
    PVDIR_ATTRIBUTE pAttr = NULL;

    if (!pEntry || !pEntry->pSchemaCtx || !pszAttrName || !pszAttrValue || iAttrValueLen < 1)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirAttributeAllocate(
                pszAttrName,
                1,
                pEntry->pSchemaCtx,
                &pAttr);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateMemory(
            iAttrValueLen + 1,                  // want string null terminated.
            (PVOID*)&pAttr->vals[0].lberbv.bv_val );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirCopyMemory(
        pAttr->vals[0].lberbv.bv_val,
        (iAttrValueLen + 1),
        (PCVOID)pszAttrValue,
        iAttrValueLen
    );
    BAIL_ON_VMDIR_ERROR(dwError);

    pAttr->vals[0].bOwnBvVal = TRUE;
    pAttr->vals[0].lberbv.bv_len = iAttrValueLen;

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

cleanup:

    return dwError;

error:

    if (pAttr)
    {
        VmDirFreeAttribute(pAttr);
    }

    goto cleanup;
}
Exemplo n.º 16
0
/*
 * Create an Attribute on the heap and establish its pATDesc
 * two memory allocate
 * 1. pAttribute
 * 2. pAttribute->vals (BerValue array is one more then requested)
 */
DWORD
VmDirAttributeAllocate(
    PCSTR               pszName,
    USHORT              usBerSize,
    PVDIR_SCHEMA_CTX    pCtx,
    PVDIR_ATTRIBUTE*    ppOutAttr
    )
{
    DWORD              dwError = 0;
    PVDIR_ATTRIBUTE    pAttr = NULL;

    if (!ppOutAttr)
    {
        return 0;
    }

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

    // add one more BerValue as Encode/Decode entry in data store layer needs it.
    dwError = VmDirAllocateMemory(sizeof(VDIR_BERVALUE) * (usBerSize + 1), (PVOID*)&pAttr->vals);
    BAIL_ON_VMDIR_ERROR(dwError);

    pAttr->numVals = usBerSize;

    pAttr->pATDesc = VmDirSchemaAttrNameToDesc(pCtx, pszName);

    if (!pAttr->pATDesc)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_NO_SUCH_ATTRIBUTE);
    }

    // pAttr->type.lberbv.bv_val always store in-place
    pAttr->type.lberbv.bv_val = pAttr->pATDesc->pszName;
    pAttr->type.lberbv.bv_len = VmDirStringLenA(pAttr->type.lberbv.bv_val);

    *ppOutAttr = pAttr;

cleanup:
    return dwError;

error:
    VmDirFreeAttribute(pAttr);
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError);
    goto cleanup;
}
Exemplo n.º 17
0
static int
GenerateDeleteAttrsMods(
    PVDIR_OPERATION pOperation,
    VDIR_ENTRY *    pEntry
    )
{
    int                 retVal = 0;
    VDIR_MODIFICATION * delMod = NULL;
    VDIR_ATTRIBUTE *    attr = NULL;
    PVDIR_ATTRIBUTE     objectGuidAttr = NULL;
    VDIR_BERVALUE       deletedObjDN = VDIR_BERVALUE_INIT;
    ModifyReq *         modReq = &(pOperation->request.modifyReq);

    for ( attr = pEntry->attrs; attr != NULL; attr = attr->next )
    {
        // Retain the following kind of attributes
        if (attr->pATDesc->usage != VDIR_ATTRIBUTETYPE_USER_APPLICATIONS ||
            VmDirStringCompareA( attr->type.lberbv.bv_val, ATTR_OBJECT_CLASS, FALSE ) == 0)
        {
            continue;
        }
        retVal = VmDirAllocateMemory( sizeof( VDIR_MODIFICATION ), (PVOID *)&(delMod) );
        BAIL_ON_VMDIR_ERROR( retVal );

        delMod->operation = MOD_OP_DELETE;

        delMod->attr.next = NULL;
        delMod->attr.type = attr->type;
        delMod->attr.pATDesc = attr->pATDesc;
        delMod->attr.vals = NULL;
        delMod->attr.numVals = 0;

        delMod->next = modReq->mods;
        modReq->mods = delMod;
        modReq->numMods++;
    }

    // Add mod to set new DN.
    objectGuidAttr = VmDirEntryFindAttribute(ATTR_OBJECT_GUID, pEntry);
    assert( objectGuidAttr );

    retVal = constructDeletedObjDN( &pOperation->request.deleteReq.dn, objectGuidAttr->vals[0].lberbv.bv_val, &deletedObjDN );
    BAIL_ON_VMDIR_ERROR( retVal );

    retVal = VmDirAppendAMod( pOperation, MOD_OP_REPLACE, ATTR_DN, ATTR_DN_LEN,
                               deletedObjDN.lberbv.bv_val, deletedObjDN.lberbv.bv_len );
    BAIL_ON_VMDIR_ERROR( retVal );

cleanup:
    VmDirFreeMemory( deletedObjDN.lberbv.bv_val );

    return retVal;

error:
    goto cleanup;
}
Exemplo n.º 18
0
/*
 * pEntry is created from a difference instance of schema.
 * Path it to use new instance it now associates with.
 * 1. inpalce menory of pAttr->type
 * 2. pEntry->pSchemaCtx
 */
static
DWORD
_VmDirSchemaInitFixBootstrapEntry(
    PVDIR_SCHEMA_INSTANCE   pSchema,
    PVDIR_ENTRY             pEntry
    )
{
    DWORD               dwError = 0;
    VDIR_ATTRIBUTE*     pAttr = NULL;
    PVDIR_SCHEMA_CTX    pNewCtx = NULL;

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

    // create the very first ctx for pSchema
    pNewCtx->pSchema = pSchema;
    pNewCtx->pSchema->usRefCount++;

    // switch pEntry to use the new schema instance it creates.
    VmDirSchemaCtxRelease(pEntry->pSchemaCtx);
    pEntry->pSchemaCtx = pNewCtx;
    pNewCtx = NULL;

    for (pAttr = pEntry->attrs; pAttr; pAttr = pAttr->next)
    {
        USHORT usId = pAttr->pATDesc->usAttrID;
        PVDIR_SCHEMA_AT_DESC pResult = pSchema->ats.ppATSortIdMap[usId - 1];

        if (!pResult)
        {   // this should never happen as attribute ID never change once it is assigned.
            dwError = ERROR_INVALID_SCHEMA;
            BAIL_ON_VMDIR_ERROR(dwError);
        }

        // patch Attribute.pATDesc
        pAttr->pATDesc = pResult;

        // patch Attribute.type in-place storage as well
        pAttr->type.lberbv.bv_val = pResult->pszName;
        pAttr->type.lberbv.bv_len = VmDirStringLenA(pAttr->type.lberbv.bv_val);
    }

cleanup:

    return dwError;

error:

    if ( pNewCtx )
    {
        VmDirSchemaCtxRelease( pNewCtx );
    }

    goto cleanup;
}
Exemplo n.º 19
0
static
DWORD
VmDirRegConfigHandleOpen(
    PVMDIR_CONFIG_CONNECTION_HANDLE *ppCfgHandle)
{
    DWORD dwError = 0;
    PVMDIR_CONFIG_CONNECTION_HANDLE pCfgHandle = NULL;

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

#ifndef _WIN32
    dwError = RegOpenServer(&pCfgHandle->hConnection);
    BAIL_ON_VMDIR_ERROR(dwError);
#endif

#ifndef _WIN32
    dwError = RegOpenKeyExA(
                pCfgHandle->hConnection,
                NULL,
                HKEY_THIS_MACHINE,
                0,
                KEY_READ,
                &pCfgHandle->hKey);
    BAIL_ON_VMDIR_ERROR(dwError);
#else
        dwError = RegOpenKeyExA(
                HKEY_LOCAL_MACHINE,
                NULL,
                0,
                KEY_READ,
                &pCfgHandle->hKey);
    BAIL_ON_VMDIR_ERROR(dwError);
#endif

    *ppCfgHandle = pCfgHandle;

cleanup:

    return dwError;

error:

    *ppCfgHandle = NULL;

    if (pCfgHandle)
    {
        VmDirRegConfigHandleClose(pCfgHandle);
    }

    goto cleanup;
}
Exemplo n.º 20
0
DWORD
VmDirStringListInitialize(
    PVMDIR_STRING_LIST *ppStringList,
    DWORD dwInitialCount
    )
{
    DWORD dwError = 0;
    PVMDIR_STRING_LIST pStringList = NULL;
    DWORD dwAllocationSize = 0;

    if (dwInitialCount < 4)
    {
        dwInitialCount = 4; // default to 4
    }

    dwAllocationSize = dwInitialCount * sizeof(PSTR);
    if (dwAllocationSize < dwInitialCount)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

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

    dwError = VmDirAllocateMemory(
                dwAllocationSize,
                (PVOID *)&pStringList->pStringList);
    BAIL_ON_VMDIR_ERROR(dwError);

    pStringList->dwCount = 0;
    pStringList->dwSize = dwInitialCount;

    *ppStringList = pStringList;

cleanup:
    return dwError;

error:
    VmDirStringListFree(pStringList);
    goto cleanup;
}
Exemplo n.º 21
0
DWORD
VmDirInitializeEntry(
   VDIR_ENTRY *               e,
   VDIR_ENTRY_ALLOCATION_TYPE allocType,
   int                        nAttrs,
   int                        nVals
   )
{
    DWORD           dwError = 0;
    PVDIR_ATTRIBUTE pLocalAttrs = NULL;
    PVDIR_BERVALUE  pLocalBervs = NULL;
    VDIR_BERVALUE   localDNBerv = VDIR_BERVALUE_INIT;

    VmDirLog( LDAP_DEBUG_TRACE, "InitializeEntry: Begin, allocType = %d", allocType );

    e->allocType = allocType;
    e->dn = localDNBerv;
    dwError = VmDirAllocateMemory( nAttrs * sizeof(VDIR_ATTRIBUTE), (PVOID *)&pLocalAttrs);
    BAIL_ON_VMDIR_ERROR( dwError );

    dwError = VmDirAllocateMemory( nVals * sizeof( VDIR_BERVALUE ), (PVOID *)&pLocalBervs );
    BAIL_ON_VMDIR_ERROR( dwError );

    e->pAclCtx = NULL;
    e->pszGuid = NULL;

    e->attrs = pLocalAttrs;
    e->savedAttrsPtr = e->attrs;

    e->bvs = pLocalBervs;
    e->usNumBVs = nVals;

cleanup:
    VmDirLog( LDAP_DEBUG_TRACE, "InitializeEntry: End" );
    return dwError;

error:
    VMDIR_SAFE_FREE_MEMORY(pLocalAttrs);
    VMDIR_SAFE_FREE_MEMORY(pLocalBervs);
    goto cleanup;
}
Exemplo n.º 22
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.º 23
0
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;
}
Exemplo n.º 24
0
DWORD
VdirAttrIndexCacheAllocate(
    PVDIR_ATTR_INDEX_INSTANCE* ppAttrIdxCache,
    USHORT  usIdxSize
    )
{
    DWORD dwError = 0;
    PVDIR_ATTR_INDEX_INSTANCE pAttrIdxCache = NULL;

    assert(ppAttrIdxCache);

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

    pAttrIdxCache->usNumIndex = usIdxSize;

    dwError = VmDirAllocateMemory(
            sizeof(VDIR_CFG_ATTR_INDEX_DESC) * pAttrIdxCache->usNumIndex,
            (PVOID*)&pAttrIdxCache->pSortName);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppAttrIdxCache = pAttrIdxCache;

cleanup:

    return dwError;

error:

    if (pAttrIdxCache)
    {
        VdirAttrIdxCacheFree(pAttrIdxCache);
    }

    *ppAttrIdxCache = NULL;

    goto cleanup;
}
Exemplo n.º 25
0
/*
 * For given DN (pszDN content will be modified),
 * 1. allocate ppszRDNs to hold PSTR to RDN
 * 2. change pszDN ',' to '\0' and have ppszRDNs[i] point to it
 * 3. set *piNumRDNs
 *
 * Caller should free *pppszRDNs but NOT **pppszRDNs, which point into pszDN.
 */
static
DWORD
VdirSchemaInPlaceDN2RDNs(
    PSTR    pszDN,
    PSTR**  pppszRDNs,
    int*    piNumRDNs
    )
{
    DWORD   dwError = 0;
    PSTR*   ppszRDNs = NULL;
    int     iCnt = 0;
    PSTR    pChar = NULL;

    assert(pppszRDNs && piNumRDNs);

    for (iCnt = 0, pChar = pszDN; pChar; iCnt++)
    {
        pChar = VmDirStringChrA(pChar+1, ',');
    }

    dwError = VmDirAllocateMemory(
            sizeof(PSTR) * (iCnt+1),
            (PVOID)&ppszRDNs);
    BAIL_ON_VMDIR_ERROR(dwError);

    *piNumRDNs = iCnt;

    for (iCnt = 0, pChar = pszDN, ppszRDNs[0] = pszDN; pChar; iCnt++)
    {
        pChar = VmDirStringChrA(pChar+1, ',');
        if (pChar)
        {
            *pChar = '\0';
            ppszRDNs[iCnt+1] = pChar+1;
        }
    }

    *pppszRDNs = ppszRDNs;

cleanup:

    return dwError;

error:

    VMDIR_SAFE_FREE_MEMORY(ppszRDNs);

    *pppszRDNs = NULL;
    *piNumRDNs = 0;

    goto cleanup;
}
Exemplo n.º 26
0
//Add one more single value replace mod onto the LdapOp's mods
DWORD
VmDirAddModSingleAttributeReplace(
    PVDIR_OPERATION     pLdapOp,
    PCSTR               pszNormDN,
    PCSTR               pszAttrName,
    PVDIR_BERVALUE      pBervAttrValue
    )
{
    DWORD               dwError = 0;
    PVDIR_MODIFICATION  pMod = NULL;

    if (!pszNormDN || !pszAttrName || !pBervAttrValue)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    pLdapOp->reqDn.lberbv.bv_val = (PSTR)pszNormDN;
    pLdapOp->reqDn.lberbv.bv_len = VmDirStringLenA(pszNormDN);

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

    pMod->operation = MOD_OP_REPLACE;
    dwError = VmDirModAddSingleValueAttribute(
            pMod,
            pLdapOp->pSchemaCtx,
            pszAttrName,
            pBervAttrValue->lberbv.bv_val,
            pBervAttrValue->lberbv.bv_len);
    BAIL_ON_VMDIR_ERROR(dwError);

    pLdapOp->request.modifyReq.dn.lberbv.bv_val = (PSTR)pszNormDN;
    pLdapOp->request.modifyReq.dn.lberbv.bv_len = VmDirStringLenA(pszNormDN);
    pMod->next = pLdapOp->request.modifyReq.mods;
    pLdapOp->request.modifyReq.mods = pMod;
    pLdapOp->request.modifyReq.numMods++;
    pMod = NULL;

cleanup:

    if (pMod)
    {
        VmDirModificationFree(pMod);
    }

    return dwError;

error:
    goto cleanup;
}
Exemplo n.º 27
0
int
GenerateDeleteAttrsMods(
    PVDIR_OPERATION pOperation,
    VDIR_ENTRY *    pEntry
    )
{
    int                 retVal = 0;
    VDIR_MODIFICATION * delMod = NULL;
    VDIR_ATTRIBUTE *    attr = NULL;
    ModifyReq *         modReq = &(pOperation->request.modifyReq);

    for (attr = pEntry->attrs; attr != NULL; attr = attr->next)
    {
        if (VmDirStringCompareA(attr->type.lberbv.bv_val, ATTR_DN, FALSE) == 0)
        {
            continue;
        }

        retVal = VmDirAllocateMemory(
                sizeof(VDIR_MODIFICATION), (PVOID*)&delMod);
        BAIL_ON_VMDIR_ERROR(retVal);

        delMod->operation = MOD_OP_DELETE;

        delMod->attr.next = NULL;
        delMod->attr.type = attr->type;
        delMod->attr.pATDesc = attr->pATDesc;
        delMod->attr.vals = NULL;
        delMod->attr.numVals = 0;

        delMod->next = modReq->mods;
        modReq->mods = delMod;
        modReq->numMods++;
    }

    retVal = VmDirAppendAMod(
            pOperation,
            MOD_OP_DELETE,
            ATTR_DN,
            ATTR_DN_LEN,
            pOperation->request.deleteReq.dn.lberbv.bv_val,
            pOperation->request.deleteReq.dn.lberbv.bv_len);
    BAIL_ON_VMDIR_ERROR(retVal);

cleanup:
    return retVal;

error:
    goto cleanup;
}
Exemplo n.º 28
0
static
DWORD
VmDirRegConfigMultiStringToDwords(
    PCSTR   pszValues,
    PDWORD* ppdwValues,
    DWORD*  pdwValuesLen
    )
{
    DWORD dwError = 0;
    PDWORD pdwValues = NULL;
    DWORD dwValuesLen = 0;
    DWORD dwCount = 0;
    PCSTR pszIter = NULL;

    if (pszValues)
    {
        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            dwValuesLen++;

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        /* Allocate space for one even if no space is really needed,
         * that way we have a valid pointer.
         */
        dwError = VmDirAllocateMemory(sizeof(DWORD) * (dwValuesLen == 0 ? 1 : dwValuesLen), (PVOID)&pdwValues);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            DWORD dwVal = atoi(pszIter);
            pdwValues[dwCount++] = dwVal;
            pszIter += VmDirStringLenA(pszIter) + 1;
        }
    }

    *ppdwValues = pdwValues;
    *pdwValuesLen = dwValuesLen;

cleanup:
    return dwError;

error:
    VMDIR_SAFE_FREE_MEMORY(pdwValues);
    goto cleanup;
}
Exemplo n.º 29
0
DWORD
VmDirRESTCacheGetBuiltInAdminsGroupSid(
    PVDIR_REST_HEAD_CACHE   pRestCache,
    PSID*                   ppBuiltInAdminsGroupSid
    )
{
    DWORD   dwError = 0;
    ULONG   ulSidLen = 0;
    BOOLEAN bInLock = FALSE;
    PSID    pSid = NULL;

    if (!pRestCache || !ppBuiltInAdminsGroupSid)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    VMDIR_RWLOCK_READLOCK(bInLock, gpVdirRestCache->pRWLock, 0);

    if (!RtlValidSid(pRestCache->pBuiltInAdminsGroupSid))
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_NOT_FOUND);
    }

    ulSidLen = RtlLengthSid(pRestCache->pBuiltInAdminsGroupSid);

    dwError = VmDirAllocateMemory(ulSidLen, (PVOID*)&pSid);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = RtlCopySid(ulSidLen, pSid, pRestCache->pBuiltInAdminsGroupSid);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppBuiltInAdminsGroupSid = pSid;

cleanup:
    VMDIR_RWLOCK_UNLOCK(bInLock, gpVdirRestCache->pRWLock);
    return dwError;

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

    VMDIR_SAFE_FREE_MEMORY(pSid);
    goto cleanup;
}
Exemplo n.º 30
0
/*
 * Initialize an attribute structure
 */
DWORD
VmDirAttributeInitialize(
    PSTR    pszName,
    USHORT  usBerSize,
    PVDIR_SCHEMA_CTX pCtx,
    PVDIR_ATTRIBUTE pAttr
    )
{
    DWORD    dwError = 0;

    if (!pAttr)
    {
        return 0;
    }

    // add one more BerValue as Encode/Decode entry in data store layer needs it.
    dwError = VmDirAllocateMemory(
            sizeof(VDIR_BERVALUE) * (usBerSize + 1),
            (PVOID*)&pAttr->vals);
    BAIL_ON_VMDIR_ERROR(dwError);

    pAttr->numVals = usBerSize;

    pAttr->pATDesc = VmDirSchemaAttrNameToDesc(
                    pCtx,
                    pszName);
    if (!pAttr->pATDesc)
    {
        dwError = VMDIR_ERROR_NO_SUCH_ATTRIBUTE;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // pAttr->type.lberbv.bv_val always store in-place
    pAttr->type.lberbv.bv_val = pAttr->pATDesc->pszName;
    pAttr->type.lberbv.bv_len = VmDirStringLenA(pAttr->type.lberbv.bv_val);

cleanup:

    return dwError;

error:

    VmDirLog( LDAP_DEBUG_ANY, "VmDirAttributeInitialize failed (%d)(%s)",
              dwError, VDIR_SAFE_STRING(pszName));

    goto cleanup;
}