Skip to content

Introduce generic linked list implementation #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SUBDIRS = test
AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src/libev -I${top_srcdir}/auparse -I${top_srcdir}/audisp -I${top_srcdir}/common
sbin_PROGRAMS = auditd auditctl aureport ausearch
AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign ${WFLAGS}
noinst_HEADERS = auditd-config.h auditd-event.h auditd-listen.h ausearch-llist.h ausearch-options.h auditctl-llist.h aureport-options.h ausearch-parse.h aureport-scan.h ausearch-lookup.h ausearch-int.h auditd-dispatch.h ausearch-string.h ausearch-nvpair.h ausearch-common.h ausearch-avc.h ausearch-time.h ausearch-lol.h auditctl-listing.h ausearch-checkpt.h
noinst_HEADERS = auditd-config.h auditd-event.h auditd-listen.h ausearch-llist.h ausearch-options.h aureport-options.h ausearch-parse.h aureport-scan.h ausearch-lookup.h ausearch-int.h auditd-dispatch.h ausearch-string.h ausearch-nvpair.h ausearch-common.h ausearch-avc.h ausearch-time.h ausearch-lol.h auditctl-listing.h ausearch-checkpt.h generic-llist.h

auditd_SOURCES = auditd.c auditd-event.c auditd-config.c auditd-reconfig.c auditd-sendmail.c auditd-dispatch.c
if ENABLE_LISTENER
Expand All @@ -37,7 +37,7 @@ auditd_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now
auditd_DEPENDENCIES = libev/libev.a
auditd_LDADD = @LIBWRAP_LIBS@ ${top_builddir}/src/libev/libev.la ${top_builddir}/audisp/libdisp.la ${top_builddir}/lib/libaudit.la ${top_builddir}/auparse/libauparse.la -lpthread -lm $(gss_libs) ${top_builddir}/common/libaucommon.la

auditctl_SOURCES = auditctl.c auditctl-llist.c delete_all.c auditctl-listing.c
auditctl_SOURCES = auditctl.c generic-llist.c delete_all.c auditctl-listing.c
auditctl_CFLAGS = -fPIE -DPIE -g -D_GNU_SOURCE ${WFLAGS}
auditctl_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now
auditctl_LDADD = ${top_builddir}/lib/libaudit.la ${top_builddir}/auparse/libauparse.la ${top_builddir}/common/libaucommon.la
Expand Down
21 changes: 13 additions & 8 deletions src/auditctl-listing.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#endif
#include "auditctl-listing.h"
#include "private.h"
#include "auditctl-llist.h"
#include "generic-llist.h"
#include "auparse-idata.h"

#ifndef IORING_OP_LAST
Expand Down Expand Up @@ -525,7 +525,7 @@ static void print_rule(const struct audit_rule_data *r)
void audit_print_init(void)
{
printed = 0;
list_create(&l);
list_create(&l, free);
}

static const char *get_enable(unsigned e)
Expand Down Expand Up @@ -585,9 +585,9 @@ int audit_print_reply(const struct audit_reply *rep, int fd)
else {
lnode *n;
list_first(&l);
n = l.cur;
n = list_get_cur(&l);
while (n) {
print_rule(n->r);
print_rule((const struct audit_rule_data *)n->data);
n = list_next(&l);
}
list_clear(&l);
Expand Down Expand Up @@ -645,10 +645,15 @@ int audit_print_reply(const struct audit_reply *rep, int fd)
#endif
case AUDIT_LIST_RULES:
list_requested = 0;
if (key_match(rep->ruledata))
list_append(&l, rep->ruledata,
sizeof(struct audit_rule_data) +
rep->ruledata->buflen);
if (key_match(rep->ruledata)) {
size_t sz = sizeof(struct audit_rule_data) +
rep->ruledata->buflen;
struct audit_rule_data *rule = malloc(sz);
if (rule) {
memcpy(rule, rep->ruledata, sz);
list_append(&l, rule, sz);
}
}
printed = 1;
return 1;
default:
Expand Down
113 changes: 0 additions & 113 deletions src/auditctl-llist.c

This file was deleted.

57 changes: 0 additions & 57 deletions src/auditctl-llist.h

This file was deleted.

23 changes: 14 additions & 9 deletions src/delete_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "libaudit.h"
#include "private.h"

#include "auditctl-llist.h"
#include "generic-llist.h"

extern int key_match(const struct audit_rule_data *r);

Expand All @@ -48,7 +49,7 @@ int delete_all_rules(int fd)

FD_ZERO(&read_mask);
FD_SET(fd, &read_mask);
list_create(&l);
list_create(&l, free);

for (i = 0; i < timeout; i++) {
struct timeval t;
Expand Down Expand Up @@ -83,18 +84,22 @@ int delete_all_rules(int fd)
if (rep.type != AUDIT_LIST_RULES)
continue;

if (key_match(rep.ruledata))
list_append(&l, rep.ruledata,
sizeof(struct audit_rule_data) +
rep.ruledata->buflen);

if (key_match(rep.ruledata)) {
size_t sz = sizeof(struct audit_rule_data) +
rep.ruledata->buflen;
struct audit_rule_data *rule = malloc(sz);
if (rule) {
memcpy(rule, rep.ruledata, sz);
list_append(&l, rule, sz);
}
}
}
}
list_first(&l);
n = l.cur;
n = list_get_cur(&l);
while (n) {
/* Bounce it right back with delete */
rc = audit_send(fd, AUDIT_DEL_RULE, n->r, n->size);
rc = audit_send(fd, AUDIT_DEL_RULE, n->data, n->size);
if (rc < 0) {
audit_msg(LOG_ERR, "Error deleting rule (%s)",
strerror(-rc));
Expand Down
Loading