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

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