3 Copyright 2000, 2001, 2002, 2003, 2004, 2009, 2011, 2014, 2015 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>
21 #include <cygwin/version.h>
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"
70 "Display file and directory access control lists (ACLs).\n"
72 " -a, --access display the file access control list only\n"
73 " -d, --default display the default access control list only\n"
74 " -c, --omit-header do not display the comment header\n"
75 " -e, --all-effective print all effective rights\n"
76 " -E, --no-effective print no effective rights\n"
77 " -n, --numeric print numeric user/group identifiers\n"
78 " -V, --version print version and exit\n"
79 " -h, --help this help text\n"
81 "When multiple files are specified on the command line, a blank\n"
82 "line separates the ACLs for each file.\n", prog_name
);
86 "For each argument that is a regular file, special file or\n"
87 "directory, getfacl displays the owner, the group, and the ACL.\n"
88 "For directories getfacl displays additionally the default ACL.\n"
90 "With no options specified, getfacl displays the filename, the\n"
91 "owner, the group, the setuid (s), setgid (s), and sticky (t)\n"
92 "bits if available, and both the ACL and the default ACL, if it\n"
95 "The format for ACL output is as follows:\n"
97 " # owner: name or uid\n"
98 " # group: name or uid\n"
101 " user:name or uid:perm\n"
103 " group:name or gid:perm\n"
106 " default:user::perm\n"
107 " default:user:name or uid:perm\n"
108 " default:group::perm\n"
109 " default:group:name or gid:perm\n"
110 " default:mask:perm\n"
111 " default:other:perm\n"
116 struct option longopts
[] = {
117 {"access", no_argument
, NULL
, 'a'},
118 {"all", no_argument
, NULL
, 'a'},
119 {"omit-header", no_argument
, NULL
, 'c'},
120 {"all-effective", no_argument
, NULL
, 'e'},
121 {"no-effective", no_argument
, NULL
, 'E'},
122 {"default", no_argument
, NULL
, 'd'},
123 {"dir", no_argument
, NULL
, 'd'},
124 {"help", no_argument
, NULL
, 'h'},
125 {"noname", no_argument
, NULL
, 'n'}, /* Backward compat */
126 {"numeric", no_argument
, NULL
, 'n'},
127 {"version", no_argument
, NULL
, 'V'},
128 {0, no_argument
, NULL
, 0}
130 const char *opts
= "acdeEhnV";
135 printf ("getfacl (cygwin) %d.%d.%d\n"
136 "Get POSIX ACL information\n"
137 "Copyright (C) 2000 - %s Red Hat, Inc.\n"
138 "This is free software; see the source for copying conditions. There is NO\n"
139 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
140 CYGWIN_VERSION_DLL_MAJOR
/ 1000,
141 CYGWIN_VERSION_DLL_MAJOR
% 1000,
142 CYGWIN_VERSION_DLL_MINOR
,
143 strrchr (__DATE__
, ' ') + 1);
147 main (int argc
, char **argv
)
156 int istty
= isatty (fileno (stdout
));
158 aclent_t acls
[MAX_ACL_ENTRIES
];
160 prog_name
= program_invocation_short_name
;
162 while ((c
= getopt_long (argc
, argv
, opts
, longopts
, NULL
)) != EOF
)
190 fprintf (stderr
, "Try `%s --help' for more information.\n", prog_name
);
193 if (optind
> argc
- 1)
198 for (; optind
< argc
; ++optind
)
201 mode_t mask
= S_IRWXO
, def_mask
= S_IRWXO
;
203 if (stat (argv
[optind
], &st
)
204 || (num_acls
= acl (argv
[optind
], GETACL
, MAX_ACL_ENTRIES
, acls
)) < 0)
206 fprintf (stderr
, "%s: %s: %s\n",
207 prog_name
, argv
[optind
], strerror (errno
));
213 printf ("# file: %s\n", argv
[optind
]);
216 printf ("# owner: %lu\n", (unsigned long)st
.st_uid
);
217 printf ("# group: %lu\n", (unsigned long)st
.st_gid
);
221 printf ("# owner: %s\n", username (st
.st_uid
));
222 printf ("# group: %s\n", groupname (st
.st_gid
));
224 if (st
.st_mode
& (S_ISUID
| S_ISGID
| S_ISVTX
))
225 printf ("# flags: %c%c%c\n", (st
.st_mode
& S_ISUID
) ? 's' : '-',
226 (st
.st_mode
& S_ISGID
) ? 's' : '-',
227 (st
.st_mode
& S_ISVTX
) ? 't' : '-');
229 for (i
= 0; i
< num_acls
; ++i
)
231 if (acls
[i
].a_type
== CLASS_OBJ
)
232 mask
= acls
[i
].a_perm
;
233 else if (acls
[i
].a_type
== DEF_CLASS_OBJ
)
234 def_mask
= acls
[i
].a_perm
;
236 for (i
= 0; i
< num_acls
; ++i
)
239 int print_effective
= 0;
240 mode_t effective
= acls
[i
].a_perm
;
242 if (acls
[i
].a_type
& ACL_DEFAULT
)
246 n
+= printf ("default:");
250 switch (acls
[i
].a_type
& ~ACL_DEFAULT
)
257 n
+= printf ("user:%lu:", (unsigned long)acls
[i
].a_id
);
259 n
+= printf ("user:%s:", username (acls
[i
].a_id
));
262 n
+= printf ("group::");
266 n
+= printf ("group:%lu:", (unsigned long)acls
[i
].a_id
);
268 n
+= printf ("group:%s:", groupname (acls
[i
].a_id
));
277 n
+= printf ("%s", permstr (acls
[i
].a_perm
));
278 switch (acls
[i
].a_type
)
283 effective
= acls
[i
].a_perm
& mask
;
289 effective
= acls
[i
].a_perm
& def_mask
;
293 if (print_effective
&& eopt
>= 0
294 && (eopt
> 0 || effective
!= acls
[i
].a_perm
))
301 printf ("%*s", n
, " ");
305 printf ("#effective:%s", permstr (effective
));