searchacl.c

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

C
835
字号
			*s = '\0';			s++;		} else {			*s = '\0';			s++;		}	}	while ( isspace( *str ) )		str++;	/* max results */	new->sac_maxresults = atoi( str );	if ( new->sac_maxresults <= 0 ) {		parse_error( "searchacl maxresults must be > 0" ,NULLCP);		sacl_free( new );		return( NULLSACL );	}	if ( s == NULL ) {		parse_error( "[no]partialresults 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)) {			*s = '\0';			s++;		} else {			*s = '\0';			s++;		}	}	while ( isspace( *str ) )		str++;	/* zero-results-if-limit-exceeded flag */	if ( lexnequ( str, "partial", 7 ) == 0 )		new->sac_zeroifexceeded = FALSE;	else if ( lexnequ( str, "nopartial", 9 ) == 0 )		new->sac_zeroifexceeded = TRUE;	else {		parse_error( "expecting [no]partialresults got '%s'", str );		sacl_free( new );		return( NULLSACL );	}	if ( s == NULL ) {		return( new );	/* default to no min key length */	}	/* skip past next # */	*s++ = save;	str = s;	while ( isspace( *str ) )		str++;	/* min substring key length */	new->sac_minkeylength = atoi( str );	if ( new->sac_minkeylength < 0 ) {		parse_error( "searchacl minkeylength must be >= 0",NULLCP );		sacl_free( new );		return( NULLSACL );	}	return( new );}static char	*sacl_scope[] = {			"subtree",			"singlelevel",			"baseobject"		};sacl_print( ps, acl, format )PS		ps;Saclinfo	acl;int		format;{	int		i, once;	extern char	*acl_sel[];	/* selector */	if ( format == READOUT )		ps_printf( ps, "%s ", acl_sel[ acl->sac_selector ] );	else		ps_printf( ps, "%s # ", acl_sel[ acl->sac_selector ] );	if ( acl->sac_selector == ACL_GROUP	   || acl->sac_selector == ACL_PREFIX ) {		if ( format == READOUT )			ps_printf( ps, "( " );		dn_seq_print( ps, acl->sac_name, format );		if ( format == READOUT )			ps_printf( ps, " ) " );		else			ps_printf( ps, " # " );	}	/* access */	if ( acl->sac_access == SACL_SEARCHABLE ) {		if ( format == READOUT )			ps_printf( ps, "can search " );		else			ps_printf( ps, "search # " );	} else {		if ( format == READOUT )			ps_printf( ps, "cannot search " );		else			ps_printf( ps, "nosearch # " );	}	/* attributes */	if ( acl->sac_types == NULLOIDSEQ ) {		if ( format == READOUT )			ps_printf( ps, "by the default" );		else			ps_printf( ps, "default" );	} else {		if ( format == READOUT )			ps_printf( ps, "by the attributes ( " );		oid_seq_print( ps, acl->sac_types, format );		if ( format == READOUT )			ps_printf( ps, " )" );	}	if ( format != READOUT )		ps_printf( ps, " # " );	/* scope */	if ( format == READOUT )		ps_printf( ps, " in the " );	once = 0;	for ( i = 0; i < 3; i++ ) {		if ( acl->sac_scope & (1 << i) ) {			if ( once ) {				if ( format == READOUT )					ps_printf( ps, " and " );				else					ps_printf( ps, "$" );			}			ps_printf( ps, "%s", sacl_scope[ i ] );			once = 1;		}	}	if ( acl->sac_access == SACL_UNSEARCHABLE )		return;	/* if it's only a baseobject sacl, nothing more to print */	if ( acl->sac_scope == SACL_BASEOBJECT )		return;	/* max results */	if ( format == READOUT )		ps_printf( ps, "\n\t\t\t(limit %d matches",		    acl->sac_maxresults );	else		ps_printf( ps, " # %d", acl->sac_maxresults );	/* zero results flag */	if ( format == READOUT ) {		if ( acl->sac_zeroifexceeded )			ps_printf( ps, ", none if limit is exceeded)" );		else			ps_printf( ps, ")" );	} else		ps_printf( ps, " # %s", acl->sac_zeroifexceeded ?		    "nopartialresults" : "partialresults" );	/* min key length */	if ( acl->sac_minkeylength != SACL_NOMINLENGTH ) {		if ( format == READOUT )			ps_printf( ps,			    ",\n\t\t\tminimum substring key length is %d",			    acl->sac_minkeylength );		else			ps_printf( ps, " # %d", acl->sac_minkeylength );	}}static Listacl lacl_decode( pe )PE	pe;{	Listacl	acl;	if ( decode_Quipu_ListACLSyntax( pe, 1, NULLIP, NULLVP, &acl )	    == NOTOK ) {		return( NULLLISTACL );	}	return( acl );}static PE lacl_enc( acl )Listacl acl;{	PE ret_pe;	(void) encode_Quipu_ListACLSyntax( &ret_pe, 0, 0, NULLCP, acl );	return( ret_pe );}Listacl str2lacl( str )char	*str;{	char	*s, save;	Listacl	new;	if ( (s = index( str, '#' )) == NULL ) {		parse_error( "# missing in list acl '%s'", str );		return( NULLLISTACL );	}	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 list acl selector type '%s'", str );		free( (char *) new );		return( NULLLISTACL );	}	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 list acl '%s'", str );			sacl_free( new );			return( NULLLISTACL );		}		save = *s;		*s = '\0';		while ( isspace( *str ) )			str++;		str = TidyString(str);		if ( (new->sac_name = str2dnseq( str )) == NULLDNSEQ ) {			free( (char *) new );			return( NULLLISTACL );		}	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		*s = '\0';	}	while ( isspace( *str ) )		str++;	/* get access */	if ( lexnequ( str, "list", 4 ) == 0 ) {		new->sac_maxresults = -1;	} else if ( lexnequ( str, "nolist", 6 ) == 0 ) {		new->sac_maxresults = 0;	} else {		parse_error( "expecting [no]list, found '%s'", str );		sacl_free( new );		return( NULLLISTACL );	}	if ( s == NULL ) {		parse_error( "listacl scope missing",NULLCP );		sacl_free( new );		return( NULLLISTACL );	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		*s = '\0';	}	while ( isspace( *str ) )		str++;	/* get scope */	if ( lexnequ( str, "entry", 5 ) == 0 ) {		new->sac_scope = SACL_BASEOBJECT;		return( new );	} else if ( lexnequ( str, "children", 8 ) == 0 ) {		new->sac_scope = SACL_SINGLELEVEL;		if ( new->sac_maxresults == 0 ) {			return( new );	/* nolist was specified */		}	} else {		parse_error( "expecting entry or children, got '%s'", str );		sacl_free( new );		return( NULLLISTACL );	}	if ( s == NULL ) {		return( new );	}	/* skip past next # */	*s++ = save;	str = s;	if ( (s = index( str, '#' )) != NULL ) {		save = *s;		*s = '\0';	}	while ( isspace( *str ) )		str++;	/* get max results */	new->sac_maxresults = atoi( str );	return( new );}lacl_print( ps, acl, format )PS	ps;Listacl	acl;int	format;{	extern char	*acl_sel[];	/* selector */	if ( format == READOUT )		ps_printf( ps, "%s ", acl_sel[ acl->sac_selector ] );	else		ps_printf( ps, "%s # ", acl_sel[ acl->sac_selector ] );	if ( acl->sac_selector == ACL_GROUP	    || acl->sac_selector == ACL_PREFIX ){		if ( format == READOUT )			ps_printf( ps, "( " );		dn_seq_print( ps, acl->sac_name, format );		if ( format == READOUT )			ps_printf( ps, " ) " );		else			ps_printf( ps, " # " );	}	/* access */	if ( acl->sac_maxresults != 0 ) {		if ( format == READOUT )			ps_printf( ps, "can list " );		else			ps_printf( ps, "list # " );	} else {		if ( format == READOUT )			ps_printf( ps, "cannot list " );		else			ps_printf( ps, "nolist # " );	}	/* scope */	if ( acl->sac_scope == SACL_BASEOBJECT ) {		if ( format == READOUT )			ps_printf( ps, "the entry" );		else			ps_printf( ps, "entry" );		return;	} else {		if ( format == READOUT )			ps_printf( ps, "the children" );		else			ps_printf( ps, "children" );	}	if ( acl->sac_maxresults > 0 ) {		if ( format == READOUT )			ps_printf( ps, " (limit %d entries)",			    acl->sac_maxresults );		else			ps_printf( ps, " # %d", acl->sac_maxresults );	}	return;}sacl_syntax(){	sacl_sntx = add_attribute_syntax ("SearchACLSyntax",		(IFP) sacl_enc,	(IFP) sacl_decode,		(IFP) str2sacl,	sacl_print,		(IFP) sacl_cpy,	sacl_cmp,		sacl_free,	NULLCP,		NULLIFP,	TRUE);}lacl_syntax(){	lacl_sntx = add_attribute_syntax ("ListACLSyntax",		(IFP) lacl_enc,	(IFP) lacl_decode,		(IFP) str2lacl,	lacl_print,		(IFP) lacl_cpy,	lacl_cmp,		lacl_free,	NULLCP,		NULLIFP,	TRUE);}

⌨️ 快捷键说明

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