Example #1
0
static
NTSTATUS
SrvSetDispositionInfo(
    PSRV_EXEC_CONTEXT pExecContext
    )
{
    NTSTATUS                      ntStatus     = 0;
    PSRV_PROTOCOL_EXEC_CONTEXT    pCtxProtocol = pExecContext->pProtocolContext;
    PSRV_EXEC_CONTEXT_SMB_V1      pCtxSmb1     = pCtxProtocol->pSmb1Context;
    PSRV_TRANS2_STATE_SMB_V1      pTrans2State = NULL;

    pTrans2State = (PSRV_TRANS2_STATE_SMB_V1)pCtxSmb1->hState;

    if (pTrans2State->pRequestHeader->dataCount  < sizeof(FILE_DISPOSITION_INFORMATION))
    {
        ntStatus = STATUS_INVALID_NETWORK_RESPONSE;
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (!pTrans2State->bSetInfoAttempted)
    {
        PFILE_DISPOSITION_INFORMATION pFileDispositionInfo =
                        (PFILE_DISPOSITION_INFORMATION)pTrans2State->pData;

        SrvUnmarshallBoolean(&pFileDispositionInfo->DeleteFile);

		pTrans2State->bSetInfoAttempted = TRUE;

        SrvPrepareTrans2StateAsync(pTrans2State, pExecContext);

        ntStatus = IoSetInformationFile(
                        (pTrans2State->pFile ? pTrans2State->pFile->hFile :
                                               pTrans2State->hFile),
                        pTrans2State->pAcb,
                        &pTrans2State->ioStatusBlock,
                        pFileDispositionInfo,
                        sizeof(FILE_DISPOSITION_INFORMATION),
                        FileDispositionInformation);
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseTrans2StateAsync(pTrans2State); // completed synchronously
    }

error:

    return ntStatus;
}
Example #2
0
static
NTSTATUS
SrvSetEaList(
    PSRV_EXEC_CONTEXT pExecContext
    )
{
    NTSTATUS                   ntStatus     = 0;
    PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol = pExecContext->pProtocolContext;
    PSRV_EXEC_CONTEXT_SMB_V1   pCtxSmb1     = pCtxProtocol->pSmb1Context;
    PSRV_TRANS2_STATE_SMB_V1   pTrans2State = NULL;

    pTrans2State = (PSRV_TRANS2_STATE_SMB_V1)pCtxSmb1->hState;

    if (!pTrans2State->pData2)
    {
        ntStatus = SrvUnmarshalSetEaListInformation(pExecContext);
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (!pTrans2State->bSetInfoAttempted)
    {
        pTrans2State->bSetInfoAttempted = TRUE;

        SrvPrepareTrans2StateAsync(pTrans2State, pExecContext);

        ntStatus = IoSetInformationFile(
                        (pTrans2State->pFile ? pTrans2State->pFile->hFile :
                                               pTrans2State->hFile),
                        pTrans2State->pAcb,
                        &pTrans2State->ioStatusBlock,
                        (PFILE_FULL_EA_INFORMATION)pTrans2State->pData2,
                        pTrans2State->usBytesAllocated,
                        FileFullEaInformation);
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseTrans2StateAsync(pTrans2State); // completed synchronously
    }

error:

    return ntStatus;
}
Example #3
0
static
NTSTATUS
SrvRenameFile(
    PSRV_EXEC_CONTEXT pExecContext
    )
{
    NTSTATUS                   ntStatus     = 0;
    PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol = pExecContext->pProtocolContext;
    PSRV_EXEC_CONTEXT_SMB_V1   pCtxSmb1     = pCtxProtocol->pSmb1Context;
    PSRV_TRANS2_STATE_SMB_V1   pTrans2State = NULL;

    pTrans2State = (PSRV_TRANS2_STATE_SMB_V1)pCtxSmb1->hState;

    if (!pTrans2State->pData2)
    {
        ntStatus = SrvUnmarshalRenameInformation(pExecContext);
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (pTrans2State->pRootDir)
    {
        ((PFILE_RENAME_INFORMATION)pTrans2State->pData2)->RootDirectory =
                                                  pTrans2State->pRootDir->hFile;
    }
    else if (!pTrans2State->hDir)
    {
        wchar16_t wszBackSlash[] = { '\\', 0 };

        PFILE_RENAME_INFORMATION pRenameInfo    =
                        (PFILE_RENAME_INFORMATION)pTrans2State->pData2;

        if (*pRenameInfo->FileName == wszBackSlash[0])
        {
            ntStatus = STATUS_NOT_SUPPORTED;
        }
        else if (pTrans2State->pFile)
        {
            ntStatus = SrvGetParentPath(
                            &pTrans2State->pFile->pFilename->Name,
                            &pTrans2State->dirPath.Name);
        }
        else if (pTrans2State->hFile)
        {
            ntStatus = SrvGetParentPath(
                            &pTrans2State->fileName.Name,
                            &pTrans2State->dirPath.Name);
        }
        else
        {
            ntStatus = STATUS_INVALID_PARAMETER;
        }
        BAIL_ON_NT_STATUS(ntStatus);

        pTrans2State->dirPath.RootFileHandle = pTrans2State->pTree->hFile;

        // Catch failed CreateFile calls when they come back around

        ntStatus = pTrans2State->ioStatusBlock.Status;
        BAIL_ON_NT_STATUS(ntStatus);

        SrvPrepareTrans2StateAsync(pTrans2State, pExecContext);

        ntStatus = SrvIoCreateFile(
                                pTrans2State->pTree->pShareInfo,
                                &pTrans2State->hDir,
                                pTrans2State->pAcb,
                                &pTrans2State->ioStatusBlock,
                                pCtxSmb1->pSession->pIoSecurityContext,
                                &pTrans2State->dirPath,
                                pTrans2State->pSecurityDescriptor,
                                pTrans2State->pSecurityQOS,
                                GENERIC_READ,
                                0,
                                FILE_ATTRIBUTE_NORMAL,
                                FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                                FILE_OPEN,
                                FILE_DIRECTORY_FILE,
                                NULL, /* EA Buffer */
                                0,    /* EA Length */
                                pTrans2State->pEcpList
                                );
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseTrans2StateAsync(pTrans2State); // completed synchronously
    }

    if (!pTrans2State->pRootDir)
    {
        ((PFILE_RENAME_INFORMATION)pTrans2State->pData2)->RootDirectory =
                                                            pTrans2State->hDir;
    }

    if (!pTrans2State->bSetInfoAttempted)
    {
        pTrans2State->bSetInfoAttempted = TRUE;

        SrvPrepareTrans2StateAsync(pTrans2State, pExecContext);

        ntStatus = IoSetInformationFile(
                    (pTrans2State->pFile ? pTrans2State->pFile->hFile :
                                           pTrans2State->hFile),
                    pTrans2State->pAcb,
                    &pTrans2State->ioStatusBlock,
                    (PFILE_RENAME_INFORMATION)pTrans2State->pData2,
                    pTrans2State->usBytesAllocated,
                    FileRenameInformation);
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseTrans2StateAsync(pTrans2State); // completed synchronously
    }

error:

    return ntStatus;
}
Example #4
0
static
NTSTATUS
SrvSetSmbStandardInfo(
    PSRV_EXEC_CONTEXT pExecContext
    )
{
    NTSTATUS                   ntStatus       = 0;
    PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol   = pExecContext->pProtocolContext;
    PSRV_EXEC_CONTEXT_SMB_V1   pCtxSmb1       = pCtxProtocol->pSmb1Context;
    PSRV_TRANS2_STATE_SMB_V1   pTrans2State   = NULL;
    FILE_BASIC_INFORMATION     FileBasicInfo  = {0};
    PTRANS2_FILE_SMB_INFO_STANDARD_SET pFileSmbInfoStandard = NULL;

    pTrans2State = (PSRV_TRANS2_STATE_SMB_V1)pCtxSmb1->hState;

    if (pTrans2State->pRequestHeader->dataCount <
        sizeof(TRANS2_FILE_SMB_INFO_STANDARD_SET))
    {
        ntStatus = STATUS_INVALID_NETWORK_RESPONSE;
        BAIL_ON_NT_STATUS(ntStatus);
    }

    if (!pTrans2State->bSetInfoAttempted)
    {
        pFileSmbInfoStandard =
            (PTRANS2_FILE_SMB_INFO_STANDARD_SET)pTrans2State->pData;

        ntStatus = WireSMBDateTimeToNTTime(
            &pFileSmbInfoStandard->CreationDate,
            &pFileSmbInfoStandard->CreationTime,
            &FileBasicInfo.CreationTime);
        BAIL_ON_NT_STATUS(ntStatus);

        ntStatus = WireSMBDateTimeToNTTime(
            &pFileSmbInfoStandard->LastAccessDate,
            &pFileSmbInfoStandard->LastAccessTime,
            &FileBasicInfo.LastAccessTime);

        ntStatus = WireSMBDateTimeToNTTime(
            &pFileSmbInfoStandard->LastWriteDate,
            &pFileSmbInfoStandard->LastWriteTime,
            &FileBasicInfo.LastWriteTime);
        BAIL_ON_NT_STATUS(ntStatus);

        pTrans2State->bSetInfoAttempted = TRUE;

        SrvPrepareTrans2StateAsync(pTrans2State, pExecContext);

        ntStatus = IoSetInformationFile(
                        (pTrans2State->pFile ? pTrans2State->pFile->hFile :
                                               pTrans2State->hFile),
                        pTrans2State->pAcb,
                        &pTrans2State->ioStatusBlock,
                        &FileBasicInfo,
                        sizeof(FILE_BASIC_INFORMATION),
                        FileBasicInformation);
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseTrans2StateAsync(pTrans2State); // completed synchronously
    }

error:

    return ntStatus;
}
Example #5
0
static
NTSTATUS
SrvExecuteRename(
    PSRV_EXEC_CONTEXT pExecContext
    )
{
    NTSTATUS                   ntStatus        = 0;
    PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol    = pExecContext->pProtocolContext;
    PSRV_EXEC_CONTEXT_SMB_V1   pCtxSmb1        = pCtxProtocol->pSmb1Context;
    PSRV_RENAME_STATE_SMB_V1   pRenameState    = NULL;

    pRenameState = (PSRV_RENAME_STATE_SMB_V1)pCtxSmb1->hState;

    ntStatus = pRenameState->ioStatusBlock.Status;
    BAIL_ON_NT_STATUS(ntStatus);

    if (!pRenameState->hDir)
    {
        SrvPrepareRenameStateAsync(pRenameState, pExecContext);

        ntStatus = SrvIoCreateFile(
                        pCtxSmb1->pTree->pShareInfo,
                        &pRenameState->hDir,
                        pRenameState->pAcb,
                        &pRenameState->ioStatusBlock,
                        pCtxSmb1->pSession->pIoSecurityContext,
                        &pRenameState->dirPath,
                        pRenameState->pSecurityDescriptor,
                        pRenameState->pSecurityQOS,
                        GENERIC_READ,
                        0,
                        FILE_ATTRIBUTE_NORMAL,
                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                        FILE_OPEN,
                        FILE_DIRECTORY_FILE,
                        NULL, /* EA Buffer */
                        0,    /* EA Length */
                        pRenameState->pDirEcpList
                        );
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseRenameStateAsync(pRenameState); // completed synchronously
    }

    if (!pRenameState->hFile)
    {
        SrvPrepareRenameStateAsync(pRenameState, pExecContext);

        ntStatus = SrvIoCreateFile(
                        pCtxSmb1->pTree->pShareInfo,
                        &pRenameState->hFile,
                        pRenameState->pAcb,
                        &pRenameState->ioStatusBlock,
                        pCtxSmb1->pSession->pIoSecurityContext,
                        &pRenameState->oldName,
                        pRenameState->pSecurityDescriptor,
                        pRenameState->pSecurityQOS,
                        DELETE,
                        0,
                        FILE_ATTRIBUTE_NORMAL,
                        FILE_SHARE_READ,
                        FILE_OPEN,
                        0,
                        NULL, /* EA Buffer */
                        0,    /* EA Length */
                        pRenameState->pFileEcpList
                        );
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseRenameStateAsync(pRenameState); // completed synchronously
    }

    if (!pRenameState->pFileRenameInfo)
    {
        pRenameState->ulDataLen =
                sizeof(FILE_RENAME_INFORMATION) +
                wc16slen(pRenameState->newName.FileName) * sizeof(wchar16_t);

        ntStatus = SrvAllocateMemory(
                        pRenameState->ulDataLen,
                        (PVOID*)&pRenameState->pData);
        BAIL_ON_NT_STATUS(ntStatus);

        pRenameState->pFileRenameInfo =
                    (PFILE_RENAME_INFORMATION)pRenameState->pData;

        pRenameState->pFileRenameInfo->ReplaceIfExists = FALSE;
        pRenameState->pFileRenameInfo->RootDirectory   = pRenameState->hDir;
        pRenameState->pFileRenameInfo->FileNameLength  =
                wc16slen(pRenameState->newName.FileName) * sizeof(wchar16_t);
        memcpy( (PBYTE)pRenameState->pFileRenameInfo->FileName,
                (PBYTE)pRenameState->newName.FileName,
                pRenameState->pFileRenameInfo->FileNameLength);

        SrvPrepareRenameStateAsync(pRenameState, pExecContext);

        ntStatus = IoSetInformationFile(
                        pRenameState->hFile,
                        pRenameState->pAcb,
                        &pRenameState->ioStatusBlock,
                        pRenameState->pFileRenameInfo,
                        pRenameState->ulDataLen,
                        FileRenameInformation);
        BAIL_ON_NT_STATUS(ntStatus);

        SrvReleaseRenameStateAsync(pRenameState); // completed synchronously
    }

cleanup:

    return ntStatus;

error:

    goto cleanup;
}