2 * Copyright (c) 2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Test our various libacl functions.
21 * Use IRIX semantics or Linux semantics if pertinent.
31 int irixsemantics = 0;
35 fprintf(stderr, "usage: %s\n"
36 " -i - use irix semantics\n"
44 printf("%s: %s: %s\n", prog, msg, strerror(errno));
48 dump_ace(acl_entry_t ace)
50 printf("<tag:%d,id:%d,perm:%u>",
51 ace->ae_tag, ace->ae_id, ace->ae_perm);
58 printf("ACL[n=%d]: ", acl->acl_cnt);
59 for (i=0;i<acl->acl_cnt;i++) {
60 acl_entry_t ace = &acl->acl_entry[i];
70 dump_acl_by_entry(acl_t acl)
75 printf("Get 1st entry on filled ACL\n");
76 sts = acl_get_entry(acl, ACL_FIRST_ENTRY, &ace);
77 printf("acl_get_entry -> %d\n", sts);
79 printf("1: "); dump_ace(ace); printf("\n");
82 for(i=2;i<=acl->acl_cnt+2;i++) {
83 printf("Get %dth entry on filled ACL\n", i);
84 sts = acl_get_entry(acl, ACL_NEXT_ENTRY, &ace);
85 printf("acl_get_entry -> %d\n", sts);
87 printf("%d: ",i); dump_ace(ace); printf("\n");
93 * create a full acl with entries with known bogus values
96 create_filled_acl(void)
101 acl = acl_init(ACL_MAX_ENTRIES);
103 for(i=0;i<ACL_MAX_ENTRIES;i++) {
104 acl_entry_t ace = &acl->acl_entry[i];
114 test_acl_get_qualifier(void)
116 struct acl_entry ace;
119 printf("*** test out acl_get_qualifier ***\n");
122 ace.ae_tag = ACL_USER;
126 /* make sure we can get uid and free it */
127 uidp = acl_get_qualifier(&ace);
128 printf("uid = %d\n", *uidp);
131 /* change to another valid tag with a qualifier */
132 ace.ae_tag = ACL_GROUP;
133 uidp = acl_get_qualifier(&ace);
134 printf("uid = %d\n", *uidp);
137 /* let's get some errors */
139 ace.ae_tag = ACL_USER_OBJ;
140 uidp = acl_get_qualifier(&ace);
142 printf("uidp is NULL: %s\n", strerror(errno));
144 printf("Error: uidp is NOT NULL\n");
146 uidp = acl_get_qualifier(NULL);
148 printf("uidp is NULL: %s\n", strerror(errno));
150 printf("Error: uidp is NOT NULL\n");
154 main(int argc, char **argv)
157 acl_t acl1, acl2, acl3;
162 for (p = prog; *p; p++) {
168 while ((c = getopt(argc, argv, "i")) != -1) {
180 acl_set_compat(ACL_COMPAT_IRIXGET);
183 /* ---------------------------------------------- */
184 printf("*** test out creating an ACL ***\n");
186 printf("Test acl_init(ACL_MAX_ENTRIES+1)\n");
187 acl1 = acl_init(ACL_MAX_ENTRIES+1);
189 print_err("acl_init(max+1)");
191 printf("Test acl_init(-1)\n");
194 print_err("acl_init(-1)");
196 printf("Test acl_init(0)\n");
199 print_err("acl_init(0)");
202 printf("Test acl_create_entry(NULL, ...)\n");
203 if (acl_create_entry(NULL, &ace1) == -1) {
204 print_err("acl_create_entry(NULL,ace1)");
206 printf("Test acl_create_entry(..., NULL)\n");
207 if (acl_create_entry(&acl1, NULL) == -1) {
208 print_err("acl_create_entry(NULL,ace1)");
210 printf("Test acl_create_entry(acl1, ace1)\n");
212 if (acl_create_entry(&acl1, &ace1) == -1) {
213 print_err("acl_create_entry(*null,ace1)");
218 for (i=0;i<=ACL_MAX_ENTRIES+1;i++) {
219 printf("%d: creating ace\n", i);
220 if (acl_create_entry(&acl1, &ace1) == -1) {
221 print_err("acl_create_entry");
226 /* ---------------------------------------------- */
227 printf("*** test out getting ACEs ***\n");
229 dump_acl_by_entry(acl1);
231 printf("dump empty ACL\n");
234 print_err("acl_init(0)");
236 dump_acl_by_entry(acl2);
238 printf("fill an ACL with known bogus values\n");
239 acl3 = create_filled_acl();
240 dump_acl_by_entry(acl3);
242 /* ---------------------------------------------- */
243 printf("*** test out ACL to text for empty ACL***\n");
247 acl_t empty_acl = acl_init(0);
248 text = acl_to_text(empty_acl, NULL);
249 printf("acl_to_text(empty_acl,NULL) -> \"%s\"\n", text);
250 text = acl_to_text(empty_acl, &len);
251 printf("acl_to_text(empty_acl,NULL) -> \"%s\", len = %u\n", text, len);
252 text = acl_to_text(NULL, NULL);
253 printf("acl_to_text(NULL,NULL) -> \"%s\"\n", text==NULL?"NULL":text);
255 /* NOTE: Other tests will test out the text for ACLs with ACEs.
256 * So don't have to test it here.
257 * It is simplest to choose ids not in /etc/passwd /etc/group
258 * which is done already in a script.
261 test_acl_get_qualifier();