Home | History | Annotate | Download | only in utils
      1 #include <unistd.h>
      2 #include <sys/types.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <errno.h>
      6 #include <selinux/selinux.h>
      7 
      8 int main(int argc, char **argv)
      9 {
     10 	char *buf;
     11 	security_class_t tclass;
     12 	int ret;
     13 
     14 	if (argc != 4) {
     15 		fprintf(stderr, "usage:  %s scontext tcontext tclass\n",
     16 			argv[0]);
     17 		exit(1);
     18 	}
     19 
     20 	tclass = string_to_security_class(argv[3]);
     21 	if (!tclass) {
     22 		fprintf(stderr, "%s:  invalid class '%s'\n", argv[0], argv[3]);
     23 		exit(2);
     24 	}
     25 
     26 	ret = security_compute_relabel(argv[1], argv[2], tclass, &buf);
     27 	if (ret < 0) {
     28 		fprintf(stderr, "%s:  security_compute_relabel failed\n",
     29 			argv[0]);
     30 		exit(3);
     31 	}
     32 
     33 	printf("%s\n", buf);
     34 	freecon(buf);
     35 	exit(0);
     36 }
     37