Blame SOURCES/coreutils-selinux.patch

5244b2
diff -urNp coreutils-8.21-orig/init.cfg coreutils-8.21/init.cfg
5244b2
--- coreutils-8.21-orig/init.cfg	2013-01-31 01:46:24.000000000 +0100
5244b2
+++ coreutils-8.21/init.cfg	2013-02-15 14:31:58.957469955 +0100
5244b2
@@ -308,8 +308,8 @@ require_selinux_()
5244b2
   # Independent of whether SELinux is enabled system-wide,
5244b2
   # the current file system may lack SELinux support.
5244b2
   # Also the current build may have SELinux support disabled.
5244b2
-  case $(ls -Zd .) in
5244b2
-    '? .'|'unlabeled .')
5244b2
+  case $(ls -Zd . | cut -f4 -d" ") in
5244b2
+    '?'|'unlabeled')
5244b2
       test -z "$CONFIG_HEADER" \
5244b2
         && framework_failure_ 'CONFIG_HEADER not defined'
5244b2
       grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
5244b2
diff -urNp coreutils-8.21-orig/man/chcon.x coreutils-8.21/man/chcon.x
5244b2
--- coreutils-8.21-orig/man/chcon.x	2011-08-23 15:44:01.000000000 +0200
5244b2
+++ coreutils-8.21/man/chcon.x	2013-02-15 14:31:58.937482694 +0100
5244b2
@@ -1,4 +1,4 @@
5244b2
 [NAME]
5244b2
-chcon \- change file security context
5244b2
+chcon \- change file SELinux security context
5244b2
 [DESCRIPTION]
5244b2
 .\" Add any additional description here
5244b2
diff -urNp coreutils-8.21-orig/man/runcon.x coreutils-8.21/man/runcon.x
5244b2
--- coreutils-8.21-orig/man/runcon.x	2011-08-23 15:44:01.000000000 +0200
5244b2
+++ coreutils-8.21/man/runcon.x	2013-02-15 14:31:58.938486496 +0100
5244b2
@@ -1,5 +1,5 @@
5244b2
 [NAME]
5244b2
-runcon \- run command with specified security context
5244b2
+runcon \- run command with specified SELinux security context
5244b2
 [DESCRIPTION]
5244b2
 Run COMMAND with completely-specified CONTEXT, or with current or
5244b2
 transitioned security context modified by one or more of LEVEL,
