chkcon.c revision 255e72915d4cbddceb435e13d81601755714e9f3
1#include <sepol/sepol.h>
2#include <unistd.h>
3#include <sys/types.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <errno.h>
8
9void usage(char *progname)
10{
11	printf("usage:  %s policy context\n", progname);
12	exit(1);
13}
14
15int main(int argc, char **argv)
16{
17	FILE *fp;
18
19	if (argc != 3)
20		usage(argv[0]);
21
22	fp = fopen(argv[1], "r");
23	if (!fp) {
24		fprintf(stderr, "Can't open '%s':  %s\n",
25			argv[1], strerror(errno));
26		exit(1);
27	}
28	if (sepol_set_policydb_from_file(fp) < 0) {
29		fprintf(stderr, "Error while processing %s:  %s\n",
30			argv[1], strerror(errno));
31		exit(1);
32	}
33	fclose(fp);
34
35	if (sepol_check_context(argv[2]) < 0) {
36		fprintf(stderr, "%s is not valid\n", argv[2]);
37		exit(1);
38	}
39
40	printf("%s is valid\n", argv[2]);
41	exit(0);
42}
43