2 * Copyright (c) 2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This prog is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This prog is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this prog with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this prog; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Get an access or default acl on a file
35 * using IRIX semantics or Linux semantics
44 #include <sys/types.h>
47 #include <acl/libacl.h>
53 fprintf(stderr, "usage: %s [-a] [-d] [-f] [-i] path\n"
55 " -a - get access ACL\n"
56 " -d - get default ACL\n"
57 " -f - get access ACL using file descriptor\n"
65 main(int argc, char **argv)
76 prog = basename(argv[0]);
78 while ((c = getopt(argc, argv, "adf")) != -1) {
95 if (getdefault && usefd) {
96 fprintf(stderr, "%s: -f and -d are not compatible\n", prog);
101 if (optind == argc) {
110 fd = open(file, O_RDONLY);
112 fprintf (stderr, "%s: error opening \"%s\": %s\n",
113 prog, file, strerror(errno));
122 acl = acl_get_fd(fd);
125 acl = acl_get_file(file, ACL_TYPE_ACCESS);
128 fprintf(stderr, "%s: error getting access ACL on \"%s\": %s\n",
129 prog, file, strerror(errno));
132 acl_text = acl_to_any_text(acl, NULL, "", ',', "", TEXT_ABBREVIATE);
133 if (acl_text == NULL) {
134 fprintf(stderr, "%s: cannot get access ACL text on '%s': %s\n",
135 prog, file, strerror(errno));
138 printf("%s: access %s", file, acl_text);
144 acl = acl_get_file(file, ACL_TYPE_DEFAULT);
146 fprintf(stderr, "%s: error getting default ACL on \"%s\": %s\n",
147 prog, file, strerror(errno));
150 acl_text = acl_to_any_text(acl, NULL, "", ',', "", TEXT_ABBREVIATE);
151 if (acl_text == NULL) {
152 fprintf(stderr, "%s: cannot get default ACL text on '%s': %s\n",
153 prog, file, strerror(errno));
156 printf("%s: default %s", file, acl_text);