Chris PeBenito 473ea7
#include <unistd.h>
Chris PeBenito 473ea7
#include <stdio.h>
Chris PeBenito 473ea7
#include <stdlib.h>
Chris PeBenito 473ea7
#include <ctype.h>
Chris PeBenito 473ea7
#include <string.h>
Chris PeBenito 473ea7
#include <strings.h>
Chris PeBenito 473ea7
#include <selinux/selinux.h>
Chris PeBenito 473ea7
Chris PeBenito 473ea7
void usage(const char *progname) {
Chris PeBenito 473ea7
	fprintf(stderr, "usage:  %s [ Enforcing | Permissive | 1 | 0 ]\n", progname);
Chris PeBenito 473ea7
	exit(1);
Chris PeBenito 473ea7
}
Chris PeBenito 473ea7
Chris PeBenito 473ea7
int main(int argc, char **argv) 
Chris PeBenito 473ea7
{
Chris PeBenito 473ea7
	int rc=0;
Chris PeBenito 473ea7
	if (argc != 2) {
Chris PeBenito 473ea7
		usage(argv[0]);
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
Chris PeBenito 473ea7
	if (is_selinux_enabled() <= 0) {
Chris PeBenito 473ea7
		fprintf(stderr, "%s: SELinux is disabled\n", argv[0]);
Chris PeBenito 473ea7
		return 1;
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
	if (strlen(argv[1]) == 1 && (argv[1][0] == '0' || argv[1][0]=='1')) {
Chris PeBenito 473ea7
		rc = security_setenforce(atoi(argv[1]));
Chris PeBenito 473ea7
	} else {
Chris PeBenito 473ea7
		if (strcasecmp(argv[1], "enforcing")==0) {
Chris PeBenito 473ea7
			rc = security_setenforce(1);
Chris PeBenito 473ea7
		}
Chris PeBenito 473ea7
		else
Chris PeBenito 473ea7
		if (strcasecmp(argv[1], "permissive")==0) {
Chris PeBenito 473ea7
			rc = security_setenforce(0);
Chris PeBenito 473ea7
		}
Chris PeBenito 473ea7
		else
Chris PeBenito 473ea7
			usage(argv[0]);
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
	if (rc < 0) {
Chris PeBenito 473ea7
		fprintf(stderr, "%s:  setenforce() failed\n", argv[0]);
Chris PeBenito 473ea7
		return 2;
Chris PeBenito 473ea7
	}
Chris PeBenito 473ea7
	return 0;
Chris PeBenito 473ea7
}