Blame SOURCES/0174-tests-linkat-reset-context-to-the-expected-one-if-a-.patch

742536
From 78a81bcfb71ef3d9f6e8b1a32e123fbbc6112a60 Mon Sep 17 00:00:00 2001
742536
From: Eugene Syromyatnikov <evgsyr@gmail.com>
742536
Date: Tue, 18 Jan 2022 18:24:34 +0100
742536
Subject: [PATCH 174/174] tests/linkat: reset context to the expected one if a
742536
 mismatch has been detected
742536
742536
* tests/secontext.h (reset_secontext_file): New declaration.
742536
* tests/secontext.c (reset_secontext_file): New function.
742536
* tests/linkat.c (main): Check that there is no initial mismatch
742536
in the sample_1 context, reset it otherwise.
742536
---
742536
 tests/linkat.c    | 3 +++
742536
 tests/secontext.c | 7 +++++++
742536
 tests/secontext.h | 7 +++++++
742536
 3 files changed, 17 insertions(+)
742536
742536
diff --git a/tests/linkat.c b/tests/linkat.c
742536
index decb736..781b85a 100644
742536
--- a/tests/linkat.c
742536
+++ b/tests/linkat.c
742536
@@ -103,6 +103,9 @@ main(void)
742536
 	if (close(fd_sample_2))
742536
 		perror_msg_and_fail("close");
742536
 
742536
+	if (*sample_1_secontext && strstr(sample_1_secontext, "!!"))
742536
+		reset_secontext_file(sample_1);
742536
+
742536
 	free(sample_1_secontext);
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
diff --git a/tests/secontext.c b/tests/secontext.c
742536
index ba271c8..94fadd4 100644
742536
--- a/tests/secontext.c
742536
+++ b/tests/secontext.c
742536
@@ -235,6 +235,13 @@ secontext_short_pid(pid_t pid)
742536
 	return FORMAT_SPACE_AFTER(raw_secontext_short_pid(pid));
742536
 }
742536
 
742536
+void reset_secontext_file(const char *file)
742536
+{
742536
+	char *proper_ctx = raw_expected_secontext_full_file(file);
742536
+	(void) setfilecon(file, proper_ctx);
742536
+	free(proper_ctx);
742536
+}
742536
+
742536
 void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
diff --git a/tests/secontext.h b/tests/secontext.h
742536
index e5571d5..387263e 100644
742536
--- a/tests/secontext.h
742536
+++ b/tests/secontext.h
742536
@@ -32,6 +32,8 @@ char *get_secontext_field(const char *full_context, enum secontext_field field);
742536
 
742536
 char *get_secontext_field_file(const char *file, enum secontext_field field);
742536
 
742536
+void reset_secontext_file(const char *file);
742536
+
742536
 void update_secontext_field(const char *file, enum secontext_field field,
742536
 			    const char *newvalue);
742536
 
742536
@@ -69,6 +71,11 @@ get_secontext_field_file(const char *file, enum secontext_field field)
742536
 }
742536
 
742536
 static inline void
742536
+reset_secontext_file(const char *file)
742536
+{
742536
+}
742536
+
742536
+static inline void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
 {
742536
diff --git a/tests-m32/linkat.c b/tests-m32/linkat.c
742536
index decb736..781b85a 100644
742536
--- a/tests-m32/linkat.c
742536
+++ b/tests-m32/linkat.c
742536
@@ -103,6 +103,9 @@ main(void)
742536
 	if (close(fd_sample_2))
742536
 		perror_msg_and_fail("close");
742536
 
742536
+	if (*sample_1_secontext && strstr(sample_1_secontext, "!!"))
742536
+		reset_secontext_file(sample_1);
742536
+
742536
 	free(sample_1_secontext);
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
diff --git a/tests-m32/secontext.c b/tests-m32/secontext.c
742536
index ba271c8..94fadd4 100644
742536
--- a/tests-m32/secontext.c
742536
+++ b/tests-m32/secontext.c
742536
@@ -235,6 +235,13 @@ secontext_short_pid(pid_t pid)
742536
 	return FORMAT_SPACE_AFTER(raw_secontext_short_pid(pid));
742536
 }
