Mike Frysinger | 50e31fa | 2018-01-19 18:59:49 -0500 | [diff] [blame] | 1 | /* Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 5 | |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "bpf.h" |
| 9 | #include "syscall_filter.h" |
| 10 | #include "util.h" |
| 11 | |
| 12 | /* TODO(jorgelo): Use libseccomp disassembler here. */ |
| 13 | int main(int argc, char **argv) { |
Luis Hector Chavez | 114a930 | 2017-09-05 20:36:58 -0700 | [diff] [blame] | 14 | init_logging(LOG_TO_FD, STDERR_FILENO, LOG_INFO); |
| 15 | |
Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 16 | if (argc < 2) { |
| 17 | fprintf(stderr, "Usage: %s <policy file>\n", argv[0]); |
| 18 | return 1; |
| 19 | } |
| 20 | |
| 21 | FILE *f = fopen(argv[1], "r"); |
| 22 | if (!f) { |
| 23 | pdie("fopen(%s) failed", argv[1]); |
| 24 | } |
| 25 | |
| 26 | struct sock_fprog fp; |
Luis Hector Chavez | 7624e71 | 2017-08-28 19:30:59 -0700 | [diff] [blame] | 27 | int res = compile_filter(argv[1], f, &fp, 0, 0); |
Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 28 | if (res != 0) { |
| 29 | die("compile_filter failed"); |
| 30 | } |
| 31 | dump_bpf_prog(&fp); |
| 32 | |
| 33 | free(fp.filter); |
| 34 | fclose(f); |
| 35 | return 0; |
| 36 | } |