staticconststruct timeval audit_tv_dom_drop = { /* * Because domain deallocation is tied to asynchronous credential * freeing, receiving such event may take some time. In practice, * on a small VM, it should not exceed 100k usec, but let's wait up * to 1 second to be safe.
*/
.tv_sec = 1,
};
/* Returns a pointer to the last filled character of @dst, which is `\0`. */ static __maybe_unused char *regex_escape(constchar *const src, char *dst,
size_t dst_size)
{ char *d = dst;
/* * @domain_id: The domain ID extracted from the audit message (if the first part * of @pattern is REGEX_LANDLOCK_PREFIX). It is set to 0 if the domain ID is * not found.
*/ staticint audit_match_record(int audit_fd, const __u16 type, constchar *const pattern, __u64 *domain_id)
{ struct audit_message msg; int ret, err = 0; bool matches_record = !type;
regmatch_t matches[2];
regex_t regex;
ret = regcomp(®ex, pattern, 0); if (ret) return -EINVAL;
do {
memset(&msg, 0, sizeof(msg));
err = audit_recv(audit_fd, &msg); if (err) goto out;
if (msg.header.nlmsg_type == type)
matches_record = true;
} while (!matches_record);
ret = regexec(®ex, msg.data, ARRAY_SIZE(matches), matches, 0); if (ret) {
printf("DATA: %s\n", msg.data);
printf("ERROR: no match for pattern: %s\n", pattern);
err = -ENOENT;
}
if (domain_id) {
*domain_id = 0; if (matches[1].rm_so != -1) { int match_len = matches[1].rm_eo - matches[1].rm_so; /* The maximal characters of a 2^64 hexadecimal number is 17. */ char dom_id[18];
do {
memset(&msg, 0, sizeof(msg));
err = audit_recv(audit_fd, &msg); if (err) { if (err == -EAGAIN) return 0; else return err;
}
switch (msg.header.nlmsg_type) { case AUDIT_LANDLOCK_ACCESS:
records->access++; break; case AUDIT_LANDLOCK_DOMAIN:
records->domain++; break;
}
} while (true);
/* It is assume that there is not already filtering rules. */
filter->record_type = AUDIT_EXE; if (!path) { int ret = readlink("/proc/self/exe", filter->exe, sizeof(filter->exe) - 1); if (ret < 0) return -errno;
filter->exe_len = ret; return 0;
}
absolute_path = realpath(path, NULL); if (!absolute_path) return -errno;
/* No need for the terminating NULL byte. */
filter->exe_len = strlen(absolute_path); if (filter->exe_len > sizeof(filter->exe)) return -E2BIG;
/* * Simulates audit_init_with_exe_filter() when called from * FIXTURE_TEARDOWN_PARENT().
*/
audit_fd = audit_init(); if (audit_fd < 0) return audit_fd;
/* Filters might not be in place. */
audit_filter_exe(audit_fd, filter, AUDIT_DEL_RULE);
audit_filter_drop(audit_fd, AUDIT_DEL_RULE);
/* * Because audit_cleanup() might not be called by the test auditd * process, it might not be possible to explicitly set it. Anyway, * AUDIT_STATUS_ENABLED will implicitly be set to 0 when the auditd * process will exit.
*/ return close(audit_fd);
}
staticint audit_init_with_exe_filter(struct audit_filter *filter)
{ int fd, err;
fd = audit_init(); if (fd < 0) return fd;
err = audit_init_filter_exe(filter, NULL); if (err) return err;
err = audit_filter_exe(fd, filter, AUDIT_ADD_RULE); if (err) return err;
return fd;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.