2 * Copyright (c) 2001-2002 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Get an access or default acl on a file
21 * using IRIX semantics or Linux semantics
30 #include <sys/types.h>
33 #include <acl/libacl.h>
39 fprintf(stderr, "usage: %s [-a] [-d] [-f] [-i] path\n"
41 " -a - get access ACL\n"
42 " -d - get default ACL\n"
43 " -f - get access ACL using file descriptor\n"
51 main(int argc, char **argv)
62 prog = basename(argv[0]);
64 while ((c = getopt(argc, argv, "adf")) != -1) {
81 if (getdefault && usefd) {
82 fprintf(stderr, "%s: -f and -d are not compatible\n", prog);
96 fd = open(file, O_RDONLY);
98 fprintf (stderr, "%s: error opening \"%s\": %s\n",
99 prog, file, strerror(errno));
108 acl = acl_get_fd(fd);
111 acl = acl_get_file(file, ACL_TYPE_ACCESS);
114 fprintf(stderr, "%s: error getting access ACL on \"%s\": %s\n",
115 prog, file, strerror(errno));
118 acl_text = acl_to_any_text(acl, NULL, ',', TEXT_ABBREVIATE);
119 if (acl_text == NULL) {
120 fprintf(stderr, "%s: cannot get access ACL text on '%s': %s\n",
121 prog, file, strerror(errno));
124 printf("%s: access %s", file, acl_text);
130 acl = acl_get_file(file, ACL_TYPE_DEFAULT);
132 fprintf(stderr, "%s: error getting default ACL on \"%s\": %s\n",
133 prog, file, strerror(errno));
136 acl_text = acl_to_any_text(acl, NULL, ',', TEXT_ABBREVIATE);
137 if (acl_text == NULL) {
138 fprintf(stderr, "%s: cannot get default ACL text on '%s': %s\n",
139 prog, file, strerror(errno));
142 printf("%s: default %s", file, acl_text);