コード例 #1
0
ファイル: stringlist.c プロジェクト: DhanashreeA/lightwave
VOID
TestStringListRemoveShouldHaveCorrectLayout(
    VOID)
{
    PCSTR ppszStrings[] = {
        "Test 1",
        "Test 2",
        "Test 3",
        "Test 4",
        "Test 5"
    };
    PVMDIR_STRING_LIST pStringList = NULL;
    DWORD dwError = 0;
    DWORD i = 0;

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

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

    dwError = VmDirStringListRemove(pStringList, ppszStrings[2]);
    ASSERT(dwError == 0);
    ASSERT(pStringList->dwCount == VMDIR_ARRAY_SIZE(ppszStrings) - 1);
    ASSERT(pStringList->pStringList[0] == ppszStrings[0]);
    ASSERT(pStringList->pStringList[1] == ppszStrings[1]);
    ASSERT(pStringList->pStringList[2] == ppszStrings[3]);
    ASSERT(pStringList->pStringList[3] == ppszStrings[4]);
}
コード例 #2
0
ファイル: stringlist.c プロジェクト: vmware/lightwave
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
ファイル: stringlist.c プロジェクト: DhanashreeA/lightwave
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);
}
コード例 #4
0
ファイル: stringlist.c プロジェクト: DhanashreeA/lightwave
VOID
TestStringListInitializationCountTooBig(
    VOID
    )
{
    PVMDIR_STRING_LIST pStringList = NULL;
    DWORD dwError = 0;

    dwError = VmDirStringListInitialize(&pStringList, 0xFFFFFFFF);
    ASSERT(dwError == VMDIR_ERROR_INVALID_PARAMETER);
    ASSERT(pStringList == NULL);
}
コード例 #5
0
ファイル: stringlist.c プロジェクト: DhanashreeA/lightwave
VOID
TestStringListInitialization(
    PVMDIR_STRING_LIST *ppStringList
    )
{
    PVMDIR_STRING_LIST pStringList;
    DWORD dwError = 0;

    dwError = VmDirStringListInitialize(&pStringList, 10);
    ASSERT(dwError == 0);
    ASSERT(pStringList != NULL);
    ASSERT(pStringList->dwCount == 0);
    ASSERT(pStringList->dwSize == 10);

    *ppStringList = pStringList;
}
コード例 #6
0
ファイル: regconfig.c プロジェクト: vmware/lightwave
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;
}
コード例 #7
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;
}
コード例 #8
0
ファイル: main.c プロジェクト: vmware/lightwave
int
VmDirMain(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    VMDIR_TEST_STATE State = { 0 };
    PVMDIR_STRING_LIST pStringList = NULL;
    DWORD dwIndex = 0;
    VMDIR_COMMAND_LINE_OPTION CommandLineOptions[] =
    {
        {'H', "host", CL_STRING_PARAMETER, &State.pszServerName},
        {'u', "username", CL_STRING_PARAMETER, &State.pszUserName},
        {'w', "password", CL_STRING_PARAMETER, &State.pszPassword},
        {'d', "domain", CL_STRING_PARAMETER, &State.pszDomain},
        {'b', "break", CL_NO_PARAMETER, &State.bBreakIntoDebugger},
        {'k', "keep-going", CL_NO_PARAMETER, &State.bKeepGoing},
        {'t', "test", CL_STRING_PARAMETER, &State.pszTest},
        {0, 0, 0, 0}
    };

    VMDIR_PARSE_ARG_CALLBACKS Callbacks =
    {
        PostValidationRoutine,
        ShowUsage,
        &State
    };

    dwError = VmDirParseArguments(
                CommandLineOptions,
                &Callbacks,
                argc,
                argv);
    BAIL_ON_VMDIR_ERROR(dwError);


    dwError = VmDirAllocateStringPrintf(
                (PSTR*)&State.pszUserUPN,
                "%s@%s",
                State.pszUserName,
                State.pszDomain);
    BAIL_ON_VMDIR_ERROR(dwError);

    printf("VmDir integration tests starting ...\n");

    dwError = TestInfrastructureInitialize(&State);
    BAIL_ON_VMDIR_ERROR(dwError);

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

    dwError = _VmDirEnumerateTests(State.pszTest, pStringList);
    BAIL_ON_VMDIR_ERROR(dwError);

    if (pStringList->dwCount == 0)
    {
        printf("No tests found!\n");
        goto cleanup;
    }

    for (dwIndex = 0; dwIndex < pStringList->dwCount; dwIndex++)
    {
        _VmDirExecuteTestModule(&State, pStringList->pStringList[dwIndex]);
    }

cleanup:
    TestInfrastructureCleanup(&State);

    return dwError;

error:
    printf("Integration test failed with error 0n%d\n", dwError);
    goto cleanup;
}
コード例 #9
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;
}
コード例 #10
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;
}
コード例 #11
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;

}