在 IRP_MJ_CREATE 上新增稽核
檔案系統內安全性檢查的另一個重要層面是視需要新增稽核 () 。 一般而言,這是一組進行安全性決策的相同常式完成,因為稽核的目的是記錄系統所做的安全性決策。 例如,下列程式碼可用來在完成存取檢查之後,在檔案系統內實作稽核:
{
UNICODE_STRING FileAuditObjectName;
RtlInitUnicodeString(&FileAuditObjectName, L"File");
if ( SeAuditingFileOrGlobalEvents (AccessGranted,
&Fcb->SecurityDescriptor,
&AccessState->SubjectSecurityContext)) {
//
// Must pass complete Windows path name, including device name.
//
ConstructAuditFileName(Irp, Fcb, &AuditName);
if (IrpSp->Parameters.Create.SecurityContext->FullCreateOptions
& FILE_DELETE_ON_CLOSE) {
SeOpenObjectForDeleteAuditAlarm(&FileAuditObjectName,
NULL,
&AuditName,
&Fcb->SecurityDescriptor,
AccessState,
FALSE, // Object not created.
// Was it successful?
// Based on SeAccessCheck
SeAccessCheckAccessGranted,
// UserMode or KernelMode
EffectiveMode,
&AccessState->GenerateOnClose
);
} else {
SeOpenObjectAuditAlarm(&FileAuditObjectName,
NULL,
&AuditName,
&Fcb->SecurityDescriptor,
AccessState,
FALSE, // object not created
// Was it successful?
// Based on SeAccessCheck
AccessGranted,
// UserMode or KernelMode
EffectiveMode,
&AccessState->GenerateOnClose
);
}
//
// Free file name here if needed.
//
}