]>
iEval git - linux-seccomp.git/blob - libseccomp/tests/11-basic-basic_errors.c
2 * Seccomp Library test program
4 * Copyright IBM Corp. 2012
5 * Author: Corey Bryant <coreyb@linux.vnet.ibm.com>
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of version 2.1 of the GNU Lesser General Public License as
11 * published by the Free Software Foundation.
13 * This library is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, see <http://www.gnu.org/licenses>.
27 int main(int argc
, char *argv
[])
32 /* seccomp_init errors */
33 ctx
= seccomp_init(SCMP_ACT_ALLOW
+ 1);
37 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
43 /* seccomp_reset error */
44 rc
= seccomp_reset(ctx
, SCMP_ACT_KILL
+ 1);
47 rc
= seccomp_reset(ctx
, SCMP_ACT_KILL
);
51 /* seccomp_load error */
52 rc
= seccomp_load(ctx
);
56 /* seccomp_syscall_priority errors */
57 rc
= seccomp_syscall_priority(ctx
, SCMP_SYS(read
), 1);
61 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
65 rc
= seccomp_syscall_priority(ctx
, -10, 1);
72 /* seccomp_rule_add errors */
73 rc
= seccomp_rule_add(ctx
, SCMP_ACT_ALLOW
, SCMP_SYS(read
), 1,
74 SCMP_A0(SCMP_CMP_EQ
, 0));
78 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
82 rc
= seccomp_rule_add(ctx
, SCMP_ACT_ALLOW
, SCMP_SYS(read
), 0);
85 rc
= seccomp_rule_add(ctx
, SCMP_ACT_KILL
- 1, SCMP_SYS(read
), 0);
88 rc
= seccomp_rule_add(ctx
, SCMP_ACT_KILL
, SCMP_SYS(read
), 7);
91 rc
= seccomp_rule_add(ctx
, SCMP_ACT_KILL
, SCMP_SYS(read
), 7,
92 SCMP_A0(SCMP_CMP_EQ
, 0),
93 SCMP_A1(SCMP_CMP_EQ
, 0),
94 SCMP_A2(SCMP_CMP_EQ
, 0),
95 SCMP_A3(SCMP_CMP_EQ
, 0),
96 SCMP_A4(SCMP_CMP_EQ
, 0),
97 SCMP_A5(SCMP_CMP_EQ
, 0),
98 SCMP_CMP(6, SCMP_CMP_EQ
, 0));
101 rc
= seccomp_rule_add(ctx
, SCMP_ACT_KILL
, SCMP_SYS(read
), 1,
102 SCMP_A0(_SCMP_CMP_MIN
, 0));
105 rc
= seccomp_rule_add(ctx
, SCMP_ACT_KILL
, SCMP_SYS(read
), 1,
106 SCMP_A0(_SCMP_CMP_MAX
, 0));
109 rc
= seccomp_rule_add_exact(ctx
, SCMP_ACT_KILL
, -10001, 0);
113 seccomp_release(ctx
);
116 /* seccomp_rule_add_exact error */
117 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
120 rc
= seccomp_arch_remove(ctx
, SCMP_ARCH_NATIVE
);
123 rc
= seccomp_arch_add(ctx
, SCMP_ARCH_X86
);
126 rc
= seccomp_rule_add_exact(ctx
, SCMP_ACT_KILL
, SCMP_SYS(socket
), 1,
127 SCMP_A0(SCMP_CMP_EQ
, 2));
130 seccomp_release(ctx
);
133 /* errno values beyond MAX_ERRNO */
134 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
137 rc
= seccomp_rule_add(ctx
, SCMP_ACT_ERRNO(0xffff), 0, 0);
140 seccomp_release(ctx
);
143 /* seccomp_export_pfc errors */
144 rc
= seccomp_export_pfc(ctx
, STDOUT_FILENO
);
148 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
152 rc
= seccomp_export_pfc(ctx
, sysconf(_SC_OPEN_MAX
) - 1);
156 seccomp_release(ctx
);
159 /* seccomp_export_bpf errors */
160 rc
= seccomp_export_bpf(ctx
, STDOUT_FILENO
);
164 ctx
= seccomp_init(SCMP_ACT_ALLOW
);
168 rc
= seccomp_export_bpf(ctx
, sysconf(_SC_OPEN_MAX
) - 1);
172 seccomp_release(ctx
);
This page took 0.050088 seconds and 4 git commands to generate.