예제 #1
0
VOID
TestStringListFree(
    PVMDIR_STRING_LIST pStringList
    )
{
    VmDirStringListFree(pStringList);
}
예제 #2
0
DWORD
VmDirStringListFromMultiString(
    PCSTR pszMultiString,
    DWORD dwCountHint, // 0 if caller doesn't know
    PVMDIR_STRING_LIST *ppStrList
    )
{
    PVMDIR_STRING_LIST pStringList = NULL;
    DWORD dwError = 0;

    dwError = VmDirStringListInitialize(&pStringList, dwCountHint);
    BAIL_ON_VMDIR_ERROR(dwError);

    do
    {
        dwError = VmDirStringListAddStrClone(pszMultiString, pStringList);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszMultiString += strlen(pszMultiString) + 1;
    } while (*pszMultiString != '\0');

    *ppStrList = pStringList;

cleanup:
    return dwError;
error:
    VmDirStringListFree(pStringList);
    goto cleanup;
}
예제 #3
0
파일: ldap.c 프로젝트: nks5295/lightwave
DWORD
VmDirTestDeleteContainerByDn(
    LDAP *pLd,
    PCSTR pszContainerDn
    )
{
    DWORD dwError = 0;
    DWORD dwIndex = 0;
    PVMDIR_STRING_LIST pObjectList = NULL;

    dwError = VmDirTestGetObjectList(pLd, pszContainerDn, &pObjectList);
    BAIL_ON_VMDIR_ERROR(dwError);

    for (dwIndex = 0; dwIndex < pObjectList->dwCount; ++dwIndex)
    {
        dwError = ldap_delete_ext_s(
                pLd, pObjectList->pStringList[dwIndex], NULL, NULL);
        if (dwError == LDAP_NOT_ALLOWED_ON_NONLEAF)
        {
            dwError = VmDirTestDeleteContainerByDn(
                    pLd, pObjectList->pStringList[dwIndex]);
            BAIL_ON_VMDIR_ERROR(dwError);
        }
    }

    dwError = ldap_delete_ext_s(pLd, pszContainerDn, NULL, NULL);
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    VmDirStringListFree(pObjectList);
    return dwError;

error:
    goto cleanup;
}
예제 #4
0
VOID
TestStringListFreeWithNull(
    VOID
    )
{
    VmDirStringListFree(NULL);
}
예제 #5
0
VOID
TestStringListAddLayout(
    VOID
    )
{
    PSTR ppszStrings[5];
    DWORD dwError = 0;
    DWORD i = 0;
    PVMDIR_STRING_LIST pStringList;

    dwError = VmDirStringListInitialize(&pStringList, 10);
    ASSERT(dwError == 0);

    for (i = 0; i < VMDIR_ARRAY_SIZE(ppszStrings); ++i)
    {
        ppszStrings[i] = GenerateString();
        dwError = VmDirStringListAdd(pStringList, ppszStrings[i]);
        ASSERT(dwError == 0);
    }

    ASSERT(pStringList->dwCount == VMDIR_ARRAY_SIZE(ppszStrings));

    for (i = 0; i < VMDIR_ARRAY_SIZE(ppszStrings); ++i)
    {
        ASSERT(pStringList->pStringList[i] == ppszStrings[i]);
    }

    VmDirStringListFree(pStringList);
}
예제 #6
0
DWORD
VmDirRegGetMultiSZ(
    PCSTR   pszKeyPath,
    PCSTR   pszKeyName,
    PVMDIR_STRING_LIST* ppStrList
    )
{
    DWORD               dwError = 0;
    PSTR                pszValue = NULL;
    PVMDIR_STRING_LIST  pStrList = NULL;

    PVMDIR_CONFIG_CONNECTION_HANDLE pCfgHandle = NULL;

    if (!pszKeyPath || !pszKeyName || !ppStrList)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirRegConfigHandleOpen(&pCfgHandle);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRegConfigGetMultiString(
                            pCfgHandle,
                            pszKeyPath,
                            pszKeyName,
                            &pszValue);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRegConfigMultiStringToStrList(pszValue, &pStrList);
    BAIL_ON_VMDIR_ERROR(dwError);

    // bail if there is no content in pStrList
    if (!pStrList || pStrList->dwCount == 0)
    {
        dwError = VMDIR_ERROR_INVALID_CONFIGURATION;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    *ppStrList = pStrList; pStrList = NULL;

cleanup:
    if (pCfgHandle)
    {
        VmDirRegConfigHandleClose(pCfgHandle);
    }
    if (pStrList)
    {
        VmDirStringListFree(pStrList);
    }
    VMDIR_SAFE_FREE_MEMORY(pszValue);

    return dwError;
error:
    goto cleanup;
}
예제 #7
0
파일: metadata.c 프로젝트: vmware/lightwave
//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;
}
예제 #8
0
static
DWORD
VmDirRegConfigMultiStringToStrList(
    PCSTR               pszValues,
    PVMDIR_STRING_LIST* ppStrList
    )
{
    DWORD               dwError = 0;
    DWORD               dwValuesLen = 0;
    PCSTR               pszIter = NULL;
    PVMDIR_STRING_LIST  pStrList = NULL;

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

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        dwError = VmDirStringListInitialize(&pStrList, dwValuesLen);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            dwError = VmDirStringListAddStrClone(pszIter, pStrList);
            BAIL_ON_VMDIR_ERROR(dwError);

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        *ppStrList = pStrList; pStrList = NULL;
    }

