Home | History | Annotate | Download | only in load_policy
      1 #include <unistd.h>
      2 #include <stdlib.h>
      3 #include <stdio.h>
      4 #include <errno.h>
      5 #include <getopt.h>
      6 #include <string.h>
      7 #include <selinux/selinux.h>
      8 #include <sepol/sepol.h>
      9 #ifdef USE_NLS
     10 #include <locale.h>		/* for setlocale() */
     11 #include <libintl.h>		/* for gettext() */
     12 #define _(msgid) gettext (msgid)
     13 #else
     14 #define _(msgid) (msgid)
     15 #endif
     16 #ifndef PACKAGE
     17 #define PACKAGE "policycoreutils"	/* the name of this package lang translation */
     18 #endif
     19 
     20 static __attribute__((__noreturn__)) void usage(const char *progname)
     21 {
     22 	fprintf(stderr, _("usage:  %s [-qi]\n"), progname);
     23 	exit(1);
     24 }
     25 
     26 int main(int argc, char **argv)
     27 {
     28 	int ret, opt, quiet = 0, nargs, init=0, enforce=0;
     29 
     30 #ifdef USE_NLS
     31 	setlocale(LC_ALL, "");
     32 	bindtextdomain(PACKAGE, LOCALEDIR);
     33 	textdomain(PACKAGE);
     34 #endif
     35 
     36 	while ((opt = getopt(argc, argv, "bqi")) > 0) {
     37 		switch (opt) {
     38 		case 'b':
     39 			fprintf(stderr, "%s:  Warning! The -b option is no longer supported, booleans are always preserved across reloads.  Continuing...\n",
     40 				argv[0]);
     41 			break;
     42 		case 'q':
     43 			quiet = 1;
     44 			sepol_debug(0);
     45 			break;
     46 		case 'i':
     47 			init = 1;
     48 			break;
     49 		default:
     50 			usage(argv[0]);
     51 		}
     52 	}
     53 
     54 	nargs = argc - optind;
     55 	if (nargs > 2)
     56 		usage(argv[0]);
     57 	if (nargs >= 1 && !quiet) {
     58 			fprintf(stderr,
     59 				"%s:  Warning!  Policy file argument (%s) is no longer supported, installed policy is always loaded.  Continuing...\n",
     60 				argv[0], argv[optind++]);
     61 	}
     62 	if (nargs == 2 && ! quiet) {
     63 		fprintf(stderr,
     64 			"%s:  Warning!  Boolean file argument (%s) is no longer supported, installed booleans file is always used.  Continuing...\n",
     65 			argv[0], argv[optind++]);
     66 	}
     67 	if (init) {
     68 		ret = selinux_init_load_policy(&enforce);
     69 		if (ret != 0 ) {
     70 			if (enforce > 0) {
     71 				/* SELinux in enforcing mode but load_policy failed */
     72 				fprintf(stderr,
     73 						_("%s:  Can't load policy and enforcing mode requested:  %s\n"),
     74 						argv[0], strerror(errno));
     75 				exit(3);
     76 			}
     77 		}
     78 	}
     79 	else {
     80 		ret = selinux_mkload_policy(1);
     81 	}
     82 	if (ret < 0) {
     83 		fprintf(stderr, _("%s:  Can't load policy:  %s\n"),
     84 			argv[0], strerror(errno));
     85 		exit(2);
     86 	}
     87 	exit(0);
     88 }
     89