Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | #include <selinux/selinux.h> |
| 6 | #include <selinux/get_context_list.h> |
| 7 | |
| 8 | int main(int argc, char **argv) |
| 9 | { |
| 10 | char *seuser = NULL, *level = NULL; |
Stephen Smalley | 9eb9c93 | 2014-02-19 09:16:17 -0500 | [diff] [blame] | 11 | char **contextlist; |
Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 12 | int rc, n, i; |
| 13 | |
| 14 | if (argc != 3) { |
| 15 | fprintf(stderr, "usage: %s linuxuser fromcon\n", argv[0]); |
| 16 | exit(1); |
| 17 | } |
| 18 | |
| 19 | rc = getseuserbyname(argv[1], &seuser, &level); |
| 20 | if (rc) { |
| 21 | fprintf(stderr, "getseuserbyname failed: %s\n", |
| 22 | strerror(errno)); |
| 23 | exit(2); |
| 24 | } |
| 25 | printf("seuser: %s, level %s\n", seuser, level); |
| 26 | n = get_ordered_context_list_with_level(seuser, level, argv[2], |
| 27 | &contextlist); |
| 28 | if (n <= 0) { |
| 29 | fprintf(stderr, |
| 30 | "get_ordered_context_list_with_level failed: %s\n", |
| 31 | strerror(errno)); |
| 32 | exit(3); |
| 33 | } |
| 34 | free(seuser); |
| 35 | free(level); |
| 36 | for (i = 0; i < n; i++) |
| 37 | printf("Context %d\t%s\n", i, contextlist[i]); |
| 38 | freeconary(contextlist); |
Unto Sten | 5d8f44e | 2019-05-10 20:10:37 +0300 | [diff] [blame] | 39 | exit(EXIT_SUCCESS); |
Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 40 | } |