]> sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/getfacl.c
Cleanup formatting on some files. Remove excessive whitespace.
[newlib-cygwin.git] / winsup / utils / getfacl.c
1
2 #include <pwd.h>
3 #include <grp.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <getopt.h>
7 #include <sys/types.h>
8 #include <sys/acl.h>
9 #include <sys/stat.h>
10
11 char *
12 permstr (mode_t perm)
13 {
14 static char pbuf[4];
15
16 pbuf[0] = (perm & S_IREAD) ? 'r' : '-';
17 pbuf[1] = (perm & S_IWRITE) ? 'w' : '-';
18 pbuf[2] = (perm & S_IEXEC) ? 'x' : '-';
19 pbuf[3] = '\0';
20 return pbuf;
21 }
22
23 #if 0
24 char *
25 username (uid_t uid)
26 {
27 static char ubuf[256];
28 struct passwd *pw;
29
30 if (pw = getpwuid (uid))
31 strcpy (ubuf, pw->pw_name);
32 else
33 strcpy (ubuf, "<unknown>");
34 }
35
36 char *
37 groupname (gid_t gid)
38 {
39 static char gbuf[256];
40 struct group *gr;
41
42 if (gr = getgruid (gid))
43 strcpy (gbuf, gr->gr_name);
44 else
45 strcpy (gbuf, "<unknown>");
46 }
47 #endif
48
49 int
50 main (int argc, char **argv)
51 {
52 extern int optind;
53 int c, i;
54 int aopt = 0;
55 int dopt = 0;
56 int first = 1;
57 struct stat st;
58 aclent_t acls[MAX_ACL_ENTRIES];
59
60 while ((c = getopt (argc, argv, "ad")) != EOF)
61 switch (c)
62 {
63 case 'a':
64 aopt = 1;
65 break;
66 case 'd':
67 dopt = 1;
68 break;
69 default:
70 fprintf (stderr, "usage: %s [-ad] file...\n", argv[0]);
71 return 1;
72 }
73 while ((c = optind++) < argc)
74 {
75 if (stat (argv[c], &st))
76 {
77 perror (argv[0]);
78 continue;
79 }
80 if (!first)
81 putchar ('\n');
82 first = 0;
83 printf ("# file: %s\n", argv[c]);
84 printf ("# owner: %d\n", st.st_uid);
85 printf ("# group: %d\n", st.st_gid);
86 if ((c = acl (argv[c], GETACL, MAX_ACL_ENTRIES, acls)) < 0)
87 {
88 perror (argv[0]);
89 continue;
90 }
91 for (i = 0; i < c; ++i)
92 {
93 if (acls[i].a_type & ACL_DEFAULT)
94 {
95 if (aopt)
96 continue;
97 printf ("default:");
98 }
99 else if (dopt)
100 continue;
101 switch (acls[i].a_type & ~ACL_DEFAULT)
102 {
103 case USER_OBJ:
104 printf ("user::");
105 break;
106 case USER:
107 printf ("user:%d:", acls[i].a_id);
108 break;
109 case GROUP_OBJ:
110 printf ("group::");
111 break;
112 case GROUP:
113 printf ("group:%d:", acls[i].a_id);
114 break;
115 case CLASS_OBJ:
116 printf ("mask::");
117 break;
118 case OTHER_OBJ:
119 printf ("other::");
120 break;
121 }
122 printf ("%s\n", permstr (acls[i].a_perm));
123 }
124 }
125 return 0;
126 }
This page took 0.043862 seconds and 6 git commands to generate.