2 * Copyright (c) 2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This prog is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This prog is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this prog with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this prog; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Test our various libacl functions.
35 * Use IRIX semantics or Linux semantics if pertinent.
45 int irixsemantics = 0;
49 fprintf(stderr, "usage: %s\n"
50 " -i - use irix semantics\n"
58 printf("%s: %s: %s\n", prog, msg, strerror(errno));
62 dump_ace(acl_entry_t ace)
64 printf("<tag:%d,id:%d,perm:%u>",
65 ace->ae_tag, ace->ae_id, ace->ae_perm);
72 printf("ACL[n=%d]: ", acl->acl_cnt);
73 for (i=0;i<acl->acl_cnt;i++) {
74 acl_entry_t ace = &acl->acl_entry[i];
84 dump_acl_by_entry(acl_t acl)
89 printf("Get 1st entry on filled ACL\n");
90 sts = acl_get_entry(acl, ACL_FIRST_ENTRY, &ace);
91 printf("acl_get_entry -> %d\n", sts);
93 printf("1: "); dump_ace(ace); printf("\n");
96 for(i=2;i<=acl->acl_cnt+2;i++) {
97 printf("Get %dth entry on filled ACL\n", i);
98 sts = acl_get_entry(acl, ACL_NEXT_ENTRY, &ace);
99 printf("acl_get_entry -> %d\n", sts);
101 printf("%d: ",i); dump_ace(ace); printf("\n");
107 * create a full acl with entries with known bogus values
110 create_filled_acl(void)
115 acl = acl_init(ACL_MAX_ENTRIES);
117 for(i=0;i<ACL_MAX_ENTRIES;i++) {
118 acl_entry_t ace = &acl->acl_entry[i];
128 test_acl_get_qualifier(void)
130 struct acl_entry ace;
133 printf("*** test out acl_get_qualifier ***\n");
136 ace.ae_tag = ACL_USER;
140 /* make sure we can get uid and free it */
141 uidp = acl_get_qualifier(&ace);
142 printf("uid = %d\n", *uidp);
145 /* change to another valid tag with a qualifier */
146 ace.ae_tag = ACL_GROUP;
147 uidp = acl_get_qualifier(&ace);
148 printf("uid = %d\n", *uidp);
151 /* let's get some errors */
153 ace.ae_tag = ACL_USER_OBJ;
154 uidp = acl_get_qualifier(&ace);
156 printf("uidp is NULL: %s\n", strerror(errno));
158 printf("Error: uidp is NOT NULL\n");
160 uidp = acl_get_qualifier(NULL);
162 printf("uidp is NULL: %s\n", strerror(errno));
164 printf("Error: uidp is NOT NULL\n");
168 main(int argc, char **argv)
171 acl_t acl1, acl2, acl3;
174 prog = basename(argv[0]);
176 while ((c = getopt(argc, argv, "i")) != -1) {
188 acl_set_compat(ACL_COMPAT_IRIXGET);
191 /* ---------------------------------------------- */
192 printf("*** test out creating an ACL ***\n");
194 printf("Test acl_init(ACL_MAX_ENTRIES+1)\n");
195 acl1 = acl_init(ACL_MAX_ENTRIES+1);
197 print_err("acl_init(max+1)");
199 printf("Test acl_init(-1)\n");
202 print_err("acl_init(-1)");
204 printf("Test acl_init(0)\n");
207 print_err("acl_init(0)");
210 printf("Test acl_create_entry(NULL, ...)\n");
211 if (acl_create_entry(NULL, &ace1) == -1) {
212 print_err("acl_create_entry(NULL,ace1)");
214 printf("Test acl_create_entry(..., NULL)\n");
215 if (acl_create_entry(&acl1, NULL) == -1) {
216 print_err("acl_create_entry(NULL,ace1)");
218 printf("Test acl_create_entry(acl1, ace1)\n");
220 if (acl_create_entry(&acl1, &ace1) == -1) {
221 print_err("acl_create_entry(*null,ace1)");
226 for (i=0;i<=ACL_MAX_ENTRIES+1;i++) {
227 printf("%d: creating ace\n", i);
228 if (acl_create_entry(&acl1, &ace1) == -1) {
229 print_err("acl_create_entry");
234 /* ---------------------------------------------- */
235 printf("*** test out getting ACEs ***\n");
237 dump_acl_by_entry(acl1);
239 printf("dump empty ACL\n");
242 print_err("acl_init(0)");
244 dump_acl_by_entry(acl2);
246 printf("fill an ACL with known bogus values\n");
247 acl3 = create_filled_acl();
248 dump_acl_by_entry(acl3);
250 /* ---------------------------------------------- */
251 printf("*** test out ACL to text for empty ACL***\n");
255 acl_t empty_acl = acl_init(0);
256 text = acl_to_text(empty_acl, NULL);
257 printf("acl_to_text(empty_acl,NULL) -> \"%s\"\n", text);
258 text = acl_to_text(empty_acl, &len);
259 printf("acl_to_text(empty_acl,NULL) -> \"%s\", len = %u\n", text, len);
260 text = acl_to_text(NULL, NULL);
261 printf("acl_to_text(NULL,NULL) -> \"%s\"\n", text==NULL?"NULL":text);
263 /* NOTE: Other tests will test out the text for ACLs with ACEs.
264 * So don't have to test it here.
265 * It is simplest to choose ids not in /etc/passwd /etc/group
266 * which is done already in a script.
269 test_acl_get_qualifier();