#include #include #include #include #include #include #include #include #include #include #include #include "private.h" #define UNSET_FEATURE_MASK AUDIT_FEATURE_TO_MASK(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) #define IMMUTABLE_FEATURE_MASK AUDIT_FEATURE_TO_MASK(AUDIT_FEATURE_LOGINUID_IMMUTABLE) static void print_af(char *prefix, struct audit_features *af) { fprintf(stdout, "%s vers=%d mask=%08x feature=%08x lock=%08x\n", prefix, af->vers, af->mask, af->features, af->lock); } static int get_and_print(int fd) { struct audit_features af, *paf; char buf[4096]; int rc; /* get the features */ rc = audit_send(fd, AUDIT_GET_FEATURE, &af, sizeof(af)); if (rc < 0) return rc; rc = get_reply(fd, buf, sizeof(buf)); if (rc < 0) return rc; paf = NLMSG_DATA(buf); print_af("FROM:", paf); return 0; } static int set_features(int fd, struct audit_features *af) { int rc; print_af("TO:", af); rc = audit_send(fd, AUDIT_SET_FEATURE, af, sizeof(*af)); if (rc < 0) { perror("audit_send"); return rc; } rc = get_and_print(fd); if (rc < 0) return rc; return 0; } int main(int argc, char *argv[]) { int fd; int rc; struct audit_features af; unsigned int mask = UNSET_FEATURE_MASK | IMMUTABLE_FEATURE_MASK; unsigned int features = 0; unsigned int lock = 0; if (argc < 4) { fprintf(stderr, "Dude, gets your args together, unset, immut, lock\n"); return -EINVAL; } if (atoi(argv[1])) features |= UNSET_FEATURE_MASK; if (atoi(argv[2])) features |= IMMUTABLE_FEATURE_MASK; if (atoi(argv[3])) lock = mask; fd = audit_open(); if (fd < 0) return fd; rc = get_and_print(fd); if (rc < 0) return rc; memset(&af, 0, sizeof(af)); /* set new features */ af.vers = AUDIT_FEATURE_VERSION; af.mask = mask; af.features = features; af.lock = lock; rc = set_features(fd, &af); if (rc < 0) return rc; return 0; }