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*) __attribute__((noreturn));
10
11void usage(char *progname)
12{
13	printf("usage:  %s policy context\n", progname);
14	exit(1);
15}
16
17int main(int argc, char **argv)
18{
19	FILE *fp;
20
21	if (argc != 3)
22		usage(argv[0]);
23
24	fp = fopen(argv[1], "r");
25	if (!fp) {
26		fprintf(stderr, "Can't open '%s':  %s\n",
27			argv[1], strerror(errno));
28		exit(1);
29	}
30	if (sepol_set_policydb_from_file(fp) < 0) {
31		fprintf(stderr, "Error while processing %s:  %s\n",
32			argv[1], strerror(errno));
33		exit(1);
34	}
35	fclose(fp);
36
37	if (sepol_check_context(argv[2]) < 0) {
38		fprintf(stderr, "%s is not valid\n", argv[2]);
39		exit(1);
40	}
41
42	printf("%s is valid\n", argv[2]);
43	exit(0);
44}
45