Kamil Dudka baf644
From d70ddb3eb845c494280e7365e2b889242e7e1bb9 Mon Sep 17 00:00:00 2001
Kamil Dudka baf644
From: rpm-build <rpm-build>
Kamil Dudka baf644
Date: Mon, 4 Oct 2021 08:45:53 +0200
Kamil Dudka baf644
Subject: [PATCH] coreutils-selinux.patch
Kamil Dudka baf644
Kamil Dudka baf644
---
Kamil Dudka 9d8502
 src/cp.c      | 19 ++++++++++++++++++-
Kamil Dudka 9d8502
 src/install.c | 12 +++++++++++-
Kamil Dudka 9d8502
 2 files changed, 29 insertions(+), 2 deletions(-)
Kamil Dudka baf644
Kamil Dudka 8d9eac
diff --git a/src/cp.c b/src/cp.c
Kamil Dudka baf644
index c97a675..89fb8ec 100644
Kamil Dudka 8d9eac
--- a/src/cp.c
Kamil Dudka 8d9eac
+++ b/src/cp.c
Kamil Dudka 9d8502
@@ -952,7 +952,7 @@ main (int argc, char **argv)
Kamil Dudka 8d9eac
   selinux_enabled = (0 < is_selinux_enabled ());
Kamil Dudka 8d9eac
   cp_option_init (&x);
Ondrej Vasik 66a4fe
 
Ondřej Vašík bb33bc
-  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
Ondřej Vašík bb33bc
+  while ((c = getopt_long (argc, argv, "abcdfHilLnprst:uvxPRS:TZ",
Ondrej Vasik 66a4fe
                            long_opts, NULL))
Ondrej Vasik 66a4fe
          != -1)
Ondrej Vasik 66a4fe
     {
Kamil Dudka 9d8502
@@ -1000,6 +1000,23 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
           copy_contents = true;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+        case 'c':
Kamil Dudka 9d8502
+          fprintf (stderr, "%s: warning: option '-c' is deprecated,"
Kamil Dudka 9d8502
+                  " please use '--preserve=context' instead\n", argv[0]);
Kamil Dudka 9d8502
+          if (x.set_security_context)
Kamil Dudka 9d8502
+            {
Kamil Dudka 9d8502
+              fprintf (stderr,
Kamil Dudka 9d8502
+                      "%s: cannot force target context and preserve it\n",
Kamil Dudka 9d8502
+                      argv[0]);
Kamil Dudka 9d8502
+              exit (1);
Kamil Dudka 9d8502
+            }
Kamil Dudka 9d8502
+          else if (selinux_enabled)
Kamil Dudka 9d8502
+            {
Ondrej Vasik 66a4fe
+              x.preserve_security_context = true;
Ondrej Vasik 66a4fe
+              x.require_preserve_context = true;
Kamil Dudka 9d8502
+            }
Ondrej Vasik 66a4fe
+          break;
Kamil Dudka 9d8502
+
Ondrej Vasik 66a4fe
         case 'd':
Ondrej Vasik 66a4fe
           x.preserve_links = true;
Ondrej Vasik 66a4fe
           x.dereference = DEREF_NEVER;
Kamil Dudka 8d9eac
diff --git a/src/install.c b/src/install.c
Kamil Dudka baf644
index c9456fe..2b1bee9 100644
Kamil Dudka 8d9eac
--- a/src/install.c
Kamil Dudka 8d9eac
+++ b/src/install.c
Kamil Dudka 9d8502
@@ -794,7 +794,7 @@ main (int argc, char **argv)
Kamil Dudka 8d9eac
   dir_arg = false;
Kamil Dudka 8d9eac
   umask (0);
Ondrej Vasik 66a4fe
 
Ondřej Vašík bb33bc
-  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z", long_options,
Ondřej Vašík bb33bc
+  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pPt:TvS:Z", long_options,
Ondrej Vasik 66a4fe
                               NULL)) != -1)
Ondrej Vasik 66a4fe
     {
Ondrej Vasik 66a4fe
       switch (optc)
Kamil Dudka 9d8502
@@ -855,6 +855,9 @@ main (int argc, char **argv)
Ondřej Vašík 50a3ba
           no_target_directory = true;
Ondřej Vašík 50a3ba
           break;
Ondřej Vašík 50a3ba
 
Ondrej Vasik 66a4fe
+        case 'P':
Kamil Dudka 9d8502
+          fprintf (stderr, "%s: warning: option '-P' is deprecated,"
Kamil Dudka 9d8502
+                  " please use '--preserve-context' instead\n", argv[0]);
Ondrej Vasik 66a4fe
         case PRESERVE_CONTEXT_OPTION:
Ondřej Vašík bb33bc
           if (! selinux_enabled)
Ondrej Vasik 66a4fe
             {
Kamil Dudka 9d8502
@@ -862,6 +865,13 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
                              "this kernel is not SELinux-enabled"));
Ondrej Vasik 66a4fe
               break;
Ondrej Vasik 66a4fe
             }
Kamil Dudka 9d8502
+          if (x.set_security_context)
Kamil Dudka 9d8502
+            {
Kamil Dudka 9d8502
+              fprintf (stderr,
Kamil Dudka 9d8502
+                      "%s: cannot force target context and preserve it\n",
Kamil Dudka 9d8502
+                      argv[0]);
Kamil Dudka 9d8502
+              exit (1);
Kamil Dudka 9d8502
+            }
Ondrej Vasik 66a4fe
           x.preserve_security_context = true;
Ondrej Vasik 66a4fe
           use_default_selinux_context = false;
Ondrej Vasik 66a4fe
           break;
Kamil Dudka baf644
-- 
Kamil Dudka baf644
2.31.1
Kamil Dudka baf644