Blame SOURCES/0172-tests-linkat-provide-fallback-values-for-secontext-f.patch

742536
From 97e2742a7f1e6e113354911d04505ada3bfb5d70 Mon Sep 17 00:00:00 2001
742536
From: Eugene Syromyatnikov <evgsyr@gmail.com>
742536
Date: Tue, 18 Jan 2022 18:04:42 +0100
742536
Subject: [PATCH 172/174] tests/linkat: provide fallback values for secontext
742536
 fields changes
742536
742536
* tests/linkat.c (mangle_secontext_field): New function.
742536
(main): Replace calls to update_secontext_field
742536
with mangle_secontext_field calls.
742536
---
742536
 tests/linkat.c | 23 ++++++++++++++++++++---
742536
 1 file changed, 20 insertions(+), 3 deletions(-)
742536
742536
diff --git a/tests/linkat.c b/tests/linkat.c
742536
index c3e2ee4..decb736 100644
742536
--- a/tests/linkat.c
742536
+++ b/tests/linkat.c
742536
@@ -21,6 +21,20 @@
742536
 #include "secontext.h"
742536
 #include "xmalloc.h"
742536
 
742536
+static void
742536
+mangle_secontext_field(const char *path, enum secontext_field field,
742536
+		       const char *new_val, const char *fallback_val)
742536
+{
742536
+	char *orig = get_secontext_field_file(path, field);
742536
+	if (!orig)
742536
+		return;
742536
+
742536
+	update_secontext_field(path, field,
742536
+			       strcmp(new_val, orig) ? new_val : fallback_val);
742536
+
742536
+	free(orig);
742536
+}
742536
+
742536
 int
742536
 main(void)
742536
 {
742536
@@ -93,7 +107,8 @@ main(void)
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_USER, "system_u");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_USER, "system_u",
742536
+							 "unconfined_u");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 
742536
 # ifdef PRINT_SECONTEXT_FULL
742536
@@ -115,7 +130,8 @@ main(void)
742536
 #endif
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_TYPE, "default_t",
742536
+							 "unconfined_t");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 	sample_2_secontext = sample_1_secontext;
742536
 
742536
@@ -146,7 +162,8 @@ main(void)
742536
 	char *cwd = get_fd_path(dfd_old);
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(".", SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(".", SECONTEXT_TYPE, "default_t",
742536
+						    "unconfined_t");
742536
 	char *dfd_old_secontext = SECONTEXT_FILE(".");
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
diff --git a/tests-m32/linkat.c b/tests-m32/linkat.c
742536
index c3e2ee4..decb736 100644
742536
--- a/tests-m32/linkat.c
742536
+++ b/tests-m32/linkat.c
742536
@@ -21,6 +21,20 @@
742536
 #include "secontext.h"
742536
 #include "xmalloc.h"
742536
 
742536
+static void
742536
+mangle_secontext_field(const char *path, enum secontext_field field,
742536
+		       const char *new_val, const char *fallback_val)
742536
+{
742536
+	char *orig = get_secontext_field_file(path, field);
742536
+	if (!orig)
742536
+		return;
742536
+
742536
+	update_secontext_field(path, field,
742536
+			       strcmp(new_val, orig) ? new_val : fallback_val);
742536
+
742536
+	free(orig);
742536
+}
742536
+
742536
 int
742536
 main(void)
742536
 {
742536
@@ -93,7 +107,8 @@ main(void)
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_USER, "system_u");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_USER, "system_u",
742536
+							 "unconfined_u");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 
742536
 # ifdef PRINT_SECONTEXT_FULL
742536
@@ -115,7 +130,8 @@ main(void)
742536
 #endif
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_TYPE, "default_t",
742536
+							 "unconfined_t");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 	sample_2_secontext = sample_1_secontext;
742536
 
742536
@@ -146,7 +162,8 @@ main(void)
742536
 	char *cwd = get_fd_path(dfd_old);
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(".", SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(".", SECONTEXT_TYPE, "default_t",
742536
+						    "unconfined_t");
742536
 	char *dfd_old_secontext = SECONTEXT_FILE(".");
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
diff --git a/tests-mx32/linkat.c b/tests-mx32/linkat.c
742536
index c3e2ee4..decb736 100644
742536
--- a/tests-mx32/linkat.c
742536
+++ b/tests-mx32/linkat.c
742536
@@ -21,6 +21,20 @@
742536
 #include "secontext.h"
742536
 #include "xmalloc.h"
742536
 
742536
+static void
742536
+mangle_secontext_field(const char *path, enum secontext_field field,
742536
+		       const char *new_val, const char *fallback_val)
742536
+{
742536
+	char *orig = get_secontext_field_file(path, field);
742536
+	if (!orig)
742536
+		return;
742536
+
742536
+	update_secontext_field(path, field,
742536
+			       strcmp(new_val, orig) ? new_val : fallback_val);
742536
+
742536
+	free(orig);
742536
+}
742536
+
742536
 int
742536
 main(void)
742536
 {
742536
@@ -93,7 +107,8 @@ main(void)
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_USER, "system_u");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_USER, "system_u",
742536
+							 "unconfined_u");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 
742536
 # ifdef PRINT_SECONTEXT_FULL
742536
@@ -115,7 +130,8 @@ main(void)
742536
 #endif
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(sample_1, SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(sample_1, SECONTEXT_TYPE, "default_t",
742536
+							 "unconfined_t");
742536
 	sample_1_secontext = SECONTEXT_FILE(sample_1);
742536
 	sample_2_secontext = sample_1_secontext;
742536
 
742536
@@ -146,7 +162,8 @@ main(void)
742536
 	char *cwd = get_fd_path(dfd_old);
742536
 
742536
 	errno = 0;
742536
-	update_secontext_field(".", SECONTEXT_TYPE, "default_t");
742536
+	mangle_secontext_field(".", SECONTEXT_TYPE, "default_t",
742536
+						    "unconfined_t");
742536
 	char *dfd_old_secontext = SECONTEXT_FILE(".");
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
-- 
742536
2.1.4
742536