[BACK]Return to acl_test.c CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfstests / src

File: [Development] / xfs-cmds / xfstests / src / acl_test.c (download)

Revision 1.1, Tue May 29 07:08:24 2001 UTC (16 years, 5 months ago) by tes
Branch: MAIN
CVS Tags: Linux-2_4_5-merge

Program to do libacl tests.
Started it off with testing of acl_create_entry and acl_get_entry.
Check to see it follows standard as much as possible.

/*
 * Copyright (c) 2001 Silicon Graphics, Inc.  All Rights Reserved.
 * 
 * This prog is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * 
 * This prog is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like.  Any license provided herein, whether implied or
 * otherwise, applies only to this software file.  Patent licenses, if
 * any, provided herein do not apply to combinations of this prog with
 * other software, or any other product whatsoever.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this prog; if not, write the Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 * 
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 * Mountain View, CA  94043, or:
 * 
 * http://www.sgi.com 
 * 
 * For further information regarding this notice, see: 
 * 
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
 */

/*
 * Test our various libacl functions.
 * Use IRIX semantics or Linux semantics if pertinent.
 */
 
#include "global.h"

#include <errno.h>
#include <acl.h>

char *prog;
int irixsemantics = 0;

void usage(void)
{
    fprintf(stderr, "usage: %s\n"
           "    -i - use irix semantics\n" 
           ,prog);
           
}

void
print_err(char *msg)
{
    printf("%s: %s: %s\n", prog, msg, strerror(errno));
}

void
dump_ace(acl_entry_t ace)
{
    printf("<tag:%d,id:%d,perm:%u>", 
	    ace->ae_tag, ace->ae_id, ace->ae_perm);
}

void
dump_acl(acl_t acl)
{
    int i;
    printf("ACL[n=%d]: ", acl->acl_cnt);
    for (i=0;i<acl->acl_cnt;i++) {
	acl_entry_t ace = &acl->acl_entry[i];
	printf("%d: ", i);
	dump_ace(ace);
	printf(" ");
    }
    printf("\n");

}

void
dump_acl_by_entry(acl_t acl)
{
    int sts, i;
    acl_entry_t ace; 

    printf("Get 1st entry on filled ACL\n");
    sts = acl_get_entry(acl, ACL_FIRST_ENTRY, &ace);
    printf("acl_get_entry -> %d\n", sts);
    if (sts > 0) {
	printf("1: "); dump_ace(ace); printf("\n");
    }

    for(i=2;i<=acl->acl_cnt+2;i++) {
	printf("Get %dth entry on filled ACL\n", i);
	sts = acl_get_entry(acl, ACL_NEXT_ENTRY, &ace);
	printf("acl_get_entry -> %d\n", sts);
	if (sts > 0) {
	    printf("%d: ",i); dump_ace(ace); printf("\n");
	}
    }
}

/*
 * create a full acl with entries with known bogus values
 */
acl_t
create_filled_acl(void)
{
    acl_t acl;
    int i;

    acl = acl_init(ACL_MAX_ENTRIES);	

    for(i=0;i<ACL_MAX_ENTRIES;i++) {
	acl_entry_t ace = &acl->acl_entry[i];
	ace->ae_tag = i;
	ace->ae_id = i+1;
	ace->ae_perm = i+2;
	acl->acl_cnt++;
    }
    return acl;
}

int
main(int argc, char **argv)
{
	int c, i;
	acl_t acl1, acl2, acl3;
	acl_entry_t ace1;

        prog = basename(argv[0]);

	while ((c = getopt(argc, argv, "i")) != -1) {
		switch (c) {
		case 'i':
			irixsemantics = 1;
			break;
		case '?':
                        usage();
			return 1;
		}
	}

	if (irixsemantics) {
	    acl_set_compat(ACL_COMPAT_IRIXGET);
	}

        /* ---------------------------------------------- */
        printf("*** test out creating an ACL ***\n");

	printf("Test acl_init(ACL_MAX_ENTRIES+1)\n");
	acl1 = acl_init(ACL_MAX_ENTRIES+1);
	if (acl1 == NULL) {
	    print_err("acl_init(max+1)");
	}
	printf("Test acl_init(-1)\n");
	acl1 = acl_init(-1);
	if (acl1 == NULL) {
	    print_err("acl_init(-1)");
	}
	printf("Test acl_init(0)\n");
	acl1 = acl_init(0);
	if (acl1 == NULL) {
	    print_err("acl_init(0)");
	}

	printf("Test acl_create_entry(NULL, ...)\n");
	if (acl_create_entry(NULL, &ace1) == -1) {
	    print_err("acl_create_entry(NULL,ace1)");
	}
	printf("Test acl_create_entry(..., NULL)\n");
	if (acl_create_entry(&acl1, NULL) == -1) {
	    print_err("acl_create_entry(NULL,ace1)");
	}
	printf("Test acl_create_entry(acl1, ace1)\n");
	acl1 = NULL;
	if (acl_create_entry(&acl1, &ace1) == -1) {
	    print_err("acl_create_entry(*null,ace1)");
	}

	acl_free(acl1);
	acl1 = acl_init(0);
	for (i=0;i<=ACL_MAX_ENTRIES+1;i++) {
	    printf("%d: creating ace\n", i);
	    if (acl_create_entry(&acl1, &ace1) == -1) {
		print_err("acl_create_entry");
	    }
	    dump_acl(acl1);
	}

        /* ---------------------------------------------- */
        printf("*** test out getting ACEs ***\n");

	dump_acl_by_entry(acl1);

	printf("dump empty ACL\n");
	acl2 = acl_init(0);
	if (acl2 == NULL) {
	    print_err("acl_init(0)");
	}
	dump_acl_by_entry(acl2);

	printf("fill an ACL with known bogus values\n");
	acl3 = create_filled_acl();	
	dump_acl_by_entry(acl3);

        /* ---------------------------------------------- */

	return 0;
}