cleanup:
    if (pStrList)
    {
        VmDirStringListFree(pStrList);
    }
    return dwError;

error:
    goto cleanup;
}
예제 #9
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;
}
예제 #10
0
파일: file.c 프로젝트: nks5295/lightwave
/*
 * Read schema definition from file
 * We only care for
 *  attributetypes
 *  objectclasses
 *  ditcontentrules
 *  attributeindices
 */
DWORD
VmDirReadSchemaFile(
    PCSTR               pszSchemaFilePath,
    PVMDIR_STRING_LIST* ppAtStrList,
    PVMDIR_STRING_LIST* ppOcStrList,
    PVMDIR_STRING_LIST* ppCrStrList,
    PVMDIR_STRING_LIST* ppIdxStrList
    )
{
    DWORD dwError = 0;
    CHAR  pbuf[1024] = {0};
    FILE* fp = NULL;

    PVMDIR_STRING_LIST  pAtStrList = NULL;
    PVMDIR_STRING_LIST  pOcStrList = NULL;
    PVMDIR_STRING_LIST  pCrStrList = NULL;
    PVMDIR_STRING_LIST  pIdxStrList = NULL;

    if (!pszSchemaFilePath || !ppAtStrList || !ppOcStrList || !ppCrStrList || !ppIdxStrList)
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirStringListInitialize(&pAtStrList, 2048);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringListInitialize(&pOcStrList, 512);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringListInitialize(&pCrStrList, 512);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirStringListInitialize(&pIdxStrList, 16);
    BAIL_ON_VMDIR_ERROR(dwError);

#ifndef _WIN32
    fp = fopen(pszSchemaFilePath, "r");
#else
    if (fopen_s(&fp, pszSchemaFilePath, "r") != 0)
    {
        fp = NULL;
    }
#endif
    if (NULL == fp)
    {
        dwError = errno;
        VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL,
                "Open schema file (%s) failed. Error (%d)",
                pszSchemaFilePath, dwError);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    while (fgets(pbuf, sizeof(pbuf), fp) != NULL)
    {
        PSTR pszTag = NULL;

        if ((pbuf[0] == '\n')    ||
            (pbuf[0] == '#')     ||
            (pbuf[0] != ' ' && (pszTag = VmDirStringChrA(pbuf, ':')) == NULL))
        {
            continue;
        }

        if (IS_ATTRIBUTETYPES_TAG(pbuf))
        {
            dwError = _VmDirReadOneDefFromFile(fp, pAtStrList);
            BAIL_ON_VMDIR_ERROR(dwError);
        }
        else if (IS_OBJECTCLASSES_TAG(pbuf))
        {
            dwError = _VmDirReadOneDefFromFile(fp, pOcStrList);
            BAIL_ON_VMDIR_ERROR(dwError);
        }
        else if (IS_CONTENTRULES_TAG(pbuf))
        {
            dwError = _VmDirReadOneDefFromFile(fp, pCrStrList);
            BAIL_ON_VMDIR_ERROR(dwError);
        }
        else if (IS_ATTRIBUTEINDICES_TAG(pbuf))
        {
            dwError = _VmDirReadOneDefFromFile(fp, pIdxStrList);
            BAIL_ON_VMDIR_ERROR(dwError);
        }
        else
        {
            continue;
        }
    }

    *ppAtStrList = pAtStrList;
    *ppOcStrList = pOcStrList;
    *ppCrStrList = pCrStrList;
    *ppIdxStrList = pIdxStrList;

cleanup:
    if (fp)
    {
        fclose(fp);
    }
    return dwError;

error:
    VmDirStringListFree(pAtStrList);
    VmDirStringListFree(pOcStrList);
    VmDirStringListFree(pCrStrList);
    VmDirStringListFree(pIdxStrList);
    goto cleanup;
}
예제 #11
0
파일: ldap.c 프로젝트: nks5295/lightwave
DWORD
VdcLdapEnumerateObjects(
    LDAP *pLd,
    PCSTR pszBase,
    int ldapScope,
    PVMDIR_STRING_LIST *ppObjectDNs
    )
{
    DWORD dwError = 0;
    PCSTR ppszAttrs[] = {NULL};
    LDAPMessage *pResult = NULL;
    LDAPMessage* pEntry = NULL;
    PSTR pszObjectDN = NULL;
    DWORD iEntryCount = 0;
    PVMDIR_STRING_LIST pObjectDNs = NULL;

    dwError = ldap_search_ext_s(
                pLd,
                pszBase,
                ldapScope,
                "(objectClass=*)",
                (PSTR*)ppszAttrs,
                0,
                NULL,
                NULL,
                NULL,
                -1,
                &pResult);
    BAIL_ON_VMDIR_ERROR(dwError);

    iEntryCount = ldap_count_entries(pLd, pResult);
    if (iEntryCount > 0)
    {
        dwError = VmDirStringListInitialize(&pObjectDNs, iEntryCount);
        BAIL_ON_VMDIR_ERROR(dwError);

        pEntry = ldap_first_entry(pLd, pResult);
        for (; pEntry != NULL; pEntry = ldap_next_entry(pLd, pEntry))
        {
            assert(pObjectDNs->dwCount < iEntryCount);

            dwError = VmDirAllocateStringA(ldap_get_dn(pLd, pEntry), &pszObjectDN);
            BAIL_ON_VMDIR_ERROR(dwError);

            dwError = VmDirStringListAdd(pObjectDNs, pszObjectDN);
            BAIL_ON_VMDIR_ERROR(dwError);

            pszObjectDN = NULL;
        }
    }

    *ppObjectDNs = pObjectDNs;
    pObjectDNs = NULL;

cleanup:
    VmDirStringListFree(pObjectDNs);
    VMDIR_SAFE_FREE_STRINGA(pszObjectDN);
    if (pResult)
    {
        ldap_msgfree(pResult);
    }

    return dwError;

error:
    goto cleanup;
}
예제 #12
0
파일: ldap.c 프로젝트: nks5295/lightwave
//
// Enumerates the objects at a certain DN. If you just want to verify that the
// user can enumerate but don't care about the actual objects, pass NULL
// for ppObjectList.
//
// NB -- The VMDIR_STRING_LIST returned contains full DNs for the individual
// objects.
//
DWORD
VmDirTestGetObjectList(
    LDAP *pLd,
    PCSTR pszDn,
    PVMDIR_STRING_LIST *ppObjectList /* OPTIONAL */
    )
{
    DWORD dwError = 0;
    DWORD dwObjectCount = 0;
    PCSTR ppszAttrs[] = {NULL};
    LDAPMessage *pResult = NULL;
    PVMDIR_STRING_LIST pObjectList = NULL;

    dwError = ldap_search_ext_s(
                pLd,
                pszDn,
                LDAP_SCOPE_SUBTREE,
                "(objectClass=*)",
                (PSTR*)ppszAttrs,
                0,
                NULL,
                NULL,
                NULL,
                -1,
                &pResult);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (ppObjectList != NULL)
    {
        dwObjectCount = ldap_count_entries(pLd, pResult);
        dwError = VmDirStringListInitialize(&pObjectList, dwObjectCount);
        BAIL_ON_VMDIR_ERROR(dwError);

        if (dwObjectCount > 0)
        {
            LDAPMessage* pEntry = ldap_first_entry(pLd, pResult);

            //
            // Grab the next entry. The first one will be the base DN itself.
            //
            pEntry = ldap_next_entry(pLd, pEntry);
            for (; pEntry != NULL; pEntry = ldap_next_entry(pLd, pEntry))
            {
                dwError = VmDirStringListAddStrClone(ldap_get_dn(pLd, pEntry), pObjectList);
                BAIL_ON_VMDIR_ERROR(dwError);
            }
        }

        *ppObjectList = pObjectList;
    }

cleanup:
    if (pResult)
    {
        ldap_msgfree(pResult);
    }

    return dwError;

error:
    VmDirStringListFree(pObjectList);
    goto cleanup;
}
예제 #13
0
파일: idmap.c 프로젝트: vmware/lightwave
DWORD
VmDirSchemaAttrIdMapReadDB(
    PVDIR_SCHEMA_ATTR_ID_MAP    pAttrIdMap
    )
{
    DWORD   dwError = 0;
    DWORD   i = 0;
    VDIR_BACKEND_CTX    beCtx = {0};
    BOOLEAN             bHasTxn = FALSE;
    PVMDIR_STRING_LIST  pStringList = NULL;
    PSTR                pszBuf = NULL;
    PSTR                pszName = NULL;
    PSTR                pszId = NULL;
    USHORT              usId = 0;

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

    beCtx.pBE = VmDirBackendSelect(PERSISTED_DSE_ROOT_DN);

    dwError = beCtx.pBE->pfnBETxnBegin(&beCtx, VDIR_BACKEND_TXN_READ, &bHasTxn);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = beCtx.pBE->pfnBEDupKeyGetValues(
            &beCtx, ATTR_ID_MAP_KEY, &pStringList);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (bHasTxn)
    {
        dwError = beCtx.pBE->pfnBETxnCommit(&beCtx);
        bHasTxn = FALSE;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    for (i = 0; i < pStringList->dwCount; i++)
    {
        dwError = VmDirAllocateStringA(pStringList->pStringList[i], &pszBuf);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszId = VmDirStringTokA(pszBuf, SCHEMA_ATTR_ID_MAP_SEP, &pszName);
        usId = (USHORT)VmDirStringToIA(pszId);

        if (VmDirSchemaAttrIdMapGetAttrId(pAttrIdMap, pszName, NULL) != 0)
        {
            dwError = VmDirAllocateStringA(pszName, &pszName);
            BAIL_ON_VMDIR_ERROR(dwError);

            dwError = LwRtlHashMapInsert(pAttrIdMap->pStoredIds,
                    pszName, (PVOID)(uintptr_t)usId, NULL);
            BAIL_ON_VMDIR_ERROR(dwError);

            if (usId >= pAttrIdMap->usNextId)
            {
                pAttrIdMap->usNextId = usId + 1;
            }
        }

        VMDIR_SAFE_FREE_MEMORY(pszBuf);
    }

cleanup:
    VmDirBackendCtxContentFree(&beCtx);
    VmDirStringListFree(pStringList);
    return dwError;

error:
    if (bHasTxn)
    {
        beCtx.pBE->pfnBETxnAbort(&beCtx);
    }
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL,
            "%s failed, error (%d)", __FUNCTION__, dwError );

    VMDIR_SAFE_FREE_MEMORY(pszBuf);
    goto cleanup;
}
예제 #14
0
파일: idmap.c 프로젝트: vmware/lightwave
DWORD
VmDirSchemaAttrIdMapUpdateDB(
    PVDIR_SCHEMA_ATTR_ID_MAP    pAttrIdMap
    )
{
    DWORD   dwError = 0;
    DWORD   dwNumNewIds = 0;
    LW_HASHMAP_ITER iter = LW_HASHMAP_ITER_INIT;
    LW_HASHMAP_PAIR pair = {NULL, NULL};
    PSTR                pszMapStr = NULL;
    PVMDIR_STRING_LIST  pMapStrList = NULL;
    VDIR_BACKEND_CTX    beCtx = {0};
    BOOLEAN             bHasTxn = FALSE;

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

    dwNumNewIds = LwRtlHashMapGetCount(pAttrIdMap->pNewIds);
    if (dwNumNewIds == 0)
    {   // No new Id
        goto cleanup;
    }

    dwError = VmDirStringListInitialize(&pMapStrList, dwNumNewIds);
    BAIL_ON_VMDIR_ERROR(dwError);

    while (LwRtlHashMapIterate(pAttrIdMap->pNewIds, &iter, &pair))
    {
        dwError = VmDirAllocateStringPrintf(&pszMapStr, "%d%s%s",
                (USHORT)(uintptr_t)pair.pValue,
                SCHEMA_ATTR_ID_MAP_SEP,
                (PSTR)pair.pKey);
        BAIL_ON_VMDIR_ERROR(dwError);

        dwError = VmDirStringListAdd(pMapStrList, pszMapStr);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    beCtx.pBE = VmDirBackendSelect(PERSISTED_DSE_ROOT_DN);

    dwError = beCtx.pBE->pfnBETxnBegin(&beCtx, VDIR_BACKEND_TXN_WRITE, &bHasTxn);
    BAIL_ON_VMDIR_ERROR( dwError );

    dwError = beCtx.pBE->pfnBEDupKeySetValues(&beCtx, ATTR_ID_MAP_KEY, pMapStrList);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (bHasTxn)
    {
        dwError = beCtx.pBE->pfnBETxnCommit(&beCtx);
        bHasTxn = FALSE;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    LwRtlHashMapResetIter(&iter);
    while (LwRtlHashMapIterate(pAttrIdMap->pNewIds, &iter, &pair))
    {
        dwError = LwRtlHashMapInsert(pAttrIdMap->pStoredIds,
                pair.pKey, pair.pValue, NULL);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    LwRtlHashMapClear(pAttrIdMap->pNewIds, VmDirNoopHashMapPairFree, NULL);

cleanup:
    VmDirBackendCtxContentFree(&beCtx);
    VmDirStringListFree(pMapStrList);
    return dwError;

error:
    if (bHasTxn)
    {
        beCtx.pBE->pfnBETxnAbort(&beCtx);
    }
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL,
            "%s failed, error (%d)", __FUNCTION__, dwError );

    goto cleanup;

}