Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 1 | // parse_seccomp_policy.cc |
| 2 | // Copyright (C) 2016 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | |
| 18 | #include "bpf.h" |
| 19 | #include "syscall_filter.h" |
| 20 | #include "util.h" |
| 21 | |
| 22 | /* TODO(jorgelo): Use libseccomp disassembler here. */ |
| 23 | int main(int argc, char **argv) { |
Luis Hector Chavez | 114a930 | 2017-09-05 20:36:58 -0700 | [diff] [blame] | 24 | init_logging(LOG_TO_FD, STDERR_FILENO, LOG_INFO); |
| 25 | |
Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 26 | if (argc < 2) { |
| 27 | fprintf(stderr, "Usage: %s <policy file>\n", argv[0]); |
| 28 | return 1; |
| 29 | } |
| 30 | |
| 31 | FILE *f = fopen(argv[1], "r"); |
| 32 | if (!f) { |
| 33 | pdie("fopen(%s) failed", argv[1]); |
| 34 | } |
| 35 | |
| 36 | struct sock_fprog fp; |
Luis Hector Chavez | 7624e71 | 2017-08-28 19:30:59 -0700 | [diff] [blame] | 37 | int res = compile_filter(argv[1], f, &fp, 0, 0); |
Jorge Lucangeli Obes | f16d6d1 | 2016-09-29 20:25:27 -0400 | [diff] [blame] | 38 | if (res != 0) { |
| 39 | die("compile_filter failed"); |
| 40 | } |
| 41 | dump_bpf_prog(&fp); |
| 42 | |
| 43 | free(fp.filter); |
| 44 | fclose(f); |
| 45 | return 0; |
| 46 | } |