Mercurial > illumos > illumos-gate
changeset 13698:37bcb30d41d5
2705 EOF libldap.so.4
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Albert Lee <trisk@nexenta.com>
Approved by: Garrett D'Amore <garrett@damore.org>
author | Milan Jurik <milan.jurik@xylab.cz> |
---|---|
date | Sat, 19 May 2012 19:59:14 -0700 |
parents | e2d77ee5f4aa |
children | 733714f4dc24 |
files | usr/src/cmd/abi/appcert/etc/etc.warn.in usr/src/lib/Makefile usr/src/lib/libldap4/Makefile usr/src/lib/libldap4/Makefile.com usr/src/lib/libldap4/THIRDPARTYLICENSE usr/src/lib/libldap4/THIRDPARTYLICENSE.descrip usr/src/lib/libldap4/amd64/Makefile usr/src/lib/libldap4/ber/Version.c usr/src/lib/libldap4/ber/bprint.c usr/src/lib/libldap4/ber/decode.c usr/src/lib/libldap4/ber/encode.c usr/src/lib/libldap4/ber/i18n.c usr/src/lib/libldap4/ber/io.c usr/src/lib/libldap4/common/Version.c usr/src/lib/libldap4/common/abandon.c usr/src/lib/libldap4/common/add.c usr/src/lib/libldap4/common/addentry.c usr/src/lib/libldap4/common/bind.c usr/src/lib/libldap4/common/cache.c usr/src/lib/libldap4/common/charset.c usr/src/lib/libldap4/common/cldap.c usr/src/lib/libldap4/common/compare.c usr/src/lib/libldap4/common/controls.c usr/src/lib/libldap4/common/delete.c usr/src/lib/libldap4/common/disptmpl.c usr/src/lib/libldap4/common/dsparse.c usr/src/lib/libldap4/common/error.c usr/src/lib/libldap4/common/extensions.c usr/src/lib/libldap4/common/extop.c usr/src/lib/libldap4/common/free.c usr/src/lib/libldap4/common/friendly.c usr/src/lib/libldap4/common/getattr.c usr/src/lib/libldap4/common/getdn.c usr/src/lib/libldap4/common/getdxbyname.c usr/src/lib/libldap4/common/getentry.c usr/src/lib/libldap4/common/getfilter.c usr/src/lib/libldap4/common/getmsg.c usr/src/lib/libldap4/common/getref.c usr/src/lib/libldap4/common/getvalues.c usr/src/lib/libldap4/common/kbind.c usr/src/lib/libldap4/common/llib-lldap usr/src/lib/libldap4/common/mapfile-vers usr/src/lib/libldap4/common/modify.c usr/src/lib/libldap4/common/modrdn.c usr/src/lib/libldap4/common/notif.c usr/src/lib/libldap4/common/open.c usr/src/lib/libldap4/common/option.c usr/src/lib/libldap4/common/os-ip.c usr/src/lib/libldap4/common/referral.c usr/src/lib/libldap4/common/regex.c usr/src/lib/libldap4/common/rename.c usr/src/lib/libldap4/common/request.c usr/src/lib/libldap4/common/result.c usr/src/lib/libldap4/common/saslbind.c usr/src/lib/libldap4/common/sbind.c usr/src/lib/libldap4/common/search.c usr/src/lib/libldap4/common/sort.c usr/src/lib/libldap4/common/sortctrl.c usr/src/lib/libldap4/common/srchpref.c usr/src/lib/libldap4/common/tmplout.c usr/src/lib/libldap4/common/ufn.c usr/src/lib/libldap4/common/unbind.c usr/src/lib/libldap4/common/url.c usr/src/lib/libldap4/common/utils.c usr/src/lib/libldap4/common/version.c usr/src/lib/libldap4/common/vlistctrl.c usr/src/lib/libldap4/i386/Makefile usr/src/lib/libldap4/include/avl.h usr/src/lib/libldap4/include/cdefs.h usr/src/lib/libldap4/include/ch_malloc.h usr/src/lib/libldap4/include/charray.h usr/src/lib/libldap4/include/client_door.h usr/src/lib/libldap4/include/entry.h usr/src/lib/libldap4/include/fe.h usr/src/lib/libldap4/include/hsearch.h usr/src/lib/libldap4/include/lber.h usr/src/lib/libldap4/include/ldap-int.h usr/src/lib/libldap4/include/ldap-private.h usr/src/lib/libldap4/include/ldap.h usr/src/lib/libldap4/include/ldapconfig.h usr/src/lib/libldap4/include/ldif.h usr/src/lib/libldap4/include/log.h usr/src/lib/libldap4/include/lthread.h usr/src/lib/libldap4/include/portable.h usr/src/lib/libldap4/include/regex.h usr/src/lib/libldap4/include/sec.h usr/src/lib/libldap4/include/ssl.h usr/src/lib/libldap4/include/sysexits-compat.h usr/src/lib/libldap4/include/thq.h usr/src/lib/libldap4/misc/ldapfilter.conf usr/src/lib/libldap4/misc/ldapfriendly usr/src/lib/libldap4/misc/ldapsearchprefs.conf usr/src/lib/libldap4/misc/ldaptemplates.conf usr/src/lib/libldap4/sec/cram_md5.c usr/src/lib/libldap4/sec/secutil.c usr/src/lib/libldap4/sparc/Makefile usr/src/lib/libldap4/sparcv9/Makefile usr/src/lib/libldap4/util/line64.c usr/src/lib/libldap4/util/log.c usr/src/lib/libnisdb/ldap_op.c usr/src/pkg/manifests/system-library.mf |
diffstat | 101 files changed, 2 insertions(+), 29003 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/abi/appcert/etc/etc.warn.in Wed May 16 04:25:04 2012 +0000 +++ b/usr/src/cmd/abi/appcert/etc/etc.warn.in Sat May 19 19:59:14 2012 -0700 @@ -1,5 +1,3 @@ -# -# ident "%Z%%M% %I% %E% SMI" # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. @@ -77,6 +75,8 @@ ############################################################################### WARNING:libldap.so.3:gettext("calls obsolete LDAP library libldap.so.3"):libldap.so.3|*|*DIRECT*: ############################################################################### +WARNING:libldap.so.4:gettext("calls obsolete LDAP library libldap.so.4"):libldap.so.4|*|*DIRECT*: +############################################################################### WARNING:libxfn:gettext("calls obsolete federated naming library libxfn.so"):libxfn.so.1|*|*DIRECT*,libxfn.so.2|*|*DIRECT*: ############################################################################### WARNING:libXinput:gettext("calls obsolete input library libXinput.so.0"):libXinput.so.0|*|*DIRECT*:
--- a/usr/src/lib/Makefile Wed May 16 04:25:04 2012 +0000 +++ b/usr/src/lib/Makefile Sat May 19 19:59:14 2012 -0700 @@ -125,7 +125,6 @@ libumem \ libnvpair .WAIT \ libexacct \ - libldap4 \ libsasl \ libldap5 \ libsldap .WAIT \
--- a/usr/src/lib/libldap4/Makefile Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.lib - -SUBDIRS = $(MACH) -$(BUILD64)SUBDIRS += $(MACH64) - -all := TARGET= all -clean := TARGET= clean -clobber := TARGET= clobber -delete := TARGET= delete -install := TARGET= install -lint := TARGET= lint -catalog := TARGET= catalog -package := TARGET= package - -.KEEP_STATE: - -all clean clobber delete install lint catalog package: $(SUBDIRS) - -# install rule for install_h target -$(ROOTHDRDIR)/%: % - $(INS.file) - -install_h: $(ROOTHDRS) - -check: $(CHECKHDRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -FRC:
--- a/usr/src/lib/libldap4/Makefile.com Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -LIBRARY= libldap.a -VERS= .4 - -LDAPOBJS= abandon.o getentry.o referral.o \ - add.o getfilter.o regex.o \ - addentry.o getmsg.o rename.o \ - bind.o getref.o request.o \ - cache.o getvalues.o result.o \ - charset.o kbind.o saslbind.o \ - cldap.o sbind.o compare.o \ - search.o controls.o sort.o \ - delete.o srchpref.o disptmpl.o \ - tmplout.o dsparse.o \ - error.o ufn.o \ - extensions.o unbind.o extop.o \ - url.o \ - free.o modify.o utils.o \ - friendly.o modrdn.o notif.o Version.o \ - getattr.o open.o \ - getdn.o option.o \ - getdxbyname.o os-ip.o sortctrl.o \ - vlistctrl.o - -BEROBJS= bprint.o decode.o \ - encode.o \ - io.o i18n.o - -UTILOBJS= line64.o log.o - - -SECOBJS= cram_md5.o secutil.o - -OBJECTS= $(LDAPOBJS) $(BEROBJS) $(UTILOBJS) $(SECOBJS) - -include ../../Makefile.lib - -LDAPINC= $(SRC)/lib/libldap4/include -LDAP_FLAGS= -DLDAP_REFERRALS -DCLDAP -DLDAP_DNS -DSUN - -SRCDIR = ../common -SRCS= $(LDAPOBJS:%.o=../common/%.c) $(BEROBJS:%.o=../ber/%.c) \ - $(UTILOBJS:%.o=../util/%.c) $(SECOBJS:%.o=../sec/%.c) - -LIBS = $(DYNLIB) - -$(LINTLIB):= SRCS=../common/llib-lldap - -LINTSRC= $(LINTLIB:%.ln=%) -ROOTLINTDIR= $(ROOTLIBDIR) -ROOTLINT= $(LINTSRC:%=$(ROOTLINTDIR)/%) - - -CLEANFILES += $(LINTOUT) $(LINTLIB) - -# Local Libldap definitions - -LOCFLAGS += -D_SYS_STREAM_H -D_REENTRANT -DSVR4 -DSUNW_OPTIONS \ - -DTHREAD_SUNOS5_LWP -DSOUNDEX -DSTR_TRANSLATION \ - $(LDAP_FLAGS) -I$(LDAPINC) - -CPPFLAGS = $(LOCFLAGS) $(CPPFLAGS.master) -CFLAGS += $(CCVERBOSE) -LDLIBS += -lsocket -lnsl -lresolv -lc -lmd - -.KEEP_STATE: - -lint: lintcheck - -# include library targets -include ../../Makefile.targ - -objs/%.o pics/%.o: ../common/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) - -objs/%.o pics/%.o: ../ber/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) - -objs/%.o pics/%.o: ../util/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) - -objs/%.o pics/%.o: ../sec/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O)
--- a/usr/src/lib/libldap4/THIRDPARTYLICENSE Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ - * Copyright (c) 1991 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. - - * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain. - * 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 Universitat Jaume I. 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.
--- a/usr/src/lib/libldap4/THIRDPARTYLICENSE.descrip Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -LDAP4 LIBRARY
--- a/usr/src/lib/libldap4/amd64/Makefile Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com -include ../../Makefile.lib.64 - -LIBS = $(DYNLIB) - -.KEEP_STATE: - -all: $(LIBS) - -install: all $(ROOTLIBS64)
--- a/usr/src/lib/libldap4/ber/Version.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1991 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. - */ - -static char Version[] = " liblber.a v%VERSION% (%WHEN%)\n\t%WHOANDWHERE%\n";
--- a/usr/src/lib/libldap4/ber/bprint.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "lber.h" - -/* - * Print arbitrary stuff, for debugging. - */ - -#ifdef LDAP_DEBUG - -#ifndef NO_USERINTERFACE -#define BPLEN 48 - -void -lber_bprint( char *data, int len ) -{ - static char hexdig[] = "0123456789abcdef"; - char out[ BPLEN ]; - int i = 0; - - (void) memset( out, 0, BPLEN ); - for ( ;; ) { - if ( len < 1 ) { - (void) fprintf( stderr, "\t%s\n", ( i == 0 ) ? catgets(slapdcat, 1, 72, "(end)") : out ); - break; - } - -#ifndef HEX - if ( isgraph( (unsigned char)*data )) { - out[ i ] = ' '; - out[ i+1 ] = *data; - } else { -#endif - out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ]; - out[ i+1 ] = hexdig[ *data & 0x0f ]; -#ifndef HEX - } -#endif - i += 2; - len--; - data++; - - if ( i > BPLEN - 2 ) { - (void) fprintf( stderr, "\t%s\n", out ); - (void) memset( out, 0, BPLEN ); - i = 0; - continue; - } - out[ i++ ] = ' '; - } -} -#else /* NO_USERINTERFACE */ -void -lber_bprint( char *data, int len ) -{ -} -#endif /* NO_USERINTERFACE */ - -#endif
--- a/usr/src/lib/libldap4/ber/decode.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,630 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* decode.c - ber input decoding routines */ -/* - * Copyright (c) 1990 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 <stdio.h> -#ifdef MACOS -#include <stdlib.h> -#include <stdarg.h> -#include "macos.h" -#else /* MACOS */ -#if defined(NeXT) || defined(VMS) -#include <stdlib.h> -#else /* next || vms */ -#include <malloc.h> -#endif /* next || vms */ -#if defined(BC31) || defined(_WIN32) || defined(__sun) -#include <stdarg.h> -#else /* BC31 || _WIN32 */ -#include <varargs.h> -#endif /* BC31 || _WIN32 */ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#ifdef PCNFS -#include <tklib.h> -#endif /* PCNFS */ -#endif /* MACOS */ - -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#endif /* DOS */ - -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifdef LDAP_DEBUG -int lber_debug; -#endif - -#ifdef NEEDPROTOS -static int ber_getnint( BerElement *ber, int *num, int len ); -#endif /* NEEDPROTOS */ - - -/* return the tag - LBER_DEFAULT returned means trouble */ -unsigned int -ber_get_tag( BerElement *ber ) -{ - unsigned char xbyte; - unsigned int tag; - char *tagp; - int i; - - if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) - return( LBER_DEFAULT ); - - if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) - return( (unsigned int) xbyte ); - - tagp = (char *) &tag; - tagp[0] = xbyte; - for ( i = 1; i < sizeof(int); i++ ) { - if ( ber_read( ber, (char *) &xbyte, 1 ) != 1 ) - return( LBER_DEFAULT ); - - tagp[i] = xbyte; - - if ( ! (xbyte & LBER_MORE_TAG_MASK) ) - break; - } - - /* tag too big! */ - if ( i == sizeof(int) ) - return( LBER_DEFAULT ); - - /* want leading, not trailing 0's */ - return( tag >> (sizeof(int) - i - 1) ); -} - -unsigned int -ber_skip_tag( BerElement *ber, unsigned int *len ) -{ - unsigned int tag; - unsigned char lc; - int noctets, diff; - unsigned int netlen; - - /* - * Any ber element looks like this: tag length contents. - * Assuming everything's ok, we return the tag byte (we - * can assume a single byte), and return the length in len. - * - * Assumptions: - * 1) definite lengths - * 2) primitive encodings used whenever possible - */ - - /* - * First, we read the tag. - */ - - if ( (tag = ber_get_tag( ber )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - - /* - * Next, read the length. The first byte contains the length of - * the length. If bit 8 is set, the length is the int form, - * otherwise it's the short form. We don't allow a length that's - * greater than what we can hold in an unsigned int. - */ - - *len = netlen = 0; - if ( ber_read( ber, (char *) &lc, 1 ) != 1 ) - return( LBER_DEFAULT ); - if ( lc & 0x80 ) { - noctets = (lc & 0x7f); - if ( noctets > sizeof(unsigned int) ) - return( LBER_DEFAULT ); - diff = (int)sizeof(unsigned int) - noctets; - if ( ber_read( ber, (char *) &netlen + diff, noctets ) - != noctets ) - return( LBER_DEFAULT ); - *len = LBER_NTOHL( netlen ); - } else { - *len = lc; - } - - return( tag ); -} - -unsigned int -ber_peek_tag( BerElement *ber, unsigned int *len ) -{ - char *save; - unsigned int tag; - - save = ber->ber_ptr; - tag = ber_skip_tag( ber, len ); - ber->ber_ptr = save; - - return( tag ); -} - -static int -ber_getnint( BerElement *ber, int *num, int len ) -{ /* New patch much cleaner, from David Wilson, Isode. Old code not kept*/ - int i; - unsigned char buffer[sizeof(int)]; - int value; - - /* - * The tag and length have already been stripped off. We should - * be sitting right before len bytes of 2's complement integer, - * ready to be read straight into an int. - */ - - if ( len > sizeof(int) ) - return( -1 ); - - if ( ber_read( ber, (char *) buffer, len ) != len ) - return( -1 ); - - /* This sets the required sign extension */ - value = 0x80 & buffer[0] ? (-1) : 0; - - for ( i = 0; i < len; i++ ) - value = (value << 8) | buffer[i]; - - *num = value; - - return( len ); -} - -unsigned int -ber_get_int( BerElement *ber, int *num ) -{ - unsigned int tag, len; - - if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - - if ( ber_getnint( ber, num, (int)len ) != len ) - return( LBER_DEFAULT ); - else - return( tag ); -} - -unsigned int -ber_get_stringb( BerElement *ber, char *buf, unsigned int *len ) -{ - unsigned int datalen, tag; -#ifdef STR_TRANSLATION - char *transbuf; -#endif /* STR_TRANSLATION */ - - if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - if ( datalen > (*len - 1) ) - return( LBER_DEFAULT ); - - if ( ber_read( ber, buf, datalen ) != datalen ) - return( LBER_DEFAULT ); - - buf[datalen] = '\0'; - -#ifdef STR_TRANSLATION - if ( datalen > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0 - && ber->ber_decode_translate_proc != NULL ) { - transbuf = buf; - ++datalen; - if ( (*(ber->ber_decode_translate_proc))( &transbuf, &datalen, - 0 ) != 0 ) { - return( LBER_DEFAULT ); - } - if ( datalen > *len ) { - free( transbuf ); - return( LBER_DEFAULT ); - } - (void) SAFEMEMCPY( buf, transbuf, datalen ); - free( transbuf ); - --datalen; - } -#endif /* STR_TRANSLATION */ - - *len = datalen; - return( tag ); -} - -unsigned int -ber_get_stringa( BerElement *ber, char **buf ) -{ - unsigned int datalen, tag; - - if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - - if ( (*buf = (char *) malloc( (size_t)datalen + 1 )) == NULL ) - return( LBER_DEFAULT ); - - if ( ber_read( ber, *buf, datalen ) != datalen ) - return( LBER_DEFAULT ); - (*buf)[datalen] = '\0'; - -#ifdef STR_TRANSLATION - if ( datalen > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0 - && ber->ber_decode_translate_proc != NULL ) { - ++datalen; - if ( (*(ber->ber_decode_translate_proc))( buf, &datalen, 1 ) - != 0 ) { - free( *buf ); - return( LBER_DEFAULT ); - } - } -#endif /* STR_TRANSLATION */ - - return( tag ); -} - -unsigned int -ber_get_stringal( BerElement *ber, struct berval **bv ) -{ - unsigned int len, tag; - - if ( (*bv = (struct berval *) malloc( sizeof(struct berval) )) == NULL ) - return( LBER_DEFAULT ); - - if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - - if ( ((*bv)->bv_val = (char *) malloc( (size_t)len + 1 )) == NULL ) - return( LBER_DEFAULT ); - - if ( ber_read( ber, (*bv)->bv_val, len ) != len ) - return( LBER_DEFAULT ); - ((*bv)->bv_val)[len] = '\0'; - (*bv)->bv_len = len; - -#ifdef STR_TRANSLATION - if ( len > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0 - && ber->ber_decode_translate_proc != NULL ) { - ++len; - if ( (*(ber->ber_decode_translate_proc))( &((*bv)->bv_val), - &len, 1 ) != 0 ) { - free( (*bv)->bv_val ); - return( LBER_DEFAULT ); - } - (*bv)->bv_len = len - 1; - } -#endif /* STR_TRANSLATION */ - - return( tag ); -} - -unsigned int -ber_get_bitstringa( BerElement *ber, char **buf, unsigned int *blen ) -{ - unsigned int datalen, tag; - unsigned char unusedbits; - - if ( (tag = ber_skip_tag( ber, &datalen )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - --datalen; - - if ( (*buf = (char *) malloc( (size_t)datalen )) == NULL ) - return( LBER_DEFAULT ); - - if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) - return( LBER_DEFAULT ); - - if ( ber_read( ber, *buf, datalen ) != datalen ) - return( LBER_DEFAULT ); - - *blen = datalen * 8 - unusedbits; - return( tag ); -} - -unsigned int -ber_get_null( BerElement *ber ) -{ - unsigned int len, tag; - - if ( (tag = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) - return( LBER_DEFAULT ); - - if ( len != 0 ) - return( LBER_DEFAULT ); - - return( tag ); -} - -unsigned int -ber_get_boolean( BerElement *ber, int *boolval ) -{ - int longbool; - int rc; - - rc = ber_get_int( ber, &longbool ); - *boolval = longbool; - - return( rc ); -} - -unsigned int -ber_first_element( BerElement *ber, unsigned int *len, char **last ) -{ - /* skip the sequence header, use the len to mark where to stop */ - if ( ber_skip_tag( ber, len ) == LBER_DEFAULT ) { - return( LBER_DEFAULT ); - } - - *last = ber->ber_ptr + *len; - - if ( *last == ber->ber_ptr ) { - return( LBER_DEFAULT ); - } - - return( ber_peek_tag( ber, len ) ); -} - -unsigned int -ber_next_element( BerElement *ber, unsigned int *len, char *last ) -{ - if ( ber->ber_ptr == last ) { - return( LBER_DEFAULT ); - } - - return( ber_peek_tag( ber, len ) ); -} - -/* VARARGS */ -unsigned int -ber_scanf( -#if defined(MACOS) || defined(BC31) || defined(_WIN32) || defined(__sun) - BerElement *ber, char *fmt, ... ) -#else - va_alist ) -va_dcl -#endif -{ - va_list ap; -#if !defined(MACOS) && !defined(BC31) && !defined(_WIN32) && !defined(__sun) - BerElement *ber; - char *fmt; -#endif - char *last; - char *s, **ss, ***sss; - struct berval ***bv, **bvp, *bval; - int *i, j; - int *l, rc, tag; - unsigned int len; - -#if defined(MACOS) || defined(BC31) || defined(_WIN32) || defined(__sun) - va_start( ap, fmt ); -#else - va_start( ap ); - ber = va_arg( ap, BerElement * ); - fmt = va_arg( ap, char * ); -#endif - -#ifdef LDAP_DEBUG - if ( lber_debug & 64 ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 73, "ber_scanf fmt (%s) ber:\n"), fmt ); - ber_dump( ber, 1 ); - } -#endif - - for ( rc = 0; *fmt && rc != LBER_DEFAULT; fmt++ ) { - switch ( *fmt ) { - case 'a': /* octet string - allocate storage as needed */ - ss = va_arg( ap, char ** ); - rc = ber_get_stringa( ber, ss ); - break; - - case 'b': /* boolean */ - i = va_arg( ap, int * ); - rc = ber_get_boolean( ber, i ); - break; - - case 'e': /* enumerated */ - case 'i': /* int */ - l = va_arg( ap, int * ); - rc = ber_get_int( ber, l ); - break; - - case 'l': /* length of next item */ - l = va_arg( ap, int * ); - rc = ber_peek_tag( ber, (unsigned int *)l ); - break; - - case 'n': /* null */ - rc = ber_get_null( ber ); - break; - - case 's': /* octet string - in a buffer */ - s = va_arg( ap, char * ); - l = va_arg( ap, int * ); - rc = ber_get_stringb( ber, s, (unsigned int *)l ); - break; - - case 'o': /* octet string in a supplied berval */ - bval = va_arg( ap, struct berval * ); - ber_peek_tag( ber, &bval->bv_len ); - rc = ber_get_stringa( ber, &bval->bv_val ); - break; - - case 'O': /* octet string - allocate & include length */ - bvp = va_arg( ap, struct berval ** ); - rc = ber_get_stringal( ber, bvp ); - break; - - case 'B': /* bit string - allocate storage as needed */ - ss = va_arg( ap, char ** ); - l = va_arg( ap, int * ); /* for length, in bits */ - rc = ber_get_bitstringa( ber, ss, (unsigned int *)l ); - break; - - case 't': /* tag of next item */ - i = va_arg( ap, int * ); - *i = rc = ber_peek_tag( ber, &len ); - break; - - case 'T': /* skip tag of next item */ - i = va_arg( ap, int * ); - *i = rc = ber_skip_tag( ber, &len ); - break; - - case 'v': /* sequence of strings */ - sss = va_arg( ap, char *** ); - *sss = NULL; - j = 0; - for ( tag = ber_first_element( ber, &len, &last ); - tag != LBER_DEFAULT && rc != LBER_DEFAULT; - tag = ber_next_element( ber, &len, last ) ) { - if ( *sss == NULL ) { - *sss = (char **) malloc( - 2 * sizeof(char *) ); - } else { - *sss = (char **) realloc( *sss, - (j + 2) * sizeof(char *) ); - } - rc = ber_get_stringa( ber, &((*sss)[j]) ); - j++; - } - if ( j > 0 ) - (*sss)[j] = NULL; - break; - - case 'V': /* sequence of strings + lengths */ - bv = va_arg( ap, struct berval *** ); - *bv = NULL; - j = 0; - for ( tag = ber_first_element( ber, &len, &last ); - tag != LBER_DEFAULT && rc != LBER_DEFAULT; - tag = ber_next_element( ber, &len, last ) ) { - if ( *bv == NULL ) { - *bv = (struct berval **) malloc( - 2 * sizeof(struct berval *) ); - } else { - *bv = (struct berval **) realloc( *bv, - (j + 2) * sizeof(struct berval *) ); - } - rc = ber_get_stringal( ber, &((*bv)[j]) ); - j++; - } - if ( j > 0 ) - (*bv)[j] = NULL; - break; - - case 'x': /* skip the next element - whatever it is */ - if ( (rc = ber_skip_tag( ber, &len )) == LBER_DEFAULT ) - break; - ber->ber_ptr += len; - break; - - case '{': /* begin sequence */ - case '[': /* begin set */ - if ( *(fmt + 1) != 'v' && *(fmt + 1) != 'V' ) - rc = ber_skip_tag( ber, &len ); - break; - - case '}': /* end sequence */ - case ']': /* end set */ - break; - - default: -#ifndef NO_USERINTERFACE - (void) fprintf( stderr, catgets(slapdcat, 1, 74, "unknown fmt %c\n"), *fmt ); -#endif /* NO_USERINTERFACE */ - rc = (int) LBER_DEFAULT; - break; - } - } - - va_end( ap ); - - return( rc ); -} - -void -ber_bvfree( struct berval *bv ) -{ - if ( bv->bv_val != NULL ) - free( bv->bv_val ); - free( (char *) bv ); -} - -void -ber_bvecfree( struct berval **bv ) -{ - int i; - - for ( i = 0; bv[i] != NULL; i++ ) - ber_bvfree( bv[i] ); - free( (char *) bv ); -} - -struct berval * -ber_bvdup( struct berval *bv ) -{ - struct berval *new; - - if ( (new = (struct berval *) malloc( sizeof(struct berval) )) - == NULL ) { - return( NULL ); - } - if ( (new->bv_val = (char *) malloc( bv->bv_len + 1 )) == NULL ) { - free(new); - return( NULL ); - } - SAFEMEMCPY( new->bv_val, bv->bv_val, (size_t) bv->bv_len ); - new->bv_val[bv->bv_len] = '\0'; - new->bv_len = bv->bv_len; - - return( new ); -} - - -#ifdef STR_TRANSLATION -void -ber_set_string_translators( BerElement *ber, BERTranslateProc encode_proc, - BERTranslateProc decode_proc ) -{ - ber->ber_encode_translate_proc = encode_proc; - ber->ber_decode_translate_proc = decode_proc; -} -#endif /* STR_TRANSLATION */ - -int ber_flatten(BerElement *ber, struct berval **bvPtr) -{ - struct berval * bv; - int len; - - if ((ber == NULL) || (ber->ber_buf == NULL)) - return (-1); - - len = ber->ber_ptr - ber->ber_buf; - - if ((bv = (struct berval *)malloc(sizeof(struct berval))) == NULL) - return (-1); - if ((bv->bv_val = (char *) malloc(len + 1)) == NULL) { - free(bv); - return (-1); - } - - SAFEMEMCPY(bv->bv_val, ber->ber_buf, (size_t)len); - bv->bv_val[len] = '\0'; - bv->bv_len = len; - - *bvPtr = bv; - return (0); -}
--- a/usr/src/lib/libldap4/ber/encode.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,658 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* encode.c - ber output encoding routines */ -/* - * Copyright (c) 1990 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 <stdio.h> -#ifdef MACOS -#include <stdlib.h> -#include <stdarg.h> -#include "macos.h" -#else /* MACOS */ -#if defined(NeXT) || defined(VMS) -#include <stdlib.h> -#else /* next || vms */ -#include <malloc.h> -#endif /* next || vms */ -#if defined( BC31 ) || defined( _WIN32 ) || defined(__sun) -#include <stdarg.h> -#else /* BC31 || _WIN32 */ -#include <varargs.h> -#endif /* BC31 || _WIN32 */ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#ifdef PCNFS -#include <tklib.h> -#endif /* PCNFS */ -#endif /* MACOS */ -#ifndef VMS -#include <memory.h> -#endif -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#endif /* DOS */ - -#ifdef NEEDPROTOS -static int ber_put_len( BerElement *ber, unsigned int len, int nosos ); -static int ber_start_seqorset( BerElement *ber, unsigned int tag ); -static int ber_put_seqorset( BerElement *ber ); -static int ber_put_int_or_enum( BerElement *ber, int num, unsigned int tag ); -#endif /* NEEDPROTOS */ - -extern int ber_realloc(BerElement *ber, unsigned int len); - -static int -ber_calc_taglen( unsigned int tag ) -{ - int i; - int mask; - - /* find the first non-all-zero byte in the tag */ - for ( i = sizeof(int) - 1; i > 0; i-- ) { - mask = (0xffL << (i * 8)); - /* not all zero */ - if ( tag & mask ) - break; - } - - return( i + 1 ); -} - -static int -ber_put_tag( BerElement *ber, unsigned int tag, int nosos ) -{ - int taglen; - unsigned int ntag; - - taglen = ber_calc_taglen( tag ); - - ntag = LBER_HTONL( tag ); - - return( ber_write( ber, ((char *) &ntag) + sizeof(int) - taglen, - taglen, nosos ) ); -} - -static int -ber_calc_lenlen( unsigned int len ) -{ - /* - * short len if it's less than 128 - one byte giving the len, - * with bit 8 0. - */ - - if ( len <= 0x7F ) - return( 1 ); - - /* - * int len otherwise - one byte with bit 8 set, giving the - * length of the length, followed by the length itself. - */ - - if ( len <= 0xFF ) - return( 2 ); - if ( len <= 0xFFFF ) - return( 3 ); - if ( len <= 0xFFFFFF ) - return( 4 ); - - return( 5 ); -} - -static int -ber_put_len( BerElement *ber, unsigned int len, int nosos ) -{ - int i; - char lenlen; - int mask; - unsigned int netlen; - - /* - * short len if it's less than 128 - one byte giving the len, - * with bit 8 0. - */ - - if ( len <= 127 ) { - netlen = LBER_HTONL( len ); - return( ber_write( ber, (char *) &netlen + sizeof(int) - 1, - 1, nosos ) ); - } - - /* - * int len otherwise - one byte with bit 8 set, giving the - * length of the length, followed by the length itself. - */ - - /* find the first non-all-zero byte */ - for ( i = sizeof(int) - 1; i > 0; i-- ) { - mask = (0xff << (i * 8)); - /* not all zero */ - if ( len & mask ) - break; - } - lenlen = ++i; - if ( lenlen > 4 ) - return( -1 ); - lenlen |= 0x80; - - /* write the length of the length */ - if ( ber_write( ber, &lenlen, 1, nosos ) != 1 ) - return( -1 ); - - /* write the length itself */ - netlen = LBER_HTONL( len ); - if ( ber_write( ber, (char *) &netlen + (sizeof(int) - i), i, nosos ) - != i ) - return( -1 ); - - return( i + 1 ); -} - -static int -ber_put_int_or_enum( BerElement *ber, int num, unsigned int tag ) -{ - int i, sign, taglen; - int len, lenlen; - int netnum, mask; - - sign = (num < 0); - - /* - * high bit is set - look for first non-all-one byte - * high bit is clear - look for first non-all-zero byte - */ - for ( i = sizeof(int) - 1; i > 0; i-- ) { - mask = (0xff << (i * 8)); - - if ( sign ) { - /* not all ones */ - if ( (num & mask) != mask ) - break; - } else { - /* not all zero */ - if ( num & mask ) - break; - } - } - - /* - * we now have the "leading byte". if the high bit on this - * byte matches the sign bit, we need to "back up" a byte. - */ - mask = (num & (0x80 << (i * 8))); - if ( (mask && !sign) || (sign && !mask) ) - i++; - - len = i + 1; - - if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) - return( -1 ); - - if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 ) - return( -1 ); - i++; - netnum = LBER_HTONL( num ); - if ( ber_write( ber, (char *) &netnum + (sizeof(int) - i), i, 0 ) - != i ) - return( -1 ); - - /* length of tag + length + contents */ - return( taglen + lenlen + i ); -} - -int -ber_put_enum( BerElement *ber, int num, unsigned int tag ) -{ - if ( tag == LBER_DEFAULT ) - tag = LBER_ENUMERATED; - - return( ber_put_int_or_enum( ber, num, tag ) ); -} - -int -ber_put_int( BerElement *ber, int num, unsigned int tag ) -{ - if ( tag == LBER_DEFAULT ) - tag = LBER_INTEGER; - - return( ber_put_int_or_enum( ber, num, tag ) ); -} - -int -ber_put_ostring( BerElement *ber, char *str, unsigned int len, - unsigned int tag ) -{ - int taglen, lenlen, rc; -#ifdef STR_TRANSLATION - int free_str; -#endif /* STR_TRANSLATION */ - - if ( tag == LBER_DEFAULT ) - tag = LBER_OCTETSTRING; - - if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) - return( -1 ); - -#ifdef STR_TRANSLATION - if ( len > 0 && ( ber->ber_options & LBER_TRANSLATE_STRINGS ) != 0 && - ber->ber_encode_translate_proc != NULL ) { - if ( (*(ber->ber_encode_translate_proc))( &str, &len, 0 ) - != 0 ) { - return( -1 ); - } - free_str = 1; - } else { - free_str = 0; - } -#endif /* STR_TRANSLATION */ - - if ( (lenlen = ber_put_len( ber, len, 0 )) == -1 || - ber_write( ber, str, len, 0 ) != len ) { - rc = -1; - } else { - /* return length of tag + length + contents */ - rc = taglen + lenlen + len; - } - -#ifdef STR_TRANSLATION - if ( free_str ) { - free( str ); - } -#endif /* STR_TRANSLATION */ - - return( rc ); -} - -int -ber_put_string( BerElement *ber, char *str, unsigned int tag ) -{ - return( ber_put_ostring( ber, str, (unsigned int)strlen( str ), tag )); -} - -int -ber_put_bitstring( BerElement *ber, char *str, - unsigned int blen /* in bits */, unsigned int tag ) -{ - int taglen, lenlen, len; - unsigned char unusedbits; - - if ( tag == LBER_DEFAULT ) - tag = LBER_BITSTRING; - - if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) - return( -1 ); - - len = ( blen + 7 ) / 8; - unusedbits = len * 8 - blen; - if ( (lenlen = ber_put_len( ber, len + 1, 0 )) == -1 ) - return( -1 ); - - if ( ber_write( ber, (char *)&unusedbits, 1, 0 ) != 1 ) - return( -1 ); - - if ( ber_write( ber, str, len, 0 ) != len ) - return( -1 ); - - /* return length of tag + length + unused bit count + contents */ - return( taglen + 1 + lenlen + len ); -} - -int -ber_put_null( BerElement *ber, unsigned int tag ) -{ - int taglen; - - if ( tag == LBER_DEFAULT ) - tag = LBER_NULL; - - if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) - return( -1 ); - - if ( ber_put_len( ber, 0, 0 ) != 1 ) - return( -1 ); - - return( taglen + 1 ); -} - -int -ber_put_boolean( BerElement *ber, int boolval, unsigned int tag ) -{ - int taglen; - unsigned char trueval = 0xff; - unsigned char falseval = 0x00; - - if ( tag == LBER_DEFAULT ) - tag = LBER_BOOLEAN; - - if ( (taglen = ber_put_tag( ber, tag, 0 )) == -1 ) - return( -1 ); - - if ( ber_put_len( ber, 1, 0 ) != 1 ) - return( -1 ); - - if ( ber_write( ber, (char *)(boolval ? &trueval : &falseval), 1, 0 ) - != 1 ) - return( -1 ); - - return( taglen + 2 ); -} - -#define FOUR_BYTE_LEN 5 - -static int -ber_start_seqorset( BerElement *ber, unsigned int tag ) -{ - Seqorset *new; - - if ( (new = (Seqorset *) calloc( sizeof(Seqorset), 1 )) - == NULLSEQORSET ) - return( -1 ); - new->sos_ber = ber; - if ( ber->ber_sos == NULLSEQORSET ) - new->sos_first = ber->ber_ptr; - else - new->sos_first = ber->ber_sos->sos_ptr; - - /* Set aside room for a 4 byte length field */ - new->sos_ptr = new->sos_first + ber_calc_taglen( tag ) + FOUR_BYTE_LEN; - new->sos_tag = tag; - - new->sos_next = ber->ber_sos; - ber->ber_sos = new; - if (ber->ber_sos->sos_ptr > ber->ber_end) - ber_realloc(ber, ber->ber_sos->sos_ptr - ber->ber_end); - - return( 0 ); -} - -int -ber_start_seq( BerElement *ber, unsigned int tag ) -{ - if ( tag == LBER_DEFAULT ) - tag = LBER_SEQUENCE; - - return( ber_start_seqorset( ber, tag ) ); -} - -int -ber_start_set( BerElement *ber, unsigned int tag ) -{ - if ( tag == LBER_DEFAULT ) - tag = LBER_SET; - - return( ber_start_seqorset( ber, tag ) ); -} - -static int -ber_put_seqorset( BerElement *ber ) -{ - unsigned int len, netlen; - int taglen, lenlen; - unsigned char ltag = 0x80 + FOUR_BYTE_LEN - 1; - Seqorset *next; - Seqorset **sos = &ber->ber_sos; - - /* - * If this is the toplevel sequence or set, we need to actually - * write the stuff out. Otherwise, it's already been put in - * the appropriate buffer and will be written when the toplevel - * one is written. In this case all we need to do is update the - * length and tag. - */ - - len = (*sos)->sos_clen; - netlen = LBER_HTONL( len ); - /* CONSTCOND */ - if ( sizeof(int) > 4 && len > 0xFFFFFFFF ) - return( -1 ); - - if ( ber->ber_options & LBER_USE_DER ) { - lenlen = ber_calc_lenlen( len ); - } else { - lenlen = FOUR_BYTE_LEN; - } - - if ( (next = (*sos)->sos_next) == NULLSEQORSET ) { - /* write the tag */ - if ( (taglen = ber_put_tag( ber, (*sos)->sos_tag, 1 )) == -1 ) - return( -1 ); - - if ( ber->ber_options & LBER_USE_DER ) { - /* Write the length in the minimum # of octets */ - if ( ber_put_len( ber, len, 1 ) == -1 ) - return( -1 ); - - if (lenlen != FOUR_BYTE_LEN) { - /* - * We set aside FOUR_BYTE_LEN bytes for - * the length field. Move the data if - * we don't actually need that much - */ - (void) SAFEMEMCPY( (*sos)->sos_first + taglen + - lenlen, (*sos)->sos_first + taglen + - FOUR_BYTE_LEN, len ); - } - } else { - /* Fill FOUR_BYTE_LEN bytes for length field */ - /* one byte of length length */ - if ( ber_write( ber, (char *)<ag, 1, 1 ) != 1 ) - return( -1 ); - - /* the length itself */ - if ( ber_write( ber, (char *) &netlen + sizeof(int) - - (FOUR_BYTE_LEN - 1), FOUR_BYTE_LEN - 1, 1 ) - != FOUR_BYTE_LEN - 1 ) - return( -1 ); - } - /* The ber_ptr is at the set/seq start - move it to the end */ - (*sos)->sos_ber->ber_ptr += len; - } else { - unsigned int ntag; - - /* the tag */ - taglen = ber_calc_taglen( (*sos)->sos_tag ); - ntag = LBER_HTONL( (*sos)->sos_tag ); - (void) SAFEMEMCPY( (*sos)->sos_first, (char *) &ntag + - sizeof(int) - taglen, taglen ); - - if ( ber->ber_options & LBER_USE_DER ) { - ltag = (lenlen == 1) ? len : 0x80 + (lenlen - 1); - } - - /* one byte of length length */ - (void) SAFEMEMCPY( (*sos)->sos_first + 1, <ag, 1 ); - - if ( ber->ber_options & LBER_USE_DER ) { - if (lenlen > 1) { - /* Write the length itself */ - (void) SAFEMEMCPY( (*sos)->sos_first + 2, - (char *)&netlen + sizeof(unsigned int) - - (lenlen - 1), - lenlen - 1 ); - } - if (lenlen != FOUR_BYTE_LEN) { - /* - * We set aside FOUR_BYTE_LEN bytes for - * the length field. Move the data if - * we don't actually need that much - */ - (void) SAFEMEMCPY( (*sos)->sos_first + taglen + - lenlen, (*sos)->sos_first + taglen + - FOUR_BYTE_LEN, len ); - } - } else { - /* the length itself */ - (void) SAFEMEMCPY( (*sos)->sos_first + taglen + 1, - (char *) &netlen + sizeof(int) - - (FOUR_BYTE_LEN - 1), FOUR_BYTE_LEN - 1 ); - } - - next->sos_clen += (taglen + lenlen + len); - next->sos_ptr += (taglen + lenlen + len); - } - - /* we're done with this seqorset, so free it up */ - free( (char *) (*sos) ); - *sos = next; - - return( taglen + lenlen + len ); -} - -int -ber_put_seq( BerElement *ber ) -{ - return( ber_put_seqorset( ber ) ); -} - -int -ber_put_set( BerElement *ber ) -{ - return( ber_put_seqorset( ber ) ); -} - -/* VARARGS */ -int -ber_printf( -#if defined(MACOS) || defined(_WIN32) || defined(BC31) || defined(__sun) - BerElement *ber, char *fmt, ... ) -#else /* MACOS || _WIN32 || BC31 */ - va_alist ) -va_dcl -#endif /* MACOS || _WIN32 || BC31 */ -{ - va_list ap; -#if !defined(MACOS) && !defined(_WIN32) && !defined(BC31) && !defined(__sun) - BerElement *ber; - char *fmt; -#endif /* !MACOS && !_WIN32 && !BC31 */ - char *s, **ss; - struct berval **bv; - int rc, i; - unsigned int len; - -#if defined(MACOS) || defined(_WIN32) || defined(BC31) || defined(__sun) - va_start( ap, fmt ); -#else /* MACOS || _WIN32 || BC31 */ - va_start( ap ); - ber = va_arg( ap, BerElement * ); - fmt = va_arg( ap, char * ); -#endif /* MACOS || _WIN32 || BC31 */ - - for ( rc = 0; *fmt && rc != -1; fmt++ ) { - switch ( *fmt ) { - case 'b': /* boolean */ - i = va_arg( ap, int ); - rc = ber_put_boolean( ber, i, ber->ber_tag ); - break; - - case 'i': /* int */ - i = va_arg( ap, int ); - rc = ber_put_int( ber, i, ber->ber_tag ); - break; - - case 'e': /* enumeration */ - i = va_arg( ap, int ); - rc = ber_put_enum( ber, i, ber->ber_tag ); - break; - - case 'n': /* null */ - rc = ber_put_null( ber, ber->ber_tag ); - break; - - case 'o': /* octet string (non-null terminated) */ - s = va_arg( ap, char * ); - len = va_arg( ap, int ); - rc = ber_put_ostring( ber, s, len, ber->ber_tag ); - break; - - case 's': /* string */ - s = va_arg( ap, char * ); - rc = ber_put_string( ber, s, ber->ber_tag ); - break; - - case 'B': /* bit string */ - s = va_arg( ap, char * ); - len = va_arg( ap, int ); /* in bits */ - rc = ber_put_bitstring( ber, s, len, ber->ber_tag ); - break; - - case 't': /* tag for the next element */ - ber->ber_tag = va_arg( ap, unsigned int ); - ber->ber_usertag = 1; - break; - - case 'v': /* vector of strings */ - if ( (ss = va_arg( ap, char ** )) == NULL ) - break; - for ( i = 0; ss[i] != NULL; i++ ) { - if ( (rc = ber_put_string( ber, ss[i], - ber->ber_tag )) == -1 ) - break; - } - break; - - case 'V': /* sequences of strings + lengths */ - if ( (bv = va_arg( ap, struct berval ** )) == NULL ) - break; - for ( i = 0; bv[i] != NULL; i++ ) { - if ( (rc = ber_put_ostring( ber, bv[i]->bv_val, - bv[i]->bv_len, ber->ber_tag )) == -1 ) - break; - } - break; - - case '{': /* begin sequence */ - rc = ber_start_seq( ber, ber->ber_tag ); - break; - - case '}': /* end sequence */ - rc = ber_put_seqorset( ber ); - break; - - case '[': /* begin set */ - rc = ber_start_set( ber, ber->ber_tag ); - break; - - case ']': /* end set */ - rc = ber_put_seqorset( ber ); - break; - - default: -#ifndef NO_USERINTERFACE - (void) fprintf( stderr, catgets(slapdcat, 1, 74, "unknown fmt %c\n"), *fmt ); -#endif /* NO_USERINTERFACE */ - rc = -1; - break; - } - - if ( ber->ber_usertag == 0 ) - ber->ber_tag = LBER_DEFAULT; - else - ber->ber_usertag = 0; - } - - va_end( ap ); - - return( rc ); -}
--- a/usr/src/lib/libldap4/ber/i18n.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <nl_types.h> -/* #include <lthread.h> */ -#include <pthread.h> -#include <thread.h> - -nl_catd slapdcat = 0; -int notdone = 1; -static pthread_mutex_t log_mutex; -pthread_mutex_t systime_mutex; - -void i18n_catopen(char * name) -{ - if ( notdone ) { - notdone = 0; - slapdcat = catopen(name, NL_CAT_LOCALE); - } /* end if */ -} -
--- a/usr/src/lib/libldap4/ber/io.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,683 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* io.c - ber general i/o routines */ -/* - * Copyright (c) 1990 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 <stdio.h> -#include <ctype.h> -#include <unistd.h> -#include <poll.h> - -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#endif /* DOS || _WIN32 */ - -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined(NeXT) || defined(VMS) -#include <stdlib.h> -#else /* next || vms */ -#include <malloc.h> -#endif /* next || vms */ -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#ifdef PCNFS -#include <tklib.h> -#endif /* PCNFS */ -#endif /* MACOS */ - -#ifdef SUN -#include <unistd.h> -#endif - -#ifndef VMS -#include <memory.h> -#endif -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifdef _WIN32 -#include <winsock.h> -#include <io.h> -#endif /* _WIN32 */ - -#ifdef NEEDPROTOS -int ber_realloc(BerElement *ber, unsigned int len); -static int ber_filbuf(Sockbuf *sb, int len); -static int BerRead(Sockbuf *sb, char *buf, int len); -#ifdef PCNFS -static int BerWrite( Sockbuf *sb, char *buf, int len ); -#endif /* PCNFS */ -#else -int ber_filbuf(); -int BerRead(); -int ber_realloc(); -#endif /* NEEDPROTOS */ - -#define bergetc( sb, len ) ( sb->sb_ber.ber_end > sb->sb_ber.ber_ptr ? \ - (unsigned char)*sb->sb_ber.ber_ptr++ : \ - ber_filbuf( sb, len )) - -#ifdef MACOS -/* - * MacTCP/OpenTransport - */ -#define read( s, b, l ) tcpread( s, 0, (unsigned char *)b, l, NULL ) -#define MAX_WRITE 65535 -#define BerWrite( sb, b, l ) tcpwrite( sb->sb_sd, (unsigned char *)(b), (l<MAX_WRITE)? l : MAX_WRITE ) -#else /* MACOS */ -#ifdef DOS -#ifdef PCNFS -/* - * PCNFS (under DOS) - */ -#define read( s, b, l ) recv( s, b, l, 0 ) -#define BerWrite( s, b, l ) send( s->sb_sd, b, (int) l, 0 ) -#endif /* PCNFS */ -#ifdef NCSA -/* - * NCSA Telnet TCP/IP stack (under DOS) - */ -#define read( s, b, l ) nread( s, b, l ) -#define BerWrite( s, b, l ) netwrite( s->sb_sd, b, l ) -#endif /* NCSA */ -#ifdef WINSOCK -/* - * Windows Socket API (under DOS/Windows 3.x) - */ -#define read( s, b, l ) recv( s, b, l, 0 ) -#define BerWrite( s, b, l ) send( s->sb_sd, b, l, 0 ) -#endif /* WINSOCK */ -#else /* DOS */ -#ifdef _WIN32 -/* - * 32-bit Windows Socket API (under Windows NT or Windows 95) - */ -#define read( s, b, l ) recv( s, b, l, 0 ) -#define BerWrite( s, b, l ) send( s->sb_sd, b, l, 0 ) -#else /* _WIN32 */ -#ifdef VMS -/* - * VMS -- each write must be 64K or smaller - */ -#define MAX_WRITE 65535 -#define BerWrite( sb, b, l ) write( sb->sb_sd, b, (l<MAX_WRITE)? l : MAX_WRITE) -#else /* VMS */ -/* - * everything else (Unix/BSD 4.3 socket API) - */ -#define BerWrite( sb, b, l ) write( sb->sb_sd, b, l ) -#endif /* VMS */ -#define udp_read( sb, b, l, al ) recvfrom(sb->sb_sd, (char *)b, l, 0, \ - (struct sockaddr *)sb->sb_fromaddr, \ - (al = sizeof(struct sockaddr), &al)) -#define udp_write( sb, b, l ) sendto(sb->sb_sd, (char *)(b), l, 0, \ - (struct sockaddr *)sb->sb_useaddr, sizeof(struct sockaddr)) -#endif /* _WIN32 */ -#endif /* DOS */ -#endif /* MACOS */ - -#ifndef udp_read -#define udp_read( sb, b, l, al ) CLDAP NOT SUPPORTED -#define udp_write( sb, b, l ) CLDAP NOT SUPPORTED -#endif /* udp_read */ - -#define EXBUFSIZ 1024 - -int -ber_filbuf( Sockbuf *sb, int len ) -{ - ssize_t rc; -#ifdef CLDAP - int addrlen; -#endif /* CLDAP */ - - if ( sb->sb_ber.ber_buf == NULL ) { - if ( (sb->sb_ber.ber_buf = (char *) malloc( READBUFSIZ )) == - NULL ) - return( -1 ); - sb->sb_ber.ber_ptr = sb->sb_ber.ber_buf; - sb->sb_ber.ber_end = sb->sb_ber.ber_buf; - } - - if ( sb->sb_naddr > 0 ) { -#ifdef CLDAP - rc = udp_read(sb, sb->sb_ber.ber_buf, READBUFSIZ, addrlen ); -#ifdef LDAP_DEBUG - if ( lber_debug ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 75, "ber_filbuf udp_read %d bytes\n"), - (int)rc ); - if ( lber_debug > 1 && rc > 0 ) - lber_bprint( sb->sb_ber.ber_buf, (int)rc ); - } -#endif /* LDAP_DEBUG */ -#else /* CLDAP */ - rc = -1; -#endif /* CLDAP */ -#ifdef LDAP_SSL - } else if ( sb->sb_ssl != NULL ) { - rc = SSL_read(sb->sb_ssl,(u_char *)sb->sb_ber.ber_buf, - ((sb->sb_options & LBER_NO_READ_AHEAD) && - (len < READBUFSIZ)) ? - len : READBUFSIZ ); -#endif /* LDAP_SSL */ - } else { - int loop=2; - while (loop>0) { - --loop; - rc = read( sb->sb_sd, sb->sb_ber.ber_buf, - ((sb->sb_options & LBER_NO_READ_AHEAD) && - (len < READBUFSIZ)) ? - len : READBUFSIZ ); - /* - * if packet not here yet, wait 10 seconds to let it arrive - */ - if ( rc <= 0 && (errno==EWOULDBLOCK || errno==EAGAIN) ) { - struct pollfd poll_tab[1]; - poll_tab[0].fd = sb->sb_sd; - poll_tab[0].events = POLLIN; - poll_tab[0].revents = 0; - if ( poll(poll_tab, 1, 10000) <= 0) { - /* nothing received or error, just abandon the read */ - break; - } /* end if */ - } else { - break; - } /* end if */ - } /* end while */ - } - - if ( rc > 0 ) { - sb->sb_ber.ber_ptr = sb->sb_ber.ber_buf + 1; - sb->sb_ber.ber_end = sb->sb_ber.ber_buf + rc; - return( (unsigned char)*sb->sb_ber.ber_buf ); - } - - return( -1 ); -} - - -int -BerRead( Sockbuf *sb, char *buf, int len ) -{ - int c; - int nread = 0; - - while ( len > 0 ) { - if ( (c = bergetc( sb, len )) < 0 ) { - if ( nread > 0 ) - break; - return( c ); - } - *buf++ = (char)c; - nread++; - len--; - } - - return( nread ); -} - - -int -ber_read( BerElement *ber, char *buf, unsigned int len ) -{ - unsigned int actuallen, nleft; - - nleft = (int)(ber->ber_end - ber->ber_ptr); - actuallen = nleft < len ? nleft : len; - - SAFEMEMCPY( buf, ber->ber_ptr, (size_t)actuallen ); - - ber->ber_ptr += actuallen; - - return( (int)actuallen ); -} - -int -ber_write( BerElement *ber, char *buf, unsigned int len, int nosos ) -{ - if ( nosos || ber->ber_sos == NULL ) { - if ( ber->ber_ptr + len > ber->ber_end ) { - if ( ber_realloc( ber, len ) != 0 ) - return( -1 ); - } - (void) SAFEMEMCPY( ber->ber_ptr, buf, (size_t)len ); - ber->ber_ptr += len; - return( len ); - } else { - if ( ber->ber_sos->sos_ptr + len > ber->ber_end ) { - if ( ber_realloc( ber, len ) != 0 ) - return( -1 ); - } - (void) SAFEMEMCPY( ber->ber_sos->sos_ptr, buf, (size_t)len ); - ber->ber_sos->sos_ptr += len; - ber->ber_sos->sos_clen += len; - return( len ); - } -} - -int -ber_realloc(BerElement *ber, unsigned int len) -{ - size_t need, have, total; - Seqorset *s; - ssize_t off; - char *oldbuf; - - have = (ber->ber_end - ber->ber_buf) / EXBUFSIZ; - need = (len < EXBUFSIZ ? 1 : (len + (EXBUFSIZ - 1)) / EXBUFSIZ); - total = have * EXBUFSIZ + need * EXBUFSIZ; - - oldbuf = ber->ber_buf; - - if ( ber->ber_buf == NULL ) { - if ( (ber->ber_buf = (char *) malloc( (size_t)total )) == NULL ) - return( -1 ); - } else if ( (ber->ber_buf = (char *) realloc( ber->ber_buf, - (size_t)total )) == NULL ) - return( -1 ); - - ber->ber_end = ber->ber_buf + total; - - /* - * If the stinking thing was moved, we need to go through and - * reset all the sos and ber pointers. Offsets would've been - * a better idea... oh well. - */ - - if ( ber->ber_buf != oldbuf ) { - ber->ber_ptr = ber->ber_buf + (ber->ber_ptr - oldbuf); - - for ( s = ber->ber_sos; s != NULLSEQORSET; s = s->sos_next ) { - off = s->sos_first - oldbuf; - s->sos_first = ber->ber_buf + off; - - off = s->sos_ptr - oldbuf; - s->sos_ptr = ber->ber_buf + off; - } - } - - return( 0 ); -} - -void -ber_free(BerElement *ber, int freebuf) -{ - if (NULL != ber) { - if (freebuf && ber->ber_buf != NULL) - free(ber->ber_buf); - free((char *)ber); - } -} - -int -ber_flush( Sockbuf *sb, BerElement *ber, int freeit ) -{ - ssize_t nwritten, towrite, rc; - - if ( ber->ber_rwptr == NULL ) { - ber->ber_rwptr = ber->ber_buf; - } - towrite = ber->ber_ptr - ber->ber_rwptr; - -#ifdef LDAP_DEBUG - if ( lber_debug ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 76, "ber_flush: %1$ld bytes to sd %2$ld%s\n"), towrite, - sb->sb_sd, ber->ber_rwptr != ber->ber_buf ? " (re-flush)" - : "" ); - if ( lber_debug > 1 ) - lber_bprint( ber->ber_rwptr, towrite ); - } -#endif -#if !defined(MACOS) && !defined(DOS) - if ( sb->sb_options & (LBER_TO_FILE | LBER_TO_FILE_ONLY) ) { -#ifdef LDAP_SSL - if (sb->sb_ssl) { - rc = SSL_write( sb->sb_ssl, (u_char *)ber->ber_buf, towrite ); - if ( rc < 0 ) { - fprintf( stderr, SSL_strerr(SSL_errno(sb->sb_ssl))); - } - } else { -#endif /* LDAP_SSL */ - rc = write( sb->sb_fd, ber->ber_buf, towrite ); - if ( sb->sb_options & LBER_TO_FILE_ONLY ) { - return( (int)rc ); - } -#ifdef LDAP_SSL - } -#endif /* LDAP_SSL */ - } -#endif - - nwritten = 0; - do { - if (sb->sb_naddr > 0) { -#ifdef CLDAP - rc = udp_write( sb, ber->ber_buf + nwritten, - (size_t)towrite ); -#else /* CLDAP */ - rc = -1; -#endif /* CLDAP */ - if ( rc <= 0 ) - return( -1 ); - /* fake error if write was not atomic */ - if (rc < towrite) { -#if !defined( MACOS ) && !defined( DOS ) - errno = EMSGSIZE; -#endif - return( -1 ); - } - } else { -#ifdef LDAP_SSL - if (sb->sb_ssl) { - if ( (rc = SSL_write( sb->sb_ssl, (u_char *)ber->ber_rwptr, - (size_t) towrite )) <= 0 ) { - return( -1 ); - } - } else -#endif /* LDAP_SSL */ - if ( (rc = BerWrite( sb, ber->ber_rwptr, - (size_t) towrite )) <= 0 ) { - return( -1 ); - } - } - towrite -= rc; - nwritten += rc; - ber->ber_rwptr += rc; - } while ( towrite > 0 ); - - if ( freeit ) - ber_free( ber, 1 ); - - return( 0 ); -} - -BerElement * -ber_alloc_t( int options ) -{ - BerElement *ber; - - if ( (ber = (BerElement *) calloc( (size_t) 1, sizeof(BerElement) )) == NULLBER ) - return( NULLBER ); - ber->ber_tag = LBER_DEFAULT; - ber->ber_options = (char) options; - - return( ber ); -} - -BerElement * -ber_alloc() -{ - return( ber_alloc_t( 0 ) ); -} - -BerElement * -der_alloc() -{ - return( ber_alloc_t( LBER_USE_DER ) ); -} - -BerElement * -ber_dup( BerElement *ber ) -{ - BerElement *new; - - if ( (new = ber_alloc()) == NULLBER ) - return( NULLBER ); - - *new = *ber; - - return( new ); -} - -BerElement *ber_init(struct berval *bv) -{ - BerElement *new; - - if (bv == NULL) - return (NULLBER); - - if ((new = ber_alloc()) == NULLBER) - return (NULLBER); - if ((new->ber_buf = (char *)malloc(bv->bv_len + 1)) == NULL){ - free(new); - return (NULLBER); - } - SAFEMEMCPY(new->ber_buf, bv->bv_val, bv->bv_len); - new->ber_end = new->ber_buf + bv->bv_len; - new->ber_ptr = new->ber_buf; - new->ber_len = bv->bv_len; - return (new); -} - -void -ber_zero_init( BerElement *ber, int options ) -{ - (void) memset( (char *)ber, '\0', sizeof( BerElement )); - ber->ber_tag = LBER_DEFAULT; - ber->ber_options = options; -} - - -void -ber_reset( BerElement *ber, int was_writing ) -{ - if ( was_writing ) { - ber->ber_end = ber->ber_ptr; - ber->ber_ptr = ber->ber_buf; - } else { - ber->ber_ptr = ber->ber_end; - } - - ber->ber_rwptr = NULL; -} - - -#ifdef LDAP_DEBUG - -void -ber_dump( BerElement *ber, int inout ) -{ - (void) fprintf( stderr, catgets(slapdcat, 1, 77, "ber_dump: buf 0x%1$lx, ptr 0x%2$lx, end 0x%3$lx\n"), - ber->ber_buf, ber->ber_ptr, ber->ber_end ); - if ( inout == 1 ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 78, " current len %ld, contents:\n"), - ber->ber_end - ber->ber_ptr ); - lber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr ); - } else { - (void) fprintf( stderr, catgets(slapdcat, 1, 78, " current len %ld, contents:\n"), - ber->ber_ptr - ber->ber_buf ); - lber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf ); - } -} - -void -ber_sos_dump( Seqorset *sos ) -{ - (void) fprintf( stderr, catgets(slapdcat, 1, 79, "*** sos dump ***\n") ); - while ( sos != NULLSEQORSET ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 80, "ber_sos_dump: clen %1$ld first 0x%2$lx ptr 0x%3$lx\n"), - sos->sos_clen, sos->sos_first, sos->sos_ptr ); - (void) fprintf( stderr, catgets(slapdcat, 1, 81, " current len %ld contents:\n"), - sos->sos_ptr - sos->sos_first ); - lber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first ); - - sos = sos->sos_next; - } - (void) fprintf( stderr, catgets(slapdcat, 1, 82, "*** end dump ***\n") ); -} - -#endif - -/* return the tag - LBER_DEFAULT returned means trouble */ -static unsigned int -get_tag( Sockbuf *sb ) -{ - unsigned char xbyte; - unsigned int tag; - char *tagp; - int i; - - if ( BerRead( sb, (char *) &xbyte, 1 ) != 1 ) - return( LBER_DEFAULT ); - - if ( (xbyte & LBER_BIG_TAG_MASK) != LBER_BIG_TAG_MASK ) - return( (unsigned int) xbyte ); - - tagp = (char *) &tag; - tagp[0] = xbyte; - for ( i = 1; i < sizeof(int); i++ ) { - if ( BerRead( sb, (char *) &xbyte, 1 ) != 1 ) - return( LBER_DEFAULT ); - - tagp[i] = xbyte; - - if ( ! (xbyte & LBER_MORE_TAG_MASK) ) - break; - } - - /* tag too big! */ - if ( i == sizeof(int) ) - return( LBER_DEFAULT ); - - /* want leading, not trailing 0's */ - return( tag >> (sizeof(int) - i - 1) ); -} - -unsigned int -ber_get_next( Sockbuf *sb, unsigned int *len, BerElement *ber ) -{ - unsigned int tag, netlen, toread; - unsigned char lc; - int rc; - int noctets, diff; - -#ifdef LDAP_DEBUG - if ( lber_debug ) - (void) fprintf( stderr, catgets(slapdcat, 1, 83, "ber_get_next\n") ); -#endif - - /* - * Any ber element looks like this: tag length contents. - * Assuming everything's ok, we return the tag byte (we - * can assume a single byte), return the length in len, - * and the rest of the undecoded element in buf. - * - * Assumptions: - * 1) small tags (less than 128) - * 2) definite lengths - * 3) primitive encodings used whenever possible - */ - - /* - * first time through - malloc the buffer, set up ptrs, and - * read the tag and the length and as much of the rest as we can - */ - - if ( ber->ber_rwptr == NULL ) { - /* - * First, we read the tag. - */ - - if ( (tag = get_tag( sb )) == LBER_DEFAULT ) { - return( LBER_DEFAULT ); - } - ber->ber_tag = tag; - - /* - * Next, read the length. The first byte contains the length - * of the length. If bit 8 is set, the length is the int - * form, otherwise it's the short form. We don't allow a - * length that's greater than what we can hold in an unsigned - * int. - */ - - *len = netlen = 0; - if ( BerRead( sb, (char *) &lc, 1 ) != 1 ) { - return( LBER_DEFAULT ); - } - if ( lc & 0x80 ) { - noctets = (lc & 0x7f); - if ( noctets > sizeof(unsigned int) ) - return( LBER_DEFAULT ); - diff = sizeof(unsigned int) - noctets; - if ( BerRead( sb, (char *) &netlen + diff, noctets ) != - noctets ) { - return( LBER_DEFAULT ); - } - *len = LBER_NTOHL( netlen ); - } else { - *len = lc; - } - ber->ber_len = *len; - - /* - * Finally, malloc a buffer for the contents and read it in. - * It's this buffer that's passed to all the other ber decoding - * routines. - */ - -#if defined( DOS ) && !defined( _WIN32 ) - if ( *len > 65535 ) { /* DOS can't allocate > 64K */ - return( LBER_DEFAULT ); - } -#endif /* DOS && !_WIN32 */ - - if ( ( sb->sb_options & LBER_MAX_INCOMING_SIZE ) && - *len > sb->sb_max_incoming ) { - return( LBER_DEFAULT ); - } - - if ( (ber->ber_buf = (char *) malloc( (size_t)*len )) == NULL ) { - return( LBER_DEFAULT ); - } - ber->ber_ptr = ber->ber_buf; - ber->ber_end = ber->ber_buf + *len; - ber->ber_rwptr = ber->ber_buf; - } - - toread = (uintptr_t)ber->ber_end - (uintptr_t)ber->ber_rwptr; - do { - if ( (rc = BerRead( sb, ber->ber_rwptr, (int)toread )) <= 0 ) { - return( LBER_DEFAULT ); - } - - toread -= rc; - ber->ber_rwptr += rc; - } while ( toread != 0 ); /* DF SUN for LINT */ - -#ifdef LDAP_DEBUG - if ( lber_debug ) { - (void) fprintf( stderr, catgets(slapdcat, 1, 84, "ber_get_next: tag 0x%1$lx len %2$ld contents:\n"), - tag, ber->ber_len ); - if ( lber_debug > 1 ) - ber_dump( ber, 1 ); - } -#endif - - *len = ber->ber_len; - ber->ber_rwptr = NULL; - return( ber->ber_tag ); -}
--- a/usr/src/lib/libldap4/common/Version.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1991 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. - */ - -static char Version[] = " libldap.a v%VERSION% (%WHEN%)\n\t%WHOANDWHERE%\n";
--- a/usr/src/lib/libldap4/common/abandon.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,267 +0,0 @@ - -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * abandon.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#endif /* DOS */ - -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifdef NEEDPROTOS -static int do_abandon( LDAP *ld, int origid, int msgid, LDAPControl **serverctrls ); -#else /* NEEDPROTOS */ -static int do_abandon(); -#endif /* NEEDPROTOS */ - -BerElement * ldap_build_abandon_req( LDAP *ld, int msgid, LDAPControl ** serverctrls) -{ - BerElement *ber; - int rc; - - /* create a message to send */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - rc = -1; - ld->ld_errno = LDAP_NO_MEMORY; - return (NULLBER); - } -#ifdef CLDAP - if ( ld->ld_sb.sb_naddr > 0 ) { - rc = ber_printf( ber, "{isti", - ++ld->ld_msgid, ld->ld_cldapdn, - LDAP_REQ_ABANDON, msgid ); - } else { -#endif /* CLDAP */ - rc = ber_printf( ber, "{iti", ++ld->ld_msgid, - LDAP_REQ_ABANDON, msgid ); -#ifdef CLDAP - } -#endif /* CLDAP */ - - if ( rc == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return (NULLBER); - } - /* LDAPv3 */ - /* Code controls if any */ - if (serverctrls && serverctrls[0]) { - if (ldap_controls_code(ber, serverctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - return( NULLBER ); - } - } else if (ld->ld_srvctrls && ld->ld_srvctrls[0]) { - /* Otherwise, is there any global server ctrls ? */ - if (ldap_controls_code(ber, ld->ld_srvctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - return( NULLBER ); - } - } - - if ( ber_printf( ber, "}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - return (ber); -} - - -/* - * ldap_abandon - perform an ldap (and X.500) abandon operation. Parameters: - * - * ld LDAP descriptor - * msgid The message id of the operation to abandon - * - * ldap_abandon returns 0 if everything went ok, -1 otherwise. - * - * Example: - * ldap_abandon( ld, msgid ); - */ -int -ldap_abandon( LDAP *ld, int msgid ) -{ - int rv; - -#ifdef _REENTRANT - LOCK_LDAP( ld ); -#endif - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 85, "ldap_abandon %d\n"), msgid, 0, 0 ); - - rv = do_abandon( ld, msgid, msgid , NULL); -#ifdef _REENTRANT - UNLOCK_LDAP( ld ); -#endif - return (rv); -} - -/* ldapv3 API extensions */ - -int ldap_abandon_ext(LDAP *ld, int msgid, LDAPControl **serverctrls, LDAPControl **clientctrls) -{ - int rv; - -#ifdef _REENTRANT - LOCK_LDAP( ld ); -#endif - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 85, "ldap_abandon %d\n"), msgid, 0, 0 ); - - rv = do_abandon( ld, msgid, msgid , NULL); - if (rv == -1) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS) - rv = LDAP_OTHER; -#ifdef _REENTRANT - UNLOCK_LDAP( ld ); -#endif - return (rv); - } -#ifdef _REENTRANT - UNLOCK_LDAP( ld ); -#endif - return (LDAP_SUCCESS); -} - - -static int -do_abandon( LDAP *ld, int origid, int msgid , LDAPControl **serverctrls) -{ - BerElement *ber; - int i, err, sendabandon; - Sockbuf *sb; -#ifdef LDAP_REFERRALS - LDAPRequest *lr; -#endif /* LDAP_REFERRALS */ - - /* - * An abandon request looks like this: - * AbandonRequest ::= MessageID - */ - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 86, "do_abandon origid %1$d, msgid %2$d\n"), - origid, msgid, 0 ); - - sendabandon = 1; - -#ifdef LDAP_REFERRALS - /* find the request that we are abandoning */ - for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) { - if ( lr->lr_msgid == msgid ) { /* this message */ - break; - } - if ( lr->lr_origid == msgid ) { /* child: abandon it */ - do_abandon( ld, msgid, lr->lr_msgid , serverctrls); - } - } - - if ( lr != NULL ) { - if ( origid == msgid && lr->lr_parent != NULL ) { - /* don't let caller abandon child requests! */ - ld->ld_errno = LDAP_PARAM_ERROR; - return( -1 ); - } - if ( lr->lr_status != LDAP_REQST_INPROGRESS ) { - /* no need to send abandon message */ - sendabandon = 0; - } - } -#endif /* LDAP_REFERRALS */ - - if ( ldap_msgdelete( ld, msgid ) == 0 ) { - ld->ld_errno = LDAP_SUCCESS; - return( 0 ); - } - - err = 0; - if ( sendabandon ) { - if ((ber = ldap_build_abandon_req(ld, msgid, serverctrls)) == NULLBER){ - return (-1); - } - -#ifdef LDAP_REFERRALS - if ( lr != NULL ) { - sb = lr->lr_conn->lconn_sb; - } else { - sb = &ld->ld_sb; - } -#else /* LDAP_REFERRALS */ - sb = &ld->ld_sb; -#endif /* LDAP_REFERRALS */ - if ( ber_flush( sb, ber, 1 ) != 0 ) { - ld->ld_errno = LDAP_SERVER_DOWN; - err = -1; - } else { - err = 0; - } - } -#ifdef LDAP_REFERRALS - if ( lr != NULL ) { - if ( sendabandon ) { - free_connection( ld, lr->lr_conn, 0, 1 ); - } - if ( origid == msgid ) { - free_request( ld, lr ); - } - } -#endif /* LDAP_REFERRALS */ - - - if ( ld->ld_abandoned == NULL ) { - if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) )) - == NULL ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( -1 ); - } - i = 0; - } else { - for ( i = 0; ld->ld_abandoned[i] != -1; i++ ) - ; /* NULL */ - if ( (ld->ld_abandoned = (int *) realloc( (char *) - ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( -1 ); - } - } - ld->ld_abandoned[i] = msgid; - ld->ld_abandoned[i + 1] = -1; - - if ( err != -1 ) { - ld->ld_errno = LDAP_SUCCESS; - } - return( err ); -} -
--- a/usr/src/lib/libldap4/common/add.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,270 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * add.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include "macos.h" -#endif /* MACOS */ - -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#endif /* DOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif /* !MACOS && !DOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - - -BerElement * ldap_build_add_req(LDAP *ld, char *dn, LDAPMod **attrs, - LDAPControl ** serverctrls) -{ - BerElement * ber; - int rc, i; - - /* - * An add request looks like this: - * AddRequest ::= [APPLICATION 8] SEQUENCE { - * entry DistinguishedName, - * attrs SEQUENCE OF SEQUENCE { - * type AttributeType, - * values SET OF AttributeValue - * } - * } - */ - - /* create a message to send */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( NULLBER ); - } - - if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_ADD, dn ) - == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - /* for each attribute in the entry... */ - for ( i = 0; attrs[i] != NULL; i++ ) { - if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) { - rc = ber_printf( ber, "{s[V]}", attrs[i]->mod_type, - attrs[i]->mod_values ); - } else { - rc = ber_printf( ber, "{s[v]}", attrs[i]->mod_type, - attrs[i]->mod_values ); - } - if ( rc == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return(NULLBER); - } - } - - if ( ber_printf( ber, "}}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - -/* LDAPv3 */ - /* Code controls if any */ - if (serverctrls && serverctrls[0]) { - if (ldap_controls_code(ber, serverctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } else if (ld->ld_srvctrls && ld->ld_srvctrls[0]) { - /* Otherwise, is there any global server ctrls ? */ - if (ldap_controls_code(ber, ld->ld_srvctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } - - if ( ber_printf( ber, "}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - return (ber); -} - - -/* - * ldap_add - initiate an ldap (and X.500) add operation. Parameters: - * - * ld LDAP descriptor - * dn DN of the entry to add - * mods List of attributes for the entry. This is a null- - * terminated array of pointers to LDAPMod structures. - * only the type and values in the structures need be - * filled in. - * - * Example: - * LDAPMod *attrs[] = { - * { 0, "cn", { "babs jensen", "babs", 0 } }, - * { 0, "sn", { "jensen", 0 } }, - * { 0, "objectClass", { "person", 0 } }, - * 0 - * } - * msgid = ldap_add( ld, dn, attrs ); - */ -int ldap_add( LDAP *ld, char *dn, LDAPMod **attrs ) -{ - BerElement *ber; - int rv; - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 87, "ldap_add\n"), 0, 0, 0 ); - - if ((ber = ldap_build_add_req(ld, dn, attrs, NULL)) == NULLBER){ -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (-1); - } - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_ADD, dn, ber ); -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); -} - -int -ldap_add_s( LDAP *ld, char *dn, LDAPMod **attrs ) -{ - int msgid; - LDAPMessage *res; - - if ( (msgid = ldap_add( ld, dn, attrs )) == -1 ) - return( ld->ld_errno ); - - if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) - return( ld->ld_errno ); - - return( ldap_result2error( ld, res, 1 ) ); -} - - -/* ldapv3 API extensions */ -/* - * ldap_add_ext - initiate an ldap (and X.500) add operation. Parameters: - * - * ld LDAP descriptor - * dn DN of the entry to add - * attrs List of attributes for the entry. This is a null- - * terminated array of pointers to LDAPMod structures. - * only the type and values in the structures need be - * filled in. - * serverctrls List of server controls. This is a null-terminated - * array of pointers to LDAPControl structures. - * clientctrls List of client controls. - * - * Example: - * LDAPMod *attrs[] = { - * { 0, "cn", { "babs jensen", "babs", 0 } }, - * { 0, "sn", { "jensen", 0 } }, - * { 0, "objectClass", { "person", 0 } }, - * 0 - * } - * - * retcode = ldap_add_ext( ld, dn, attrs, srvctrls, cltctrls, &msgid ); - */ - -int ldap_add_ext(LDAP *ld, char *dn, LDAPMod **attrs, - LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp) -{ - BerElement *ber; - int i, rc; - int rv; - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 87, "ldap_add\n"), 0, 0, 0 ); - - if ((ber = ldap_build_add_req(ld, dn, attrs, serverctrls)) == NULLBER){ - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS) - rv = LDAP_OTHER; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_ADD, dn, ber ); - if (rv == -1) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS){ - rv = LDAP_OTHER; - } - -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - - *msgidp = rv; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (LDAP_SUCCESS); -} - -int ldap_add_ext_s(LDAP *ld, char *dn, LDAPMod **attrs, - LDAPControl ** serverctrls, LDAPControl **clientctrls) -{ - int msgid; - int retcode = LDAP_SUCCESS; - LDAPMessage *res; - - if ((retcode = ldap_add_ext(ld, dn, attrs, serverctrls, clientctrls, &msgid)) != LDAP_SUCCESS) - return (retcode); - if (ldap_result(ld, msgid, 1, (struct timeval *)NULL, &res ) == -1) - return (ld->ld_errno ); - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - retcode = ldap_parse_result(ld, res, &ld->ld_errno, &ld->ld_matched, &ld->ld_error, - &ld->ld_referrals, &ld->ld_ret_ctrls, 1); - if (retcode == LDAP_SUCCESS) - retcode = ld->ld_errno; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (retcode); -}
--- a/usr/src/lib/libldap4/common/addentry.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * addentry.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" - -LDAPMessage * -ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e ) -{ - LDAPMessage *tmp, *prev = NULL; - - for ( tmp = *list; tmp != NULL && tmp != e; tmp = tmp->lm_chain ) - prev = tmp; - - if ( tmp == NULL ) - return( NULL ); - - if ( prev == NULL ) - *list = tmp->lm_chain; - else - prev->lm_chain = tmp->lm_chain; - tmp->lm_chain = NULL; - - return( tmp ); -} - -void -ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e ) -{ - e->lm_chain = *list; - *list = e; -}
--- a/usr/src/lib/libldap4/common/bind.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * bind.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#ifdef DOS -#include "msdos.h" -#ifdef NCSA -#include "externs.h" -#endif /* NCSA */ -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - - -/* - * ldap_bind - bind to the ldap server (and X.500). The dn and password - * of the entry to which to bind are supplied, along with the authentication - * method to use. The msgid of the bind request is returned on success, - * -1 if there's trouble. Note, the kerberos support assumes the user already - * has a valid tgt for now. ldap_result() should be called to find out the - * outcome of the bind request. - * - * Example: - * ldap_bind( ld, "cn=manager, o=university of michigan, c=us", "secret", - * LDAP_AUTH_SIMPLE ) - */ - -int -ldap_bind( LDAP *ld, char *dn, char *passwd, int authmethod ) -{ - /* - * The bind request looks like this: - * BindRequest ::= SEQUENCE { - * version INTEGER, - * name DistinguishedName, -- who - * authentication CHOICE { - * simple [0] OCTET STRING -- passwd -#ifdef KERBEROS - * krbv42ldap [1] OCTET STRING - * krbv42dsa [2] OCTET STRING -#endif - * } - * } - * all wrapped up in an LDAPMessage sequence. - */ - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 88, "ldap_bind\n"), 0, 0, 0 ); - - switch ( authmethod ) { - case LDAP_AUTH_SIMPLE: - return( ldap_simple_bind( ld, dn, passwd ) ); - -#ifdef KERBEROS - case LDAP_AUTH_KRBV41: - return( ldap_kerberos_bind1( ld, dn ) ); - - case LDAP_AUTH_KRBV42: - return( ldap_kerberos_bind2( ld, dn ) ); -#endif - - default: - ld->ld_errno = LDAP_AUTH_UNKNOWN; - return( -1 ); - } -} - -/* - * ldap_bind_s - bind to the ldap server (and X.500). The dn and password - * of the entry to which to bind are supplied, along with the authentication - * method to use. This routine just calls whichever bind routine is - * appropriate and returns the result of the bind (e.g. LDAP_SUCCESS or - * some other error indication). Note, the kerberos support assumes the - * user already has a valid tgt for now. - * - * Examples: - * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us", - * "secret", LDAP_AUTH_SIMPLE ) - * ldap_bind_s( ld, "cn=manager, o=university of michigan, c=us", - * NULL, LDAP_AUTH_KRBV4 ) - */ -int -ldap_bind_s( LDAP *ld, char *dn, char *passwd, int authmethod ) -{ - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 89, "ldap_bind_s\n"), 0, 0, 0 ); - - switch ( authmethod ) { - case LDAP_AUTH_SIMPLE: - return( ldap_simple_bind_s( ld, dn, passwd ) ); - -#ifdef KERBEROS - case LDAP_AUTH_KRBV4: - return( ldap_kerberos_bind_s( ld, dn ) ); - - case LDAP_AUTH_KRBV41: - return( ldap_kerberos_bind1_s( ld, dn ) ); - - case LDAP_AUTH_KRBV42: - return( ldap_kerberos_bind2_s( ld, dn ) ); -#endif - - default: - return( ld->ld_errno = LDAP_AUTH_UNKNOWN ); - } -} - - -void -ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_FUNCTION *rebindproc, void *extra_arg ) -{ -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - ld->ld_rebindproc = rebindproc; - ld->ld_rebind_extra_arg = extra_arg; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif -}
--- a/usr/src/lib/libldap4/common/cache.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,714 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * Copyright (c) 1993 The Regents of the University of Michigan. - * All rights reserved. - * - * cache.c - local caching support for LDAP - */ - -#ifndef NO_CACHE - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 The Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> -#ifdef MACOS -#include <stdlib.h> -#include <time.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#ifdef NCSA -#include "externs.h" -#endif /* NCSA */ -#ifdef WINSOCK -#include <time.h> -#endif /* WINSOCK */ -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifdef NEEDPROTOS -static int cache_hash( BerElement *ber ); -static LDAPMessage *msg_dup( LDAPMessage *msg ); -static int request_cmp( BerElement *req1, BerElement *req2 ); -static int chain_contains_dn( LDAPMessage *msg, char *dn ); -static ssize_t msg_size( LDAPMessage *msg ); -static void check_cache_memused( LDAPCache *lc ); -static void uncache_entry_or_req( LDAP *ld, char *dn, int msgid ); -#else /* NEEDPROTOS */ -static int cache_hash(); -static LDAPMessage *msg_dup(); -static int request_cmp(); -static int chain_contains_dn(); -static ssize_t msg_size(); -static void check_cache_memused(); -static void uncache_entry_or_req(); -#endif /* NEEDPROTOS */ - - -int -ldap_enable_cache( LDAP *ld, time_t timeout, ssize_t maxmem ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - if ( ld->ld_cache == NULLLDCACHE ) { - if (( ld->ld_cache = (LDAPCache *)malloc( sizeof( LDAPCache ))) - == NULLLDCACHE ) { - ld->ld_errno = LDAP_NO_MEMORY; -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( -1 ); - } - (void) memset( ld->ld_cache, 0, sizeof( LDAPCache )); - ld->ld_cache->lc_memused = sizeof( LDAPCache ); - } - - ld->ld_cache->lc_timeout = timeout; - ld->ld_cache->lc_maxmem = maxmem; - check_cache_memused( ld->ld_cache ); - ld->ld_cache->lc_enabled = 1; -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( 0 ); -} - - -void -ldap_disable_cache( LDAP *ld ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - if ( ld->ld_cache != NULLLDCACHE ) { - ld->ld_cache->lc_enabled = 0; - } -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - - -void -ldap_set_cache_options( LDAP *ld, unsigned int opts ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - if ( ld->ld_cache != NULLLDCACHE ) { - ld->ld_cache->lc_options = opts; - } -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -void -ldap_destroy_cache( LDAP *ld ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - if ( ld->ld_cache != NULLLDCACHE ) { - ldap_flush_cache( ld ); - free( (char *)ld->ld_cache ); - ld->ld_cache = NULLLDCACHE; - } -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -void -ldap_flush_cache( LDAP *ld ) -{ - int i; - LDAPMessage *m, *next; - -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 90, "ldap_flush_cache\n"), 0, 0, 0 ); - - if ( ld->ld_cache != NULLLDCACHE ) { - /* delete all requests in the queue */ - for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) { - next = m->lm_next; - ldap_msgfree( m ); - } - ld->ld_cache->lc_requests = NULLMSG; - - /* delete all messages in the cache */ - for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { - for ( m = ld->ld_cache->lc_buckets[ i ]; - m != NULLMSG; m = next ) { - next = m->lm_next; - ldap_msgfree( m ); - } - ld->ld_cache->lc_buckets[ i ] = NULLMSG; - } - ld->ld_cache->lc_memused = sizeof( LDAPCache ); - } -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -void -ldap_uncache_request( LDAP *ld, int msgid ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 91, "ldap_uncache_request %1$d ld_cache %2$x\n"), - msgid, ld->ld_cache, 0 ); - - uncache_entry_or_req( ld, NULL, msgid ); -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -void -ldap_uncache_entry( LDAP *ld, char *dn ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 92, "ldap_uncache_entry %1$s ld_cache %2$x\n"), - dn, ld->ld_cache, 0 ); - - uncache_entry_or_req( ld, dn, 0 ); -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -static void -uncache_entry_or_req( LDAP *ld, - char *dn, /* if non-NULL, uncache entry */ - int msgid ) /* request to uncache (if dn == NULL) */ -{ - int i; - LDAPMessage *m, *prev, *next; - - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 93, "ldap_uncache_entry_or_req dn %1$s msgid %2$d ld_cache %3$x\n"), - dn, msgid, ld->ld_cache ); - - if ( ld->ld_cache == NULLLDCACHE ) { - return; - } - - /* first check the request queue */ - prev = NULLMSG; - for ( m = ld->ld_cache->lc_requests; m != NULLMSG; m = next ) { - next = m->lm_next; - if (( dn != NULL && chain_contains_dn( m, dn )) || - ( dn == NULL && m->lm_msgid == msgid )) { - if ( prev == NULLMSG ) { - ld->ld_cache->lc_requests = next; - } else { - prev->lm_next = next; - } - ld->ld_cache->lc_memused -= msg_size( m ); - ldap_msgfree( m ); - } else { - prev = m; - } - } - - /* now check the rest of the cache */ - for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { - prev = NULLMSG; - for ( m = ld->ld_cache->lc_buckets[ i ]; m != NULLMSG; - m = next ) { - next = m->lm_next; - if (( dn != NULL && chain_contains_dn( m, dn )) || - ( dn == NULL && m->lm_msgid == msgid )) { - if ( prev == NULLMSG ) { - ld->ld_cache->lc_buckets[ i ] = next; - } else { - prev->lm_next = next; - } - ld->ld_cache->lc_memused -= msg_size( m ); - ldap_msgfree( m ); - } else { - prev = m; - } - } - } -} - - -void -add_request_to_cache( LDAP *ld, unsigned int msgtype, BerElement *request ) -{ - LDAPMessage *new; - size_t len; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 94, "add_request_to_cache\n"), 0, 0, 0 ); - - ld->ld_errno = LDAP_SUCCESS; - if ( ld->ld_cache == NULLLDCACHE || - ( ld->ld_cache->lc_enabled == 0 )) { - return; - } - - if (( new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) )) - != NULL ) { - if (( new->lm_ber = alloc_ber_with_options( ld )) == NULLBER ) { - free( (char *)new ); - return; - } - len = request->ber_ptr - request->ber_buf; - if (( new->lm_ber->ber_buf = (char *) malloc( len )) - == NULL ) { - ber_free( new->lm_ber, 0 ); - free( (char *)new ); - ld->ld_errno = LDAP_NO_MEMORY; - return; - } - SAFEMEMCPY( new->lm_ber->ber_buf, request->ber_buf, len ); - new->lm_ber->ber_ptr = new->lm_ber->ber_buf; - new->lm_ber->ber_end = new->lm_ber->ber_buf + len; - new->lm_msgid = ld->ld_msgid; - new->lm_msgtype = (int) msgtype;; - new->lm_next = ld->ld_cache->lc_requests; - ld->ld_cache->lc_requests = new; - } else { - ld->ld_errno = LDAP_NO_MEMORY; - } -} - - -void -add_result_to_cache( LDAP *ld, LDAPMessage *result ) -{ - LDAPMessage *m, **mp, *req, *new, *prev; - int err, keep; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 95, "add_result_to_cache: id %1$d, type %2$d\n"), - result->lm_msgid, result->lm_msgtype, 0 ); - - if ( ld->ld_cache == NULLLDCACHE || - ( ld->ld_cache->lc_enabled == 0 )) { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 96, "artc: cache disabled\n"), 0, 0, 0 ); - return; - } - - if ( result->lm_msgtype != LDAP_RES_SEARCH_ENTRY && - result->lm_msgtype != LDAP_RES_SEARCH_RESULT && - result->lm_msgtype != LDAP_RES_SEARCH_REFERENCE && - result->lm_msgtype != LDAP_RES_COMPARE ) { - /* - * only cache search and compare operations - */ - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 97, "artc: only caching search & compare operations\n"), 0, 0, 0 ); - return; - } - - /* - * if corresponding request is in the lc_requests list, add this - * result to it. if this result completes the results for the - * request, add the request/result chain to the cache proper. - */ - prev = NULLMSG; - for ( m = ld->ld_cache->lc_requests; m != NULL; m = m->lm_next ) { - if ( m->lm_msgid == result->lm_msgid ) { - break; - } - prev = m; - } - - if ( m != NULLMSG ) { /* found request; add to end of chain */ - req = m; - for ( ; m->lm_chain != NULLMSG; m = m->lm_chain ) - ; - if (( new = msg_dup( result )) != NULLMSG ) { - new->lm_chain = NULLMSG; - m->lm_chain = new; - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 98, "artc: result added to cache request chain\n"), - 0, 0, 0 ); - } - if ( result->lm_msgtype == LDAP_RES_SEARCH_RESULT || - result->lm_msgtype == LDAP_RES_COMPARE ) { - /* - * this result completes the chain of results - * add to cache proper if appropriate - */ - keep = 0; /* pessimistic */ - err = ldap_result2error( ld, result, 0 ); - if ( err == LDAP_SUCCESS || - ( result->lm_msgtype == LDAP_RES_COMPARE && - ( err == LDAP_COMPARE_FALSE || - err == LDAP_COMPARE_TRUE || - err == LDAP_NO_SUCH_ATTRIBUTE ))) { - keep = 1; - } - - if ( ld->ld_cache->lc_options == 0 ) { - if ( err == LDAP_SIZELIMIT_EXCEEDED ) { - keep = 1; - } - } else if (( ld->ld_cache->lc_options & - LDAP_CACHE_OPT_CACHEALLERRS ) != 0 ) { - keep = 1; - } - - if ( prev == NULLMSG ) { - ld->ld_cache->lc_requests = req->lm_next; - } else { - prev->lm_next = req->lm_next; - } - - if ( !keep ) { - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 99, "artc: not caching result with error %d\n"), - err, 0, 0 ); - ldap_msgfree( req ); - } else { - mp = &ld->ld_cache->lc_buckets[ - cache_hash( req->lm_ber ) ]; - req->lm_next = *mp; - *mp = req; - req->lm_time = time( NULL ); - ld->ld_cache->lc_memused += msg_size( req ); - check_cache_memused( ld->ld_cache ); - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 100, "artc: cached result with error %d\n"), - err, 0, 0 ); - } - } - } else { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 101, "artc: msgid not in request list\n"), - 0, 0, 0 ); - } -} - - -/* - * look in the cache for this request - * return 0 if found, -1 if not - * if found, the corresponding result messages are added to the incoming - * queue with the correct (new) msgid so that subsequent ldap_result calls - * will find them. - */ -int -check_cache( LDAP *ld, unsigned int msgtype, BerElement *request ) -{ - LDAPMessage *m, *new, *prev, *next; - BerElement reqber; - int first, hash; - unsigned long validtime; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 102, "check_cache\n"), 0, 0, 0 ); - - if ( ld->ld_cache == NULLLDCACHE || - ( ld->ld_cache->lc_enabled == 0 )) { - return( -1 ); - } - - reqber.ber_buf = reqber.ber_ptr = request->ber_buf; - reqber.ber_end = request->ber_ptr; - - validtime = time( NULL ) - ld->ld_cache->lc_timeout; - - prev = NULLMSG; - hash = cache_hash( &reqber ); - for ( m = ld->ld_cache->lc_buckets[ hash ]; m != NULLMSG; m = next ) { - Debug( LDAP_DEBUG_TRACE,catgets(slapdcat, 1, 103, "cc: examining id %1$d,type %2$d\n"), - m->lm_msgid, m->lm_msgtype, 0 ); - if ( m->lm_time < validtime ) { - /* delete expired message */ - next = m->lm_next; - if ( prev == NULL ) { - ld->ld_cache->lc_buckets[ hash ] = next; - } else { - prev->lm_next = next; - } - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 104, "cc: expired id %d\n"), - m->lm_msgid, 0, 0 ); - ld->ld_cache->lc_memused -= msg_size( m ); - ldap_msgfree( m ); - } else { - if ( m->lm_msgtype == msgtype && - request_cmp( m->lm_ber, &reqber ) == 0 ) { - break; - } - next = m->lm_next; - prev = m; - } - } - - if ( m == NULLMSG ) { - return( -1 ); - } - - /* - * add duplicates of responses to incoming queue - */ - first = 1; -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_RESPONSE(ld); -#endif - for ( m = m->lm_chain; m != NULLMSG; m = m->lm_chain ) { - if (( new = msg_dup( m )) == NULLMSG ) { -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_RESPONSE(ld); -#endif - return( -1 ); - } - - new->lm_msgid = ld->ld_msgid; - new->lm_chain = NULLMSG; - if ( first ) { - new->lm_next = ld->ld_responses; - ld->ld_responses = new; - first = 0; - } else { - prev->lm_chain = new; - } - prev = new; - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 105, "cc: added type %d\n"), - new->lm_msgtype, 0, 0 ); - } - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 106, "cc: result returned from cache\n"), 0, 0, 0 ); -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_RESPONSE(ld); -#endif - return( 0 ); -} - - -static int -cache_hash( BerElement *ber ) -{ - BerElement bercpy; - unsigned int len; - - /* - * just take the length of the packet and mod with # of buckets - */ - bercpy = *ber; - if ( ber_skip_tag( &bercpy, &len ) == LBER_ERROR - || ber_scanf( &bercpy, "x" ) == LBER_ERROR ) { - len = 0; /* punt: just return zero */ - } else { - len = (int) ( bercpy.ber_end - bercpy.ber_ptr ); - } - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 107, "cache_hash: len is %1$ld, returning %2$ld\n"), - len, len % LDAP_CACHE_BUCKETS, 0 ); - return ( len % LDAP_CACHE_BUCKETS ); -} - - -static LDAPMessage * -msg_dup( LDAPMessage *msg ) -{ - LDAPMessage *new; - size_t len; - - if (( new = (LDAPMessage *)malloc( sizeof(LDAPMessage))) != NULL ) { - *new = *msg; /* struct copy */ - if (( new->lm_ber = ber_dup( msg->lm_ber )) == NULLBER ) { - free( (char *)new ); - return( NULLMSG ); - } - len = msg->lm_ber->ber_end - msg->lm_ber->ber_buf; - if (( new->lm_ber->ber_buf = (char *) malloc( len )) == NULL ) { - ber_free( new->lm_ber, 0 ); - free( (char *)new ); - return( NULLMSG ); - } - SAFEMEMCPY( new->lm_ber->ber_buf, msg->lm_ber->ber_buf, len ); - - new->lm_ber->ber_ptr = new->lm_ber->ber_buf + - ( msg->lm_ber->ber_ptr - msg->lm_ber->ber_buf ); - new->lm_ber->ber_end = new->lm_ber->ber_buf + len; - } - - return( new ); -} - - -static int -request_cmp( BerElement *req1, BerElement *req2 ) -{ - unsigned int len; - size_t slen; - BerElement r1, r2; - - r1 = *req1; /* struct copies */ - r2 = *req2; - - /* - * skip the enclosing tags (sequence markers) and the msg ids - */ - if ( ber_skip_tag( &r1, &len ) == LBER_ERROR || ber_scanf( &r1, "x" ) - == LBER_ERROR ) { - return( -1 ); - } - if ( ber_skip_tag( &r2, &len ) == LBER_ERROR || ber_scanf( &r2, "x" ) - == LBER_ERROR ) { - return( -1 ); - } - - /* - * check remaining length and bytes if necessary - */ - if (( slen = r1.ber_end - r1.ber_ptr ) != r2.ber_end - r2.ber_ptr ) { - return( -1 ); /* different lengths */ - } - return( memcmp( r1.ber_ptr, r2.ber_ptr, slen )); -} - - -static int -chain_contains_dn( LDAPMessage *msg, char *dn ) -{ - LDAPMessage *m; - BerElement ber; - int msgid; - char *s; - int rc; - - - /* - * first check the base or dn of the request - */ - ber = *msg->lm_ber; /* struct copy */ - if ( ber_scanf( &ber, "{i{a", &msgid, &s ) != LBER_ERROR ) { - rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0; - free( s ); - if ( rc != 0 ) { - return( rc ); - } - } - - if ( msg->lm_msgtype == LDAP_REQ_COMPARE ) { - return( 0 ); - } - - /* - * now check the dn of each search result - */ - rc = 0; - for ( m = msg->lm_chain; m != NULLMSG && rc == 0 ; m = m->lm_chain ) { - if ( m->lm_msgtype != LDAP_RES_SEARCH_ENTRY ) { - continue; - } - ber = *m->lm_ber; /* struct copy */ - if ( ber_scanf( &ber, "{a", &s ) != LBER_ERROR ) { - rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0; - free( s ); - } - } - - return( rc ); -} - - -static ssize_t -msg_size( LDAPMessage *msg ) -{ - LDAPMessage *m; - ssize_t size; - - size = 0; - for ( m = msg; m != NULLMSG; m = m->lm_chain ) { - size += sizeof( LDAPMessage ) + m->lm_ber->ber_end - - m->lm_ber->ber_buf; - } - - return( size ); -} - - -#define THRESHOLD_FACTOR 3 / 4 -#define SIZE_FACTOR 2 / 3 - -static void -check_cache_memused( LDAPCache *lc ) -{ -/* - * this routine is called to check if the cache is too big (lc_maxmem > - * minimum cache size and lc_memused > lc_maxmem). If too big, it reduces - * the cache size to < SIZE_FACTOR * lc_maxmem. The algorithm is as follows: - * remove_threshold = lc_timeout seconds; - * do { - * remove everything older than remove_threshold seconds; - * remove_threshold = remove_threshold * THRESHOLD_FACTOR; - * } while ( cache size is > SIZE_FACTOR * lc_maxmem ) - */ - int i; - unsigned long remove_threshold, validtime; - LDAPMessage *m, *prev, *next; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 108, "check_cache_memused: %1$ld bytes in use (%2$ld max)\n"), - lc->lc_memused, lc->lc_maxmem, 0 ); - - if ( lc->lc_maxmem <= sizeof( LDAPCache ) - || lc->lc_memused <= lc->lc_maxmem * SIZE_FACTOR ) { - return; - } - - remove_threshold = lc->lc_timeout; - while ( lc->lc_memused > lc->lc_maxmem * SIZE_FACTOR ) { - validtime = time( NULL ) - remove_threshold; - for ( i = 0; i < LDAP_CACHE_BUCKETS; ++i ) { - prev = NULLMSG; - for ( m = lc->lc_buckets[ i ]; m != NULLMSG; - m = next ) { - next = m->lm_next; - if ( m->lm_time < validtime ) { - if ( prev == NULLMSG ) { - lc->lc_buckets[ i ] = next; - } else { - prev->lm_next = next; - } - lc->lc_memused -= msg_size( m ); - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 109, "ccm: removed %d\n"), - m->lm_msgid, 0, 0 ); - ldap_msgfree( m ); - } else { - prev = m; - } - } - } - remove_threshold *= THRESHOLD_FACTOR; - } - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 110, "ccm: reduced usage to %ld bytes\n"), - lc->lc_memused, 0, 0 ); -} - -#endif /* !NO_CACHE */
--- a/usr/src/lib/libldap4/common/charset.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1869 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1995 Regents of the University of Michigan. - * All rights reserved. - * - * charset.c - */ - -#if defined( DOS ) || defined( _WIN32 ) -/* - * This MUST precede "#ifdef STR_TRANSLATION" - * because STR_TRANSLATION and friends are defined in msdos.h. - */ -#include "msdos.h" -#endif /* DOS */ - -#ifdef STR_TRANSLATION - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1995 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#endif /* MACOS */ - -#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 ) && !defined(VMS) -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/param.h> -#endif -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - - -void -ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc, - BERTranslateProc decode_proc ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - ld->ld_lber_encode_translate_proc = encode_proc; - ld->ld_lber_decode_translate_proc = decode_proc; -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -void -ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable ) -{ - char *optionsp; - -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions : - &entry->lm_ber->ber_options; - - if ( enable ) { - *optionsp |= LBER_TRANSLATE_STRINGS; - } else { - *optionsp &= ~LBER_TRANSLATE_STRINGS; - } -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -int -ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned int *lenp, - int free_input ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - BERTranslateProc decode_proc; - - LOCK_LDAP(ld); -#endif - if ( ld->ld_lber_decode_translate_proc == NULL ) { -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( LDAP_SUCCESS ); - } -#if defined( SUN ) && defined( _REENTRANT ) - decode_proc = ld->ld_lber_decode_translate_proc; - UNLOCK_LDAP(ld); - - return( (*decode_proc)( bufp, lenp, free_input )); -#else - return( (*ld->ld_lber_decode_translate_proc)( bufp, lenp, free_input )); -#endif -} - - -int -ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned int *lenp, - int free_input ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - BERTranslateProc encode_proc; - - LOCK_LDAP(ld); -#endif - if ( ld->ld_lber_encode_translate_proc == NULL ) { -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( LDAP_SUCCESS ); - } - -#if defined( SUN ) && defined( _REENTRANT ) - encode_proc = ld->ld_lber_encode_translate_proc; - UNLOCK_LDAP(ld); - return( (*encode_proc)( bufp, lenp, free_input )); -#else - return( (*ld->ld_lber_encode_translate_proc)( bufp, lenp, free_input )); -#endif -} - - -/* - ** Character translation routine notes: - * - * On entry: bufp points to a "string" to be converted (not necessarily - * zero-terminated) and buflenp points to the length of the buffer. - * - * On exit: bufp should point to a malloc'd result. If free_input is - * non-zero then the original bufp will be freed. *buflenp should be - * set to the new length. Zero bytes in the input buffer must be left - * as zero bytes. - * - * Return values: any ldap error code (LDAP_SUCCESS if all goes well). - */ - - -#ifdef LDAP_CHARSET_8859 - -#if LDAP_CHARSET_8859 == 88591 -#define ISO_8859 1 -#elif LDAP_CHARSET_8859 == 88592 -#define ISO_8859 2 -#elif LDAP_CHARSET_8859 == 88593 -#define ISO_8859 3 -#elif LDAP_CHARSET_8859 == 88594 -#define ISO_8859 4 -#elif LDAP_CHARSET_8859 == 88595 -#define ISO_8859 5 -#elif LDAP_CHARSET_8859 == 88596 -#define ISO_8859 6 -#elif LDAP_CHARSET_8859 == 88597 -#define ISO_8859 7 -#elif LDAP_CHARSET_8859 == 88598 -#define ISO_8859 8 -#elif LDAP_CHARSET_8859 == 88599 -#define ISO_8859 9 -#elif LDAP_CHARSET_8859 == 885910 -#define ISO_8859 10 -#else -#define ISO_8859 0 -#endif - -/* - * the following ISO_8859 to/afrom T.61 character set translation code is - * based on the code found in Enrique Silvestre Mora's iso-t61.c, found - * as part of this package: - * ftp://pereiii.uji.es/pub/uji-ftp/unix/ldap/iso-t61.translation.tar.Z - * Enrique is now (10/95) at this address: enrique.silvestre@uv.es - * - * changes made by mcs@umich.edu 12 October 1995: - * Change calling conventions of iso8859_t61() and t61_iso8859() to - * match libldap conventions; rename to ldap_8859_to_t61() and - * ldap_t61_to_8859(). - * Change conversion routines to deal with non-zero terminated strings. - * ANSI-ize functions and include prototypes. - */ - -/* iso-t61.c - ISO-T61 translation routines (version: 0.2.1, July-1994) */ -/* - * Copyright (c) 1994 Enrique Silvestre Mora, Universitat Jaume I, Spain. - * 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 Universitat Jaume I. 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 <stdio.h> -#include <stdlib.h> -#include <string.h> - -/* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */ -/* #define ISO_8859 1 */ - -#ifndef ISO_8859 -# define ISO_8859 0 -#endif - -typedef unsigned char Byte; -typedef struct { Byte a, b; } Couple; - -#ifdef NEEDPROTOS -static Byte *c_to_hh( Byte *o, Byte c ); -static Byte *c_to_cc( Byte *o, Couple *cc, Byte c ); -static int hh_to_c( Byte *h ); -static Byte *cc_to_t61( Byte *o, Byte *s ); -#else /* NEEDPROTOS */ -static Byte *c_to_hh(); -static Byte *c_to_cc(); -static int hh_to_c(); -static Byte *cc_to_t61(); -#endif /* NEEDPROTOS */ - -/* - Character choosed as base in diacritics alone: NO-BREAK SPACE. - (The standard say it must be a blank space, 0x20.) -*/ -#define ALONE 0xA0 - -static Couple diacritic[16] = { -#if (ISO_8859 == 1) || (ISO_8859 == 9) - {0,0}, {'`',0}, {0xb4,0}, {'^',0}, - {'~',0}, {0xaf,0}, {'(',ALONE}, {'.',ALONE}, - {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0}, - {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE}, -#elif (ISO_8859 == 2) - {0,0}, {'`',0}, {0xb4,0}, {'^',0}, - {'~',0}, {'-',ALONE}, {0xa2,0}, {0xff,0}, - {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0}, - {0,0}, {0xbd,0}, {0xb2,0}, {0xb7,0} -#elif (ISO_8859 == 3) - {0,0}, {'`',0}, {0xb4,0}, {'^',0}, - {'~',0}, {'-',ALONE}, {0xa2,0}, {0xff,0}, - {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0}, - {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE} -#elif (ISO_8859 == 4) - {0,0}, {'`',0}, {0xb4,0}, {'^',0}, - {'~',0}, {0xaf,0}, {'(',ALONE}, {0xff,0}, - {0xa8,0}, {0,0}, {'0',ALONE}, {0xb8,0}, - {0,0}, {'"',ALONE}, {0xb2,0}, {0xb7,0} -#else - {0,0}, {'`',0}, {'\'',ALONE}, {'^',0}, - {'~',0}, {'-',ALONE}, {'(',ALONE}, {'.',ALONE}, - {':',ALONE}, {0,0}, {'0',ALONE}, {',',ALONE}, - {0,0}, {'"',ALONE}, {';',ALONE}, {'<',ALONE} -#endif -}; - -/* - --- T.61 (T.51) letters with diacritics: conversion to ISO 8859-n ----- - A, C, D, E, G, H, I, J, K, - L, N, O, R, S, T, U, W, Y, Z. - ----------------------------------------------------------------------- -*/ -static int letter_w_diacritic[16][38] = { -#if (ISO_8859 == 1) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc0,0, 0, 0xc8,0, 0, 0xcc,0, 0, - 0, 0, 0xd2,0, 0, 0, 0xd9,0, 0, 0, - 0xe0,0, 0, 0xe8,0, 0, 0xec,0, 0, - 0, 0, 0xf2,0, 0, 0, 0xf9,0, 0, 0, - 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0, - -1, -1, 0xd3,-1, -1, 0, 0xda,0, 0xdd,-1, - 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0, - -1, -1, 0xf3,-1, -1, 0, 0xfa,0, 0xfd,-1, - 0xc2,-1, 0, 0xca,-1, -1, 0xce,-1, 0, - 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0, - 0xe2,-1, 0, 0xea,-1, -1, 0xee,-1, 0, - 0, 0, 0xf4,0, -1, 0, 0xfb,-1, -1, 0, - 0xc3,0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xd1,0xd5,0, 0, 0, -1, 0, 0, 0, - 0xe3,0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xf1,0xf5,0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, -1, -1, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0, -1, 0, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0xc4,0, 0, 0xcb,0, 0, 0xcf,0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, 0xef,0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, 0xff,0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xe5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, 0xc7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, - 0, 0xe7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1 -#elif (ISO_8859 == 2) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xc1,0xc6,0, 0xc9,0, 0, 0xcd,0, 0, - 0xc5,0xd1,0xd3,0xc0,0xa6,0, 0xda,0, 0xdd,0xac, - 0xe1,0xe6,0, 0xe9,0, 0, 0xed,0, 0, - 0xe5,0xf1,0xf3,0xe0,0xb6,0, 0xfa,0, 0xfd,0xbc, - 0xc2,-1, 0, -1, -1, -1, 0xce,-1, 0, - 0, 0, 0xd4,0, -1, 0, -1, -1, -1, 0, - 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0, - 0, 0, 0xf4,0, -1, 0, -1, -1, -1, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, -1, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, -1, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xc3,0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xe3,0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, -1, -1, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xaf, - 0, -1, 0, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xbf, - 0xc4,0, 0, 0xcb,0, 0, -1, 0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, -1, 0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, -1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0xd9,0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0xf9,0, 0, 0, - 0, 0xc7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xaa,0xde,0, 0, 0, 0, - 0, 0xe7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xba,0xfe,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0xd5,0, 0, 0, 0xdb,0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0xf5,0, 0, 0, 0xfb,0, 0, 0, - 0xa1,0, 0, 0xca,0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xb1,0, 0, 0xea,0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, 0xc8,0xcf,0xcc,0, 0, 0, 0, 0, - 0xa5,0xd2,0, 0xd8,0xa9,0xab,0, 0, 0, 0xae, - 0, 0xe8,0xef,0xec,0, 0, 0, 0, 0, - 0xb5,0xf2,0, 0xf8,0xb9,0xbb,0, 0, 0, 0xbe -#elif (ISO_8859 == 3) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc0,0, 0, 0xc8,0, 0, 0xcc,0, 0, - 0, 0, 0xd2,0, 0, 0, 0xd9,0, 0, 0, - 0xe0,0, 0, 0xe8,0, 0, 0xec,0, 0, - 0, 0, 0xf2,0, 0, 0, 0xf9,0, 0, 0, - 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0, - -1, -1, 0xd3,-1, -1, 0, 0xda,0, -1, -1, - 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0, - -1, -1, 0xf3,-1, -1, 0, 0xfa,0, -1, -1, - 0xc2,0xc6,0, 0xca,0xd8,0xa6,0xce,0xac,0, - 0, 0, 0xd4,0, 0xde,0, 0xdb,-1, -1, 0, - 0xe2,0xe6,0, 0xea,0xf8,0xb6,0xee,0xbc,0, - 0, 0, 0xf4,0, 0xfe,0, 0xfb,-1, -1, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xd1,-1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xf1,-1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0xab,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0xdd,0, 0, 0, - -1, 0, 0, 0, 0xbb,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0xfd,0, 0, 0, - 0, 0xc5,0, -1, 0xd5,0, 0xa9,0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xaf, - 0, 0xe5,0, -1, 0xf5,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xbf, - 0xc4,0, 0, 0xcb,0, 0, 0xcf,0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, 0xef,0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, -1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, 0xc7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xaa,-1, 0, 0, 0, 0, - 0, 0xe7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xba,-1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1 -#elif (ISO_8859 == 4) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0, - -1, -1, -1, -1, -1, 0, 0xda,0, -1, -1, - 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0, - -1, -1, -1, -1, -1, 0, 0xfa,0, -1, -1, - 0xc2,-1, 0, -1, -1, -1, 0xce,-1, 0, - 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0, - 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0, - 0, 0, 0xf4,0, -1, 0, 0xfb,-1, -1, 0, - 0xc3,0, 0, 0, 0, 0, 0xa5,0, 0, - 0, -1, 0xd5,0, 0, 0, 0xdd,0, 0, 0, - 0xe3,0, 0, 0, 0, 0, 0xb5,0, 0, - 0, -1, 0xf5,0, 0, 0, 0xfd,0, 0, 0, - 0xc0,0, 0, 0xaa,0, 0, 0xcf,0, 0, - 0, 0, 0xd2,0, 0, 0, 0xde,0, 0, 0, - 0xe0,0, 0, 0xba,0, 0, 0xef,0, 0, - 0, 0, 0xf2,0, 0, 0, 0xfe,0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, 0xcc,-1, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0, -1, 0, 0xec,-1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0xc4,0, 0, 0xcb,0, 0, -1, 0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, -1, 0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, -1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xe5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, 0, 0xab,0, 0, 0, 0xd3, - 0xa6,0xd1,0, 0xa3,-1, -1, 0, 0, 0, 0, - 0, -1, 0, 0, 0xbb,0, 0, 0, 0xf3, - 0xb6,0xf1,0, 0xb3,-1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xa1,0, 0, 0xca,0, 0, 0xc7,0, 0, - 0, 0, 0, 0, 0, 0, 0xd9,0, 0, 0, - 0xb1,0, 0, 0xea,0, 0, 0xe7,0, 0, - 0, 0, 0, 0, 0, 0, 0xf9,0, 0, 0, - 0, 0xc8,-1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, 0xa9,-1, 0, 0, 0, 0xae, - 0, 0xe8,-1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, 0xb9,-1, 0, 0, 0, 0xbe -#elif (ISO_8859 == 9) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc0,0, 0, 0xc8,0, 0, 0xcc,0, 0, - 0, 0, 0xd2,0, 0, 0, 0xd9,0, 0, 0, - 0xe0,0, 0, 0xe8,0, 0, -1, 0, 0, - 0, 0, 0xf2,0, 0, 0, 0xf9,0, 0, 0, - 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0, - -1, -1, 0xd3,-1, -1, 0, 0xda,0, -1, -1, - 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0, - -1, -1, 0xf3,-1, -1, 0, 0xfa,0, -1, -1, - 0xc2,-1, 0, 0xca,-1, -1, 0xce,-1, 0, - 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0, - 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0, - 0, 0, 0xf4,0, -1, 0, 0xfb,-1, -1, 0, - 0xc3,0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xd1,0xd5,0, 0, 0, -1, 0, 0, 0, - 0xe3,0, 0, 0, 0, 0, -1, 0, 0, - 0, 0xf1,0xf5,0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, 0xef,0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0xd0,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0xf0,0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, -1, -1, 0, 0xdd,0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0, -1, 0, 0xec,-1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0xc4,0, 0, 0xcb,0, 0, 0xcf,0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, -1, 0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, 0xff,0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xe5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, 0xc7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xde,-1, 0, 0, 0, 0, - 0, 0xe7,0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, 0xfe,-1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0xea,0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1 -#elif (ISO_8859 == 10) - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xc1,-1, 0, 0xc9,0, 0, 0xcd,0, 0, - -1, -1, 0xd3,-1, -1, 0, 0xda,0, 0xdd,-1, - 0xe1,-1, 0, 0xe9,0, 0, 0xed,0, 0, - -1, -1, 0xf3,-1, -1, 0, 0xfa,0, 0xfd,-1, - 0xc2,-1, 0, -1, -1, -1, 0xce,-1, 0, - 0, 0, 0xd4,0, -1, 0, 0xdb,-1, -1, 0, - 0xe2,-1, 0, -1, -1, -1, 0xee,-1, 0, - 0, 0, 0xf4,0, -1, 0, 0xfb,-1, -1, 0, - 0xc3,0, 0, 0, 0, 0, 0xa5,0, 0, - 0, -1, 0xd5,0, 0, 0, 0xd7,0, 0, 0, - 0xe3,0, 0, 0, 0, 0, 0xb5,0, 0, - 0, -1, 0xf5,0, 0, 0, 0xf7,0, 0, 0, - 0xc0,0, 0, 0xa2,0, 0, 0xa4,0, 0, - 0, 0, 0xd2,0, 0, 0, 0xae,0, 0, 0, - 0xe0,0, 0, 0xb2,0, 0, 0xb4,0, 0, - 0, 0, 0xf2,0, 0, 0, 0xbe,0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, 0xcc,-1, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0, -1, 0, 0xec,-1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0xc4,0, 0, 0xcb,0, 0, 0xcf,0, 0, - 0, 0, 0xd6,0, 0, 0, 0xdc,0, -1, 0, - 0xe4,0, 0, 0xeb,0, 0, 0xef,0, 0, - 0, 0, 0xf6,0, 0, 0, 0xfc,0, -1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xc5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0xe5,0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, 0, 0xa3,0, 0, 0, 0xa6, - 0xa8,0xd1,0, -1, -1, -1, 0, 0, 0, 0, - 0, -1, 0, 0, 0xb3,0, 0, 0, 0xb6, - 0xb8,0xf1,0, -1, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0xa1,0, 0, 0xca,0, 0, 0xc7,0, 0, - 0, 0, 0, 0, 0, 0, 0xd9,0, 0, 0, - 0xb1,0, 0, 0xea,0, 0, 0xe7,0, 0, - 0, 0, 0, 0, 0, 0, 0xf9,0, 0, 0, - 0, 0xc8,-1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, 0xaa,-1, 0, 0, 0, 0xac, - 0, 0xe8,-1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, 0xba,-1, 0, 0, 0, 0xbc -#else - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, -1, 0, -1, 0, 0, -1, 0, 0, - -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, - -1, -1, 0, -1, 0, 0, -1, 0, 0, - -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, - -1, -1, 0, -1, -1, -1, -1, -1, 0, - 0, 0, -1, 0, -1, 0, -1, -1, -1, 0, - -1, -1, 0, -1, -1, -1, -1, -1, 0, - 0, 0, -1, 0, -1, 0, -1, -1, -1, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, -1, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, -1, 0, 0, - 0, -1, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, -1, -1, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - 0, -1, 0, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, 0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, - 0, -1, 0, 0, -1, 0, 0, 0, -1, - -1, -1, 0, -1, -1, -1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - -1, 0, 0, -1, 0, 0, -1, 0, 0, - 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1, - 0, -1, -1, -1, 0, 0, 0, 0, 0, - -1, -1, 0, -1, -1, -1, 0, 0, 0, -1 -#endif -}; - -/* ---- T.61 characters [0xA0 .. 0xBF] ----------------- -*/ -static Couple trans_t61a_iso8859[32] = { -#if (ISO_8859 == 1) || (ISO_8859 == 9) - {'N','S'}, {0xa1,0}, {0xa2,0}, {0xa3,0}, - {'D','O'}, {0xa5,0}, {'C','u'}, {0xa7,0}, - {0xa4,0}, {'\'','6'},{'"','6'}, {0xab,0}, - {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'}, - {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0}, - {0xd7,0}, {0xb5,0}, {0xb6,0}, {0xb7,0}, - {0xf7,0}, {'\'','9'},{'"','9'}, {0xbb,0}, - {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0} -#elif (ISO_8859 == 2) || (ISO_8859 == 4) - {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'}, - {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0}, - {0xa4,0}, {'\'','6'},{'"','6'}, {'<','<'}, - {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'}, - {0xb0,0}, {'+','-'}, {'2','S'}, {'3','S'}, - {0xd7,0}, {'M','y'}, {'P','I'}, {'.','M'}, - {0xf7,0}, {'\'','9'},{'"','9'}, {'>','>'}, - {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'}, -#elif (ISO_8859 == 3) - {'N','S'}, {'!','I'}, {'C','t'}, {0xa3,0}, - {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0}, - {0xa4,0}, {'\'','6'},{'"','6'}, {'<','<'}, - {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'}, - {0xb0,0}, {'+','-'}, {0xb2,0}, {0xb3,0}, - {0xd7,0}, {0xb5,0}, {'P','I'}, {0xb7,0}, - {0xf7,0}, {'\'','9'},{'"','9'}, {'>','>'}, - {'1','4'}, {0xbd,0}, {'3','4'}, {'?','I'} -#elif (ISO_8859 == 10) - {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'}, - {'D','O'}, {'Y','e'}, {'C','u'}, {0xa7,0}, - {'C','u'}, {'\'','6'},{'"','6'}, {'<','<'}, - {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'}, - {0xb0,0}, {'+','-'}, {'2','S'}, {'3','S'}, - {'*','X'}, {'M','y'}, {'P','I'}, {0xb7,0}, - {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'}, - {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'} -#else - {'N','S'}, {'!','I'}, {'C','t'}, {'P','d'}, - {'D','O'}, {'Y','e'}, {'C','u'}, {'S','E'}, - {'X','O'}, {'\'','6'},{'"','6'}, {'<','<'}, - {'<','-'}, {'-','!'}, {'-','>'}, {'-','v'}, - {'D','G'}, {'+','-'}, {'2','S'}, {'3','S'}, - {'*','X'}, {'M','y'}, {'P','I'}, {'.','M'}, - {'-',':'}, {'\'','9'},{'"','9'}, {'>','>'}, - {'1','4'}, {'1','2'}, {'3','4'}, {'?','I'} -#endif -}; - -/* ---- T.61 characters [0xE0 .. 0xFF] ----------------- -*/ -static Couple trans_t61b_iso8859[48] = { -#if (ISO_8859 == 1) - {'-','M'}, {0xb9,0}, {0xae,0}, {0xa9,0}, - {'T','M'}, {'M','8'}, {0xac,0}, {0xa6,0}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {0xc6,0}, {0xd0,0}, {0xaa,0}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {0xd8,0}, {'O','E'}, {0xba,0}, - {0xde,0}, {'T','/'}, {'N','G'}, {'\'','n'}, - {'k','k'}, {0xe6,0}, {'d','/'}, {0xf0,0}, - {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'}, - {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0}, - {0xfe,0}, {'t','/'}, {'n','g'}, {'-','-'} -#elif (ISO_8859 == 2) - {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'}, - {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {'A','E'}, {0xd0,0}, {'-','a'}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {0xa3,0}, {'O','/'}, {'O','E'}, {'-','o'}, - {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'}, - {'k','k'}, {'a','e'}, {0xf0,0}, {'d','-'}, - {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'}, - {0xb3,0}, {'o','/'}, {'o','e'}, {0xdf,0}, - {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'} -#elif (ISO_8859 == 3) - {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'}, - {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'}, - {0xa1,0}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'}, - {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'}, - {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'}, - {0xb1,0}, {0xb9,0}, {'i','j'}, {'l','.'}, - {'l','/'}, {'o','/'}, {'o','e'}, {0xdf,0}, - {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'} -#elif (ISO_8859 == 4) - {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'}, - {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {0xc6,0}, {0xd0,0}, {'-','a'}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {0xd8,0}, {'O','E'}, {'-','o'}, - {'T','H'}, {0xac,0}, {0xbd,0}, {'\'','n'}, - {0xa2,0}, {0xe6,0}, {0xf0,0}, {'d','-'}, - {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'}, - {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0}, - {'t','h'}, {0xbc,0}, {0xbf,0}, {'-','-'} -#elif (ISO_8859 == 9) - {'-','M'}, {0xb9,0}, {0xae,0}, {0xa9,0}, - {'T','M'}, {'M','8'}, {0xac,0}, {0xa6,0}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {0xc6,0}, {'D','/'}, {0xaa,0}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {0xd8,0}, {'O','E'}, {0xba,0}, - {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'}, - {'k','k'}, {0xe6,0}, {'d','/'}, {'d','-'}, - {'h','/'}, {0xfd,0}, {'i','j'}, {'l','.'}, - {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0}, - {'t','h'}, {'t','/'}, {'n','g'}, {'-','-'} -#elif (ISO_8859 == 10) - {0xbd,0}, {'1','S'}, {'R','g'}, {'C','o'}, - {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {0xc6,0}, {0xa9,0}, {'-','a'}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {0xd8,0}, {'O','E'}, {'-','o'}, - {0xde,0}, {0xab,0}, {0xaf,0}, {'\'','n'}, - {0xff,0}, {0xe6,0}, {0xb9,0}, {0xf0,0}, - {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'}, - {'l','/'}, {0xf8,0}, {'o','e'}, {0xdf,0}, - {0xfe,0}, {0xbb,0}, {0xbf,0}, {'-','-'} -#else - {'-','M'}, {'1','S'}, {'R','g'}, {'C','o'}, - {'T','M'}, {'M','8'}, {'N','O'}, {'B','B'}, - {0,0}, {0,0}, {0,0}, {0,0}, - {'1','8'}, {'3','8'}, {'5','8'}, {'7','8'}, - {'O','m'}, {'A','E'}, {'D','/'}, {'-','a'}, - {'H','/'}, {0,0}, {'I','J'}, {'L','.'}, - {'L','/'}, {'O','/'}, {'O','E'}, {'-','o'}, - {'T','H'}, {'T','/'}, {'N','G'}, {'\'','n'}, - {'k','k'}, {'a','e'}, {'d','/'}, {'d','-'}, - {'h','/'}, {'i','.'}, {'i','j'}, {'l','.'}, - {'l','/'}, {'o','/'}, {'o','e'}, {'s','s'}, - {'t','h'}, {'t','-'}, {'n','g'}, {'-','-'} -#endif -}; - -/* ---- ISO 8859-n characters <0xA0 .. 0xFF> ------------------- -*/ -#if (ISO_8859 == 1) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xa1,0}, {0xa2,0}, {0xa3,0}, - {0xa8,0}, {0xa5,0}, {0xd7,0}, {0xa7,0}, - {0xc8,ALONE}, {0xd3,0}, {0xe3,0}, {0xab,0}, - {0xd6,0}, {0xff,0}, {0xd2,0}, {0xc5,ALONE}, - {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0}, - {0xc2,ALONE}, {0xb5,0}, {0xb6,0}, {0xb7,0}, - {0xcb,ALONE}, {0xd1,0}, {0xeb,0}, {0xbb,0}, - {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0}, - {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'}, - {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xcb,'C'}, - {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'}, - {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'}, - {0xe2,0}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'}, - {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0}, - {0xe9,0}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'}, - {0xc8,'U'}, {0xc2,'Y'}, {0xec,0}, {0xfb,0}, - {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'}, - {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xcb,'c'}, - {0xc1,'e'}, {0xc2,'e'}, {0xc3,'e'}, {0xc8,'e'}, - {0xc1,'i'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'}, - {0xf3,0}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'}, - {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0}, - {0xf9,0}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'}, - {0xc8,'u'}, {0xc2,'y'}, {0xfc,0}, {0xc8,'y'} -}; -#elif (ISO_8859 == 2) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xce,'A'}, {0xc6,ALONE}, {0xe8,0}, - {0xa8,0}, {0xcf,'L'}, {0xc2,'S'}, {0xa7,0}, - {0xc8,ALONE}, {0xcf,'S'}, {0xcb,'S'}, {0xcf,'T'}, - {0xc2,'Z'}, {0xff,0}, {0xcf,'Z'}, {0xc7,'Z'}, - {0xb0,0}, {0xce,'a'}, {0xce,ALONE}, {0xf8,0}, - {0xc2,ALONE}, {0xcf,'l'}, {0xc2,'s'}, {0xcf,ALONE}, - {0xcb,ALONE}, {0xcf,'s'}, {0xcb,'s'}, {0xcf,'t'}, - {0xc2,'z'}, {0xcd,ALONE}, {0xcf,'z'}, {0xc7,'z'}, - {0xc2,'R'}, {0xc2,'A'}, {0xc3,'A'}, {0xc6,'A'}, - {0xc8,'A'}, {0xc2,'L'}, {0xc2,'C'}, {0xcb,'C'}, - {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'}, - {0xcf,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xcf,'D'}, - {0xe2,0}, {0xc2,'N'}, {0xcf,'N'}, {0xc2,'O'}, - {0xc3,'O'}, {0xcd,'O'}, {0xc8,'O'}, {0xb4,0}, - {0xcf,'R'}, {0xca,'U'}, {0xc2,'U'}, {0xcd,'U'}, - {0xc8,'U'}, {0xc2,'Y'}, {0xcb,'T'}, {0xfb,0}, - {0xc2,'r'}, {0xc2,'a'}, {0xc3,'a'}, {0xc6,'a'}, - {0xc8,'a'}, {0xc2,'l'}, {0xc2,'c'}, {0xcb,'c'}, - {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'}, - {0xcf,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xcf,'d'}, - {0xf2,0}, {0xc2,'n'}, {0xcf,'n'}, {0xc2,'o'}, - {0xc3,'o'}, {0xcd,'o'}, {0xc8,'o'}, {0xb8,0}, - {0xcf,'r'}, {0xca,'u'}, {0xc2,'u'}, {0xcd,'u'}, - {0xc8,'u'}, {0xc2,'y'}, {0xcb,'t'}, {0xc7,ALONE} -}; -#elif (ISO_8859 == 3) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xe4,0}, {0xc6,ALONE}, {0xa3,0}, - {0xa8,0}, {0,0}, {0xc3,'H'}, {0xa7,0}, - {0xc8,ALONE}, {0xc7,'I'}, {0xcb,'S'}, {0xc6,'G'}, - {0xc3,'J'}, {0xff,0}, {0,0}, {0xc7,'Z'}, - {0xb0,0}, {0xf4,0}, {0xb2,0}, {0xb3,0}, - {0xc2,ALONE}, {0xb5,0}, {0xc3,'h'}, {0xb7,0}, - {0xcb,ALONE}, {0xf5,0}, {0xcb,'s'}, {0xc6,'g'}, - {0xc3,'j'}, {0xbd,0}, {0,0}, {0xc7,'z'}, - {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0,0}, - {0xc8,'A'}, {0xc7,'C'}, {0xc3,'C'}, {0xcb,'C'}, - {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'}, - {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'}, - {0,0}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'}, - {0xc3,'O'}, {0xc7,'G'}, {0xc8,'O'}, {0xb4,0}, - {0xc3,'G'}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'}, - {0xc8,'U'}, {0xc6,'U'}, {0xc3,'S'}, {0xfb,0}, - {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0,0}, - {0xc8,'a'}, {0xc7,'c'}, {0xc3,'c'}, {0xcb,'c'}, - {0xc1,'e'}, {0xc2,'e'}, {0xc3,'e'}, {0xc8,'e'}, - {0xc1,'i'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'}, - {0,0}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'}, - {0xc3,'o'}, {0xc7,'g'}, {0xc8,'o'}, {0xb8,0}, - {0xc3,'g'}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'}, - {0xc8,'u'}, {0xc6,'u'}, {0xc3,'s'}, {0xc7,ALONE} -}; -#elif (ISO_8859 == 4) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xce,'A'}, {0xf0,0}, {0xcb,'R'}, - {0xa8,0}, {0xc4,'I'}, {0xcb,'L'}, {0xa7,0}, - {0xc8,ALONE}, {0xcf,'S'}, {0xc5,'E'}, {0xcb,'G'}, - {0xed,0}, {0xff,0}, {0xcf,'Z'}, {0xc5,ALONE}, - {0xb0,0}, {0xce,'a'}, {0xce,ALONE}, {0xcb,'r'}, - {0xc2,ALONE}, {0xc4,'i'}, {0xcb,'l'}, {0xcf,ALONE}, - {0xcb,ALONE}, {0xcf,'s'}, {0xc5,'e'}, {0xcb,'g'}, - {0xfd,0}, {0xee,0}, {0xcf,'z'}, {0xfe,0}, - {0xc5,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'}, - {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xce,'I'}, - {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'}, - {0xc7,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xc5,'I'}, - {0xe2,0}, {0xcb,'N'}, {0xc5,'O'}, {0xcb,'K'}, - {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0}, - {0xe9,0}, {0xce,'U'}, {0xc2,'U'}, {0xc3,'U'}, - {0xc8,'U'}, {0xc4,'U'}, {0xc5,'U'}, {0xfb,0}, - {0xc5,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'}, - {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xce,'i'}, - {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'}, - {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc5,'i'}, - {0xf2,0}, {0xcb,'n'}, {0xc5,'o'}, {0xcb,'k'}, - {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0}, - {0xf9,0}, {0xce,'u'}, {0xc2,'u'}, {0xc3,'u'}, - {0xc8,'u'}, {0xc4,'u'}, {0xc5,'u'}, {0xc7,ALONE} -}; -#elif (ISO_8859 == 9) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xa1,0}, {0xa2,0}, {0xa3,0}, - {0xa8,0}, {0xa5,0}, {0xd7,0}, {0xa7,0}, - {0xc8,ALONE}, {0xd3,0}, {0xe3,0}, {0xab,0}, - {0xd6,0}, {0xff,0}, {0xd2,0}, {0xc5,ALONE}, - {0xb0,0}, {0xb1,0}, {0xb2,0}, {0xb3,0}, - {0xc2,ALONE}, {0xb5,0}, {0xb6,0}, {0xb7,0}, - {0xcb,ALONE}, {0xd1,0}, {0xeb,0}, {0xbb,0}, - {0xbc,0}, {0xbd,0}, {0xbe,0}, {0xbf,0}, - {0xc1,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'}, - {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xcb,'C'}, - {0xc1,'E'}, {0xc2,'E'}, {0xc3,'E'}, {0xc8,'E'}, - {0xc1,'I'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'}, - {0xc6,'G'}, {0xc4,'N'}, {0xc1,'O'}, {0xc2,'O'}, - {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xb4,0}, - {0xe9,0}, {0xc1,'U'}, {0xc2,'U'}, {0xc3,'U'}, - {0xc8,'U'}, {0xc7,'I'}, {0xcb,'S'}, {0xfb,0}, - {0xc1,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'}, - {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xcb,'c'}, - {0xc1,'e'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'}, - {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc5,'i'}, - {0xc6,'g'}, {0xc4,'n'}, {0xc1,'o'}, {0xc2,'o'}, - {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xb8,0}, - {0xf9,0}, {0xc1,'u'}, {0xc2,'u'}, {0xc3,'u'}, - {0xc8,'u'}, {0xf5,0}, {0xcb,'s'}, {0xc8,'y'} -}; -#elif (ISO_8859 == 10) -static Couple trans_iso8859_t61[96] = { - {0xa0,0}, {0xce,'A'}, {0xc5,'E'}, {0xcb,'G'}, - {0xc5,'I'}, {0xc4,'I'}, {0xcb,'K'}, {0xa7,0}, - {0xcb,'L'}, {0xe2,0}, {0xcf,'S'}, {0xed,0}, - {0xcf,'Z'}, {0xff,0}, {0xc5,'U'}, {0xee,0}, - {0xb0,0}, {0xce,'a'}, {0xc5,'e'}, {0xcb,'g'}, - {0xc5,'i'}, {0xc4,'i'}, {0xcb,'k'}, {0xb7,0}, - {0xcb,'l'}, {0xf2,0}, {0xcf,'s'}, {0xfd,0}, - {0xcf,'z'}, {0xd0,0}, {0xc5,'u'}, {0xfe,0}, - {0xc5,'A'}, {0xc2,'A'}, {0xc3,'A'}, {0xc4,'A'}, - {0xc8,'A'}, {0xca,'A'}, {0xe1,0}, {0xce,'I'}, - {0xcf,'C'}, {0xc2,'E'}, {0xce,'E'}, {0xc8,'E'}, - {0xc7,'E'}, {0xc2,'I'}, {0xc3,'I'}, {0xc8,'I'}, - {0,0}, {0xcb,'N'}, {0xc5,'O'}, {0xc2,'O'}, - {0xc3,'O'}, {0xc4,'O'}, {0xc8,'O'}, {0xc4,'U'}, - {0xe9,0}, {0xce,'U'}, {0xc2,'U'}, {0xc3,'U'}, - {0xc8,'U'}, {0xc2,'Y'}, {0xec,0}, {0xfb,0}, - {0xc5,'a'}, {0xc2,'a'}, {0xc3,'a'}, {0xc4,'a'}, - {0xc8,'a'}, {0xca,'a'}, {0xf1,0}, {0xce,'i'}, - {0xcf,'c'}, {0xc2,'e'}, {0xce,'e'}, {0xc8,'e'}, - {0xc7,'e'}, {0xc2,'i'}, {0xc3,'i'}, {0xc8,'i'}, - {0xf3,0}, {0xcb,'n'}, {0xc5,'o'}, {0xc2,'o'}, - {0xc3,'o'}, {0xc4,'o'}, {0xc8,'o'}, {0xc4,'u'}, - {0xf9,0}, {0xce,'u'}, {0xc2,'u'}, {0xc3,'u'}, - {0xc8,'u'}, {0xc2,'y'}, {0xfc,0}, {0xf0,0} -}; -#endif - - -static Byte * -c_to_hh( Byte *o, Byte c ) -{ - Byte n; - - *o++ = '{'; *o++ = 'x'; - n = c >> 4; - *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n; - n = c & 0x0F; - *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n; - *o++ = '}'; - return o; -} - - -static Byte * -c_to_cc( Byte *o, Couple *cc, Byte c ) -{ - if ( (*cc).a != 0 ) { - if ( (*cc).b == 0 ) - *o++ = (*cc).a; - else { - *o++ = '{'; - *o++ = (*cc).a; - *o++ = (*cc).b; - *o++ = '}'; - } - return o; - } - else - return c_to_hh( o, c ); -} - -/* --- routine to convert from T.61 to ISO 8859-n --- */ - -int -ldap_t61_to_8859( char **bufp, unsigned int *buflenp, int free_input ) -{ - Byte *s, *oo, *o; - unsigned int n; - int c; - unsigned int len; - Couple *cc; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 111, "ldap_t61_to_8859 input length: %ld\n"), - *buflenp, 0, 0 ); - - len = *buflenp; - s = (Byte *) *bufp; - - if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) { - return( 1 ); - } - - while ( (char *)s - *(char **)bufp < len ) { - switch ( *s >> 4 ) { - - case 0xA: case 0xB: - o = c_to_cc( o, &trans_t61a_iso8859[ *s - 0xA0 ], *s ); - s++; - break; - - case 0xD: case 0xE: case 0xF: - o = c_to_cc( o, &trans_t61b_iso8859[ *s - 0xD0 ], *s ); - s++; - break; - - case 0xC: - if ( (*s == 0xC0) || (*s == 0xC9) || (*s == 0xCC) ) { - o = c_to_hh( o, *s++ ); - break; - } - - n = (*s++) - 0xC0; - switch ( *s ) { - - case 'A': c = letter_w_diacritic[n][0]; break; - case 'C': c = letter_w_diacritic[n][1]; break; - case 'D': c = letter_w_diacritic[n][2]; break; - case 'E': c = letter_w_diacritic[n][3]; break; - case 'G': c = letter_w_diacritic[n][4]; break; - case 'H': c = letter_w_diacritic[n][5]; break; - case 'I': c = letter_w_diacritic[n][6]; break; - case 'J': c = letter_w_diacritic[n][7]; break; - case 'K': c = letter_w_diacritic[n][8]; break; - case 'L': c = letter_w_diacritic[n][9]; break; - case 'N': c = letter_w_diacritic[n][10]; break; - case 'O': c = letter_w_diacritic[n][11]; break; - case 'R': c = letter_w_diacritic[n][12]; break; - case 'S': c = letter_w_diacritic[n][13]; break; - case 'T': c = letter_w_diacritic[n][14]; break; - case 'U': c = letter_w_diacritic[n][15]; break; - case 'W': c = letter_w_diacritic[n][16]; break; - case 'Y': c = letter_w_diacritic[n][17]; break; - case 'Z': c = letter_w_diacritic[n][18]; break; - - case 'a': c = letter_w_diacritic[n][19]; break; - case 'c': c = letter_w_diacritic[n][20]; break; - case 'd': c = letter_w_diacritic[n][21]; break; - case 'e': c = letter_w_diacritic[n][22]; break; - case 'g': c = letter_w_diacritic[n][23]; break; - case 'h': c = letter_w_diacritic[n][24]; break; - case 'i': c = letter_w_diacritic[n][25]; break; - case 'j': c = letter_w_diacritic[n][26]; break; - case 'k': c = letter_w_diacritic[n][27]; break; - case 'l': c = letter_w_diacritic[n][28]; break; - case 'n': c = letter_w_diacritic[n][29]; break; - case 'o': c = letter_w_diacritic[n][30]; break; - case 'r': c = letter_w_diacritic[n][31]; break; - case 's': c = letter_w_diacritic[n][32]; break; - case 't': c = letter_w_diacritic[n][33]; break; - case 'u': c = letter_w_diacritic[n][34]; break; - case 'w': c = letter_w_diacritic[n][35]; break; - case 'y': c = letter_w_diacritic[n][36]; break; - case 'z': c = letter_w_diacritic[n][37]; break; - - case ALONE: c = (( !diacritic[n].b ) ? diacritic[n].a : -1); - break; - - default: c = 0; - } - - if ( c > 0 ) { - *o++ = c; s++; - } else { - *o++ = '{'; - if ( c == -1 ) { - *o++ = ( ( *s == ALONE ) ? ' ' : *s ); - s++; - } else { - *o++ = '"'; - } - *o++ = diacritic[n].a; - *o++ = '}'; - } - break; - -#if (ISO_8859 == 0) - case 0x8: case 0x9: - *o++ = 0x1B; /* <ESC> */ - *o++ = *s++ - 0x40; - break; -#endif - - default: - *o++ = *s++; - } - } - - len = o - oo; - o = oo; - - if ( (oo = (Byte *)realloc( o, len )) == NULL ) { - free( o ); - return( 1 ); - } - - if ( free_input ) { - free( *bufp ); - } - *bufp = (char *) oo; - *buflenp = len; - return( 0 ); -} - - -static int -hh_to_c( Byte *h ) -{ - Byte c; - - if ( (*h >= '0') && (*h <= '9') ) c = *h++ - '0'; - else if ( (*h >= 'A') && (*h <= 'F') ) c = *h++ - 'A' + 10; - else if ( (*h >= 'a') && (*h <= 'f') ) c = *h++ - 'a' + 10; - else return -1; - - c <<= 4; - - if ( (*h >= '0') && (*h <= '9') ) c |= *h - '0'; - else if ( (*h >= 'A') && (*h <= 'F') ) c |= *h - 'A' + 10; - else if ( (*h >= 'a') && (*h <= 'f') ) c |= *h - 'a' + 10; - else return -1; - - return c; -} - - -static Byte * -cc_to_t61( Byte *o, Byte *s ) -{ - int n, c = 0; - - switch ( *(s + 1) ) { - - case '`': c = -1; break; /* <grave-accent> */ - - case '!': - switch ( *s ) { - case '!': c = 0x7C; break; /* <vertical-line> */ - case '(': c = 0x7B; break; /* <left-curly-bracket> */ - case '-': c = 0xAD; break; /* <upwards-arrow> */ - default: c = -1; /* <grave-accent> */ - } - break; - -#if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \ - (ISO_8859 == 4) || (ISO_8859 == 9) - case 0xB4: -#endif - case '\'': c = -2; break; /* <acute-accent> */ - - case '^': c = -3; break; /* <circumflex-acent> */ - - case '>': - switch ( *s ) { - case ')': c = 0x5D; break; /* <right-square-bracket> */ - case '>': c = 0xBB; break; /* <right-angle-quotation> */ - case '-': c = 0xAE; break; /* <rightwards-arrow> */ - default: c = -3; /* <circumflex-acent> */ - } - break; - - case '~': - case '?': c = -4; break; /* <tilde> */ - -#if (ISO_8859 == 1) || (ISO_8859 == 4) || (ISO_8859 == 9) - case 0xAF: c = -5; break; /* <macron> */ -#endif - - case '-': - switch ( *s ) { - case '-': c = 0xFF; break; /* <soft-hyphen> */ - case '<': c = 0xAC; break; /* <leftwards arrow> */ - case '+': c = 0xB1; break; /* <plus-minus> */ - case 'd': c = 0xF3; break; /* <eth> */ - default: c = -5; /* <macron> */ - } - break; - -#if (ISO_8859 == 2) || (ISO_8859 == 3) - case 0xA2: c = -6; break; /* <breve> */ -#endif - - case '(': - if ( *s == '<' ) c = 0x5B; /* <left-square-bracket> */ - else c = -6; /* <breve> */ - break; - -#if (ISO_8859 == 2) || (ISO_8859 == 3) || (ISO_8859 == 4) - case 0xFF: c = -7; break; /* <dot-accent> */ -#endif - - case '.': - switch ( *s ) { - case 'i': c = 0xF5; break; /* <dotless-i> */ - case 'L': c = 0xE7; break; /* <L-middle-dot> */ - case 'l': c = 0xF7; break; /* <l-middle-dot> */ - default: c = -7; /* <dot-accent> */ - } - break; - -#if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \ - (ISO_8859 == 4) || (ISO_8859 == 9) - case 0xA8: c = -8; break; /* <diaeresis> */ -#endif - - case ':': - if ( *s == '-') c = 0xB8; /* <division-sign> */ - else c = -8; /* <diaeresis> */ - break; - -#if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \ - (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10) - case 0xB0: -#endif - case '0': c = -10; break; /* <ring-above> */ - -#if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \ - (ISO_8859 == 4) || (ISO_8859 == 9) - case 0xB8: -#endif - case ',': c = -11; break; /* <cedilla> */ - -#if (ISO_8859 == 2) - case 0xBD: -#endif - case '"': c = -13; break; /* <double-acute-accent> */ - -#if (ISO_8859 == 2) || (ISO_8859 == 4) - case 0xB2: -#endif - case ';': c = -14; break; /* <ogonek> */ - -#if (ISO_8859 == 2) || (ISO_8859 == 4) - case 0xB7: c = -15; break; /* <caron> */ -#endif - - case ')': - if ( *s == '!' ) c = 0x7D; /* <left-curly-bracket> */ - break; - - case '<': - if ( *s == '<' ) c = 0xAB; /* <left-angle-quotation> */ - else c = -15; /* <caron> */ - break; - - case '/': - switch ( *s ) { - case '/': c = 0x5C; break; /* <reverse-solidus> */ - case 'D': c = 0xE2; break; /* <D-stroke> */ - case 'd': c = 0xF2; break; /* <d-stroke> */ - case 'H': c = 0xE4; break; /* <H-stroke> */ - case 'h': c = 0xF4; break; /* <h-stroke> */ - case 'L': c = 0xE8; break; /* <L-stroke> */ - case 'l': c = 0xF8; break; /* <l-stroke> */ - case 'O': c = 0xE9; break; /* <O-stroke> */ - case 'o': c = 0xF9; break; /* <o-stroke> */ - case 'T': c = 0xED; break; /* <T-stroke> */ - case 't': c = 0xFD; break; /* <t-stroke> */ - } - break; - - case '2': - if ( *s == '1' ) c = 0xBD; /* <one-half> */ - break; - - case '4': - switch ( *s ) { - case '1': c = 0xBC; break; /* <one-quarter> */ - case '3': c = 0xBE; break; /* <three-quarters> */ - } - break; - - case '6': - switch ( *s ) { - case '\'': c = 0xA9; break; /* <left-single-quotation> */ - case '"': c = 0xAA; break; /* <left-double-quotation> */ - } - break; - - case '8': - switch ( *s ) { - case '1': c = 0xDC; break; /* <one-eighth> */ - case '3': c = 0xDD; break; /* <three-eighths> */ - case '5': c = 0xDE; break; /* <five-eighths> */ - case '7': c = 0xDF; break; /* <seven-eighths> */ - case 'M': c = 0xD5; break; /* <eighth-note> */ - } - break; - - case '9': - switch ( *s ) { - case '\'': c = 0xB9; break; /* <right-single-quotation> */ - case '"': c = 0xBA; break; /* <right-double-quotation> */ - } - break; - - case 'A': - if ( *s == 'A' ) c = -10; /* <ring-above> + <A> */ - break; - - case 'a': - switch ( *s ) { - case '-': c = 0xE3; break; /* <femenine-ordinal-a> */ - case 'a': c = -10; break; /* <ring-above> + <a> */ - } - break; - - case 'B': - if ( *s == 'B' ) c = 0xD7; /* <broken-bar> */ - break; - - case 'b': - if ( *s == 'N' ) c = 0xA6; /* <number-sign> */ - break; - - case 'd': - if ( *s == 'P' ) c = 0xA3; /* <pound-sign> */ - break; - - case 'E': - switch ( *s ) { - case 'S': c = 0xA7; break; /* <section-sign> */ - case 'A': c = 0xE1; break; /* <AE> */ - case 'O': c = 0xEA; break; /* <OE> */ - } - break; - - case 'e': - switch ( *s ) { - case 'a': c = 0xF1; break; /* <ae> */ - case 'o': c = 0xFA; break; /* <oe> */ - case 'Y': c = 0xA5; break; /* <yen-sign> */ - } - break; - - case 'G': - switch ( *s ) { - case 'D': c = 0xB0; break; /* <degree-sign> */ - case 'N': c = 0xEE; break; /* <Eng> */ - } - break; - - case 'g': - switch ( *s ) { - case 'R': c = 0xD2; break; /* <registered-sign> */ - case 'n': c = 0xFE; break; /* <eng> */ - } - break; - - case 'H': - if ( *s == 'T' ) c = 0xEC; /* <Thorn> */ - break; - - case 'h': - if ( *s == 't' ) c = 0xFC; /* <thorn> */ - break; - - case 'I': - switch ( *s ) { - case 'P': c = 0xB6; break; /* <pilcrow-sign> */ - case '!': c = 0xA1; break; /* <inverted-exclamation> */ - case '?': c = 0xBF; break; /* <inverted-question> */ - } - break; - - case 'J': - if ( *s == 'I' ) c = 0xE6; /* <IJ> */ - break; - - case 'j': - if ( *s == 'i' ) c = 0xF6; /* <ij> */ - break; - - case 'k': - if ( *s == 'k' ) c = 0xF0; /* <kra> */ - break; - - case 'M': - switch ( *s ) { - case '.': c = 0xB7; break; /* <middle-dot> */ - case '-': c = 0xD0; break; /* <em-dash> */ - case 'T': c = 0xD4; break; /* <trade-mark-sign> */ - } - break; - - case 'm': - switch ( *s ) { - case '\'': /* <macron> RFC 1345 */ - case ' ': c = -5; break; /* <macron> */ - case 'O': c = 0xE0; break; /* <Ohm sign> */ - } - break; - - case 'n': - if ( *s == '\'' ) c = 0xEF; /* <n-preceded-by-apostrophe> */ - break; - - case 'O': - switch ( *s ) { - case 'D': c = 0xA4; break; /* <dollar-sign> */ - case 'N': c = 0xD6; break; /* <not-sign> */ - } - break; - - case 'o': - switch ( *s ) { - case 'C': c = 0xD3; break; /* <copyright-sign> */ - case '-': c = 0xEB; break; /* <masculine-ordinal-o> */ - } - break; - - case 'S': - switch ( *s ) { - case '1': c = 0xD1; break; /* <superscript-1> */ - case '2': c = 0xB2; break; /* <superscript-2> */ - case '3': c = 0xB3; break; /* <superscript-3> */ - case 'N': c = 0xA0; break; /* <no-break-space> */ - } - break; - - case 's': - if ( *s == 's' ) c = 0xFB; /* <sharp-s> */ - break; - - case 't': - if ( *s == 'C' ) c = 0xA2; /* <cent-sign> */ - break; - - case 'u': - if ( *s == 'C' ) c = 0xA8; /* <currency-sign> */ - break; - - case 'v': - if ( *s == '-' ) c = 0xAF; /* <downwards-arrow> */ - break; - - case 'X': - if ( *s == '*' ) c = 0xB4; /* <multiplication-sign> */ - break; - - case 'y': - if ( *s == 'M' ) c = 0xB5; /* <micro-sign> */ - break; - } - - if ( c > 0 ) { - *o++ = c; - return o; - } else if ( !c ) - return NULL; - - /* else: c < 0 */ - n = -c; - switch ( *s ) { - - case 'A': c = letter_w_diacritic[n][0]; break; - case 'C': c = letter_w_diacritic[n][1]; break; - case 'D': c = letter_w_diacritic[n][2]; break; - case 'E': c = letter_w_diacritic[n][3]; break; - case 'G': c = letter_w_diacritic[n][4]; break; - case 'H': c = letter_w_diacritic[n][5]; break; - case 'I': c = letter_w_diacritic[n][6]; break; - case 'J': c = letter_w_diacritic[n][7]; break; - case 'K': c = letter_w_diacritic[n][8]; break; - case 'L': c = letter_w_diacritic[n][9]; break; - case 'N': c = letter_w_diacritic[n][10]; break; - case 'O': c = letter_w_diacritic[n][11]; break; - case 'R': c = letter_w_diacritic[n][12]; break; - case 'S': c = letter_w_diacritic[n][13]; break; - case 'T': c = letter_w_diacritic[n][14]; break; - case 'U': c = letter_w_diacritic[n][15]; break; - case 'W': c = letter_w_diacritic[n][16]; break; - case 'Y': c = letter_w_diacritic[n][17]; break; - case 'Z': c = letter_w_diacritic[n][18]; break; - - case 'a': c = letter_w_diacritic[n][19]; break; - case 'c': c = letter_w_diacritic[n][20]; break; - case 'd': c = letter_w_diacritic[n][21]; break; - case 'e': c = letter_w_diacritic[n][22]; break; - case 'g': c = letter_w_diacritic[n][23]; break; - case 'h': c = letter_w_diacritic[n][24]; break; - case 'i': c = letter_w_diacritic[n][25]; break; - case 'j': c = letter_w_diacritic[n][26]; break; - case 'k': c = letter_w_diacritic[n][27]; break; - case 'l': c = letter_w_diacritic[n][28]; break; - case 'n': c = letter_w_diacritic[n][29]; break; - case 'o': c = letter_w_diacritic[n][30]; break; - case 'r': c = letter_w_diacritic[n][31]; break; - case 's': c = letter_w_diacritic[n][32]; break; - case 't': c = letter_w_diacritic[n][33]; break; - case 'u': c = letter_w_diacritic[n][34]; break; - case 'w': c = letter_w_diacritic[n][35]; break; - case 'y': c = letter_w_diacritic[n][36]; break; - case 'z': c = letter_w_diacritic[n][37]; break; - - case '\'': - case ' ': c = -1; break; - - default: c = 0; - } - - if ( !c ) - return NULL; - - *o++ = n + 0xC0; - *o++ = ( ( (*s == ' ') || (*s == '\'') ) ? ALONE : *s ); - return o; -} - - -/* --- routine to convert from ISO 8859-n to T.61 --- */ - -int -ldap_8859_to_t61( char **bufp, unsigned int *buflenp, int free_input ) -{ - Byte *s, *oo, *o, *aux; - int c; - unsigned int len; - Couple *cc; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 112, "ldap_8859_to_t61 input length: %ld\n"), - *buflenp, 0, 0 ); - - len = *buflenp; - s = (Byte *) *bufp; - - if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) { - return( 1 ); - } - - while ( (char *)s - *(char **)bufp < len ) { - switch( *s >> 5 ) { - - case 2: - switch ( *s ) { - - case '^': *o++ = 0xC3; *o++ = ALONE; s++; break; - - case '\\': - s++; - if ( (c = hh_to_c( s )) != -1 ) { - *o++ = c; - s += 2; - } else - *o++ = '\\'; - break; - - default: *o++ = *s++; - } - break; - - case 3: - switch ( *s ) { - - case '`': *o++ = 0xC1; *o++ = ALONE; s++; break; - case '~': *o++ = 0xC4; *o++ = ALONE; s++; break; - - case '{': - s++; - if ( *(s + 2) == '}' ) { - if ( (aux = cc_to_t61( o, s )) != NULL ) { - o = aux; - s += 3; - } else { - *o++ = '{'; - } - } else if ( (*(s + 3) == '}') && ( (*s == 'x') || (*s == 'X') ) && - ( (c = hh_to_c( s + 1 )) != -1 ) ) { - *o++ = c; - s += 4; - } else { - *o++ = '{'; - } - break; - - default: - *o++ = *s++; - } - break; - -#if (ISO_8859 == 0) - case 4: case 5: case 6: case 7: - s++; - break; -#else - case 5: case 6: case 7: -# if (ISO_8859 == 1) || (ISO_8859 == 2) || (ISO_8859 == 3) || \ - (ISO_8859 == 4) || (ISO_8859 == 9) || (ISO_8859 == 10) - if ( (*(cc = &trans_iso8859_t61[ *s - 0xA0 ])).a ) { - *o++ = (*cc).a; - if ( (*cc).b ) *o++ = (*cc).b; - } -# endif - s++; - break; -#endif - - default: - *o++ = *s++; - } - } - - len = o - oo; - o = oo; - - if ( (oo = (Byte *)realloc( o, len )) == NULL ) { - free( o ); - return( 1 ); - } - - if ( free_input ) { - free( *bufp ); - } - *bufp = (char *) oo; - *buflenp = len; - return( 0 ); -} - - -#ifdef NOT_NEEDED_IN_LIBLDAP /* mcs@umich.edu 12 Oct 1995 */ -/* --- routine to convert "escaped" (\hh) characters to 8bits --- */ - -void convert_escaped_to_8bit( s ) -char *s; -{ - char *o = s; - int c; - - while ( *s ) { - if ( *s == '\\' ) { - if ( (c = hh_to_c( ++s )) != -1 ) { - *o++ = c; - s += 2; - } else - *o++ = '\\'; - } else - *o++ = *s++; - } - *o = '\0'; -} - -/* --- routine to convert 8bits characters to the "escaped" (\hh) form --- */ - -char *convert_8bit_to_escaped( s ) -Byte *s; -{ - Byte *o, *oo; - Byte n; - - if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) { - return( NULL ); - } - - while ( *s ) { - if ( *s < 0x80 ) - *o++ = *s++; - else { - *o++ = '\\'; - n = *s >> 4; - *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n; - n = *s++ & 0x0F; - *o++ = ((n < 0xA) ? '0' : 'A' - 0xA) + n; - } - } - *o = '\0'; - - o = oo; - - if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) { - free( o ); - return( NULL ); - } - - return( (char *)oo ); -} - -/* --- routine to convert from T.61 to printable characters --- */ - -/* - printable characters [RFC 1488]: 'A'..'Z', 'a'..'z', '0'..'9', - '\'', '(', ')', '+', ',', '-', '.', '/', ':', '?, ' '. - - that conversion is language dependent. -*/ - -static Couple last_t61_printabled[32] = { - {0,0}, {'A','E'}, {'D',0}, {0,0}, - {'H',0}, {0,0}, {'I','J'}, {'L',0}, - {'L',0}, {'O',0}, {'O','E'}, {0,0}, - {'T','H'}, {'T',0}, {'N','G'}, {'n',0}, - {'k',0}, {'a','e'}, {'d',0}, {'d',0}, - {'h',0}, {'i',0}, {'i','j'}, {'l',0}, - {'l',0}, {'o',0}, {'o','e'}, {'s','s'}, - {'t','h'}, {'t',0}, {'n','g'}, {0,0} -}; - -char *t61_printable( s ) -Byte *s; -{ - Byte *o, *oo; - Byte n; - Couple *cc; - - if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) { - return( NULL ); - } - - while ( *s ) { - if ( ( (*s >= 'A') && (*s <= 'Z') ) || - ( (*s >= 'a') && (*s <= 'z') ) || - ( (*s >= '0') && (*s <= '9') ) || - ( (*s >= '\'') && (*s <= ')') ) || - ( (*s >= '+') && (*s <= '/') ) || - ( *s == '?' ) || ( *s == ' ' ) ) - *o++ = *s++; - else { - if ( *s >= 0xE0 ) { - if ( (*(cc = &last_t61_printabled[ *s - 0xE0 ])).a ) { - *o++ = (*cc).a; - if ( (*cc).b ) *o++ = (*cc).b; - } - } - else if ( (*s >> 4) == 0xC ) { - switch ( *s ) { - case 0xCA: /* ring */ - switch ( *(s + 1) ) { - case 'A': *o++ = 'A'; *o++ = 'A'; s++; break; /* Swedish */ - case 'a': *o++ = 'a'; *o++ = 'a'; s++; break; /* Swedish */ - } - break; - - case 0xC8: /* diaeresis */ - switch ( *(s + 1) ) { - case 'Y': *o++ = 'I'; *o++ = 'J'; s++; break; /* Dutch */ - case 'y': *o++ = 'i'; *o++ = 'j'; s++; break; /* Dutch */ - } - break; - } - } - s++; - } - } - *o = '\0'; - - o = oo; - - if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) { - free( o ); - return( NULL ); - } - - return( (char *)oo ); -} -#endif /* NOT_NEEDED_IN_LIBLDAP */ /* mcs@umich.edu 12 Oct 1995 */ - -#endif /* LDAP_CHARSET_8859 */ -#endif /* STR_TRANSLATION */
--- a/usr/src/lib/libldap4/common/cldap.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,597 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990, 1994 Regents of the University of Michigan. - * All rights reserved. - * - * cldap.c - synchronous, retrying interface to the cldap protocol - */ - - -#ifdef CLDAP - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990, 1994 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> -#include <errno.h> -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#ifdef DOS -#include "msdos.h" -#else /* DOS */ -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#endif /* DOS */ -#endif /* MACOS */ -#ifdef SUN -#include <nss_dbdefs.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#define DEF_CLDAP_TIMEOUT 3 -#define DEF_CLDAP_TRIES 4 - -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) -#endif - - -struct cldap_retinfo { - int cri_maxtries; - int cri_try; - int cri_useaddr; - time_t cri_timeout; -}; - -#ifdef NEEDPROTOS -static int add_addr( LDAP *ld, struct sockaddr *sap ); -static int cldap_result( LDAP *ld, int msgid, LDAPMessage **res, - struct cldap_retinfo *crip, char *base ); -static int cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber, - LDAPMessage **res, char *base ); -#else /* NEEDPROTOS */ -static int add_addr(); -static int cldap_result(); -static int cldap_parsemsg(); -#endif /* NEEDPROTOS */ - -/* - * cldap_open - initialize and connect to an ldap server. A magic cookie to - * be used for future communication is returned on success, NULL on failure. - * - * Example: - * LDAP *ld; - * ld = cldap_open( hostname, port ); - */ - -LDAP * -cldap_open( char *host, int port ) -{ - int s; - in_addr_t address; - struct sockaddr_in sock; - struct hostent *hp; - LDAP *ld; - char *p; - int i; -#ifdef SUN - struct hostent hpret; - char hpbuf[NSS_BUFLEN_HOSTS]; - int hperrno; -#endif - in_addr_t inet_addr(const char *); - int close(int); - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 113, "ldap_open\n"), 0, 0, 0 ); - - if ( port == 0 ) { - port = LDAP_PORT; - } - - if ( (s = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { - return( NULL ); - } - - sock.sin_addr.s_addr = 0; - sock.sin_family = AF_INET; - sock.sin_port = 0; - if ( bind(s, (struct sockaddr *) &sock, sizeof(sock)) < 0) { - close( s ); - return( NULL ); - } - - if (( ld = ldap_init( host, port )) == NULL ) { - close( s ); - return( NULL ); - } - if ( (ld->ld_sb.sb_fromaddr = (void *) calloc( 1, - sizeof( struct sockaddr ))) == NULL ) { - free( ld ); - close( s ); - return( NULL ); - } - ld->ld_sb.sb_sd = s; - ld->ld_sb.sb_naddr = 0; - ld->ld_version = LDAP_VERSION; - - sock.sin_family = AF_INET; - sock.sin_port = htons( port ); - - /* - * 'host' may be a space-separated list. - */ - if ( host != NULL ) { - for ( ; host != NULL; host = p ) { - if (( p = strchr( host, ' ' )) != NULL ) { - for (*p++ = '\0'; *p == ' '; p++) { - ; - } - } - - if ( (address = inet_addr( host )) == -1 ) { -#ifdef SUN - if ( (hp = gethostbyname_r( host, &hpret, hpbuf, NSS_BUFLEN_HOSTS, &hperrno)) == NULL ) { - errno = EHOSTUNREACH; - continue; - } -#else - if ( (hp = gethostbyname( host )) == NULL ) { - errno = EHOSTUNREACH; - continue; - } -#endif - - for ( i = 0; hp->h_addr_list[ i ] != 0; ++i ) { - SAFEMEMCPY( (char *)&sock.sin_addr.s_addr, - (char *)hp->h_addr_list[ i ], - sizeof(sock.sin_addr.s_addr)); - if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) { - close( s ); - free( ld ); - return( NULL ); - } - } - - } else { - sock.sin_addr.s_addr = address; - if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) { - close( s ); - free( ld ); - return( NULL ); - } - } - - if ( ld->ld_host == NULL ) { - ld->ld_host = strdup( host ); - } - } - - } else { - address = INADDR_LOOPBACK; - sock.sin_addr.s_addr = htonl( address ); - if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) { - close( s ); - free( ld ); - return( NULL ); - } - } - - if ( ld->ld_sb.sb_addrs == NULL -#ifdef LDAP_REFERRALS - || ( ld->ld_defconn = new_connection( ld, NULL, 1,0,0 )) == NULL -#endif /* LDAP_REFERRALS */ - ) { - free( ld ); - return( NULL ); - } - - ld->ld_sb.sb_useaddr = ld->ld_sb.sb_addrs[ 0 ]; - cldap_setretryinfo( ld, 0, 0 ); - -#ifdef LDAP_DEBUG - putchar( '\n' ); - for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 114, "end of cldap_open address %1$d is %2$s\n"), - i, inet_ntoa( ((struct sockaddr_in *) - ld->ld_sb.sb_addrs[ i ])->sin_addr ), 0 ); - } -#endif - - return( ld ); -} - - - -void -cldap_close( LDAP *ld ) -{ - ldap_ld_free( ld, 0 ); -} - - -void -cldap_setretryinfo( LDAP *ld, int tries, time_t timeout ) -{ -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - ld->ld_cldaptries = ( tries <= 0 ) ? DEF_CLDAP_TRIES : tries; - ld->ld_cldaptimeout = ( timeout <= 0 ) ? DEF_CLDAP_TIMEOUT : timeout; -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif -} - - -int -cldap_search_s( LDAP *ld, char *base, int scope, char *filter, char **attrs, - int attrsonly, LDAPMessage **res, char *logdn ) -{ - int ret, msgid; - struct cldap_retinfo cri; - - *res = NULLMSG; - - (void) memset( &cri, 0, sizeof( cri )); - -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - - if ( logdn != NULL ) { - ld->ld_cldapdn = logdn; - } else if ( ld->ld_cldapdn == NULL ) { - ld->ld_cldapdn = ""; - } - - do { - if ( cri.cri_try != 0 ) { - --ld->ld_msgid; /* use same id as before */ - } - ld->ld_sb.sb_useaddr = ld->ld_sb.sb_addrs[ cri.cri_useaddr ]; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 115, "cldap_search_s try %1$d (to %2$s)\n"), - cri.cri_try, inet_ntoa( ((struct sockaddr_in *) - ld->ld_sb.sb_useaddr)->sin_addr ), 0 ); - - if ( (msgid = ldap_search( ld, base, scope, filter, attrs, - attrsonly )) == -1 ) { -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( ld->ld_errno ); - } -#ifndef NO_CACHE -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_RESPONSE(ld); -#endif - if ( ld->ld_cache != NULL && ld->ld_responses != NULL ) { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 116, "cldap_search_s res from cache\n"), - 0, 0, 0 ); - *res = ld->ld_responses; - ld->ld_responses = ld->ld_responses->lm_next; -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); - ret = ldap_result2error( ld, *res, 0 ); - UNLOCK_RESPONSE(ld); - return( ret ); -#else - return( ldap_result2error( ld, *res, 0 )); -#endif - } -#endif /* NO_CACHE */ - ret = cldap_result( ld, msgid, res, &cri, base ); -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_RESPONSE(ld); -#endif - } while (ret == -1); - - return( ret ); -} - - -static int -add_addr( LDAP *ld, struct sockaddr *sap ) -{ - struct sockaddr *newsap, **addrs; - - if (( newsap = (struct sockaddr *)malloc( sizeof( struct sockaddr ))) - == NULL ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( -1 ); - } - - if ( ld->ld_sb.sb_naddr == 0 ) { - addrs = (struct sockaddr **)malloc( sizeof(struct sockaddr *)); - } else { - addrs = (struct sockaddr **)realloc( ld->ld_sb.sb_addrs, - ( ld->ld_sb.sb_naddr + 1 ) * sizeof(struct sockaddr *)); - } - - if ( addrs == NULL ) { - free( newsap ); - ld->ld_errno = LDAP_NO_MEMORY; - return( -1 ); - } - - SAFEMEMCPY( (char *)newsap, (char *)sap, sizeof( struct sockaddr )); - addrs[ ld->ld_sb.sb_naddr++ ] = newsap; - ld->ld_sb.sb_addrs = (void **)addrs; - return( 0 ); -} - - -static int -cldap_result( LDAP *ld, int msgid, LDAPMessage **res, - struct cldap_retinfo *crip, char *base ) -{ - Sockbuf *sb; - BerElement ber; - char *logdn; - int ret, id, fromaddr, i; - struct timeval tv; - -#if defined( SUN ) && defined( _REENTRANT ) - LOCK_LDAP(ld); -#endif - - sb = &ld->ld_sb; - fromaddr = -1; - - if ( crip->cri_try == 0 ) { - crip->cri_maxtries = ld->ld_cldaptries * sb->sb_naddr; - crip->cri_timeout = ld->ld_cldaptimeout; - crip->cri_useaddr = 0; - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 117, "cldap_result tries %1$d timeout %2$d\n"), - ld->ld_cldaptries, ld->ld_cldaptimeout, 0 ); - } - - if ((tv.tv_sec = crip->cri_timeout / sb->sb_naddr) < 1 ) { - tv.tv_sec = 1; - } - tv.tv_usec = 0; - - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 118, "cldap_result waiting up to %d seconds for a response\n"), - tv.tv_sec, 0, 0 ); - ber_zero_init( &ber, 0 ); - set_ber_options( ld, &ber ); - - if ( cldap_getmsg( ld, &tv, &ber ) == -1 ) { - ret = ld->ld_errno; - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 119, "cldap_getmsg returned -1 (%d)\n"), - ret, 0, 0 ); - } else if ( ld->ld_errno == LDAP_TIMEOUT ) { - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 120, "cldap_result timed out\n"), 0, 0, 0 ); - /* - * It timed out; is it time to give up? - */ - if ( ++crip->cri_try >= crip->cri_maxtries ) { - ret = LDAP_TIMEOUT; - --crip->cri_try; - } else { - if ( ++crip->cri_useaddr >= sb->sb_naddr ) { - /* - * new round: reset address to first one and - * double the timeout - */ - crip->cri_useaddr = 0; - crip->cri_timeout <<= 1; - } - ret = -1; - } - - } else { - /* - * Got a response. It should look like: - * { msgid, logdn, { searchresponse...}} - */ - logdn = NULL; - - if ( ber_scanf( &ber, "ia", &id, &logdn ) == LBER_ERROR ) { - free( ber.ber_buf ); /* gack! */ - ret = LDAP_DECODING_ERROR; - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 121, "cldap_result: ber_scanf returned LBER_ERROR (%d)\n"), - ret, 0, 0 ); - } else if ( id != msgid ) { - free( ber.ber_buf ); /* gack! */ - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 122, "cldap_result: looking for msgid %1$d; got %2$d\n"), - msgid, id, 0 ); - ret = -1; /* ignore and keep looking */ - } else { - /* - * got a result: determine which server it came from - * decode into ldap message chain - */ - for ( fromaddr = 0; fromaddr < sb->sb_naddr; ++fromaddr ) { - if ( memcmp( &((struct sockaddr_in *) - sb->sb_addrs[ fromaddr ])->sin_addr, - &((struct sockaddr_in *)sb->sb_fromaddr)->sin_addr, - sizeof( struct in_addr )) == 0 ) { - break; - } - } - ret = cldap_parsemsg( ld, msgid, &ber, res, base ); - free( ber.ber_buf ); /* gack! */ - Debug( LDAP_DEBUG_TRACE, - catgets(slapdcat, 1, 123, "cldap_result got result (%d)\n"), ret, 0, 0 ); - } - - if ( logdn != NULL ) { - free( logdn ); - } - } - - - /* - * If we are giving up (successfully or otherwise) then - * abandon any outstanding requests. - */ - if ( ret != -1 ) { - i = crip->cri_try; - if ( i >= sb->sb_naddr ) { - i = sb->sb_naddr - 1; - } - - for ( ; i >= 0; --i ) { - if ( i == fromaddr ) { - continue; - } - sb->sb_useaddr = sb->sb_addrs[ i ]; - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 124, "cldap_result abandoning id %1$d (to %2$s)\n"), - msgid, inet_ntoa( ((struct sockaddr_in *) - sb->sb_useaddr)->sin_addr ), 0 ); - (void) ldap_abandon( ld, msgid ); - } - } - -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( ld->ld_errno = ret ); -} - - -static int -cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber, - LDAPMessage **res, char *base ) -{ - unsigned int tag, len; - int rc; - size_t baselen, slen; - char *dn, *p, *cookie; - LDAPMessage *chain, *prev, *ldm; - struct berval *bv; - - rc = LDAP_DECODING_ERROR; /* pessimistic */ - ldm = chain = prev = NULLMSG; - baselen = ( base == NULL ) ? 0 : strlen( base ); - bv = NULL; - - for ( tag = ber_first_element( ber, &len, &cookie ); - tag != LBER_DEFAULT && rc != LDAP_SUCCESS; - tag = ber_next_element( ber, &len, cookie )) { - if (( ldm = (LDAPMessage *)calloc( 1, sizeof(LDAPMessage))) - == NULL || ( ldm->lm_ber = alloc_ber_with_options( ld )) - == NULLBER ) { - rc = LDAP_NO_MEMORY; - break; /* return w/error*/ - } - ldm->lm_msgid = msgid; - ldm->lm_msgtype = tag; - - if ( tag == LDAP_RES_SEARCH_RESULT ) { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 125, "cldap_parsemsg got search result\n"), - 0, 0, 0 ); - - if ( ber_get_stringal( ber, &bv ) == LBER_DEFAULT ) { - break; /* return w/error */ - } - - if ( ber_printf( ldm->lm_ber, "to", tag, bv->bv_val, - bv->bv_len ) == -1 ) { - break; /* return w/error */ - } - ber_bvfree( bv ); - bv = NULL; - rc = LDAP_SUCCESS; - - } else if ( tag == LDAP_RES_SEARCH_ENTRY ) { - if ( ber_scanf( ber, "{aO", &dn, &bv ) == LBER_ERROR ) { - break; /* return w/error */ - } - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 126, "cldap_parsemsg entry %s\n"), dn, 0, 0 ); - if ( dn != NULL && *(dn + ( slen = strlen(dn)) - 1) == '*' && - baselen > 0 ) { - /* - * substitute original searchbase for trailing '*' - */ - if (( p = (char *)malloc( slen + baselen )) == NULL ) { - rc = LDAP_NO_MEMORY; - free( dn ); - break; /* return w/error */ - } - strcpy( p, dn ); - strcpy( p + slen - 1, base ); - free( dn ); - dn = p; - } - - if ( ber_printf( ldm->lm_ber, "t{so}", tag, dn, bv->bv_val, - bv->bv_len ) == -1 ) { - break; /* return w/error */ - } - free( dn ); - ber_bvfree( bv ); - bv = NULL; - - } else { - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 127, "cldap_parsemsg got unknown tag %d\n"), - tag, 0, 0 ); - rc = LDAP_PROTOCOL_ERROR; - break; /* return w/error */ - } - - /* Reset message ber so we can read from it later. Gack! */ - ldm->lm_ber->ber_end = ldm->lm_ber->ber_ptr; - ldm->lm_ber->ber_ptr = ldm->lm_ber->ber_buf; - -#ifdef LDAP_DEBUG - if ( ldap_debug & LDAP_DEBUG_PACKETS ) { - fprintf( stderr, "cldap_parsemsg add message id %d type %d:\n", - ldm->lm_msgid, ldm->lm_msgtype ); - ber_dump( ldm->lm_ber, 1 ); - } -#endif /* LDAP_DEBUG */ - -#ifndef NO_CACHE - if ( ld->ld_cache != NULL ) { - add_result_to_cache( ld, ldm ); - } -#endif /* NO_CACHE */ - - if ( chain == NULL ) { - chain = ldm; - } else { - prev->lm_chain = ldm; - } - prev = ldm; - ldm = NULL; - } - - /* dispose of any leftovers */ - if ( ldm != NULL ) { - if ( ldm->lm_ber != NULLBER ) { - ber_free( ldm->lm_ber, 1 ); - } - free( ldm ); - } - if ( bv != NULL ) { - ber_bvfree( bv ); - } - - /* return chain, calling result2error if we got anything at all */ - *res = chain; - return(( *res == NULLMSG ) ? rc : ldap_result2error( ld, *res, 0 )); -} -#endif /* CLDAP */
--- a/usr/src/lib/libldap4/common/compare.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,259 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * compare.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include "macos.h" -#endif /* MACOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -BerElement * ldap_build_compare_req(LDAP *ld, char *dn, char *attr, - struct berval *bvalue, LDAPControl **serverctrls) -{ - BerElement *ber; - int rc, rv; - - /* The compare request looks like this: - * CompareRequest ::= SEQUENCE { - * entry DistinguishedName, - * ava SEQUENCE { - * type AttributeType, - * value AttributeValue - * } - * } - * and must be wrapped in an LDAPMessage. - */ - /* create a message to send */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( NULLBER ); - } - - if ( ber_printf( ber, "{it{s{so}}", ++ld->ld_msgid, LDAP_REQ_COMPARE, - dn, attr, bvalue->bv_val, bvalue->bv_len ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - /* LDAPv3 */ - /* Code controls if any */ - if (serverctrls && serverctrls[0]) { - if (ldap_controls_code(ber, serverctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - return( NULLBER ); - } - } else if (ld->ld_srvctrls && ld->ld_srvctrls[0]) { - /* Otherwise, is there any global server ctrls ? */ - if (ldap_controls_code(ber, ld->ld_srvctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - return( NULLBER ); - } - } - if (ber_printf(ber, "}") == -1) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free(ber, 1); - return (NULLBER); - } - - return (ber); -} - -/* - * ldap_compare - perform an ldap (and X.500) compare operation. The dn - * of the entry to compare to and the attribute and value to compare (in - * attr and value) are supplied. The msgid of the response is returned. - * - * Example: - * ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" ) - */ -int -ldap_compare( LDAP *ld, char *dn, char *attr, char *value ) -{ - BerElement *ber; - struct berval bv; - int rv; - - /* The compare request looks like this: - * CompareRequest ::= SEQUENCE { - * entry DistinguishedName, - * ava SEQUENCE { - * type AttributeType, - * value AttributeValue - * } - * } - * and must be wrapped in an LDAPMessage. - */ - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 ); - - bv.bv_val = value; - bv.bv_len = strlen(value); - - if ((ber = ldap_build_compare_req(ld, dn, attr, &bv, NULL)) == NULLBER) { -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (-1); - } - -#ifndef NO_CACHE - if ( ld->ld_cache != NULL ) { - if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) { - ber_free( ber, 1 ); - ld->ld_errno = LDAP_SUCCESS; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return( ld->ld_msgid ); - } - add_request_to_cache( ld, LDAP_REQ_COMPARE, ber ); - } -#endif /* NO_CACHE */ - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ); -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); -} - -int -ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value ) -{ - int msgid; - LDAPMessage *res; - - if ( (msgid = ldap_compare( ld, dn, attr, value )) == -1 ) - return( ld->ld_errno ); - - if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) - return( ld->ld_errno ); - - return( ldap_result2error( ld, res, 1 ) ); -} - -/* LDAPv3 API extensions */ -int ldap_compare_ext(LDAP *ld, char *dn, char *attr, struct berval *bvalue, - LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp) -{ - BerElement *ber; - struct berval bv; - int rv; - - /* The compare request looks like this: - * CompareRequest ::= SEQUENCE { - * entry DistinguishedName, - * ava SEQUENCE { - * type AttributeType, - * value AttributeValue - * } - * } - * and must be wrapped in an LDAPMessage. - */ - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 ); - - if ((ber = ldap_build_compare_req(ld, dn, attr, bvalue, NULL)) == NULLBER) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS) - rv = LDAP_OTHER; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - -#ifndef NO_CACHE - if ( ld->ld_cache != NULL ) { - if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) { - ber_free( ber, 1 ); - ld->ld_errno = LDAP_SUCCESS; - *msgidp = ld->ld_msgid; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return( LDAP_SUCCESS ); - } - add_request_to_cache( ld, LDAP_REQ_COMPARE, ber ); - } -#endif /* NO_CACHE */ - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber ); - if (rv == -1) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS){ - rv = LDAP_OTHER; - } -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - - *msgidp = rv; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (LDAP_SUCCESS); -} - -int ldap_compare_ext_s(LDAP *ld, char *dn, char *attr, struct berval *bvalue, - LDAPControl ** serverctrls, LDAPControl **clientctrls) -{ - int msgid, retcode = LDAP_SUCCESS; - LDAPMessage *res; - - if ( (retcode = ldap_compare_ext( ld, dn, attr, bvalue, serverctrls, clientctrls, &msgid )) != LDAP_SUCCESS ) - return( retcode ); - - if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) - return( ld->ld_errno ); - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - retcode = ldap_parse_result( ld, res, &ld->ld_errno, &ld->ld_matched, &ld->ld_error, - &ld->ld_referrals, &ld->ld_ret_ctrls, 1); - if (retcode == LDAP_SUCCESS) - retcode = ld->ld_errno; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (retcode); -} -
--- a/usr/src/lib/libldap4/common/controls.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +0,0 @@ -/* - * - * Copyright 1999 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * - * Comments: - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -static int ldap_control_copy_contents(LDAPControl *, LDAPControl *); - -void ldap_control_free (LDAPControl *ctrl) -{ - if (ctrl != NULL){ - if (ctrl->ldctl_oid) - free (ctrl->ldctl_oid); - if (ctrl->ldctl_value.bv_val != NULL) - free (ctrl->ldctl_value.bv_val); - free ((char *)ctrl); - } - return; -} - -void ldap_controls_free (LDAPControl **ctrls) -{ - int i; - - if (ctrls == NULL) - return; - - for (i = 0; ctrls[i] != NULL; i++){ - ldap_control_free(ctrls[i]); - } - free((char *)ctrls); -} - -LDAPControl * ldap_control_dup(LDAPControl *ctrl) -{ - LDAPControl *newctrl; - - if ((newctrl = (LDAPControl *)calloc(1, sizeof(LDAPControl))) == NULL) - return (NULL); - - if (ldap_control_copy_contents(newctrl, ctrl) != LDAP_SUCCESS) { - free(newctrl); - return (NULL); - } - - return(newctrl); -} - - -static int ldap_control_copy_contents(LDAPControl *ctrl_dst, -LDAPControl *ctrl_src) -{ - size_t len; - - if (NULL == ctrl_dst || NULL == ctrl_src) { - return (LDAP_PARAM_ERROR); - } - - ctrl_dst->ldctl_iscritical = ctrl_src->ldctl_iscritical; - - /* fill in the fields of this new control */ - if ((ctrl_dst->ldctl_oid = strdup(ctrl_src->ldctl_oid)) == NULL) { - return (LDAP_NO_MEMORY); - } - - len = (size_t)(ctrl_src->ldctl_value).bv_len; - if (ctrl_src->ldctl_value.bv_val == NULL || len <= 0) { - ctrl_dst->ldctl_value.bv_len = 0; - ctrl_dst->ldctl_value.bv_val = NULL; - } else { - ctrl_dst->ldctl_value.bv_len = len; - if ((ctrl_dst->ldctl_value.bv_val = malloc(len)) - == NULL) { - free(ctrl_dst->ldctl_oid); - return (LDAP_NO_MEMORY); - } - SAFEMEMCPY(ctrl_dst->ldctl_value.bv_val, - ctrl_src->ldctl_value.bv_val, len); - } - - return (LDAP_SUCCESS); -} - - -LDAPControl ** ldap_controls_dup(LDAPControl ** ctrls) -{ - int i; - LDAPControl **newctrls; - - for (i = 0; ctrls[i] != NULL; i++); - newctrls = (LDAPControl **)calloc(i+1, sizeof(LDAPControl*)); - if (newctrls == NULL) { - return (NULL); - } - - for (i = 0; ctrls[i] != NULL; i++) { - newctrls[i] = ldap_control_dup(ctrls[i]); - if (newctrls[i] == NULL) { - ldap_controls_free(newctrls); - return (NULL); - } - } - return (newctrls); -} - -int ldap_controls_code (BerElement *ber, LDAPControl **ctrls) -{ - int i, rc; - - if (ctrls && ctrls[0]){ - rc = ber_printf(ber, "t{", LDAP_TAG_CONTROL_LIST); - if (rc == -1){ - ber_free(ber, 1); - return(LDAP_ENCODING_ERROR); - } - - for (i = 0; ctrls[i] != NULL; i++){ - rc = ber_printf(ber, "{s", ctrls[i]->ldctl_oid); - if (rc == -1){ - ber_free(ber, 1); - return(LDAP_ENCODING_ERROR); - } - if (ctrls[i]->ldctl_iscritical){ - rc = ber_printf(ber, "b", ctrls[i]->ldctl_iscritical); - if (rc == -1){ - ber_free(ber, 1); - return(LDAP_ENCODING_ERROR); - } - } - - if (ctrls[i]->ldctl_value.bv_val) - rc = ber_printf(ber, "o}", ctrls[i]->ldctl_value.bv_val, ctrls[i]->ldctl_value.bv_len); - else - rc = ber_printf(ber, "}"); - if (rc == -1){ - ber_free(ber, 1); - return(LDAP_ENCODING_ERROR); - } - } - - rc = ber_printf(ber, "}"); - if (rc == -1){ - ber_free(ber, 1); - return(LDAP_ENCODING_ERROR); - } - } - return (LDAP_SUCCESS); -} - -/* Decode the sequence of control from the ber, return a NULL terminated list of LDAPControl* */ -LDAPControl ** ldap_controls_decode(BerElement *ber, int *errcode) -{ - LDAPControl ** ctrls = NULL; - - char *opaque; - unsigned int tag, len; - int i = 0, count = 0; - - BerElement tmpber = *ber; - - for (tag = ber_first_element(&tmpber, &len, &opaque); - tag != LBER_DEFAULT; - tag = ber_next_element(&tmpber, &len, opaque )) { - count ++; - ber_skip_tag(&tmpber, &len); - } - - - if ((ctrls = (LDAPControl **)calloc(count + 1, sizeof(LDAPControl *))) == NULL){ - *errcode = LDAP_NO_MEMORY; - return(NULL); - } - - for (tag = ber_first_element(ber, &len, &opaque ); - tag != LBER_DEFAULT; - tag = ber_next_element (ber, &len, opaque )) { - LDAPControl *aCtrl; - unsigned int ttag, tlen; - - if ((aCtrl = (LDAPControl *)calloc(1, sizeof(LDAPControl))) == NULL) { - *errcode = LDAP_NO_MEMORY; - ldap_controls_free(ctrls); - return (NULL); - } - if (ber_scanf(ber, "{a", &aCtrl->ldctl_oid) == LBER_ERROR){ - *errcode = LDAP_PROTOCOL_ERROR; - free(aCtrl); - ldap_controls_free(ctrls); - return (NULL); - } - aCtrl->ldctl_iscritical = 0; - ttag = ber_peek_tag(ber, &tlen); - if (ttag == 0x01) { /* Boolean : criticality */ - if (ber_scanf(ber, "b", &aCtrl->ldctl_iscritical) == LBER_ERROR){ - *errcode = LDAP_PROTOCOL_ERROR; - free(aCtrl); - ldap_controls_free(ctrls); - return (NULL); - } - ttag = ber_peek_tag(ber, &tlen); - } - if (ttag == 0x04) { /* Octet string : value (it's optional)*/ - if (ber_scanf(ber, "o", &aCtrl->ldctl_value) == LBER_ERROR){ - *errcode = LDAP_PROTOCOL_ERROR; - free(aCtrl); - ldap_controls_free(ctrls); - return (NULL); - } - - } else if (ttag != LBER_DEFAULT){ - *errcode = LDAP_PROTOCOL_ERROR; - free(aCtrl); - ldap_controls_free(ctrls); - return (NULL); - } - - if (ber_scanf(ber, "}") == LBER_ERROR){ - *errcode = LDAP_PROTOCOL_ERROR; - free(aCtrl); - ldap_controls_free(ctrls); - return (NULL); - } - /* add aCtrl in ctrls */ - ctrls[i++] = aCtrl; - } - return (ctrls); -} - -/* build an allocated LDAPv3 control. Returns an LDAP error code. */ -int ldap_build_control(char *oid, BerElement *ber, int freeber, -char iscritical, LDAPControl **ctrlp) -{ - int rc; - struct berval *bvp; - - if (ber == NULL) { - bvp = NULL; - } else { - /* allocate struct berval with contents of the BER encoding */ - rc = ber_flatten(ber, &bvp); - if (freeber) { - ber_free(ber, 1); - } - if (rc == -1) { - return (LDAP_NO_MEMORY); - } - } - - /* allocate the new control structure */ - if ((*ctrlp = (LDAPControl *)calloc(1, sizeof (LDAPControl))) - == NULL) { - if (bvp != NULL) { - ber_bvfree(bvp); - } - return (LDAP_NO_MEMORY); - } - - /* fill in the fields of this new control */ - (*ctrlp)->ldctl_iscritical = iscritical; - if (((*ctrlp)->ldctl_oid = strdup(oid)) == NULL) { - free(*ctrlp); - *ctrlp = NULL; - if (bvp != NULL) { - ber_bvfree(bvp); - } - return (LDAP_NO_MEMORY); - } - - if (bvp == NULL) { - (*ctrlp)->ldctl_value.bv_len = 0; - (*ctrlp)->ldctl_value.bv_val = NULL; - } else { - (*ctrlp)->ldctl_value = *bvp; /* struct copy */ - free(bvp); /* free container, not contents! */ - } - - return (LDAP_SUCCESS); -}
--- a/usr/src/lib/libldap4/common/delete.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * delete.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include "macos.h" -#endif /* MACOS */ - -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#endif /* DOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -BerElement * ldap_build_delete_req(LDAP *ld, char *dn, LDAPControl **serverctrls) -{ - BerElement *ber; - int rv; - - /* create a message to send */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - ld->ld_errno = LDAP_NO_MEMORY; - return(NULLBER ); - } - - if ( ber_printf( ber, "{its", ++ld->ld_msgid, LDAP_REQ_DELETE, dn ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return(NULLBER ); - } - - /* LDAPv3 */ - /* Code controls if any */ - if (serverctrls && serverctrls[0]) { - if (ldap_controls_code(ber, serverctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } else if (ld->ld_srvctrls && ld->ld_srvctrls[0]) { - /* Otherwise, is there any global server ctrls ? */ - if (ldap_controls_code(ber, ld->ld_srvctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } - - if ( ber_printf( ber, "}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - return (ber); -} - -/* - * ldap_delete - initiate an ldap (and X.500) delete operation. Parameters: - * - * ld LDAP descriptor - * dn DN of the object to delete - * - * Example: - * msgid = ldap_delete( ld, dn ); - */ -int -ldap_delete( LDAP *ld, char *dn ) -{ - BerElement *ber; - int rv; - - /* - * A delete request looks like this: - * DelRequet ::= DistinguishedName, - */ - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 129, "ldap_delete\n"), 0, 0, 0 ); - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - - if (( ber = ldap_build_delete_req(ld, dn, NULL)) == NULLBER) { -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (-1); - } - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_DELETE, dn, ber ); -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return ( rv ); -} - - -int -ldap_delete_s( LDAP *ld, char *dn ) -{ - int msgid; - LDAPMessage *res; - - if ( (msgid = ldap_delete( ld, dn )) == -1 ) - return( ld->ld_errno ); - - if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) - return( ld->ld_errno ); - - return( ldap_result2error( ld, res, 1 ) ); -} - -/* ldapv3 API extensions */ - -int ldap_delete_ext(LDAP *ld, char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp) -{ - BerElement *ber; - int rv; - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 192, "ldap_modify\n"), 0, 0, 0 ); - - if ((ber = ldap_build_delete_req(ld, dn, serverctrls)) == NULLBER){ - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS) - rv = LDAP_OTHER; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_DELETE, dn, ber ); - if (rv == -1){ - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS){ - rv = LDAP_OTHER; - } -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - *msgidp = rv; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return ( LDAP_SUCCESS ); -} - -int ldap_delete_ext_s(LDAP *ld, char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls) -{ - int msgid; - int retcode = LDAP_SUCCESS; - LDAPMessage *res; - - if ((retcode = ldap_delete_ext(ld, dn, serverctrls, clientctrls, &msgid)) != LDAP_SUCCESS) - return (retcode); - if (ldap_result(ld, msgid, 1, (struct timeval *)NULL, &res ) == -1) - return (ld->ld_errno ); - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - retcode = ldap_parse_result( ld, res, &ld->ld_errno, &ld->ld_matched, &ld->ld_error, - &ld->ld_referrals, &ld->ld_ret_ctrls, 1); - if (retcode == LDAP_SUCCESS) - retcode = ld->ld_errno; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (retcode); -}
--- a/usr/src/lib/libldap4/common/disptmpl.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,751 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" -/* - * 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. - * - * disptmpl.c: display template library routines for LDAP clients - * 7 March 1994 by Mark C Smith - */ - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> -#ifdef MACOS -#include "macos.h" -#else /* MACOS */ -#ifdef DOS -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/file.h> -#ifndef VMS -#include <unistd.h> -#endif /* VMS */ -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifndef NEEDPROTOS -static void free_disptmpl(); -static int read_next_tmpl(); -int next_line_tokens(); -#else /* !NEEDPROTOS */ -static void free_disptmpl( struct ldap_disptmpl *tmpl ); -static int read_next_tmpl( char **bufp, ssize_t *blenp, - struct ldap_disptmpl **tmplp, int dtversion ); -int next_line_tokens( char **bufp, ssize_t *blenp, char ***toksp ); -#endif /* !NEEDPROTOS */ - -static char *tmploptions[] = { - "addable", "modrdn", - "altview", - NULL -}; - - -static unsigned int tmploptvals[] = { - LDAP_DTMPL_OPT_ADDABLE, LDAP_DTMPL_OPT_ALLOWMODRDN, - LDAP_DTMPL_OPT_ALTVIEW, -}; - - -static char *itemtypes[] = { - "cis", "mls", "dn", - "bool", "jpeg", "jpegbtn", - "fax", "faxbtn", "audiobtn", - "time", "date", "url", - "searchact", "linkact", "adddnact", - "addact", "verifyact", "mail", -#ifdef SUN - "protected", -#endif - NULL -}; - -static unsigned int itemsynids[] = { - LDAP_SYN_CASEIGNORESTR, LDAP_SYN_MULTILINESTR, LDAP_SYN_DN, - LDAP_SYN_BOOLEAN, LDAP_SYN_JPEGIMAGE, LDAP_SYN_JPEGBUTTON, - LDAP_SYN_FAXIMAGE, LDAP_SYN_FAXBUTTON, LDAP_SYN_AUDIOBUTTON, - LDAP_SYN_TIME, LDAP_SYN_DATE, LDAP_SYN_LABELEDURL, - LDAP_SYN_SEARCHACTION, LDAP_SYN_LINKACTION, LDAP_SYN_ADDDNACTION, - LDAP_SYN_ADDDNACTION, LDAP_SYN_VERIFYDNACTION,LDAP_SYN_RFC822ADDR, -#ifdef SUN - LDAP_SYN_PROTECTED, -#endif -}; - - -static char *itemoptions[] = { - "ro", "sort", - "1val", "hide", - "required", "hideiffalse", - NULL -}; - - -static unsigned int itemoptvals[] = { - LDAP_DITEM_OPT_READONLY, LDAP_DITEM_OPT_SORTVALUES, - LDAP_DITEM_OPT_SINGLEVALUED, LDAP_DITEM_OPT_HIDEIFEMPTY, - LDAP_DITEM_OPT_VALUEREQUIRED, LDAP_DITEM_OPT_HIDEIFFALSE, -}; - - -#define ADDEF_CONSTANT "constant" -#define ADDEF_ADDERSDN "addersdn" - -#ifdef SUN -/* LP@Sun : right_trim */ -static void right_trim(char *aStr) -{ - char * theEnd = aStr + strlen(aStr); - while ((theEnd > aStr) && isspace(*(theEnd - 1))) - theEnd--; - theEnd; - *theEnd= '\0'; -} -#endif - -int -ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp ) -{ - FILE *fp; - char *buf; - ssize_t rlen, len; - int rc, eof; - - *tmpllistp = NULLDISPTMPL; - - if (( fp = fopen( file, "r" )) == NULL ) { - return( LDAP_TMPL_ERR_FILE ); - } - - if ( fseek( fp, 0L, SEEK_END ) != 0 ) { /* move to end to get len */ - fclose( fp ); - return( LDAP_TMPL_ERR_FILE ); - } - - len = ftell( fp ); - - if ( fseek( fp, 0L, SEEK_SET ) != 0 ) { /* back to start of file */ - fclose( fp ); - return( LDAP_TMPL_ERR_FILE ); - } - - if (( buf = malloc( len )) == NULL ) { - fclose( fp ); - return( LDAP_TMPL_ERR_MEM ); - } - - rlen = fread( buf, (size_t) 1, len, fp ); - eof = feof( fp ); - fclose( fp ); - - if ( rlen != len && !eof ) { /* error: didn't get the whole file */ - free( buf ); - return( LDAP_TMPL_ERR_FILE ); - } - - rc = ldap_init_templates_buf( buf, rlen, tmpllistp ); - free( buf ); - - return( rc ); -} - - -int -ldap_init_templates_buf( char *buf, ssize_t 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 ); -} - - - -void -ldap_free_templates( struct ldap_disptmpl *tmpllist ) -{ - struct ldap_disptmpl *tp, *nexttp; - - if ( tmpllist != NULL ) { - for ( tp = tmpllist; tp != NULL; tp = nexttp ) { - nexttp = tp->dt_next; - free_disptmpl( tp ); - } - } -} - - -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 ); - } -} - - -struct ldap_disptmpl * -ldap_first_disptmpl( struct ldap_disptmpl *tmpllist ) -{ - return( tmpllist ); -} - - -struct ldap_disptmpl * -ldap_next_disptmpl( struct ldap_disptmpl *tmpllist, - struct ldap_disptmpl *tmpl ) -{ - return( tmpl == NULLDISPTMPL ? tmpl : tmpl->dt_next ); -} - - -struct ldap_disptmpl * -ldap_name2template( char *name, struct ldap_disptmpl *tmpllist ) -{ - struct ldap_disptmpl *dtp; - - for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL; - dtp = ldap_next_disptmpl( tmpllist, dtp )) { - if ( strcasecmp( name, dtp->dt_name ) == 0 ) { - return( dtp ); - } - } - - return( NULLDISPTMPL ); -} - - -struct ldap_disptmpl * -ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist ) -{ - struct ldap_disptmpl *dtp; - struct ldap_oclist *oclp; - int i, j, needcnt, matchcnt; - - if ( tmpllist == NULL || oclist == NULL || oclist[ 0 ] == NULL ) { - return( NULLDISPTMPL ); - } - - for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL; - dtp = ldap_next_disptmpl( tmpllist, dtp )) { - for ( oclp = dtp->dt_oclist; oclp != NULLOCLIST; - oclp = oclp->oc_next ) { - needcnt = matchcnt = 0; - for ( i = 0; oclp->oc_objclasses[ i ] != NULL; ++i ) { - for ( j = 0; oclist[ j ] != NULL; ++j ) { -#ifdef SUN - /* LP@Sun : remove ending space from objectclass */ - right_trim(oclist[j]); -#endif - if ( strcasecmp( oclist[ j ], oclp->oc_objclasses[ i ] ) - == 0 ) { - ++matchcnt; - } - } - ++needcnt; - } - - if ( matchcnt == needcnt ) { - return( dtp ); - } - } - } - - return( NULLDISPTMPL ); -} - - -struct ldap_tmplitem * -ldap_first_tmplrow( struct ldap_disptmpl *tmpl ) -{ - return( tmpl->dt_items ); -} - - -struct ldap_tmplitem * -ldap_next_tmplrow( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row ) -{ - return( row == NULLTMPLITEM ? row : row->ti_next_in_col ); -} - - -struct ldap_tmplitem * -ldap_first_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row ) -{ - return( row ); -} - - -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 ); -} - - -char ** -ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs, - int exclude, unsigned int syntaxmask ) -{ -/* - * this routine should filter out duplicate attributes... - */ - struct ldap_tmplitem *tirowp, *ticolp; - int i, attrcnt, memerr; - char **attrs; - - attrcnt = 0; - memerr = 0; - - if (( attrs = (char **)malloc( sizeof( char * ))) == NULL ) { - return( NULL ); - } - - if ( includeattrs != NULL ) { - for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) { - if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) * - sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] = - strdup( includeattrs[ i ] )) == NULL ) { - memerr = 1; - } else { - attrs[ attrcnt ] = NULL; - } - } - } - - for ( tirowp = ldap_first_tmplrow( tmpl ); - !memerr && tirowp != NULLTMPLITEM; - tirowp = ldap_next_tmplrow( tmpl, tirowp )) { - for ( ticolp = ldap_first_tmplcol( tmpl, tirowp ); - ticolp != NULLTMPLITEM; - ticolp = ldap_next_tmplcol( tmpl, tirowp, ticolp )) { - - if ( syntaxmask != 0 ) { - if (( exclude && - ( syntaxmask & ticolp->ti_syntaxid ) != 0 ) || - ( !exclude && - ( syntaxmask & ticolp->ti_syntaxid ) == 0 )) { - continue; - } - } - - if ( ticolp->ti_attrname != NULL ) { - if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) * - sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] = - strdup( ticolp->ti_attrname )) == NULL ) { - memerr = 1; - } else { - attrs[ attrcnt ] = NULL; - } - } - } - } - - if ( memerr || attrcnt == 0 ) { - for ( i = 0; i < attrcnt; ++i ) { - if ( attrs[ i ] != NULL ) { - free( attrs[ i ] ); - } - } - - free( (char *)attrs ); - return( NULL ); - } - - return( attrs ); -} - - -static int -read_next_tmpl( char **bufp, ssize_t *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( (size_t) 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( (size_t) 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( (size_t) 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( (size_t) 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( (size_t) (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 ); -}
--- a/usr/src/lib/libldap4/common/dsparse.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * 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" -#include "ldap-private.h" -#include "ldap-int.h" - -#ifndef NEEDPROTOS -int next_line_tokens(); -static ssize_t next_line(); -static char *next_token(); -#else /* !NEEDPROTOS */ -int next_line_tokens( char **bufp, ssize_t *blenp, char ***toksp ); -static ssize_t next_line( char **bufp, ssize_t *blenp, char **linep ); -static char *next_token( char ** sp ); -#endif /* !NEEDPROTOS */ - - - -int -next_line_tokens( char **bufp, ssize_t *blenp, char ***toksp ) -{ - char *p, *line, *token, **toks; - ssize_t rc; - int tokcnt; - - *toksp = NULL; - - if (( rc = next_line( bufp, blenp, &line )) <= 0 ) { - return( (int)rc ); - } - - if (( toks = (char **)calloc( (size_t) 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 ssize_t -next_line( char **bufp, ssize_t *blenp, char **linep ) -{ - char *linestart, *line, *p; - ssize_t 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 )); -}
--- a/usr/src/lib/libldap4/common/error.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,345 +0,0 @@ -/* - * Portions Copyright 1999 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> /* free() for Solaris */ -#ifdef MACOS -#include <stdlib.h> -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -struct ldaperror { - int e_code; - char *e_reason; -}; - -static struct ldaperror ldap_errlist[] = { -#ifdef SUN - LDAP_SUCCESS, 0, - LDAP_OPERATIONS_ERROR, 0, - LDAP_PROTOCOL_ERROR, 0, - LDAP_TIMELIMIT_EXCEEDED, 0, - LDAP_SIZELIMIT_EXCEEDED, 0, - LDAP_COMPARE_FALSE, 0, - LDAP_COMPARE_TRUE, 0, - LDAP_AUTH_METHOD_NOT_SUPPORTED, 0, - LDAP_STRONG_AUTH_REQUIRED, 0, - LDAP_PARTIAL_RESULTS, 0, -/* new with ldapv3 */ - LDAP_REFERRAL, 0, - LDAP_ADMINLIMIT_EXCEEDED, 0, - LDAP_UNAVAILABLE_CRITICAL_EXTENSION, 0, - LDAP_CONFIDENTIALITY_REQUIRED, 0, -/* end of new */ - LDAP_NO_SUCH_ATTRIBUTE, 0, - LDAP_UNDEFINED_TYPE, 0, - LDAP_INAPPROPRIATE_MATCHING, 0, - LDAP_CONSTRAINT_VIOLATION, 0, - LDAP_TYPE_OR_VALUE_EXISTS, 0, - LDAP_INVALID_SYNTAX, 0, - LDAP_NO_SUCH_OBJECT, 0, - LDAP_ALIAS_PROBLEM, 0, - LDAP_INVALID_DN_SYNTAX, 0, - LDAP_IS_LEAF, 0, - LDAP_ALIAS_DEREF_PROBLEM, 0, - LDAP_INAPPROPRIATE_AUTH, 0, - LDAP_INVALID_CREDENTIALS, 0, - LDAP_INSUFFICIENT_ACCESS, 0, - LDAP_BUSY, 0, - LDAP_UNAVAILABLE, 0, - LDAP_UNWILLING_TO_PERFORM, 0, - LDAP_LOOP_DETECT, 0, - LDAP_NAMING_VIOLATION, 0, - LDAP_OBJECT_CLASS_VIOLATION, 0, - LDAP_NOT_ALLOWED_ON_NONLEAF, 0, - LDAP_NOT_ALLOWED_ON_RDN, 0, - LDAP_ALREADY_EXISTS, 0, - LDAP_NO_OBJECT_CLASS_MODS, 0, - LDAP_RESULTS_TOO_LARGE, 0, -/* new with ldapv3 */ - LDAP_AFFECTS_MULTIPLE_DSAS, 0, -/* end of new */ - LDAP_OTHER, 0, - LDAP_SERVER_DOWN, 0, - LDAP_LOCAL_ERROR, 0, - LDAP_ENCODING_ERROR, 0, - LDAP_DECODING_ERROR, 0, - LDAP_TIMEOUT, 0, - LDAP_AUTH_UNKNOWN, 0, - LDAP_FILTER_ERROR, 0, - LDAP_USER_CANCELLED, 0, - LDAP_PARAM_ERROR, 0, - LDAP_NO_MEMORY, 0, -/* new with ldapv3 */ - LDAP_CONNECT_ERROR, 0, - LDAP_NOT_SUPPORTED, 0, - LDAP_CONTROL_NOT_FOUND, 0, - LDAP_NO_RESULTS_RETURNED, 0, - LDAP_MORE_RESULTS_TO_RETURN, 0, - LDAP_CLIENT_LOOP, 0, - LDAP_REFERRAL_LIMIT_EXCEEDED, 0, -/* end of new */ -#else - LDAP_SUCCESS, "Success", - LDAP_OPERATIONS_ERROR, "Operations error", - LDAP_PROTOCOL_ERROR, "Protocol error", - LDAP_TIMELIMIT_EXCEEDED, "Timelimit exceeded", - LDAP_SIZELIMIT_EXCEEDED, "Sizelimit exceeded", - LDAP_COMPARE_FALSE, "Compare false", - LDAP_COMPARE_TRUE, "Compare true", - LDAP_AUTH_METHOD_NOT_SUPPORTED, "Authentication method not supported", - LDAP_STRONG_AUTH_REQUIRED, "Strong authentication required", - LDAP_PARTIAL_RESULTS, "Partial results and referral received", -/* new with ldapv3 */ - LDAP_REFERRAL, "Referral received", - LDAP_ADMINLIMIT_EXCEEDED, "Admin. limit exceeded", - LDAP_UNAVAILABLE_CRITICAL_EXTENSION, "Unavailable critical extension", - LDAP_CONFIDENTIALITY_REQUIRED, "Confidentiality required", -/* end of new */ - LDAP_NO_SUCH_ATTRIBUTE, "No such attribute", - LDAP_UNDEFINED_TYPE, "Undefined attribute type", - LDAP_INAPPROPRIATE_MATCHING, "Inappropriate matching", - LDAP_CONSTRAINT_VIOLATION, "Constraint violation", - LDAP_TYPE_OR_VALUE_EXISTS, "Type or value exists", - LDAP_INVALID_SYNTAX, "Invalid syntax", - LDAP_NO_SUCH_OBJECT, "No such object", - LDAP_ALIAS_PROBLEM, "Alias problem", - LDAP_INVALID_DN_SYNTAX, "Invalid DN syntax", - LDAP_IS_LEAF, "Object is a leaf", - LDAP_ALIAS_DEREF_PROBLEM, "Alias dereferencing problem", - LDAP_INAPPROPRIATE_AUTH, "Inappropriate authentication", - LDAP_INVALID_CREDENTIALS, "Invalid credentials", - LDAP_INSUFFICIENT_ACCESS, "Insufficient access", - LDAP_BUSY, "DSA is busy", - LDAP_UNAVAILABLE, "DSA is unavailable", - LDAP_UNWILLING_TO_PERFORM, "DSA is unwilling to perform", - LDAP_LOOP_DETECT, "Loop detected", - LDAP_NAMING_VIOLATION, "Naming violation", - LDAP_OBJECT_CLASS_VIOLATION, "Object class violation", - LDAP_NOT_ALLOWED_ON_NONLEAF, "Operation not allowed on nonleaf", - LDAP_NOT_ALLOWED_ON_RDN, "Operation not allowed on RDN", - LDAP_ALREADY_EXISTS, "Already exists", - LDAP_NO_OBJECT_CLASS_MODS, "Cannot modify object class", - LDAP_RESULTS_TOO_LARGE, "Results too large", -/* new with ldapv3 */ - LDAP_AFFECTS_MULTIPLE_DSAS, "Affects multiple DSAs", -/* end of new */ - LDAP_OTHER, "Unknown error", - LDAP_SERVER_DOWN, "Can't contact LDAP server", - LDAP_LOCAL_ERROR, "Local error", - LDAP_ENCODING_ERROR, "Encoding error", - LDAP_DECODING_ERROR, "Decoding error", - LDAP_TIMEOUT, "Timed out", - LDAP_AUTH_UNKNOWN, "Unknown authentication method", - LDAP_FILTER_ERROR, "Bad search filter", - LDAP_USER_CANCELLED, "User cancelled operation", - LDAP_PARAM_ERROR, "Bad parameter to an ldap routine", - LDAP_NO_MEMORY, "Out of memory", -/* new with ldapv3 */ - LDAP_CONNECT_ERROR, "Connection error", - LDAP_NOT_SUPPORTED, "Not supported", - LDAP_CONTROL_NOT_FOUND, "Control not found", - LDAP_NO_RESULTS_RETURNED, "No results have been returned", - LDAP_MORE_RESULTS_TO_RETURN, "More results to return", - LDAP_CLIENT_LOOP, "Loop detected in referrals", - LDAP_REFERRAL_LIMIT_EXCEEDED, "Too many referrals followed", -/* end of new */ -#endif - -1, 0 -}; - -#ifdef SUN -#pragma init (fill_ldap_errlist) - -static void fill_ldap_errlist() -{ - int i=0; - Debug(LDAP_DEBUG_TRACE, "fill_ldap_errlist\n", 0, 0, 0 ); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 130, "Success"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 131, "Operations error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 132, "Protocol error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 133, "Timelimit exceeded"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 134, "Sizelimit exceeded"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 135, "Compare false"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 136, "Compare true"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 137, "Strong authentication not supported"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 138, "Strong authentication required"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 139, "Partial results and referral received"); -/* new with ldapv3 */ - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1262, "Referral received"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1263, "Admin. limit exceeded"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1264, "Unavailable critical extension"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1265, "Confidentiality required"); -/* end of new */ - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 140, "No such attribute"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 141, "Undefined attribute type"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 142, "Inappropriate matching"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 143, "Constraint violation"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 144, "Type or value exists"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 145, "Invalid syntax"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 146, "No such object"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 147, "Alias problem"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 148, "Invalid DN syntax"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 149, "Object is a leaf"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 150, "Alias dereferencing problem"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 151, "Inappropriate authentication"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 152, "Invalid credentials"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 153, "Insufficient access"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 154, "DSA is busy"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 155, "DSA is unavailable"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 156, "DSA is unwilling to perform"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 157, "Loop detected"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 158, "Naming violation"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 159, "Object class violation"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 160, "Operation not allowed on nonleaf"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 161, "Operation not allowed on RDN"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 162, "Already exists"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 163, "Cannot modify object class"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 164, "Results too large"); -/* new with ldapv3 */ - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1266, "Affects multiple DSAs"); -/* end of new */ - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 165, "Unknown error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 166, "Can't contact LDAP server"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 167, "Local error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 168, "Encoding error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 169, "Decoding error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 170, "Timed out"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 171, "Unknown authentication method"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 172, "Bad search filter"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 173, "User cancelled operation"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 174, "Bad parameter to an ldap routine"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 175, "Out of memory"); - - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1267, "Connection error"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1268, "Not supported"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1269, "Control not found"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1270, "No results have been returned"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1271, "More results to return"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1272, "Loop detected in referrals"); - ldap_errlist[i++].e_reason = catgets(slapdcat, 1, 1273, "Too many referrals followed"); -} -#endif - -char * -ldap_err2string( int err ) -{ - int i; - - Debug( LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0 ); - - for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) { - if ( err == ldap_errlist[i].e_code ) - return( ldap_errlist[i].e_reason ); - } - - return( catgets(slapdcat, 1 , 165, "Unknown error") ); -} - -#ifndef NO_USERINTERFACE -void -ldap_perror( LDAP *ld, char *s ) -{ - int i; - - Debug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 ); - - if ( ld == NULL ) { - perror( s ); - return; - } -#ifdef SUN - /* for I18N */ - if ( ldap_errlist[0].e_reason == NULL ) { - fill_ldap_errlist(); - } /* end if */ -#endif - - for ( i = 0; ldap_errlist[i].e_code != -1; i++ ) { - if ( ld->ld_errno == ldap_errlist[i].e_code ) { - (void) fprintf( stderr, "%s: %s\n", s, - ldap_errlist[i].e_reason ); - if ( ld->ld_matched != NULL && *ld->ld_matched != '\0' ) - (void) fprintf( stderr, catgets(slapdcat, 1, 176, "%1$s: matched: %2$s\n"), s, - ld->ld_matched ); - if ( ld->ld_error != NULL && *ld->ld_error != '\0' ) - (void) fprintf( stderr, catgets(slapdcat, 1, 177, "%1$s: additional info: %2$s\n"), - s, ld->ld_error ); - (void) fflush( stderr ); - return; - } - } - - (void) fprintf( stderr, catgets(slapdcat, 1, 178, "%1$s: Not an LDAP errno %2$d\n"), s, ld->ld_errno ); - (void) fflush( stderr ); -} - -#else - -void -ldap_perror( LDAP *ld, char *s ) -{ -} - -#endif /* NO_USERINTERFACE */ - - -int -ldap_result2error( LDAP *ld, LDAPMessage *r, int freeit ) -{ - LDAPMessage *lm; - BerElement ber; - int along; - int rc; - - Debug( LDAP_DEBUG_TRACE, "ldap_result2error\n", 0, 0, 0 ); - - if ( r == NULLMSG ) - return( LDAP_PARAM_ERROR ); - - for ( lm = r; lm->lm_chain != NULL; lm = lm->lm_chain ) - ; /* NULL */ - - if ( ld->ld_error ) { - free( ld->ld_error ); - ld->ld_error = NULL; - } - if ( ld->ld_matched ) { - free( ld->ld_matched ); - ld->ld_matched = NULL; - } - - ber = *(lm->lm_ber); - if ( ld->ld_version == LDAP_VERSION2 ) { - rc = ber_scanf( &ber, "{iaa}", &along, &ld->ld_matched, - &ld->ld_error ); - } else { - rc = ber_scanf( &ber, "{ia}", &along, &ld->ld_error ); - } - if ( rc == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - } else { - ld->ld_errno = along; - } - - if ( freeit ) - ldap_msgfree( r ); - - return( ld->ld_errno ); -}
--- a/usr/src/lib/libldap4/common/extensions.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * - * Copyright 1999 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * - * Comments: - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include "macos.h" -#endif /* MACOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -int ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output) -{ - BerElement *ber; - int rc; - - if (NULL == ld || NULL == output) - return (LDAP_PARAM_ERROR); - - if ((ber = ber_alloc_t(LBER_USE_DER)) == NULLBER){ - return (LDAP_NO_MEMORY); - } - - if (ber_printf(ber, "{io}", pagesize, - (cookie && cookie->bv_val) ? cookie->bv_val : "", - (cookie && cookie->bv_val) ? cookie->bv_len : 0) - == LBER_ERROR) { - ber_free(ber, 1); - return (LDAP_ENCODING_ERROR); - } - - rc = ldap_build_control(LDAP_CONTROL_SIMPLE_PAGE, ber, 1, isCritical, - output); - - ld->ld_errno = rc; - return (rc); -} - -int ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie) -{ - int i, rc; - BerElement *theBer; - LDAPControl *listCtrlp; - - for (i = 0; controls[i] != NULL; i++){ - if (strcmp(controls[i]->ldctl_oid, "1.2.840.113556.1.4.319") == 0) { - listCtrlp = controls[i]; - if ((theBer = ber_init(&listCtrlp->ldctl_value)) == NULLBER){ - return (LDAP_NO_MEMORY); - } - if ((rc = ber_scanf(theBer, "{iO}", totalcount, cookie)) == LBER_ERROR){ - ber_free(theBer, 1); - return (LDAP_DECODING_ERROR); - } - ber_free(theBer, 1); - return (LDAP_SUCCESS); - } - } - return (LDAP_CONTROL_NOT_FOUND); -} -
--- a/usr/src/lib/libldap4/common/extop.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +0,0 @@ -/* - * - * Copyright 1999 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * - * Comments: - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include "macos.h" -#endif /* MACOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -BerElement * ldap_build_extended_operation_req(LDAP *ld, char *exoid, struct berval *exdata, LDAPControl ** serverctrls) -{ - BerElement *ber; - int rv; - - /* an extended operation request looks like this: - * ExtendedRequest ::= [APPLICATION 23] SEQUENCE { - * requestName [0] LDAPOID, - * requestValue [1] OCTECT STRING OPTIONAL - * } - */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - ld->ld_errno = LDAP_NO_MEMORY; - return( NULLBER ); - } - - if ( ber_printf( ber, "{it{ts", ++ld->ld_msgid, LDAP_REQ_EXTENDED, LDAP_TAG_EXT_NAME, exoid ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - if (exdata && (ber_printf(ber, "to", LDAP_TAG_EXT_VAL, exdata->bv_val, exdata->bv_len) == -1 )) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - if ( ber_printf( ber, "}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - /* LDAPv3 */ - /* Code controls if any */ - if (serverctrls && serverctrls[0]) { - if (ldap_controls_code(ber, serverctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } else if (ld->ld_srvctrls && ld->ld_srvctrls[0]) { - /* Otherwise, is there any global server ctrls ? */ - if (ldap_controls_code(ber, ld->ld_srvctrls) != LDAP_SUCCESS){ - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - } - - if ( ber_printf( ber, "}" ) == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( NULLBER ); - } - - return (ber); -} - -/* ldap_extended_operation - initiate an ldap extended operation. - * Parameters : - * ld : LDAP descriptor. - * exoid : OID of the request. - * exdata : Arbitrary data required by the operation. - * serverctrls : List of server controls. - * clientctrls : List of client controls. - * msgidp : msg id returned if operation succeeded. - * Returns LDAP_SUCCESS or error code. - */ - -int ldap_extended_operation(LDAP *ld, char *exoid, struct berval *exdata, - LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp) -{ - BerElement *ber; - int rv; - -#ifdef _REENTRANT - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 242, "ldap_extended_operation\n"), 0, 0, 0 ); - - if (( ber = ldap_build_extended_operation_req( ld, exoid, exdata, serverctrls)) == NULLBER ) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS) - rv = LDAP_OTHER; -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return( rv); - } - - /* send the message */ - rv = send_initial_request( ld, LDAP_REQ_EXTENDED, NULL, ber ); - if (rv == -1) { - rv = ld->ld_errno; - if (rv == LDAP_SUCCESS){ - rv = LDAP_OTHER; - } -#ifdef _REENTRANT - UNLOCK_LDAP(ld); -#endif - return (rv); - } - - *msgidp = rv; -#if _REENTRANT - UNLOCK_LDAP(ld); -#endif - return ( LDAP_SUCCESS ); -} - - -int ldap_extended_operation_s(LDAP *ld, char *exoid, struct berval *exdata, - LDAPControl **serverctrls, LDAPControl **clientctrls, - char **retoidp, struct berval **retdatap) -{ - int msgid; - int retcode; - LDAPMessage *res = NULL; - - if ((retcode = ldap_extended_operation(ld, exoid, exdata, serverctrls, clientctrls, &msgid)) != LDAP_SUCCESS) - return (retcode); - if (ldap_result(ld, msgid, 1, (struct timeval *)NULL, &res ) == -1) - return (ld->ld_errno ); - - return (ldap_parse_extended_result(ld, res, retoidp, retdatap, 1)); -}
--- a/usr/src/lib/libldap4/common/free.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * - * Portions Copyright 1999 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1994 The Regents of the University of Michigan. - * All rights reserved. - * - * free.c - some free routines are included here to avoid having to - * 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 <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 "ldap-private.h" - -void -ldap_getfilter_free( LDAPFiltDesc *lfdp ) -{ - 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 ); -} - -/* - * free a null-terminated array of pointers to mod structures. the - * structures are freed, not the array itself, unless the freemods - * flag is set. - */ - -void -ldap_mods_free( LDAPMod **mods, int freemods ) -{ - int i; - - if ( mods == NULL ) - return; - - 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_type) - free(mods[i]->mod_type); - free( (char *) mods[i] ); - } - - if ( freemods ) - free( (char *) mods ); -}
--- a/usr/src/lib/libldap4/common/friendly.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* - * - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * friendly.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> /* malloc(), free() for Solaris */ -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#endif /* MACOS */ - -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#endif /* DOS */ - -#if !defined( MACOS ) && !defined( DOS ) -#include <errno.h> -#include <sys/types.h> -#include <sys/socket.h> -#endif - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -char * -ldap_friendly_name( char *filename, char *uname, FriendlyMap **map ) -{ - int i, entries; - FILE *fp; - char *s; - char buf[BUFSIZ]; - - if ( map == NULL ) { -#if !defined( MACOS ) && !defined( DOS ) - errno = EINVAL; -#endif - return( uname ); - } - - if ( *map == NULL ) { - if ( (fp = fopen( filename, "r" )) == NULL ) - return( uname ); - - entries = 0; - while ( fgets( buf, sizeof(buf), fp ) != NULL ) { - if ( buf[0] != '#' ) - entries++; - } - rewind( fp ); - - if ( (*map = (FriendlyMap *) malloc( (entries + 1) * - sizeof(FriendlyMap) )) == NULL ) { - (void) fclose( fp ); - return( uname ); - } - - i = 0; - while ( fgets( buf, sizeof(buf), fp ) != NULL && i < entries ) { - if ( buf[0] == '#' ) - continue; - - if ( (s = strchr( buf, '\n' )) != NULL ) - *s = '\0'; - - if ( (s = strchr( buf, '\t' )) == NULL ) - continue; - *s++ = '\0'; - - if ( *s == '"' ) { - int esc = 0, found = 0; - - for ( ++s; *s && !found; s++ ) { - switch ( *s ) { - case '\\': - esc = 1; - break; - case '"': - if ( !esc ) - found = 1; - /* FALL */ - default: - esc = 0; - break; - } - } - } - - (*map)[i].f_unfriendly = strdup( buf ); - (*map)[i].f_friendly = strdup( s ); - i++; - } - - (void) fclose( fp ); - (*map)[i].f_unfriendly = NULL; - } - - for ( i = 0; (*map)[i].f_unfriendly != NULL; i++ ) { - if ( strcasecmp( uname, (*map)[i].f_unfriendly ) == 0 ) - return( (*map)[i].f_friendly ); - } - return( uname ); -} - - -void -ldap_free_friendlymap( FriendlyMap **map ) -{ - struct friendly* pF = *map; - - if ( pF == NULL ) - return; - - while ( pF->f_unfriendly ) - { - free( pF->f_unfriendly ); - free( pF->f_friendly ); - pF++; - } - free( *map ); - *map = NULL; -}
--- a/usr/src/lib/libldap4/common/getattr.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Portions Copyright 2001 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * getattr.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -char * -ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber ) -{ - int len; - char *attrbuffer; - - if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) { - return (NULL); - } - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 179, "ldap_first_attribute\n"), 0, 0, 0 ); - - if ( (*ber = alloc_ber_with_options( ld )) == NULLBER ) { - free(attrbuffer); - return( NULL ); - } - - **ber = *entry->lm_ber; - - /* - * Skip past the sequence, dn, sequence of sequence, snarf the - * attribute type, and skip the set of values, leaving us - * positioned right before the next attribute type/value sequence. - */ - - len = LDAP_MAX_ATTR_LEN; - if ( ber_scanf( *ber, "{x{{sx}", attrbuffer, &len ) - == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - ber_free( *ber, 0 ); - *ber = NULL; - free(attrbuffer); - return( NULL ); - } - - return( attrbuffer ); -} - -/* ARGSUSED */ -char * -ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber ) -{ - int len; - char *attrbuffer; - - if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) { - return (NULL); - } - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 180, "ldap_next_attribute\n"), 0, 0, 0 ); - - /* skip sequence, snarf attribute type, skip values */ - len = LDAP_MAX_ATTR_LEN; - if ( ber_scanf( ber, "{sx}", attrbuffer, &len ) - == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - free(attrbuffer); - return( NULL ); - } - ld->ld_errno = LDAP_SUCCESS; - return( attrbuffer ); -} - -void ldap_memfree(char *mem) -{ - free(mem); -} -
--- a/usr/src/lib/libldap4/common/getdn.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,412 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1994 Regents of the University of Michigan. - * All rights reserved. - * - * getdn.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> /* malloc(), realloc(), calloc() for Solaris */ -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -char * -ldap_get_dn( LDAP *ld, LDAPMessage *entry ) -{ - char *dn; - BerElement tmp; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 181, "ldap_get_dn\n"), 0, 0, 0 ); - - if ( entry == NULL ) { - ld->ld_errno = LDAP_PARAM_ERROR; - return( NULL ); - } - - tmp = *entry->lm_ber; /* struct copy */ - if ( ber_scanf( &tmp, "{a", &dn ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - return( dn ); -} - -char * -ldap_dn2ufn( char *dn ) -{ - char *p, *ufn, *r; - int state; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 182, "ldap_dn2ufn\n"), 0, 0, 0 ); - - if ( ldap_is_dns_dn( dn ) || ( p = strchr( dn, '=' )) == NULL ) - return( strdup( dn )); - - ufn = strdup( ++p ); - -#define INQUOTE 1 -#define OUTQUOTE 2 - state = OUTQUOTE; - for ( p = ufn, r = ufn; *p; p++ ) { - switch ( *p ) { - case '\\': - if ( *++p == '\0' ) - p--; - else { - *r++ = '\\'; - *r++ = *p; - } - break; - case '"': - if ( state == INQUOTE ) - state = OUTQUOTE; - else - state = INQUOTE; - *r++ = *p; - break; - case ';': - case ',': - if ( state == OUTQUOTE ) - *r++ = ','; - else - *r++ = *p; - break; - case '=': - if ( state == INQUOTE ) - *r++ = *p; - else { - char *rsave = r; - - *r-- = '\0'; - while ( !isspace( *r ) && *r != ';' - && *r != ',' && r > ufn ) - r--; - r++; - - if ( strcasecmp( r, "c" ) - && strcasecmp( r, "o" ) - && strcasecmp( r, "ou" ) - && strcasecmp( r, "st" ) - && strcasecmp( r, "l" ) - && strcasecmp( r, "cn" ) ) { - r = rsave; - *r++ = '='; - } - } - break; - default: - *r++ = *p; - break; - } - } - *r = '\0'; - - return( ufn ); -} - -char ** -ldap_explode_dns( char *dn ) -{ - int ncomps, maxcomps; - char *s; - char **rdns; - - if ( (rdns = (char **) malloc( 8 * sizeof(char *) )) == NULL ) { - return( NULL ); - } - - maxcomps = 8; - ncomps = 0; - for ( s = strtok( dn, "@." ); s != NULL; s = strtok( NULL, "@." ) ) { - if ( ncomps == maxcomps ) { - maxcomps *= 2; - if ( (rdns = (char **) realloc( rdns, maxcomps * - sizeof(char *) )) == NULL ) { - return( NULL ); - } - } - rdns[ncomps++] = strdup( s ); - } - rdns[ncomps] = NULL; - - return( rdns ); -} - -char ** -ldap_explode_dn( char *dn, int notypes ) -{ - char *p, *q, *rdnstart, **rdns = NULL; - int state, count = 0, endquote; - ssize_t len; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 183, "ldap_explode_dn\n"), 0, 0, 0 ); - - if ( ldap_is_dns_dn( dn ) ) { - return( ldap_explode_dns( dn ) ); - } - - rdnstart = dn; - p = dn-1; - state = OUTQUOTE; - - do { - - ++p; - switch ( *p ) { - case '\\': - if ( *++p == '\0' ) - p--; - break; - case '"': - if ( state == INQUOTE ) - state = OUTQUOTE; - else - state = INQUOTE; - break; - case ';': - case ',': - case '\0': - if ( state == OUTQUOTE ) { - ++count; - if ( rdns == NULL ) { - if (( rdns = (char **)malloc( 8 - * sizeof( char *))) == NULL ) - return( NULL ); - } else if ( count >= 8 ) { - if (( rdns = (char **)realloc( rdns, - (count+1) * sizeof( char *))) - == NULL ) - return( NULL ); - } - rdns[ count ] = NULL; - endquote = 0; - if ( notypes ) { - for ( q = rdnstart; - q < p && *q != '='; ++q ) { - ; - } - if ( q < p ) { - rdnstart = ++q; - } - if ( *rdnstart == '"' ) { - ++rdnstart; - } - - if ( *(p-1) == '"' ) { - endquote = 1; - --p; - } - } - - len = p - rdnstart; - if (( rdns[ count-1 ] = (char *)calloc( 1, - len + 1 )) != NULL ) { - (void) SAFEMEMCPY( rdns[ count-1 ], rdnstart, - len ); - rdns[ count-1 ][ len ] = '\0'; - } - - /* - * Don't forget to increment 'p' back to where - * it should be. If we don't, then we will - * never get past an "end quote." - */ - if ( endquote == 1 ) - p++; - - rdnstart = *p ? p + 1 : p; - while ( isspace( *rdnstart )) - ++rdnstart; - } - break; - } - } while ( *p ); - - return( rdns ); -} - - -int -ldap_is_dns_dn( char *dn ) -{ - return( dn[ 0 ] != '\0' && strchr( dn, '=' ) == NULL && - strchr( dn, ',' ) == NULL ); -} - - -#if defined( ultrix ) || defined( NeXT ) - -char *strdup( char *s ) -{ - char *p; - - if ( (p = (char *) malloc( strlen( s ) + 1 )) == NULL ) - return( NULL ); - - strcpy( p, s ); - - return( p ); -} - -#endif /* ultrix */ - - -/* - * Convert a DNS domain name into an X.500 distinguished name. - * For example, "sales.wiz.com" -> "dc=sales,dc=wiz,dc=com" - * - * If an error is encountered zero is returned, otherwise a string - * distinguished name and the number of nameparts is returned. - * The caller should free the returned string if it is non-zero. - */ - -char * -ldap_dns_to_dn( - char *dns_name, - int *nameparts -) -{ - size_t dns_len; - char *dn = 0; - char *cp; - - /* check for NULL string, empty name and name ending in '.' */ - if (dns_name && (dns_len = strlen(dns_name)) && - (dns_name[dns_len - 1] != '.')) { - if (dn = (char *)malloc(dns_len * 3 + 1)) { - *nameparts = 0; - cp = dn; - while (*dns_name) { - *cp++ = 'd'; - *cp++ = 'c'; - *cp++ = '='; - - while (*dns_name && (*dns_name != '.')) { - *cp++ = *dns_name++; - } - if (*dns_name == '.') { - dns_name++; - *cp++ = ','; - } - (*nameparts)++; - } - *cp = '\0'; - } - } - return (dn); -} - -char ** -ldap_explode_rdn( char *rdn, int notypes ) -{ - char *p, *q, *rdnstart, **rdncomps = NULL; - int state, count = 0, endquote; - size_t len; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 183, "ldap_explode_rdn\n"), 0, 0, 0 ); - - rdnstart = rdn; - p = rdn-1; - state = OUTQUOTE; - - do { - - ++p; - switch ( *p ) { - case '\\': - if ( *++p == '\0' ) - p--; - break; - case '"': - if ( state == INQUOTE ) - state = OUTQUOTE; - else - state = INQUOTE; - break; - case '+': - case '\0': - if ( state == OUTQUOTE ) { - ++count; - if ( rdncomps == NULL ) { - if (( rdncomps = (char **)malloc( 8 * sizeof( char *))) == NULL ) - return( NULL ); - } else if ( count >= 8 ) { - if (( rdncomps = (char **)realloc( rdncomps, - (count+1) * sizeof( char *))) - == NULL ) - return( NULL ); - } - rdncomps[ count ] = NULL; - endquote = 0; - if ( notypes ) { - for ( q = rdnstart; - q < p && *q != '='; ++q ) { - ; - } - if ( q < p ) { - rdnstart = ++q; - } - if ( *rdnstart == '"' ) { - ++rdnstart; - } - - if ( *(p-1) == '"' ) { - endquote = 1; - --p; - } - } - - len = p - rdnstart; - if (( rdncomps[ count-1 ] = (char *)calloc( 1, len + 1 )) != NULL ) { - SAFEMEMCPY( rdncomps[ count-1 ], rdnstart, - len ); - rdncomps[ count-1 ][ len ] = '\0'; - } - - /* - * Don't forget to increment 'p' back to where - * it should be. If we don't, then we will - * never get past an "end quote." - */ - if ( endquote == 1 ) - p++; - - rdnstart = *p ? p + 1 : p; - while ( isspace( *rdnstart )) - ++rdnstart; - } - break; - } - } while ( *p ); - - return( rdncomps ); -}
--- a/usr/src/lib/libldap4/common/getdxbyname.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef LDAP_DNS -/* - * Copyright (c) 1995 Regents of the University of Michigan. - * All rights reserved. - * - * getdxbyname - retrieve DX records from the DNS (from TXT records for now) - */ -#include <stdio.h> -#include <string.h> -#include <ctype.h> - -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#endif /* MACOS */ - -#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 ) -#include <sys/types.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <resolv.h> -#endif -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -#if defined( DOS ) || defined( _WIN32 ) -#include "msdos.h" -#endif /* DOS */ - - -#ifdef NEEDPROTOS -static char ** decode_answer( unsigned char *answer, int len ); -#else /* NEEDPROTOS */ -static char **decode_answer(); -#endif /* NEEDPROTOS */ - -extern int h_errno; -extern char *h_errlist[]; - - -#define MAX_TO_SORT 32 - - -/* - * getdxbyname - lookup DNS DX records for domain and return an ordered - * array. - */ -char ** -getdxbyname( char *domain ) -{ - unsigned char buf[ PACKETSZ ]; - char **dxs; - int rc; - - Debug( LDAP_DEBUG_TRACE, "getdxbyname( %s )\n", domain, 0, 0 ); - - memset( buf, 0, sizeof( buf )); - - if (( rc = res_search( domain, C_IN, T_TXT, buf, sizeof( buf ))) < 0 - || ( dxs = decode_answer( buf, rc )) == NULL ) { - /* - * punt: return list conisting of the original domain name only - */ - if (( dxs = (char **)malloc( 2 * sizeof( char * ))) == NULL || - ( dxs[ 0 ] = strdup( domain )) == NULL ) { - if ( dxs != NULL ) { - free( dxs ); - } - dxs = NULL; - } else { - dxs[ 1 ] = NULL; - } - } - - return( dxs ); -} - - -static char ** -decode_answer( unsigned char *answer, int len ) -{ - HEADER *hp; - char buf[ 256 ], **dxs; - unsigned char *eom, *p; - int ancount, err, rc, type, class, dx_count, rr_len; - int dx_pref[ MAX_TO_SORT ]; - - int _getshort( unsigned char * ); -#ifdef LDAP_DEBUG - if ( ldap_debug & LDAP_DEBUG_PACKETS ) { -/* __p_query( answer ); */ - } -#endif /* LDAP_DEBUG */ - - dxs = NULL; - hp = (HEADER *)answer; - eom = answer + len; - - if ( ntohs( hp->qdcount ) != 1 ) { - h_errno = NO_RECOVERY; - return( NULL ); - } - - ancount = ntohs( hp->ancount ); - if ( ancount < 1 ) { - h_errno = NO_DATA; - return( NULL ); - } - - /* - * skip over the query - */ - p = answer + HFIXEDSZ; - if (( rc = dn_expand( answer, eom, p, buf, sizeof( buf ))) < 0 ) { - h_errno = NO_RECOVERY; - return( NULL ); - } - p += ( rc + QFIXEDSZ ); - - /* - * pull out the answers we are interested in - */ - err = dx_count = 0; - while ( ancount > 0 && err == 0 && p < eom ) { - if (( rc = dn_expand( answer, eom, p, buf, sizeof( buf ))) < 0 ) { - err = NO_RECOVERY; - continue; - } - p += rc; /* skip over name */ - type = _getshort( p ); - p += INT16SZ; - class = _getshort( p ); - p += INT16SZ; - p += INT32SZ; /* skip over TTL */ - rr_len = _getshort( p ); - p += INT16SZ; - if ( class == C_IN && type == T_TXT ) { - int i, n, pref, txt_len; - char *q, *r; - - q = (char *)p; - while ( q < (char *)p + rr_len && err == 0 ) { - if ( *q >= 3 && strncasecmp( q + 1, "dx:", 3 ) == 0 ) { - txt_len = *q - 3; - r = q + 4; - while ( isspace( *r )) { - ++r; - --txt_len; - } - pref = 0; - while ( isdigit( *r )) { - pref *= 10; - pref += ( *r - '0' ); - ++r; - --txt_len; - } - if ( dx_count < MAX_TO_SORT - 1 ) { - dx_pref[ dx_count ] = pref; - } - while ( isspace( *r )) { - ++r; - --txt_len; - } - if ( dx_count == 0 ) { - dxs = (char **)malloc( 2 * sizeof( char * )); - } else { - dxs = (char **)realloc( dxs, - ( dx_count + 2 ) * sizeof( char * )); - } - if ( dxs == NULL || ( dxs[ dx_count ] = - (char *)calloc( 1, txt_len + 1 )) == NULL ) { - err = NO_RECOVERY; - continue; - } - memcpy( dxs[ dx_count ], r, txt_len ); - dxs[ ++dx_count ] = NULL; - } - q += ( *q + 1 ); /* move past last TXT record */ - } - } - p += rr_len; - } - - if ( err == 0 ) { - if ( dx_count == 0 ) { - err = NO_DATA; - } else { - /* - * sort records based on associated preference value - */ - int i, j, sort_count, tmp_pref; - char *tmp_dx; - - sort_count = ( dx_count < MAX_TO_SORT ) ? dx_count : MAX_TO_SORT; - for ( i = 0; i < sort_count; ++i ) { - for ( j = i + 1; j < sort_count; ++j ) { - if ( dx_pref[ i ] > dx_pref[ j ] ) { - tmp_pref = dx_pref[ i ]; - dx_pref[ i ] = dx_pref[ j ]; - dx_pref[ j ] = tmp_pref; - tmp_dx = dxs[ i ]; - dxs[ i ] = dxs[ j ]; - dxs[ j ] = tmp_dx; - } - } - } - } - } - - h_errno = err; - return( dxs ); -} - -#endif /* LDAP_DNS */
--- a/usr/src/lib/libldap4/common/getentry.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * getentry.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" - -/* ARGSUSED */ -LDAPMessage * -ldap_first_entry( LDAP *ld, LDAPMessage *res ) -{ - LDAPMessage *msg = res; - - while ( msg != NULLMSG) { - if (msg->lm_msgtype == LDAP_RES_SEARCH_ENTRY) - break; - msg = msg->lm_chain; - } - return (msg); -} - -/* ARGSUSED */ -LDAPMessage *ldap_next_entry( LDAP *ld, LDAPMessage *entry ) -{ - LDAPMessage *msg; - - if ( entry == NULLMSG) - return( NULLMSG ); - - msg = entry->lm_chain; - while(msg != NULLMSG){ - if (msg->lm_msgtype == LDAP_RES_SEARCH_ENTRY) - break; - msg = msg->lm_chain; - } - - return( msg ); -} - -/* ARGSUSED */ -int -ldap_count_entries( LDAP *ld, LDAPMessage *res ) -{ - int i; - - for ( i = 0; res != NULL; res = res->lm_chain ) - if (res->lm_msgtype == LDAP_RES_SEARCH_ENTRY) - i++; - - return( i ); -}
--- a/usr/src/lib/libldap4/common/getfilter.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,447 +0,0 @@ -/* - * Copyright 2000-2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1993 Regents of the University of Michigan. - * All rights reserved. - * - * getfilter.c -- optional add-on to libldap - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#if defined(NeXT) -#include <regex.h> -#endif -#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> -#include <errno.h> -#ifndef VMS -#include <unistd.h> -#endif /* VMS */ -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" -#include "regex.h" - -#ifdef NEEDPROTOS -static int break_into_words( char *str, char *delims, char ***wordsp ); -int next_line_tokens( char **bufp, ssize_t *blenp, char ***toksp ); -void free_strarray( char **sap ); -#else /* NEEDPROTOS */ -static int break_into_words(); -int next_line_tokens(); -void free_strarray(); -#endif /* NEEDPROTOS */ - -#if !defined( MACOS ) && !defined( DOS ) -extern int errno; -extern char *re_comp(); -#endif - -#define FILT_MAX_LINE_LEN 1024 - -LDAPFiltDesc * -ldap_init_getfilter( char *fname ) -{ - FILE *fp; - char *buf; - ssize_t 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 = malloc( len )) == NULL ) { - fclose( fp ); - return( NULL ); - } - - rlen = fread( buf, (size_t) 1, len, fp ); - eof = feof( fp ); - fclose( fp ); - - if ( rlen != len && !eof ) { /* error: didn't get the whole file */ - free( buf ); - return( NULL ); - } - - - lfdp = ldap_init_getfilter_buf( buf, rlen ); - free( buf ); - - return( lfdp ); -} - - -LDAPFiltDesc * -ldap_init_getfilter_buf( char *buf, ssize_t buflen ) -{ - LDAPFiltDesc *lfdp; - LDAPFiltList *flp, *nextflp; - LDAPFiltInfo *fip, *nextfip; - char *tag, **tok; - int tokcnt, i; - - if (( lfdp = (LDAPFiltDesc *)calloc( (size_t) 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( (size_t) 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 ) - 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( (size_t) 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 ) - 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 ) - errno = EINVAL; -#endif - return( NULL ); - } - } - - if ( tag != NULL ) { - free( tag ); - } - - return( lfdp ); -} - - -void -ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix ) -{ - if ( lfdp->lfd_filtprefix != NULL ) { - free( lfdp->lfd_filtprefix ); - } - lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : strdup( prefix ); - - if ( lfdp->lfd_filtsuffix != NULL ) { - free( lfdp->lfd_filtsuffix ); - } - lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : strdup( suffix ); -} - - -LDAPFiltInfo * -ldap_getfirstfilter( LDAPFiltDesc *lfdp, char *tagpat, char *value ) -{ - LDAPFiltList *flp; - - if ( lfdp->lfd_curvalcopy != NULL ) { - free( lfdp->lfd_curvalcopy ); - free( lfdp->lfd_curvalwords ); - } - - lfdp->lfd_curval = value; - lfdp->lfd_curfip = NULL; - - for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = flp->lfl_next ) { - if ( re_comp( tagpat ) == NULL && re_exec( flp->lfl_tag ) == 1 - && re_comp( flp->lfl_pattern ) == NULL - && re_exec( lfdp->lfd_curval ) == 1 ) { - lfdp->lfd_curfip = flp->lfl_ilist; - break; - } - } - - if ( lfdp->lfd_curfip == NULL ) { - return( NULL ); - } - - if (( lfdp->lfd_curvalcopy = strdup( value )) == NULL ) { - return( NULL ); - } - - if ( break_into_words( lfdp->lfd_curvalcopy, flp->lfl_delims, - &lfdp->lfd_curvalwords ) < 0 ) { - free( lfdp->lfd_curvalcopy ); - 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, (size_t) 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 -ldap_build_filter( char *filtbuf, size_t buflen, char *pattern, - char *prefix, char *suffix, char *attr, char *value, char **valwords ) -{ - char *p, *f; - 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' ) { - if ( isdigit( *(p+1))) { - ++p; - wordnum = *p - '1'; - if ( *(p+1) == '-' ) { - ++p; - if ( isdigit( *(p+1))) { - ++p; - endwordnum = *p - '1'; /* e.g., "%v2-4" */ -#ifndef SUN /* Patch from innosoft Craig.Watkins 08.Jul.97 */ - if ( endwordnum > wordcount - 1 ) { - endwordnum = wordcount - 1; - } -#endif - } else { - endwordnum = wordcount - 1; /* e.g., "%v2-" */ - } - } else { - endwordnum = wordnum; /* e.g., "%v2" */ - } -#ifdef SUN /* Patch from innosoft Craig.Watkins 08.Jul.97 */ - if ( endwordnum > wordcount - 1 ) { - endwordnum = wordcount - 1; - } -#endif - 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; - } - - if ( f - filtbuf > buflen ) { - /* sanity check */ - --f; - break; - } - } - - if ( suffix != NULL && ( f - filtbuf ) < buflen ) { - strcpy( f, suffix ); - } else { - *f = '\0'; - } -} - - -static int -break_into_words( char *str, char *delims, char ***wordsp ) -{ - char *word, **words; - int count; - - if (( words = (char **)calloc( (size_t) 1, sizeof( char * ))) == NULL ) { - return( -1 ); - } - count = 0; - words[ count ] = NULL; - - word = strtok( str, delims ); - while ( word != NULL ) { - if (( words = (char **)realloc( words, - ( count + 2 ) * sizeof( char * ))) == NULL ) { - return( -1 ); - } - - words[ count ] = word; - words[ ++count ] = NULL; - word = strtok( NULL, delims ); - } - - *wordsp = words; - return( count ); -}
--- a/usr/src/lib/libldap4/common/getmsg.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * - * Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * - * Comments: - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" - -LDAPMessage * ldap_first_message(LDAP *ld, LDAPMessage *res) -{ - return (res == NULLMSG ? NULLMSG : res); -} - -LDAPMessage * ldap_next_message(LDAP *ld, LDAPMessage *msg) -{ - if (msg == NULLMSG || msg->lm_chain == NULLMSG) - return (NULLMSG); - return (msg->lm_chain); -} - -int ldap_count_messages( LDAP *ld, LDAPMessage *res) -{ - int i; - - for ( i =0; res != NULL; res = res->lm_chain) - i++; - - return (i); -}
--- a/usr/src/lib/libldap4/common/getref.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * - * Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * - * Comments: - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -LDAPMessage * ldap_first_reference(LDAP *ld, LDAPMessage *res) -{ - LDAPMessage *msg = res; - - while ( msg != NULLMSG) { - if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) - break; - msg = msg->lm_chain; - } - return (msg); -} - -LDAPMessage * ldap_next_reference(LDAP *ld, LDAPMessage *entry) -{ - LDAPMessage *msg; - - if ( entry == NULLMSG) - return( NULLMSG ); - - msg = entry->lm_chain; - while(msg != NULLMSG){ - if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) - break; - msg = msg->lm_chain; - } - - return( msg ); -} - -int -ldap_count_references( LDAP *ld, LDAPMessage *res ) -{ - int i; - - for ( i = 0; res != NULL; res = res->lm_chain ) - if (res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) - i++; - - return( i ); -} - -char ** ldap_get_reference_urls(LDAP *ld, LDAPMessage *res) -{ - BerElement tmp; - char **urls = NULL; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1274, "ldap_get_reference_urls\n"), 0, 0, 0 ); - - if (res == NULL){ - ld->ld_errno = LDAP_PARAM_ERROR; - return (NULL); - } - tmp = *res->lm_ber; /* struct copy */ - if ( ber_scanf( &tmp, "{v}", &urls) == LBER_ERROR){ - ld->ld_errno = LDAP_DECODING_ERROR; - return (NULL); - } - return (urls); -}
--- a/usr/src/lib/libldap4/common/getvalues.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -/* - * - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. - * - * getvalues.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> /* free() for Solaris */ -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#if defined( DOS ) || defined( _WIN32 ) -#include <malloc.h> -#include "msdos.h" -#else /* DOS */ -#include <sys/types.h> -#include <sys/socket.h> -#endif /* DOS */ -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - -char ** -ldap_get_values( LDAP *ld, LDAPMessage *entry, char *target ) -{ - BerElement ber; - char attr[LDAP_MAX_ATTR_LEN]; - int found = 0; - int len; - char **vals; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 184, "ldap_get_values\n"), 0, 0, 0 ); - - ber = *entry->lm_ber; - - /* skip sequence, dn, sequence of, and snag the first attr */ - len = sizeof(attr); - if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - if ( strcasecmp( target, attr ) == 0 ) - found = 1; - - /* break out on success, return out on error */ - while ( ! found ) { - len = sizeof(attr); - if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - if ( strcasecmp( target, attr ) == 0 ) - break; - } - - /* - * if we get this far, we've found the attribute and are sitting - * just before the set of values. - */ - - if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - return( vals ); -} - -struct berval ** -ldap_get_values_len( LDAP *ld, LDAPMessage *entry, char *target ) -{ - BerElement ber; - char attr[LDAP_MAX_ATTR_LEN]; - int found = 0; - int len; - struct berval **vals; - - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 185, "ldap_get_values_len\n"), 0, 0, 0 ); - - ber = *entry->lm_ber; - - /* skip sequence, dn, sequence of, and snag the first attr */ - len = sizeof(attr); - if ( ber_scanf( &ber, "{x{{s", attr, &len ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - if ( strcasecmp( target, attr ) == 0 ) - found = 1; - - /* break out on success, return out on error */ - while ( ! found ) { - len = sizeof(attr); - if ( ber_scanf( &ber, "x}{s", attr, &len ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - if ( strcasecmp( target, attr ) == 0 ) - break; - } - - /* - * if we get this far, we've found the attribute and are sitting - * just before the set of values. - */ - - if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) { - ld->ld_errno = LDAP_DECODING_ERROR; - return( NULL ); - } - - return( vals ); -} - -int -ldap_count_values( char **vals ) -{ - int i; - - if ( vals == NULL ) - return( 0 ); - - for ( i = 0; vals[i] != NULL; i++ ) - ; /* NULL */ - - return( i ); -} - -int -ldap_count_values_len( struct berval **vals ) -{ - return( ldap_count_values( (char **) vals ) ); -} - -void -ldap_value_free( char **vals ) -{ - int i; - - if ( vals == NULL ) - return; - for ( i = 0; vals[i] != NULL; i++ ) - free( vals[i] ); - free( (char *) vals ); -} - -void -ldap_value_free_len( struct berval **vals ) -{ - int i; - - if ( vals == NULL ) - return; - for ( i = 0; vals[i] != NULL; i++ ) { - free( vals[i]->bv_val ); - free( vals[i] ); - } - free( (char *) vals ); -}
--- a/usr/src/lib/libldap4/common/kbind.c Wed May 16 04:25:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,349 +0,0 @@ -/* - * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Copyright (c) 1993 Regents of the University of Michigan. - * All rights reserved. - * - * kbind.c - */ - -#ifndef lint -static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n"; -#endif - -#ifdef KERBEROS - -#include <stdio.h> -#include <string.h> - -#ifdef MACOS -#include <stdlib.h> -#include "macos.h" -#else /* MACOS */ -#ifdef DOS -#include "msdos.h" -#endif /* DOS */ -#include <krb.h> -#include <stdlib.h> -#if !defined(DOS) && !defined( _WIN32 ) -#include <sys/types.h> -#endif /* !DOS && !_WIN32 */ -#include <sys/time.h> -#include <sys/socket.h> -#endif /* MACOS */ - -#include "lber.h" -#include "ldap.h" -#include "ldap-private.h" -#include "ldap-int.h" - - - -/* - * ldap_kerberos_bind1 - initiate a bind to the ldap server using - * kerberos authentication. The dn is supplied. It is assumed the user - * already has a valid ticket granting ticket. The msgid of the - * request is returned on success (suitable for passing to ldap_result()), - * -1 is returned if there's trouble. - * - * Example: - * ldap_kerberos_bind1( ld, "cn=manager, o=university of michigan, c=us" ) - */ -int -ldap_kerberos_bind1( LDAP *ld, char *dn ) -{ - BerElement *ber; - char *cred; - int rc, credlen; - char *get_kerberosv4_credentials(); -#ifdef STR_TRANSLATION - int str_translation_on; -#endif /* STR_TRANSLATION */ - - /* - * The bind request looks like this: - * BindRequest ::= SEQUENCE { - * version INTEGER, - * name DistinguishedName, - * authentication CHOICE { - * krbv42ldap [1] OCTET STRING - * krbv42dsa [2] OCTET STRING - * } - * } - * all wrapped up in an LDAPMessage sequence. - */ - -#if defined( SUN ) && defined( _REENTRANT ) - int rv; - - LOCK_LDAP(ld); -#endif - Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 186, "ldap_kerberos_bind1\n"), 0, 0, 0 ); - - if ( dn == NULL ) - dn = ""; - - if ( (cred = get_kerberosv4_credentials( ld, dn, "ldapserver", - &credlen )) == NULL ) { -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( -1 ); /* ld_errno should already be set */ - } - - /* create a message to send */ - if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) { - free( cred ); -#if defined( SUN ) && defined( _REENTRANT ) - UNLOCK_LDAP(ld); -#endif - return( -1 ); - } - -#ifdef STR_TRANSLATION - if (( str_translation_on = (( ber->ber_options & - LBER_TRANSLATE_STRINGS ) != 0 ))) { /* turn translation off */ - ber->ber_options &= ~LBER_TRANSLATE_STRINGS; - } -#endif /* STR_TRANSLATION */ - - /* fill it in */ - rc = ber_printf( ber, "{it{isto}}", ++ld->ld_msgid, LDAP_REQ_BIND, - ld->ld_version, dn, LDAP_AUTH_KRBV41, cred, credlen ); - -#ifdef STR_TRANSLATION - if ( str_translation_on ) { /* restore translation */ - ber->ber_options |= LBER_TRANSLATE_STRINGS; - } -#endif /* STR_TRANSLATION */ - - if ( rc == -1 ) { - free( cred );