⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 disptmpl.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 2 页
字号:


struct ldap_tmplitem *
ldap_first_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row )
{
    return( row );
}


struct ldap_tmplitem *
ldap_next_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row,
	struct ldap_tmplitem *col )
{
    return( col == NULLTMPLITEM ? col : col->ti_next_in_row );
}


char **
ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
	int exclude, unsigned long syntaxmask )
{
/*
 * this routine should filter out duplicate attributes...
 */
    struct ldap_tmplitem	*tirowp, *ticolp;
    int			i, attrcnt, memerr;
    char		**attrs;

    attrcnt = 0;
    memerr = 0;

    if (( attrs = (char **)malloc( sizeof( char * ))) == NULL ) {
	return( NULL );
    }

    if ( includeattrs != NULL ) {
	for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) {
	    if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
		    sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
		    strdup( includeattrs[ i ] )) == NULL ) {
		memerr = 1;
	    } else {
		attrs[ attrcnt ] = NULL;
	    }
	}
    }

    for ( tirowp = ldap_first_tmplrow( tmpl );
	    !memerr && tirowp != NULLTMPLITEM;
	    tirowp = ldap_next_tmplrow( tmpl, tirowp )) {
	for ( ticolp = ldap_first_tmplcol( tmpl, tirowp );
		ticolp != NULLTMPLITEM;
		ticolp = ldap_next_tmplcol( tmpl, tirowp, ticolp )) {

	    if ( syntaxmask != 0 ) {
		if (( exclude &&
			( syntaxmask & ticolp->ti_syntaxid ) != 0 ) ||
			( !exclude &&
			( syntaxmask & ticolp->ti_syntaxid ) == 0 )) {
		    continue;
		}
	    }

	    if ( ticolp->ti_attrname != NULL ) {
		if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
			sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
			strdup( ticolp->ti_attrname )) == NULL ) {
		    memerr = 1;
		} else {
		    attrs[ attrcnt ] = NULL;
		}
	    }
	}
    }

    if ( memerr || attrcnt == 0 ) {
	for ( i = 0; i < attrcnt; ++i ) {
	    if ( attrs[ i ] != NULL ) {
		free( attrs[ i ] );
	    }
	}

	free( (char *)attrs );
	return( NULL );
    }

    return( attrs );
}


