| 1 |
/** |
| 2 |
* Syscall resolver |
| 3 |
* |
| 4 |
* Copyright (c) 2012 Red Hat <[email protected]> |
| 5 |
* Author: Paul Moore <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* This library is free software; you can redistribute it and/or modify it |
| 10 |
* under the terms of version 2.1 of the GNU Lesser General Public License as |
| 11 |
* published by the Free Software Foundation. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, but WITHOUT |
| 14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 16 |
* for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with this library; if not, see <http://www.gnu.org/licenses>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <errno.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <ctype.h> |
| 26 |
#include <string.h> |
| 27 |
#include <unistd.h> |
| 28 |
|
| 29 |
#include <seccomp.h> |
| 30 |
|
| 31 |
/** |
| 32 |
* Print the usage information to stderr and exit |
| 33 |
* @param program the name of the current program being invoked |
| 34 |
* |
| 35 |
* Print the usage information and exit with EINVAL. |
| 36 |
* |
| 37 |
*/ |
| 38 |
static void exit_usage(const char *program) |
| 39 |
{ |
| 40 |
fprintf(stderr, |
| 41 |
"usage: %s [-h] [-a <arch>] [-t] <name>|<number>\n", |
| 42 |
program); |
| 43 |
exit(EINVAL); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* main |
| 48 |
*/ |
| 49 |
int main(int argc, char *argv[]) |
| 50 |
{ |
| 51 |
int opt; |
| 52 |
int translate = 0; |
| 53 |
uint32_t arch; |
| 54 |
int sys_num; |
| 55 |
const char *sys_name; |
| 56 |
|
| 57 |
arch = seccomp_arch_native(); |
| 58 |
|
| 59 |
/* parse the command line */ |
| 60 |
while ((opt = getopt(argc, argv, "a:ht")) > 0) { |
| 61 |
switch (opt) { |
| 62 |
case 'a': |
| 63 |
arch = seccomp_arch_resolve_name(optarg); |
| 64 |
if (arch == 0) |
| 65 |
exit_usage(argv[0]); |
| 66 |
break; |
| 67 |
case 't': |
| 68 |
translate = 1; |
| 69 |
break; |
| 70 |
case 'h': |
| 71 |
default: |
| 72 |
/* usage information */ |
| 73 |
exit_usage(argv[0]); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/* sanity checks */ |
| 78 |
if (optind >= argc) |
| 79 |
exit_usage(argv[0]); |
| 80 |
|
| 81 |
/* perform the syscall lookup */ |
| 82 |
if (isdigit(argv[optind][0]) || argv[optind][0] == '-') { |
| 83 |
sys_num = atoi(argv[optind]); |
| 84 |
sys_name = seccomp_syscall_resolve_num_arch(arch, sys_num); |
| 85 |
printf("%s\n", (sys_name ? sys_name : "UNKNOWN")); |
| 86 |
} else if (translate) { |
| 87 |
sys_num = seccomp_syscall_resolve_name_rewrite(arch, |
| 88 |
argv[optind]); |
| 89 |
printf("%d\n", sys_num); |
| 90 |
} else { |
| 91 |
sys_num = seccomp_syscall_resolve_name_arch(arch, argv[optind]); |
| 92 |
printf("%d\n", sys_num); |
| 93 |
} |
| 94 |
|
| 95 |
return 0; |
| 96 |
} |