1 /*
2  *
3  *  Author:  Machon Gregory, <mbgrego@tycho.ncsc.mil>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License version 2,
7  *  as published by the Free Software Foundation.
8  */
9 
10 #include <stdlib.h>
11 #include <errno.h>
12 #include <stdio.h>
13 #include <xenctrl.h>
14 #include <fcntl.h>
15 #include <sys/mman.h>
16 #include <sys/stat.h>
17 #include <string.h>
18 #include <unistd.h>
19 
usage(int argCnt,const char * args[])20 static void usage (int argCnt, const char *args[])
21 {
22     fprintf(stderr, "Usage: %s\n", args[0]);
23     exit(1);
24 }
25 
main(int argCnt,const char * args[])26 int main (int argCnt, const char *args[])
27 {
28     int ret;
29     xc_interface *xch = 0;
30 
31     if (argCnt != 1)
32         usage(argCnt, args);
33 
34     xch = xc_interface_open(0,0,0);
35     if ( !xch )
36     {
37         fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
38                 strerror(errno));
39         ret = -1;
40         goto done;
41     }
42 
43     ret = xc_flask_getenforce(xch);
44     if ( ret < 0 )
45     {
46         errno = -ret;
47         fprintf(stderr, "Unable to get enforcing mode: %s\n",
48                 strerror(errno));
49         ret = -1;
50         goto done;
51     }
52     else
53     {
54         if(ret)
55             printf("Enforcing\n");
56         else
57             printf("Permissive\n");
58     }
59 
60 done:
61     if ( xch )
62         xc_interface_close(xch);
63 
64     return ret;
65 }
66