]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/seccomp-util.c
resolved: fix deserialization of UTF8 host names
[thirdparty/systemd.git] / src / shared / seccomp-util.c
CommitLineData
57183d11
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <seccomp.h>
23
24#include "util.h"
25#include "seccomp-util.h"
26
27const char* seccomp_arch_to_string(uint32_t c) {
28
29 if (c == SCMP_ARCH_NATIVE)
30 return "native";
31 if (c == SCMP_ARCH_X86)
32 return "x86";
33 if (c == SCMP_ARCH_X86_64)
34 return "x86-64";
35 if (c == SCMP_ARCH_X32)
36 return "x32";
37 if (c == SCMP_ARCH_ARM)
38 return "arm";
39
40 return NULL;
41}
42
43int seccomp_arch_from_string(const char *n, uint32_t *ret) {
44 if (!n)
45 return -EINVAL;
46
47 assert(ret);
48
49 if (streq(n, "native"))
50 *ret = SCMP_ARCH_NATIVE;
51 else if (streq(n, "x86"))
52 *ret = SCMP_ARCH_X86;
53 else if (streq(n, "x86-64"))
54 *ret = SCMP_ARCH_X86_64;
55 else if (streq(n, "x32"))
56 *ret = SCMP_ARCH_X32;
57 else if (streq(n, "arm"))
58 *ret = SCMP_ARCH_ARM;
59 else
60 return -EINVAL;
61
62 return 0;
63}
e9642be2
LP
64
65int seccomp_add_secondary_archs(scmp_filter_ctx *c) {
66
67#if defined(__i386__) || defined(__x86_64__)
68 int r;
69
70 /* Add in all possible secondary archs we are aware of that
71 * this kernel might support. */
72
73 r = seccomp_arch_add(c, SCMP_ARCH_X86);
74 if (r < 0 && r != -EEXIST)
75 return r;
76
77 r = seccomp_arch_add(c, SCMP_ARCH_X86_64);
78 if (r < 0 && r != -EEXIST)
79 return r;
80
81 r = seccomp_arch_add(c, SCMP_ARCH_X32);
82 if (r < 0 && r != -EEXIST)
83 return r;
84
85#endif
86
87 return 0;
88
89}