Blame tests/33-sim-socket_syscalls_be.c

Packit Service 8eee21
/**
Packit Service 8eee21
 * Seccomp Library test program
Packit Service 8eee21
 *
Packit Service 8eee21
 * Copyright (c) 2016 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
	rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_arch_add(ctx, SCMP_ARCH_S390);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
	rc = seccomp_arch_add(ctx, SCMP_ARCH_S390X);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 0);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(connect), 0);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(accept), 0);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(accept4), 0);
Packit Service 8eee21
	if (rc != 0)
Packit Service 8eee21
		goto out;
Packit Service 8eee21
Packit Service 8eee21
	rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(shutdown), 0);
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
}