searchacl.c

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

C
835
字号
/* searchacl.c - Search and List Access Control routines */#ifndef	lintstatic char *rcsid = "$Header: /xtel/isode/isode/dsap/common/RCS/searchacl.c,v 9.0 1992/06/16 12:12:39 isode Rel $";#endif/*  * $Header: /xtel/isode/isode/dsap/common/RCS/searchacl.c,v 9.0 1992/06/16 12:12:39 isode Rel $ * * * $Log: searchacl.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"#include "logger.h"/* * These routines implement the searchACLSyntax.  The EDB representation * of this syntax is as follows: * * SearchACLSyntax ::= <accessselector> '#' <access> '#' <attrs> '#' <scope>  *			[ '#' <max-results> '#' <partialresults>  *			[ '#' <minkeylen> ]] * * * <accessselector> ::= 'group' '#' <dnseq>	| *			'prefix' '#' <dnseq> 	| *			'self'		 	| *			'other' * * <access> ::= 'search' | 'nosearch' * * <attrs> ::= 'default' | <attr-list> * * <attr-list> ::= attributetype | attributetype <attr-list> * * <scope> ::= <singlescope> | <singlescope> '$' <scope> * * <singlescope> ::= 'subtree' | 'singlelevel' | 'baseobject' * * <max-results> ::= integer * * <partialresults> ::= 'partialresults' | 'nopartialresults' * * <minkeylen> ::= integer * */short sacl_sntx = -1;short lacl_sntx = -1;extern LLog	*log_dsap;static Saclinfo sacl_alloc(){	Saclinfo	new;	new = (Saclinfo) smalloc( sizeof(saclinfo) );	bzero( (char *) new, sizeof(saclinfo) );	new->sac_access = SACL_SEARCHABLE;	new->sac_minkeylength = SACL_NOMINLENGTH;	new->sac_zeroifexceeded = TRUE;	new->sac_scope = SACL_SUBTREE | SACL_SINGLELEVEL;	return( new );}sacl_free( p )Saclinfo p;{	if ( p->sac_tmpbstr )		free( p->sac_tmpbstr );	if ( p->sac_name != NULLDNSEQ )		dn_seq_free( p->sac_name );	if ( p->sac_types != NULLOIDSEQ )		oid_seq_free( p->sac_types );	free( (char *) p );}lacl_free( p )Saclinfo p;{	if ( p->sac_tmpbstr )		free( p->sac_tmpbstr );	if ( p->sac_name != NULLDNSEQ )		dn_seq_free( p->sac_name );	free( (char *) p );}/*  * selector_rank is used to rank acl selectors from most to least specific. */int selector_rank[] = {	-1,	/* error */	1,	/* ACL_ENTRY	*/	4,	/* ACL_OTHER	*/	3,	/* ACL_PREFIX	*/	2	/* ACL_GROUP	*/};sacl_cmp( a, b )Saclinfo a;Saclinfo b;{	int	i;	if ( a == NULLSACL && b == NULLSACL )		return( 0 );	if ( a == NULLSACL )		return( -1 );	if ( b == NULLSACL )		return( 1 );	if ( (i = acl_info_cmp( &a->sac_info, &b->sac_info )) != 0 )		return( i );	if ( a->sac_scope != b->sac_scope )		return( a->sac_scope < b->sac_scope ? -1 : 1 );	if ( a->sac_access != b->sac_access )		return( a->sac_access < b->sac_access ? -1 : 1 );	if ( (i = oid_seq_cmp( a->sac_types, b->sac_types )) != 0 )		return( i );	if ( a->sac_access == SACL_UNSEARCHABLE )		return( 0 );	if ( a->sac_maxresults != b->sac_maxresults )		return( a->sac_maxresults < b->sac_maxresults ? -1 : 1 );	if ( a->sac_minkeylength != b->sac_minkeylength )		return( a->sac_minkeylength < b->sac_minkeylength ? -1 : 1 );	if ( a->sac_zeroifexceeded != b->sac_zeroifexceeded )		return( a->sac_zeroifexceeded < b->sac_zeroifexceeded ?		    -1 : 1 );	return( 0 );}static lacl_cmp( a, b )Listacl	a;Listacl	b;{	int	i;	if ( a == NULLSACL && b == NULLSACL )		return( 0 );	if ( a == NULLSACL )		return( -1 );	if ( b == NULLSACL )		return( 1 );	if ( (i = acl_info_cmp( &a->sac_info, &b->sac_info )) != 0 )		return( i );	if ( a->sac_scope != b->sac_scope )		return( a->sac_scope < b->sac_scope ? -1 : 1 );	if ( a->sac_maxresults != b->sac_maxresults )		return( a->sac_maxresults < b->sac_maxresults ? -1 : 1 );	return( 0 );}static Saclinfo sacl_cpy( sacl )Saclinfo sacl;{	Saclinfo new;	new = sacl_alloc();	*new = *sacl;	/* struct copy */	if ( sacl->sac_name != NULLDNSEQ )		new->sac_name = dn_seq_cpy( sacl->sac_name );	new->sac_tmpbstr = NULL;	if ( sacl->sac_types != NULLOIDSEQ )		new->sac_types = oid_seq_cpy( sacl->sac_types );	return( new );}static Listacl lacl_cpy( lacl )Listacl	lacl;{	return( sacl_cpy( lacl ) );}static Saclinfo sacl_decode( pe )PE	pe;{	Saclinfo acl;	if ( decode_Quipu_SearchACLSyntax( pe, 1, NULLIP, NULLVP, &acl )	    == NOTOK ) {		return( NULLSACL );	}	return( acl );}static PE sacl_enc( acl )Saclinfo acl;{	PE ret_pe;	(void) encode_Quipu_SearchACLSyntax( &ret_pe, 0, 0, NULLCP, acl );	return( ret_pe );}static Saclinfo str2sacl( str )char	*str;{	Saclinfo	new;	char		save, *s, *tmp;	int		scope;	struct oid_seq	*str2oidseq();	if ( (s = index( str, '#' )) == NULL ) {		parse_error( "# missing in search acl '%s'", str );		return( NULLSACL );	}	new = sacl_alloc();	save = *s;	*s = '\0';	while ( isspace( *str ) )		str++;	/* get access selector */	if ( lexnequ( str, "group", 5 ) == 0 ) {		new->sac_selector = ACL_GROUP;	} else if ( lexnequ( str, "prefix", 6 ) == 0 ) {		new->sac_selector = ACL_PREFIX;	} else if ( lexnequ( str, "other", 5 ) == 0 ) {		new->sac_selector = ACL_OTHER;	} else if ( lexnequ( str, "self", 4 ) == 0 ) {		new->sac_selector = ACL_ENTRY;	} else {		parse_error( "unknown access selector '%s'", str );		free( (char *) new );		return( NULLSACL );	}	if ( new->sac_selector == ACL_GROUP	    || new->sac_selector == ACL_PREFIX) {		/* skip past next # */		*s++ = save;		str = s;		if ( (s = index( str, '#' )) == NULL ) {			parse_error( "2nd # missing in search acl '%s'", str );			sacl_free( new );			return( NULLSACL );		}		save = *s;		*s = '\0';		while ( isspace( *str ) )			str++;		str = TidyString(str);		if ( (new->sac_name = str2dnseq( str )) == NULLDNSEQ ) {			free( (char *) new );			return( NULLSACL );		}	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		s--;		if ( !isspace(*s)) {			s++;			*s = '\0';		} else {			*s = '\0';			s++;		}	}	while ( isspace( *str ) )		str++;	/* get access */	if ( lexnequ( str, "search", 6 ) == 0 ) {		new->sac_access = SACL_SEARCHABLE;	} else if ( lexnequ( str, "nosearch", 8 ) == 0 ) {		new->sac_access = SACL_UNSEARCHABLE;	} else {		parse_error( "expecting [no]search, found '%s'", str );		sacl_free( new );		return( NULLSACL );	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		s--;		if ( !isspace(*s)) {			*s = '\0';			s++;		} else {			*s = '\0';			s++;		}	}	while ( isspace( *str ) )		str++;	/* attribute list */	if ( lexnequ( str, "default", 7 ) == 0 ) {		new->sac_types = NULLOIDSEQ;	} else {		FAST_TIDY(str);		if ( (new->sac_types = str2oidseq( str )) == NULLOIDSEQ ) {			sacl_free( new );			return( NULLSACL );		}	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		s--;		if ( !isspace(*s)) {			*s = '\0';			s++;		} else {			*s = '\0';			s++;		}	}	while ( isspace( *str ) )		str++;	/* get scope */	scope = 0;	while ( str != NULL && *str != '\0' ) {		if ( lexnequ( str, "subtree", 7 ) == 0 ) {			scope |= SACL_SUBTREE;		} else if ( lexnequ( str, "single", 6 ) == 0 ) {			scope |= SACL_SINGLELEVEL;		} else if ( lexnequ( str, "base", 4 ) == 0 ) {			scope |= SACL_BASEOBJECT;		} else {			parse_error( "unknown scope in search acl '%s'", str );			sacl_free( new );			return( NULLSACL );		}		tmp = str;		if ( (str = index( tmp, '$' )) || (str = index( tmp, ' ' )) ) {			str++;			while ( isspace( *str ) )				str++;		}	}	if ( scope != 0 )		new->sac_scope = scope;	if ( new->sac_access == SACL_UNSEARCHABLE ) {		if ( s != NULL ) {			parse_error( "extra junk after nosearch '%s'", s+1 );			sacl_free( new );			return( NULLSACL );		} else {			return( new );		}	}	if ( s == NULL ) {		/*		 * if this is only a baseobject sacl, it doesn't need		 * anything more.		 */		if ( new->sac_scope == SACL_BASEOBJECT )			return( new );		parse_error( "max-results missing from searchacl", NULLCP );		sacl_free( new );		return( NULLSACL );	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		s--;		if ( !isspace(*s)) {

⌨️ 快捷键说明

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