summaryrefslogtreecommitdiff
path: root/regress/sys/kern/tame/generic/actions.c
blob: e4724410e8ae02bbc594e20f25e6ca7cf37fd81b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*	$OpenBSD: actions.c,v 1.2 2015/08/24 09:23:04 semarie Exp $ */
/*
 * Copyright (c) 2015 Sebastien Marie <semarie@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/tame.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#include "actions.h"

int
execute_action(action_t action, va_list opts)
{
	errno = 0;

	switch (action) {
	case AC_EXIT:
		/* should be catched by manager.c (before been here) */
		_exit(ENOTSUP);
		/* NOTREACHED */

	case AC_KILL:
		kill(0, SIGINT);
		break;

	case AC_INET:
		socket(AF_INET, SOCK_STREAM, 0);
		break;

	case AC_TAME:
		tame(va_arg(opts, int), NULL);
		break;

	case AC_ALLOWED_SYSCALLS:
		clock_getres(CLOCK_MONOTONIC, NULL);
		clock_gettime(CLOCK_MONOTONIC, NULL);
		/* fchdir(); */
		getdtablecount();
		getegid();
		geteuid();
		getgid();
		getgroups(0, NULL);
		getitimer(ITIMER_REAL, NULL);
		getlogin();
		getpgid(0);
		getpgrp();
		getpid();
		getppid();
		/* getresgid(); */
		/* getresuid(); */
		{ struct rlimit rl; getrlimit(RLIMIT_CORE, &rl); }
		getsid(0);
		getthrid();
		{ struct timeval tp; gettimeofday(&tp, NULL); }
		getuid();
		geteuid();
		issetugid();
		/* nanosleep(); */
		/* sigreturn(); */
		umask(0000);
		/* wait4(); */

		break;

	case AC_OPENFILE_RDONLY:
		{
			const char *filename = va_arg(opts, const char *);
			int fd = open(filename, O_RDONLY);
			if (fd != -1)
				close(fd);
		}
		break;
	}

	return (errno);
}