예제 #1
0
파일: main.c 프로젝트: divyamehta/lightwave
static
int
VmDirMain(int argc, char* argv[])
{
    DWORD dwError = 0;
    LDAP *pLd = NULL;
    COMMAND_LINE_PARAMETER_STATE State = { 0 };
    PLW_HASHMAP pUserToSidMapping = NULL; // Used to store "user/group SID" => "display name" mapping.
    PLW_HASHMAP pSidToUserMapping = NULL; // Used to store "display name" => "user/group SID" mapping.
    CHAR pszPasswordBuf[VMDIR_MAX_PWD_LEN + 1] = { 0 };

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

    dwError = VdcGetUsersPassword(&State, pszPasswordBuf, VMDIR_ARRAY_SIZE(pszPasswordBuf));
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirSafeLDAPBind(
                &pLd,
                State.pszServerName,
                State.pszUserName,
                pszPasswordBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VdcLoadUsersAndGroups(pLd, State.pszBaseDN, &pUserToSidMapping, &pSidToUserMapping);
    BAIL_ON_VMDIR_ERROR(dwError);

    //
    // We're either granting a user/group privileges on an object or just showing the
    // existing privileges on it.
    //
    if (State.pszGrantParameter)
    {
        dwError = VdcGrantPermissionToUser(pLd, pUserToSidMapping, State.pszObjectName, State.pszGrantParameter);
    }
    else if (State.pszRemoveParameter)
    {
        dwError = VdcRemovePermissionFromUser(pLd, pUserToSidMapping, State.pszObjectName, State.pszRemoveParameter);
    }
    else
    {
        dwError = VdcPrintSecurityDescriptorForObject(pLd, pSidToUserMapping, State.pszObjectName, State.bVerbose);
    }

cleanup:
    VdcFreeHashMap(&pUserToSidMapping);
    VdcFreeHashMap(&pSidToUserMapping);
    return dwError;

error:
    goto cleanup;
}
예제 #2
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;
}