xref: /dragonfly/tools/regression/priv/test_acct.c (revision 6693db17)
1 #include <unistd.h>
2 #include <errno.h>
3 #include <fcntl.h>
4 #include <sys/types.h>
5 #include "test.h"
6 
7 static char *tmp_file;
8 
9 void
10 setup() {
11 	tmp_file = "./tmpfile";
12 	int fh = open(tmp_file, O_CREAT | O_TRUNC | O_WRONLY, 0666);
13 	close(fh);
14 }
15 
16 void
17 teardown() {
18 	unlink(tmp_file);
19 }
20 
21 int
22 test_acct() {
23 	int error;
24 
25 	error = acct(tmp_file);
26 	if (error == -1)
27   		return errno;
28 
29 	error = acct(NULL);
30 	if (error == -1)
31 		return errno;
32 
33 	return 0;
34 }
35 
36 int main()
37 {
38 	test_as_root		(test_acct, 0, "acct");
39 	test_as_jailed_root	(test_acct, EPERM, "acct");
40 	test_as_unpriv		(test_acct, EPERM, "acct");
41 	test_as_jailed_unpriv	(test_acct, EPERM, "acct");
42 
43 	return 0;
44 }
45