1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
1998-08-08 20:43:13 -04:00
|
|
|
/*
|
2000-05-12 22:36:07 -04:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1998-12-28 15:53:15 -05:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
|
|
|
|
/* Portions
|
1998-08-08 20:43:13 -04:00
|
|
|
* Copyright (c) 1993 Regents of the University of Michigan.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* getfilter.c -- optional add-on to libldap
|
|
|
|
|
*/
|
|
|
|
|
|
1998-10-24 21:41:42 -04:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1999-06-02 20:37:44 -04:00
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
|
#include <ac/errno.h>
|
|
|
|
|
#include <ac/regex.h>
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_FILE_H
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <sys/file.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
#endif
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-10-25 20:18:41 -05:00
|
|
|
#include "ldap-int.h"
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-05-18 21:12:33 -04:00
|
|
|
static int break_into_words LDAP_P((
|
|
|
|
|
/* LDAP_CONST */ char *str,
|
|
|
|
|
LDAP_CONST char *delims,
|
|
|
|
|
char ***wordsp ));
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
#define FILT_MAX_LINE_LEN 1024
|
|
|
|
|
|
|
|
|
|
LDAPFiltDesc *
|
1999-05-18 21:12:33 -04:00
|
|
|
ldap_init_getfilter( LDAP_CONST char *fname )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char *buf;
|
|
|
|
|
long rlen, len;
|
|
|
|
|
int eof;
|
|
|
|
|
LDAPFiltDesc *lfdp;
|
|
|
|
|
|
|
|
|
|
if (( fp = fopen( fname, "r" )) == NULL ) {
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( fseek( fp, 0L, SEEK_END ) != 0 ) { /* move to end to get len */
|
|
|
|
|
fclose( fp );
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = ftell( fp );
|
|
|
|
|
|
|
|
|
|
if ( fseek( fp, 0L, SEEK_SET ) != 0 ) { /* back to start of file */
|
|
|
|
|
fclose( fp );
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
fclose( fp );
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rlen = fread( buf, 1, (size_t)len, fp );
|
|
|
|
|
eof = feof( fp );
|
|
|
|
|
fclose( fp );
|
|
|
|
|
|
|
|
|
|
if ( rlen != len && !eof ) { /* error: didn't get the whole file */
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( buf );
|
1998-08-08 20:43:13 -04:00
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lfdp = ldap_init_getfilter_buf( buf, rlen );
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( buf );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
return( lfdp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LDAPFiltDesc *
|
1999-06-18 19:53:05 -04:00
|
|
|
ldap_init_getfilter_buf( char *buf, ber_len_t buflen )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
LDAPFiltDesc *lfdp;
|
|
|
|
|
LDAPFiltList *flp, *nextflp;
|
|
|
|
|
LDAPFiltInfo *fip, *nextfip;
|
1998-08-21 02:33:42 -04:00
|
|
|
char *tag, **tok;
|
|
|
|
|
int tokcnt, i;
|
|
|
|
|
int rc;
|
|
|
|
|
regex_t re;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( lfdp = (LDAPFiltDesc *)LDAP_CALLOC( 1, sizeof( LDAPFiltDesc))) == NULL ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
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 ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( tag );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
tag = tok[ 0 ];
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( tok );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
case 5: /* start of filter info. list */
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( nextflp = (LDAPFiltList *)LDAP_CALLOC( 1, sizeof( LDAPFiltList )))
|
1998-08-08 20:43:13 -04:00
|
|
|
== NULL ) {
|
|
|
|
|
ldap_getfilter_free( lfdp );
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
1999-06-02 18:28:22 -04:00
|
|
|
nextflp->lfl_tag = LDAP_STRDUP( tag );
|
1998-08-08 20:43:13 -04:00
|
|
|
nextflp->lfl_pattern = tok[ 0 ];
|
1998-08-21 02:33:42 -04:00
|
|
|
if ( (rc = regcomp( &re, nextflp->lfl_pattern, 0 )) != 0 ) {
|
1998-10-24 21:41:42 -04:00
|
|
|
#ifdef LDAP_LIBUI
|
1998-08-21 02:33:42 -04:00
|
|
|
char error[512];
|
|
|
|
|
regerror(rc, &re, error, sizeof(error));
|
1998-08-08 20:43:13 -04:00
|
|
|
ldap_getfilter_free( lfdp );
|
1999-02-02 15:38:45 -05:00
|
|
|
fprintf( stderr, "bad regular expression %s, %s\n",
|
1998-08-21 02:33:42 -04:00
|
|
|
nextflp->lfl_pattern, error );
|
1998-08-08 20:43:13 -04:00
|
|
|
errno = EINVAL;
|
1998-10-24 21:41:42 -04:00
|
|
|
#endif /* LDAP_LIBUI */
|
1998-08-08 20:43:13 -04:00
|
|
|
free_strarray( tok );
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
1998-08-21 02:33:42 -04:00
|
|
|
regfree(&re);
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
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 */
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( nextfip = (LDAPFiltInfo *)LDAP_CALLOC( 1,
|
1998-08-08 20:43:13 -04:00
|
|
|
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 );
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( tok[ 2 ] );
|
1998-08-08 20:43:13 -04:00
|
|
|
tok[ 2 ] = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
nextfip->lfi_scope = LDAP_SCOPE_SUBTREE; /* default */
|
|
|
|
|
}
|
|
|
|
|
nextfip->lfi_isexact = ( strchr( tok[ 0 ], '*' ) == NULL &&
|
|
|
|
|
strchr( tok[ 0 ], '~' ) == NULL );
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( tok );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
free_strarray( tok );
|
|
|
|
|
ldap_getfilter_free( lfdp );
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( tag != NULL ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( tag );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return( lfdp );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-18 21:12:33 -04:00
|
|
|
ldap_setfilteraffixes( LDAPFiltDesc *lfdp, LDAP_CONST char *prefix, LDAP_CONST char *suffix )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
if ( lfdp->lfd_filtprefix != NULL ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( lfdp->lfd_filtprefix );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1999-06-02 18:28:22 -04:00
|
|
|
lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : LDAP_STRDUP( prefix );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
if ( lfdp->lfd_filtsuffix != NULL ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( lfdp->lfd_filtsuffix );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1999-06-02 18:28:22 -04:00
|
|
|
lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : LDAP_STRDUP( suffix );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LDAPFiltInfo *
|
1999-05-18 21:12:33 -04:00
|
|
|
ldap_getfirstfilter(
|
|
|
|
|
LDAPFiltDesc *lfdp,
|
|
|
|
|
/* LDAP_CONST */ char *tagpat,
|
|
|
|
|
/* LDAP_CONST */ char *value )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
LDAPFiltList *flp;
|
1998-08-21 02:33:42 -04:00
|
|
|
int rc;
|
|
|
|
|
regex_t re;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
if ( lfdp->lfd_curvalcopy != NULL ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( lfdp->lfd_curvalcopy );
|
|
|
|
|
LDAP_FREE( lfdp->lfd_curvalwords );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lfdp->lfd_curval = value;
|
|
|
|
|
lfdp->lfd_curfip = NULL;
|
|
|
|
|
|
1998-08-21 02:33:42 -04:00
|
|
|
for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = flp->lfl_next ) {
|
|
|
|
|
/* compile tagpat, continue if we fail */
|
1999-08-25 02:44:08 -04:00
|
|
|
if (regcomp(&re, tagpat, REG_EXTENDED|REG_NOSUB) != 0)
|
1998-08-21 02:33:42 -04:00
|
|
|
continue;
|
|
|
|
|
|
1999-08-25 02:44:08 -04:00
|
|
|
/* match tagpattern and tag, continue if we fail */
|
1998-08-21 02:33:42 -04:00
|
|
|
rc = regexec(&re, flp->lfl_tag, 0, NULL, 0);
|
|
|
|
|
regfree(&re);
|
|
|
|
|
if (rc != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* compile flp->ifl_pattern, continue if we fail */
|
1999-08-25 02:44:08 -04:00
|
|
|
if (regcomp(&re, flp->lfl_pattern, REG_EXTENDED|REG_NOSUB) != 0)
|
1998-08-21 02:33:42 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* match ifl_pattern and lfd_curval, continue if we fail */
|
|
|
|
|
rc = regexec(&re, lfdp->lfd_curval, 0, NULL, 0);
|
|
|
|
|
regfree(&re);
|
|
|
|
|
if (rc != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* we successfully compiled both patterns and matched both values */
|
|
|
|
|
lfdp->lfd_curfip = flp->lfl_ilist;
|
|
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( lfdp->lfd_curfip == NULL ) {
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-02 18:28:22 -04:00
|
|
|
if (( lfdp->lfd_curvalcopy = LDAP_STRDUP( value )) == NULL ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( break_into_words( lfdp->lfd_curvalcopy, flp->lfl_delims,
|
|
|
|
|
&lfdp->lfd_curvalwords ) < 0 ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
LDAP_FREE( lfdp->lfd_curvalcopy );
|
1998-08-08 20:43:13 -04:00
|
|
|
lfdp->lfd_curvalcopy = NULL;
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return( ldap_getnextfilter( lfdp ));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LDAPFiltInfo *
|
|
|
|
|
ldap_getnextfilter( LDAPFiltDesc *lfdp )
|
|
|
|
|
{
|
|
|
|
|
LDAPFiltInfo *fip;
|
|
|
|
|
|
|
|
|
|
fip = lfdp->lfd_curfip;
|
|
|
|
|
|
|
|
|
|
if ( fip == NULL ) {
|
|
|
|
|
return( NULL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lfdp->lfd_curfip = fip->lfi_next;
|
|
|
|
|
|
|
|
|
|
ldap_build_filter( lfdp->lfd_filter, LDAP_FILT_MAXSIZ, fip->lfi_filter,
|
|
|
|
|
lfdp->lfd_filtprefix, lfdp->lfd_filtsuffix, NULL,
|
|
|
|
|
lfdp->lfd_curval, lfdp->lfd_curvalwords );
|
|
|
|
|
lfdp->lfd_retfi.lfi_filter = lfdp->lfd_filter;
|
|
|
|
|
lfdp->lfd_retfi.lfi_desc = fip->lfi_desc;
|
|
|
|
|
lfdp->lfd_retfi.lfi_scope = fip->lfi_scope;
|
|
|
|
|
lfdp->lfd_retfi.lfi_isexact = fip->lfi_isexact;
|
|
|
|
|
|
|
|
|
|
return( &lfdp->lfd_retfi );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-05-18 21:12:33 -04:00
|
|
|
ldap_build_filter(
|
|
|
|
|
char *filtbuf,
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_len_t buflen,
|
1999-05-18 21:12:33 -04:00
|
|
|
LDAP_CONST char *pattern,
|
|
|
|
|
LDAP_CONST char *prefix,
|
|
|
|
|
LDAP_CONST char *suffix,
|
|
|
|
|
LDAP_CONST char *attr,
|
|
|
|
|
LDAP_CONST char *value,
|
|
|
|
|
char **valwords )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
1999-05-18 21:12:33 -04:00
|
|
|
const char *p;
|
|
|
|
|
char *f;
|
1998-08-08 20:43:13 -04:00
|
|
|
size_t slen;
|
|
|
|
|
int i, wordcount, wordnum, endwordnum;
|
|
|
|
|
|
|
|
|
|
if ( valwords == NULL ) {
|
|
|
|
|
wordcount = 0;
|
|
|
|
|
} else {
|
|
|
|
|
for ( wordcount = 0; valwords[ wordcount ] != NULL; ++wordcount ) {
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f = filtbuf;
|
|
|
|
|
|
|
|
|
|
if ( prefix != NULL ) {
|
|
|
|
|
strcpy( f, prefix );
|
|
|
|
|
f += strlen( prefix );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( p = pattern; *p != '\0'; ++p ) {
|
|
|
|
|
if ( *p == '%' ) {
|
|
|
|
|
++p;
|
|
|
|
|
if ( *p == 'v' ) {
|
1999-02-22 12:57:22 -05:00
|
|
|
if ( isdigit( (unsigned char) p[1] )) {
|
1998-08-08 20:43:13 -04:00
|
|
|
++p;
|
|
|
|
|
wordnum = *p - '1';
|
|
|
|
|
if ( *(p+1) == '-' ) {
|
|
|
|
|
++p;
|
1999-02-22 12:57:22 -05:00
|
|
|
if ( isdigit( (unsigned char) p[1] )) {
|
1998-08-08 20:43:13 -04:00
|
|
|
++p;
|
|
|
|
|
endwordnum = *p - '1'; /* e.g., "%v2-4" */
|
|
|
|
|
if ( endwordnum > wordcount - 1 ) {
|
|
|
|
|
endwordnum = wordcount - 1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
endwordnum = wordcount - 1; /* e.g., "%v2-" */
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
endwordnum = wordnum; /* e.g., "%v2" */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( wordcount > 0 ) {
|
|
|
|
|
for ( i = wordnum; i <= endwordnum; ++i ) {
|
|
|
|
|
if ( i > wordnum ) { /* add blank btw words */
|
|
|
|
|
*f++ = ' ';
|
|
|
|
|
}
|
|
|
|
|
slen = strlen( valwords[ i ] );
|
|
|
|
|
SAFEMEMCPY( f, valwords[ i ], slen );
|
|
|
|
|
f += slen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if ( *(p+1) == '$' ) {
|
|
|
|
|
++p;
|
|
|
|
|
if ( wordcount > 0 ) {
|
|
|
|
|
wordnum = wordcount - 1;
|
|
|
|
|
slen = strlen( valwords[ wordnum ] );
|
|
|
|
|
SAFEMEMCPY( f, valwords[ wordnum ], slen );
|
|
|
|
|
f += slen;
|
|
|
|
|
}
|
|
|
|
|
} else if ( value != NULL ) {
|
|
|
|
|
slen = strlen( value );
|
|
|
|
|
SAFEMEMCPY( f, value, slen );
|
|
|
|
|
f += slen;
|
|
|
|
|
}
|
|
|
|
|
} else if ( *p == 'a' && attr != NULL ) {
|
|
|
|
|
slen = strlen( attr );
|
|
|
|
|
SAFEMEMCPY( f, attr, slen );
|
|
|
|
|
f += slen;
|
|
|
|
|
} else {
|
|
|
|
|
*f++ = *p;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
*f++ = *p;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-02 01:51:04 -04:00
|
|
|
if ( (size_t) (f - filtbuf) > buflen ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
/* sanity check */
|
|
|
|
|
--f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-02 01:51:04 -04:00
|
|
|
if ( suffix != NULL && ( (size_t) (f - filtbuf) < buflen ) )
|
1998-10-24 21:41:42 -04:00
|
|
|
{
|
1998-08-08 20:43:13 -04:00
|
|
|
strcpy( f, suffix );
|
|
|
|
|
} else {
|
|
|
|
|
*f = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
1999-05-18 21:12:33 -04:00
|
|
|
break_into_words( /* LDAP_CONST */ char *str, LDAP_CONST char *delims, char ***wordsp )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
char *word, **words;
|
|
|
|
|
int count;
|
1998-12-18 20:27:20 -05:00
|
|
|
char *tok_r;
|
|
|
|
|
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( words = (char **)LDAP_CALLOC( 1, sizeof( char * ))) == NULL ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
return( -1 );
|
|
|
|
|
}
|
|
|
|
|
count = 0;
|
|
|
|
|
words[ count ] = NULL;
|
|
|
|
|
|
1999-01-15 09:49:03 -05:00
|
|
|
word = ldap_pvt_strtok( str, delims, &tok_r );
|
1998-08-08 20:43:13 -04:00
|
|
|
while ( word != NULL ) {
|
1999-05-28 21:19:14 -04:00
|
|
|
if (( words = (char **)LDAP_REALLOC( words,
|
1998-08-08 20:43:13 -04:00
|
|
|
( count + 2 ) * sizeof( char * ))) == NULL ) {
|
|
|
|
|
return( -1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
words[ count ] = word;
|
|
|
|
|
words[ ++count ] = NULL;
|
1999-01-15 09:49:03 -05:00
|
|
|
word = ldap_pvt_strtok( NULL, delims, &tok_r );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*wordsp = words;
|
|
|
|
|
return( count );
|
|
|
|
|
}
|