aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/getenforce.c
blob: ce43f523da0fd24e76e58c40bcf6ef8827926372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* getenforce.c - Get the current SELinux mode
 *
 * Copyright 2014 The Android Open Source Project

USE_GETENFORCE(NEWTOY(getenforce, "", TOYFLAG_USR|TOYFLAG_SBIN))

config GETENFORCE
  bool "getenforce"
  default n
  help
    usage: getenforce

    Shows whether SELinux is disabled, enforcing, or permissive.
*/

#define FOR_getenforce
#include "toys.h"
#include <selinux/selinux.h>

void getenforce_main(void)
{
  if (!is_selinux_enabled())
    printf("Disabled\n");
  else {
    int ret = security_getenforce();
    if (ret == -1)
      perror_exit("Couldn't get enforcing status");
    else
      printf(ret ? "Enforcing\n" : "Permissive\n");
  }
}