acl.c

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

C
895
字号
	for (c=a ; c!= NULLACL_ATTR; c=c->aa_next) {		if (oid_seq_cmp (c->aa_types,b->aa_types) == 0) {			b->aa_acl->acl_next = c->aa_acl;			c->aa_acl = b->aa_acl;			oid_seq_free (b->aa_types);			b->aa_types = NULLOIDSEQ;			free ((char *)b);			return (a);		}	}	b->aa_next = a;	return (b);					}static acl_merge (a,str)AV_Sequence a;char * str;{struct acl * aclptr, aclstr;struct acl * newacl;	bzero ((char*)&aclstr,sizeof(struct acl));	if ((newacl = str2acl_aux(str,&aclstr)) == NULLACL)		return;	aclptr = (struct acl *) a->avseq_av.av_struct;	if (newacl->ac_child != NULLACL_INFO) {		newacl->ac_child->acl_next = aclptr->ac_child;		aclptr->ac_child = newacl->ac_child;	}	if (newacl->ac_entry != NULLACL_INFO) {		newacl->ac_entry->acl_next = aclptr->ac_entry;		aclptr->ac_entry = newacl->ac_entry;	}	if (newacl->ac_default != NULLACL_INFO) {		newacl->ac_default->acl_next = aclptr->ac_default;		aclptr->ac_default = newacl->ac_default;	}	if (newacl->ac_attributes != NULLACL_ATTR) 		aclptr->ac_attributes = acl_attr_merge (aclptr->ac_attributes,newacl->ac_attributes);}static char * acl_cat [] = {	"none",	"detect",	"compare",	"read",	"add",	"write"	};char * acl_sel  []  = {	"ACL SELECTOR INTERNAL ERROR",	"self",	"others",	"prefix",	"group"	};static acl_info_comp_print (ps,aclptr,format)register PS ps;register struct acl_info * aclptr;register int format;{	if (format == READOUT) {	   switch (aclptr->acl_selector_type) {		case ACL_PREFIX:		case ACL_GROUP:			ps_printf (ps,"%s ( ",acl_sel[aclptr->acl_selector_type]);			dn_seq_print  (ps,aclptr->acl_name,format);			ps_printf (ps," ) can %s ",acl_cat[aclptr->acl_categories]);			break;		default:			ps_printf (ps,"%s can %s ", acl_sel[aclptr->acl_selector_type], acl_cat[aclptr->acl_categories]);	   }	} else {	   switch (aclptr->acl_selector_type) {		case ACL_PREFIX:		case ACL_GROUP:			ps_printf (ps,"%s # ",acl_sel[aclptr->acl_selector_type]);			dn_seq_print  (ps,aclptr->acl_name,format);			ps_printf (ps," # %s ",acl_cat[aclptr->acl_categories]);			break;		default:			ps_printf (ps,"%s # %s ", acl_sel[aclptr->acl_selector_type], acl_cat[aclptr->acl_categories]);	   }	}}static acl_info_print (ps,aclptr,format,acl_type,oidseq)register PS ps;struct   acl_info * aclptr;register int format;char * acl_type;struct oid_seq *oidseq;{register struct acl_info * ptr;char printed = FALSE;	if (dsa_mode && (test_acl_default(aclptr) == OK))		return;	for (ptr=aclptr ; ptr!=NULLACL_INFO; ptr=ptr->acl_next ) {		if (printed)			if (format != READOUT)				if (dsa_mode)					ps_print (ps," &\\\n\t");				else					ps_print (ps,"\nacl= ");			else				ps_print (ps,"\n\t\t\t");		else			printed = TRUE;		acl_info_comp_print (ps,ptr,format);		if (format == READOUT) {			if (oidseq != NULLOIDSEQ) {				ps_printf (ps,"the %s: ",acl_type);				oid_seq_print (ps,oidseq,format) ;			} else				ps_printf (ps,"the %s",acl_type);		} else {			ps_printf (ps,"# %s",acl_type);			if (oidseq != NULLOIDSEQ) {				ps_print (ps," # ");				oid_seq_print (ps,oidseq,format) ;			}		}	}}static acl_print (ps,aclptr,format)register PS ps;struct   acl * aclptr;register int format;{char printed = FALSE;register struct acl_attr * ptr;	if ( (!dsa_mode) || (test_acl_default(aclptr->ac_child) != OK)) {		acl_info_print (ps,aclptr->ac_child,format, "child", NULLOIDSEQ);		printed = TRUE;	}	if ((!dsa_mode) || (test_acl_default(aclptr->ac_entry) != OK)) {		if (printed)			if (format != READOUT)				if (dsa_mode)					ps_print (ps," &\\\n\t");				else					ps_print (ps,"\nacl= ");			else				ps_print (ps,"\n\t\t\t");		else			printed = TRUE;		acl_info_print (ps,aclptr->ac_entry,format,"entry", NULLOIDSEQ);	}	if ( (!dsa_mode) || (test_acl_default(aclptr->ac_default) != OK)) {		if (printed)			if (format != READOUT)				if (dsa_mode)					ps_print (ps," &\\\n\t");				else					ps_print (ps,"\nacl= ");			else				ps_print (ps,"\n\t\t\t");		else {			printed = TRUE;		}		acl_info_print (ps,aclptr->ac_default,format,"default", NULLOIDSEQ);	}	for (ptr=aclptr->ac_attributes ; ptr!=NULLACL_ATTR; ptr=ptr->aa_next ) {		if (dsa_mode && (test_acl_default(ptr->aa_acl) == OK))			continue;		if (acl_info_cmp(ptr->aa_acl,aclptr->ac_default) == 0)			continue;		if (printed)			if (format != READOUT)				if (dsa_mode)					ps_print (ps," &\\\n\t");				else					ps_print (ps,"\nacl= ");			else				ps_print (ps,"\n\t\t\t");		else {			printed = TRUE;		}		acl_info_print (ps,ptr->aa_acl,format, "attributes", ptr->aa_types);	}	if (! printed)	     if (format == READOUT)		ps_print (ps,"(default)");}static struct acl_info * str2acl_info (strptr)char ** strptr;{char * ptr;char * save,val;int class,what;struct dn_seq * dnseq = NULLDNSEQ;static CMD_TABLE cmd_what [] = {        "none",         ACL_NONE,        "detect",       ACL_DETECT,        "compare",      ACL_COMPARE,        "read",         ACL_READ,        "add",          ACL_ADD,        "write",        ACL_WRITE,        0,              -1        } ;static CMD_TABLE cmd_class [] = {	"SELF",		ACL_ENTRY,	"OTHERS",	ACL_OTHER,	"GROUP",	ACL_GROUP,	"PREFIX",	ACL_PREFIX,        0,              -1,        } ;	if ((ptr = index (*strptr,'#')) == 0) {		parse_error ("# missing in acl syntax '%s'",*strptr);		return (NULLACL_INFO);	}	save = ptr++;	if (**strptr == '#') {		parse_error ("acl class missing before first '#' ",NULLCP);		return (NULLACL_INFO);	} else {		if (! isspace (*--save))			save++;		val = *save;		*save = 0;		if (( class = cmd_srch (*strptr,cmd_class)) == -1) {			parse_error ("unknown acl class '%s'",*strptr);			*save = val;			return (NULLACL_INFO);		}		*save = val;	}	*strptr = SkipSpace(ptr);	if ((ptr = index (*strptr,'#')) == 0) {		parse_error ("2nd # missing in acl syntax ",NULLCP);		return (NULLACL_INFO);	}	if ( (class == ACL_GROUP) || (class == ACL_PREFIX) ) {  /* group or prefix */		save = ptr++;		if (**strptr == '#') {			parse_error ("acl class missing before first '#' ",NULLCP);			return (NULLACL_INFO);		} else {			if (! isspace (*--save))				save++;			val = *save;			*save = 0;			if ((dnseq = str2dnseq (*strptr)) == NULLDNSEQ)				return (NULLACL_INFO);			*save = val;		}		*strptr = SkipSpace(ptr);		if ((ptr = index (*strptr,'#')) == 0) {			parse_error ("3rd # missing in acl syntax ",NULLCP);			return (NULLACL_INFO);		}	}	save = ptr++;	if (**strptr == '#') {		parse_error ("acl level missing",NULLCP);		return (NULLACL_INFO);	} else {		if (! isspace (*--save))			save++;		val = *save;		*save = 0;		if (( what = cmd_srch (*strptr,cmd_what)) == -1) {			parse_error ("unknown level '%s'",*strptr);			*save = val;			return (NULLACL_INFO);		}		*save = val;	}	*strptr = SkipSpace(ptr);	return (acl_info_new (what,class,dnseq));}static struct acl * str2acl_aux (str,the_acl)char * str;struct acl * the_acl;{struct acl_info * info;char * save, *ptr, val = 0;int oidlist;struct oid_seq * str2oidseq();static CMD_TABLE cmd_who [] = {        "child",        0,        "entry",        1,        "default",      2,        0,              -1,        };	if ((info = str2acl_info (&str)) == NULLACL_INFO)		return ( (struct acl *) NULL );	/* this has left us with "string [#oidlist] [#]" */	if ((ptr = index (str,'#')) != 0) {		save = ptr++;		if (*ptr == 0) 			oidlist = FALSE;		else			oidlist = TRUE;		if (! isspace (*--save))			save++;		val = *save;		*save = 0;	} else		oidlist = FALSE;	if (oidlist) {		struct acl_attr * at_acl;		if (lexequ (str,"attributes") != 0) {			parse_error ("\"attributes\" expected",NULLCP);			if (val != 0)				*save = val;			return ( (struct acl *) NULL );		}		at_acl = acl_attr_alloc();		at_acl->aa_next = NULLACL_ATTR;		at_acl->aa_acl = info;		if ((str = rindex(ptr,'#')) != NULLCP) {			*str-- = 0;			if (isspace (*str))				*str = 0;		}				if ((at_acl->aa_types = str2oidseq (SkipSpace(ptr))) == NULLOIDSEQ) {			if (val != 0)				*save = val;			return ( (struct acl *) NULL );		}		the_acl->ac_child = NULLACL_INFO;		the_acl->ac_entry = NULLACL_INFO;		the_acl->ac_default = NULLACL_INFO;		the_acl->ac_attributes = at_acl;			} else {		int who;		if ((who = cmd_srch (str,cmd_who)) == -1) {			parse_error ("unknown acl type specifier '%s'",str);			if (val != 0)				*save = val;			return ( (struct acl *) NULL );		}		the_acl->ac_child = NULLACL_INFO;		the_acl->ac_entry = NULLACL_INFO;		the_acl->ac_default = NULLACL_INFO;		the_acl->ac_attributes = NULLACL_ATTR;		switch (who) {		case 0:			the_acl->ac_child = info;			break;		case 1:			the_acl->ac_entry = info;			break;		case 2:			the_acl->ac_default = info;			break;		}	}	if (val != 0)		*save = val;		return (the_acl);}static struct acl * str2acl (str)char * str;{struct acl * the_acl;	the_acl = acl_alloc ();	if (str2acl_aux(str,the_acl) != NULLACL)		return (the_acl);	free ((char *)the_acl);	return (NULLACL);}static PE acl_enc (acl)struct acl * acl;{PE ret_pe;	(void) encode_Quipu_ACLSyntax (&ret_pe,0,0,NULLCP,acl);	return (ret_pe);}acl_syntax (){extern short acl_sntx;extern IFP merge_acl;extern IFP acl_fn;	acl_sntx = add_attribute_syntax ("acl",		(IFP) acl_enc,	(IFP) acl_decode,		(IFP) str2acl,	acl_print,		(IFP) acl_cpy,	acl_cmp,		acl_free,	NULLCP,		NULLIFP,	TRUE);	merge_acl = (IFP) acl_merge;	acl_fn = (IFP) acl_default;	get_default_acl();}

⌨️ 快捷键说明

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