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