示例#1
0
static
VOID
IopIrpFree(
    IN OUT PIRP* ppIrp
    )
{
    PIRP pIrp = *ppIrp;

    if (pIrp)
    {
        PIRP_INTERNAL irpInternal = IopIrpGetInternal(pIrp);

        LWIO_ASSERT(0 == irpInternal->ReferenceCount);
        LWIO_ASSERT(STATUS_PENDING != pIrp->IoStatusBlock.Status);

        switch (pIrp->Type)
        {
            case IRP_TYPE_CREATE:
            case IRP_TYPE_CREATE_NAMED_PIPE:
                IoSecurityDereferenceSecurityContext(&pIrp->Args.Create.SecurityContext);
                RtlWC16StringFree(&pIrp->Args.Create.FileName.FileName);
                break;
            case IRP_TYPE_QUERY_DIRECTORY:
                if (pIrp->Args.QueryDirectory.FileSpec)
                {
                    LwRtlUnicodeStringFree(&pIrp->Args.QueryDirectory.FileSpec->Pattern);
                    IO_FREE(&pIrp->Args.QueryDirectory.FileSpec);
                }
                break;
            default:
                break;
        }

        // Note that the parent (FO) lock is already held
        // by IopIrpDereference().

        // Might not be in the list if IRP creation failed.
        if (irpInternal->FileObjectLinks.Next)
        {
            LwListRemove(&irpInternal->FileObjectLinks);
        }
        IopFileObjectDereference(&pIrp->FileHandle);

        IoMemoryFree(pIrp);
        *ppIrp = NULL;
    }
}
static NTSTATUS
FillFileIdFullDirInfoBuffer(
    PVOID pBuffer,
    DWORD dwBufLen,
    PSTR pszParent,
    PPVFS_DIRECTORY_ENTRY pEntry,
    PDWORD pdwConsumed
    )
{
    NTSTATUS ntError = STATUS_UNSUCCESSFUL;
    PFILE_ID_FULL_DIR_INFORMATION pFileInfo = (PFILE_ID_FULL_DIR_INFORMATION)pBuffer;
    PWSTR pwszFilename = NULL;
    PSTR pszFullPath = NULL;
    DWORD dwNeeded = 0;
    size_t W16FilenameLen = 0;
    size_t W16FilenameLenBytes = 0;

    /* Check for enough space for static members */

    if (dwBufLen < sizeof(*pFileInfo))
    {
        ntError = STATUS_BUFFER_TOO_SMALL;
        BAIL_ON_NT_STATUS(ntError);
    }

    /* Build the absolute path and stat() it */

    ntError = RtlCStringAllocatePrintf(
                  &pszFullPath,
                  "%s/%s",
                  pszParent,
                  pEntry->pszFilename);
    BAIL_ON_NT_STATUS(ntError);

    ntError = PvfsSysStat(pszFullPath, &pEntry->Stat);
    BAIL_ON_NT_STATUS(ntError);

    ntError = RtlWC16StringAllocateFromCString(
                  &pwszFilename,
                  pEntry->pszFilename);
    BAIL_ON_NT_STATUS(ntError);

    ntError = FillFileIdFullDirInfoStatic(
                  pFileInfo,
                  pwszFilename,
                  &pEntry->Stat);
    BAIL_ON_NT_STATUS(ntError);

    /* We have more information here to fill in the
       file attributes */

    ntError = PvfsGetFilenameAttributes(
                  pszFullPath,
                  &pFileInfo->FileAttributes);
    BAIL_ON_NT_STATUS(ntError);

    /* Save what we have used so far */

    *pdwConsumed = sizeof(*pFileInfo);

    /* Calculate space */

    W16FilenameLen = RtlWC16StringNumChars(pwszFilename);
    W16FilenameLenBytes = W16FilenameLen * sizeof(WCHAR);
    dwNeeded = sizeof(*pFileInfo) + W16FilenameLenBytes;

    /* alignment on 8 byte boundary */

    if (dwNeeded % 8) {
        dwNeeded += 8 - (dwNeeded % 8);
    }

    if (dwNeeded > dwBufLen)
    {
        ntError = STATUS_BUFFER_TOO_SMALL;
        BAIL_ON_NT_STATUS(ntError);
    }

    pFileInfo->FileNameLength = W16FilenameLenBytes;
    memcpy(pFileInfo->FileName, pwszFilename, W16FilenameLenBytes);

    *pdwConsumed = dwNeeded;
    ntError = STATUS_SUCCESS;

cleanup:
    RtlCStringFree(&pszFullPath);
    RtlWC16StringFree(&pwszFilename);

    return ntError;

error:
    goto cleanup;
}
示例#3
0
NTSTATUS
LsaOpenPolicy2(
    IN  LSA_BINDING      hBinding,
    IN  PCWSTR           pwszSysName,
    IN  PVOID            attrib,
    IN  UINT32           AccessMask,
    OUT POLICY_HANDLE   *phPolicy
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    WCHAR wszDefaultSysName[] = LSA_DEFAULT_SYSNAME;
    PWSTR pwszSystemName = NULL;
    POLICY_HANDLE hPolicy = NULL;
    SECURITY_QUALITY_OF_SERVICE SecQos = {0};
    ObjectAttribute ObjAttribute = {0};

    BAIL_ON_INVALID_PTR(hBinding, ntStatus);
    BAIL_ON_INVALID_PTR(phPolicy, ntStatus);

    ntStatus = RtlWC16StringDuplicate(
                        &pwszSystemName,
                        (pwszSysName) ? pwszSysName : &(wszDefaultSysName[0]));
    BAIL_ON_NT_STATUS(ntStatus);

    /* ObjectAttribute argument is not used, so just
       pass an empty structure */

    SecQos.Length              = 0;
    SecQos.ImpersonationLevel  = SecurityImpersonation;
    SecQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
    SecQos.EffectiveOnly       = 0;

    ObjAttribute.len          = 0;
    ObjAttribute.root_dir     = NULL;
    ObjAttribute.object_name  = NULL;
    ObjAttribute.attributes   = 0;
    ObjAttribute.sec_desc     = NULL;
    // TODO-QOS field in object attributes should probaby be NULL.
    ObjAttribute.sec_qos      = &SecQos;

    DCERPC_CALL(ntStatus, cli_LsaOpenPolicy2(
                              (handle_t)hBinding,
                              pwszSystemName,
                              &ObjAttribute,
                              AccessMask,
                              &hPolicy));
    BAIL_ON_NT_STATUS(ntStatus);

    *phPolicy = hPolicy;

cleanup:
    RtlWC16StringFree(&pwszSystemName);

    return ntStatus;

error:
    if (phPolicy)
    {
        *phPolicy = NULL;
    }

    goto cleanup;
}