|
Packit Service |
8eee21 |
/**
|
|
Packit Service |
8eee21 |
* Seccomp Library test program
|
|
Packit Service |
8eee21 |
*
|
|
Packit Service |
8eee21 |
* Copyright (c) 2012 Red Hat <pmoore@redhat.com>
|
|
Packit Service |
8eee21 |
* Author: Paul Moore <paul@paul-moore.com>
|
|
Packit Service |
8eee21 |
*/
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
/*
|
|
Packit Service |
8eee21 |
* This library is free software; you can redistribute it and/or modify it
|
|
Packit Service |
8eee21 |
* under the terms of version 2.1 of the GNU Lesser General Public License as
|
|
Packit Service |
8eee21 |
* published by the Free Software Foundation.
|
|
Packit Service |
8eee21 |
*
|
|
Packit Service |
8eee21 |
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
8eee21 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit Service |
8eee21 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
Packit Service |
8eee21 |
* for more details.
|
|
Packit Service |
8eee21 |
*
|
|
Packit Service |
8eee21 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
8eee21 |
* along with this library; if not, see <http://www.gnu.org/licenses>.
|
|
Packit Service |
8eee21 |
*/
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
#include <errno.h>
|
|
Packit Service |
8eee21 |
#include <unistd.h>
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
#include <seccomp.h>
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
#include "util.h"
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
int main(int argc, char *argv[])
|
|
Packit Service |
8eee21 |
{
|
|
Packit Service |
8eee21 |
int rc;
|
|
Packit Service |
8eee21 |
struct util_options opts;
|
|
Packit Service |
8eee21 |
scmp_filter_ctx ctx = NULL;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
rc = util_getopt(argc, argv, &opts);
|
|
Packit Service |
8eee21 |
if (rc < 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
ctx = seccomp_init(SCMP_ACT_KILL);
|
|
Packit Service |
8eee21 |
if (ctx == NULL)
|
|
Packit Service |
8eee21 |
return ENOMEM;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
/* the syscall and argument numbers are all fake to make the test
|
|
Packit Service |
8eee21 |
* simpler */
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1000, 2,
|
|
Packit Service |
8eee21 |
SCMP_A0(SCMP_CMP_EQ, 0),
|
|
Packit Service |
8eee21 |
SCMP_A1(SCMP_CMP_EQ, 1));
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1001, 1,
|
|
Packit Service |
8eee21 |
SCMP_A0(SCMP_CMP_EQ, 0));
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1002, 0);
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
rc = seccomp_syscall_priority(ctx, 1000, 3);
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
rc = seccomp_syscall_priority(ctx, 1001, 2);
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
rc = seccomp_syscall_priority(ctx, 1002, 1);
|
|
Packit Service |
8eee21 |
if (rc != 0)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
rc = util_filter_output(&opts, ctx);
|
|
Packit Service |
8eee21 |
if (rc)
|
|
Packit Service |
8eee21 |
goto out;
|
|
Packit Service |
8eee21 |
|
|
Packit Service |
8eee21 |
out:
|
|
Packit Service |
8eee21 |
seccomp_release(ctx);
|
|
Packit Service |
8eee21 |
return (rc < 0 ? -rc : rc);
|
|
Packit Service |
8eee21 |
}
|