]> git.proxmox.com Git - mirror_libseccomp.git/blob - tests/13-basic-attrs.c
api: rename SCMP_FLTATR_SPEC_ALLOW to SCMP_FLTATR_CTL_SSB
[mirror_libseccomp.git] / tests / 13-basic-attrs.c
1 /**
2 * Seccomp Library test program
3 *
4 * Copyright (c) 2012 Red Hat <pmoore@redhat.com>
5 * Author: Paul Moore <paul@paul-moore.com>
6 */
7
8 /*
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.
12 *
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
16 * for more details.
17 *
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>.
20 */
21
22 #include <errno.h>
23 #include <unistd.h>
24
25 #include <seccomp.h>
26
27 #include "util.h"
28
29 int main(int argc, char *argv[])
30 {
31 int rc;
32 uint32_t val = (uint32_t)(-1);
33 scmp_filter_ctx ctx = NULL;
34
35 rc = seccomp_api_set(4);
36 if (rc != 0)
37 return EOPNOTSUPP;
38
39 ctx = seccomp_init(SCMP_ACT_ALLOW);
40 if (ctx == NULL)
41 return ENOMEM;
42
43 rc = seccomp_attr_get(ctx, SCMP_FLTATR_ACT_DEFAULT, &val);
44 if (rc != 0)
45 goto out;
46 if (val != SCMP_ACT_ALLOW) {
47 rc = -1;
48 goto out;
49 }
50 rc = seccomp_attr_set(ctx, SCMP_FLTATR_ACT_DEFAULT, val);
51 if (rc != -EACCES) {
52 rc = -1;
53 goto out;
54 }
55
56 rc = seccomp_attr_set(ctx, SCMP_FLTATR_ACT_BADARCH, SCMP_ACT_ALLOW);
57 if (rc != 0)
58 goto out;
59 rc = seccomp_attr_get(ctx, SCMP_FLTATR_ACT_BADARCH, &val);
60 if (rc != 0)
61 goto out;
62 if (val != SCMP_ACT_ALLOW) {
63 rc = -1;
64 goto out;
65 }
66
67 rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_NNP, 0);
68 if (rc != 0)
69 goto out;
70 rc = seccomp_attr_get(ctx, SCMP_FLTATR_CTL_NNP, &val);
71 if (rc != 0)
72 goto out;
73 if (val != 0) {
74 rc = -1;
75 goto out;
76 }
77
78 rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1);
79 if (rc != 0 && rc != -EOPNOTSUPP)
80 goto out;
81 rc = seccomp_attr_get(ctx, SCMP_FLTATR_CTL_TSYNC, &val);
82 if (rc != 0)
83 goto out;
84 if (val != 1) {
85 rc = -1;
86 goto out;
87 }
88
89 rc = seccomp_attr_set(ctx, SCMP_FLTATR_API_TSKIP, 1);
90 if (rc != 0)
91 goto out;
92 rc = seccomp_attr_get(ctx, SCMP_FLTATR_API_TSKIP, &val);
93 if (rc != 0)
94 goto out;
95 if (val != 1) {
96 rc = -1;
97 goto out;
98 }
99
100 rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_LOG, 1);
101 if (rc != 0)
102 goto out;
103 rc = seccomp_attr_get(ctx, SCMP_FLTATR_CTL_LOG, &val);
104 if (rc != 0)
105 goto out;
106 if (val != 1) {
107 rc = -1;
108 goto out;
109 }
110
111
112 rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_SSB, 1);
113 if (rc != 0)
114 goto out;
115 rc = seccomp_attr_get(ctx, SCMP_FLTATR_CTL_SSB, &val);
116 if (rc != 0)
117 goto out;
118 if (val != 1) {
119 rc = -1;
120 goto out;
121 }
122
123 rc = 0;
124 out:
125 seccomp_release(ctx);
126 return (rc < 0 ? -rc : rc);
127 }