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

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