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

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