static VOID SrvReleaseGetInfoStateHandle_SMB_V2( HANDLE hGetInfoState ) { return SrvReleaseGetInfoState_SMB_V2( (PSRV_GET_INFO_STATE_SMB_V2)hGetInfoState); }
NTSTATUS SrvProcessGetInfo_SMB_V2( PSRV_EXEC_CONTEXT pExecContext ) { NTSTATUS ntStatus = STATUS_SUCCESS; PLWIO_SRV_CONNECTION pConnection = pExecContext->pConnection; PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol = pExecContext->pProtocolContext; PSRV_EXEC_CONTEXT_SMB_V2 pCtxSmb2 = pCtxProtocol->pSmb2Context; PSRV_GET_INFO_STATE_SMB_V2 pGetInfoState = NULL; PLWIO_SRV_SESSION_2 pSession = NULL; PLWIO_SRV_TREE_2 pTree = NULL; PLWIO_SRV_FILE_2 pFile = NULL; BOOLEAN bInLock = FALSE; pGetInfoState = (PSRV_GET_INFO_STATE_SMB_V2)pCtxSmb2->hState; if (pGetInfoState) { InterlockedIncrement(&pGetInfoState->refCount); } else { ULONG iMsg = pCtxSmb2->iMsg; PSRV_MESSAGE_SMB_V2 pSmbRequest = &pCtxSmb2->pRequests[iMsg]; PSMB2_GET_INFO_REQUEST_HEADER pRequestHeader = NULL; // Do not free PBYTE pInputBuffer = NULL; ULONG ulInputBufferLength = 0; ntStatus = SrvConnection2FindSession_SMB_V2( pCtxSmb2, pConnection, pSmbRequest->pHeader->ullSessionId, &pSession); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvSetStatSession2Info(pExecContext, pSession); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvSession2FindTree_SMB_V2( pCtxSmb2, pSession, pSmbRequest->pHeader->ulTid, &pTree); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SMB2UnmarshalGetInfoRequest( pSmbRequest, &pRequestHeader, &pInputBuffer, &ulInputBufferLength); BAIL_ON_NT_STATUS(ntStatus); SRV_LOG_DEBUG( pExecContext->pLogContext, SMB_PROTOCOL_VERSION_2, pSmbRequest->pHeader->command, "Get Info request params: " "command(%u),uid(%llu),cmd-seq(%llu),pid(%u),tid(%u)," "credits(%u),flags(0x%x),chain-offset(%u)," "file-id(persistent:0x%x,volatile:0x%x)," "info-class(0x%x),info-type(0x%x),flags(0x%x)," "input-buffer-length(%u),input-buffer-offset(%u)," "output-buffer-length(%u),additional-info(%u)", pSmbRequest->pHeader->command, (long long)pSmbRequest->pHeader->ullSessionId, (long long)pSmbRequest->pHeader->ullCommandSequence, pSmbRequest->pHeader->ulPid, pSmbRequest->pHeader->ulTid, pSmbRequest->pHeader->usCredits, pSmbRequest->pHeader->ulFlags, pSmbRequest->pHeader->ulChainOffset, (long long)pRequestHeader->fid.ullPersistentId, (long long)pRequestHeader->fid.ullVolatileId, pRequestHeader->ucInfoClass, pRequestHeader->ucInfoType, pRequestHeader->ulFlags, pRequestHeader->ulInputBufferLen, pRequestHeader->usInputBufferOffset, pRequestHeader->ulOutputBufferLen, pRequestHeader->ulAdditionalInfo); ntStatus = SrvTree2FindFile_SMB_V2( pCtxSmb2, pTree, &pRequestHeader->fid, &pFile); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvBuildGetInfoState_SMB_V2( pRequestHeader, pFile, pInputBuffer, ulInputBufferLength, &pGetInfoState); BAIL_ON_NT_STATUS(ntStatus); pCtxSmb2->hState = pGetInfoState; InterlockedIncrement(&pGetInfoState->refCount); pCtxSmb2->pfnStateRelease = &SrvReleaseGetInfoStateHandle_SMB_V2; } LWIO_LOCK_MUTEX(bInLock, &pGetInfoState->mutex); switch (pGetInfoState->stage) { case SRV_GET_INFO_STAGE_SMB_V2_INITIAL: pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_ATTEMPT_IO; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_ATTEMPT_IO: ntStatus = SrvQueryInfo_SMB_V2(pExecContext); BAIL_ON_NT_STATUS(ntStatus); pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_BUILD_RESPONSE; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_BUILD_RESPONSE: ntStatus = SrvBuildGetInfoResponse_SMB_V2(pExecContext); BAIL_ON_NT_STATUS(ntStatus); pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_DONE; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_DONE: break; } cleanup: if (pFile) { SrvFile2Release(pFile); } if (pTree) { SrvTree2Release(pTree); } if (pSession) { SrvSession2Release(pSession); } if (pGetInfoState) { LWIO_UNLOCK_MUTEX(bInLock, &pGetInfoState->mutex); SrvReleaseGetInfoState_SMB_V2(pGetInfoState); } return ntStatus; error: switch (ntStatus) { case STATUS_PENDING: // TODO: Add an indicator to the file object to trigger a // cleanup if the connection gets closed and all the // files involved have to be closed break; default: if (pGetInfoState) { SrvReleaseGetInfoStateAsync_SMB_V2(pGetInfoState); } break; } goto cleanup; }
NTSTATUS SrvProcessGetInfo_SMB_V2( PSRV_EXEC_CONTEXT pExecContext ) { NTSTATUS ntStatus = STATUS_SUCCESS; PLWIO_SRV_CONNECTION pConnection = pExecContext->pConnection; PSRV_PROTOCOL_EXEC_CONTEXT pCtxProtocol = pExecContext->pProtocolContext; PSRV_EXEC_CONTEXT_SMB_V2 pCtxSmb2 = pCtxProtocol->pSmb2Context; PSRV_GET_INFO_STATE_SMB_V2 pGetInfoState = NULL; PLWIO_SRV_SESSION_2 pSession = NULL; PLWIO_SRV_TREE_2 pTree = NULL; PLWIO_SRV_FILE_2 pFile = NULL; BOOLEAN bInLock = FALSE; pGetInfoState = (PSRV_GET_INFO_STATE_SMB_V2)pCtxSmb2->hState; if (pGetInfoState) { InterlockedIncrement(&pGetInfoState->refCount); } else { ULONG iMsg = pCtxSmb2->iMsg; PSRV_MESSAGE_SMB_V2 pSmbRequest = &pCtxSmb2->pRequests[iMsg]; PSMB2_GET_INFO_REQUEST_HEADER pRequestHeader = NULL; // Do not free ntStatus = SrvConnection2FindSession_SMB_V2( pCtxSmb2, pConnection, pSmbRequest->pHeader->ullSessionId, &pSession); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvSetStatSession2Info(pExecContext, pSession); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvSession2FindTree_SMB_V2( pCtxSmb2, pSession, pSmbRequest->pHeader->ulTid, &pTree); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SMB2UnmarshalGetInfoRequest(pSmbRequest, &pRequestHeader); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvTree2FindFile_SMB_V2( pCtxSmb2, pTree, &pRequestHeader->fid, LwIsSetFlag( pSmbRequest->pHeader->ulFlags, SMB2_FLAGS_RELATED_OPERATION), &pFile); BAIL_ON_NT_STATUS(ntStatus); ntStatus = SrvBuildGetInfoState_SMB_V2( pRequestHeader, pFile, &pGetInfoState); BAIL_ON_NT_STATUS(ntStatus); pCtxSmb2->hState = pGetInfoState; InterlockedIncrement(&pGetInfoState->refCount); pCtxSmb2->pfnStateRelease = &SrvReleaseGetInfoStateHandle_SMB_V2; } LWIO_LOCK_MUTEX(bInLock, &pGetInfoState->mutex); switch (pGetInfoState->stage) { case SRV_GET_INFO_STAGE_SMB_V2_INITIAL: pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_ATTEMPT_IO; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_ATTEMPT_IO: ntStatus = SrvQueryInfo_SMB_V2(pExecContext); BAIL_ON_NT_STATUS(ntStatus); pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_BUILD_RESPONSE; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_BUILD_RESPONSE: ntStatus = SrvBuildGetInfoResponse_SMB_V2(pExecContext); BAIL_ON_NT_STATUS(ntStatus); pGetInfoState->stage = SRV_GET_INFO_STAGE_SMB_V2_DONE; // Intentional fall through case SRV_GET_INFO_STAGE_SMB_V2_DONE: break; } cleanup: if (pFile) { SrvFile2Release(pFile); } if (pTree) { SrvTree2Release(pTree); } if (pSession) { SrvSession2Release(pSession); } if (pGetInfoState) { LWIO_UNLOCK_MUTEX(bInLock, &pGetInfoState->mutex); SrvReleaseGetInfoState_SMB_V2(pGetInfoState); } return ntStatus; error: switch (ntStatus) { case STATUS_PENDING: // TODO: Add an indicator to the file object to trigger a // cleanup if the connection gets closed and all the // files involved have to be closed break; default: if (pGetInfoState) { SrvReleaseGetInfoStateAsync_SMB_V2(pGetInfoState); } break; } goto cleanup; }