3 Written by Corinna Vinschen <vinschen@redhat.com>
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
18 #include <acl/libacl.h>
20 #include <cygwin/version.h>
24 static char *prog_name
;
29 static char ubuf
[256];
32 if ((pw
= getpwuid (uid
)))
33 snprintf (ubuf
, sizeof ubuf
, "%s", pw
->pw_name
);
35 sprintf (ubuf
, "%lu <unknown>", (unsigned long)uid
);
42 static char gbuf
[256];
45 if ((gr
= getgrgid (gid
)))
46 snprintf (gbuf
, sizeof gbuf
, "%s", gr
->gr_name
);
48 sprintf (gbuf
, "%lu <unknown>", (unsigned long)gid
);
52 static void __attribute__ ((__noreturn__
))
55 fprintf (stream
, "Usage: %s [-adn] FILE [FILE2...]\n"
57 "Display file and directory access control lists (ACLs).\n"
59 " -a, --access display the file access control list only\n"
60 " -d, --default display the default access control list only\n"
61 " -c, --omit-header do not display the comment header\n"
62 " -e, --all-effective print all effective rights\n"
63 " -E, --no-effective print no effective rights\n"
64 " -n, --numeric print numeric user/group identifiers\n"
65 " -V, --version print version and exit\n"
66 " -h, --help this help text\n"
68 "When multiple files are specified on the command line, a blank\n"
69 "line separates the ACLs for each file.\n", prog_name
);
73 "For each argument that is a regular file, special file or\n"
74 "directory, getfacl displays the owner, the group, and the ACL.\n"
75 "For directories getfacl displays additionally the default ACL.\n"
77 "With no options specified, getfacl displays the filename, the\n"
78 "owner, the group, the setuid (s), setgid (s), and sticky (t)\n"
79 "bits if available, and both the ACL and the default ACL, if it\n"
82 "The format for ACL output is as follows:\n"
84 " # owner: name or uid\n"
85 " # group: name or uid\n"
88 " user:name or uid:perm\n"
90 " group:name or gid:perm\n"
93 " default:user::perm\n"
94 " default:user:name or uid:perm\n"
95 " default:group::perm\n"
96 " default:group:name or gid:perm\n"
97 " default:mask::perm\n"
98 " default:other::perm\n"
101 exit (stream
== stdout
? 0 : 1);
104 struct option longopts
[] = {
105 {"access", no_argument
, NULL
, 'a'},
106 {"all", no_argument
, NULL
, 'a'},
107 {"omit-header", no_argument
, NULL
, 'c'},
108 {"all-effective", no_argument
, NULL
, 'e'},
109 {"no-effective", no_argument
, NULL
, 'E'},
110 {"default", no_argument
, NULL
, 'd'},
111 {"dir", no_argument
, NULL
, 'd'},
112 {"help", no_argument
, NULL
, 'h'},
113 {"noname", no_argument
, NULL
, 'n'}, /* Backward compat */
114 {"numeric", no_argument
, NULL
, 'n'},
115 {"version", no_argument
, NULL
, 'V'},
116 {0, no_argument
, NULL
, 0}
118 const char *opts
= "acdeEhnV";
123 printf ("getfacl (cygwin) %d.%d.%d\n"
124 "Get POSIX ACL information\n"
125 "Copyright (C) 2000 - %s Cygwin Authors\n"
126 "This is free software; see the source for copying conditions. There is NO\n"
127 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
128 CYGWIN_VERSION_DLL_MAJOR
/ 1000,
129 CYGWIN_VERSION_DLL_MAJOR
% 1000,
130 CYGWIN_VERSION_DLL_MINOR
,
131 strrchr (__DATE__
, ' ') + 1);
135 main (int argc
, char **argv
)
145 int istty
= isatty (fileno (stdout
));
148 prog_name
= program_invocation_short_name
;
150 while ((c
= getopt_long (argc
, argv
, opts
, longopts
, NULL
)) != EOF
)
177 fprintf (stderr
, "Try `%s --help' for more information.\n", prog_name
);
180 if (optind
> argc
- 1)
183 options
|= TEXT_NUMERIC_IDS
;
185 options
|= TEXT_ALL_EFFECTIVE
;
187 options
|= TEXT_SOME_EFFECTIVE
;
189 options
|= TEXT_SMART_INDENT
;
190 for (; optind
< argc
; ++optind
)
192 acl_t access_acl
= NULL
, default_acl
= NULL
;
193 char *access_txt
, *default_txt
;
195 if (stat (argv
[optind
], &st
)
197 && !(access_acl
= acl_get_file (argv
[optind
], ACL_TYPE_ACCESS
)))
198 || (!aopt
&& S_ISDIR (st
.st_mode
)
199 && !(default_acl
= acl_get_file (argv
[optind
],
204 printf ("# file: %s\n", argv
[optind
]);
207 printf ("# owner: %lu\n", (unsigned long)st
.st_uid
);
208 printf ("# group: %lu\n", (unsigned long)st
.st_gid
);
212 printf ("# owner: %s\n", username (st
.st_uid
));
213 printf ("# group: %s\n", groupname (st
.st_gid
));
215 if (st
.st_mode
& (S_ISUID
| S_ISGID
| S_ISVTX
))
216 printf ("# flags: %c%c%c\n", (st
.st_mode
& S_ISUID
) ? 's' : '-',
217 (st
.st_mode
& S_ISGID
) ? 's' : '-',
218 (st
.st_mode
& S_ISVTX
) ? 't' : '-');
222 if (!(access_txt
= acl_to_any_text (access_acl
, NULL
, '\n', options
)))
224 acl_free (access_acl
);
227 printf ("%s\n", access_txt
);
228 acl_free (access_txt
);
229 acl_free (access_acl
);
233 if (!(default_txt
= acl_to_any_text (default_acl
, "default:",
236 acl_free (default_acl
);
239 printf ("%s\n", default_txt
);
240 acl_free (default_txt
);
241 acl_free (default_acl
);
246 fprintf (stderr
, "%s: %s: %s\n\n",
247 prog_name
, argv
[optind
], strerror (errno
));