5244b2
diff -urNp coreutils-8.21-orig/src/copy.c coreutils-8.21/src/copy.c
5244b2
--- coreutils-8.21-orig/src/copy.c	2013-02-07 10:37:05.000000000 +0100
5244b2
+++ coreutils-8.21/src/copy.c	2013-02-15 14:31:58.941467872 +0100
5244b2
@@ -2410,6 +2410,17 @@ copy_internal (char const *src_name, cha
5244b2
       else
5244b2
         {
5244b2
           omitted_permissions = 0;
5244b2
+
5244b2
+          /* For directories, the process global context could be reset for
5244b2
+             descendents, so use it to set the context for existing dirs here.
5244b2
+             This will also give earlier indication of failure to set ctx.  */
5244b2
+          if (x->set_security_context || x->preserve_security_context)
5244b2
+            if (! set_file_security_ctx (dst_name, x->preserve_security_context,
5244b2
+                                         false, x))
5244b2
+              {
5244b2
+                if (x->require_preserve_context)
5244b2
+                  goto un_backup;
5244b2
+              }
5244b2
         }
5244b2
 
5244b2
       /* Decide whether to copy the contents of the directory.  */
5244b2
@@ -2415,6 +2426,8 @@ copy_internal (char const *src_name, cha
5244b2
         {
5244b2
           /* Here, we are crossing a file system boundary and cp's -x option
5244b2
              is in effect: so don't copy the contents of this directory. */
5244b2
+        if (x->preserve_security_context)
5244b2
+           restore_default_fscreatecon_or_die ();
5244b2
         }
5244b2
       else
5244b2
         {
5244b2
@@ -2602,7 +2613,7 @@ copy_internal (char const *src_name, cha
5244b2
 
5244b2
   /* With -Z or --preserve=context, set the context for existing files.
5244b2
      Note this is done already for copy_reg() for reasons described therein.  */
5244b2
-  if (!new_dst && !x->copy_as_regular
5244b2
+  if (!new_dst && !x->copy_as_regular && !S_ISDIR (src_mode)
5244b2
       && (x->set_security_context || x->preserve_security_context))
5244b2
     {
5244b2
       if (! set_file_security_ctx (dst_name, x->preserve_security_context,
5244b2
diff -urNp coreutils-8.21-orig/src/cp.c coreutils-8.21/src/cp.c
5244b2
--- coreutils-8.21-orig/src/cp.c	2013-02-07 10:37:05.000000000 +0100
5244b2
+++ coreutils-8.21/src/cp.c	2013-02-15 14:31:58.945468929 +0100
5244b2
@@ -201,6 +202,9 @@ Copy SOURCE to DEST, or multiple SOURCE(
5244b2
                                  all\n\
5244b2
 "), stdout);
5244b2
       fputs (_("\
5244b2
+  -c                           deprecated, same as --preserve=context\n\
5244b2
+"), stdout);
5244b2
+      fputs (_("\
5244b2
       --no-preserve=ATTR_LIST  don't preserve the specified attributes\n\
5244b2
       --parents                use full source file name under DIRECTORY\n\
5244b2
 "), stdout);
5244b2
@@ -933,7 +939,7 @@ main (int argc, char **argv)
5244b2
      we'll actually use backup_suffix_string.  */
5244b2
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
5244b2
 
5244b2
-  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
5244b2
+  while ((c = getopt_long (argc, argv, "abcdfHilLnprst:uvxPRS:TZ",
5244b2
                            long_opts, NULL))
5244b2
          != -1)
5244b2
     {
5244b2
@@ -981,6 +987,17 @@ main (int argc, char **argv)
5244b2
           copy_contents = true;
5244b2
           break;
5244b2
 
5244b2
+        case 'c':
5244b2
+          fprintf (stderr, "%s: warning: option '-c' is deprecated, please use '--preserve=context' instead\n", argv[0]);
5244b2
+          if ( x.set_security_context ) { 
5244b2
+              (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
5244b2
+             exit( 1 );
5244b2
+           }
5244b2
+           else if (selinux_enabled) {
5244b2
+              x.preserve_security_context = true;
5244b2
+              x.require_preserve_context = true;
5244b2
+           }
5244b2
+          break;
5244b2
         case 'd':
5244b2
           x.preserve_links = true;
5244b2
           x.dereference = DEREF_NEVER;
5244b2
diff -urNp coreutils-8.21-orig/src/id.c coreutils-8.21/src/id.c
5244b2
--- coreutils-8.21-orig/src/id.c	2013-01-31 01:46:24.000000000 +0100
5244b2
+++ coreutils-8.21/src/id.c	2013-02-15 14:31:58.946469154 +0100
5244b2
@@ -106,7 +106,7 @@ int
5244b2
 main (int argc, char **argv)
5244b2
 {
5244b2
   int optc;
5244b2
-  int selinux_enabled = (is_selinux_enabled () > 0);
5244b2
+  bool selinux_enabled = (is_selinux_enabled () > 0);
5244b2
   bool smack_enabled = is_smack_enabled ();
5244b2
   bool opt_zero = false;
5244b2
   char *pw_name = NULL;
5244b2
diff -urNp coreutils-8.21-orig/src/install.c coreutils-8.21/src/install.c
5244b2
--- coreutils-8.21-orig/src/install.c	2013-02-07 10:37:05.000000000 +0100
5244b2
+++ coreutils-8.21/src/install.c	2013-02-15 14:31:58.948469440 +0100
5244b2
@@ -639,7 +640,7 @@ In the 4th form, create all components o
5244b2
   -v, --verbose       print the name of each directory as it is created\n\
5244b2
 "), stdout);
5244b2
       fputs (_("\
5244b2
-      --preserve-context  preserve SELinux security context\n\
5244b2
+  -P, --preserve-context  preserve SELinux security context (-P deprecated)\n\
5244b2
   -Z, --context[=CTX]     set SELinux security context of destination file to\n\
5244b2
                             default type, or to CTX if specified\n\
5244b2
 "), stdout);
5244b2
@@ -782,7 +783,7 @@ main (int argc, char **argv)
5244b2
      we'll actually use backup_suffix_string.  */
5244b2
   backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
5244b2
 
5244b2
-  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pt:TvS:Z", long_options,
5244b2
+  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pPt:TvS:Z", long_options,
5244b2
                               NULL)) != -1)
5244b2
     {
5244b2
       switch (optc)
5244b2
@@ -853,6 +854,8 @@ main (int argc, char **argv)
5244b2
           no_target_directory = true;
5244b2
           break;
5244b2
 
5244b2
+        case 'P':
5244b2
+          fprintf (stderr, "%s: warning: option '-P' is deprecated, please use '--preserve-context' instead\n", argv[0]);
5244b2
         case PRESERVE_CONTEXT_OPTION:
5244b2
           if (! selinux_enabled)
5244b2
             {
5244b2
@@ -860,6 +862,10 @@ main (int argc, char **argv)
5244b2
                              "this kernel is not SELinux-enabled"));
5244b2
               break;
5244b2
             }
5244b2
+          if ( x.set_security_context ) {
5244b2
+             (void) fprintf(stderr, "%s: cannot force target context and preserve it\n", argv[0]);
5244b2
+             exit( 1 );
5244b2
+          }
5244b2
           x.preserve_security_context = true;
5244b2
           use_default_selinux_context = false;
5244b2
           break;
5244b2
diff -urNp coreutils-8.21-orig/src/ls.c coreutils-8.21/src/ls.c
5244b2
--- coreutils-8.21-orig/src/ls.c	2013-02-03 04:24:02.000000000 +0100
5244b2
+++ coreutils-8.21/src/ls.c	2013-02-15 14:31:58.953469008 +0100
5244b2
@@ -165,7 +165,8 @@ enum filetype
5244b2
     symbolic_link,
5244b2
     sock,
5244b2
     whiteout,
5244b2
-    arg_directory
5244b2
+    arg_directory,
5244b2
+    command_line
5244b2
   };
5244b2
 
5244b2
 /* Display letters and indicators for each filetype.
5244b2
@@ -281,6 +282,7 @@ static void queue_directory (char const 
5244b2
                              bool command_line_arg);
5244b2
 static void sort_files (void);
5244b2
 static void parse_ls_color (void);
5244b2
+static void print_scontext_format (const struct fileinfo *f);
5244b2
 
5244b2
 /* Initial size of hash table.
5244b2
    Most hierarchies are likely to be shallower than this.  */
5244b2
@@ -350,7 +352,7 @@ static struct pending *pending_dirs;
5244b2
 
5244b2
 static struct timespec current_time;
5244b2
 
5244b2
-static bool print_scontext;
5244b2
+static int print_scontext = 0;
5244b2
 static char UNKNOWN_SECURITY_CONTEXT[] = "?";
5244b2
 
5244b2
 /* Whether any of the files has an ACL.  This affects the width of the
5244b2
@@ -390,7 +392,9 @@ enum format
5244b2
     one_per_line,		/* -1 */
5244b2
     many_per_line,		/* -C */
5244b2
     horizontal,			/* -x */
5244b2
-    with_commas			/* -m */
5244b2
+    with_commas,			/* -m */
5244b2
+    security_format, /* -Z */
5244b2
+    invalid_format
5244b2
   };
5244b2
 
5244b2
 static enum format format;
5244b2
@@ -793,6 +797,9 @@ enum
5244b2
   SHOW_CONTROL_CHARS_OPTION,
5244b2
   SI_OPTION,
5244b2
   SORT_OPTION,
5244b2
+  CONTEXT_OPTION,
5244b2
+  LCONTEXT_OPTION,
5244b2
+  SCONTEXT_OPTION,
5244b2
   TIME_OPTION,
5244b2
   TIME_STYLE_OPTION
5244b2
 };
5244b2
@@ -839,7 +846,9 @@ static struct option const long_options[
5244b2
   {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
5244b2
   {"color", optional_argument, NULL, COLOR_OPTION},
5244b2
   {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
5244b2
-  {"context", no_argument, 0, 'Z'},
5244b2
+  {"context", no_argument, 0, CONTEXT_OPTION},
5244b2
+  {"lcontext", no_argument, 0, LCONTEXT_OPTION},
5244b2
+  {"scontext", no_argument, 0, SCONTEXT_OPTION},
5244b2
   {"author", no_argument, NULL, AUTHOR_OPTION},
5244b2
   {GETOPT_HELP_OPTION_DECL},
5244b2
   {GETOPT_VERSION_OPTION_DECL},
5244b2
@@ -849,12 +858,12 @@ static struct option const long_options[
5244b2
 static char const *const format_args[] =
5244b2
 {
5244b2
   "verbose", "long", "commas", "horizontal", "across",
5244b2
-  "vertical", "single-column", NULL
5244b2
+  "vertical", "single-column", "context", NULL
5244b2
 };
5244b2
 static enum format const format_types[] =
5244b2
 {
5244b2
   long_format, long_format, with_commas, horizontal, horizontal,
5244b2
-  many_per_line, one_per_line
5244b2
+  many_per_line, one_per_line, security_format
5244b2
 };
5244b2
 ARGMATCH_VERIFY (format_args, format_types);
5244b2
 
5244b2
@@ -1296,7 +1305,8 @@ main (int argc, char **argv)
5244b2
       /* Avoid following symbolic links when possible.  */
5244b2
       if (is_colored (C_ORPHAN)
5244b2
           || (is_colored (C_EXEC) && color_symlink_as_referent)
5244b2
-          || (is_colored (C_MISSING) && format == long_format))
5244b2
+          || (is_colored (C_MISSING) && (format == long_format
5244b2
+              || format == security_format)))
5244b2
         check_symlink_color = true;
5244b2
 
5244b2
       /* If the standard output is a controlling terminal, watch out
5244b2
@@ -1343,7 +1353,7 @@ main (int argc, char **argv)
5244b2
   if (dereference == DEREF_UNDEFINED)
5244b2
     dereference = ((immediate_dirs
5244b2
                     || indicator_style == classify
5244b2
-                    || format == long_format)
5244b2
+                    || format == long_format || format == security_format)
5244b2
                    ? DEREF_NEVER
5244b2
                    : DEREF_COMMAND_LINE_SYMLINK_TO_DIR);
5244b2
 
5244b2
@@ -1363,7 +1373,7 @@ main (int argc, char **argv)
5244b2
 
5244b2
   format_needs_stat = sort_type == sort_time || sort_type == sort_size
5244b2
     || format == long_format
5244b2
-    || print_scontext
5244b2
+    || format == security_format || print_scontext
5244b2
     || print_block_size;
5244b2
   format_needs_type = (! format_needs_stat
5244b2
                        && (recursive
5244b2
@@ -1394,7 +1404,7 @@ main (int argc, char **argv)
5244b2
     }
5244b2
   else
5244b2
     do
5244b2
-      gobble_file (argv[i++], unknown, NOT_AN_INODE_NUMBER, true, "");
5244b2
+      gobble_file (argv[i++], command_line, NOT_AN_INODE_NUMBER, true, "");
5244b2
     while (i < argc);
5244b2
 
5244b2
   if (cwd_n_used)
5244b2
@@ -1565,7 +1575,7 @@ decode_switches (int argc, char **argv)
5244b2
   ignore_mode = IGNORE_DEFAULT;
5244b2
   ignore_patterns = NULL;
5244b2
   hide_patterns = NULL;
5244b2
-  print_scontext = false;
5244b2
+  print_scontext = 0;
5244b2
 
5244b2
   /* FIXME: put this in a function.  */
5244b2
   {
5244b2
@@ -1941,13 +1951,27 @@ decode_switches (int argc, char **argv)
5244b2
           break;
5244b2
 
5244b2
         case 'Z':
5244b2
-          print_scontext = true;
5244b2
+          print_scontext = 1;
5244b2
+    format = security_format;
5244b2
           break;
5244b2
 
5244b2
         case_GETOPT_HELP_CHAR;
5244b2
 
5244b2
         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
5244b2
 
5244b2
+  case CONTEXT_OPTION: /* default security context format */
5244b2
+                print_scontext = 1;
5244b2
+                format = security_format;
5244b2
+                break;
5244b2
+        case LCONTEXT_OPTION: /* long format plus security context */
5244b2
+                print_scontext = 1;
5244b2
+                format = long_format;
5244b2
+                break;
5244b2
+        case SCONTEXT_OPTION: /* short form of new security format */
5244b2
+                print_scontext = 0;
5244b2
+                format = security_format;
5244b2
+                break;
5244b2
+
5244b2
         default:
5244b2
           usage (LS_FAILURE);
5244b2
         }
5244b2
@@ -2883,6 +2907,7 @@ gobble_file (char const *name, enum file
5244b2
   memset (f, '\0', sizeof *f);
5244b2
   f->stat.st_ino = inode;
5244b2
   f->filetype = type;
5244b2
+  f->scontext = NULL;
5244b2
 
5244b2
   if (command_line_arg
5244b2
       || format_needs_stat
5244b2
@@ -2995,7 +3020,7 @@ gobble_file (char const *name, enum file
5244b2
           && print_with_color && is_colored (C_CAP))
5244b2
         f->has_capability = has_capability_cache (absolute_name, f);
5244b2
 
5244b2
-      if (format == long_format || print_scontext)
5244b2
+      if (format == long_format || format == security_format || print_scontext)
5244b2
         {
5244b2
           bool have_scontext = false;
5244b2
           bool have_acl = false;
5244b2
@@ -3016,7 +3041,7 @@ gobble_file (char const *name, enum file
5244b2
                 err = 0;
5244b2
             }
5244b2
 
5244b2
-          if (err == 0 && format == long_format)
5244b2
+          if (err == 0 && (format == long_format || format == security_format))
5244b2
             {
5244b2
               int n = file_has_acl_cache (absolute_name, f);
5244b2
               err = (n < 0);
5244b2
@@ -3035,7 +3060,8 @@ gobble_file (char const *name, enum file
5244b2
         }
5244b2
 
5244b2
       if (S_ISLNK (f->stat.st_mode)
5244b2
-          && (format == long_format || check_symlink_color))
5244b2
+          && (format == long_format || format == security_format
5244b2
+              || check_symlink_color))
5244b2
         {
5244b2
           struct stat linkstats;
5244b2
 
5244b2
@@ -3054,6 +3080,7 @@ gobble_file (char const *name, enum file
5244b2
                  command line are automatically traced if not being
5244b2
                  listed as files.  */
5244b2
               if (!command_line_arg || format == long_format
5244b2
+                  || format == security_format
5244b2
                   || !S_ISDIR (linkstats.st_mode))
5244b2
                 {
5244b2
                   /* Get the linked-to file's mode for the filetype indicator
5244b2
@@ -3087,7 +3114,7 @@ gobble_file (char const *name, enum file
5244b2
             block_size_width = len;
5244b2
         }
5244b2
 
5244b2
-      if (format == long_format)
5244b2
+      if (format == long_format || format == security_format)
5244b2
         {
5244b2
           if (print_owner)
5244b2
             {
5244b2
@@ -3591,6 +3618,13 @@ print_current_files (void)
5244b2
           print_long_format (sorted_file[i]);
5244b2
           DIRED_PUTCHAR ('\n');
5244b2
         }
5244b2
+     break;
5244b2
+    case security_format:
5244b2
+      for (i = 0; i < cwd_n_used; i++)
5244b2
+      {
5244b2
+        print_scontext_format (sorted_file[i]);
5244b2
+        DIRED_PUTCHAR ('\n');
5244b2
+      }
5244b2
       break;
5244b2
     }
5244b2
 }
5244b2
@@ -3753,6 +3787,67 @@ format_inode (char *buf, size_t buflen, 
5244b2
           : (char *) "?");
5244b2
 }
5244b2
 
5244b2
+/* Print info about f in scontext format */
5244b2
+static void
5244b2
+print_scontext_format (const struct fileinfo *f)
5244b2
+{
5244b2
+  char modebuf[12];
5244b2
+
5244b2
+  /* 7 fields that may require LONGEST_HUMAN_READABLE bytes,
5244b2
+     1 10-byte mode string,
5244b2
+     9 spaces, one following each of these fields, and
5244b2
+     1 trailing NUL byte.  */
5244b2
+
5244b2
+  char init_bigbuf[7 * LONGEST_HUMAN_READABLE + 10  + 9 + 1];
5244b2
+  char *buf = init_bigbuf;
5244b2
+  char *p;
5244b2
+
5244b2
+  p = buf;
5244b2
+
5244b2
+  if ( print_scontext ) { /* zero means terse listing */
5244b2
+    filemodestring (&f->stat, modebuf);
5244b2
+    if (! any_has_acl)
5244b2
+      modebuf[10] = '\0';
5244b2
+    else if (f->acl_type == ACL_T_SELINUX_ONLY)
5244b2
+      modebuf[10] = '.';
5244b2
+    else if (f->acl_type == ACL_T_YES)
5244b2
+      modebuf[10] = '+';
5244b2
+    modebuf[11] = '\0';
5244b2
+
5244b2
+    /* print mode */
5244b2
+
5244b2
+    (void) sprintf (p, "%s ", modebuf);
5244b2
+    p += strlen (p);
5244b2
+
5244b2
+    /* print standard user and group */
5244b2
+
5244b2
+    DIRED_FPUTS (buf, stdout, p - buf);
5244b2
+    format_user (f->stat.st_uid, owner_width, f->stat_ok);
5244b2
+    format_group (f->stat.st_gid, group_width, f->stat_ok);
5244b2
+    p = buf;
5244b2
+  }
5244b2
+
5244b2
+  (void) sprintf (p, "%-32s ", f->scontext ?: "");
5244b2
+  p += strlen (p);
5244b2
+
5244b2
+  DIRED_INDENT ();
5244b2
+  DIRED_FPUTS (buf, stdout, p - buf);
5244b2
+  size_t w = print_name_with_quoting (f, false, &dired_obstack, p - buf);
5244b2
+
5244b2
+  if (f->filetype == symbolic_link) {
5244b2
+      if (f->linkname) {
5244b2
+          DIRED_FPUTS_LITERAL (" -> ", stdout);
5244b2
+          print_name_with_quoting (f, true, NULL, (p - buf) + w + 4);
5244b2
+          if (indicator_style != none)
5244b2
+            print_type_indicator (f->stat_ok, f->linkmode, f->filetype);
5244b2
+      }
5244b2
+  }
5244b2
+  else {
5244b2
+    if (indicator_style != none)
5244b2
+      print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
5244b2
+  }
5244b2
+}
5244b2
+
5244b2
 /* Print information about F in long format.  */
5244b2
 static void
5244b2
 print_long_format (const struct fileinfo *f)
5244b2
@@ -3844,9 +3939,15 @@ print_long_format (const struct fileinfo
5244b2
      The latter is wrong when nlink_width is zero.  */
5244b2
   p += strlen (p);
5244b2
 
5244b2
+  if (print_scontext)
5244b2
+    {
5244b2
+      sprintf (p, "%-32s ", f->scontext ? f->scontext : "");
5244b2
+      p += strlen (p);
5244b2
+    }
5244b2
+
5244b2
   DIRED_INDENT ();
5244b2
 
5244b2
-  if (print_owner || print_group || print_author || print_scontext)
5244b2
+  if (print_owner || print_group || print_author)
5244b2
     {
5244b2
       DIRED_FPUTS (buf, stdout, p - buf);
5244b2
 
5244b2
@@ -3859,9 +3960,6 @@ print_long_format (const struct fileinfo
5244b2
       if (print_author)
5244b2
         format_user (f->stat.st_author, author_width, f->stat_ok);
5244b2
 
5244b2
-      if (print_scontext)
5244b2
-        format_user_or_group (f->scontext, 0, scontext_width);
5244b2
-
5244b2
       p = buf;
5244b2
     }
5244b2
 
5244b2
@@ -4207,9 +4305,6 @@ print_file_name_and_frills (const struct
5244b2
             : human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
5244b2
                               ST_NBLOCKSIZE, output_block_size));
5244b2
 
5244b2
-  if (print_scontext)
5244b2
-    printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
5244b2
-
5244b2
   size_t width = print_name_with_quoting (f, false, NULL, start_col);
5244b2
 
5244b2
   if (indicator_style != none)
5244b2
@@ -4417,9 +4512,6 @@ length_of_file_name_and_frills (const st
5244b2
                                             output_block_size))
5244b2
                 : block_size_width);
5244b2
 
5244b2
-  if (print_scontext)
5244b2
-    len += 1 + (format == with_commas ? strlen (f->scontext) : scontext_width);
5244b2
-
5244b2
   quote_name (NULL, f->name, filename_quoting_options, &name_width);
5244b2
   len += name_width;
5244b2
 
5244b2
@@ -4856,9 +4948,16 @@ Sort entries alphabetically if none of -
5244b2
   -w, --width=COLS           assume screen width instead of current value\n\
5244b2
   -x                         list entries by lines instead of by columns\n\
5244b2
   -X                         sort alphabetically by entry extension\n\
5244b2
-  -Z, --context              print any SELinux security context of each file\n\
5244b2
   -1                         list one file per line\n\
5244b2
 "), stdout);
5244b2
+      fputs(_("\nSELinux options:\n\n\
5244b2
+  --lcontext                 Display security context.   Enable -l. Lines\n\
5244b2
+                             will probably be too wide for most displays.\n\
5244b2
+  -Z, --context              Display security context so it fits on most\n\
5244b2
+                             displays.  Displays only mode, user, group,\n\
5244b2
+                             security context and file name.\n\
5244b2
+  --scontext                 Display only security context and file name.\n\
5244b2
+"), stdout);
5244b2
       fputs (HELP_OPTION_DESCRIPTION, stdout);
5244b2
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
5244b2
       emit_size_note ();
5244b2
diff -urNp coreutils-8.21-orig/tests/misc/selinux.sh coreutils-8.21/tests/misc/selinux.sh
5244b2
--- coreutils-8.21-orig/tests/misc/selinux.sh	2013-01-31 01:46:24.000000000 +0100
5244b2
+++ coreutils-8.21/tests/misc/selinux.sh	2013-02-15 14:31:58.957469955 +0100
5244b2
@@ -37,7 +37,7 @@ chcon $ctx f d p ||
5244b2
 
5244b2
 # inspect that context with both ls -Z and stat.
5244b2
 for i in d f p; do
5244b2
-  c=$(ls -dogZ $i|cut -d' ' -f3); test x$c = x$ctx || fail=1
5244b2
+  c=$(ls -dogZ $i|cut -d' ' -f4); test x$c = x$ctx || fail=1
5244b2
   c=$(stat --printf %C $i); test x$c = x$ctx || fail=1
5244b2
 done
5244b2