static VOID SrvSession2Free( PLWIO_SRV_SESSION_2 pSession ) { LWIO_LOG_DEBUG("Freeing session [object:0x%x][uid:%u]", pSession, pSession->ullUid); if (pSession->pMutex) { pthread_rwlock_destroy(&pSession->mutex); pSession->pMutex = NULL; } if (pSession->pTreeCollection) { LwRtlRBTreeFree(pSession->pTreeCollection); } if (pSession->hFinderRepository) { SrvFinderCloseRepository(pSession->hFinderRepository); } SRV_SAFE_FREE_MEMORY(pSession->pwszClientPrincipalName); if (pSession->pIoSecurityContext) { IoSecurityDereferenceSecurityContext(&pSession->pIoSecurityContext); } SrvFreeMemory(pSession); }
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); RtlUnicodeStringFree(&pIrp->Args.Create.FileName.Name); 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 SrvCreateDefaultSharePath( PWSTR pwszDefaultSharePath ) { NTSTATUS ntStatus = STATUS_SUCCESS; PSECURITY_DESCRIPTOR_RELATIVE pRelSecDesc = NULL; IO_FILE_HANDLE hFile = NULL; IO_STATUS_BLOCK ioStatusBlock = {0}; IO_FILE_NAME filename = {0}; PIO_CREATE_SECURITY_CONTEXT pSecContext = NULL; ntStatus = SrvBuildDefaultShareSID(&pRelSecDesc); BAIL_ON_NT_STATUS(ntStatus); ntStatus = IoSecurityCreateSecurityContextFromUidGid( &pSecContext, 0, 0, NULL); BAIL_ON_NT_STATUS(ntStatus); filename.FileName = pwszDefaultSharePath; ntStatus = IoCreateFile( &hFile, NULL, &ioStatusBlock, pSecContext, &filename, pRelSecDesc, NULL, /* Security QOS */ FILE_LIST_DIRECTORY | FILE_ADD_SUBDIRECTORY, 0, /* Allocation Size */ FILE_ATTRIBUTE_NORMAL, /* File Attributes */ 0, /* No Sharing */ FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, /* Extended Attributes */ 0, /* EA Length */ NULL); /* ECP List */ BAIL_ON_NT_STATUS(ntStatus); cleanup: if (hFile) { IoCloseFile(hFile); } if (pRelSecDesc) { SrvFreeMemory(pRelSecDesc); } IoSecurityDereferenceSecurityContext(&pSecContext); return ntStatus; error: goto cleanup; }