3 Copyright 2000, 2001, 2002, 2003, 2004, 2009 Red Hat Inc.
5 Written by Corinna Vinschen <vinschen@redhat.com>
7 This file is part of Cygwin.
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
18 #include <sys/types.h>
24 static const char version[] = "$Revision$";
25 static char *prog_name;
32 pbuf[0] = (perm & S_IROTH) ? 'r' : '-';
33 pbuf[1] = (perm & S_IWOTH) ? 'w' : '-';
34 pbuf[2] = (perm & S_IXOTH) ? 'x' : '-';
42 static char ubuf[256];
45 if ((pw = getpwuid (uid)))
46 strcpy (ubuf, pw->pw_name);
48 sprintf (ubuf, "%lu <unknown>", (unsigned long)uid);
55 static char gbuf[256];
58 if ((gr = getgrgid (gid)))
59 strcpy (gbuf, gr->gr_name);
61 sprintf (gbuf, "%lu <unknown>", (unsigned long)gid);
68 fprintf (stream, "Usage: %s [-adn] FILE [FILE2...]\n"
69 "Display file and directory access control lists (ACLs).\n"
71 " -a, --all display the filename, the owner, the group, and\n"
72 " the ACL of the file\n"
73 " -d, --dir display the filename, the owner, the group, and\n"
74 " the default ACL of the directory, if it exists\n"
75 " -h, --help output usage information and exit\n"
76 " -n, --noname display user and group IDs instead of names\n"
77 " -v, --version output version information and exit\n"
79 "When multiple files are specified on the command line, a blank\n"
80 "line separates the ACLs for each file.\n", prog_name);
84 "For each argument that is a regular file, special file or\n"
85 "directory, getfacl displays the owner, the group, and the ACL.\n"
86 "For directories getfacl displays additionally the default ACL.\n"
88 "With no options specified, getfacl displays the filename, the\n"
89 "owner, the group, and both the ACL and the default ACL, if it\n"
92 "The format for ACL output is as follows:\n"
94 " # owner: name or uid\n"
95 " # group: name or uid\n"
97 " user:name or uid:perm\n"
99 " group:name or gid:perm\n"
102 " default:user::perm\n"
103 " default:user:name or uid:perm\n"
104 " default:group::perm\n"
105 " default:group:name or gid:perm\n"
106 " default:mask:perm\n"
107 " default:other:perm\n"
112 struct option longopts[] = {
113 {"all", no_argument, NULL, 'a'},
114 {"dir", no_argument, NULL, 'd'},
115 {"help", no_argument, NULL, 'h'},
116 {"noname", no_argument, NULL, 'n'},
117 {"version", no_argument, NULL, 'v'},
118 {0, no_argument, NULL, 0}
124 const char *v = strchr (version, ':');
134 len = strchr (v, ' ') - v;
137 getfacl (cygwin) %.*s\n\
139 Copyright (c) 2000, 2001, 2002, 2003, 2004, 2009 Red Hat, Inc.\n\
141 ", len, v, __DATE__);
145 main (int argc, char **argv)
153 aclent_t acls[MAX_ACL_ENTRIES];
155 prog_name = strrchr (argv[0], '/');
156 if (prog_name == NULL)
157 prog_name = strrchr (argv[0], '\\');
158 if (prog_name == NULL)
163 while ((c = getopt_long (argc, argv, "adhnv", longopts, NULL)) != EOF)
185 if (optind > argc - 1)
190 for (; optind < argc; ++optind)
193 if (stat (argv[optind], &st)
194 || (num_acls = acl (argv[optind], GETACL, MAX_ACL_ENTRIES, acls)) < 0)
196 fprintf (stderr, "%s: %s: %s\n",
197 prog_name, argv[optind], strerror (errno));
201 printf ("# file: %s\n", argv[optind]);
204 printf ("# owner: %lu\n", (unsigned long)st.st_uid);
205 printf ("# group: %lu\n", (unsigned long)st.st_gid);
209 printf ("# owner: %s\n", username (st.st_uid));
210 printf ("# group: %s\n", groupname (st.st_gid));
212 for (i = 0; i < num_acls; ++i)
214 if (acls[i].a_type & ACL_DEFAULT)
222 switch (acls[i].a_type & ~ACL_DEFAULT)
229 printf ("user:%lu:", (unsigned long)acls[i].a_id);
231 printf ("user:%s:", username (acls[i].a_id));
238 printf ("group:%lu:", (unsigned long)acls[i].a_id);
240 printf ("group:%s:", groupname (acls[i].a_id));
249 printf ("%s\n", permstr (acls[i].a_perm));