2 * Copyright (c) 2018 Aniket Pandey
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 #include <sys/ioctl.h>
30 #include <bsm/audit.h>
31 #include <security/audit/audit_ioctl.h>
41 ATF_TC(auditpipe_get_qlen);
42 ATF_TC_HEAD(auditpipe_get_qlen, tc)
44 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
45 "AUDITPIPE_GET_QLEN works properly");
48 ATF_TC_BODY(auditpipe_get_qlen, tc)
51 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
52 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLEN, &qlen));
53 ATF_REQUIRE(qlen != -1);
58 ATF_TC(auditpipe_get_qlimit);
59 ATF_TC_HEAD(auditpipe_get_qlimit, tc)
61 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
62 "AUDITPIPE_GET_QLIMIT works properly");
65 ATF_TC_BODY(auditpipe_get_qlimit, tc)
68 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
69 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &qlimit));
70 ATF_REQUIRE(qlimit != -1);
75 ATF_TC_WITH_CLEANUP(auditpipe_set_qlimit);
76 ATF_TC_HEAD(auditpipe_set_qlimit, tc)
78 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
79 "AUDITPIPE_SET_QLIMIT works properly");
82 ATF_TC_BODY(auditpipe_set_qlimit, tc)
84 int test_qlimit, curr_qlimit, recv_qlimit;
86 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
87 /* Retreive the current QLIMIT value and store it in a file */
88 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &curr_qlimit));
89 ATF_REQUIRE((fileptr = fopen("qlimit_store", "a")) != NULL);
90 ATF_REQUIRE_EQ(sizeof(curr_qlimit),
91 fprintf(fileptr, "%d\n", curr_qlimit));
94 * Set QLIMIT different from the current system value to confirm
95 * proper functioning of AUDITPIPE_SET_QLIMIT ioctl.
97 test_qlimit = curr_qlimit - 1;
98 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_SET_QLIMIT, &test_qlimit));
99 /* Receive modified value and check whether QLIMIT was set correctly */
100 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &recv_qlimit));
101 ATF_REQUIRE_EQ(test_qlimit, recv_qlimit);
107 ATF_TC_CLEANUP(auditpipe_set_qlimit, tc)
109 if (atf_utils_file_exists("qlimit_store")) {
111 ATF_REQUIRE((fileptr = fopen("qlimit_store", "r")) != NULL);
112 ATF_REQUIRE(fscanf(fileptr, "%d", &curr_qlim));
114 ATF_REQUIRE((fd = open("/dev/auditpipe", O_RDONLY)) != -1);
115 /* Set QLIMIT's value as it was prior to test-case invocation */
116 ATF_REQUIRE_EQ(0, ioctl(fd, AUDITPIPE_SET_QLIMIT, &curr_qlim));
124 ATF_TC(auditpipe_get_qlimit_min);
125 ATF_TC_HEAD(auditpipe_get_qlimit_min, tc)
127 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
128 "AUDITPIPE_GET_QLIMIT_MIN works properly");
131 ATF_TC_BODY(auditpipe_get_qlimit_min, tc)
134 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
135 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MIN, &qlim_min));
136 ATF_REQUIRE(qlim_min != -1);
141 ATF_TC(auditpipe_get_qlimit_max);
142 ATF_TC_HEAD(auditpipe_get_qlimit_max, tc)
144 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
145 "AUDITPIPE_GET_QLIMIT_MAX works properly");
148 ATF_TC_BODY(auditpipe_get_qlimit_max, tc)
151 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
152 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MAX, &qlim_max));
153 ATF_REQUIRE(qlim_max != -1);
158 ATF_TC(auditpipe_get_maxauditdata);
159 ATF_TC_HEAD(auditpipe_get_maxauditdata, tc)
161 atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, "
162 "AUDITPIPE_GET_MAXAUDITDATA works properly");
165 ATF_TC_BODY(auditpipe_get_maxauditdata, tc)
168 ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1);
169 ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_MAXAUDITDATA, &audata));
170 ATF_REQUIRE(audata != -1);
177 ATF_TP_ADD_TC(tp, auditpipe_get_qlen);
178 ATF_TP_ADD_TC(tp, auditpipe_get_qlimit);
179 ATF_TP_ADD_TC(tp, auditpipe_set_qlimit);
180 ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_min);
181 ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_max);
182 ATF_TP_ADD_TC(tp, auditpipe_get_maxauditdata);
184 return (atf_no_error());