Blame SOURCES/0011-libsemanage-clean-up-semanage_direct_commit-a-bit.patch

634418
From 129e121c9ab17f726a9a6294cfe04db97016e7ef Mon Sep 17 00:00:00 2001
634418
From: Ondrej Mosnacek <omosnace@redhat.com>
634418
Date: Thu, 3 Feb 2022 17:53:25 +0100
634418
Subject: [PATCH] libsemanage: clean up semanage_direct_commit() a bit
634418
634418
Do some minor cosmetic cleanup, mainly to eliminate the 'rebuilt' goto
634418
label.
634418
634418
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
634418
---
634418
 libsemanage/src/direct_api.c | 91 ++++++++++++++++++------------------
634418
 1 file changed, 45 insertions(+), 46 deletions(-)
634418
634418
diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c
634418
index 63a18808..7e99a59f 100644
634418
--- a/libsemanage/src/direct_api.c
634418
+++ b/libsemanage/src/direct_api.c
634418
@@ -994,6 +994,16 @@ cleanup:
634418
 	return status;
634418
 }
634418
 
634418
+/* Files that must exist in order to skip policy rebuild. */
634418
+static const int semanage_computed_files[] = {
634418
+	SEMANAGE_STORE_KERNEL,
634418
+	SEMANAGE_STORE_FC,
634418
+	SEMANAGE_STORE_SEUSERS,
634418
+	SEMANAGE_LINKED,
634418
+	SEMANAGE_SEUSERS_LINKED,
634418
+	SEMANAGE_USERS_EXTRA_LINKED
634418
+};
634418
+
634418
 /* Copies a file from src to dst. If dst already exists then
634418
  * overwrite it. If source doesn't exist then return success.
634418
  * Returns 0 on success, -1 on error. */
634418
@@ -1053,6 +1063,14 @@ static int semanage_direct_commit(semanage_handle_t * sh)
634418
 	seusers_modified = seusers->dtable->is_modified(seusers->dbase);
634418
 	fcontexts_modified = fcontexts->dtable->is_modified(fcontexts->dbase);
634418
 
634418
+	/* Before we do anything else, flush the join to its component parts.
634418
+	 * This *does not* flush to disk automatically */
634418
+	if (users->dtable->is_modified(users->dbase)) {
634418
+		retval = users->dtable->flush(sh, users->dbase);
634418
+		if (retval < 0)
634418
+			goto cleanup;
634418
+	}
634418
+
634418
 	/* Rebuild if explicitly requested or any module changes occurred. */
634418
 	do_rebuild = sh->do_rebuild | sh->modules_modified;
634418
 
634418
@@ -1119,14 +1137,6 @@ static int semanage_direct_commit(semanage_handle_t * sh)
634418
 		}
634418
 	}
634418
 
634418
-	/* Before we do anything else, flush the join to its component parts.
634418
-	 * This *does not* flush to disk automatically */
634418
-	if (users->dtable->is_modified(users->dbase)) {
634418
-		retval = users->dtable->flush(sh, users->dbase);
634418
-		if (retval < 0)
634418
-			goto cleanup;
634418
-	}
634418
-
634418
 	/*
634418
 	 * This is for systems that have already migrated with an older version
634418
 	 * of semanage_migrate_store. The older version did not copy
634418
@@ -1135,48 +1145,20 @@ static int semanage_direct_commit(semanage_handle_t * sh)
634418
 	 * in order to skip re-linking are present; otherwise, we force
634418
 	 * a rebuild.
634418
 	 */
634418
-	if (!do_rebuild) {
634418
-		int files[] = {SEMANAGE_STORE_KERNEL,
634418
-					   SEMANAGE_STORE_FC,
634418
-					   SEMANAGE_STORE_SEUSERS,
634418
-					   SEMANAGE_LINKED,
634418
-					   SEMANAGE_SEUSERS_LINKED,
634418
-					   SEMANAGE_USERS_EXTRA_LINKED};
634418
-
634418
-		for (i = 0; i < (int) ARRAY_SIZE(files); i++) {
634418
-			path = semanage_path(SEMANAGE_TMP, files[i]);
634418
-			if (stat(path, &sb) != 0) {
634418
-				if (errno != ENOENT) {
634418
-					ERR(sh, "Unable to access %s: %s\n", path, strerror(errno));
634418
-					retval = -1;
634418
-					goto cleanup;
634418
-				}
634418
-
634418
-				do_rebuild = 1;
634418
-				goto rebuild;
634418
+	for (i = 0; !do_rebuild && i < (int)ARRAY_SIZE(semanage_computed_files); i++) {
634418
+		path = semanage_path(SEMANAGE_TMP, semanage_computed_files[i]);
634418
+		if (stat(path, &sb) != 0) {
634418
+			if (errno != ENOENT) {
634418
+				ERR(sh, "Unable to access %s: %s\n", path, strerror(errno));
634418
+				retval = -1;
634418
+				goto cleanup;
634418
 			}
634418
+
634418
+			do_rebuild = 1;
634418
+			break;
634418
 		}
634418
 	}
634418
 
634418
-rebuild:
634418
-	/*
634418
-	 * Now that we know whether or not a rebuild is required,
634418
-	 * we can determine what else needs to be done.
634418
-	 * We need to write the kernel policy if we are rebuilding
634418
-	 * or if any other policy component that lives in the kernel
634418
-	 * policy has been modified.
634418
-	 * We need to install the policy files if any of the managed files
634418
-	 * that live under /etc/selinux (kernel policy, seusers, file contexts)
634418
-	 * will be modified.
634418
-	 */
634418
-	do_write_kernel = do_rebuild | ports_modified | ibpkeys_modified |
634418
-		ibendports_modified |
634418
-		bools->dtable->is_modified(bools->dbase) |
634418
-		ifaces->dtable->is_modified(ifaces->dbase) |
634418
-		nodes->dtable->is_modified(nodes->dbase) |
634418
-		users->dtable->is_modified(users_base->dbase);
634418
-	do_install = do_write_kernel | seusers_modified | fcontexts_modified;
634418
-
634418
 	/*
634418
 	 * If there were policy changes, or explicitly requested, or
634418
 	 * any required files are missing, rebuild the policy.
634418
@@ -1323,6 +1305,23 @@ rebuild:
634418
 		}
634418
 	}
634418
 
634418
+	/*
634418
+	 * Determine what else needs to be done.
634418
+	 * We need to write the kernel policy if we are rebuilding
634418
+	 * or if any other policy component that lives in the kernel
634418
+	 * policy has been modified.
634418
+	 * We need to install the policy files if any of the managed files
634418
+	 * that live under /etc/selinux (kernel policy, seusers, file contexts)
634418
+	 * will be modified.
634418
+	 */
634418
+	do_write_kernel = do_rebuild | ports_modified | ibpkeys_modified |
634418
+		ibendports_modified |
634418
+		bools->dtable->is_modified(bools->dbase) |
634418
+		ifaces->dtable->is_modified(ifaces->dbase) |
634418
+		nodes->dtable->is_modified(nodes->dbase) |
634418
+		users->dtable->is_modified(users_base->dbase);
634418
+	do_install = do_write_kernel | seusers_modified | fcontexts_modified;
634418
+
634418
 	/* Attach our databases to the policydb we just created or loaded. */
634418
 	dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase, out);
634418
 	dbase_policydb_attach((dbase_policydb_t *) pports->dbase, out);
634418
-- 
634418
2.30.2
634418