]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/getfacl.c
3 Copyright 2000, 2001, 2002 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>
23 static const char version
[] = "$Revision$";
24 static char *prog_name
;
31 pbuf
[0] = (perm
& S_IROTH
) ? 'r' : '-';
32 pbuf
[1] = (perm
& S_IWOTH
) ? 'w' : '-';
33 pbuf
[2] = (perm
& S_IXOTH
) ? 'x' : '-';
41 static char ubuf
[256];
44 if ((pw
= getpwuid (uid
)))
45 strcpy (ubuf
, pw
->pw_name
);
47 sprintf (ubuf
, "%lu <unknown>", (unsigned long)uid
);
54 static char gbuf
[256];
57 if ((gr
= getgrgid (gid
)))
58 strcpy (gbuf
, gr
->gr_name
);
60 sprintf (gbuf
, "%lu <unknown>", (unsigned long)gid
);
67 fprintf (stream
, "Usage: %s [-adn] FILE [FILE2...]\n"
68 "Display file and directory access control lists (ACLs).\n"
70 " -a, --all display the filename, the owner, the group, and\n"
71 " the ACL of the file\n"
72 " -d, --dir display the filename, the owner, the group, and\n"
73 " the default ACL of the directory, if it exists\n"
74 " -h, --help output usage information and exit\n"
75 " -n, --noname display user and group IDs instead of names\n"
76 " -v, --version output version information and exit\n"
78 "When multiple files are specified on the command line, a blank\n"
79 "line separates the ACLs for each file.\n", prog_name
);
83 "For each argument that is a regular file, special file or\n"
84 "directory, getfacl displays the owner, the group, and the ACL.\n"
85 "For directories getfacl displays additionally the default ACL.\n"
87 "With no options specified, getfacl displays the filename, the\n"
88 "owner, the group, and both the ACL and the default ACL, if it\n"
91 "The format for ACL output is as follows:\n"
93 " # owner: name or uid\n"
94 " # group: name or uid\n"
96 " user:name or uid:perm\n"
98 " group:name or gid:perm\n"
101 " default:user::perm\n"
102 " default:user:name or uid:perm\n"
103 " default:group::perm\n"
104 " default:group:name or gid:perm\n"
105 " default:mask:perm\n"
106 " default:other:perm\n"
111 struct option longopts
[] = {
112 {"all", no_argument
, NULL
, 'a'},
113 {"dir", no_argument
, NULL
, 'd'},
114 {"help", no_argument
, NULL
, 'h'},
115 {"noname", no_argument
, NULL
, 'n'},
116 {"version", no_argument
, NULL
, 'v'},
117 {0, no_argument
, NULL
, 0}
123 const char *v
= strchr (version
, ':');
133 len
= strchr (v
, ' ') - v
;
136 getfacl (cygwin) %.*s\n\
138 Copyright (c) 2000, 2001, 2002 Red Hat, Inc.\n\
140 ", len
, v
, __DATE__
);
144 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 while ((c
= optind
++) < argc
)
192 if (stat (argv
[c
], &st
))
200 printf ("# file: %s\n", argv
[c
]);
203 printf ("# owner: %lu\n", (unsigned long)st
.st_uid
);
204 printf ("# group: %lu\n", (unsigned long)st
.st_gid
);
208 printf ("# owner: %s\n", username (st
.st_uid
));
209 printf ("# group: %s\n", groupname (st
.st_gid
));
211 if ((c
= acl (argv
[c
], GETACL
, MAX_ACL_ENTRIES
, acls
)) < 0)
216 for (i
= 0; i
< c
; ++i
)
218 if (acls
[i
].a_type
& ACL_DEFAULT
)
226 switch (acls
[i
].a_type
& ~ACL_DEFAULT
)
233 printf ("user:%lu\n", (unsigned long)acls
[i
].a_id
);
235 printf ("user:%s:", username (acls
[i
].a_id
));
242 printf ("group:%lu\n", (unsigned long)acls
[i
].a_id
);
244 printf ("group:%s:", groupname (acls
[i
].a_id
));
253 printf ("%s\n", permstr (acls
[i
].a_perm
));
This page took 0.045027 seconds and 6 git commands to generate.