Commit 853c2c80 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

zap ldapv2 only stuff

parent d60ef41c
......@@ -11,8 +11,8 @@ PROGRAMS = apitest dntest ftest ltest
SRCS = bind.c open.c result.c error.c compare.c search.c \
controls.c messages.c references.c extended.c cyrus.c \
modify.c add.c modrdn.c delete.c abandon.c cache.c \
getfilter.c sasl.c sbind.c kbind.c unbind.c \
filter.c free.c dsparse.c sort.c \
sasl.c sbind.c kbind.c unbind.c \
filter.c free.c sort.c \
getdn.c getentry.c getattr.c getvalues.c addentry.c \
request.c os-ip.c url.c sortctrl.c vlvctrl.c \
init.c options.c print.c string.c util-int.c schema.c \
......@@ -20,8 +20,8 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \
OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
controls.lo messages.lo references.lo extended.lo cyrus.lo \
modify.lo add.lo modrdn.lo delete.lo abandon.lo cache.lo \
getfilter.lo sasl.lo sbind.lo kbind.lo unbind.lo \
filter.lo free.lo dsparse.lo sort.lo \
sasl.lo sbind.lo kbind.lo unbind.lo \
filter.lo free.lo sort.lo \
getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \
request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.lo \
......@@ -46,7 +46,7 @@ ftest: $(XLIBS) ftest.o
ltest: $(XLIBS) test.o
$(LTLINK) -o $@ test.o $(LIBS)
CFFILES=ldap.conf ldapfilter.conf
CFFILES=ldap.conf
install-local: $(CFFILES) FORCE
-$(MKDIR) $(DESTDIR)$(libdir)
......
/*
* Copyright (c) 1993, 1994 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*
* dsparse.c: parsing routines used by display template and search
* preference file library routines for LDAP clients.
*
* 7 March 1994 by Mark C Smith
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#else /* MACOS */
#ifdef DOS
#include <malloc.h>
#include "msdos.h"
#else /* DOS */
#include <sys/types.h>
#include <sys/file.h>
#include <stdlib.h>
#endif /* DOS */
#endif /* MACOS */
#include "lber.h"
#include "ldap.h"
#ifndef NEEDPROTOS
int next_line_tokens();
void free_strarray();
static int next_line();
static char *next_token();
#else /* !NEEDPROTOS */
int next_line_tokens( char **bufp, long *blenp, char ***toksp );
void free_strarray( char **sap );
static int next_line( char **bufp, long *blenp, char **linep );
static char *next_token( char ** sp );
#endif /* !NEEDPROTOS */
int
next_line_tokens( char **bufp, long *blenp, char ***toksp )
{
char *p, *line, *token, **toks;
int rc, tokcnt;
*toksp = NULL;
if (( rc = next_line( bufp, blenp, &line )) <= 0 ) {
return( rc );
}
if (( toks = (char **)calloc( 1, sizeof( char * ))) == NULL ) {
free( line );
return( -1 );
}
tokcnt = 0;
p = line;
while (( token = next_token( &p )) != NULL ) {
if (( toks = (char **)realloc( toks, ( tokcnt + 2 ) *
sizeof( char * ))) == NULL ) {
free( (char *)toks );
free( line );
return( -1 );
}
toks[ tokcnt ] = token;
toks[ ++tokcnt ] = NULL;
}
if ( tokcnt == 1 && strcasecmp( toks[ 0 ], "END" ) == 0 ) {
tokcnt = 0;
free_strarray( toks );
toks = NULL;
}
free( line );
if ( tokcnt == 0 ) {
if ( toks != NULL ) {
free( (char *)toks );
}
} else {
*toksp = toks;
}
return( tokcnt );
}
static int
next_line( char **bufp, long *blenp, char **linep )
{
char *linestart, *line, *p;
long plen;
linestart = *bufp;
p = *bufp;
plen = *blenp;
do {
for ( linestart = p; plen > 0; ++p, --plen ) {
if ( *p == '\r' ) {
if ( plen > 1 && *(p+1) == '\n' ) {
++p;
--plen;
}
break;
}
if ( *p == '\n' ) {
if ( plen > 1 && *(p+1) == '\r' ) {
++p;
--plen;
}
break;
}
}
++p;
--plen;
} while ( plen > 0 && ( *linestart == '#' || linestart + 1 == p ));
*bufp = p;
*blenp = plen;
if ( plen <= 0 ) {
*linep = NULL;
return( 0 ); /* end of file */
}
if (( line = malloc( p - linestart )) == NULL ) {
*linep = NULL;
return( -1 ); /* fatal error */
}
(void) memcpy( line, linestart, p - linestart );
line[ p - linestart - 1 ] = '\0';
*linep = line;
return( strlen( line ));
}
static char *
next_token( char **sp )
{
int in_quote = 0;
char *p, *tokstart, *t;
if ( **sp == '\0' ) {
return( NULL );
}
p = *sp;
while ( isspace( *p )) { /* skip leading white space */
++p;
}
if ( *p == '\0' ) {
return( NULL );
}
if ( *p == '\"' ) {
in_quote = 1;
++p;
}
t = tokstart = p;
for ( ;; ) {
if ( *p == '\0' || ( isspace( *p ) && !in_quote )) {
if ( *p != '\0' ) {
++p;
}
*t++ = '\0'; /* end of token */
break;
}
if ( *p == '\"' ) {
in_quote = !in_quote;
++p;
} else {
*t++ = *p++;
}
}
*sp = p;
if ( t == tokstart ) {
return( NULL );
}
return( strdup( tokstart ));
}
void
free_strarray( char **sap )
{
int i;
if ( sap != NULL ) {
for ( i = 0; sap[ i ] != NULL; ++i ) {
free( sap[ i ] );
}
free( (char *)sap );
}
}
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
* Copyright (c) 1994 The Regents of the University of Michigan.
* All rights reserved.
*
......@@ -6,64 +11,53 @@
* link in lots of extra code when not using certain features
*/
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
#endif
#include "portable.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef MACOS
#include <stdlib.h>
#include "macos.h"
#else /* MACOS */
#ifdef DOS
#include <malloc.h>
#include "msdos.h"
#else /* DOS */
#include <sys/types.h>
#include <stdlib.h>
#endif /* DOS */
#endif /* MACOS */
#include "lber.h"
#include "ldap.h"
#include <ac/stdlib.h>
#include <ac/string.h>
#include <ac/time.h>
#include "ldap-int.h"
/*
* C-API deallocator
*/
void
ldap_getfilter_free( LDAPFiltDesc *lfdp )
ldap_memfree( void *p )
{
LDAPFiltList *flp, *nextflp;
LDAPFiltInfo *fip, *nextfip;
for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
nextfip = fip->lfi_next;
free( fip->lfi_filter );
free( fip->lfi_desc );
free( fip );
}
nextflp = flp->lfl_next;
free( flp->lfl_pattern );
free( flp->lfl_delims );
free( flp->lfl_tag );
free( flp );
}
if ( lfdp->lfd_curvalcopy != NULL ) {
free( lfdp->lfd_curvalcopy );
}
if ( lfdp->lfd_curvalwords != NULL ) {
free( lfdp->lfd_curvalwords );
}
if ( lfdp->lfd_filtprefix != NULL ) {
free( lfdp->lfd_filtprefix );
}
if ( lfdp->lfd_filtsuffix != NULL ) {
free( lfdp->lfd_filtsuffix );
}
free( lfdp );
LDAP_FREE( p );
}
void
ldap_memvfree( void **v )
{
LDAP_VFREE( v );
}
void *
ldap_memalloc( ber_len_t s )
{
return LDAP_MALLOC( s );
}
void *
ldap_memcalloc( ber_len_t n, ber_len_t s )
{
return LDAP_CALLOC( n, s );
}
void *
ldap_memrealloc( void* p, ber_len_t s )
{
return LDAP_REALLOC( p, s );
}
char *
ldap_strdup( LDAP_CONST char *p )
{
return LDAP_STRDUP( p );
}
/*
......@@ -82,13 +76,21 @@ ldap_mods_free( LDAPMod **mods, int freemods )
for ( i = 0; mods[i] != NULL; i++ ) {
if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
ber_bvecfree( mods[i]->mod_bvalues );
} else {
ldap_value_free( mods[i]->mod_values );
if( mods[i]->mod_bvalues != NULL )
ber_bvecfree( mods[i]->mod_bvalues );
} else if( mods[i]->mod_values != NULL ) {
LDAP_VFREE( mods[i]->mod_values );
}
free( (char *) mods[i] );
if ( mods[i]->mod_type != NULL ) {
LDAP_FREE( mods[i]->mod_type );
}
LDAP_FREE( (char *) mods[i] );
}
if ( freemods )
free( (char *) mods );
if ( freemods ) {
LDAP_FREE( (char *) mods );
}
}
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
* Copyright (c) 1993 Regents of the University of Michigan.
* All rights reserved.
*
* getfilter.c -- optional add-on to libldap
*/
#include "portable.h"
#include <stdio.h>
#include <ac/stdlib.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
#include <sys/file.h>
#endif
#include "ldap-int.h"
static int break_into_words LDAP_P((
/* LDAP_CONST */ char *str,
LDAP_CONST char *delims,
char ***wordsp ));
#define FILT_MAX_LINE_LEN 1024
static LDAPFiltDesc *
ldap_init_getfilter_buf( char *buf, ber_len_t buflen )
{
LDAPFiltDesc *lfdp;
LDAPFiltList *flp, *nextflp;
LDAPFiltInfo *fip, *nextfip;
char *tag, **tok;
int tokcnt, i;
int rc;
regex_t re;
if (( lfdp = (LDAPFiltDesc *)LDAP_CALLOC( 1, sizeof( LDAPFiltDesc))) == NULL ) {
return( NULL );
}
flp = nextflp = NULL;
fip = NULL;
tag = NULL;
while ( buflen > 0 && ( tokcnt = ldap_int_next_line_tokens( &buf, &buflen, &tok ))
> 0 ) {
switch( tokcnt ) {
case 1: /* tag line */
if ( tag != NULL ) {
LDAP_FREE( tag );
}
tag = tok[ 0 ];
LDAP_FREE( tok );
break;
case 4:
case 5: /* start of filter info. list */
if (( nextflp = (LDAPFiltList *)LDAP_CALLOC( 1, sizeof( LDAPFiltList )))
== NULL ) {
ldap_getfilter_free( lfdp );
return( NULL );
}
nextflp->lfl_tag = LDAP_STRDUP( tag );
nextflp->lfl_pattern = tok[ 0 ];
if ( (rc = regcomp( &re, nextflp->lfl_pattern, 0 )) != 0 ) {
char error[512];
regerror(rc, &re, error, sizeof(error));
ldap_getfilter_free( lfdp );
#ifdef NEW_LOGGING
LDAP_LOG ( FILTER, ERR,
"ldap_init_get_filter_buf: bad regular expression %s, %s\n",
nextflp->lfl_pattern, error, 0 );
#else
Debug( LDAP_DEBUG_ANY, "ldap_init_get_filter_buf: "
"bad regular expression %s, %s\n",
nextflp->lfl_pattern, error, 0 );
#endif
errno = EINVAL;
LDAP_VFREE( tok );
return( NULL );
}
regfree(&re);
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 *)LDAP_CALLOC( 1,
sizeof( LDAPFiltInfo ))) == NULL ) {
ldap_getfilter_free( lfdp );
LDAP_VFREE( 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 {
LDAP_VFREE( tok );
ldap_getfilter_free( lfdp );
errno = EINVAL;
return( NULL );
}
LDAP_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 );
LDAP_FREE( tok );
}
break;
default:
LDAP_VFREE( tok );
ldap_getfilter_free( lfdp );
errno = EINVAL;
return( NULL );
}
}
if ( tag != NULL ) {
LDAP_FREE( tag );
}
return( lfdp );
}
LDAPFiltDesc *
ldap_init_getfilter( LDAP_CONST char *fname )
{
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 );
}
if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
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 */
LDAP_FREE( buf );
return( NULL );
}
lfdp = ldap_init_getfilter_buf( buf, rlen );
LDAP_FREE( buf );
return( lfdp );
}
LDAPFiltInfo *
ldap_getfirstfilter(
LDAPFiltDesc *lfdp,
/* LDAP_CONST */ char *tagpat,
/* LDAP_CONST */ char *value )