예제 #1
0
NTSTATUS
NetrAllocateValidationInfo(
    OUT NetrValidationInfo  *pOut,
    IN OUT PDWORD            pdwOffset,
    IN OUT PDWORD            pdwSpaceLeft,
    IN  WORD                 swLevel,
    IN  NetrValidationInfo  *pIn,
    IN OUT PDWORD            pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    DWORD dwInfoOffset = 0;
    DWORD dwInfoSize = 0;
    DWORD dwInfoSpaceLeft = 0;
    PVOID pInfo = NULL;
    PVOID *ppInfo = NULL;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    /*
     * pIn->sam2 is essentially the same pointer as other legs of the union
     * so the following condition checks if anything has been passed at all
     */
    if (pIn->sam2)
    {
        switch (swLevel)
        {
        case 2:
            ntStatus = NetrAllocateSamInfo2(NULL,
                                            &dwInfoOffset,
                                            NULL,
                                            pIn->sam2,
                                            &dwInfoSize);
            break;

        case 3:
            ntStatus = NetrAllocateSamInfo3(NULL,
                                            &dwInfoOffset,
                                            NULL,
                                            pIn->sam3,
                                            &dwInfoSize);
            break;

        case 4:
            ntStatus = NetrAllocatePacInfo(NULL,
                                           &dwInfoOffset,
                                           NULL,
                                           pIn->pac4,
                                           &dwInfoSize);
            break;

        case 5:
            ntStatus = NetrAllocatePacInfo(NULL,
                                           &dwInfoOffset,
                                           NULL,
                                           pIn->pac5,
                                           &dwInfoSize);
            break;

        case 6:
            ntStatus = NetrAllocateSamInfo6(NULL,
                                            &dwInfoOffset,
                                            NULL,
                                            pIn->sam6,
                                            &dwInfoSize);
            break;

        default:
            ntStatus = STATUS_INVALID_LEVEL;
        }
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwInfoSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->sam2)
        {
            pInfo = LWBUF_TARGET_PTR(pBuffer, dwInfoSize, pdwSpaceLeft);

            /* sanity check - the info pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(PVOID, pInfo, dwError);

            dwInfoSpaceLeft = dwInfoSize;
            dwInfoOffset    = 0;

            /* Allocate the info */
            switch (swLevel)
            {
            case 2:
                ntStatus = NetrAllocateSamInfo2(pInfo,
                                                &dwInfoOffset,
                                                &dwInfoSpaceLeft,
                                                pIn->sam2,
                                                pdwSize);
                break;

            case 3:
                ntStatus = NetrAllocateSamInfo3(pInfo,
                                                &dwInfoOffset,
                                                &dwInfoSpaceLeft,
                                                pIn->sam3,
                                                pdwSize);
                break;

            case 4:
                ntStatus = NetrAllocatePacInfo(pInfo,
                                               &dwInfoOffset,
                                               &dwInfoSpaceLeft,
                                               pIn->pac4,
                                               pdwSize);
                break;

            case 5:
                ntStatus = NetrAllocatePacInfo(pInfo,
                                               &dwInfoOffset,
                                               &dwInfoSpaceLeft,
                                               pIn->pac5,
                                               pdwSize);
                break;

            case 6:
                ntStatus = NetrAllocateSamInfo6(pInfo,
                                                &dwInfoOffset,
                                                &dwInfoSpaceLeft,
                                                pIn->sam6,
                                                pdwSize);
                break;

            default:
                ntStatus = STATUS_INVALID_LEVEL;
            }
            BAIL_ON_NT_STATUS(ntStatus);
        }

        ppInfo           = pCursor;
        *ppInfo          = pInfo;
        (*pdwSpaceLeft) -= (pInfo) ? LWBUF_ALIGN_SIZE(dwInfoSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(PVOID);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwInfoSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(PVOID);
    (*pdwSize)   += sizeof(PVOID);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #2
0
static
NTSTATUS
NetrAllocateRidWithAttributeArray(
    OUT PVOID                      *pOut,
    IN OUT PDWORD                   pdwOffset,
    IN OUT PDWORD                   pdwSpaceLeft,
    IN  PRID_WITH_ATTRIBUTE_ARRAY   pIn,
    IN OUT PDWORD                   pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    DWORD dwRidsSize = 0;
    DWORD dwRidsSpaceLeft = 0;
    DWORD dwRidsOffset = 0;
    DWORD iRid = 0;
    PVOID pRids = NULL;
    PRID_WITH_ATTRIBUTE *ppRids = NULL;
    
    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->dwCount);
    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->dwCount)
    {
        dwRidsSize = sizeof(pIn->pRids[0]) * pIn->dwCount;
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwRidsSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->pRids)
        {
            pRids = LWBUF_TARGET_PTR(pBuffer, dwRidsSize, pdwSpaceLeft);

            /* sanity check - the rids pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(PRID_WITH_ATTRIBUTE, pRids, dwError);

            dwRidsSpaceLeft = dwRidsSize;
            dwRidsOffset    = 0;

            /* Allocate the rid entries */
            for (iRid = 0; iRid < pIn->dwCount; iRid++)
            {
                PVOID pRidCursor = pRids + (iRid * sizeof(pIn->pRids[0]));

                ntStatus = NetrAllocateRidWithAttribute(pRidCursor,
                                                        &dwRidsOffset,
                                                        &dwRidsSpaceLeft,
                                                        &(pIn->pRids[iRid]),
                                                        pdwSize);
                BAIL_ON_NT_STATUS(ntStatus);

                dwRidsOffset = 0;
            }
        }

        ppRids           = (PRID_WITH_ATTRIBUTE*)pCursor;
        *ppRids          = (PRID_WITH_ATTRIBUTE)pRids;
        (*pdwSpaceLeft) -= (pRids) ? LWBUF_ALIGN_SIZE(dwRidsSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(PRID_WITH_ATTRIBUTE);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwRidsSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(PRID_WITH_ATTRIBUTE);
    (*pdwSize)   += sizeof(PRID_WITH_ATTRIBUTE);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #3
0
static
NTSTATUS
NetrAllocateSamInfo3(
    OUT NetrSamInfo3    *pOut,
    IN OUT PDWORD        pdwOffset,
    IN OUT PDWORD        pdwSpaceLeft,
    IN  NetrSamInfo3    *pIn,
    IN OUT PDWORD        pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    UINT32 iSid = 0;
    DWORD dwSidsOffset = 0;
    DWORD dwSidsSize = 0;
    DWORD dwSidsSpaceLeft = 0;
    PVOID pSids = NULL;
    NetrSidAttr **ppSids = NULL;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    ntStatus = NetrInitSamBaseInfo((NetrSamBaseInfo*)pBuffer,
                                   pdwOffset,
                                   pdwSpaceLeft,
                                   &pIn->base,
                                   pdwSize);
    BAIL_ON_NT_STATUS(ntStatus);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->sidcount);
    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->sidcount)
    {
        for (iSid = 0; iSid < pIn->sidcount; iSid++)
        {
            ntStatus = NetrAllocateSidAttr(NULL,
                                           &dwSidsOffset,
                                           NULL,
                                           &(pIn->sids[iSid]),
                                           &dwSidsSize);
            BAIL_ON_NT_STATUS(ntStatus);
        }
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwSidsSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->sids)
        {
            pSids = LWBUF_TARGET_PTR(pBuffer, dwSidsSize, pdwSpaceLeft);

            /* sanity check - the sids pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(NetrSidAttr*, pSids, dwError);

            dwSidsSpaceLeft = dwSidsSize;
            dwSidsOffset    = 0;

            /* Allocate the sid entries */
            for (iSid = 0; iSid < pIn->sidcount; iSid++)
            {
                PVOID pSidCursor = pSids + (iSid * sizeof(pIn->sids[0]));

                ntStatus = NetrAllocateSidAttr(pSidCursor,
                                               &dwSidsOffset,
                                               &dwSidsSpaceLeft,
                                               &(pIn->sids[iSid]),
                                               pdwSize);
                BAIL_ON_NT_STATUS(ntStatus);

                dwSidsOffset = 0;
            }
        }

        ppSids           = (NetrSidAttr**)pCursor;
        *ppSids          = (NetrSidAttr*)pSids;
        (*pdwSpaceLeft) -= (pSids) ? LWBUF_ALIGN_SIZE(dwSidsSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(NetrSidAttr*);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwSidsSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(NetrSidAttr*);
    (*pdwSize)   += sizeof(NetrSidAttr*);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #4
0
static
NTSTATUS
NetrAllocateChallengeResponse(
    OUT PVOID         pOut,
    IN OUT PDWORD     pdwOffset,
    IN OUT PDWORD     pdwSpaceLeft,
    IN  PBYTE         pResponse,
    IN  DWORD         dwResponseLen,
    IN OUT PDWORD     pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    PVOID pRespData = NULL;
    PBYTE *ppRespData = NULL;
    DWORD dwResponseSize = dwResponseLen;
    DWORD dwResponseSpaceLeft = 0;
    DWORD dwResponseOffset = 0;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    LWBUF_ALLOC_WORD(pBuffer, dwResponseLen);
    LWBUF_ALLOC_WORD(pBuffer, dwResponseLen);
    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwResponseSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pResponse)
        {
            pRespData = LWBUF_TARGET_PTR(pBuffer, dwResponseSize, pdwSpaceLeft);

            /* sanity check - the data pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(PBYTE, pRespData, dwError);

            dwResponseSpaceLeft = dwResponseSize;
            dwResponseOffset    = 0;

            dwError = LwBufferAllocFixedBlob(pRespData,
                                             &dwResponseOffset,
                                             &dwResponseSpaceLeft,
                                             pResponse,
                                             dwResponseSize,
                                             pdwSize);
            BAIL_ON_WIN_ERROR(dwError);
        }

        ppRespData       = (PBYTE*)pCursor;
        *ppRespData      = pRespData;
        (*pdwSpaceLeft) -= (pRespData) ? LWBUF_ALIGN_SIZE(dwResponseSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(PBYTE);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwResponseSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(PBYTE);
    (*pdwSize)   += sizeof(PBYTE);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #5
0
static
NTSTATUS
NetrAllocateDomainInfo1(
    OUT NetrDomainInfo1  *pOut,
    IN OUT PDWORD         pdwOffset,
    IN OUT PDWORD         pdwSpaceLeft,
    IN  NetrDomainInfo1  *pIn,
    IN OUT PDWORD         pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    DWORD iTrust = 0;
    DWORD dwTrustsSize = 0;
    DWORD dwTrustsOffset = 0;
    DWORD dwTrustsSpaceLeft = 0;
    PVOID pTrusts = NULL;
    NetrDomainTrustInfo **ppTrusts = NULL;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    ntStatus = NetrAllocateDomainTrustInfo(pBuffer,
                                           pdwOffset,
                                           pdwSpaceLeft,
                                           &pIn->domain_info,
                                           pdwSize);
    BAIL_ON_NT_STATUS(ntStatus);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->num_trusts);
    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->num_trusts)
    {
        for (iTrust = 0; iTrust < pIn->num_trusts; iTrust++)
        {
            ntStatus = NetrAllocateDomainTrustInfo(NULL,
                                                   &dwTrustsOffset,
                                                   NULL,
                                                   &(pIn->trusts[iTrust]),
                                                   &dwTrustsSize);
            BAIL_ON_NT_STATUS(ntStatus);
        }
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwTrustsSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->trusts)
        {
            pTrusts = LWBUF_TARGET_PTR(pBuffer, dwTrustsSize, pdwSpaceLeft);

            /* sanity check - the rids pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(NetrDomainTrustInfo*, pTrusts, dwError);

            dwTrustsSpaceLeft = dwTrustsSize;
            dwTrustsOffset    = 0;

            /* Allocate the trust entries */
            for (iTrust = 0; iTrust < pIn->num_trusts; iTrust++)
            {
                PVOID pTrustCursor = pTrusts +
                                     (iTrust * sizeof(NetrDomainTrustInfo));

                ntStatus = NetrAllocateDomainTrustInfo(pTrustCursor,
                                                       &dwTrustsOffset,
                                                       &dwTrustsSpaceLeft,
                                                       &(pIn->trusts[iTrust]),
                                                       pdwSize);
                BAIL_ON_NT_STATUS(ntStatus);

                dwTrustsOffset = 0;
            }
        }

        ppTrusts         = (NetrDomainTrustInfo**)pCursor;
        *ppTrusts        = (NetrDomainTrustInfo*)pTrusts;
        (*pdwSpaceLeft) -= (pTrusts) ? LWBUF_ALIGN_SIZE(dwTrustsSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(NetrDomainTrustInfo*);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwTrustsSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(NetrDomainTrustInfo*);
    (*pdwSize)   += sizeof(NetrDomainTrustInfo*);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #6
0
NTSTATUS
NetrAllocateDomainInfo(
    OUT NetrDomainInfo  *pOut,
    IN OUT PDWORD        pdwOffset,
    IN OUT PDWORD        pdwSpaceLeft,
    IN  WORD             swLevel,
    IN  NetrDomainInfo  *pIn,
    IN OUT PDWORD        pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    DWORD dwInfoSize = 0;
    DWORD dwInfoOffset = 0;
    DWORD dwInfoSpaceLeft = 0;
    PVOID pInfo = NULL;
    NetrDomainInfo1 **ppInfo = NULL;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    LWBUF_ALIGN(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->info1)
    {
        switch (swLevel)
        {
        case 1:
            ntStatus = NetrAllocateDomainInfo1(NULL,
                                               &dwInfoOffset,
                                               NULL,
                                               pIn->info1,
                                               &dwInfoSize);
            break;

        case 2:
            ntStatus = NetrAllocateDomainInfo1(NULL,
                                               &dwInfoOffset,
                                               NULL,
                                               pIn->info2,
                                               &dwInfoSize);
            break;

        default:
            ntStatus = STATUS_INVALID_LEVEL;
        }
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwInfoSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->info1)
        {
            pInfo = LWBUF_TARGET_PTR(pBuffer, dwInfoSize, pdwSpaceLeft);

            /* sanity check - the rids pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(NetrDomainInfo1*, pInfo, dwError);

            dwInfoSpaceLeft = dwInfoSize;
            dwInfoOffset    = 0;

            switch (swLevel)
            {
            case 1:
                ntStatus = NetrAllocateDomainInfo1(pBuffer,
                                                   &dwInfoOffset,
                                                   &dwInfoSpaceLeft,
                                                   pIn->info1,
                                                   pdwSize);
                break;

            case 2:
                ntStatus = NetrAllocateDomainInfo1(pBuffer,
                                                   &dwInfoOffset,
                                                   &dwInfoSpaceLeft,
                                                   pIn->info2,
                                                   pdwSize);
                break;

            default:
                ntStatus = STATUS_INVALID_LEVEL;
            }
            BAIL_ON_NT_STATUS(ntStatus);
        }

        ppInfo           = (NetrDomainInfo1**)pCursor;
        *ppInfo          = (NetrDomainInfo1*)pInfo;
        (*pdwSpaceLeft) -= (pInfo) ? LWBUF_ALIGN_SIZE(dwInfoSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft)  -= sizeof(NetrDomainInfo1*);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwInfoSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(NetrDomainInfo1*);
    (*pdwSize)   += sizeof(NetrDomainInfo1*);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #7
0
static
NTSTATUS
LsaAllocateAuditEventsInfo(
    OUT PVOID            pOut,
    IN OUT PDWORD        pdwOffset,
    IN OUT PDWORD        pdwSpaceLeft,
    IN AuditEventsInfo  *pIn,
    IN OUT PDWORD        pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    PVOID pBlob = NULL;
    PVOID *ppBlob = NULL;
    DWORD dwBlobSize = 0;
    DWORD dwBlobSpaceLeft = 0;
    DWORD dwBlobOffset = 0;

    LWBUF_ALLOC_DWORD(pBuffer, pIn->auditing_mode);
    LWBUF_ALIGN_PTR(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->count)
    {
        dwBlobSize = sizeof(pIn->settings[0]) * pIn->count;
    }

    /* Set pointer to the entries array */
    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwBlobSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->count)
        {
            pBlob = LWBUF_TARGET_PTR(pBuffer, dwBlobSize, pdwSpaceLeft);

            /* sanity check - the blob and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(AuditEventsInfo*, pBlob, dwError);

            dwBlobSpaceLeft = dwBlobSize;
            dwBlobSize      = 0;
            dwBlobOffset    = 0;

            dwError = LwBufferAllocFixedBlob(
                                       pBlob,
                                       &dwBlobSize,
                                       &dwBlobSpaceLeft,
                                       (PBYTE)pIn->settings,
                                       sizeof(pIn->settings[0]) * pIn->count,
                                       &dwBlobSize);
            BAIL_ON_WIN_ERROR(dwError);
        }

        ppBlob           = (PVOID*)pCursor;
        *ppBlob          = (PVOID)pBlob;
        (*pdwSpaceLeft) -= (pBlob) ? LWBUF_ALIGN_SIZE(dwBlobSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft) -= sizeof(PVOID);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwBlobSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(PVOID);
    (*pdwSize)   += sizeof(PVOID);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->count);

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

    return ntStatus;

error:
    goto cleanup;
}
예제 #8
0
NTSTATUS
LsaAllocateRefDomainList(
    OUT RefDomainList *pOut,
    IN OUT PDWORD      pdwOffset,
    IN OUT PDWORD      pdwSpaceLeft,
    IN  RefDomainList *pIn,
    IN OUT PDWORD      pdwSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwError = ERROR_SUCCESS;
    PVOID pBuffer = pOut;
    PVOID pCursor = NULL;
    PVOID pDomains = NULL;
    PVOID *ppDomains = NULL;
    DWORD iDom = 0;
    DWORD dwDomainsSize = 0;
    DWORD dwDomainsSpaceLeft = 0;
    DWORD dwDomainsOffset = 0;

    BAIL_ON_INVALID_PTR(pdwOffset, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);
    BAIL_ON_INVALID_PTR(pdwSize, ntStatus);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->count);
    LWBUF_ALIGN_PTR(pdwOffset, pdwSize, pdwSpaceLeft);

    if (pIn->count > 0)
    {
        for (iDom = 0; iDom < pIn->count; iDom++)
        {
            ntStatus = LsaAllocateDomainInfo(NULL,
                                             &dwDomainsOffset,
                                             NULL,
                                             &(pIn->domains[iDom]),
                                             &dwDomainsSize);
            BAIL_ON_NT_STATUS(ntStatus);
        }
    }

    if (pBuffer && pdwSpaceLeft)
    {
        BAIL_IF_NOT_ENOUGH_SPACE(dwDomainsSize, pdwSpaceLeft, dwError);
        pCursor = pBuffer + (*pdwOffset);

        if (pIn->count)
        {
            pDomains = LWBUF_TARGET_PTR(pBuffer, dwDomainsSize, pdwSpaceLeft);

            /* sanity check - the data pointer and current buffer cursor
               must not overlap */
            BAIL_IF_PTR_OVERLAP(PBYTE, pDomains, dwError);

            dwDomainsSpaceLeft = dwDomainsSize;
            dwDomainsOffset    = 0;

            /* Allocate the entries */
            for (iDom = 0; iDom < pIn->count; iDom++)
            {
                PVOID pDomCursor = pDomains + (iDom * sizeof(pIn->domains[0]));

                ntStatus = LsaAllocateDomainInfo(pDomCursor,
                                                 &dwDomainsOffset,
                                                 &dwDomainsSpaceLeft,
                                                 &(pIn->domains[iDom]),
                                                 pdwSize);
                BAIL_ON_NT_STATUS(ntStatus);

                dwDomainsOffset = 0;
            }
        }

        ppDomains        = (PVOID*)pCursor;
        *ppDomains       = (PVOID)pDomains;
        (*pdwSpaceLeft) -= (pDomains) ? LWBUF_ALIGN_SIZE(dwDomainsSize) : 0;

        /* recalculate space after setting the pointer */
        (*pdwSpaceLeft) -= sizeof(PVOID);
    }
    else
    {
        (*pdwSize) += LWBUF_ALIGN_SIZE(dwDomainsSize);
    }

    /* include size of the pointer */
    (*pdwOffset) += sizeof(PVOID);
    (*pdwSize)   += sizeof(PVOID);

    LWBUF_ALLOC_DWORD(pBuffer, pIn->max_size);

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

    return ntStatus;

error:
    goto cleanup;
}