From 07c7d3c3cbb4fbde27c705c4acc7ae2f8a5bb4c4 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sun, 25 Jun 2000 21:40:13 +0000 Subject: [PATCH] QUIPU -> Attic --- build/top.mk | 5 +- configure.in | 23 - servers/slapd/tools/Makefile.in | 47 +- servers/slapd/tools/chlog2replog.c | 702 ---------------------- servers/slapd/tools/edb2ldif.c | 906 ----------------------------- servers/slapd/tools/ldapsyntax.c | 464 --------------- servers/slapd/tools/ldapsyntax.h | 33 -- 7 files changed, 10 insertions(+), 2170 deletions(-) delete mode 100644 servers/slapd/tools/chlog2replog.c delete mode 100644 servers/slapd/tools/edb2ldif.c delete mode 100644 servers/slapd/tools/ldapsyntax.c delete mode 100644 servers/slapd/tools/ldapsyntax.h diff --git a/build/top.mk b/build/top.mk index a92af5005e..aaa1baa3c1 100644 --- a/build/top.mk +++ b/build/top.mk @@ -140,8 +140,9 @@ SLAPD_SQL_LDFLAGS = @SLAPD_SQL_LDFLAGS@ SLAPD_SQL_INCLUDES = @SLAPD_SQL_INCLUDES@ SLAPD_SQL_LIBS = @SLAPD_SQL_LIBS@ -QUIPU_LIBS = @QUIPU_LIBS@ -SLAPD_LIBS = @SLAPD_LIBS@ @SLAPD_PERL_LDFLAGS@ @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ +SLAPD_LIBS = @SLAPD_LIBS@ \ + @SLAPD_PERL_LDFLAGS@ \ + @SLAPD_SQL_LDFLAGS@ @SLAPD_SQL_LIBS@ SLURPD_LIBS = @SLURPD_LIBS@ # Our Defaults diff --git a/configure.in b/configure.in index 1a4efa6613..b7ceb8c666 100644 --- a/configure.in +++ b/configure.in @@ -146,7 +146,6 @@ OL_ARG_ENABLE(spasswd,[ --enable-spasswd enable (Cyrus) SASL password verific OL_ARG_ENABLE(modules,[ --enable-modules enable dynamic module support], no)dnl OL_ARG_ENABLE(multimaster,[ --enable-multimaster enable multimaster replication], no)dnl OL_ARG_ENABLE(phonetic,[ --enable-phonetic enable phonetic/soundex], no)dnl -OL_ARG_ENABLE(quipu,[ --enable-quipu build quipu migration tools], no)dnl OL_ARG_ENABLE(rlookups,[ --enable-rlookups enable reverse lookups], auto)dnl OL_ARG_ENABLE(aci,[ --enable-aci enable per-object ACIs], no)dnl OL_ARG_ENABLE(wrappers,[ --enable-wrappers enable tcp wrapper support], no)dnl @@ -235,9 +234,6 @@ if test $ol_enable_slapd = no ; then if test $ol_enable_phonetic = yes ; then AC_MSG_WARN([slapd disabled, ignoring --enable-phonetic argument]) fi - if test $ol_enable_quipu = yes ; then - AC_MSG_WARN([slapd disabled, ignoring --enable-quipu argument]) - fi if test $ol_enable_rlookups = yes ; then AC_MSG_WARN([slapd disabled, ignoring --enable-rlookups argument]) fi @@ -291,7 +287,6 @@ if test $ol_enable_slapd = no ; then ol_enable_modules=no ol_enable_multimaster=no ol_enable_phonetic=no - ol_enable_quipu=no ol_enable_rlookups=no ol_enable_aci=no ol_enable_wrappers=no @@ -393,14 +388,12 @@ LDBM_LIBS= LTHREAD_LIBS= LUTIL_LIBS= -QUIPU_LIBS= SLAPD_LIBS= SLURPD_LIBS= BUILD_SLAPD=no BUILD_SLURPD=no -BUILD_QUIPU=no BUILD_THREAD=no BUILD_DNSSRV=no @@ -815,20 +808,6 @@ if test "$ol_enable_dnssrv" = yes -a "$ol_link_dnssrv" = no ; then AC_MSG_ERROR([DNSSRV requires res_query()]) fi -dnl ---------------------------------------------------------------- -dnl QUIPU -if test $ol_enable_quipu != no ; then - AC_CHECK_HEADERS(quipu/commonarg.h) - - if test $ac_cv_header_quipu_commonarg_h = yes ; then - BUILD_QUIPU=yes - elif test $ol_enable_quipu = auto ; then - AC_MSG_WARN([no quipu for --enable-quipu=auto, disabling]) - else - AC_MSG_ERROR(no quipu for --enable-quipu=$ol_enable_quipu) - fi -fi - dnl ---------------------------------------------------------------- dnl Kerberos ol_link_kbind=no @@ -2324,7 +2303,6 @@ AC_SUBST(BUILD_SLAPD) AC_SUBST(BUILD_LDBM) AC_SUBST(BUILD_PASSWD) AC_SUBST(BUILD_PERL) - AC_SUBST(BUILD_QUIPU) AC_SUBST(BUILD_SHELL) AC_SUBST(BUILD_SQL) AC_SUBST(BUILD_TCL) @@ -2341,7 +2319,6 @@ AC_SUBST(BUILD_SLURPD) AC_SUBST(LDAP_LIBS) AC_SUBST(LDIF_LIBS) AC_SUBST(SLAPD_LIBS) -AC_SUBST(QUIPU_LIBS) AC_SUBST(SLURPD_LIBS) AC_SUBST(LDBM_LIBS) AC_SUBST(LTHREAD_LIBS) diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index d303ad9a2b..8ce6b4eb86 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -16,7 +16,6 @@ # #----------------------------------------------------------------------------- BUILD_LDBM = @BUILD_LDBM@ -BUILD_QUIPU = @BUILD_QUIPU@ LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries @@ -27,14 +26,13 @@ XDEFS = $(MODULES_CPPFLAGS) XLDFLAGS = $(MODULES_LDFLAGS) $(SLAPD_MODULES) XLIBS = -lavl -lldif -lldbm -llutil -lldap_r -llber -XXLIBS = $(QUIPU_LIBS) $(SLAPD_LIBS) \ +XXLIBS = $(SLAPD_LIBS) \ $(LDBM_LIBS) $(SECURITY_LIBS) \ $(LDIF_LIBS) $(LUTIL_LIBS) XXXLIBS = $(LTHREAD_LIBS) $(MODULES_LIBS) PROGRAMS=ldif slappasswd slapadd slapcat slapindex LDBMPROGRAMS=centipede sizecount -QUIPUPROGRAMS=chlog2replog edb2ldif # CPPFLAGS will include the defines for dynamic libs in Mingw32. NT_DYN_DEFS = -DLBER_DECL=dllimport -DLDAP_DECL=dllimport @@ -47,7 +45,6 @@ XSRCS = edb2-vers.c # LDBMSRCS = centipede.c sizecount.c LDBMSRCS = -QUIPUSRCS = edb2ldif.c ldapsyntax.c chlog2replog.c SLAPD_OBJS = ../config.o ../ch_malloc.o ../backend.o ../charray.o \ ../module.o ../aclparse.o ../filterentry.o \ ../schema.o ../schema_check.o ../schema_init.o ../schema_prep.o \ @@ -62,7 +59,7 @@ SLAPOBJS = $(SLAPD_OBJS) slapcommon.o mimic.o EDB2LDIFSRCS = edb2ldif.c ldapsyntax.c EDB2LDIFOBJS = edb2ldif.o ldapsyntax.o -UNIX_PRGS = build-ldbm build-quipu +UNIX_PRGS = build-ldbm all-local: build-progs $(@PLAT@_PRGS) @@ -74,12 +71,6 @@ ldbm-tools-no: ldbm-tools-yes ldbm-tools-mod: $(LDBMPROGRAMS) -build-quipu: quipu-tools-$(BUILD_QUIPU) -quipu-tools-no: - @echo "run configure with --enable-quipu to build QUIPU tools" - -quipu-tools-yes quipu-tools-mod: $(QUIPUPROGRAMS) - # # SLAP Tools # @@ -107,37 +98,20 @@ centipede: centipede.o $(SLAPD_LIBDEPEND) sizecount: sizecount.o ../phonetic.o ../ch_malloc.o $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ sizecount.o ../phonetic.o ../ch_malloc.o $(LIBS) -# -# QUIPU Specific Tools -# -edb2ldif: edb2-vers.o - $(CC) $(LDFLAGS) -o $@ $(EDB2LDIFOBJS) edb2-vers.o $(LIBS) - -edb2-vers.c: $(EDB2LDIFOBJS) - @-$(RM) $@ - $(MKVERSION) ebd2ldif > $@ - -chlog2replog: chlog2replog.o ../lock.o ../ch_malloc.o $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ chlog2replog.o ../lock.o ../ch_malloc.o $(LIBS) - clean-local: FORCE - $(RM) $(PROGRAMS) $(LDBMPROGRAMS) $(QUIPUPROGRAMS) \ + $(RM) $(PROGRAMS) $(LDBMPROGRAMS) \ $(XPROGRAMS) $(XSRCS) *.o core .libs/* *.exe depend-local: FORCE - DEPEND_LDBM= ; DEPEND_QUIPU= ; \ + DEPEND_LDBM= ; \ if [ "$(BUILD_LDBM)" != "no" ]; then \ DEPEND_LDBM="$(LDBMSRCS)"; \ fi; \ - if [ "$(BUILD_QUIPU)" != "no" ]; then \ - DEPEND_QUIPU="$(QUIPUINCLUDEFLAG) $(QUIPUSRCS)"; \ - fi; \ - $(MKDEP) $(DEFS) $(DEFINES) $(SRCS) $$DEPEND_QUIPU $$DEPEND_LDBM + $(MKDEP) $(DEFS) $(DEFINES) $(SRCS) $$DEPEND_LDBM -install-local: install-ldbm-$(BUILD_LDBM) \ - install-quipu-$(BUILD_QUIPU) +install-local: install-ldbm-$(BUILD_LDBM) -install-ldbm-no install-quipu-no: +install-ldbm-no: install-ldbm-yes install-ldbm-mod: FORCE -$(MKDIR) $(DESTDIR)$(sbindir) @@ -145,10 +119,3 @@ install-ldbm-yes install-ldbm-mod: FORCE $(LTINSTALL) $(INSTALLFLAGS) -s -m 755 \ $$bin$(EXEEXT) $(DESTDIR)$(sbindir); \ done - -install-quipu-yes: FORCE - @-$(MKDIR) $(DESTDIR)$(sbindir) - for bin in edb2ldif chlog2replog; do \ - $(LTINSTALL) $(INSTALLFLAGS) -s -m 755 \ - $$bin $(DESTDIR)$(sbindir); \ - done diff --git a/servers/slapd/tools/chlog2replog.c b/servers/slapd/tools/chlog2replog.c deleted file mode 100644 index 2d77aa67d5..0000000000 --- a/servers/slapd/tools/chlog2replog.c +++ /dev/null @@ -1,702 +0,0 @@ -/* $OpenLDAP$ */ -/* - * Copyright (c) 1990, 1995 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. - */ - -/* - * chlog2replog - read a quipu-style changelog on stdin and write a - * slapd-style replog on stdout, or write to a file, respecting - * slapd/slurpd locking conventions. - */ - -#include "portable.h" - -#include -#include - -#include -#include -#include - -#include -#include - -#include "ldif.h" - -static int dn2ldif(PS ps, DN dn); -static void de_t61(char *s, int t61mark); - -extern FILE *lock_fopen( char *, char *, FILE ** ); -extern int lock_fclose( FILE *, FILE * ); -extern void *ch_realloc( void *, unsigned long ); - -short ldap_dn_syntax; -PS rps; -char *progname; -int ldap_syslog = 0; -int ldap_syslog_level = 0; - - -#define ST_START 0 -#define ST_DN 2 -#define ST_TYPE 3 -#define ST_ARGS 4 -#define ST_NL1 5 -#define ST_PUNT 6 -#define ST_BAD 7 -#define ST_CONCAT 8 - -#define TY_MODIFYTYPE 1 -#define TY_ADD 2 -#define TY_REMOVE 3 -#define TY_NEWRDN 4 -#define TY_PUNT 5 -#define TY_MODIFYARGS 6 - -#define MOD_ADDVALUES 1 -#define MOD_ADDATTRIBUTE 2 -#define MOD_REMOVEATTRIBUTE 3 -#define MOD_REMOVEVALUES 4 - - -char * -dn2ldap( char *edbdn ) -{ - DN dn; - PS str_ps; - char *ldapdn; - int len; - static int inited = 0; - - if ( !inited ) { - /* load & initialize quipu syntax handlers */ - quipu_syntaxes(); - -#ifdef LDAP_USE_PP - pp_quipu_init( progname ); -#endif - - dsap_init( NULL, NULL ); - - if (( ldap_dn_syntax = str2syntax( "DN" )) == 0 ) { - return( NULL ); - } - inited = 1; - } - - if (( dn = str2dn( edbdn )) == NULLDN ) { - return( NULL ); - } - - if (( str_ps = ps_alloc( str_open )) == NULLPS || - str_setup( str_ps, NULLCP, 0, 0 ) == NOTOK ) { - dn_free( dn ); - return( NULL ); - } - - if ( dn2ldif( str_ps, dn ) != 0 ) { - ps_free( str_ps ); - dn_free( dn ); - return( NULL ); - } - - dn_free( dn ); - len = ( str_ps->ps_ptr - str_ps->ps_base ); - - if (( ldapdn = malloc( len + 1 )) == NULL ) { - ps_free( str_ps ); - return( NULL ); - } - - memcpy( ldapdn, str_ps->ps_base, len ); - ldapdn[ len ] = '\0'; - ps_free( str_ps ); - return( ldapdn ); -} - - -#define SEPARATOR(c) ((c) == ',' || (c) == ';') -#define SPACE(c) ((c) == ' ' || (c) == '\n') - -static int -dn2ldif( PS ps, DN dn ) -{ - RDN rdn; - int firstrdn, rc; - char *value; - PS rps; - - if ( dn == NULLDN ) { - return( 0 ); - } - - if ( dn->dn_parent != NULLDN ) { - if (( rc = dn2ldif( ps, dn->dn_parent )) != 0 ) { - return( rc ); - } - ps_print( ps, ", " ); - } - - if ( (rps = ps_alloc( str_open )) == NULLPS || - str_setup( rps, NULLCP, 0, 0 ) == NOTOK ) { - return( -1 ); - } - - firstrdn = 1; - for ( rdn = dn->dn_rdn; rdn != NULLRDN; rdn = rdn->rdn_next ) { - if ( firstrdn ) { - firstrdn = 0; - } else { - ps_print( ps, " + " ); - } - - AttrT_print( ps, rdn->rdn_at, EDBOUT ); - ps_print( ps, "=" ); - - if ( rdn->rdn_at->oa_syntax == ldap_dn_syntax ) { - if (( rc = dn2ldif( rps, (DN) rdn->rdn_av.av_struct )) != 0 ) { - return( rc ); - } - *rps->ps_ptr = '\0'; - value = rps->ps_base; - } else { - AttrV_print( rps, &rdn->rdn_av, EDBOUT ); - *rps->ps_ptr = '\0'; - value = rps->ps_base; - de_t61( value, 0 ); - } - - /* - * ,+="\\\n all go in quotes. " and \\ need to - * be preceeded by \\. - */ - - if ( strpbrk( value, ",+=\"\\\n" ) != NULL || SPACE( value[0] ) - || SPACE( value[max( strlen(value) - 1, 0 )] ) ) { - char *p, *t, *tmp; - int specialcount; - - ps_print( ps, "\"" ); - - specialcount = 0; - for ( p = value; *p != '\0'; p++ ) { - if ( *p == '"' || *p == '\\' ) { - specialcount++; - } - } - if ( specialcount > 0 ) { - tmp = smalloc( strlen( value ) + specialcount + 1 ); - for ( p = value, t = tmp; *p != '\0'; p++ ) { - switch ( *p ) { - case '"': - case '\\': - *t++ = '\\'; - /* FALL THROUGH */ - default: - *t++ = *p; - } - } - *t = '\0'; - ps_print( ps, tmp ); - free( tmp ); - } else { - ps_print( ps, value ); - } - - ps_print( ps, "\"" ); - } else { - ps_print( ps, value ); - } - - rps->ps_ptr = rps->ps_base; - } - - ps_free( rps ); - - return( 0 ); -} - -#define T61 "{T.61}" -#define T61LEN 6 - - - -static void -de_t61(char *s, int t61mark) -{ - char *next = s; - unsigned char c; - unsigned int hex; - - while ( *s ) { - switch ( *s ) { - case '{' : - if ( strncasecmp( s, T61, T61LEN) == 0 ) { - s += T61LEN; - if ( t61mark ) - *next++ = '@'; - } else { - *next++ = *s++; - } - break; - - case '\\': - c = *(s + 1); - if ( c == '\n' ) { - s += 2; - if ( *s == '\t' ) - s++; - break; - } - if ( isdigit( c ) ) - hex = c - '0'; - else if ( c >= 'A' && c <= 'F' ) - hex = c - 'A' + 10; - else if ( c >= 'a' && c <= 'f' ) - hex = c - 'a' + 10; - else { - *next++ = *s++; - break; - } - hex <<= 4; - c = *(s + 2); - if ( isdigit( c ) ) - hex += c - '0'; - else if ( c >= 'A' && c <= 'F' ) - hex += c - 'A' + 10; - else if ( c >= 'a' && c <= 'f' ) - hex += c - 'a' + 10; - else { - *next++ = *s++; - *next++ = *s++; - break; - } - - *next++ = hex; - s += 3; - break; - - default: - *next++ = *s++; - break; - } - } - *next = '\0'; -} - - - - -char * -getattr(char *buf, char sep) -{ - char *val; -#define RBSIZE 255 - static char retbuf[ RBSIZE ]; - - if (( val = strchr( buf, sep )) != NULL ) { - strncpy( retbuf, buf, val - buf ); - retbuf[ val - buf ] = '\0'; - } else { - retbuf[ 0 ] = '\0'; - } - return( retbuf ); -} - - -char * -getattr_ldif(char *buf) -{ - return( getattr( buf, ':' )); -} - - -char * -getattr_edb(char *buf) -{ - return( getattr( buf, '=' )); -} - -char * -getval(char *buf, char sep) -{ - char *val; - - if (( val = strchr( buf, sep )) != NULL ) { - return( strdup( ++val )); - } else { - return( NULL ); - } -} - -char * -getval_ldif(char *buf) -{ - return( getval( buf, ':' )); -} - - -char * -getval_edb(char *buf) -{ - return( getval( buf, '=' )); -} - - - - -int -isDNsyntax(char *attr) -{ - oid_table_attr *p, *name2attr(char *); - - p = name2attr( attr ); - if ( p == ( oid_table_attr * ) 0 ) { - return( -1 ); - } - if ( p->oa_syntax == ldap_dn_syntax ) { - return( 1 ); - } else { - return( 0 ); - } -} - - - -void -print_as(Attr_Sequence as, int modtype, FILE *ofp) -{ - Attr_Sequence p; - AV_Sequence av; - char *attrname, *tmpdn, *obuf; - - p = as; - for ( p = as; p != NULLATTR; p = p->attr_link) { - rps->ps_ptr = rps->ps_base; - AttrT_print( rps, p->attr_type, EDBOUT ); - *rps->ps_ptr = '\0'; - attrname = strdup( rps->ps_base ); - if ( modtype != 0 ) { - switch ( modtype ) { - case MOD_ADDVALUES: - case MOD_ADDATTRIBUTE: - fprintf( ofp, "add: %s\n", attrname ); - break; - case MOD_REMOVEATTRIBUTE: - case MOD_REMOVEVALUES: - fprintf( ofp, "delete: %s\n", attrname ); - break; - default: - break; - } - } - for ( av = p->attr_value; av != NULLAV; av = av->avseq_next ) { - rps->ps_ptr = rps->ps_base; - AttrV_print( rps, &av->avseq_av, EDBOUT ); - *rps->ps_ptr = '\0'; - de_t61( rps->ps_base, 0 ); - if ( isDNsyntax( attrname )) { - tmpdn = dn2ldap( rps->ps_base ); - obuf = ldif_type_and_value( attrname, tmpdn, - strlen( tmpdn )); - free( tmpdn ); - } else { - obuf = ldif_type_and_value( attrname, rps->ps_base, - strlen( rps->ps_base )); - } - if ( obuf != NULL ) { - fputs( obuf, ofp ); - ber_memfree( obuf ); - } - } - if ( modtype != 0 ) { - fprintf( ofp, "-\n" ); - } - free( attrname ); - } -} - - - -void -usage( char *name ) -{ - fprintf( stderr, "usage: %s -d dn-suffix -r replica:port ", name ); - fprintf( stderr, "[-r replica:port...] [-o outputfile]\n" ); -} - - - -main( int argc, char **argv ) -{ - char *ldapdn, nbuf[ 4096 ], *buf, *p; - int state, prevstate, modstate, modtype, i; - int buflen, nbuflen; - Attr_Sequence as; - PS std_ps; - int arg; - char *ofile = NULL; - FILE *ofp, *lfp; - - extern char *optarg; - char **replicas = NULL; - int nreplicas = 0; - char *dn_suffix = NULL; - - if (( progname = strrchr( argv[ 0 ], '/' )) == NULL ) { - progname = argv[ 0 ]; - } else { - ++progname; - } - - while (( arg = getopt( argc, argv, "o:r:d:" )) != EOF ) { - switch( arg ) { - case 'o': - ofile = optarg; - break; - case 'r': - replicas = (char **) ch_realloc( (char *) replicas, (unsigned long) - ( nreplicas + 2 ) * sizeof( char * )); - replicas[ nreplicas ] = optarg; - replicas[ nreplicas + 1 ] = NULL; - nreplicas++; - break; - case 'd': - dn_suffix = optarg; - break; - default: - usage( progname ); - exit( EXIT_FAILURE ); - } - } - - if (( dn_suffix == NULL ) || ( nreplicas == 0 )) { - usage( progname ); - exit( EXIT_FAILURE ); - } - - if ( ofile == NULL ) { - /* Just write to stdout */ - ofp = stdout; - } - - - state = prevstate = ST_START; - buf = NULL; - as = NULL; - if (( std_ps = ps_alloc( std_open )) == NULLPS || - std_setup( std_ps, ofp ) != OK ) { - fprintf( stderr, "std_ps setup failed - help!\n" ); - exit( EXIT_FAILURE ); - } - if (( rps = ps_alloc( str_open )) == NULLPS || - str_setup( rps, NULLCP, 0, 0 ) != OK ) { - fprintf( stderr, "rps setup failed - help!\n" ); - exit( EXIT_FAILURE ); - } - - - while ( gets( nbuf ) != NULL ) { - if ( nbuf[ 0 ] == '\0' ) { - if ( state == ST_NL1 ) { - if ( prevstate == ST_ARGS ) { - /* We've got an attribute sequence to print */ - if ( modtype == TY_ADD ) { - print_as( as, 0, ofp ); - } else { - print_as( as, modstate, ofp ); - } - /* as_print( std_ps, as, EDBOUT ); */ - as_free( as ); - as = NULL; - } - state = ST_START; - fprintf( ofp, "\n" ); - fflush( ofp ); - /* If writing to a file, release the lock */ - if ( ofile != NULL ) { - lock_fclose( ofp, lfp ); - } - } else { - prevstate = state; - state = ST_NL1; - } - continue; - } - - /* See if we've got a line continuation to deal with */ - nbuflen = strlen( nbuf ); - if ( state == ST_CONCAT ) { - for ( p = nbuf; isspace( (unsigned char) *p ); p++, nbuflen-- ) - ; /* skip space */ - buf = realloc( buf, buflen + nbuflen + 1 ); - strcat( buf, p ); - buflen += ( nbuflen ); - } else { - if ( buf != NULL ) { - free( buf ); - } - buf = strdup( nbuf ); - buflen = nbuflen; - } - if ( buf[ buflen - 1 ] == '\\' ) { - if ( state != ST_CONCAT ) { - prevstate = state; - } - state = ST_CONCAT; - buf[ buflen - 1 ] = '\0'; - buflen--; - continue; - } else if ( state == ST_CONCAT ) { - state = prevstate; - } - - if ( state == ST_PUNT ) { - continue; - } - - if ( state == ST_START ) { - /* - * Acquire the file lock if writing to a file. - */ - if ( ofile != NULL ) { - if (( ofp = lock_fopen( ofile, "a", &lfp )) == NULL ) { - perror( "open" ); - exit( EXIT_FAILURE ); - } - } - /* - * If we have a changelog entry, then go ahead - * and write the replica: lines for the replog entry. - */ - for ( i = 0; replicas[ i ] != NULL; i++ ) { - fprintf( ofp, "replica: %s\n", replicas[ i ] ); - } - fprintf( ofp, "time: %ld\n", time( NULL )); - state = ST_DN; - continue; - } - - if ( state == ST_DN ) { - /* Second line - dn (quipu-style) of entry to be modified */ - if (( ldapdn = dn2ldap( buf )) == NULL ) { - fprintf( ofp, "dn: (conversion failed)\n" ); - } else { - fprintf( ofp, "dn: %s%s\n", ldapdn, dn_suffix ); - free( ldapdn ); - } - state = ST_TYPE; - continue; - } - - if ( state == ST_TYPE ) { - state = ST_ARGS; - modstate = 0; - if ( !strcmp( buf, "modify" )) { - modtype = TY_MODIFYTYPE; - fprintf( ofp, "changetype: modify\n" ); - } else if ( !strcmp( buf, "add" )) { - modtype = TY_ADD; - fprintf( ofp, "changetype: add\n" ); - as = NULL; - } else if ( !strcmp( buf, "remove" )) { - modtype = TY_REMOVE; - fprintf( ofp, "changetype: delete\n" ); - } else if ( !strcmp( buf, "newrdn" )) { - modtype = TY_NEWRDN; - fprintf( ofp, "changetype: modrdn\n" ); - } else { - modtype = TY_PUNT; - state = ST_BAD; - } - continue; - } - - if ( state == ST_ARGS ) { - switch ( modtype ) { - case TY_NEWRDN: - fprintf( ofp, "newrdn: %s\n", buf ); - break; - case TY_REMOVE: /* No additional args */ - break; - case TY_ADD: - as = as_combine( as, buf, 0 ); - break; - case TY_MODIFYTYPE: - case TY_MODIFYARGS: - if ( buf[ 0 ] == '\0' ) { - state == ST_NL1; - if ( as != NULL ) { - print_as( as, modstate, ofp); - as_free( as ); - as = NULL; - } - continue; - } - if (!strcmp( buf, "addvalues" )) { - if ( as != NULL ) { - print_as( as, modstate, ofp ); - as_free( as ); - as = NULL; - } - modstate = MOD_ADDVALUES; - continue; - } else if (!strcmp( buf, "removevalues" )) { - if ( as != NULL ) { - print_as( as, modstate, ofp ); - as_free( as ); - as = NULL; - } - modstate = MOD_REMOVEVALUES; - continue; - } else if (!strcmp( buf, "addattribute" )) { - if ( as != NULL ) { - print_as( as, modstate, ofp ); - as_free( as ); - as = NULL; - } - modstate = MOD_ADDATTRIBUTE; - continue; - } else if (!strcmp( buf, "removeattribute" )) { - if ( as != NULL ) { - print_as( as, modstate, ofp ); - as_free( as ); - as = NULL; - } - modstate = MOD_REMOVEATTRIBUTE; - continue; - } - switch ( modstate ) { - case MOD_ADDVALUES: - as = as_combine( as, buf, 0 ); - break; - case MOD_REMOVEVALUES: - as = as_combine( as, buf, 0 ); - break; - case MOD_ADDATTRIBUTE: - as = as_combine( as, buf, 0 ); - break; - case MOD_REMOVEATTRIBUTE: - fprintf( ofp, "delete: %s\n-\n", buf); - break; - } - } - continue; - } - } - - if ( ofile != NULL ) { - lock_fclose( ofp, lfp ); - sprintf( nbuf, "%s.lock", ofile ); - (void) unlink( nbuf ); - } - exit( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/edb2ldif.c b/servers/slapd/tools/edb2ldif.c deleted file mode 100644 index 0ef3fb8edc..0000000000 --- a/servers/slapd/tools/edb2ldif.c +++ /dev/null @@ -1,906 +0,0 @@ -/* $OpenLDAP$ */ -/* - * Copyright (c) 1995 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. - */ - -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#if ICRELEASE > 1 -#define HAVE_FILE_ATTR_DIR -#endif - -#ifdef TURBO_DISK -#define HAVE_PARSE_ENTRY -#endif - -#define DEF_EDBFILENAME "EDB" -#define EDB_ROOT_FILENAME "EDB.root" -#define DEF_BASEDN "" -#define EDBMAP_FILENAME "EDB.map" -#define ADDVALS_FILENAME ".add" - -#define MAX_LINE_SIZE 2048 - -#define VERBOSE_ENTRY_REPORT_THRESHOLD 250 - - -/* data structures */ -struct edbmap { - char *edbm_filename; - char *edbm_rdn; - struct edbmap *edbm_next; -}; - -/* prototypes */ -static int edb2ldif( FILE *outfp, char *edbfile, char *basedn, int recurse ); -static int convert_entry( FILE *fp, char *edbname, FILE *outfp, - char *basedn, char *loc_addvals, int loc_addlen, char *linebuf ); -static int add_rdn_values (Attr_Sequence entryas, RDN rdn); -static int read_edbmap( char *mapfile, struct edbmap **edbmapp ); -static char *file2rdn( struct edbmap *edbmap, char *filename ); -static void free_edbmap( struct edbmap *edbmap ); -static char *read_file( char *filename, int *lenp ); -static void print_err( char *msg ); - - -/* globals */ -#ifdef LDAP_DEBUG -static int debugflg; -#endif -static int verboseflg; -static int override_add = 0; -static int entrycount; -static char **ignore_attr = NULL; -static char *always_addvals = NULL; -static int always_addlen; -static char *last_dn; -static char *edb_home = "."; -char *progname; -int ldap_syslog = 0; -int ldap_syslog_level = 0; - - -int -main( int argc, char **argv ) -{ - char *usage = "usage: %s [-d] [-o] [-r] [-v] [-b basedn] [-a addvalsfile] [-f fileattrdir] [-i ignoreattr...] [edbfile...]\n"; - char edbfile[ MAXNAMLEN ], *basedn; - int c, rc, errflg, ignore_count, recurse; - extern char dsa_mode; -#ifdef HAVE_FILE_ATTR_DIR - extern char *file_attr_directory; -#endif - - if (( progname = strrchr( argv[ 0 ], '/' )) == NULL ) { - progname = argv[ 0 ]; - } else { - ++progname; - } - - errflg = recurse = 0; -#ifdef LDAP_DEBUG - debugflg = 0; -#endif - ignore_count = 0; - always_addvals = NULL; - basedn = NULL; - - while (( c = getopt( argc, argv, "dorva:b:f:h:i:" )) != EOF ) { - switch( c ) { - case 'd': -#ifdef LDAP_DEBUG - ++debugflg; -#else - fprintf( stderr, "Ignoring -d: compile with -DLDAP_DEBUG to enable this option.\n" ); -#endif - break; - - case 'o': - ++override_add; - break; - - case 'r': - ++recurse; - break; - - case 'v': - ++verboseflg; - break; - - case 'a': - if ( always_addvals != NULL ) { - ++errflg; - } else if (( always_addvals = read_file( optarg, &always_addlen )) - == NULL ) { - print_err( optarg ); - exit( EXIT_FAILURE ); - } - break; - - case 'b': - if ( basedn != NULL ) { - ++errflg; - } else { - basedn = optarg; - } - break; - - case 'f': -#ifdef HAVE_FILE_ATTR_DIR - /* add trailing slash to directory name if missing */ - if ( *( optarg + strlen( optarg ) - 1 ) == '/' ) { - file_attr_directory = strdup( optarg ); - } else if (( file_attr_directory = (char *)malloc( strlen( optarg ) - + 2 )) != NULL ) { - sprintf( file_attr_directory, "%s/", optarg ); - - } - if ( file_attr_directory == NULL ) { - print_err( "malloc" ); - exit( EXIT_FAILURE ); - } -#else /* HAVE_FILE_ATTR_DIR */ - fprintf( stderr, "Ignoring -f: this option requires a newer version of ISODE.\n" ); -#endif /* HAVE_FILE_ATTR_DIR */ - break; - - case 'h': - edb_home = optarg; - break; - - case 'i': - if ( ignore_count == 0 ) { - ignore_attr = (char **)malloc( 2 * sizeof( char * )); - } else { - ignore_attr = (char **)realloc( ignore_attr, - ( ignore_count + 2 ) * sizeof( char * )); - } - if ( ignore_attr == NULL ) { - print_err( "malloc/realloc" ); - exit( EXIT_FAILURE ); - } - ignore_attr[ ignore_count ] = optarg; - ignore_attr[ ++ignore_count ] = NULL; - break; - - default: - ++errflg; - } - } - - if ( errflg ) { - fprintf( stderr, usage, progname ); - exit( EXIT_FAILURE ); - } - - if ( basedn == NULL ) { - basedn = DEF_BASEDN; - } - - /* load & initialize quipu syntax handlers */ - quipu_syntaxes(); -#ifdef LDAP_USE_PP - pp_quipu_init( progname ); -#endif - dsap_init( NULL, NULL ); - - dsa_mode = 1; /* so {CRYPT} is accepted by EDB parse routines */ - - if ( init_syntaxes() < 0 ) { - fprintf( stderr, "%s: init_syntaxes failed -- check your oid tables \n", - progname ); - exit( EXIT_FAILURE ); - } - - - entrycount = 0; - - /* process EDB file(s) */ - if ( optind >= argc ) { - *edbfile = '\0'; - rc = edb2ldif( stdout, edbfile, basedn, recurse ); - } else { - for ( rc = 0; rc >= 0 && optind < argc; ++optind ) { - if ( argv[ optind ][ 0 ] == '/' ) { - strcpy( edbfile, argv[ optind ] ); - } else { - sprintf( edbfile, "%s/%s", edb_home, argv[ optind ] ); - } - rc = edb2ldif( stdout, edbfile, basedn, recurse ); - } - } - - if ( last_dn != NULL ) { - free( last_dn ); - } - -#ifdef LDAP_DEBUG - fprintf( stderr, "edb2ldif: exit( %d )\n", ( rc < 0 ) ? 1 : 0 ); -#endif - - exit( ( rc < 0 ) ? EXIT_FAILURE : EXIT_SUCCESS ); -} - - -static int -edb2ldif( FILE *outfp, char *edbfile, char *basedn, int recurse ) -{ - FILE *fp; - char *addvals, *p, *rdn, line[ MAX_LINE_SIZE + 1 ]; - char dirname[ MAXNAMLEN ], filename[ MAXNAMLEN ]; - int err, startcount, addvals_len; - struct stat st; - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif( 0x%X, \"%s\", \"%s\", %d)\n", - outfp, edbfile, basedn, recurse ); - } -#endif - - if ( *edbfile == '\0' ) { - sprintf( filename, "%s/%s", edb_home, EDB_ROOT_FILENAME ); - if ( stat( filename, &st ) == 0 ) { - if (( err = edb2ldif( outfp, filename, basedn, 0 )) < 0 ) { -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 0 return( %d )\n", err ); - } -#endif - return( err ); - } - if (( basedn = strdup( last_dn )) == NULL ) { - print_err( "strdup" ); -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 1 return( -1 )\n" ); - } -#endif - return( -1 ); - } - } - sprintf( edbfile, "%s/%s", edb_home, DEF_EDBFILENAME ); - } - - if ( verboseflg ) { - fprintf( stderr, "%s: converting EDB file: \"%s\"\n\tbasedn: \"%s\"\n", - progname, edbfile, basedn ); - } - - startcount = entrycount; - err = 0; - - - /* construct name of directory we are working in */ - if (( p = strrchr( edbfile, '/' )) == NULL ) { - dirname[ 0 ] = '.'; - dirname[ 1 ] = '\0'; - } else { - strncpy( dirname, edbfile, p - edbfile ); - dirname[ p - edbfile ] = '\0'; - } - - /* load local ".add" file (if any) */ - sprintf( filename, "%s/%s", dirname, ADDVALS_FILENAME ); - addvals_len = 0; - addvals = read_file( filename, &addvals_len ); - - /* read and convert this EDB file */ - if (( fp = fopen( edbfile, "r" )) == NULL ) { - print_err( edbfile ); - if ( addvals != NULL ) { - free( addvals ); - } -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 2 return( -1 )\n" ); - } -#endif - return( -1 ); - } - - /* skip first two lines (type and timestamp) if they are present */ - if ( fgets( line, MAX_LINE_SIZE, fp ) == NULL ) { - err = -1; - } else { - line[ strlen( line ) - 1 ] = '\0'; - if ( strcmp( line, "MASTER" ) == 0 || strcmp( line, "SLAVE" ) == 0 || - strcmp( line, "CACHE" ) == 0 ) { - if ( fgets( line, MAX_LINE_SIZE, fp ) == NULL ) { - err = -1; - } - } else { - rewind( fp ); - } - } - - if ( err != 0 ) { - fprintf( stderr, "%s: skipping empty EDB file %s\n", progname, - edbfile ); - err = 0; /* treat as a non-fatal error */ - } else { - while ( !feof( fp ) && ( err = convert_entry( fp, edbfile, outfp, - basedn, addvals, addvals_len, line )) > 0 ) { - if ( verboseflg && (( entrycount - startcount ) % - VERBOSE_ENTRY_REPORT_THRESHOLD ) == 0 ) { - fprintf( stderr, "\tworking... %d entries done...\n", - entrycount - startcount ); - } - } - } - - fclose( fp ); - if ( addvals != NULL ) { - free( addvals ); - } - - if ( err < 0 ) { -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 3 return( %d )\n", err ); - } -#endif - return( err ); - } - - if ( verboseflg ) { - fprintf( stderr, "\t%d entries converted\n\n", - entrycount - startcount ); - } - - /* optionally convert EDB file within sub-directories */ - if ( recurse ) { - char *newbase; - DIR *dp; - struct dirent *dep; - struct edbmap *edbmap; - - /* open this directory */ - if (( dp = opendir( dirname )) == NULL ) { - print_err( dirname ); -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 4 return( -1 )\n" ); - } -#endif - return( -1 ); - } - - /* check for EDB.map file and record contents for future reference */ - sprintf( filename, "%s/%s", dirname, EDBMAP_FILENAME ); - if ( read_edbmap( filename, &edbmap ) < 0 ) { - print_err( "read_edbmap" ); - closedir( dp ); -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 5 return( -1 )\n" ); - } -#endif - return( -1 ); - } - - p = dirname + strlen( dirname ); - *p++ = '/'; - *p = '\0'; - - /* scan looking for sub-directories w/EDB files in them */ - err = 0; - while ( err >= 0 && ( dep = readdir( dp )) != NULL ) { - if ( dep->d_name[ 0 ] == '.' && ( dep->d_name[ 1 ] == '\0' || - ( dep->d_name[ 1 ] == '.' && dep->d_name[ 2 ] == '\0' ))) { - continue; /* skip "." and ".." */ - } - - strcpy( p, dep->d_name ); -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: checking directory \"%s\"\n", - dirname ); - } -#endif - - if ( stat( dirname, &st ) != 0 ) { - print_err( dirname ); - } else if ( S_ISDIR( st.st_mode )) { - sprintf( filename, "%s/%s", dirname, DEF_EDBFILENAME ); - - if ( stat( filename, &st ) == 0 && S_ISREG( st.st_mode )) { - if (( newbase = malloc( strlen( basedn ) + - strlen( dep->d_name ) + 3 )) == NULL ) { - print_err( "malloc" ); - err = -1; - continue; - } - - sprintf( newbase, "%s@%s", basedn, - file2rdn( edbmap, dep->d_name )); - - /* recurse */ - err = edb2ldif( outfp, filename, newbase, recurse ); - - free( newbase ); - } - } - } - - free_edbmap( edbmap ); - closedir( dp ); - - if ( verboseflg ) { - fprintf( stderr, "%s: %d total entries converted under \"%s\"\n\n", - progname, entrycount - startcount, basedn ); - } - } - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "edb2ldif: 6 return( %d )\n", err ); - } -#endif - return( err ); -} - - -/* - * read one entry from fp and write to outfp. - * return > 0 if entry converted, 0 if end of file, < 0 if error occurs - */ -static int -convert_entry( - FILE *fp, - char *edbname, - FILE *outfp, - char *basedn, - char *loc_addvals, - int loc_addlen, - char *linebuf -) -{ - Attr_Sequence as, tmpas; - AV_Sequence av; - PS attrtype_ps, val_ps; - char *dnstr; - DN dn; - RDN rdn; - int valcnt; - extern int parse_status; - extern char *parse_file; - extern RDN parse_rdn; -#ifdef HAVE_PARSE_ENTRY - extern char *parse_entry; - extern Attr_Sequence fget_attributes(); -#else /* HAVE_PARSE_ENTRY */ - extern Attr_Sequence get_attributes(); -#endif /* HAVE_PARSE_ENTRY */ - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "convert_entry( 0x%X, \"%s\", 0x%X, \"%s\", ...)\n", - fp, edbname, outfp, basedn ); - } -#endif - - while (( dnstr = fgets( linebuf, MAX_LINE_SIZE, fp )) != NULL && - *linebuf == '\n' ) { - ; - } - - if ( dnstr == NULL ) { - return( feof( fp ) ? 0 : -1 ); /* end of file or error */ - } - - linebuf[ strlen( linebuf ) - 1 ] = '\0'; - - if (( dnstr = malloc( strlen( basedn ) + strlen( linebuf ) + 2 )) - == NULL ) { - print_err( "convert_entry" ); - return( -1 ); - } - sprintf( dnstr, "%s@%s", basedn, linebuf ); - if ( last_dn != NULL ) { - free( last_dn ); - } - last_dn = dnstr; - - if ( entrycount > 0 ) { - fputc( '\n', outfp ); - } - - /* - * parse_entry, parse_file and parse_rdn are needed inside the - * libisode decoding routines, so we set it here. - */ - parse_file = edbname; -#ifdef HAVE_PARSE_ENTRY - parse_entry = dnstr; -#endif - parse_rdn = rdn = str2rdn( linebuf ); - - if (( val_ps = ps_alloc( str_open )) == NULLPS || - str_setup( val_ps, NULLCP, 0, 0 ) == NOTOK ) { - fprintf( stderr, "%s: ps_alloc/setup failed (EDB file %s)\n", progname, - edbname ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - if (( dn = str2dn( dnstr )) == NULLDN || av2ldif( outfp, NULL, dn, - 0, "dn", val_ps ) < 0 ) { - sprintf( linebuf, - "str2dn or av2ldif of DN failed (EDB file %s, entry %s)\n", - edbname, dnstr ); - print_err( linebuf ); - if ( dn != NULLDN ) { - dn_free( dn ); - } - ps_free( val_ps ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - dn_free( dn ); - - ++entrycount; - - if ( always_addvals != NULL && ( loc_addvals == NULL || !override_add ) - && fwrite( always_addvals, always_addlen, 1, outfp ) != 1 ) { - sprintf( linebuf, - "write of additional values failed (EDB file %s, entry %s)\n", - edbname, dnstr ); - print_err( linebuf ); - ps_free( val_ps ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - if ( loc_addvals != NULL && fwrite( loc_addvals, loc_addlen, 1, - outfp ) != 1 ) { - sprintf( linebuf, - "write of additional values failed (EDB file %s, entry %s)\n", - edbname, dnstr ); - print_err( linebuf ); - ps_free( val_ps ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - -#ifdef HAVE_PARSE_ENTRY - as = fget_attributes( fp ); -#else /* HAVE_PARSE_ENTRY */ - as = get_attributes( fp ); -#endif /* HAVE_PARSE_ENTRY */ - - if ( parse_status != 0 ) { - fprintf( stderr, "%s: problem parsing entry (EDB file %s)\n", progname, - edbname ); - ps_free( val_ps ); - if ( as != NULLATTR ) { - as_free( as ); - } - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - if ( add_rdn_values( as, rdn ) != 0 ) { - sprintf( linebuf, - "adding RDN values(s) failed (EDB file %s, entry %s)\n", - edbname, dnstr ); - print_err( linebuf ); - if ( as != NULLATTR ) { - as_free( as ); - } - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - if (( attrtype_ps = ps_alloc( str_open )) == NULLPS || - str_setup( attrtype_ps, NULLCP, 0, 0 ) == NOTOK ) { - fprintf( stderr, "%s: ps_alloc/setup failed (EDB file %s)\n", progname, - edbname ); - if ( as != NULLATTR ) { - as_free( as ); - } - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - - for ( tmpas = as; tmpas != NULLATTR; tmpas = tmpas->attr_link ) { - attrtype_ps->ps_ptr = attrtype_ps->ps_base; - AttrT_print( attrtype_ps, tmpas->attr_type, EDBOUT ); - *attrtype_ps->ps_ptr = '\0'; - - if ( ignore_attr != NULL ) { - int i; - - for ( i = 0; ignore_attr[ i ] != NULL; ++i ) { - if ( strcasecmp( attrtype_ps->ps_base, ignore_attr[ i ] ) - == 0 ) { - break; - } - } - if ( ignore_attr[ i ] != NULL ) { - continue; /* skip this attribute */ - } - } - - valcnt = 0; - for ( av = tmpas->attr_value; av != NULLAV; av = av->avseq_next ) { - ++valcnt; - if ( av2ldif( outfp, av, NULL, tmpas->attr_type->oa_syntax, - attrtype_ps->ps_base, val_ps ) < 0 ) { - sprintf( linebuf, - "av2ldif failed (EDB file %s, entry %s, attribute %s, value no. %d)\n", - edbname, dnstr, attrtype_ps->ps_base, valcnt ); - print_err( linebuf ); - ps_free( attrtype_ps ); - ps_free( val_ps ); - as_free( as ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - return( -1 ); - } - } - } - - ps_free( attrtype_ps ); - ps_free( val_ps ); - as_free( as ); - if ( rdn != NULLRDN ) { - rdn_free( rdn ); - } - - return( 1 ); -} - - -static int -add_rdn_values( Attr_Sequence entryas, RDN rdn ) -{ -/* - * this routine is based on code from the real_unravel_attribute() routine - * found in isode-8.0/.dsap/common/attribute.c - */ - AttributeType at; - AV_Sequence avs; - Attr_Sequence as; - - for (; rdn != NULLRDN; rdn = rdn->rdn_next ) { - if (( as = as_find_type( entryas, rdn->rdn_at )) == NULLATTR ) { - at = AttrT_cpy( rdn->rdn_at ); - avs = avs_comp_new( AttrV_cpy(&rdn->rdn_av )); - as = as_comp_new( at, avs, NULLACL_INFO ); - entryas = as_merge( entryas, as ); - } else { - for ( avs = as->attr_value; avs != NULLAV; avs = avs->avseq_next ) { - if ( AttrV_cmp( &rdn->rdn_av, &avs->avseq_av ) == 0 ) { - break; - } - } - - if ( avs == NULLAV ) { - avs = avs_comp_new( AttrV_cpy( &rdn->rdn_av )); - as->attr_value = avs_merge( as->attr_value, avs ); - } - } - } - - return( 0 ); -} - - -/* read the EDB.map file and return a linked list of translations */ -static int -read_edbmap( char *mapfile, struct edbmap **edbmapp ) -{ - FILE *fp; - char *p, *filename, *rdn, line[ MAX_LINE_SIZE + 1 ]; - int err; - struct edbmap *emp, *tmpemp; - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "read_edbmap( \"%s\", ...)\n", mapfile ); - } -#endif - - if (( fp = fopen( mapfile, "r" )) == NULL ) { - *edbmapp = NULL; - return( 0 ); /* soft error -- no EDB.map file */ - } - - emp = NULL; - - /* - * read all the lines in the file, looking for lines of the form: - * RDN # filename - */ - err = 0; - while ( err == 0 && fgets( line, MAX_LINE_SIZE, fp ) != NULL ) { - line[ strlen( line ) - 1 ] = '\0'; /* remove trailing newline */ - if (( filename = strchr( line, '#' )) == NULL ) { - continue; - } - - *filename++ = '\0'; - while ( isspace((unsigned char) *filename) ) { /* strip leading whitespace */ - ++filename; - } - - if ( *filename == '\0' ) { - continue; - } - - p = filename + strlen( filename ) - 1; - while ( isspace((unsigned char) *p) ) { /* strip trailing whitespace */ - *p-- = '\0'; - } - - rdn = line; - while ( isspace((unsigned char) *rdn)) { /* strip leading whitespace */ - ++rdn; - } - - if ( *rdn == '\0' ) { - continue; - } - - p = rdn + strlen( rdn ) - 1; - while ( isspace((unsigned char) *p)) { /* strip trailing whitespace */ - *p-- = '\0'; - } - - if (( tmpemp = (struct edbmap *)calloc( 1, sizeof( struct edbmap ))) - == NULL || - ( tmpemp->edbm_filename = strdup( filename )) == NULL || - ( tmpemp->edbm_rdn = strdup( rdn )) == NULL ) { - err = -1; - } else { - tmpemp->edbm_next = emp; - emp = tmpemp; - } - } - - fclose( fp ); - - if ( err == 0 ) { - *edbmapp = emp; - } else { - free_edbmap( emp ); - } - - return( err ); -} - - -static char * -file2rdn( struct edbmap *edbmap, char *filename ) -{ -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "file2rdn( 0x%X, \"%s\" )\n", edbmap, filename ); - } -#endif - - while ( edbmap != NULL ) { - if ( strcmp( filename, edbmap->edbm_filename ) == 0 ) { - break; - } - edbmap = edbmap->edbm_next; - } - - return(( edbmap == NULL ) ? filename : edbmap->edbm_rdn ); -} - - -/* free the edbmap list */ -static void -free_edbmap( struct edbmap *edbmap ) -{ - struct edbmap *tmp; - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "free_edbmap( 0x%X )\n", edbmap ); - } -#endif - - while ( edbmap != NULL ) { - if ( edbmap->edbm_filename != NULL ) free( edbmap->edbm_filename ); - if ( edbmap->edbm_rdn != NULL ) free( edbmap->edbm_rdn ); - tmp = edbmap; - edbmap = edbmap->edbm_next; - free( tmp ); - } -} - - -static void -print_err( char *msg ) -{ -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "print_err( \"%s\" )\n", msg ); - } -#endif - - if ( errno > sys_nerr ) { - fprintf( stderr, "%s: %s: errno=%d\n", progname, msg, errno ); - } else { - fprintf( stderr, "%s: %s: %s\n", progname, msg, sys_errlist[ errno ] ); - } -} - - -static char * -read_file( char *filename, int *lenp ) -{ - FILE *fp; - struct stat st; - char *buf; - -#ifdef LDAP_DEBUG - if ( debugflg ) { - fprintf( stderr, "read_file( \"%s\", 0x%X )\n", filename, lenp ); - } -#endif - - if ( stat( filename, &st ) != 0 || !S_ISREG( st.st_mode ) || - ( fp = fopen( filename, "r" )) == NULL ) { - return( NULL ); - } - - if (( buf = (char *)malloc( st.st_size )) == NULL ) { - fclose( fp ); - return( NULL ); - } - - if ( fread( buf, st.st_size, 1, fp ) != 1 ) { - fclose( fp ); - free( buf ); - return( NULL ); - } - - fclose( fp ); - *lenp = st.st_size; - return( buf ); -} diff --git a/servers/slapd/tools/ldapsyntax.c b/servers/slapd/tools/ldapsyntax.c deleted file mode 100644 index 04bba0fd16..0000000000 --- a/servers/slapd/tools/ldapsyntax.c +++ /dev/null @@ -1,464 +0,0 @@ -/* $OpenLDAP$ */ -/* - * Copyright (c) 1995 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. - */ - -#include "portable.h" - -#include - -#include -#include - -#include -#include -#include -#include -/* #include */ -#include - -#include - -#include "ldif.h" -#include "ldapsyntax.h" - -short ldap_dn_syntax; -short ldap_password_syntax; -short ldap_photo_syntax; -short ldap_jpeg_syntax; -short ldap_audio_syntax; - -static int dn2ldif( PS ps, DN dn ); -static int jpeg2ldif( PS ps, AttributeValue av ); -static int audio2ldif( PS ps, AttributeValue av ); -static int photo2ldif( PS ps, AttributeValue av ); -static int fileattr2ldif( PS ps, AttributeValue av ); -static void de_t61( char *s, int t61mark ); -static void de_crypt( char *s ); - -extern char *progname; - -#define SEPARATOR(c) ((c) == ',' || (c) == ';') -#define SPACE(c) ((c) == ' ' || (c) == '\n') - - -int -init_syntaxes() -{ - if (( ldap_dn_syntax = str2syntax( "DN" )) == 0 ) { - return( -1 ); /* must have this syntax handler */ - } - ldap_password_syntax = str2syntax( "password" ); - ldap_photo_syntax = str2syntax( "photo" ); - ldap_jpeg_syntax = str2syntax( "jpeg" ); - ldap_audio_syntax = str2syntax( "audio" ); - - return( 0 ); -} - - -/* - * av2ldif: convert attribute value contained in "av" to ldif format - * and write to "outfp". If "dn" is not NULL, convert it instead of "av". - */ -int -av2ldif( FILE *outfp, AV_Sequence av, DN dn, short syntax, char *attrname, - PS str_ps ) -{ - char *buf; - int rc; - struct file_syntax *fsyntax; - - if ( av != NULLAV ) { - fsyntax = (struct file_syntax *) av->avseq_av.av_struct; - } - - rc = 0; /* optimistic */ - str_ps->ps_ptr = str_ps->ps_base; /* reset string PS */ - - if ( dn != NULL || syntax == ldap_dn_syntax ) { /* DNs */ - rc = dn2ldif( str_ps, ( dn != NULLDN ) ? dn : - (DN)(av->avseq_av.av_struct)); - - } else if ( syntax == ldap_jpeg_syntax || ( syntax > AV_WRITE_FILE && - fsyntax->fs_real_syntax == ldap_jpeg_syntax )) { - rc = jpeg2ldif( str_ps, &av->avseq_av ); - - } else if ( syntax == ldap_photo_syntax || ( syntax > AV_WRITE_FILE && - fsyntax->fs_real_syntax == ldap_photo_syntax )) { - rc = photo2ldif( str_ps, &av->avseq_av ); - - } else if ( syntax == ldap_audio_syntax || ( syntax > AV_WRITE_FILE && - fsyntax->fs_real_syntax == ldap_audio_syntax )) { - rc = audio2ldif( str_ps, &av->avseq_av ); - - } else if ( syntax > AV_WRITE_FILE ) { - rc = fileattr2ldif( str_ps, &av->avseq_av ); - - } else { - AttrV_print( str_ps, &av->avseq_av, EDBOUT ); - *str_ps->ps_ptr = '\0'; - de_t61( str_ps->ps_base, 0 ); - - if ( syntax == ldap_password_syntax ) { - de_crypt( str_ps->ps_base ); - } - - str_ps->ps_ptr = str_ps->ps_base + strlen( str_ps->ps_base ); - } - - if ( rc == 0 && str_ps->ps_ptr > str_ps->ps_base ) { - *str_ps->ps_ptr = '\0'; - if (( buf = ldif_type_and_value( attrname, str_ps->ps_base, - str_ps->ps_ptr - str_ps->ps_base )) == NULL ) { - rc = -1; - } else { - if ( fputs( buf, outfp ) == EOF ) { - rc = -1; - } - ber_memfree( buf ); - } - } - - if ( rc == -2 ) { - if ( syntax > AV_WRITE_FILE ) { - fprintf( stderr, - "%s: attribute file '%s' not found (skipping value)\n", - progname, fsyntax->fs_name ); - } - rc = 0; /* treat as "soft" error -- keep going */ - } - - return( rc ); -} - - -static int -dn2ldif( PS ps, DN dn ) -{ - RDN rdn; - int firstrdn, rc; - char *value; - PS rps; - - if ( dn == NULLDN ) { - return( 0 ); - } - - if ( dn->dn_parent != NULLDN ) { - if (( rc = dn2ldif( ps, dn->dn_parent )) != 0 ) { - return( rc ); - } - ps_print( ps, ", " ); - } - - if ( (rps = ps_alloc( str_open )) == NULLPS || - str_setup( rps, NULLCP, 0, 0 ) == NOTOK ) { - return( -1 ); - } - - firstrdn = 1; - for ( rdn = dn->dn_rdn; rdn != NULLRDN; rdn = rdn->rdn_next ) { - if ( firstrdn ) { - firstrdn = 0; - } else { - ps_print( ps, " + " ); - } - - AttrT_print( ps, rdn->rdn_at, EDBOUT ); - ps_print( ps, "=" ); - - if ( rdn->rdn_at->oa_syntax == ldap_dn_syntax ) { - if (( rc = dn2ldif( rps, (DN) rdn->rdn_av.av_struct )) != 0 ) { - return( rc ); - } - *rps->ps_ptr = '\0'; - value = rps->ps_base; - } else { - AttrV_print( rps, &rdn->rdn_av, EDBOUT ); - *rps->ps_ptr = '\0'; - value = rps->ps_base; - de_t61( value, 0 ); - } - - /* - * ,+="\\\n all go in quotes. " and \\ need to - * be preceeded by \\. - */ - - if ( strpbrk( value, ",+=\"\\\n" ) != NULL || SPACE( value[0] ) - || SPACE( value[max( strlen(value) - 1, 0 )] ) ) { - char *p, *t, *tmp; - int specialcount; - - ps_print( ps, "\"" ); - - specialcount = 0; - for ( p = value; *p != '\0'; p++ ) { - if ( *p == '"' || *p == '\\' ) { - specialcount++; - } - } - if ( specialcount > 0 ) { - tmp = smalloc( strlen( value ) + specialcount + 1 ); - for ( p = value, t = tmp; *p != '\0'; p++ ) { - switch ( *p ) { - case '"': - case '\\': - *t++ = '\\'; - /* FALL THROUGH */ - default: - *t++ = *p; - } - } - *t = '\0'; - ps_print( ps, tmp ); - free( tmp ); - } else { - ps_print( ps, value ); - } - - ps_print( ps, "\"" ); - } else { - ps_print( ps, value ); - } - - rps->ps_ptr = rps->ps_base; - } - - ps_free( rps ); - - return( 0 ); -} - -#define T61 "{T.61}" -#define T61LEN 6 - -static void -de_t61( s, t61mark ) -char *s; -int t61mark; -{ - char *next = s; - unsigned char c; - unsigned int hex; - - while ( *s ) { - switch ( *s ) { - case '{' : - if ( strncasecmp( s, T61, T61LEN) == 0 ) { - s += T61LEN; - if ( t61mark ) - *next++ = '@'; - } else { - *next++ = *s++; - } - break; - - case '\\': - c = *(s + 1); - if ( c == '\n' ) { - s += 2; - if ( *s == '\t' ) - s++; - break; - } - if ( isdigit( c ) ) - hex = c - '0'; - else if ( c >= 'A' && c <= 'F' ) - hex = c - 'A' + 10; - else if ( c >= 'a' && c <= 'f' ) - hex = c - 'a' + 10; - else { - *next++ = *s++; - break; - } - hex <<= 4; - c = *(s + 2); - if ( isdigit( c ) ) - hex += c - '0'; - else if ( c >= 'A' && c <= 'F' ) - hex += c - 'A' + 10; - else if ( c >= 'a' && c <= 'f' ) - hex += c - 'a' + 10; - else { - *next++ = *s++; - *next++ = *s++; - break; - } - - *next++ = hex; - s += 3; - break; - - default: - *next++ = *s++; - break; - } - } - *next = '\0'; -} - - -#define CRYPT_MASK 0x23 - -static void -de_crypt( char *s ) -{ - char *p; - - if ( strncmp( s, "{CRYPT}", 7 ) == 0 ) { - SAFEMEMCPY( s, s + 7, strlen( s + 7 ) + 1 ); /* strip off "{CRYPT}" */ - - for ( p = s; *p != '\0'; ++p) { /* "decrypt" each byte */ - if ( *p != CRYPT_MASK ) { - *p ^= CRYPT_MASK; - } - } - } -} - - -static int -jpeg2ldif( PS ps, AttributeValue av ) -{ - PE pe; - int len; - - if (( pe = grab_pe( av )) == NULLPE || pe->pe_id == PE_PRIM_NULL ) { - return( -2 ); /* signal soft error */ - } - - if (( pe->pe_class != PE_CLASS_UNIV && pe->pe_class != PE_CLASS_CONT ) - || pe->pe_form != PE_FORM_PRIM || pe->pe_id != PE_PRIM_OCTS ) { - return( -1 ); - } - - if ( pe_pullup( pe ) == NOTOK ) { - return( -1 ); - } - - len = ps_get_abs( pe ); - - if ( ps_write( ps, (PElementData)pe->pe_prim, len ) == NOTOK ) { - return( -1 ); - } - - return( 0 ); -} - - -static int -audio2ldif( PS ps, AttributeValue av ) -{ - PE pe; - struct qbuf *qb, *p; - int rc, len; - char *buf; - - return( 0 ); /* for now */ - - if (( pe = grab_pe( av )) == NULLPE || pe->pe_id == PE_PRIM_NULL ) { - return( -2 ); /* signal soft error */ - } - - qb = (struct qbuf *)pe; - - len = 0; - for ( p = qb->qb_forw; p != qb; p = p->qb_forw ) { - len += p->qb_len; - } - - if (( buf = (char *) malloc( len )) == NULL ) { - return( -1 ); - } - - len = 0; - for ( p = qb->qb_forw; p != qb; p = p->qb_forw ) { - SAFEMEMCPY( buf + len, p->qb_data, p->qb_len ); - len += p->qb_len; - } - - if ( ps_write( ps, (PElementData)buf, len ) == NOTOK ) { - rc = -1; - } else { - rc = 0; - } - - free( buf ); - - return( rc ); -} - - -static int -photo2ldif( PS ps, AttributeValue av ) -{ - PE pe; - int len; - char *faxparamset = "\000\300\000\000"; - BerElement *phber; - - if (( pe = grab_pe( av )) == NULLPE || pe->pe_id == PE_PRIM_NULL ) { - return( -2 ); /* signal soft error */ - } - - /* old bit string-like format - only handle this for now */ - if ( pe->pe_class == PE_CLASS_UNIV && pe->pe_form == PE_FORM_PRIM - && pe->pe_id == PE_PRIM_BITS ) { - len = ps_get_abs( pe ); - if (( phber = der_alloc()) == NULL ) { - return( -1 ); - } - if ( ber_printf( phber, "t{[tB]{B}}", - (ber_tag_t) 0xA3, (ber_tag_t) 0x81, faxparamset, (ber_len_t) 31, - (char *)pe->pe_prim, (ber_len_t) (len * 8) ) == -1 ) - { - ber_free( phber, 1 ); - return( -1 ); - } - if ( ps_write( ps, (PElementData)phber->ber_buf, - phber->ber_ptr - phber->ber_buf ) == NOTOK ) { - ber_free( phber, 1 ); - return( -1 ); - } - ber_free( phber, 1 ); - } else { - /* - * try just writing this into a PS and sending it along - */ - if ( pe2ps( ps, pe ) == NOTOK ) { - return( -1 ); - } - } - - return( 0 ); -} - - -static int -fileattr2ldif( PS ps, AttributeValue av ) -{ - PE pe; - - if (( pe = grab_pe( av )) == NULLPE || pe->pe_id == PE_PRIM_NULL ) { - return( -2 ); /* signal soft error */ - } - - /* - * try just writing this into a PS and sending it along - */ - if ( pe2ps( ps, pe ) == NOTOK ) { - return( -1 ); - } - - return( 0 ); -} diff --git a/servers/slapd/tools/ldapsyntax.h b/servers/slapd/tools/ldapsyntax.h deleted file mode 100644 index f42934039c..0000000000 --- a/servers/slapd/tools/ldapsyntax.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $OpenLDAP$ */ -/* - * Copyright (c) 1995 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. - */ - -#ifndef LDAPSYNTAX_H -#define LDAPSYNTAX_H 1 - -#include - -LDAP_BEGIN_DECL - -/* XXX: the "master" LINE_WIDTH #define is in ../slap.h */ -#define LINE_WIDTH 76 /* for lines in string rep of an entry */ - -/* - * function prototypes - */ - -int init_syntaxes LDAP_P(( void )); -int av2ldif LDAP_P(( FILE *outfp, AV_Sequence av, DN dn, short syntax, - char *attrname, PS str_ps )); - -LDAP_END_DECL -#endif -- 2.39.5