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
41 #include <sys/types.h>
50 fprintf(stderr, "usage: %s [-a] [-d] [-f] [-i] path\n"
52 " -a - get access ACL\n"
53 " -d - get default ACL\n"
54 " -f - get access ACL using file descriptor\n"
55 " -i - use irix semantics\n"
63 main(int argc, char **argv)
69 int irixsemantics = 0;
75 prog = basename(argv[0]);
77 while ((c = getopt(argc, argv, "adif")) != -1) {
97 if (getdefault && usefd) {
98 fprintf(stderr, "%s: -f and -d are not compatible\n", prog);
103 if (optind == argc) {
112 acl_set_compat(ACL_COMPAT_IRIXGET);
116 fd = open(file, O_RDONLY);
118 fprintf (stderr, "%s: error opening \"%s\": %s\n",
119 prog, file, strerror(errno));
128 acl = acl_get_fd(fd);
131 acl = acl_get_file(file, ACL_TYPE_ACCESS);
134 fprintf (stderr, "%s: error getting access ACL on \"%s\": %s\n",
135 prog, file, strerror(errno));
138 if (irixsemantics && acl->acl_cnt == ACL_NOT_PRESENT) {
139 buf_acl = strdup("irix-empty");
142 buf_acl = acl_to_short_text (acl, (ssize_t *) NULL);
143 if (buf_acl == NULL) {
144 fprintf (stderr, "%s: error converting ACL to short text "
145 "for file \"%s\": %s\n",
146 prog, file, strerror(errno));
150 printf("%s: access %s\n", file, buf_acl);
156 acl = acl_get_file(file, ACL_TYPE_DEFAULT);
158 fprintf (stderr, "%s: error getting default ACL on \"%s\": %s\n",
159 prog, file, strerror(errno));
162 if (irixsemantics && acl->acl_cnt == ACL_NOT_PRESENT) {
163 buf_acl = strdup("irix-empty");
165 else if (!irixsemantics && acl->acl_cnt == 0) {
166 buf_acl = strdup("linux-empty");
169 buf_acl = acl_to_short_text (acl, (ssize_t *) NULL);
170 if (buf_acl == NULL) {
171 fprintf (stderr, "%s: error converting ACL to short text "
172 "for file \"%s\": %s\n",
173 prog, file, strerror(errno));
177 printf("%s: default %s\n", file, buf_acl);