Blame tests/25-sim-multilevel_chains_adv.c

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