2 * Copyright (c) 2006 Robert N. M. Watson
5 * This software was developed by Robert Watson for the TrustedBSD Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Simple audit pipe regression test to confirm that the ioctls for queue
33 * limit information basically work. No attempt is made to validate the
34 * queue length returned, however.
37 #include <sys/types.h>
38 #include <sys/ioctl.h>
40 #include <security/audit/audit_ioctl.h>
46 main(int argc, char *argv[])
48 u_int len, minlen, maxlen;
52 fd = open("/dev/auditpipe", O_RDONLY);
54 err(-1, "/dev/auditpipe");
57 * First, test that we can read the queue length, queue limit, and
58 * bounds on queue length limits.
61 if (ioctl(fd, AUDITPIPE_GET_QLEN, &len) < 0)
62 err(-1, "AUDITPIPE_GET_QLEN");
63 if (len == (u_int)(-1))
64 errx(-1, "AUDITPIPE_GET_QLEN: unchanged");
67 if (ioctl(fd, AUDITPIPE_GET_QLIMIT_MIN, &minlen) < 0)
68 err(-1, "AUDITPIPE_GET_QLIMIT_MIN");
69 if (minlen == (u_int)(-1))
70 errx(-1, "AUDITPIPE_GET_QLIMIT_MIN: unchanged");
73 if (ioctl(fd, AUDITPIPE_GET_QLIMIT_MAX, &maxlen) < 0)
74 err(-1, "AUDITPIPE_GET_QLIMIT_MAX");
75 if (maxlen == (u_int)(-1))
76 errx(-1, "AUDITPIPE_GET_QLIMIT_MAX: unchanged");
79 if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)
80 err(-1, "AUDITPIPE_GET_QLIMIT");
81 if (len == (u_int)(-1))
82 errx(-1, "AUDITPIPE_GET_QLIMIT: unchanged");
85 errx(-1, "queue length < minlen");
88 errx(-1, "queue length > maxlen");
91 * Try setting the queue length to first minimum, then maximum
92 * lengths. Query after each to make sure it changed.
95 if (ioctl(fd, AUDITPIPE_SET_QLIMIT, &len) < 0)
96 err(-1, "AUDITPIPE_SET_QLIMIT(min)");
98 if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)
99 err(-1, "AUDITPIPE_GET_QLIMIT");
102 errx(-1, "set to minlen didn't work");
105 if (ioctl(fd, AUDITPIPE_SET_QLIMIT, &len) < 0)
106 err(-1, "AUDITPIPE_SET_QLIMIT(max)");
108 if (ioctl(fd, AUDITPIPE_GET_QLIMIT, &len) < 0)
109 err(-1, "AUDITPIPE_GETQLIMIT");
112 errx(-1, "set to maxlen didn't work");
115 * Check that we can query the defined stats. No attempt to
118 astat = (u_int64_t)(int64_t)(-1);
119 if (ioctl(fd, AUDITPIPE_GET_INSERTS, &astat) < 0)
120 err(-1, "AUDITPIPE_GET_INSERTS");
121 if (astat == (u_int64_t)(int64_t)(-1))
122 errx(-1, "AUDITPIPE_GET_INSERTS: unchanged");
124 astat = (u_int64_t)(int64_t)(-1);
125 if (ioctl(fd, AUDITPIPE_GET_READS, &astat) < 0)
126 err(-1, "AUDITPIPE_GET_READS");
127 if (astat == (u_int64_t)(int64_t)(-1))
128 errx(-1, "AUDITPIPE_GET_READS: unchanged");
130 astat = (u_int64_t)(int64_t)(-1);
131 if (ioctl(fd, AUDITPIPE_GET_DROPS, &astat) < 0)
132 err(-1, "AUDITPIPE_GET_DROPS");
133 if (astat == (u_int64_t)(int64_t)(-1))
134 errx(-1, "AUDITPIPE_GET_DROPS: unchanged");
136 astat = (u_int64_t)(int64_t)(-1);
137 if (ioctl(fd, AUDITPIPE_GET_TRUNCATES, &astat) < 0)
138 err(-1, "AUDITPIPE_GET_TRUNCATES");
139 if (astat == (u_int64_t)(int64_t)(-1))
140 errx(-1, "AUDITPIPE_GET_TRUNCATES: unchanged");