将安全性分配给 IRP_MJ_CREATE 上的新文件
创建处理的最后一项任务是将安全性分配给新文件。 虽然 Windows 安全模型支持继承 (但单个 ACE 条目的标记方式是,在创建新文件或目录时,) 在文件系统外部实现这一点。 因此,文件系统中的大部分逻辑专用于存储新的安全描述符。 下面是一个示例例程:
NTSTATUS FsdAssignInitialSecurity( PIRP_CONTEXT IrpContext,
PFCB Fcb, PFCB Directory)
{
NTSTATUS status = STATUS_SUCCESS;
BOOLEAN CreateDir = ((IrpContext->IrpSp->Parameters.Create.Options
& FILE_DIRECTORY_FILE)==FILE_DIRECTORY_FILE);
PACCESS_STATE AccessState =
IrpContext->IrpSp->Parameters.Create.SecurityContext->AccessState;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
//
// Make sure the parent directory's security descriptor is loaded.
//
(void) FsdLoadSecurityDescriptor(IrpContext, Directory);
//
// don't care about the return code here, as it is handled later
//
if (Directory->SecurityDescriptor == NULL) {
//
// If the parent has no security, then we are outside
// of the normal Windows paradigm.
//
// The child (that is, the target of the create) will also have
// a NULL SD.
//
// Note that you can always assign security to the file object
// explicitly at later on.
//
return STATUS_SUCCESS;
}
//
// Now create the security descriptor.
//
status = SeAssignSecurity(Directory->SecurityDescriptor,
AccessState->SecurityDescriptor,
&SecurityDescriptor,
CreateDir,
&AccessState->SubjectSecurityContext,
IoGetFileObjectGenericMapping(),
PagedPool);
if (!NT_SUCCESS(status)) {
return status;
}
//
// Associate the SD with the file; use our own storage so when
// cleanup occurs it is unnecessary to know if the storage came from the
// security reference monitor.
//
Fcb->SecurityDescriptorLength =
RtlLengthSecurityDescriptor( SecurityDescriptor );
Fcb->SecurityDescriptor = ExAllocatePoolWithTag(PagedPool,
Fcb->SecurityDescriptorLength, 'DSyM');
if (!Fcb->SecurityDescriptor) {
//
// There is no paged pool.
//
SeDeassignSecurity(&SecurityDescriptor);
Fcb->SecurityDescriptorLength = 0;
return STATUS_NO_MEMORY;
}
RtlCopyMemory(Fcb->SecurityDescriptor, SecurityDescriptor,
Fcb->SecurityDescriptorLength);
SeDeassignSecurity(&SecurityDescriptor);
//
// Store the SD persistently (this is file system specific).
//
(void) FsdStoreSecurityDescriptor(IrpContext, Fcb);
return STATUS_SUCCESS;
}
请注意,构造初始安全描述符的逻辑 (理解继承,例如,) 不在文件系统中处理。 这与用于在文件系统层中处理安全描述符的简单模型保持一致的。