~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/flask/utils/getenforce.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include <libflask.h>
 
20
 
 
21
static void usage (int argCnt, const char *args[])
 
22
{
 
23
    fprintf(stderr, "Usage: %s\n", args[0]);
 
24
    exit(1);
 
25
}
 
26
 
 
27
int main (int argCnt, const char *args[])
 
28
{
 
29
    int ret;
 
30
    int xch = 0;
 
31
 
 
32
    if (argCnt != 1)
 
33
        usage(argCnt, args);
 
34
 
 
35
    xch = xc_interface_open();
 
36
    if ( xch < 0 )
 
37
    {
 
38
        fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
 
39
                strerror(errno));
 
40
        ret = -1;
 
41
        goto done;
 
42
    }
 
43
 
 
44
    ret = flask_getenforce(xch);
 
45
    if ( ret < 0 )
 
46
    {
 
47
        errno = -ret;
 
48
        fprintf(stderr, "Unable to get enforcing mode: %s\n",
 
49
                strerror(errno));
 
50
        ret = -1;
 
51
        goto done;
 
52
    }
 
53
    else
 
54
    {
 
55
        if(ret) 
 
56
            printf("Enforcing\n");
 
57
        else
 
58
            printf("Permissive\n");
 
59
    }
 
60
 
 
61
done:
 
62
    if ( xch )
 
63
        xc_interface_close(xch);
 
64
 
 
65
    return ret;
 
66
}