1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
Description: ls --acl prints ACLs (illumos only)
Bug-Dyson: http://osdyson.org/issues/106
Index: coreutils/src/ls.c
===================================================================
--- coreutils.orig/src/ls.c
+++ coreutils/src/ls.c
@@ -49,6 +49,8 @@
# include <sys/ptem.h>
#endif
+#include <sys/acl.h>
+
#include <stdio.h>
#include <assert.h>
#include <setjmp.h>
@@ -185,7 +187,7 @@ verify (sizeof filetype_letter - 1 == ar
C_LINK, C_SOCK, C_FILE, C_DIR \
}
-enum acl_type
+enum ls_acl_type
{
ACL_T_NONE,
ACL_T_LSM_CONTEXT_ONLY,
@@ -219,7 +221,7 @@ struct fileinfo
/* For long listings, true if the file has an access control list,
or a security context. */
- enum acl_type acl_type;
+ enum ls_acl_type ls_acl_type;
/* For color listings, true if a regular file has capability info. */
bool has_capability;
@@ -271,6 +273,7 @@ static void print_horizontal (void);
static int format_user_width (uid_t u);
static int format_group_width (gid_t g);
static void print_long_format (const struct fileinfo *f);
+static void do_print_acl (const struct fileinfo *f);
static void print_many_per_line (void);
static size_t print_name_with_quoting (const struct fileinfo *f,
bool symlink_target,
@@ -356,6 +359,7 @@ static struct pending *pending_dirs;
static struct timespec current_time;
static bool print_scontext;
+static bool print_acl;
static char UNKNOWN_SECURITY_CONTEXT[] = "?";
/* Whether any of the files has an ACL. This affects the width of the
@@ -799,7 +803,8 @@ enum
SI_OPTION,
SORT_OPTION,
TIME_OPTION,
- TIME_STYLE_OPTION
+ TIME_STYLE_OPTION,
+ ACL_OPTION,
};
static struct option const long_options[] =
@@ -845,6 +850,7 @@ static struct option const long_options[
{"color", optional_argument, NULL, COLOR_OPTION},
{"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
{"context", no_argument, 0, 'Z'},
+ {"acl", no_argument, 0, ACL_OPTION},
{"author", no_argument, NULL, AUTHOR_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -1579,6 +1585,7 @@ decode_switches (int argc, char **argv)
ignore_patterns = NULL;
hide_patterns = NULL;
print_scontext = false;
+ print_acl = false;
getenv_quoting_style ();
@@ -1932,6 +1939,11 @@ decode_switches (int argc, char **argv)
print_scontext = true;
break;
+ case ACL_OPTION:
+ print_acl = true;
+ format = long_format;
+ break;
+
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -3076,12 +3088,12 @@ gobble_file (char const *name, enum file
have_acl = (0 < n);
}
- f->acl_type = (!have_scontext && !have_acl
+ f->ls_acl_type = (!have_scontext && !have_acl
? ACL_T_NONE
: (have_scontext && !have_acl
? ACL_T_LSM_CONTEXT_ONLY
: ACL_T_YES));
- any_has_acl |= f->acl_type != ACL_T_NONE;
+ any_has_acl |= f->ls_acl_type != ACL_T_NONE;
if (err)
error (0, errno, "%s", quotearg_colon (absolute_name));
@@ -3807,6 +3819,19 @@ format_inode (char *buf, size_t buflen,
: (char *) "?");
}
+/* Print ACL for F. */
+static void
+do_print_acl (const struct fileinfo *f)
+{
+ acl_t *aclp;
+ if (0 == acl_get(f->name, 0, &aclp) && NULL != aclp) {
+ putchar('\n');
+ acl_printacl(aclp, 80, 0);
+ acl_free(aclp);
+ }
+
+}
+
/* Print information about F in long format. */
static void
print_long_format (const struct fileinfo *f)
@@ -3838,9 +3863,9 @@ print_long_format (const struct fileinfo
}
if (! any_has_acl)
modebuf[10] = '\0';
- else if (f->acl_type == ACL_T_LSM_CONTEXT_ONLY)
+ else if (f->ls_acl_type == ACL_T_LSM_CONTEXT_ONLY)
modebuf[10] = '.';
- else if (f->acl_type == ACL_T_YES)
+ else if (f->ls_acl_type == ACL_T_YES)
modebuf[10] = '+';
switch (time_type)
@@ -4026,6 +4051,9 @@ print_long_format (const struct fileinfo
}
else if (indicator_style != none)
print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
+
+ if (f->filetype != symbolic_link && print_acl)
+ do_print_acl(f);
}
/* Output to OUT a quoted representation of the file name NAME,
|