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) { 24 if (argc < 2) { 25 fprintf(stderr, "Usage: %s <policy file>\n", argv[0]); 26 return 1; 27 } 28 29 FILE *f = fopen(argv[1], "r"); 30 if (!f) { 31 pdie("fopen(%s) failed", argv[1]); 32 } 33 34 struct sock_fprog fp; 35 int res = compile_filter(f, &fp, 0, 0); 36 if (res != 0) { 37 die("compile_filter failed"); 38 } 39 dump_bpf_prog(&fp); 40 41 free(fp.filter); 42 fclose(f); 43 return 0; 44 } 45