acl.c

来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 895 行 · 第 1/2 页

C
895
字号
/* acl.c - General Access Control routines */#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/dsap/common/RCS/acl.c,v 9.0 1992/06/16 12:12:39 isode Rel $";#endif/* * $Header: /xtel/isode/isode/dsap/common/RCS/acl.c,v 9.0 1992/06/16 12:12:39 isode Rel $ * * * $Log: acl.c,v $ * Revision 9.0  1992/06/16  12:12:39  isode * Release 8.0 * *//* *                                NOTICE * *    Acquisition, use, and distribution of this module and related *    materials are subject to the restrictions of a license agreement. *    Consult the Preface in the User's Manual for the full terms of *    this agreement. * *//* LINTLIBRARY */#include "quipu/util.h"#include "quipu/entry.h"#include "cmd_srch.h"#include "quipu/syntaxes.h"extern char dsa_mode;static struct acl_info * defaultacl = (struct acl_info *) NULL;static acl_attr_free ();void acl_info_free ();static int acl_attr_cmp ();static int acl_attr_comp_cmp ();int acl_info_cmp ();static int acl_info_comp_cmp ();static struct acl * str2acl_aux ();static acl_free (aclptr)register struct acl * aclptr;{	acl_info_free (aclptr->ac_child);	acl_info_free (aclptr->ac_entry);	acl_info_free (aclptr->ac_default);	acl_attr_free (aclptr);	free ((char *) aclptr);}static acl_attr_free (aclptr)register struct acl * aclptr;{register struct acl_attr * ptr;register struct acl_attr * next;	for (ptr=aclptr->ac_attributes ; ptr!=NULLACL_ATTR; ptr=next ) {		next = ptr->aa_next;		oid_seq_free (ptr->aa_types);		if (ptr->aa_acl != aclptr->ac_default)			acl_info_free (ptr->aa_acl);		free ((char *) ptr);	}}void acl_info_free (aclptr)register struct acl_info * aclptr;{register struct acl_info * ptr;register struct acl_info * next;	if (test_acl_default(aclptr) == OK)		return;	for (ptr=aclptr ; ptr!=NULLACL_INFO; ptr=next ) {		next = ptr->acl_next;		dn_seq_free (ptr->acl_name);		free ((char *) ptr);	}}static int acl_default_cmp (a)struct acl	* a;{register struct acl_attr * ptr;	/* Is 'a' the default ACL ? return 0 if it is. */		if (test_acl_default ( a -> ac_child ) == NOTOK)		return NOTOK;	if (test_acl_default ( a -> ac_entry ) == NOTOK)		return NOTOK;	if (test_acl_default ( a -> ac_default ) == NOTOK)		return NOTOK;	for (ptr= a -> ac_attributes ; ptr!=NULLACL_ATTR; ptr=ptr->aa_next )		if (test_acl_default(ptr->aa_acl) == NOTOK)			return NOTOK;				return OK;}int	  acl_cmp (acl1, acl2)struct acl	* acl1;struct acl	* acl2;{    int	  i;    if((acl1 == NULLACL) && (acl2 == NULLACL))	return(0);    if(acl1 == NULLACL)	return (acl_default_cmp (acl2) == OK) ? 0 : -1 ;    if(acl2 == NULLACL)	return (acl_default_cmp (acl1) == OK) ? 0 : 1 ;    if((i = acl_info_cmp(acl1->ac_child, acl2->ac_child)) != 0)	return(i);    if((i = acl_info_cmp(acl1->ac_entry, acl2->ac_entry)) != 0)	return(i);    if((i = acl_info_cmp(acl1->ac_default, acl2->ac_default)) != 0)	return(i);    if((i = acl_attr_cmp(acl1->ac_attributes, acl2->ac_attributes)) != 0)	return(i);    return(0);}static int	  acl_attr_cmp (acl_attr1, acl_attr2)struct acl_attr	* acl_attr1;struct acl_attr	* acl_attr2;{    struct acl_attr	* aa1;    struct acl_attr	* aa2;    if((acl_attr1 == NULLACL_ATTR) && (acl_attr2 == NULLACL_ATTR))	return(0);    if(acl_attr1 == NULLACL_ATTR)	return(-1);    if(acl_attr2 == NULLACL_ATTR)	return(1);    for(aa1=acl_attr1; aa1 != NULLACL_ATTR; aa1=aa1->aa_next)    {	for(aa2=acl_attr2; aa2 != NULLACL_ATTR; aa2=aa2->aa_next)	{	    if(acl_attr_comp_cmp(aa1, aa2) == 0)		break;	}	if(aa2 == NULLACL_ATTR)	    return(1);    }    for(aa2=acl_attr2; aa2 != NULLACL_ATTR; aa2=aa2->aa_next)    {	for(aa1=acl_attr1; aa1 != NULLACL_ATTR; aa1=aa1->aa_next)	{	    if(acl_attr_comp_cmp(aa1, aa2) == 0)		break;	}	if(aa1 == NULLACL_ATTR)	    return(-1);    }    return(0);}static int	  acl_attr_comp_cmp (acl_attr1, acl_attr2)struct acl_attr	* acl_attr1;struct acl_attr	* acl_attr2;{    int	  i;    if((acl_attr1 == NULLACL_ATTR) && (acl_attr2 == NULLACL_ATTR))	return(0);    if(acl_attr1 == NULLACL_ATTR)	return(-1);    if(acl_attr2 == NULLACL_ATTR)	return(1);    if((i = oid_seq_cmp(acl_attr1->aa_types, acl_attr2->aa_types)) != 0)	return(i);    if((i = acl_info_cmp(acl_attr1->aa_acl, acl_attr2->aa_acl)) != 0)	return(i);    return(0);}int	  acl_info_cmp (acl_info1, acl_info2)struct acl_info	* acl_info1;struct acl_info	* acl_info2;{    struct acl_info	* ai1;    struct acl_info	* ai2;    if((acl_info1 == NULLACL_INFO) && (acl_info2 == NULLACL_INFO))	return(0);    if(acl_info1 == NULLACL_INFO)         if (test_acl_default(acl_info2) == OK)		return(0);	else		return(-1);    if(acl_info2 == NULLACL_INFO)        if (test_acl_default(acl_info1) == OK)		return(0);	else		return(1);    for(ai1=acl_info1; ai1 != NULLACL_INFO; ai1=ai1->acl_next)    {	for(ai2=acl_info2; ai2 != NULLACL_INFO; ai2=ai2->acl_next)	{	    if(acl_info_comp_cmp(ai1, ai2) == 0)		break;	}	if(ai2 == NULLACL_INFO)	    return(1);    }    for(ai2=acl_info2; ai2 != NULLACL_INFO; ai2=ai2->acl_next)    {	for(ai1=acl_info1; ai1 != NULLACL_INFO; ai1=ai1->acl_next)	{	    if(acl_info_comp_cmp(ai2, ai1) == 0)		break;	}	if(ai1 == NULLACL_INFO)	    return(-1);    }    return(0);}static int	  acl_info_comp_cmp (acl_info1, acl_info2)struct acl_info	* acl_info1;struct acl_info	* acl_info2;{    int	  i;    if((acl_info1 == NULLACL_INFO) && (acl_info2 == NULLACL_INFO))	return(0);    if(acl_info1 == NULLACL_INFO)	return(-1);    if(acl_info2 == NULLACL_INFO)	return(1);    if(acl_info1->acl_categories > acl_info2->acl_categories)	return(1);    if(acl_info2->acl_categories > acl_info1->acl_categories)	return(-1);    if(acl_info1->acl_selector_type > acl_info2->acl_selector_type)	return(1);    if(acl_info2->acl_selector_type > acl_info1->acl_selector_type)	return(-1);    if((i = dn_seq_cmp(acl_info1->acl_name, acl_info2->acl_name)) != 0)	return(i);    return(0);}struct acl_info * acl_info_new (x,y,z)register int x,y;struct dn_seq * z;{register struct acl_info * ptr;	ptr = acl_info_alloc ();	acl_info_fill (ptr,x,y,z);	ptr->acl_next = NULLACL_INFO;	return (ptr);}static struct acl * acl_cpy (aclptr)register struct acl * aclptr;{register struct acl * ptr;	ptr = (struct acl *) smalloc (sizeof (struct acl));	ptr->ac_child = acl_info_cpy (aclptr->ac_child);	ptr->ac_entry = acl_info_cpy (aclptr->ac_entry);	ptr->ac_default = acl_info_cpy (aclptr->ac_default);	ptr->ac_attributes = acl_attr_cpy (aclptr->ac_attributes,ptr->ac_default);	return (ptr);}static struct acl * acl_decode (pe)PE pe;{struct acl * aclptr;	if (decode_Quipu_ACLSyntax(pe,1,NULLIP,NULLVP,&aclptr) == NOTOK) {		return (struct acl *) NULL;	}	if (! aclptr->ac_child)		aclptr->ac_child = defaultacl;	if (! aclptr->ac_entry)		aclptr->ac_entry = defaultacl;	if (! aclptr->ac_default)		aclptr->ac_default = defaultacl;	return (aclptr);}static struct acl_attr * acl_attr_cpy (aclptr,dflt)struct acl_attr * aclptr;struct acl_info * dflt;{register struct acl_attr * ptr;register struct acl_attr * ptr2;register struct acl_attr * result = NULLACL_ATTR;	for (ptr=aclptr ; ptr!=NULLACL_ATTR; ptr=ptr->aa_next ) {		ptr2 = acl_attr_alloc ();		ptr2->aa_next = result;		result = ptr2;		ptr2->aa_types = oid_seq_cpy (ptr->aa_types);		if (ptr->aa_acl != dflt)			ptr2->aa_acl = acl_info_cpy (ptr->aa_acl);		else			ptr2->aa_acl = dflt;	}	return (result);}static struct acl_info * acl_info_cpy (aclptr)struct acl_info * aclptr;{register struct acl_info * ptr;register struct acl_info * ptr2;register struct acl_info * result = NULLACL_INFO;	if (test_acl_default(aclptr) == OK) {		return (defaultacl);	}	for (ptr=aclptr ; ptr!=NULLACL_INFO; ptr=ptr->acl_next ) {		ptr2 = acl_info_alloc();		ptr2 -> acl_next = result;		result = ptr2;		result->acl_categories = ptr->acl_categories;		result->acl_selector_type = ptr->acl_selector_type;		result->acl_name = dn_seq_cpy (ptr->acl_name);	}	return (result);}struct acl_info * acl_default (){	return (defaultacl);}get_default_acl (){	defaultacl = acl_info_alloc ();	set_default_acl(defaultacl);}set_default_acl (ai_ptr)struct acl_info * ai_ptr;{	/* default -   others # read & self # write */	ai_ptr ->acl_categories = ACL_READ;	ai_ptr ->acl_selector_type = ACL_OTHER;	ai_ptr ->acl_name = NULLDNSEQ;	ai_ptr ->acl_next = acl_info_alloc();	ai_ptr ->acl_next->acl_categories = ACL_WRITE;	ai_ptr ->acl_next->acl_selector_type = ACL_ENTRY;	ai_ptr ->acl_next->acl_next = NULLACL_INFO;	ai_ptr ->acl_next->acl_name = NULLDNSEQ;}test_acl_default (a)struct acl_info * a;{	if ((a == NULLACL_INFO) || (a == defaultacl))		return (OK);	if (a ->acl_categories != ACL_READ) {			if (a ->acl_categories != ACL_WRITE)			return (NOTOK);		if (a ->acl_selector_type != ACL_ENTRY)			return (NOTOK);		if (a ->acl_next == NULLACL_INFO)			return (NOTOK);		if (a ->acl_next->acl_categories != ACL_READ)			return (NOTOK);		if (a ->acl_next->acl_selector_type != ACL_OTHER)			return (NOTOK);		if (a ->acl_next->acl_next != NULLACL_INFO)			return (NOTOK);		return (OK);			} if (a ->acl_selector_type != ACL_OTHER)		return (NOTOK);	if (a ->acl_next == NULLACL_INFO)		return (NOTOK);	if (a ->acl_next->acl_categories != ACL_WRITE)		return (NOTOK);	if (a ->acl_next->acl_selector_type != ACL_ENTRY)		return (NOTOK);	if (a ->acl_next->acl_next != NULLACL_INFO)		return (NOTOK);	return (OK);}static struct acl_attr * acl_attr_merge (a,b)struct acl_attr *a;struct acl_attr *b;{struct acl_attr *c;	if (b == NULLACL_ATTR)		return (a);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?