aboutsummaryrefslogtreecommitdiff
path: root/parse_seccomp_policy.cc
blob: 09b90beb3833b182285a4a2d1f48c1fe46b8cc0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <stdio.h>

#include "bpf.h"
#include "syscall_filter.h"
#include "util.h"

/* TODO(jorgelo): Use libseccomp disassembler here. */
int main(int argc, char **argv) {
	init_logging(LOG_TO_FD, STDERR_FILENO, LOG_INFO);

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <policy file>\n", argv[0]);
		return 1;
	}

	FILE *f = fopen(argv[1], "r");
	if (!f) {
		pdie("fopen(%s) failed", argv[1]);
	}

	struct sock_fprog fp;
	int res = compile_filter(argv[1], f, &fp, 0, 0);
	if (res != 0) {
		die("compile_filter failed");
	}
	dump_bpf_prog(&fp);

	free(fp.filter);
	fclose(f);
	return 0;
}