blob: 88debbecc4cb4aab48ea4616280021d8f78932ef [file] [log] [blame]
Jorge Lucangeli Obesf16d6d12016-09-29 20:25:27 -04001// 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. */
23int main(int argc, char **argv) {
Luis Hector Chavez114a9302017-09-05 20:36:58 -070024 init_logging(LOG_TO_FD, STDERR_FILENO, LOG_INFO);
25
Jorge Lucangeli Obesf16d6d12016-09-29 20:25:27 -040026 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 Chavez7624e712017-08-28 19:30:59 -070037 int res = compile_filter(argv[1], f, &fp, 0, 0);
Jorge Lucangeli Obesf16d6d12016-09-29 20:25:27 -040038 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}