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

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