Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/configure.ac coreutils-8.1/configure.ac
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/configure.ac	2009-11-20 13:11:20.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/configure.ac	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik c77f9b
@@ -133,6 +133,13 @@ AC_ARG_ENABLE(pam, dnl
Ondrej Vasik 0363d6
 LIB_PAM="-ldl -lpam -lpam_misc"
Ondrej Vasik 0363d6
 AC_SUBST(LIB_PAM)])
Ondrej Vasik 0363d6
 
Ondrej Vasik 0363d6
+dnl Give the chance to enable SELINUX
Ondrej Vasik 0363d6
+AC_ARG_ENABLE(selinux, dnl
Ondrej Vasik 0363d6
+[  --enable-selinux              Enable use of the SELINUX libraries],
Ondrej Vasik 0363d6
+[AC_DEFINE(WITH_SELINUX, 1, [Define if you want to use SELINUX])
Ondrej Vasik 0363d6
+LIB_SELINUX="-lselinux"
Ondrej Vasik 0363d6
+AC_SUBST(LIB_SELINUX)])
Ondrej Vasik 0363d6
+
Ondrej Vasik 0363d6
 AC_FUNC_FORK
Ondrej Vasik 0363d6
 
Ondrej Vasik 0363d6
 optional_bin_progs=
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/man/chcon.x coreutils-8.1/man/chcon.x
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/man/chcon.x	2009-09-01 13:01:16.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/man/chcon.x	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 893c38
@@ -1,4 +1,4 @@
Ondrej Vasik 893c38
 [NAME]
Ondrej Vasik 0363d6
-chcon \- change file security context
Ondrej Vasik 0363d6
+chcon \- change file SELinux security context
Ondrej Vasik 893c38
 [DESCRIPTION]
Ondrej Vasik 0363d6
 .\" Add any additional description here
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/man/runcon.x coreutils-8.1/man/runcon.x
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/man/runcon.x	2009-09-01 13:01:16.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/man/runcon.x	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 893c38
@@ -1,5 +1,5 @@
Ondrej Vasik 893c38
 [NAME]
Ondrej Vasik 893c38
-runcon \- run command with specified security context
Ondrej Vasik 893c38
+runcon \- run command with specified SELinux security context
Ondrej Vasik 893c38
 [DESCRIPTION]
Ondrej Vasik 893c38
 Run COMMAND with completely-specified CONTEXT, or with current or
