1 /*
2 *
3 * Authors: 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 [ (Enforcing|1) | (Permissive|0) ]\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 = 0;
29 xc_interface *xch = 0;
30 long mode = 0;
31 char *end;
32
33 if (argCnt != 2)
34 usage(argCnt, args);
35
36 xch = xc_interface_open(0,0,0);
37 if ( !xch )
38 {
39 fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
40 strerror(errno));
41 ret = -1;
42 goto done;
43 }
44
45 if( strlen(args[1]) == 1 && (args[1][0] == '0' || args[1][0] == '1')){
46 mode = strtol(args[1], &end, 10);
47 ret = xc_flask_setenforce(xch, mode);
48 } else {
49 if( strcasecmp(args[1], "enforcing") == 0 ){
50 ret = xc_flask_setenforce(xch, 1);
51 } else if( strcasecmp(args[1], "permissive") == 0 ){
52 ret = xc_flask_setenforce(xch, 0);
53 } else {
54 usage(argCnt, args);
55 }
56 }
57
58 if ( ret < 0 )
59 {
60 errno = -ret;
61 fprintf(stderr, "Unable to get enforcing mode: %s\n",
62 strerror(errno));
63 ret = -1;
64 goto done;
65 }
66
67 done:
68 if ( xch )
69 xc_interface_close(xch);
70
71 return ret;
72 }
73