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
main(int argc,char ** argv)8 int main(int argc, char **argv)
9 {
10 char *seuser = NULL, *level = NULL;
11 char **contextlist;
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);
39 exit(EXIT_SUCCESS);
40 }
41