void free_execve_info(struct ExecveInfo *execi) { free_strarray(execi->argv); free_strarray(execi->envp); free(execi->binary); free(execi); }
int ldap_init_templates_buf( char *buf, long buflen, struct ldap_disptmpl **tmpllistp ) { int rc, version; char **toks; struct ldap_disptmpl *prevtmpl, *tmpl; *tmpllistp = prevtmpl = NULLDISPTMPL; if ( next_line_tokens( &buf, &buflen, &toks ) != 2 || strcasecmp( toks[ 0 ], "version" ) != 0 ) { free_strarray( toks ); return( LDAP_TMPL_ERR_SYNTAX ); } version = atoi( toks[ 1 ] ); free_strarray( toks ); if ( version != LDAP_TEMPLATE_VERSION ) { return( LDAP_TMPL_ERR_VERSION ); } while ( buflen > 0 && ( rc = read_next_tmpl( &buf, &buflen, &tmpl, version )) == 0 && tmpl != NULLDISPTMPL ) { if ( prevtmpl == NULLDISPTMPL ) { *tmpllistp = tmpl; } else { prevtmpl->dt_next = tmpl; } prevtmpl = tmpl; } if ( rc != 0 ) { ldap_free_templates( *tmpllistp ); } return( rc ); }
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 ); }
static void free_disptmpl( struct ldap_disptmpl *tmpl ) { if ( tmpl != NULL ) { if ( tmpl->dt_name != NULL ) { free( tmpl->dt_name ); } if ( tmpl->dt_pluralname != NULL ) { free( tmpl->dt_pluralname ); } if ( tmpl->dt_iconname != NULL ) { free( tmpl->dt_iconname ); } if ( tmpl->dt_authattrname != NULL ) { free( tmpl->dt_authattrname ); } if ( tmpl->dt_defrdnattrname != NULL ) { free( tmpl->dt_defrdnattrname ); } if ( tmpl->dt_defaddlocation != NULL ) { free( tmpl->dt_defaddlocation ); } if ( tmpl->dt_oclist != NULL ) { struct ldap_oclist *ocp, *nextocp; for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = nextocp ) { nextocp = ocp->oc_next; free_strarray( ocp->oc_objclasses ); free( ocp ); } } if ( tmpl->dt_adddeflist != NULL ) { struct ldap_adddeflist *adp, *nextadp; for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = nextadp ) { nextadp = adp->ad_next; if( adp->ad_attrname != NULL ) { free( adp->ad_attrname ); } if( adp->ad_value != NULL ) { free( adp->ad_value ); } free( adp ); } } if ( tmpl->dt_items != NULL ) { struct ldap_tmplitem *rowp, *nextrowp, *colp, *nextcolp; for ( rowp = tmpl->dt_items; rowp != NULL; rowp = nextrowp ) { nextrowp = rowp->ti_next_in_col; for ( colp = rowp; colp != NULL; colp = nextcolp ) { nextcolp = colp->ti_next_in_row; if ( colp->ti_attrname != NULL ) { free( colp->ti_attrname ); } if ( colp->ti_label != NULL ) { free( colp->ti_label ); } if ( colp->ti_args != NULL ) { free_strarray( colp->ti_args ); } free( colp ); } } } free( tmpl ); } }
LDAPFiltDesc * ldap_init_getfilter_buf( char *buf, long buflen ) { LDAPFiltDesc *lfdp; LDAPFiltList *flp, *nextflp; LDAPFiltInfo *fip, *nextfip; char *tag, **tok; int tokcnt, i; if (( lfdp = (LDAPFiltDesc *)calloc( 1, sizeof( LDAPFiltDesc))) == NULL ) { return( NULL ); } flp = nextflp = NULL; fip = NULL; tag = NULL; while ( buflen > 0 && ( tokcnt = next_line_tokens( &buf, &buflen, &tok )) > 0 ) { switch( tokcnt ) { case 1: /* tag line */ if ( tag != NULL ) { free( tag ); } tag = tok[ 0 ]; free( tok ); break; case 4: case 5: /* start of filter info. list */ if (( nextflp = (LDAPFiltList *)calloc( 1, sizeof( LDAPFiltList ))) == NULL ) { ldap_getfilter_free( lfdp ); return( NULL ); } nextflp->lfl_tag = strdup( tag ); nextflp->lfl_pattern = tok[ 0 ]; if ( re_comp( nextflp->lfl_pattern ) != NULL ) { #ifndef NO_USERINTERFACE ldap_getfilter_free( lfdp ); fprintf( stderr, "bad regular expresssion %s\n", nextflp->lfl_pattern ); #if !defined( MACOS ) && !defined( DOS ) && !defined(PGPSOCKETSLDAP) /* jason */ errno = EINVAL; #endif #endif /* NO_USERINTERFACE */ free_strarray( tok ); return( NULL ); } nextflp->lfl_delims = tok[ 1 ]; nextflp->lfl_ilist = NULL; nextflp->lfl_next = NULL; if ( flp == NULL ) { /* first one */ lfdp->lfd_filtlist = nextflp; } else { flp->lfl_next = nextflp; } flp = nextflp; fip = NULL; for ( i = 2; i < 5; ++i ) { tok[ i - 2 ] = tok[ i ]; } /* fall through */ case 2: case 3: /* filter, desc, and optional search scope */ if ( nextflp != NULL ) { /* add to info list */ if (( nextfip = (LDAPFiltInfo *)calloc( 1, sizeof( LDAPFiltInfo ))) == NULL ) { ldap_getfilter_free( lfdp ); free_strarray( tok ); return( NULL ); } if ( fip == NULL ) { /* first one */ nextflp->lfl_ilist = nextfip; } else { fip->lfi_next = nextfip; } fip = nextfip; nextfip->lfi_next = NULL; nextfip->lfi_filter = tok[ 0 ]; nextfip->lfi_desc = tok[ 1 ]; if ( tok[ 2 ] != NULL ) { if ( strcasecmp( tok[ 2 ], "subtree" ) == 0 ) { nextfip->lfi_scope = LDAP_SCOPE_SUBTREE; } else if ( strcasecmp( tok[ 2 ], "onelevel" ) == 0 ) { nextfip->lfi_scope = LDAP_SCOPE_ONELEVEL; } else if ( strcasecmp( tok[ 2 ], "base" ) == 0 ) { nextfip->lfi_scope = LDAP_SCOPE_BASE; } else { free_strarray( tok ); ldap_getfilter_free( lfdp ); #if !defined( MACOS ) && !defined( DOS ) && !defined(PGPSOCKETSLDAP) /* jason */ errno = EINVAL; #endif return( NULL ); } free( tok[ 2 ] ); tok[ 2 ] = NULL; } else { nextfip->lfi_scope = LDAP_SCOPE_SUBTREE; /* default */ } nextfip->lfi_isexact = ( strchr( tok[ 0 ], '*' ) == NULL && strchr( tok[ 0 ], '~' ) == NULL ); free( tok ); } break; default: free_strarray( tok ); ldap_getfilter_free( lfdp ); #if !defined( MACOS ) && !defined( DOS ) && !defined(PGPSOCKETSLDAP) /* jason */ errno = EINVAL; #endif return( NULL ); } } if ( tag != NULL ) { free( tag ); } return( lfdp ); }