ip1981

Add ACL to GNU ls

Mar 20th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.91 KB | None | 0 0
  1. --- src/ls.c    2012-10-23 18:14:12.000000000 +0400
  2. +++ src/ls.c.acl    2013-03-19 01:02:09.611176368 +0400
  3. @@ -49,6 +49,8 @@
  4.  # include <sys/ptem.h>
  5.  #endif
  6.  
  7. +#include <sys/acl.h>
  8. +
  9.  #include <stdio.h>
  10.  #include <assert.h>
  11.  #include <setjmp.h>
  12. @@ -182,7 +184,7 @@
  13.      C_LINK, C_SOCK, C_FILE, C_DIR          \
  14.    }
  15.  
  16. -enum acl_type
  17. +enum ls_acl_type
  18.    {
  19.      ACL_T_NONE,
  20.      ACL_T_SELINUX_ONLY,
  21. @@ -216,7 +218,7 @@
  22.  
  23.      /* For long listings, true if the file has an access control list,
  24.         or an SELinux security context.  */
  25. -    enum acl_type acl_type;
  26. +    enum ls_acl_type ls_acl_type;
  27.  
  28.      /* For color listings, true if a regular file has capability info.  */
  29.      bool has_capability;
  30. @@ -268,6 +270,7 @@
  31.  static int format_user_width (uid_t u);
  32.  static int format_group_width (gid_t g);
  33.  static void print_long_format (const struct fileinfo *f);
  34. +static void do_print_acl (const struct fileinfo *f);
  35.  static void print_many_per_line (void);
  36.  static size_t print_name_with_quoting (const struct fileinfo *f,
  37.                                         bool symlink_target,
  38. @@ -351,6 +354,7 @@
  39.  static struct timespec current_time;
  40.  
  41.  static bool print_scontext;
  42. +static bool print_acl;
  43.  static char UNKNOWN_SECURITY_CONTEXT[] = "?";
  44.  
  45.  /* Whether any of the files has an ACL.  This affects the width of the
  46. @@ -794,7 +798,8 @@
  47.    SI_OPTION,
  48.    SORT_OPTION,
  49.    TIME_OPTION,
  50. -  TIME_STYLE_OPTION
  51. +  TIME_STYLE_OPTION,
  52. +  ACL_OPTION,
  53.  };
  54.  
  55.  static struct option const long_options[] =
  56. @@ -840,6 +845,7 @@
  57.    {"color", optional_argument, NULL, COLOR_OPTION},
  58.    {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
  59.    {"context", no_argument, 0, 'Z'},
  60. +  {"acl", no_argument, 0, ACL_OPTION},
  61.    {"author", no_argument, NULL, AUTHOR_OPTION},
  62.    {GETOPT_HELP_OPTION_DECL},
  63.    {GETOPT_VERSION_OPTION_DECL},
  64. @@ -1566,6 +1572,7 @@
  65.    ignore_patterns = NULL;
  66.    hide_patterns = NULL;
  67.    print_scontext = false;
  68. +  print_acl = false;
  69.  
  70.    /* FIXME: put this in a function.  */
  71.    {
  72. @@ -1944,6 +1951,11 @@
  73.            print_scontext = true;
  74.            break;
  75.  
  76. +        case ACL_OPTION:
  77. +          print_acl = true;
  78. +          format = long_format;
  79. +          break;
  80. +
  81.          case_GETOPT_HELP_CHAR;
  82.  
  83.          case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
  84. @@ -3023,12 +3035,12 @@
  85.                have_acl = (0 < n);
  86.              }
  87.  
  88. -          f->acl_type = (!have_selinux && !have_acl
  89. +          f->ls_acl_type = (!have_selinux && !have_acl
  90.                           ? ACL_T_NONE
  91.                           : (have_selinux && !have_acl
  92.                              ? ACL_T_SELINUX_ONLY
  93.                              : ACL_T_YES));
  94. -          any_has_acl |= f->acl_type != ACL_T_NONE;
  95. +          any_has_acl |= f->ls_acl_type != ACL_T_NONE;
  96.  
  97.            if (err)
  98.              error (0, errno, "%s", quotearg_colon (absolute_name));
  99. @@ -3753,6 +3765,19 @@
  100.            : (char *) "?");
  101.  }
  102.  
  103. +/* Print ACL fo F.  */
  104. +static void
  105. +do_print_acl (const struct fileinfo *f)
  106. +{
  107. +    acl_t *aclp;
  108. +    if (0 == acl_get(f->name, 0, &aclp) && NULL != aclp) {
  109. +        putchar('\n');
  110. +        acl_printacl(aclp, 80, 0);
  111. +        acl_free(aclp);
  112. +    }
  113. +
  114. +}
  115. +
  116.  /* Print information about F in long format.  */
  117.  static void
  118.  print_long_format (const struct fileinfo *f)
  119. @@ -3784,9 +3809,9 @@
  120.      }
  121.    if (! any_has_acl)
  122.      modebuf[10] = '\0';
  123. -  else if (f->acl_type == ACL_T_SELINUX_ONLY)
  124. +  else if (f->ls_acl_type == ACL_T_SELINUX_ONLY)
  125.      modebuf[10] = '.';
  126. -  else if (f->acl_type == ACL_T_YES)
  127. +  else if (f->ls_acl_type == ACL_T_YES)
  128.      modebuf[10] = '+';
  129.  
  130.    switch (time_type)
  131. @@ -3972,6 +3997,9 @@
  132.      }
  133.    else if (indicator_style != none)
  134.      print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
  135. +
  136. +  if (f->filetype != symbolic_link && print_acl)
  137. +      do_print_acl(f);
  138.  }
  139.  
  140.  /* Output to OUT a quoted representation of the file name NAME,
Advertisement
Add Comment
Please, Sign In to add comment