NTSTATUS PvfsAllocateCreateContext( OUT PPVFS_PENDING_CREATE *ppCreate, IN PPVFS_IRP_CONTEXT pIrpContext ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; PPVFS_PENDING_CREATE pCreateCtx = NULL; IRP_ARGS_CREATE Args = pIrpContext->pIrp->Args.Create; PIO_CREATE_SECURITY_CONTEXT pSecCtx = Args.SecurityContext; ntError = PvfsAllocateMemory( (PVOID*)&pCreateCtx, sizeof(PVFS_PENDING_CREATE)); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCanonicalPathName( &pCreateCtx->pszOriginalFilename, Args.FileName); BAIL_ON_NT_STATUS(ntError); ntError = PvfsAllocateCCB(&pCreateCtx->pCcb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsAcquireAccessToken(pCreateCtx->pCcb, pSecCtx); BAIL_ON_NT_STATUS(ntError); pCreateCtx->pIrpContext = PvfsReferenceIrpContext(pIrpContext); *ppCreate = pCreateCtx; pCreateCtx = NULL; cleanup: return ntError; error: PvfsFreeCreateContext((PVOID*)&pCreateCtx); goto cleanup; }
static NTSTATUS PvfsCreateDirOpen( PPVFS_IRP_CONTEXT pIrpContext ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; IRP_ARGS_CREATE Args = pIrpContext->pIrp->Args.Create; PPVFS_PENDING_CREATE pCreateCtx = NULL; PVFS_STAT Stat = {0}; ntError = PvfsAllocateCreateContext(&pCreateCtx, pIrpContext); BAIL_ON_NT_STATUS(ntError); if (IsSetFlag( pCreateCtx->OriginalFileName->NameOptions, PVFS_FILE_NAME_OPTION_DEFINED_STREAM_TYPE)) { // Disallow named streams here (shouldn't happen) and "::$DATA" ntError = STATUS_NOT_A_DIRECTORY; BAIL_ON_NT_STATUS(ntError); } ntError = PvfsLookupPath2( &pCreateCtx->ResolvedFileName, &Stat, pCreateCtx->OriginalFileName, IsSetFlag(Args.FileName.IoNameOptions, IO_NAME_OPTION_CASE_SENSITIVE)); BAIL_ON_NT_STATUS(ntError); if (!S_ISDIR(Stat.s_mode)) { ntError = STATUS_NOT_A_DIRECTORY; BAIL_ON_NT_STATUS(ntError); } ntError = PvfsAccessCheckFile( pCreateCtx->pCcb->pUserToken, pCreateCtx->ResolvedFileName, Args.DesiredAccess, &pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCheckDosAttributes( Args, pCreateCtx->bFileExisted ? pCreateCtx->ResolvedFileName : NULL, pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCheckShareMode( pCreateCtx->ResolvedFileName, Args.ShareAccess, pCreateCtx->GrantedAccess, &pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateFileCheckPendingDelete(pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCheckQuotaFile(&Args, pCreateCtx->pCcb); BAIL_ON_NT_STATUS(ntError); pCreateCtx->bFileExisted = TRUE; ntError = PvfsAddCCBToSCB(pCreateCtx->pScb, pCreateCtx->pCcb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateDirDoSysOpen(pCreateCtx); BAIL_ON_NT_STATUS(ntError); cleanup: PvfsFreeCreateContext(OUT_PPVOID(&pCreateCtx)); return ntError; error: if (ntError != STATUS_PENDING) { pIrpContext->pIrp->IoStatusBlock.CreateResult = PvfsSetCreateResult( Args.CreateDisposition, pCreateCtx ? pCreateCtx->bFileExisted : FALSE, ntError); } if (pCreateCtx && pCreateCtx->pCcb && pCreateCtx->pCcb->pDirContext && pCreateCtx->pCcb->pDirContext->pDir) { PvfsSysCloseDir(pCreateCtx->pCcb->pDirContext->pDir); } goto cleanup; }
static NTSTATUS PvfsCreateDirOpenIf( PPVFS_IRP_CONTEXT pIrpContext ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; IRP_ARGS_CREATE Args = pIrpContext->pIrp->Args.Create; PPVFS_PENDING_CREATE pCreateCtx = NULL; PVFS_STAT statPath = { 0 }; PVFS_STAT statFile = { 0 }; PPVFS_FILE_NAME directoryName = NULL; PPVFS_FILE_NAME resolvedDirName = NULL; PPVFS_FILE_NAME relativeFileName = NULL; ntError = PvfsAllocateCreateContext(&pCreateCtx, pIrpContext); BAIL_ON_NT_STATUS(ntError); if (IsSetFlag( pCreateCtx->OriginalFileName->NameOptions, PVFS_FILE_NAME_OPTION_DEFINED_STREAM_TYPE)) { // Disallow named streams here (shouldn't happen) and "::$DATA" ntError = STATUS_NOT_A_DIRECTORY; BAIL_ON_NT_STATUS(ntError); } ntError = PvfsSplitFileNamePath( &directoryName, &relativeFileName, pCreateCtx->OriginalFileName); BAIL_ON_NT_STATUS(ntError); ntError = PvfsLookupPath2( &resolvedDirName, &statPath, directoryName, IsSetFlag(Args.FileName.IoNameOptions, IO_NAME_OPTION_CASE_SENSITIVE)); BAIL_ON_NT_STATUS(ntError); /* Check for file existence */ ntError = PvfsLookupFile2( &pCreateCtx->ResolvedFileName, &statFile, directoryName, relativeFileName, IsSetFlag(Args.FileName.IoNameOptions, IO_NAME_OPTION_CASE_SENSITIVE)); pCreateCtx->bFileExisted = NT_SUCCESS(ntError) ? TRUE : FALSE; if (!pCreateCtx->bFileExisted) { ntError = PvfsAppendFileName( &pCreateCtx->ResolvedFileName, resolvedDirName, relativeFileName); BAIL_ON_NT_STATUS(ntError); ntError = PvfsAccessCheckFile( pCreateCtx->pCcb->pUserToken, resolvedDirName, FILE_ADD_SUBDIRECTORY, &pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); pCreateCtx->GrantedAccess = PvfsGetGrantedAccessForNewObject( Args.DesiredAccess); } else { if (!S_ISDIR(statFile.s_mode)) { ntError = STATUS_NOT_A_DIRECTORY; BAIL_ON_NT_STATUS(ntError); } ntError = PvfsAccessCheckFile( pCreateCtx->pCcb->pUserToken, pCreateCtx->ResolvedFileName, Args.DesiredAccess, &pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); } ntError = PvfsCheckDosAttributes( Args, pCreateCtx->bFileExisted ? pCreateCtx->ResolvedFileName : NULL, pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCheckShareMode( pCreateCtx->ResolvedFileName, Args.ShareAccess, pCreateCtx->GrantedAccess, &pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateFileCheckPendingDelete(pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); if (!pCreateCtx->bFileExisted) { pCreateCtx->SetPropertyFlags = PVFS_SET_PROP_SECURITY| PVFS_SET_PROP_ATTRIB; } ntError = PvfsAddCCBToSCB(pCreateCtx->pScb, pCreateCtx->pCcb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateDirDoSysOpen(pCreateCtx); BAIL_ON_NT_STATUS(ntError); cleanup: PvfsFreeCreateContext(OUT_PPVOID(&pCreateCtx)); if (directoryName) { PvfsFreeFileName(directoryName); } if (relativeFileName) { PvfsFreeFileName(relativeFileName); } if (resolvedDirName) { PvfsFreeFileName(resolvedDirName); } return ntError; error: if (ntError != STATUS_PENDING) { pIrpContext->pIrp->IoStatusBlock.CreateResult = PvfsSetCreateResult( Args.CreateDisposition, pCreateCtx ? pCreateCtx->bFileExisted : FALSE, ntError); } if (pCreateCtx && pCreateCtx->pCcb && pCreateCtx->pCcb->pDirContext && pCreateCtx->pCcb->pDirContext->pDir) { PvfsSysCloseDir(pCreateCtx->pCcb->pDirContext->pDir); } goto cleanup; }
static NTSTATUS PvfsCreateDirCreate( PPVFS_IRP_CONTEXT pIrpContext ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; IRP_ARGS_CREATE Args = pIrpContext->pIrp->Args.Create; PPVFS_PENDING_CREATE pCreateCtx = NULL; PVFS_STAT statPath = { 0 }; PPVFS_FILE_NAME directoryName = NULL; PPVFS_FILE_NAME relativeFileName = NULL; PPVFS_FILE_NAME resolvedDirName = NULL; ntError = PvfsAllocateCreateContext(&pCreateCtx, pIrpContext); BAIL_ON_NT_STATUS(ntError); if (IsSetFlag( pCreateCtx->OriginalFileName->NameOptions, PVFS_FILE_NAME_OPTION_DEFINED_STREAM_TYPE)) { // Disallow named streams here (shouldn't happen) and "::$DATA" ntError = STATUS_NOT_A_DIRECTORY; BAIL_ON_NT_STATUS(ntError); } /* We expect this call to fail with OBJECT_NAME_NOT_FOUND */ ntError = PvfsLookupPath2( &pCreateCtx->ResolvedFileName, &statPath, pCreateCtx->OriginalFileName, IsSetFlag(Args.FileName.IoNameOptions, IO_NAME_OPTION_CASE_SENSITIVE)); switch (ntError) { case STATUS_SUCCESS: ntError = STATUS_OBJECT_NAME_COLLISION; break; case STATUS_OBJECT_NAME_NOT_FOUND: ntError = STATUS_SUCCESS; break; default: /* do nothing */ break; } BAIL_ON_NT_STATUS(ntError); ntError = PvfsSplitFileNamePath( &directoryName, &relativeFileName, pCreateCtx->OriginalFileName); BAIL_ON_NT_STATUS(ntError); ntError = PvfsLookupPath2( &resolvedDirName, &statPath, directoryName, IsSetFlag(Args.FileName.IoNameOptions, IO_NAME_OPTION_CASE_SENSITIVE)); if (ntError == STATUS_OBJECT_NAME_NOT_FOUND) { ntError = STATUS_OBJECT_PATH_NOT_FOUND; } BAIL_ON_NT_STATUS(ntError); ntError = PvfsAppendFileName( &pCreateCtx->ResolvedFileName, resolvedDirName, relativeFileName); BAIL_ON_NT_STATUS(ntError); /* check parent here */ ntError = PvfsAccessCheckFile( pCreateCtx->pCcb->pUserToken, resolvedDirName, FILE_ADD_SUBDIRECTORY, &pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); pCreateCtx->GrantedAccess = PvfsGetGrantedAccessForNewObject( Args.DesiredAccess); ntError = PvfsCheckDosAttributes( Args, NULL, /* New directory */ pCreateCtx->GrantedAccess); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCheckShareMode( pCreateCtx->ResolvedFileName, Args.ShareAccess, pCreateCtx->GrantedAccess, &pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateFileCheckPendingDelete(pCreateCtx->pScb); BAIL_ON_NT_STATUS(ntError); pCreateCtx->bFileExisted = FALSE; pCreateCtx->SetPropertyFlags = PVFS_SET_PROP_SECURITY|PVFS_SET_PROP_ATTRIB; ntError = PvfsAddCCBToSCB(pCreateCtx->pScb, pCreateCtx->pCcb); BAIL_ON_NT_STATUS(ntError); ntError = PvfsCreateDirDoSysOpen(pCreateCtx); BAIL_ON_NT_STATUS(ntError); cleanup: PvfsFreeCreateContext(OUT_PPVOID(&pCreateCtx)); if (directoryName) { PvfsFreeFileName(directoryName); } if (relativeFileName) { PvfsFreeFileName(relativeFileName); } if (resolvedDirName) { PvfsFreeFileName(resolvedDirName); } return ntError; error: if (ntError != STATUS_PENDING) { pIrpContext->pIrp->IoStatusBlock.CreateResult = PvfsSetCreateResult( Args.CreateDisposition, pCreateCtx ? pCreateCtx->bFileExisted : FALSE, ntError); } if (pCreateCtx && pCreateCtx->pCcb && pCreateCtx->pCcb->pDirContext && pCreateCtx->pCcb->pDirContext->pDir) { PvfsSysCloseDir(pCreateCtx->pCcb->pDirContext->pDir); } goto cleanup; }