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"
29 static char sccsid
[] = "%Z%%M% %I% %E% SMI";
33 * getfacl [-ad] file ...
34 * This command displays discretionary information for a file or files.
46 * default:user:uid:perm
48 * default:group:gid:perm
61 static char *pruname(uid_t
);
62 static char *prgname(gid_t
);
63 static char *display(int);
68 main(int argc
, char *argv
[])
81 (void) setlocale(LC_ALL
, "");
82 (void) textdomain(TEXT_DOMAIN
);
87 while ((c
= getopt(argc
, argv
, "ad")) != EOF
) {
106 for (; optind
< argc
; optind
++) {
107 register char *filep
;
109 filep
= argv
[optind
];
111 /* Get ACL info of the files */
113 if ((aclcnt
= acl(filep
, GETACLCNT
, 0, NULL
)) < 0) {
114 if (errno
== ENOSYS
) {
115 (void) fprintf(stderr
,
116 gettext("File system doesn't support "
117 "aclent_t style ACL's.\n"
118 "See acl(5) for more information on "
119 "Solaris ACL support.\n"));
125 if (aclcnt
< MIN_ACL_ENTRIES
) {
126 (void) fprintf(stderr
,
127 gettext("%d: acl count too small from %s\n"),
132 if ((aclp
= (aclent_t
*)malloc(sizeof (aclent_t
) * aclcnt
))
134 (void) fprintf(stderr
,
135 gettext("Insufficient memory\n"));
140 if (acl(filep
, GETACL
, aclcnt
, aclp
) < 0) {
145 /* display ACL: assume it is sorted. */
146 (void) printf("\n# file: %s\n", filep
);
148 for (tp
= aclp
; aclcnt
--; tp
++) {
149 if (tp
->a_type
== USER_OBJ
)
150 (void) printf("# owner: %s\n",
152 if (tp
->a_type
== GROUP_OBJ
)
153 (void) printf("# group: %s\n",
155 if (tp
->a_type
== CLASS_OBJ
)
159 for (tp
= aclp
; aclcnt
--; tp
++) {
160 switch (tp
->a_type
) {
163 permp
= display(tp
->a_perm
);
164 (void) printf("user:%s:%s\t\t",
165 pruname(tp
->a_id
), permp
);
167 permp
= display(tp
->a_perm
& mask
);
169 "#effective:%s\n", permp
);
175 /* no need to display uid */
176 permp
= display(tp
->a_perm
);
177 (void) printf("user::%s\n", permp
);
183 permp
= display(tp
->a_perm
);
184 (void) printf("group:%s:%s\t\t",
185 prgname(tp
->a_id
), permp
);
187 permp
= display(tp
->a_perm
& mask
);
189 "#effective:%s\n", permp
);
195 permp
= display(tp
->a_perm
);
196 (void) printf("group::%s\t\t", permp
);
198 permp
= display(tp
->a_perm
& mask
);
200 "#effective:%s\n", permp
);
206 permp
= display(tp
->a_perm
);
207 (void) printf("mask:%s\n", permp
);
213 permp
= display(tp
->a_perm
);
214 (void) printf("other:%s\n", permp
);
220 permp
= display(tp
->a_perm
);
221 (void) printf("default:user:%s:%s\n",
222 pruname(tp
->a_id
), permp
);
228 permp
= display(tp
->a_perm
);
229 (void) printf("default:user::%s\n",
236 permp
= display(tp
->a_perm
);
237 (void) printf("default:group:%s:%s\n",
238 prgname(tp
->a_id
), permp
);
244 permp
= display(tp
->a_perm
);
245 (void) printf("default:group::%s\n",
252 permp
= display(tp
->a_perm
);
253 (void) printf("default:mask:%s\n",
260 permp
= display(tp
->a_perm
);
261 (void) printf("default:other:%s\n",
267 (void) fprintf(stderr
,
268 gettext("unrecognized entry\n"));
284 (void) fprintf(stderr
, gettext("Insufficient memory\n"));
307 struct passwd
*passwdp
;
308 static char uidp
[10]; /* big enough */
310 passwdp
= getpwuid(uid
);
311 if (passwdp
== (struct passwd
*)NULL
) {
312 /* could not get passwd information: display uid instead */
313 (void) sprintf(uidp
, "%u", uid
);
316 return (passwdp
->pw_name
);
322 struct group
*groupp
;
323 static char gidp
[10]; /* big enough */
325 groupp
= getgrgid(gid
);
326 if (groupp
== (struct group
*)NULL
) {
327 /* could not get group information: display gid instead */
328 (void) sprintf(gidp
, "%u", gid
);
331 return (groupp
->gr_name
);
337 (void) fprintf(stderr
,
338 gettext("usage: getfacl [-ad] file ... \n"));