Skip to contentSkip to conversation

Patch's to make load_policy (and libsepol) be quiet.

PATCH Daniel J Walsh 1 participant 1 message Feb 25, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw
load_policy/load_policy.c +4 -1
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/load_policy/load_policy.c policycoreutils-1.21.20/load_policy/load_policy.c
@@ -49,6 +49,7 @@
 			break;
 		case 'q':
 			quiet = 1;
+			sepol_debug(0);
 			break;
 		default:
 			usage(argv[0]);
@@ -87,7 +88,9 @@
 
 	ret = sepol_genusers(map, sb.st_size, selinux_users_path(), &data, &data_size);
 	if (ret < 0) {
-		fprintf(stderr, _("%s:  Error while setting user configuration from %s:  %s\n"), argv[0], selinux_users_path(), strerror(errno));
+		/* No users file; non-fatal. */
+		if (! quiet) 
+			fprintf(stderr, _("%s:  Error while setting user configuration from %s/{local.users,system.users}:  %s\n"), argv[0], selinux_users_path(), strerror(errno));
 		data = map;
 		data_size = sb.st_size;
 	}
include/sepol/sepol.h +2 -1
diff --exclude-from=exclude -N -u -r nsalibsepol/include/sepol/sepol.h libsepol-1.3.6/include/sepol/sepol.h
@@ -32,5 +32,6 @@
 /* Check context validity against currently set binary policy. */
 extern int sepol_check_context(char *context);
 
-
+/* Turn on or off sepol error messages. */
+extern void sepol_debug(int on);
 #endif
src/genbools.c +7 -7
diff --exclude-from=exclude -N -u -r nsalibsepol/src/genbools.c libsepol-1.3.6/src/genbools.c
@@ -87,7 +87,7 @@
 	pf.data = data;
 	pf.len = len;
 	if (policydb_read(&policydb,&pf, 0)) {
-		fprintf(stderr, "Can't read binary policy:  %s\n",
+		__sepol_debug_printf("Can't read binary policy:  %s\n",
 			strerror(errno));
 		return -1;
 	}
@@ -97,12 +97,12 @@
 	sepol_set_policyvers(policydb.policyvers);
 
 	if (load_booleans(&policydb, booleans) < 0) {
-		fprintf(stderr, "Warning!  Error while reading %s:  %s\n",
+		__sepol_debug_printf("Warning!  Error while reading %s:  %s\n",
 			booleans, strerror(errno));
 	}
 
 	if (evaluate_conds(&policydb) < 0) {
-		fprintf(stderr, "Error while re-evaluating conditionals: %s\n",
+		__sepol_debug_printf("Error while re-evaluating conditionals: %s\n",
 			strerror(errno));
 		return -1;
 	}
@@ -111,7 +111,7 @@
 	pf.len = len;
 	rc = policydb_write(&policydb, &pf);
 	if (rc) {
-		fprintf(stderr, "Can't write binary policy:  %s\n",
+		__sepol_debug_printf("Can't write binary policy:  %s\n",
 			strerror(errno));
 		return -1;
 	}
@@ -129,7 +129,7 @@
 	pf.data = data;
 	pf.len = len;
 	if (policydb_read(&policydb,&pf, 0)) {
-		fprintf(stderr, "Can't read binary policy:  %s\n",
+		__sepol_debug_printf("Can't read binary policy:  %s\n",
 			strerror(errno));
 		return -1;
 	}
@@ -154,7 +154,7 @@
 	}
 
 	if (evaluate_conds(&policydb) < 0) {
-		fprintf(stderr, "Error while re-evaluating conditionals: %s\n",
+		__sepol_debug_printf("Error while re-evaluating conditionals: %s\n",
 			strerror(errno));
 		return -1;
 	}
@@ -163,7 +163,7 @@
 	pf.len = len;
 	rc = policydb_write(&policydb, &pf);
 	if (rc) {
-		fprintf(stderr, "Can't write binary policy:  %s\n",
+		__sepol_debug_printf("Can't write binary policy:  %s\n",
 			strerror(errno));
 		return -1;
 	}
src/genusers.c +28 -15

138 lines not on this page · raw message

src/libsepol.map +1 -1
diff --exclude-from=exclude -N -u -r nsalibsepol/src/libsepol.map libsepol-1.3.6/src/libsepol.map
@@ -1,4 +1,4 @@
 {
-  global: sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers;
+  global: sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug;
   local: *;
 };
src/private.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibsepol/src/private.h libsepol-1.3.6/src/private.h
@@ -25,6 +25,7 @@
 };
 
 extern struct policydb_compat_info *policydb_lookup_compat(int version);
+extern void __sepol_debug_printf(const char *fmt, ...);
 
 /* Reading from a policy "file". */
 static inline void *next_entry(struct policy_file * fp, size_t bytes)