Ondrej Vasik 893c38
 transitioned security context modified by one or more of LEVEL,
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/copy.c coreutils-8.1/src/copy.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/copy.c	2009-10-22 11:18:05.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/copy.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik c77f9b
@@ -1935,6 +1935,8 @@ copy_internal (char const *src_name, cha
Ondrej Vasik 250517
         {
Ondrej Vasik 250517
           /* Here, we are crossing a file system boundary and cp's -x option
Ondrej Vasik 250517
              is in effect: so don't copy the contents of this directory. */
Ondrej Vasik 0363d6
+        if (x->preserve_security_context)
Ondrej Vasik 250517
+           restore_default_fscreatecon_or_die ();
Ondrej Vasik 250517
         }
Ondrej Vasik 0363d6
       else
Ondrej Vasik 250517
         {
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/copy.h coreutils-8.1/src/copy.h
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/copy.h	2009-09-21 14:29:33.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/copy.h	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -158,6 +158,9 @@ struct cp_options
Ondrej Vasik 66a4fe
   bool preserve_mode;
Ondrej Vasik 66a4fe
   bool preserve_timestamps;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+  /* If true, attempt to set specified security context */
Ondrej Vasik 66a4fe
+  bool set_security_context;
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
   /* Enabled for mv, and for cp by the --preserve=links option.
Ondrej Vasik 66a4fe
      If true, attempt to preserve in the destination files any
Ondrej Vasik 66a4fe
      logical hard links between the source files.  If used with cp's
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/cp.c coreutils-8.1/src/cp.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/cp.c	2009-09-29 15:27:54.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/cp.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -139,6 +139,7 @@ static struct option const long_opts[] =
Ondrej Vasik 66a4fe
   {"target-directory", required_argument, NULL, 't'},
Ondrej Vasik 66a4fe
   {"update", no_argument, NULL, 'u'},
Ondrej Vasik 66a4fe
   {"verbose", no_argument, NULL, 'v'},
Ondrej Vasik 66a4fe
+  {"context", required_argument, NULL, 'Z'},
Ondrej Vasik 66a4fe
   {GETOPT_HELP_OPTION_DECL},
Ondrej Vasik 66a4fe
   {GETOPT_VERSION_OPTION_DECL},
Ondrej Vasik 66a4fe
   {NULL, 0, NULL, 0}
Ondrej Vasik 66a4fe
@@ -197,6 +198,9 @@ Mandatory arguments to long options are 
Ondrej Vasik 66a4fe
                                  all\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
       fputs (_("\
Ondrej Vasik 66a4fe
+  -c                           same as --preserve=context\n\
Ondrej Vasik 66a4fe
+"), stdout);
Ondrej Vasik 66a4fe
+      fputs (_("\
Ondrej Vasik 66a4fe
       --no-preserve=ATTR_LIST  don't preserve the specified attributes\n\
Ondrej Vasik 66a4fe
       --parents                use full source file name under DIRECTORY\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
@@ -223,6 +227,7 @@ Mandatory arguments to long options are 
Ondrej Vasik 66a4fe
                                  destination file is missing\n\
Ondrej Vasik 66a4fe
   -v, --verbose                explain what is being done\n\
Ondrej Vasik 66a4fe
   -x, --one-file-system        stay on this file system\n\
Ondrej Vasik 66a4fe
+  -Z, --context=CONTEXT        set security context of copy to CONTEXT\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
       fputs (HELP_OPTION_DESCRIPTION, stdout);
Ondrej Vasik 66a4fe
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
Ondrej Vasik 66a4fe
@@ -777,6 +782,7 @@ cp_option_init (struct cp_options *x)
Ondrej Vasik 66a4fe
   x->preserve_timestamps = false;
Ondrej Vasik 66a4fe
   x->preserve_security_context = false;
Ondrej Vasik 66a4fe
   x->require_preserve_context = false;
Ondrej Vasik 66a4fe
+  x->set_security_context = false;
Ondrej Vasik 66a4fe
   x->preserve_xattr = false;
Ondrej Vasik 66a4fe
   x->reduce_diagnostics = false;
Ondrej Vasik 66a4fe
   x->require_preserve_xattr = false;
Ondrej Vasik 66a4fe
@@ -923,7 +929,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
      we'll actually use backup_suffix_string.  */
Ondrej Vasik 66a4fe
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:T",
Ondrej Vasik 66a4fe
+  while ((c = getopt_long (argc, argv, "abcdfHilLnprst:uvxPRS:TZ:",
Ondrej Vasik 66a4fe
                            long_opts, NULL))
Ondrej Vasik 66a4fe
          != -1)
Ondrej Vasik 66a4fe
     {
Ondrej Vasik 66a4fe
@@ -966,6 +972,16 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
           copy_contents = true;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+        case 'c':
Ondrej Vasik 66a4fe
+          if ( x.set_security_context ) { 
Ondrej Vasik 66a4fe
+              (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
Ondrej Vasik 66a4fe
+             exit( 1 );
Ondrej Vasik 66a4fe
+           }
Ondrej Vasik 66a4fe
+           else if (selinux_enabled) {
Ondrej Vasik 66a4fe
+              x.preserve_security_context = true;
Ondrej Vasik 66a4fe
+              x.require_preserve_context = true;
Ondrej Vasik 66a4fe
+           }
Ondrej Vasik 66a4fe
+          break;
Ondrej Vasik 66a4fe
         case 'd':
Ondrej Vasik 66a4fe
           x.preserve_links = true;
Ondrej Vasik 66a4fe
           x.dereference = DEREF_NEVER;
Ondrej Vasik 66a4fe
@@ -1075,6 +1091,27 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
           x.one_file_system = true;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
 
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+        case 'Z':
Ondrej Vasik 66a4fe
+          /* politely decline if we're not on a selinux-enabled kernel. */
Ondrej Vasik 66a4fe
+          if( !selinux_enabled ) {
Ondrej Vasik 66a4fe
+             fprintf( stderr, "Warning:  ignoring --context (-Z). "
Ondrej Vasik 66a4fe
+                              "It requires a SELinux enabled kernel.\n" );
Ondrej Vasik 66a4fe
+             break;
Ondrej Vasik 66a4fe
+         }
Ondrej Vasik 66a4fe
+         if ( x.preserve_security_context ) {
Ondrej Vasik 66a4fe
+            (void) fprintf(stderr, "%s: cannot force target context to '%s' and preserve it\n", argv[0], optarg);
Ondrej Vasik 66a4fe
+            exit( 1 );
Ondrej Vasik 66a4fe
+         }
Ondrej Vasik 66a4fe
+         x.set_security_context = true;
Ondrej Vasik 66a4fe
+         /* if there's a security_context given set new path 
Ondrej Vasik 66a4fe
+            components to that context, too */
Ondrej Vasik 66a4fe
+         if ( setfscreatecon(optarg) < 0 ) {
Ondrej Vasik 66a4fe
+            (void) fprintf(stderr, _("cannot set default security context %s\n"), optarg);
Ondrej Vasik 66a4fe
+            exit( 1 );
Ondrej Vasik 66a4fe
+         }
Ondrej Vasik 66a4fe
+         break;
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
         case 'S':
Ondrej Vasik 66a4fe
           make_backups = true;
Ondrej Vasik 66a4fe
           backup_suffix_string = optarg;
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/chcon.c coreutils-8.1/src/chcon.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/chcon.c	2009-11-07 08:46:30.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/chcon.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik c77f9b
@@ -356,7 +356,7 @@ Usage: %s [OPTION]... CONTEXT FILE...\n\
Ondrej Vasik 66a4fe
 "),
Ondrej Vasik 66a4fe
         program_name, program_name, program_name);
Ondrej Vasik 66a4fe
       fputs (_("\
Ondrej Vasik 66a4fe
-Change the security context of each FILE to CONTEXT.\n\
Ondrej Vasik 66a4fe
+Change the SELinux security context of each FILE to CONTEXT.\n\
Ondrej Vasik 66a4fe
 With --reference, change the security context of each FILE to that of RFILE.\n\
Ondrej Vasik 66a4fe
 \n\
Ondrej Vasik 66a4fe
   -h, --no-dereference   affect symbolic links instead of any referenced file\n\
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/id.c coreutils-8.1/src/id.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/id.c	2009-11-13 15:56:41.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/id.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -107,7 +107,7 @@ int
Ondrej Vasik 66a4fe
 main (int argc, char **argv)
Ondrej Vasik 0363d6
 {
Ondrej Vasik 66a4fe
   int optc;
Ondrej Vasik 66a4fe
-  int selinux_enabled = (is_selinux_enabled () > 0);
Ondrej Vasik 66a4fe
+  bool selinux_enabled = (is_selinux_enabled () > 0);
Tim Waugh 5505e2
 
Ondrej Vasik 66a4fe
   /* If true, output the list of all group IDs. -G */
Ondrej Vasik 66a4fe
   bool just_group_list = false;
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/install.c coreutils-8.1/src/install.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/install.c	2009-09-29 15:27:54.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/install.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -284,6 +284,7 @@ cp_option_init (struct cp_options *x)
Ondrej Vasik 66a4fe
   x->reduce_diagnostics=false;
Ondrej Vasik 66a4fe
   x->require_preserve = false;
Ondrej Vasik 66a4fe
   x->require_preserve_context = false;
Ondrej Vasik 66a4fe
+  x->set_security_context = false;
Ondrej Vasik 66a4fe
   x->require_preserve_xattr = false;
Ondrej Vasik 66a4fe
   x->recursive = false;
Ondrej Vasik 66a4fe
   x->sparse_mode = SPARSE_AUTO;
Ondrej Vasik 66a4fe
@@ -461,7 +462,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
      we'll actually use backup_suffix_string.  */
Ondrej Vasik 66a4fe
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z:", long_options,
Ondrej Vasik 66a4fe
+  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)
Ondrej Vasik 66a4fe
@@ -535,6 +536,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
           error (0, 0, _("WARNING: --preserve_context is deprecated; "
Ondrej Vasik 66a4fe
                          "use --preserve-context instead"));
Ondrej Vasik 66a4fe
           /* fall through */
Ondrej Vasik 66a4fe
+        case 'P':
Ondrej Vasik 66a4fe
         case PRESERVE_CONTEXT_OPTION:
Ondrej Vasik 66a4fe
           if ( ! selinux_enabled)
Ondrej Vasik 66a4fe
             {
Ondrej Vasik 66a4fe
@@ -542,6 +544,10 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
                              "this kernel is not SELinux-enabled"));
Ondrej Vasik 66a4fe
               break;
Ondrej Vasik 66a4fe
             }
Ondrej Vasik 66a4fe
+          if ( x.set_security_context ) {
Ondrej Vasik 66a4fe
+             (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
Ondrej Vasik 66a4fe
+             exit( 1 );
Ondrej Vasik 66a4fe
+          }
Ondrej Vasik 66a4fe
           x.preserve_security_context = true;
Ondrej Vasik 66a4fe
           use_default_selinux_context = false;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
@@ -553,6 +559,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
               break;
Ondrej Vasik 66a4fe
             }
Ondrej Vasik 66a4fe
           scontext = optarg;
Ondrej Vasik 66a4fe
+          x.set_security_context = true;
Ondrej Vasik 66a4fe
           use_default_selinux_context = false;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
         case_GETOPT_HELP_CHAR;
Ondrej Vasik 66a4fe
@@ -986,8 +993,8 @@ Mandatory arguments to long options are 
Ondrej Vasik 66a4fe
   -v, --verbose       print the name of each directory as it is created\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
       fputs (_("\
Ondrej Vasik 66a4fe
-      --preserve-context  preserve SELinux security context\n\
Ondrej Vasik 66a4fe
-  -Z, --context=CONTEXT  set SELinux security context of files and directories\n\
Ondrej Vasik 66a4fe
+  -P, --preserve-context (SELinux) preserve security context\n\
Ondrej Vasik 66a4fe
+  -Z, --context=CONTEXT  (SELinux) set security context of files and directories\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
       fputs (HELP_OPTION_DESCRIPTION, stdout);
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/ls.c coreutils-8.1/src/ls.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/ls.c	2009-11-20 13:11:20.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/ls.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -162,7 +162,8 @@ enum filetype
Ondrej Vasik 66a4fe
     symbolic_link,
Ondrej Vasik 66a4fe
     sock,
Ondrej Vasik 66a4fe
     whiteout,
Ondrej Vasik 66a4fe
-    arg_directory
Ondrej Vasik 66a4fe
+    arg_directory,
Ondrej Vasik 66a4fe
+    command_line
Ondrej Vasik 66a4fe
   };
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 /* Display letters and indicators for each filetype.
Ondrej Vasik 66a4fe
@@ -279,6 +280,7 @@ static void queue_directory (char const 
Ondrej Vasik 66a4fe
 static void sort_files (void);
Ondrej Vasik 66a4fe
 static void parse_ls_color (void);
Ondrej Vasik 66a4fe
 void usage (int status);
Ondrej Vasik 66a4fe
+static void print_scontext_format (const struct fileinfo *f);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 /* Initial size of hash table.
Ondrej Vasik 66a4fe
    Most hierarchies are likely to be shallower than this.  */
Ondrej Vasik 66a4fe
@@ -348,7 +350,7 @@ static struct pending *pending_dirs;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 static struct timespec current_time;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-static bool print_scontext;
Ondrej Vasik 66a4fe
+static int print_scontext = 0;
Ondrej Vasik 66a4fe
 static char UNKNOWN_SECURITY_CONTEXT[] = "?";
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 /* Whether any of the files has an ACL.  This affects the width of the
Ondrej Vasik 66a4fe
@@ -388,7 +390,9 @@ enum format
Ondrej Vasik 66a4fe
     one_per_line,		/* -1 */
Ondrej Vasik 66a4fe
     many_per_line,		/* -C */
Ondrej Vasik 66a4fe
     horizontal,			/* -x */
Ondrej Vasik 66a4fe
-    with_commas			/* -m */
Ondrej Vasik 66a4fe
+    with_commas,			/* -m */
Ondrej Vasik 66a4fe
+    security_format, /* -Z */
Ondrej Vasik 66a4fe
+    invalid_format
Ondrej Vasik 66a4fe
   };
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 static enum format format;
Ondrej Vasik 66a4fe
@@ -790,6 +794,9 @@ enum
Ondrej Vasik 66a4fe
   SHOW_CONTROL_CHARS_OPTION,
Ondrej Vasik 66a4fe
   SI_OPTION,
Ondrej Vasik 66a4fe
   SORT_OPTION,
Ondrej Vasik 66a4fe
+  CONTEXT_OPTION,
Ondrej Vasik 66a4fe
+  LCONTEXT_OPTION,
Ondrej Vasik 66a4fe
+  SCONTEXT_OPTION,
Ondrej Vasik 66a4fe
   TIME_OPTION,
Ondrej Vasik 66a4fe
   TIME_STYLE_OPTION
Ondrej Vasik 66a4fe
 };
Ondrej Vasik 66a4fe
@@ -835,7 +842,9 @@ static struct option const long_options[
Ondrej Vasik 66a4fe
   {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
Ondrej Vasik 66a4fe
   {"color", optional_argument, NULL, COLOR_OPTION},
Ondrej Vasik 66a4fe
   {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
Ondrej Vasik 66a4fe
-  {"context", no_argument, 0, 'Z'},
Ondrej Vasik 66a4fe
+  {"context", no_argument, 0, CONTEXT_OPTION},
Ondrej Vasik 66a4fe
+  {"lcontext", no_argument, 0, LCONTEXT_OPTION},
Ondrej Vasik 66a4fe
+  {"scontext", no_argument, 0, SCONTEXT_OPTION},
Ondrej Vasik 66a4fe
   {"author", no_argument, NULL, AUTHOR_OPTION},
Ondrej Vasik 0363d6
   {GETOPT_HELP_OPTION_DECL},
Ondrej Vasik 0363d6
   {GETOPT_VERSION_OPTION_DECL},
Ondrej Vasik 66a4fe
@@ -845,12 +854,12 @@ static struct option const long_options[
Ondrej Vasik 66a4fe
 static char const *const format_args[] =
Ondrej Vasik 66a4fe
 {
Ondrej Vasik 66a4fe
   "verbose", "long", "commas", "horizontal", "across",
Ondrej Vasik 66a4fe
-  "vertical", "single-column", NULL
Ondrej Vasik 66a4fe
+  "vertical", "single-column", "context", NULL
Ondrej Vasik 66a4fe
 };
Ondrej Vasik 66a4fe
 static enum format const format_types[] =
Ondrej Vasik 66a4fe
 {
Ondrej Vasik 66a4fe
   long_format, long_format, with_commas, horizontal, horizontal,
Ondrej Vasik 66a4fe
-  many_per_line, one_per_line
Ondrej Vasik 66a4fe
+  many_per_line, one_per_line, security_format
Ondrej Vasik 66a4fe
 };
Ondrej Vasik 66a4fe
 ARGMATCH_VERIFY (format_args, format_types);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
@@ -1281,7 +1290,8 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
       /* Avoid following symbolic links when possible.  */
Ondrej Vasik 66a4fe
       if (is_colored (C_ORPHAN)
Ondrej Vasik 66a4fe
           || (is_colored (C_EXEC) && color_symlink_as_referent)
Ondrej Vasik 66a4fe
-          || (is_colored (C_MISSING) && format == long_format))
Ondrej Vasik 66a4fe
+          || (is_colored (C_MISSING) && (format == long_format
Ondrej Vasik 66a4fe
+              || format == security_format)))
Ondrej Vasik 66a4fe
         check_symlink_color = true;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
       /* If the standard output is a controlling terminal, watch out
Ondrej Vasik 66a4fe
@@ -1328,7 +1338,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
   if (dereference == DEREF_UNDEFINED)
Ondrej Vasik 66a4fe
     dereference = ((immediate_dirs
Ondrej Vasik 66a4fe
                     || indicator_style == classify
Ondrej Vasik 66a4fe
-                    || format == long_format)
Ondrej Vasik 66a4fe
+                    || format == long_format || format == security_format)
Ondrej Vasik 66a4fe
                    ? DEREF_NEVER
Ondrej Vasik 66a4fe
                    : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
@@ -1348,7 +1358,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
   format_needs_stat = sort_type == sort_time || sort_type == sort_size
Ondrej Vasik 66a4fe
     || format == long_format
Ondrej Vasik 66a4fe
-    || print_scontext
Ondrej Vasik 66a4fe
+    || format == security_format || print_scontext
Ondrej Vasik 66a4fe
     || print_block_size;
Ondrej Vasik 66a4fe
   format_needs_type = (! format_needs_stat
Ondrej Vasik 66a4fe
                        && (recursive
Ondrej Vasik 66a4fe
@@ -1379,7 +1389,7 @@ main (int argc, char **argv)
Ondrej Vasik 66a4fe
     }
Ondrej Vasik 66a4fe
   else
Ondrej Vasik 66a4fe
     do
Ondrej Vasik 66a4fe
-      gobble_file (argv[i++], unknown, NOT_AN_INODE_NUMBER, true, "");
Ondrej Vasik 66a4fe
+      gobble_file (argv[i++], command_line, NOT_AN_INODE_NUMBER, true, "");
Ondrej Vasik 66a4fe
     while (i < argc);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
   if (cwd_n_used)
Ondrej Vasik 66a4fe
@@ -1542,7 +1552,7 @@ decode_switches (int argc, char **argv)
Ondrej Vasik 66a4fe
   ignore_mode = IGNORE_DEFAULT;
Ondrej Vasik 66a4fe
   ignore_patterns = NULL;
Ondrej Vasik 66a4fe
   hide_patterns = NULL;
Ondrej Vasik 66a4fe
-  print_scontext = false;
Ondrej Vasik 66a4fe
+  print_scontext = 0;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
   /* FIXME: put this in a function.  */
Ondrej Vasik 66a4fe
   {
Ondrej Vasik 66a4fe
@@ -1924,13 +1934,27 @@ decode_switches (int argc, char **argv)
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
         case 'Z':
Ondrej Vasik 66a4fe
-          print_scontext = true;
Ondrej Vasik 66a4fe
+          print_scontext = 1;
Ondrej Vasik 66a4fe
+    format = security_format;
Ondrej Vasik 66a4fe
           break;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
         case_GETOPT_HELP_CHAR;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+  case CONTEXT_OPTION: /* default security context format */
Ondrej Vasik 66a4fe
+                print_scontext = 1;
Ondrej Vasik 66a4fe
+                format = security_format;
Ondrej Vasik 66a4fe
+                break;
Ondrej Vasik 66a4fe
+        case LCONTEXT_OPTION: /* long format plus security context */
Ondrej Vasik 66a4fe
+                print_scontext = 1;
Ondrej Vasik 66a4fe
+                format = long_format;
Ondrej Vasik 66a4fe
+                break;
Ondrej Vasik 66a4fe
+        case SCONTEXT_OPTION: /* short form of new security format */
Ondrej Vasik 66a4fe
+                print_scontext = 0;
Ondrej Vasik 66a4fe
+                format = security_format;
Ondrej Vasik 66a4fe
+                break;
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
         default:
Ondrej Vasik 66a4fe
           usage (LS_FAILURE);
Ondrej Vasik 66a4fe
         }
Ondrej Vasik c77f9b
@@ -2682,8 +2706,10 @@ clear_files (void)
Ondrej Vasik 66a4fe
       struct fileinfo *f = sorted_file[i];
Ondrej Vasik 66a4fe
       free (f->name);
Ondrej Vasik 66a4fe
       free (f->linkname);
Ondrej Vasik 66a4fe
-      if (f->scontext != UNKNOWN_SECURITY_CONTEXT)
Ondrej Vasik 66a4fe
-        freecon (f->scontext);
Ondrej Vasik 66a4fe
+      if (f->scontext != UNKNOWN_SECURITY_CONTEXT) {
Ondrej Vasik 66a4fe
+               freecon (f->scontext);
Ondrej Vasik 66a4fe
+        f->scontext = NULL;
Ondrej Vasik 66a4fe
+      }
Ondrej Vasik 66a4fe
     }
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
   cwd_n_used = 0;
Ondrej Vasik c77f9b
@@ -2725,6 +2751,7 @@ gobble_file (char const *name, enum file
Ondrej Vasik 66a4fe
   memset (f, '\0', sizeof *f);
Ondrej Vasik 66a4fe
   f->stat.st_ino = inode;
Ondrej Vasik 66a4fe
   f->filetype = type;
Ondrej Vasik 66a4fe
+  f->scontext = NULL;
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
   if (command_line_arg
Ondrej Vasik 66a4fe
       || format_needs_stat
Ondrej Vasik c77f9b
@@ -2834,7 +2861,7 @@ gobble_file (char const *name, enum file
Ondrej Vasik c77f9b
           && print_with_color && is_colored (C_CAP))
Ondrej Vasik c77f9b
         f->has_capability = has_capability (absolute_name);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-      if (format == long_format || print_scontext)
Ondrej Vasik 66a4fe
+      if (format == long_format || format == security_format || print_scontext)
Ondrej Vasik 66a4fe
         {
Ondrej Vasik 66a4fe
           bool have_selinux = false;
Ondrej Vasik 66a4fe
           bool have_acl = false;
Ondrej Vasik c77f9b
@@ -2857,7 +2884,7 @@ gobble_file (char const *name, enum file
Ondrej Vasik 66a4fe
                 err = 0;
Ondrej Vasik 66a4fe
             }
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-          if (err == 0 && format == long_format)
Ondrej Vasik 66a4fe
+          if (err == 0 && (format == long_format || format == security_format))
Ondrej Vasik 66a4fe
             {
Ondrej Vasik 66a4fe
               int n = file_has_acl (absolute_name, &f->stat);
Ondrej Vasik 66a4fe
               err = (n < 0);
Ondrej Vasik c77f9b
@@ -2876,7 +2903,8 @@ gobble_file (char const *name, enum file
Ondrej Vasik 66a4fe
         }
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
       if (S_ISLNK (f->stat.st_mode)
Ondrej Vasik 66a4fe
-          && (format == long_format || check_symlink_color))
Ondrej Vasik 66a4fe
+          && (format == long_format || format == security_format
Ondrej Vasik 66a4fe
+              || check_symlink_color))
Ondrej Vasik 66a4fe
         {
Ondrej Vasik 66a4fe
           char *linkname;
Ondrej Vasik 66a4fe
           struct stat linkstats;
Ondrej Vasik c77f9b
@@ -2896,6 +2924,7 @@ gobble_file (char const *name, enum file
Ondrej Vasik 66a4fe
                  command line are automatically traced if not being
Ondrej Vasik 66a4fe
                  listed as files.  */
Ondrej Vasik 66a4fe
               if (!command_line_arg || format == long_format
Ondrej Vasik 66a4fe
+                  || format == security_format
Ondrej Vasik 66a4fe
                   || !S_ISDIR (linkstats.st_mode))
Ondrej Vasik 66a4fe
                 {
Ondrej Vasik 66a4fe
                   /* Get the linked-to file's mode for the filetype indicator
Ondrej Vasik c77f9b
@@ -2935,7 +2964,7 @@ gobble_file (char const *name, enum file
Ondrej Vasik 66a4fe
             block_size_width = len;
Ondrej Vasik 66a4fe
         }
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-      if (format == long_format)
Ondrej Vasik 66a4fe
+      if (format == long_format || format == security_format)
Ondrej Vasik 66a4fe
         {
Ondrej Vasik 66a4fe
           if (print_owner)
Ondrej Vasik 66a4fe
             {
Ondrej Vasik c77f9b
@@ -3436,6 +3465,13 @@ print_current_files (void)
Ondrej Vasik 66a4fe
           print_long_format (sorted_file[i]);
Ondrej Vasik 66a4fe
           DIRED_PUTCHAR ('\n');
Ondrej Vasik 66a4fe
         }
Ondrej Vasik 66a4fe
+     break;
Ondrej Vasik 66a4fe
+    case security_format:
Ondrej Vasik 66a4fe
+      for (i = 0; i < cwd_n_used; i++)
Ondrej Vasik 66a4fe
+      {
Ondrej Vasik 66a4fe
+        print_scontext_format (sorted_file[i]);
Ondrej Vasik 66a4fe
+        DIRED_PUTCHAR ('\n');
Ondrej Vasik 66a4fe
+      }
Ondrej Vasik 66a4fe
       break;
Ondrej Vasik 66a4fe
     }
Ondrej Vasik 66a4fe
 }
Ondrej Vasik c77f9b
@@ -3598,6 +3634,67 @@ format_inode (char *buf, size_t buflen, 
Ondrej Vasik 66a4fe
           : (char *) "?");
Ondrej Vasik 66a4fe
 }
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+/* Print info about f in scontext format */
Ondrej Vasik f8d3fd
+static void
Ondrej Vasik 66a4fe
+print_scontext_format (const struct fileinfo *f)
Ondrej Vasik f8d3fd
+{
Ondrej Vasik 66a4fe
+  char modebuf[12];
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  /* 7 fields that may require LONGEST_HUMAN_READABLE bytes,
Ondrej Vasik 66a4fe
+     1 10-byte mode string,
Ondrej Vasik 66a4fe
+     9 spaces, one following each of these fields, and
Ondrej Vasik 66a4fe
+     1 trailing NUL byte.  */
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  char init_bigbuf[7 * LONGEST_HUMAN_READABLE + 10  + 9 + 1];
Ondrej Vasik 66a4fe
+  char *buf = init_bigbuf;
Ondrej Vasik 66a4fe
+  char *p;
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  p = buf;
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  if ( print_scontext ) { /* zero means terse listing */
Ondrej Vasik 66a4fe
+    filemodestring (&f->stat, modebuf);
Ondrej Vasik 66a4fe
+    if (! any_has_acl)
Ondrej Vasik 66a4fe
+      modebuf[10] = '\0';
Ondrej Vasik 66a4fe
+    else if (f->acl_type == ACL_T_SELINUX_ONLY)
Ondrej Vasik 66a4fe
+      modebuf[10] = '.';
Ondrej Vasik 66a4fe
+    else if (f->acl_type == ACL_T_YES)
Ondrej Vasik 66a4fe
+      modebuf[10] = '+';
Ondrej Vasik 66a4fe
+    modebuf[11] = '\0';
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+    /* print mode */
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+    (void) sprintf (p, "%s ", modebuf);
Ondrej Vasik 66a4fe
+    p += strlen (p);
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+    /* print standard user and group */
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+    DIRED_FPUTS (buf, stdout, p - buf);
Ondrej Vasik 66a4fe
+    format_user (f->stat.st_uid, owner_width, f->stat_ok);
Ondrej Vasik 66a4fe
+    format_group (f->stat.st_gid, group_width, f->stat_ok);
Ondrej Vasik 66a4fe
+    p = buf;
Ondrej Vasik 66a4fe
+  }
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  (void) sprintf (p, "%-32s ", f->scontext ?: "");
Ondrej Vasik 66a4fe
+  p += strlen (p);
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  DIRED_INDENT ();
Ondrej Vasik 66a4fe
+  DIRED_FPUTS (buf, stdout, p - buf);
Ondrej Vasik c77f9b
+  size_t w = print_name_with_quoting (f, false, &dired_obstack, p - buf);
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
+  if (f->filetype == symbolic_link) {
Ondrej Vasik 66a4fe
+      if (f->linkname) {
Ondrej Vasik 66a4fe
+          DIRED_FPUTS_LITERAL (" -> ", stdout);
Ondrej Vasik c77f9b
+          print_name_with_quoting (f, true, NULL, (p - buf) + w + 4);
Ondrej Vasik 66a4fe
+          if (indicator_style != none)
Ondrej Vasik 66a4fe
+            print_type_indicator (f->stat_ok, f->linkmode, f->filetype);
Ondrej Vasik 66a4fe
+      }
Ondrej Vasik 66a4fe
+  }
Ondrej Vasik 66a4fe
+  else {
Ondrej Vasik 66a4fe
+    if (indicator_style != none)
Ondrej Vasik 66a4fe
+      print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
Ondrej Vasik 66a4fe
+  }
Ondrej Vasik f8d3fd
+}
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
 /* Print information about F in long format.  */
Ondrej Vasik 66a4fe
 static void
Ondrej Vasik 66a4fe
 print_long_format (const struct fileinfo *f)
Ondrej Vasik c77f9b
@@ -3689,9 +3786,15 @@ print_long_format (const struct fileinfo
Ondrej Vasik 66a4fe
      The latter is wrong when nlink_width is zero.  */
Ondrej Vasik 66a4fe
   p += strlen (p);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
+  if (print_scontext)
Ondrej Vasik f8d3fd
+    {
Ondrej Vasik 66a4fe
+      sprintf (p, "%-32s ", f->scontext ? f->scontext : "");
Ondrej Vasik 66a4fe
+      p += strlen (p);
Ondrej Vasik f8d3fd
+    }
Ondrej Vasik f8d3fd
+
Ondrej Vasik 66a4fe
   DIRED_INDENT ();
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-  if (print_owner || print_group || print_author || print_scontext)
Ondrej Vasik 66a4fe
+  if (print_owner || print_group || print_author)
Ondrej Vasik 66a4fe
     {
Ondrej Vasik 66a4fe
       DIRED_FPUTS (buf, stdout, p - buf);
Ondrej Vasik 66a4fe
 
Ondrej Vasik c77f9b
@@ -3704,9 +3807,6 @@ print_long_format (const struct fileinfo
Ondrej Vasik 66a4fe
       if (print_author)
Ondrej Vasik 66a4fe
         format_user (f->stat.st_author, author_width, f->stat_ok);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-      if (print_scontext)
Ondrej Vasik 66a4fe
-        format_user_or_group (f->scontext, 0, scontext_width);
Ondrej Vasik 66a4fe
-
Ondrej Vasik 66a4fe
       p = buf;
Ondrej Vasik 66a4fe
     }
Ondrej Vasik 66a4fe
 
Ondrej Vasik c77f9b
@@ -4047,9 +4147,6 @@ print_file_name_and_frills (const struct
Ondrej Vasik 66a4fe
             : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
Ondrej Vasik 66a4fe
                               ST_NBLOCKSIZE, output_block_size));
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-  if (print_scontext)
Ondrej Vasik 66a4fe
-    printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
Ondrej Vasik 66a4fe
-
Ondrej Vasik c77f9b
   size_t width = print_name_with_quoting (f, false, NULL, start_col);
Ondrej Vasik c77f9b
 
Ondrej Vasik c77f9b
   if (indicator_style != none)
Ondrej Vasik c77f9b
@@ -4248,9 +4345,6 @@ length_of_file_name_and_frills (const st
Ondrej Vasik 66a4fe
                                             output_block_size))
Ondrej Vasik 66a4fe
                 : block_size_width);
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
-  if (print_scontext)
Ondrej Vasik 66a4fe
-    len += 1 + (format == with_commas ? strlen (f->scontext) : scontext_width);
Ondrej Vasik 66a4fe
-
Ondrej Vasik 66a4fe
   quote_name (NULL, f->name, filename_quoting_options, &name_width);
Ondrej Vasik 66a4fe
   len += name_width;
Ondrej Vasik 66a4fe
 
Ondrej Vasik c77f9b
@@ -4681,9 +4775,16 @@ Mandatory arguments to long options are 
Ondrej Vasik 66a4fe
   -w, --width=COLS           assume screen width instead of current value\n\
Ondrej Vasik 66a4fe
   -x                         list entries by lines instead of by columns\n\
Ondrej Vasik 66a4fe
   -X                         sort alphabetically by entry extension\n\
Ondrej Vasik 66a4fe
-  -Z, --context              print any SELinux security context of each file\n\
Ondrej Vasik 66a4fe
   -1                         list one file per line\n\
Ondrej Vasik 66a4fe
 "), stdout);
Ondrej Vasik 66a4fe
+      fputs(_("\nSELinux options:\n\n\
Ondrej Vasik 66a4fe
+  --lcontext                 Display security context.   Enable -l. Lines\n\
Ondrej Vasik 66a4fe
+                             will probably be too wide for most displays.\n\
Ondrej Vasik 66a4fe
+  -Z, --context              Display security context so it fits on most\n\
Ondrej Vasik 66a4fe
+                             displays.  Displays only mode, user, group,\n\
Ondrej Vasik 66a4fe
+                             security context and file name.\n\
Ondrej Vasik 66a4fe
+  --scontext                 Display only security context and file name.\n\
Ondrej Vasik 66a4fe
+"), stdout);
Ondrej Vasik 66a4fe
       fputs (HELP_OPTION_DESCRIPTION, stdout);
Ondrej Vasik 66a4fe
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
Ondrej Vasik 66a4fe
       emit_size_note ();
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/mkdir.c coreutils-8.1/src/mkdir.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/mkdir.c	2009-09-23 10:25:44.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/mkdir.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -38,6 +38,7 @@
Ondrej Vasik 66a4fe
 static struct option const longopts[] =
Ondrej Vasik 66a4fe
 {
Ondrej Vasik 66a4fe
   {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
Ondrej Vasik 66a4fe
+  {"context", required_argument, NULL, 'Z'},
Ondrej Vasik 66a4fe
   {"mode", required_argument, NULL, 'm'},
Ondrej Vasik 66a4fe
   {"parents", no_argument, NULL, 'p'},
Ondrej Vasik 66a4fe
   {"verbose", no_argument, NULL, 'v'},
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/mknod.c coreutils-8.1/src/mknod.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/mknod.c	2009-09-23 10:25:44.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/mknod.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -35,7 +35,7 @@
Ondrej Vasik 66a4fe
 
Ondrej Vasik 66a4fe
 static struct option const longopts[] =
Ondrej Vasik 66a4fe
 {
Ondrej Vasik 66a4fe
-  {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
Ondrej Vasik 66a4fe
+  {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, 
Ondrej Vasik 66a4fe
   {"mode", required_argument, NULL, 'm'},
Ondrej Vasik 66a4fe
   {GETOPT_HELP_OPTION_DECL},
Ondrej Vasik 66a4fe
   {GETOPT_VERSION_OPTION_DECL},
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/mv.c coreutils-8.1/src/mv.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/mv.c	2009-09-23 10:25:44.000000000 +0200
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/mv.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik 66a4fe
@@ -118,6 +118,7 @@ cp_option_init (struct cp_options *x)
Ondrej Vasik 66a4fe
   x->preserve_mode = true;
Ondrej Vasik 66a4fe
   x->preserve_timestamps = true;
Ondrej Vasik 66a4fe
   x->preserve_security_context = selinux_enabled;
Ondrej Vasik 66a4fe
+  x->set_security_context = false;
Ondrej Vasik 66a4fe
   x->reduce_diagnostics = false;
Ondrej Vasik 66a4fe
   x->require_preserve = false;  /* FIXME: maybe make this an option */
Ondrej Vasik 66a4fe
   x->require_preserve_context = false;
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/runcon.c coreutils-8.1/src/runcon.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/runcon.c	2009-10-29 14:53:40.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/runcon.c	2009-11-20 13:11:40.000000000 +0100
Kamil Dudka b26491
@@ -86,7 +86,7 @@ Usage: %s CONTEXT COMMAND [args]\n\
Ondrej Vasik 893c38
   or:  %s [ -c ] [-u USER] [-r ROLE] [-t TYPE] [-l RANGE] COMMAND [args]\n\
Ondrej Vasik 893c38
 "), program_name, program_name);
Ondrej Vasik 893c38
       fputs (_("\
Ondrej Vasik 893c38
-Run a program in a different security context.\n\
Ondrej Vasik 893c38
+Run a program in a different SELinux security context.\n\
Ondrej Vasik 893c38
 With neither CONTEXT nor COMMAND, print the current security context.\n\
Ondrej Vasik 893c38
 \n\
Ondrej Vasik 893c38
   CONTEXT            Complete security context\n\
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/src/stat.c coreutils-8.1/src/stat.c
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/src/stat.c	2009-10-29 11:11:29.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/src/stat.c	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik c77f9b
@@ -858,7 +858,7 @@ print_it (char const *format, char const
Tim Waugh 5505e2
 
Ondrej Vasik 0363d6
 /* Stat the file system and print what we find.  */
Ondrej Vasik 0363d6
 static bool
Ondrej Vasik 0363d6
-do_statfs (char const *filename, bool terse, char const *format)
Ondrej Vasik 0363d6
+do_statfs (char const *filename, bool terse, bool secure, char const *format)
Ondrej Vasik 0363d6
 {
Ondrej Vasik 0363d6
   STRUCT_STATVFS statfsbuf;
Tim Waugh 5505e2
 
Ondrej Vasik c77f9b
@@ -877,15 +877,31 @@ do_statfs (char const *filename, bool te
Ondrej Vasik 0363d6
     }
Tim Waugh 5505e2
 
Ondrej Vasik 0363d6
   if (format == NULL)
Ondrej Vasik 0363d6
+  {
Ondrej Vasik 0363d6
+    if (terse)
Tim Waugh 5505e2
     {
Ondrej Vasik 0363d6
-      format = (terse
Ondrej Vasik 250517
-                ? "%n %i %l %t %s %S %b %f %a %c %d\n"
Ondrej Vasik 250517
-                : "  File: \"%n\"\n"
Ondrej Vasik 0363d6
+      if (secure)
Ondrej Vasik 0363d6
+        format = "%n %i %l %t %s %S %b %f %a %c %d %C\n";
Ondrej Vasik 250517
+             else
Ondrej Vasik 250517
+              format = "%n %i %l %t %s %S %b %f %a %c %d\n";
Ondrej Vasik f8d3fd
+    }
Ondrej Vasik 0363d6
+    else
Ondrej Vasik 250517
+          {
Ondrej Vasik 250517
+            if (secure)
Ondrej Vasik 250517
+              format = "  File: \"%n\"\n"
Ondrej Vasik f8d3fd
                 "    ID: %-8i Namelen: %-7l Type: %T\n"
Ondrej Vasik f8d3fd
                 "Block size: %-10s Fundamental block size: %S\n"
Ondrej Vasik f8d3fd
                 "Blocks: Total: %-10b Free: %-10f Available: %a\n"
Ondrej Vasik f8d3fd
-                "Inodes: Total: %-10c Free: %d\n");
Ondrej Vasik f8d3fd
-    }
Ondrej Vasik 250517
+                "Inodes: Total: %-10c Free: %d\n"
Ondrej Vasik 250517
+                "   S_Context: %C\n";
Ondrej Vasik 250517
+            else
Ondrej Vasik 250517
+              format = "  File: \"%n\"\n"
Ondrej Vasik 250517
+                "    ID: %-8i Namelen: %-7l Type: %T\n"
Ondrej Vasik 250517
+                "Block size: %-10s Fundamental block size: %S\n"
Ondrej Vasik 250517
+                "Blocks: Total: %-10b Free: %-10f Available: %a\n"
Ondrej Vasik 250517
+                "Inodes: Total: %-10c Free: %d\n";
Ondrej Vasik 0363d6
+     }
Ondrej Vasik 0363d6
+  }
Tim Waugh b9e1cc
 
Ondrej Vasik 0363d6
   print_it (format, filename, print_statfs, &statfsbuf);
Ondrej Vasik 0363d6
   return true;
Ondrej Vasik c77f9b
@@ -893,7 +909,7 @@ do_statfs (char const *filename, bool te
Tim Waugh 5505e2
 
Ondrej Vasik 0363d6
 /* stat the file and print what we find */
Ondrej Vasik 0363d6
 static bool
Ondrej Vasik 0363d6
-do_stat (char const *filename, bool terse, char const *format)
Ondrej Vasik 1ecd64
+do_stat (char const *filename, bool terse, bool secure, char const *format)
Ondrej Vasik 0363d6
 {
Ondrej Vasik 0363d6
   struct stat statbuf;
Tim Waugh 5505e2
 
Ondrej Vasik c77f9b
@@ -919,9 +935,12 @@ do_stat (char const *filename, bool ters
Ondrej Vasik 0363d6
   if (format == NULL)
Ondrej Vasik 0363d6
     {
Ondrej Vasik 0363d6
       if (terse)
Ondrej Vasik 250517
-        {
Ondrej Vasik 250517
-          format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n";
Ondrej Vasik 250517
-        }
Ondrej Vasik 0363d6
+      {
Ondrej Vasik 0363d6
+        if (secure)
Ondrej Vasik 250517
+               format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C\n";
Ondrej Vasik 250517
+             else
Ondrej Vasik 250517
+               format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n";
Ondrej Vasik 0363d6
+      }
Ondrej Vasik 0363d6
       else
Ondrej Vasik 250517
         {
Ondrej Vasik 250517
           /* Temporary hack to match original output until conditional
Ondrej Vasik c77f9b
@@ -938,12 +957,22 @@ do_stat (char const *filename, bool ters
Ondrej Vasik 250517
             }
Ondrej Vasik 250517
           else
Ondrej Vasik 250517
             {
Ondrej Vasik 250517
-              format =
Ondrej Vasik 250517
-                "  File: %N\n"
Ondrej Vasik 250517
-                "  Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
Ondrej Vasik 250517
-                "Device: %Dh/%dd\tInode: %-10i  Links: %h\n"
Ondrej Vasik 250517
-                "Access: (%04a/%10.10A)  Uid: (%5u/%8U)   Gid: (%5g/%8G)\n"
Ondrej Vasik 250517
-                "Access: %x\n" "Modify: %y\n" "Change: %z\n";
Ondrej Vasik 0363d6
+        if (secure)
Ondrej Vasik 0363d6
+           format =
Ondrej Vasik 250517
+                    "  File: %N\n"
Ondrej Vasik 250517
+                    "  Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
Ondrej Vasik 250517
+                    "Device: %Dh/%dd\tInode: %-10i  Links: %-5h"
Ondrej Vasik 250517
+                    " Device type: %t,%T\n"
Ondrej Vasik 250517
+                     "Access: (%04a/%10.10A)  Uid: (%5u/%8U)   Gid: (%5g/%8G)\n"
Ondrej Vasik 250517
+                    "   S_Context: %C\n"
Ondrej Vasik 250517
+                    "Access: %x\n" "Modify: %y\n" "Change: %z\n";
Ondrej Vasik 0363d6
+        else 
Ondrej Vasik 250517
+                format =
Ondrej Vasik 250517
+                    "  File: %N\n"
Ondrej Vasik 250517
+                    "  Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
Ondrej Vasik 250517
+                    "Device: %Dh/%dd\tInode: %-10i  Links: %h\n"
Ondrej Vasik 250517
+                    "Access: (%04a/%10.10A)  Uid: (%5u/%8U)   Gid: (%5g/%8G)\n"
Ondrej Vasik 250517
+                    "Access: %x\n" "Modify: %y\n" "Change: %z\n";
Ondrej Vasik 250517
             }
Ondrej Vasik 250517
         }
Ondrej Vasik 0363d6
     }
Ondrej Vasik c77f9b
@@ -964,6 +993,7 @@ usage (int status)
Ondrej Vasik 0363d6
 Display file or file system status.\n\
Ondrej Vasik 0363d6
 \n\
Ondrej Vasik 0363d6
   -L, --dereference     follow links\n\
Ondrej Vasik 0363d6
+  -Z, --context         print the SELinux security context \n\
Ondrej Vasik 0363d6
   -f, --file-system     display file system status instead of file status\n\
Ondrej Vasik 0363d6
 "), stdout);
Ondrej Vasik 0363d6
       fputs (_("\
Ondrej Vasik c77f9b
@@ -1048,6 +1078,7 @@ main (int argc, char *argv[])
Ondrej Vasik 0363d6
   int i;
Ondrej Vasik 0363d6
   bool fs = false;
Ondrej Vasik 0363d6
   bool terse = false;
Ondrej Vasik 0363d6
+  bool secure = false;
Ondrej Vasik 0363d6
   char *format = NULL;
Ondrej Vasik 0363d6
   bool ok = true;
Tim Waugh 5505e2
 
Ondrej Vasik c77f9b
@@ -1087,13 +1118,13 @@ main (int argc, char *argv[])
Ondrej Vasik 250517
           terse = true;
Ondrej Vasik 250517
           break;
Ondrej Vasik 250517
 
Ondrej Vasik 250517
-        case 'Z':  /* FIXME: remove in 2010 */
Ondrej Vasik 250517
-          /* Ignore, for compatibility with distributions
Ondrej Vasik 250517
-             that implemented this before upstream.
Ondrej Vasik 250517
-             But warn of impending removal.  */
Ondrej Vasik 250517
-          error (0, 0,
Ondrej Vasik 250517
-                 _("the --context (-Z) option is obsolete and will be removed\n"
Ondrej Vasik 250517
-                   "in a future release"));
Ondrej Vasik 250517
+        case 'Z':
Ondrej Vasik 0363d6
+    if((is_selinux_enabled()>0))
Ondrej Vasik 250517
+            secure = 1;
Ondrej Vasik 250517
+          else {
Ondrej Vasik 250517
+            error (0, 0, _("Kernel is not SELinux enabled"));
Ondrej Vasik 250517
+            usage (EXIT_FAILURE);
Ondrej Vasik 250517
+          }
Ondrej Vasik 250517
           break;
Ondrej Vasik 250517
 
Ondrej Vasik 250517
         case_GETOPT_HELP_CHAR;
Ondrej Vasik c77f9b
@@ -1113,8 +1144,8 @@ main (int argc, char *argv[])
Daniel J Walsh 129baa
 
Tim Waugh 5505e2
   for (i = optind; i < argc; i++)
Tim Waugh 5505e2
     ok &= (fs
Ondrej Vasik 250517
-           ? do_statfs (argv[i], terse, format)
Ondrej Vasik 250517
-           : do_stat (argv[i], terse, format));
Ondrej Vasik 250517
+           ? do_statfs (argv[i], terse, secure, format)
Ondrej Vasik 250517
+           : do_stat (argv[i], terse, secure, format));
Tim Waugh 5505e2
 
Tim Waugh 5505e2
   exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
Tim Waugh 5505e2
 }
Ondrej Vasik 20666c
diff -urNp coreutils-8.4-orig/tests/test-lib.sh coreutils-8.4/tests/test-lib.sh
Ondrej Vasik 20666c
--- coreutils-8.4-orig/tests/test-lib.sh	2010-01-03 18:06:20.000000000 +0100
Ondrej Vasik 20666c
+++ coreutils-8.4/tests/test-lib.sh	2010-01-14 10:28:17.000000000 +0100
Ondrej Vasik 20666c
@@ -218,8 +218,8 @@ skip_if_()
Ondrej Vasik 20666c
 
Ondrej Vasik 20666c
 require_selinux_()
Ondrej Vasik 20666c
 {
Ondrej Vasik 20666c
-  case `ls -Zd .` in
Ondrej Vasik 20666c
-    '? .'|'unlabeled .')
Ondrej Vasik 20666c
+  case `ls -Zd . | cut -f4 -d" "` in
Ondrej Vasik 20666c
+    '?'|'unlabeled')
Ondrej Vasik 20666c
       skip_test_ "this system (or maybe just" \
Ondrej Vasik 20666c
         "the current file system) lacks SELinux support"
Ondrej Vasik 20666c
     ;;
Ondrej Vasik c77f9b
diff -urNp coreutils-8.1-orig/tests/misc/selinux coreutils-8.1/tests/misc/selinux
Ondrej Vasik c77f9b
--- coreutils-8.1-orig/tests/misc/selinux	2009-10-30 12:51:07.000000000 +0100
Ondrej Vasik c77f9b
+++ coreutils-8.1/tests/misc/selinux	2009-11-20 13:11:40.000000000 +0100
Ondrej Vasik c77f9b
@@ -29,7 +29,7 @@ chcon $ctx f d p ||
Ondrej Vasik 0363d6
 
Ondrej Vasik 0363d6
 # inspect that context with both ls -Z and stat.
Ondrej Vasik 0363d6
 for i in d f p; do
Ondrej Vasik 0363d6
-  c=`ls -dogZ $i|cut -d' ' -f3`; test x$c = x$ctx || fail=1
Ondrej Vasik 437c9e
+  c=`ls -dogZ $i|cut -d' ' -f4`; test x$c = x$ctx || fail=1
Ondrej Vasik 0363d6
   c=`stat --printf %C $i`; test x$c = x$ctx || fail=1
Ondrej Vasik 0363d6
 done
Kamil Dudka b26491