Path: blob/main/tools/regression/audit/audit_pipe_ioctl/audit_pipe_ioctl.c
48255 views
/*-1* Copyright (c) 2006 Robert N. M. Watson2* All rights reserved.3*4* This software was developed by Robert Watson for the TrustedBSD Project.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728/*29* Simple audit pipe regression test to confirm that the ioctls for queue30* limit information basically work. No attempt is made to validate the31* queue length returned, however.32*/3334#include <sys/types.h>35#include <sys/ioctl.h>3637#include <security/audit/audit_ioctl.h>3839#include <err.h>40#include <fcntl.h>4142int43main(int argc, char *argv[])44{45u_int len, minlen, maxlen;46u_int64_t astat;47int fd;4849fd = open("/dev/auditpipe", O_RDONLY);50if (fd < 0)51err(-1, "/dev/auditpipe");5253/*54* First, test that we can read the queue length, queue limit, and55* bounds on queue length limits.56*/57len = (u_int)(-1);58if (ioctl(fd, AUDITPIPE_GET_QLEN, &len) < 0)59err(-1, "AUDITPIPE_GET_QLEN");60if (len == (u_int)(-1))61errx(-1, "AUDITPIPE_GET_QLEN: unchanged");6263minlen = (u_int)(-1);64if (ioctl(fd, AUDITPIPE_GET_QLIMIT_MIN, &minlen) < 0)65err(-1, "AUDITPIPE_GET_QLIMIT_MIN");66if (minlen == (u_int)(-1))67errx(-1, "AUDITPIPE_GET_QLIMIT_MIN: unchanged");6869maxlen = (u_int)(-1);70if (ioctl(fd, AUDITPIPE_GET_QLIMIT_MAX, &maxlen) < 0)71err(-1, "AUDITPIPE_GET_QLIMIT_MAX");72if (maxlen == (u_int)(-1))73errx(-1, "AUDITPIPE_GET_QLIMIT_MAX: unchanged");7475len = (u_int)(-1);76if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)77err(-1, "AUDITPIPE_GET_QLIMIT");78if (len == (u_int)(-1))79errx(-1, "AUDITPIPE_GET_QLIMIT: unchanged");8081if (!(len >= minlen))82errx(-1, "queue length < minlen");8384if (!(len <= maxlen))85errx(-1, "queue length > maxlen");8687/*88* Try setting the queue length to first minimum, then maximum89* lengths. Query after each to make sure it changed.90*/91len = minlen;92if (ioctl(fd, AUDITPIPE_SET_QLIMIT, &len) < 0)93err(-1, "AUDITPIPE_SET_QLIMIT(min)");9495if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)96err(-1, "AUDITPIPE_GET_QLIMIT");9798if (len != minlen)99errx(-1, "set to minlen didn't work");100101len = maxlen;102if (ioctl(fd, AUDITPIPE_SET_QLIMIT, &len) < 0)103err(-1, "AUDITPIPE_SET_QLIMIT(max)");104105if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)106err(-1, "AUDITPIPE_GETQLIMIT");107108if (len != maxlen)109errx(-1, "set to maxlen didn't work");110111/*112* Check that we can query the defined stats. No attempt to113* validate.114*/115astat = (u_int64_t)(int64_t)(-1);116if (ioctl(fd, AUDITPIPE_GET_INSERTS, &astat) < 0)117err(-1, "AUDITPIPE_GET_INSERTS");118if (astat == (u_int64_t)(int64_t)(-1))119errx(-1, "AUDITPIPE_GET_INSERTS: unchanged");120121astat = (u_int64_t)(int64_t)(-1);122if (ioctl(fd, AUDITPIPE_GET_READS, &astat) < 0)123err(-1, "AUDITPIPE_GET_READS");124if (astat == (u_int64_t)(int64_t)(-1))125errx(-1, "AUDITPIPE_GET_READS: unchanged");126127astat = (u_int64_t)(int64_t)(-1);128if (ioctl(fd, AUDITPIPE_GET_DROPS, &astat) < 0)129err(-1, "AUDITPIPE_GET_DROPS");130if (astat == (u_int64_t)(int64_t)(-1))131errx(-1, "AUDITPIPE_GET_DROPS: unchanged");132133astat = (u_int64_t)(int64_t)(-1);134if (ioctl(fd, AUDITPIPE_GET_TRUNCATES, &astat) < 0)135err(-1, "AUDITPIPE_GET_TRUNCATES");136if (astat == (u_int64_t)(int64_t)(-1))137errx(-1, "AUDITPIPE_GET_TRUNCATES: unchanged");138139return (0);140}141142143