742536
 
742536
+void reset_secontext_file(const char *file)
742536
+{
742536
+	char *proper_ctx = raw_expected_secontext_full_file(file);
742536
+	(void) setfilecon(file, proper_ctx);
742536
+	free(proper_ctx);
742536
+}
742536
+
742536
 void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
diff --git a/tests-m32/secontext.h b/tests-m32/secontext.h
742536
index e5571d5..387263e 100644
742536
--- a/tests-m32/secontext.h
742536
+++ b/tests-m32/secontext.h
742536
@@ -32,6 +32,8 @@ char *get_secontext_field(const char *full_context, enum secontext_field field);
742536
 
742536
 char *get_secontext_field_file(const char *file, enum secontext_field field);
742536
 
742536
+void reset_secontext_file(const char *file);
742536
+
742536
 void update_secontext_field(const char *file, enum secontext_field field,
742536
 			    const char *newvalue);
742536
 
742536
@@ -69,6 +71,11 @@ get_secontext_field_file(const char *file, enum secontext_field field)
742536
 }
742536
 
742536
 static inline void
742536
+reset_secontext_file(const char *file)
742536
+{
742536
+}
742536
+
742536
+static inline void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
 {
742536
diff --git a/tests-mx32/linkat.c b/tests-mx32/linkat.c
742536
index decb736..781b85a 100644
742536
--- a/tests-mx32/linkat.c
742536
+++ b/tests-mx32/linkat.c
742536
@@ -103,6 +103,9 @@ main(void)
742536
 	if (close(fd_sample_2))
742536
 		perror_msg_and_fail("close");
742536
 
742536
+	if (*sample_1_secontext && strstr(sample_1_secontext, "!!"))
742536
+		reset_secontext_file(sample_1);
742536
+
742536
 	free(sample_1_secontext);
742536
 
742536
 #ifdef PRINT_SECONTEXT_MISMATCH
742536
diff --git a/tests-mx32/secontext.c b/tests-mx32/secontext.c
742536
index ba271c8..94fadd4 100644
742536
--- a/tests-mx32/secontext.c
742536
+++ b/tests-mx32/secontext.c
742536
@@ -235,6 +235,13 @@ secontext_short_pid(pid_t pid)
742536
 	return FORMAT_SPACE_AFTER(raw_secontext_short_pid(pid));
742536
 }
742536
 
742536
+void reset_secontext_file(const char *file)
742536
+{
742536
+	char *proper_ctx = raw_expected_secontext_full_file(file);
742536
+	(void) setfilecon(file, proper_ctx);
742536
+	free(proper_ctx);
742536
+}
742536
+
742536
 void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
diff --git a/tests-mx32/secontext.h b/tests-mx32/secontext.h
742536
index e5571d5..387263e 100644
742536
--- a/tests-mx32/secontext.h
742536
+++ b/tests-mx32/secontext.h
742536
@@ -32,6 +32,8 @@ char *get_secontext_field(const char *full_context, enum secontext_field field);
742536
 
742536
 char *get_secontext_field_file(const char *file, enum secontext_field field);
742536
 
742536
+void reset_secontext_file(const char *file);
742536
+
742536
 void update_secontext_field(const char *file, enum secontext_field field,
742536
 			    const char *newvalue);
742536
 
742536
@@ -69,6 +71,11 @@ get_secontext_field_file(const char *file, enum secontext_field field)
742536
 }
742536
 
742536
 static inline void
742536
+reset_secontext_file(const char *file)
742536
+{
742536
+}
742536
+
742536
+static inline void
742536
 update_secontext_field(const char *file, enum secontext_field field,
742536
 		       const char *newvalue)
742536
 {
742536
-- 
742536
2.1.4
742536