File: chkcon.c

package info (click to toggle)
android-platform-external-libselinux 8.1.0%2Br23-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,252 kB
  • sloc: ansic: 142,533; python: 23,929; makefile: 1,760; yacc: 1,367; sh: 1,108; lex: 448; xml: 176
file content (44 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (11)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <sepol/sepol.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

void usage(char*) __attribute__((noreturn));

void usage(char *progname)
{
	printf("usage:  %s policy context\n", progname);
	exit(1);
}

int main(int argc, char **argv)
{
	FILE *fp;

	if (argc != 3)
		usage(argv[0]);

	fp = fopen(argv[1], "r");
	if (!fp) {
		fprintf(stderr, "Can't open '%s':  %s\n",
			argv[1], strerror(errno));
		exit(1);
	}
	if (sepol_set_policydb_from_file(fp) < 0) {
		fprintf(stderr, "Error while processing %s:  %s\n",
			argv[1], strerror(errno));
		exit(1);
	}
	fclose(fp);

	if (sepol_check_context(argv[2]) < 0) {
		fprintf(stderr, "%s is not valid\n", argv[2]);
		exit(1);
	}

	printf("%s is valid\n", argv[2]);
	exit(0);
}