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