Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / tests / 22-sim-basic_chains_array.c
CommitLineData
8befd5cc
MG
1/**
2 * Seccomp Library test program
3 *
4 * Author: Paul Moore <paul@paul-moore.com>, Vitaly Shukela <vi0oss@gmail.com>
5 */
6
7/*
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of version 2.1 of the GNU Lesser General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses>.
19 */
20
21#include <errno.h>
22#include <unistd.h>
23
24#include <seccomp.h>
25
26#include "util.h"
27
28int main(int argc, char *argv[])
29{
30 int rc;
31 struct util_options opts;
32 scmp_filter_ctx ctx = NULL;
33 struct scmp_arg_cmp arg_cmp;
34
35 rc = util_getopt(argc, argv, &opts);
36 if (rc < 0)
37 goto out;
38
39 ctx = seccomp_init(SCMP_ACT_KILL);
40 if (ctx == NULL)
41 return ENOMEM;
42
43 arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO);
44 rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
45 SCMP_SYS(read), 1, &arg_cmp);
46 if (rc != 0)
47 goto out;
48
49 arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDOUT_FILENO);
50 rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
51 SCMP_SYS(write), 1, &arg_cmp);
52 if (rc != 0)
53 goto out;
54
55 arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDERR_FILENO);
56 rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
57 SCMP_SYS(write), 1, &arg_cmp);
58 if (rc != 0)
59 goto out;
60
61 rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
62 SCMP_SYS(close), 0, NULL);
63 if (rc != 0)
64 goto out;
65
66 rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
67 SCMP_SYS(rt_sigreturn), 0, NULL);
68 if (rc != 0)
69 goto out;
70
71 rc = util_filter_output(&opts, ctx);
72 if (rc)
73 goto out;
74
75out:
76 seccomp_release(ctx);
77 return (rc < 0 ? -rc : rc);
78}
This page took 0.013379 seconds and 4 git commands to generate.