4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 static char sccsid
[] = "%Z%%M% %I% %E% SMI";
31 * getfacl [-ad] file ...
32 * This command displays discretionary information for a file or files.
44 * default:user:uid:perm
46 * default:group:gid:perm
59 static char *pruname(uid_t
);
60 static char *prgname(gid_t
);
61 static char *display(int);
66 main(int argc
, char *argv
[])
79 (void) setlocale(LC_ALL
, "");
80 (void) textdomain(TEXT_DOMAIN
);
85 while ((c
= getopt(argc
, argv
, "ad")) != EOF
) {
104 for (; optind
< argc
; optind
++) {
105 register char *filep
;
107 filep
= argv
[optind
];
109 /* Get ACL info of the files */
111 if ((aclcnt
= acl(filep
, GETACLCNT
, 0, NULL
)) < 0) {
112 if (errno
== ENOSYS
) {
113 (void) fprintf(stderr
,
114 gettext("File system doesn't support "
115 "aclent_t style ACL's.\n"
116 "See acl(5) for more information on "
117 "Solaris ACL support.\n"));
123 if (aclcnt
< MIN_ACL_ENTRIES
) {
124 (void) fprintf(stderr
,
125 gettext("%d: acl count too small from %s\n"),
130 if ((aclp
= (aclent_t
*)malloc(sizeof (aclent_t
) * aclcnt
))
132 (void) fprintf(stderr
,
133 gettext("Insufficient memory\n"));
138 if (acl(filep
, GETACL
, aclcnt
, aclp
) < 0) {
143 /* display ACL: assume it is sorted. */
144 (void) printf("\n# file: %s\n", filep
);
146 for (tp
= aclp
; aclcnt
--; tp
++) {
147 if (tp
->a_type
== USER_OBJ
)
148 (void) printf("# owner: %s\n",
150 if (tp
->a_type
== GROUP_OBJ
)
151 (void) printf("# group: %s\n",
153 if (tp
->a_type
== CLASS_OBJ
)
157 for (tp
= aclp
; aclcnt
--; tp
++) {
158 switch (tp
->a_type
) {
161 permp
= display(tp
->a_perm
);
162 (void) printf("user:%s:%s\t\t",
163 pruname(tp
->a_id
), permp
);
165 permp
= display(tp
->a_perm
& mask
);
167 "#effective:%s\n", permp
);
173 /* no need to display uid */
174 permp
= display(tp
->a_perm
);
175 (void) printf("user::%s\n", permp
);
181 permp
= display(tp
->a_perm
);
182 (void) printf("group:%s:%s\t\t",
183 prgname(tp
->a_id
), permp
);
185 permp
= display(tp
->a_perm
& mask
);
187 "#effective:%s\n", permp
);
193 permp
= display(tp
->a_perm
);
194 (void) printf("group::%s\t\t", permp
);
196 permp
= display(tp
->a_perm
& mask
);
198 "#effective:%s\n", permp
);
204 permp
= display(tp
->a_perm
);
205 (void) printf("mask:%s\n", permp
);
211 permp
= display(tp
->a_perm
);
212 (void) printf("other:%s\n", permp
);
218 permp
= display(tp
->a_perm
);
219 (void) printf("default:user:%s:%s\n",
220 pruname(tp
->a_id
), permp
);
226 permp
= display(tp
->a_perm
);
227 (void) printf("default:user::%s\n",
234 permp
= display(tp
->a_perm
);
235 (void) printf("default:group:%s:%s\n",
236 prgname(tp
->a_id
), permp
);
242 permp
= display(tp
->a_perm
);
243 (void) printf("default:group::%s\n",
250 permp
= display(tp
->a_perm
);
251 (void) printf("default:mask:%s\n",
258 permp
= display(tp
->a_perm
);
259 (void) printf("default:other:%s\n",
265 (void) fprintf(stderr
,
266 gettext("unrecognized entry\n"));
282 (void) fprintf(stderr
, gettext("Insufficient memory\n"));
305 struct passwd
*passwdp
;
306 static char uidp
[10]; /* big enough */
308 passwdp
= getpwuid(uid
);
309 if (passwdp
== NULL
) {
310 /* could not get passwd information: display uid instead */
311 (void) sprintf(uidp
, "%u", uid
);
314 return (passwdp
->pw_name
);
320 struct group
*groupp
;
321 static char gidp
[10]; /* big enough */
323 groupp
= getgrgid(gid
);
324 if (groupp
== NULL
) {
325 /* could not get group information: display gid instead */
326 (void) sprintf(gidp
, "%u", gid
);
329 return (groupp
->gr_name
);
335 (void) fprintf(stderr
,
336 gettext("usage: getfacl [-ad] file ... \n"));