Ejemplo n.º 1
0
        wszAttrSequenceNumber,
        1,
        &AttrValues[ATTR_VAL_IDX_SEQUENCE_NUMBER]
    };

    DIRECTORY_MOD Mods[ATTR_VAL_IDX_SENTINEL + 1];
    memset(Mods, 0, sizeof(Mods));

    dwError = LsaProcessConfig(
                "Services\\lsass\\Parameters\\SAM",
                "Policy\\Services\\lsass\\Parameters\\SAM",
                SamConfig,
                sizeof(SamConfig)/sizeof(SamConfig[0]));
    BAIL_ON_LSA_ERROR(dwError);

    dwError = DirectoryOpen(&hDirectory);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = DirectoryBind(
                    hDirectory,
                    pwszUserDN,
                    pwszCredentials,
                    ulMethod);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LwAllocateStringPrintf(
                    &pszFilter,
                    pszFilterFmt,
                    dwDomainObjectClass);
    BAIL_ON_LSA_ERROR(dwError);
Ejemplo n.º 2
0
NTSTATUS
SamrSrvConnectInternal(
    IN  handle_t            hBinding,
    IN  PCWSTR              pwszSystemName,
    IN  DWORD               dwAccessMask,
    IN  DWORD               dwConnectVersion,
    IN  DWORD               dwLevelIn,
    IN  PSAMR_CONNECT_INFO  pInfoIn,
    OUT PDWORD              pdwLevelOut,
    OUT PSAMR_CONNECT_INFO  pInfoOut,
    OUT PCONNECT_CONTEXT   *ppConnCtx
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = 0;
    PCONNECT_CONTEXT pConnCtx = NULL;
    PSECURITY_DESCRIPTOR_ABSOLUTE pSecDesc = gpSamrSecDesc;
    GENERIC_MAPPING GenericMapping = {0};
    DWORD dwAccessGranted = 0;

    BAIL_ON_INVALID_PTR(hBinding);
    BAIL_ON_INVALID_PTR(pwszSystemName);
    BAIL_ON_INVALID_PTR(ppConnCtx);

    dwError = LwAllocateMemory(sizeof(*pConnCtx),
                               OUT_PPVOID(&pConnCtx));
    BAIL_ON_LSA_ERROR(dwError);

    pConnCtx->Type     = SamrContextConnect;
    pConnCtx->refcount = 1;

    ntStatus = SamrSrvInitAuthInfo(hBinding, pConnCtx);
    BAIL_ON_NTSTATUS_ERROR(ntStatus);

    if (!RtlAccessCheck(pSecDesc,
                        pConnCtx->pUserToken,
                        dwAccessMask,
                        pConnCtx->dwAccessGranted,
                        &GenericMapping,
                        &dwAccessGranted,
                        &ntStatus))
    {
        BAIL_ON_NTSTATUS_ERROR(ntStatus);
    }

    pConnCtx->dwAccessGranted = dwAccessGranted;

    dwError = DirectoryOpen(&pConnCtx->hDirectory);
    BAIL_ON_LSA_ERROR(dwError);

    pConnCtx->dwConnectVersion = dwConnectVersion;

    if (dwConnectVersion == 5)
    {
        BAIL_ON_INVALID_PTR(pInfoIn);
        BAIL_ON_INVALID_PTR(pInfoOut);
        BAIL_ON_INVALID_PTR(pdwLevelOut);

        pConnCtx->dwLevel = dwLevelIn;
        pConnCtx->Info    = *pInfoIn;
    }

    if (pdwLevelOut)
    {
        *pdwLevelOut = pConnCtx->dwLevel;
    }

    if (pInfoOut)
    {
        *pInfoOut = pConnCtx->Info;
    }

    *ppConnCtx = pConnCtx;

cleanup:
    if (ntStatus == STATUS_SUCCESS &&
        dwError != ERROR_SUCCESS)
    {
        ntStatus = LwWin32ErrorToNtStatus(dwError);
    }

    return ntStatus;

error:
    if (pdwLevelOut)
    {
        *pdwLevelOut = 0;
    }

    if (pInfoOut)
    {
        memset(pInfoOut, 0, sizeof(*pInfoOut));
    }

    if (pConnCtx)
    {
        SamrSrvConnectContextFree(pConnCtx);
    }

    *ppConnCtx = NULL;
    goto cleanup;
}