static int
read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
	int dtversion )
{
    int				i, j, tokcnt, samerow, adsource;
    char			**toks, *itemopts;
    struct ldap_disptmpl	*tmpl;
    struct ldap_oclist		*ocp, *prevocp;
    struct ldap_adddeflist	*adp, *prevadp;
    struct ldap_tmplitem	*rowp, *ip, *previp;

    *tmplp = NULL;

    /*
     * template name comes first
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	return( tokcnt == 0 ? 0 : LDAP_TMPL_ERR_SYNTAX );
    }

    if (( tmpl = (struct ldap_disptmpl *)calloc( 1,
	    sizeof( struct ldap_disptmpl ))) == NULL ) {
	free_strarray( toks );
	return(  LDAP_TMPL_ERR_MEM );
    }
    tmpl->dt_name = toks[ 0 ];
    free( (char *)toks );

    /*
     * template plural name comes next
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    tmpl->dt_pluralname = toks[ 0 ];
    free( (char *)toks );

    /*
     * template icon name is next
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    tmpl->dt_iconname = toks[ 0 ];
    free( (char *)toks );

    /*
     * template options come next
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) < 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    for ( i = 0; toks[ i ] != NULL; ++i ) {
	for ( j = 0; tmploptions[ j ] != NULL; ++j ) {
	    if ( strcasecmp( toks[ i ], tmploptions[ j ] ) == 0 ) {
		tmpl->dt_options |= tmploptvals[ j ];
	    }
	}
    }
    free_strarray( toks );

    /*
     * object class list is next
     */
    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
	if (( ocp = (struct ldap_oclist *)calloc( 1,
		sizeof( struct ldap_oclist ))) == NULL ) {
	    free_strarray( toks );
	    free_disptmpl( tmpl );
	    return( LDAP_TMPL_ERR_MEM );
	}
	ocp->oc_objclasses = toks;
	if ( tmpl->dt_oclist == NULL ) {
	    tmpl->dt_oclist = ocp;
	} else {
	    prevocp->oc_next = ocp;
	}
	prevocp = ocp;
    }
    if ( tokcnt < 0 ) {
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }

    /*
     * read name of attribute to authenticate as
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    if ( toks[ 0 ][ 0 ] != '\0' ) {
	tmpl->dt_authattrname = toks[ 0 ];
    } else {
	free( toks[ 0 ] );
    }
    free( (char *)toks );

    /*
     * read default attribute to use for RDN
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    tmpl->dt_defrdnattrname = toks[ 0 ];
    free( (char *)toks );

    /*
     * read default location for new entries
     */
    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
	free_strarray( toks );
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }
    if ( toks[ 0 ][ 0 ] != '\0' ) {
	tmpl->dt_defaddlocation = toks[ 0 ];
    } else {
	free( toks[ 0 ] );
    }
    free( (char *)toks );

    /*
     * read list of rules used to define default values for new entries
     */
    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
	if ( strcasecmp( ADDEF_CONSTANT, toks[ 0 ] ) == 0 ) {
	    adsource = LDAP_ADSRC_CONSTANTVALUE;
	} else if ( strcasecmp( ADDEF_ADDERSDN, toks[ 0 ] ) == 0 ) {
	    adsource = LDAP_ADSRC_ADDERSDN;
	} else {
	    adsource = 0;
	}
	if ( adsource == 0 || tokcnt < 2 ||
		( adsource == LDAP_ADSRC_CONSTANTVALUE && tokcnt != 3 ) ||
		( adsource == LDAP_ADSRC_ADDERSDN && tokcnt != 2 )) {
	    free_strarray( toks );
	    free_disptmpl( tmpl );
	    return( LDAP_TMPL_ERR_SYNTAX );
	}
		
	if (( adp = (struct ldap_adddeflist *)calloc( 1,
		sizeof( struct ldap_adddeflist ))) == NULL ) {
	    free_strarray( toks );
	    free_disptmpl( tmpl );
	    return( LDAP_TMPL_ERR_MEM );
	}
	adp->ad_source = adsource;
	adp->ad_attrname = toks[ 1 ];
	if ( adsource == LDAP_ADSRC_CONSTANTVALUE ) {
	    adp->ad_value = toks[ 2 ];
	}
	free( toks[ 0 ] );
	free( (char *)toks );

	if ( tmpl->dt_adddeflist == NULL ) {
	    tmpl->dt_adddeflist = adp;
	} else {
	    prevadp->ad_next = adp;
	}
	prevadp = adp;
    }

    /*
     * item list is next
     */
    samerow = 0;
    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
	if ( strcasecmp( toks[ 0 ], "item" ) == 0 ) {
	    if ( tokcnt < 4 ) {
		free_strarray( toks );
		free_disptmpl( tmpl );
		return( LDAP_TMPL_ERR_SYNTAX );
	    }

	    if (( ip = (struct ldap_tmplitem *)calloc( 1,
		    sizeof( struct ldap_tmplitem ))) == NULL ) {
		free_strarray( toks );
		free_disptmpl( tmpl );
		return( LDAP_TMPL_ERR_MEM );
	    }

	    /*
	     * find syntaxid from config file string
	     */
	    while (( itemopts = strrchr( toks[ 1 ], ',' )) != NULL ) {
		*itemopts++ = '\0';
		for ( i = 0; itemoptions[ i ] != NULL; ++i ) {
		    if ( strcasecmp( itemopts, itemoptions[ i ] ) == 0 ) {
			break;
		    }
		}
		if ( itemoptions[ i ] == NULL ) {
		    free_strarray( toks );
		    free_disptmpl( tmpl );
		    return( LDAP_TMPL_ERR_SYNTAX );
		}
		ip->ti_options |= itemoptvals[ i ];
	    }

	    for ( i = 0; itemtypes[ i ] != NULL; ++i ) {
		if ( strcasecmp( toks[ 1 ], itemtypes[ i ] ) == 0 ) {
		    break;
		}
	    }
	    if ( itemtypes[ i ] == NULL ) {
		free_strarray( toks );
		free_disptmpl( tmpl );
		return( LDAP_TMPL_ERR_SYNTAX );
	    }

	    free( toks[ 0 ] );
	    free( toks[ 1 ] );
	    ip->ti_syntaxid = itemsynids[ i ];
	    ip->ti_label = toks[ 2 ];
	    if ( toks[ 3 ][ 0 ] == '\0' ) {
		ip->ti_attrname = NULL;
		free( toks[ 3 ] );
	    } else {
		ip->ti_attrname = toks[ 3 ];
	    }
	    if ( toks[ 4 ] != NULL ) {	/* extra args. */
		for ( i = 0; toks[ i + 4 ] != NULL; ++i ) {
		    ;
		}
		if (( ip->ti_args = (char **) calloc( i + 1, sizeof( char * )))
			== NULL ) {
		    free_disptmpl( tmpl );
		    return( LDAP_TMPL_ERR_MEM );
		}
		for ( i = 0; toks[ i + 4 ] != NULL; ++i ) {
		    ip->ti_args[ i ] = toks[ i + 4 ];
		}
	    }
	    free( (char *)toks );

	    if ( tmpl->dt_items == NULL ) {
		tmpl->dt_items = rowp = ip;
	    } else if ( samerow ) {
		previp->ti_next_in_row = ip;
	    } else {
		rowp->ti_next_in_col = ip;
		rowp = ip;
	    }
	    previp = ip;
	    samerow = 0;
	} else if ( strcasecmp( toks[ 0 ], "samerow" ) == 0 ) {
	    free_strarray( toks );
	    samerow = 1;
	} else {
	    free_strarray( toks );
	    free_disptmpl( tmpl );
	    return( LDAP_TMPL_ERR_SYNTAX );
	}
    }
    if ( tokcnt < 0 ) {
	free_disptmpl( tmpl );
	return( LDAP_TMPL_ERR_SYNTAX );
    }

    *tmplp = tmpl;
    return( 0 );
}

⌨️ 快捷键说明

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