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.
44 int irixsemantics = 0;
48 fprintf(stderr, "usage: %s\n"
49 " -i - use irix semantics\n"
57 printf("%s: %s: %s\n", prog, msg, strerror(errno));
61 dump_ace(acl_entry_t ace)
63 printf("<tag:%d,id:%d,perm:%u>",
64 ace->ae_tag, ace->ae_id, ace->ae_perm);
71 printf("ACL[n=%d]: ", acl->acl_cnt);
72 for (i=0;i<acl->acl_cnt;i++) {
73 acl_entry_t ace = &acl->acl_entry[i];
83 dump_acl_by_entry(acl_t acl)
88 printf("Get 1st entry on filled ACL\n");
89 sts = acl_get_entry(acl, ACL_FIRST_ENTRY, &ace);
90 printf("acl_get_entry -> %d\n", sts);
92 printf("1: "); dump_ace(ace); printf("\n");
95 for(i=2;i<=acl->acl_cnt+2;i++) {
96 printf("Get %dth entry on filled ACL\n", i);
97 sts = acl_get_entry(acl, ACL_NEXT_ENTRY, &ace);
98 printf("acl_get_entry -> %d\n", sts);
100 printf("%d: ",i); dump_ace(ace); printf("\n");
106 * create a full acl with entries with known bogus values
109 create_filled_acl(void)
114 acl = acl_init(ACL_MAX_ENTRIES);
116 for(i=0;i<ACL_MAX_ENTRIES;i++) {
117 acl_entry_t ace = &acl->acl_entry[i];
127 test_acl_get_qualifier(void)
129 struct acl_entry ace;
132 printf("*** test out acl_get_qualifier ***\n");
135 ace.ae_tag = ACL_USER;
139 /* make sure we can get uid and free it */
140 uidp = acl_get_qualifier(&ace);
141 printf("uid = %d\n", *uidp);
144 /* change to another valid tag with a qualifier */
145 ace.ae_tag = ACL_GROUP;
146 uidp = acl_get_qualifier(&ace);
147 printf("uid = %d\n", *uidp);
150 /* let's get some errors */
152 ace.ae_tag = ACL_USER_OBJ;
153 uidp = acl_get_qualifier(&ace);
155 printf("uidp is NULL: %s\n", strerror(errno));
157 printf("Error: uidp is NOT NULL\n");
159 uidp = acl_get_qualifier(NULL);
161 printf("uidp is NULL: %s\n", strerror(errno));
163 printf("Error: uidp is NOT NULL\n");
167 main(int argc, char **argv)
170 acl_t acl1, acl2, acl3;
173 prog = basename(argv[0]);
175 while ((c = getopt(argc, argv, "i")) != -1) {
187 acl_set_compat(ACL_COMPAT_IRIXGET);
190 /* ---------------------------------------------- */
191 printf("*** test out creating an ACL ***\n");
193 printf("Test acl_init(ACL_MAX_ENTRIES+1)\n");
194 acl1 = acl_init(ACL_MAX_ENTRIES+1);
196 print_err("acl_init(max+1)");
198 printf("Test acl_init(-1)\n");
201 print_err("acl_init(-1)");
203 printf("Test acl_init(0)\n");
206 print_err("acl_init(0)");
209 printf("Test acl_create_entry(NULL, ...)\n");
210 if (acl_create_entry(NULL, &ace1) == -1) {
211 print_err("acl_create_entry(NULL,ace1)");
213 printf("Test acl_create_entry(..., NULL)\n");
214 if (acl_create_entry(&acl1, NULL) == -1) {
215 print_err("acl_create_entry(NULL,ace1)");
217 printf("Test acl_create_entry(acl1, ace1)\n");
219 if (acl_create_entry(&acl1, &ace1) == -1) {
220 print_err("acl_create_entry(*null,ace1)");
225 for (i=0;i<=ACL_MAX_ENTRIES+1;i++) {
226 printf("%d: creating ace\n", i);
227 if (acl_create_entry(&acl1, &ace1) == -1) {
228 print_err("acl_create_entry");
233 /* ---------------------------------------------- */
234 printf("*** test out getting ACEs ***\n");
236 dump_acl_by_entry(acl1);
238 printf("dump empty ACL\n");
241 print_err("acl_init(0)");
243 dump_acl_by_entry(acl2);
245 printf("fill an ACL with known bogus values\n");
246 acl3 = create_filled_acl();
247 dump_acl_by_entry(acl3);
249 /* ---------------------------------------------- */
250 printf("*** test out ACL to text for empty ACL***\n");
254 acl_t empty_acl = acl_init(0);
255 text = acl_to_text(empty_acl, NULL);
256 printf("acl_to_text(empty_acl,NULL) -> \"%s\"\n", text);
257 text = acl_to_text(empty_acl, &len);
258 printf("acl_to_text(empty_acl,NULL) -> \"%s\", len = %u\n", text, len);
259 text = acl_to_text(NULL, NULL);
260 printf("acl_to_text(NULL,NULL) -> \"%s\"\n", text==NULL?"NULL":text);
262 /* NOTE: Other tests will test out the text for ACLs with ACEs.
263 * So don't have to test it here.
264 * It is simplest to choose ids not in /etc/passwd /etc/group
265 * which is done already in a script.
268 test_acl_get_qualifier();