2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2000-10-28 07:00:00 +02:00
|
|
|
char *
|
|
|
|
permstr (mode_t perm)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
static char pbuf[4];
|
|
|
|
|
|
|
|
pbuf[0] = (perm & S_IREAD) ? 'r' : '-';
|
|
|
|
pbuf[1] = (perm & S_IWRITE) ? 'w' : '-';
|
|
|
|
pbuf[2] = (perm & S_IEXEC) ? 'x' : '-';
|
|
|
|
pbuf[3] = '\0';
|
|
|
|
return pbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2000-10-28 07:00:00 +02:00
|
|
|
char *
|
|
|
|
username (uid_t uid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
static char ubuf[256];
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
if (pw = getpwuid (uid))
|
|
|
|
strcpy (ubuf, pw->pw_name);
|
|
|
|
else
|
|
|
|
strcpy (ubuf, "<unknown>");
|
|
|
|
}
|
|
|
|
|
2000-10-28 07:00:00 +02:00
|
|
|
char *
|
|
|
|
groupname (gid_t gid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
static char gbuf[256];
|
|
|
|
struct group *gr;
|
|
|
|
|
|
|
|
if (gr = getgruid (gid))
|
|
|
|
strcpy (gbuf, gr->gr_name);
|
|
|
|
else
|
|
|
|
strcpy (gbuf, "<unknown>");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
extern int optind;
|
|
|
|
int c, i;
|
|
|
|
int aopt = 0;
|
|
|
|
int dopt = 0;
|
|
|
|
int first = 1;
|
|
|
|
struct stat st;
|
|
|
|
aclent_t acls[MAX_ACL_ENTRIES];
|
|
|
|
|
|
|
|
while ((c = getopt (argc, argv, "ad")) != EOF)
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'a':
|
2000-10-28 07:00:00 +02:00
|
|
|
aopt = 1;
|
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
case 'd':
|
2000-10-28 07:00:00 +02:00
|
|
|
dopt = 1;
|
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
default:
|
2000-10-28 07:00:00 +02:00
|
|
|
fprintf (stderr, "usage: %s [-ad] file...\n", argv[0]);
|
|
|
|
return 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
while ((c = optind++) < argc)
|
|
|
|
{
|
|
|
|
if (stat (argv[c], &st))
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
perror (argv[0]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!first)
|
|
|
|
putchar ('\n');
|
2000-02-17 20:38:33 +01:00
|
|
|
first = 0;
|
|
|
|
printf ("# file: %s\n", argv[c]);
|
|
|
|
printf ("# owner: %d\n", st.st_uid);
|
|
|
|
printf ("# group: %d\n", st.st_gid);
|
|
|
|
if ((c = acl (argv[c], GETACL, MAX_ACL_ENTRIES, acls)) < 0)
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
perror (argv[0]);
|
|
|
|
continue;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
for (i = 0; i < c; ++i)
|
2000-10-28 07:00:00 +02:00
|
|
|
{
|
|
|
|
if (acls[i].a_type & ACL_DEFAULT)
|
|
|
|
{
|
|
|
|
if (aopt)
|
|
|
|
continue;
|
|
|
|
printf ("default:");
|
|
|
|
}
|
|
|
|
else if (dopt)
|
|
|
|
continue;
|
|
|
|
switch (acls[i].a_type & ~ACL_DEFAULT)
|
|
|
|
{
|
|
|
|
case USER_OBJ:
|
|
|
|
printf ("user::");
|
|
|
|
break;
|
|
|
|
case USER:
|
|
|
|
printf ("user:%d:", acls[i].a_id);
|
|
|
|
break;
|
|
|
|
case GROUP_OBJ:
|
|
|
|
printf ("group::");
|
|
|
|
break;
|
|
|
|
case GROUP:
|
|
|
|
printf ("group:%d:", acls[i].a_id);
|
|
|
|
break;
|
|
|
|
case CLASS_OBJ:
|
|
|
|
printf ("mask::");
|
|
|
|
break;
|
|
|
|
case OTHER_OBJ:
|
|
|
|
printf ("other::");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf ("%s\n", permstr (acls[i].a_perm));
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|