]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/getfacl.c
3 Copyright 2000, 2001 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>
27 pbuf
[0] = (perm
& S_IREAD
) ? 'r' : '-';
28 pbuf
[1] = (perm
& S_IWRITE
) ? 'w' : '-';
29 pbuf
[2] = (perm
& S_IEXEC
) ? 'x' : '-';
37 static char ubuf
[256];
40 if ((pw
= getpwuid (uid
)))
41 strcpy (ubuf
, pw
->pw_name
);
43 sprintf (ubuf
, "%d <unknown>", uid
);
50 static char gbuf
[256];
53 if ((gr
= getgrgid (gid
)))
54 strcpy (gbuf
, gr
->gr_name
);
56 sprintf (gbuf
, "%d <unknown>", gid
);
60 #define pn(txt) fprintf (fp, txt "\n", name)
61 #define p(txt) fprintf (fp, txt "\n")
64 usage (const char *name
, int help
)
66 FILE *fp
= help
? stdout
: stderr
;
68 pn ("usage: %s [-adn] file...");
70 pn ("Try `%s --help' for more information.");
74 p ("Display file and directory access control lists (ACLs).");
76 p ("For each argument that is a regular file, special file or");
77 p ("directory, getfacl displays the owner, the group, and the ACL.");
78 p ("For directories getfacl displays additionally the default ACL.");
80 p ("With no options specified, getfacl displays the filename, the");
81 p ("owner, the group, and both the ACL and the default ACL, if it");
84 p ("The following options are supported:");
86 p ("-a Display the filename, the owner, the group, and the ACL");
89 p ("-d Display the filename, the owner, the group, and the default");
90 p (" ACL of the directory, if it exists.");
92 p ("-n Display user and group IDs instead of names.");
94 p ("The format for ACL output is as follows:");
95 p (" # file: filename");
96 p (" # owner: name or uid");
97 p (" # group: name or uid");
99 p (" user:name or uid:perm");
101 p (" group:name or gid:perm");
104 p (" default:user::perm");
105 p (" default:user:name or uid:perm");
106 p (" default:group::perm");
107 p (" default:group:name or gid:perm");
108 p (" default:mask:perm");
109 p (" default:other:perm");
111 p ("When multiple files are specified on the command line, a blank");
112 p ("line separates the ACLs for each file.");
117 struct option longopts
[] = {
118 {"help", no_argument
, NULL
, 'h'},
119 {0, no_argument
, NULL
, 0}
123 main (int argc
, char **argv
)
132 aclent_t acls
[MAX_ACL_ENTRIES
];
134 while ((c
= getopt_long (argc
, argv
, "adn", longopts
, NULL
)) != EOF
)
147 return usage (argv
[0], 1);
149 return usage (argv
[0], 0);
151 if (optind
> argc
- 1)
152 return usage (argv
[0], 0);
153 while ((c
= optind
++) < argc
)
155 if (stat (argv
[c
], &st
))
163 printf ("# file: %s\n", argv
[c
]);
166 printf ("# owner: %d\n", st
.st_uid
);
167 printf ("# group: %d\n", st
.st_gid
);
171 printf ("# owner: %s\n", username (st
.st_uid
));
172 printf ("# group: %s\n", groupname (st
.st_gid
));
174 if ((c
= acl (argv
[c
], GETACL
, MAX_ACL_ENTRIES
, acls
)) < 0)
179 for (i
= 0; i
< c
; ++i
)
181 if (acls
[i
].a_type
& ACL_DEFAULT
)
189 switch (acls
[i
].a_type
& ~ACL_DEFAULT
)
196 printf ("user:%d:", acls
[i
].a_id
);
198 printf ("user:%s:", username (acls
[i
].a_id
));
205 printf ("group:%d:", acls
[i
].a_id
);
207 printf ("group:%s:", groupname (acls
[i
].a_id
));
216 printf ("%s\n", permstr (acls
[i
].a_perm
));
This page took 0.048096 seconds and 6 git commands to generate.