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

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