X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fdisptmpl.c;h=32c253d32dc0699290e10ba5c9e709f37cc84775;hb=c8e37af0ca8302c276e8c6af84eca4f926171261;hp=d3db6106fdb724a0518a16e9def96b947fb90a5f;hpb=b6d85256e7d42ced89f2aead107c38eaea810a05;p=openldap diff --git a/libraries/libldap/disptmpl.c b/libraries/libldap/disptmpl.c index d3db6106fd..32c253d32d 100644 --- a/libraries/libldap/disptmpl.c +++ b/libraries/libldap/disptmpl.c @@ -20,7 +20,8 @@ #include "portable.h" #include -#include + +#include #include #include @@ -35,7 +36,7 @@ #include "disptmpl.h" static void free_disptmpl LDAP_P(( struct ldap_disptmpl *tmpl )); -static int read_next_tmpl LDAP_P(( char **bufp, long *blenp, +static int read_next_tmpl LDAP_P(( char **bufp, ber_len_t *blenp, struct ldap_disptmpl **tmplp, int dtversion )); static const char *const tmploptions[] = { @@ -98,7 +99,7 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp ) long rlen, len; int rc, eof; - *tmpllistp = NULLDISPTMPL; + *tmpllistp = NULL; if (( fp = fopen( file, "r" )) == NULL ) { return( LDAP_TMPL_ERR_FILE ); @@ -116,7 +117,7 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp ) return( LDAP_TMPL_ERR_FILE ); } - if (( buf = malloc( (size_t)len )) == NULL ) { + if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) { fclose( fp ); return( LDAP_TMPL_ERR_MEM ); } @@ -126,26 +127,26 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp ) fclose( fp ); if ( rlen != len && !eof ) { /* error: didn't get the whole file */ - free( buf ); + LDAP_FREE( buf ); return( LDAP_TMPL_ERR_FILE ); } rc = ldap_init_templates_buf( buf, rlen, tmpllistp ); - free( buf ); + LDAP_FREE( buf ); return( rc ); } int -ldap_init_templates_buf( char *buf, long buflen, +ldap_init_templates_buf( char *buf, ber_len_t buflen, struct ldap_disptmpl **tmpllistp ) { int rc=-1, version; char **toks; struct ldap_disptmpl *prevtmpl, *tmpl; - *tmpllistp = prevtmpl = NULLDISPTMPL; + *tmpllistp = prevtmpl = NULL; if ( next_line_tokens( &buf, &buflen, &toks ) != 2 || strcasecmp( toks[ 0 ], "version" ) != 0 ) { @@ -159,8 +160,8 @@ ldap_init_templates_buf( char *buf, long buflen, } while ( buflen > 0 && ( rc = read_next_tmpl( &buf, &buflen, &tmpl, - version )) == 0 && tmpl != NULLDISPTMPL ) { - if ( prevtmpl == NULLDISPTMPL ) { + version )) == 0 && tmpl != NULL ) { + if ( prevtmpl == NULL ) { *tmpllistp = tmpl; } else { prevtmpl->dt_next = tmpl; @@ -196,27 +197,27 @@ free_disptmpl( struct ldap_disptmpl *tmpl ) { if ( tmpl != NULL ) { if ( tmpl->dt_name != NULL ) { - free( tmpl->dt_name ); + LDAP_FREE( tmpl->dt_name ); } if ( tmpl->dt_pluralname != NULL ) { - free( tmpl->dt_pluralname ); + LDAP_FREE( tmpl->dt_pluralname ); } if ( tmpl->dt_iconname != NULL ) { - free( tmpl->dt_iconname ); + LDAP_FREE( tmpl->dt_iconname ); } if ( tmpl->dt_authattrname != NULL ) { - free( tmpl->dt_authattrname ); + LDAP_FREE( tmpl->dt_authattrname ); } if ( tmpl->dt_defrdnattrname != NULL ) { - free( tmpl->dt_defrdnattrname ); + LDAP_FREE( tmpl->dt_defrdnattrname ); } if ( tmpl->dt_defaddlocation != NULL ) { - free( tmpl->dt_defaddlocation ); + LDAP_FREE( tmpl->dt_defaddlocation ); } if ( tmpl->dt_oclist != NULL ) { @@ -225,7 +226,7 @@ free_disptmpl( struct ldap_disptmpl *tmpl ) for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = nextocp ) { nextocp = ocp->oc_next; free_strarray( ocp->oc_objclasses ); - free( ocp ); + LDAP_FREE( ocp ); } } @@ -235,12 +236,12 @@ free_disptmpl( struct ldap_disptmpl *tmpl ) for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = nextadp ) { nextadp = adp->ad_next; if( adp->ad_attrname != NULL ) { - free( adp->ad_attrname ); + LDAP_FREE( adp->ad_attrname ); } if( adp->ad_value != NULL ) { - free( adp->ad_value ); + LDAP_FREE( adp->ad_value ); } - free( adp ); + LDAP_FREE( adp ); } } @@ -252,20 +253,20 @@ free_disptmpl( struct ldap_disptmpl *tmpl ) for ( colp = rowp; colp != NULL; colp = nextcolp ) { nextcolp = colp->ti_next_in_row; if ( colp->ti_attrname != NULL ) { - free( colp->ti_attrname ); + LDAP_FREE( colp->ti_attrname ); } if ( colp->ti_label != NULL ) { - free( colp->ti_label ); + LDAP_FREE( colp->ti_label ); } if ( colp->ti_args != NULL ) { free_strarray( colp->ti_args ); } - free( colp ); + LDAP_FREE( colp ); } } } - free( tmpl ); + LDAP_FREE( tmpl ); } } @@ -281,7 +282,7 @@ struct ldap_disptmpl * ldap_next_disptmpl( struct ldap_disptmpl *tmpllist, struct ldap_disptmpl *tmpl ) { - return( tmpl == NULLDISPTMPL ? tmpl : tmpl->dt_next ); + return( tmpl == NULL ? tmpl : tmpl->dt_next ); } @@ -290,14 +291,14 @@ ldap_name2template( char *name, struct ldap_disptmpl *tmpllist ) { struct ldap_disptmpl *dtp; - for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL; + for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULL; dtp = ldap_next_disptmpl( tmpllist, dtp )) { if ( strcasecmp( name, dtp->dt_name ) == 0 ) { return( dtp ); } } - return( NULLDISPTMPL ); + return( NULL ); } @@ -309,12 +310,12 @@ ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist ) int i, j, needcnt, matchcnt; if ( tmpllist == NULL || oclist == NULL || oclist[ 0 ] == NULL ) { - return( NULLDISPTMPL ); + return( NULL ); } - for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL; + for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULL; dtp = ldap_next_disptmpl( tmpllist, dtp )) { - for ( oclp = dtp->dt_oclist; oclp != NULLOCLIST; + for ( oclp = dtp->dt_oclist; oclp != NULL; oclp = oclp->oc_next ) { needcnt = matchcnt = 0; for ( i = 0; oclp->oc_objclasses[ i ] != NULL; ++i ) { @@ -333,7 +334,7 @@ ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist ) } } - return( NULLDISPTMPL ); + return( NULL ); } @@ -347,7 +348,7 @@ ldap_first_tmplrow( struct ldap_disptmpl *tmpl ) struct ldap_tmplitem * ldap_next_tmplrow( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row ) { - return( row == NULLTMPLITEM ? row : row->ti_next_in_col ); + return( row == NULL ? row : row->ti_next_in_col ); } @@ -362,7 +363,7 @@ 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 ); + return( col == NULL ? col : col->ti_next_in_row ); } @@ -380,15 +381,15 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, attrcnt = 0; memerr = 0; - if (( attrs = (char **)malloc( sizeof( char * ))) == NULL ) { + if (( attrs = (char **)LDAP_MALLOC( sizeof( char * ))) == NULL ) { return( NULL ); } if ( includeattrs != NULL ) { for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) { - if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) * + if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) * sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] = - strdup( includeattrs[ i ] )) == NULL ) { + LDAP_STRDUP( includeattrs[ i ] )) == NULL ) { memerr = 1; } else { attrs[ attrcnt ] = NULL; @@ -397,10 +398,10 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, } for ( tirowp = ldap_first_tmplrow( tmpl ); - !memerr && tirowp != NULLTMPLITEM; + !memerr && tirowp != NULL; tirowp = ldap_next_tmplrow( tmpl, tirowp )) { for ( ticolp = ldap_first_tmplcol( tmpl, tirowp ); - ticolp != NULLTMPLITEM; + ticolp != NULL; ticolp = ldap_next_tmplcol( tmpl, tirowp, ticolp )) { if ( syntaxmask != 0 ) { @@ -413,9 +414,9 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, } if ( ticolp->ti_attrname != NULL ) { - if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) * + if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) * sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] = - strdup( ticolp->ti_attrname )) == NULL ) { + LDAP_STRDUP( ticolp->ti_attrname )) == NULL ) { memerr = 1; } else { attrs[ attrcnt ] = NULL; @@ -427,11 +428,11 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, if ( memerr || attrcnt == 0 ) { for ( i = 0; i < attrcnt; ++i ) { if ( attrs[ i ] != NULL ) { - free( attrs[ i ] ); + LDAP_FREE( attrs[ i ] ); } } - free( (char *)attrs ); + LDAP_FREE( (char *)attrs ); return( NULL ); } @@ -440,7 +441,7 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, static int -read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, +read_next_tmpl( char **bufp, ber_len_t *blenp, struct ldap_disptmpl **tmplp, int dtversion ) { int i, j, tokcnt, samerow, adsource; @@ -460,13 +461,13 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( tokcnt == 0 ? 0 : LDAP_TMPL_ERR_SYNTAX ); } - if (( tmpl = (struct ldap_disptmpl *)calloc( 1, + if (( tmpl = (struct ldap_disptmpl *)LDAP_CALLOC( 1, sizeof( struct ldap_disptmpl ))) == NULL ) { free_strarray( toks ); return( LDAP_TMPL_ERR_MEM ); } tmpl->dt_name = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template plural name comes next @@ -477,7 +478,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_pluralname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template icon name is next @@ -488,7 +489,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_iconname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template options come next @@ -511,7 +512,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, * object class list is next */ while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) { - if (( ocp = (struct ldap_oclist *)calloc( 1, + if (( ocp = (struct ldap_oclist *)LDAP_CALLOC( 1, sizeof( struct ldap_oclist ))) == NULL ) { free_strarray( toks ); free_disptmpl( tmpl ); @@ -541,9 +542,9 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, if ( toks[ 0 ][ 0 ] != '\0' ) { tmpl->dt_authattrname = toks[ 0 ]; } else { - free( toks[ 0 ] ); + LDAP_FREE( toks[ 0 ] ); } - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * read default attribute to use for RDN @@ -554,7 +555,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_defrdnattrname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * read default location for new entries @@ -567,9 +568,9 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, if ( toks[ 0 ][ 0 ] != '\0' ) { tmpl->dt_defaddlocation = toks[ 0 ]; } else { - free( toks[ 0 ] ); + LDAP_FREE( toks[ 0 ] ); } - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * read list of rules used to define default values for new entries @@ -590,7 +591,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } - if (( adp = (struct ldap_adddeflist *)calloc( 1, + if (( adp = (struct ldap_adddeflist *)LDAP_CALLOC( 1, sizeof( struct ldap_adddeflist ))) == NULL ) { free_strarray( toks ); free_disptmpl( tmpl ); @@ -601,8 +602,8 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, if ( adsource == LDAP_ADSRC_CONSTANTVALUE ) { adp->ad_value = toks[ 2 ]; } - free( toks[ 0 ] ); - free( (char *)toks ); + LDAP_FREE( toks[ 0 ] ); + LDAP_FREE( (char *)toks ); if ( tmpl->dt_adddeflist == NULL ) { tmpl->dt_adddeflist = adp; @@ -624,7 +625,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } - if (( ip = (struct ldap_tmplitem *)calloc( 1, + if (( ip = (struct ldap_tmplitem *)LDAP_CALLOC( 1, sizeof( struct ldap_tmplitem ))) == NULL ) { free_strarray( toks ); free_disptmpl( tmpl ); @@ -660,13 +661,13 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } - free( toks[ 0 ] ); - free( toks[ 1 ] ); + LDAP_FREE( toks[ 0 ] ); + LDAP_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 ] ); + LDAP_FREE( toks[ 3 ] ); } else { ip->ti_attrname = toks[ 3 ]; } @@ -674,7 +675,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, for ( i = 0; toks[ i + 4 ] != NULL; ++i ) { ; } - if (( ip->ti_args = (char **) calloc( i + 1, sizeof( char * ))) + if (( ip->ti_args = (char **) LDAP_CALLOC( i + 1, sizeof( char * ))) == NULL ) { free_disptmpl( tmpl ); return( LDAP_TMPL_ERR_MEM ); @@ -683,7 +684,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, ip->ti_args[ i ] = toks[ i + 4 ]; } } - free( (char *)toks ); + LDAP_FREE( (char *)toks ); if ( tmpl->dt_items == NULL ) { tmpl->dt_items = rowp = ip;