debuggers.hg

view tools/flask/utils/setenforce.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 779c0ef9682c
children
line source
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 */
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 #include <libflask.h>
21 static void usage (int argCnt, const char *args[])
22 {
23 fprintf(stderr, "Usage: %s [ (Enforcing|1) | (Permissive|0) ]\n", args[0]);
24 exit(1);
25 }
27 int main (int argCnt, const char *args[])
28 {
29 int ret = 0;
30 xc_interface *xch = 0;
31 long mode = 0;
32 char *end;
34 if (argCnt != 2)
35 usage(argCnt, args);
37 xch = xc_interface_open(0,0,0);
38 if ( !xch )
39 {
40 fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
41 strerror(errno));
42 ret = -1;
43 goto done;
44 }
46 if( strlen(args[1]) == 1 && (args[1][0] == '0' || args[1][0] == '1')){
47 mode = strtol(args[1], &end, 10);
48 ret = flask_setenforce(xch, mode);
49 } else {
50 if( strcasecmp(args[1], "enforcing") == 0 ){
51 ret = flask_setenforce(xch, 1);
52 } else if( strcasecmp(args[1], "permissive") == 0 ){
53 ret = flask_setenforce(xch, 0);
54 } else {
55 usage(argCnt, args);
56 }
57 }
59 if ( ret < 0 )
60 {
61 errno = -ret;
62 fprintf(stderr, "Unable to get enforcing mode: %s\n",
63 strerror(errno));
64 ret = -1;
65 goto done;
66 }
68 done:
69 if ( xch )
70 xc_interface_close(xch);
72 return ret;
73 }