summaryrefslogtreecommitdiff
path: root/usr/src/lib/libldap4/common
diff options
context:
space:
mode:
authorMilan Jurik <milan.jurik@xylab.cz>2012-05-19 19:59:14 -0700
committerMilan Jurik <milan.jurik@xylab.cz>2012-05-19 19:59:14 -0700
commitd387ac4c164917d885cd84bd1b62647d989033ac (patch)
tree3c8503aa5915728ea1f848bfaaecb91ab62a4d91 /usr/src/lib/libldap4/common
parentad2de4358b2074634b0f2355c34b0986da0e95f9 (diff)
downloadillumos-gate-d387ac4c164917d885cd84bd1b62647d989033ac.tar.gz
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>
Diffstat (limited to 'usr/src/lib/libldap4/common')
-rw-r--r--usr/src/lib/libldap4/common/Version.c20
-rw-r--r--usr/src/lib/libldap4/common/abandon.c267
-rw-r--r--usr/src/lib/libldap4/common/add.c270
-rw-r--r--usr/src/lib/libldap4/common/addentry.c63
-rw-r--r--usr/src/lib/libldap4/common/bind.c145
-rw-r--r--usr/src/lib/libldap4/common/cache.c714
-rw-r--r--usr/src/lib/libldap4/common/charset.c1869
-rw-r--r--usr/src/lib/libldap4/common/cldap.c597
-rw-r--r--usr/src/lib/libldap4/common/compare.c259
-rw-r--r--usr/src/lib/libldap4/common/controls.c291
-rw-r--r--usr/src/lib/libldap4/common/delete.c203
-rw-r--r--usr/src/lib/libldap4/common/disptmpl.c751
-rw-r--r--usr/src/lib/libldap4/common/dsparse.c214
-rw-r--r--usr/src/lib/libldap4/common/error.c345
-rw-r--r--usr/src/lib/libldap4/common/extensions.c79
-rw-r--r--usr/src/lib/libldap4/common/extop.c156
-rw-r--r--usr/src/lib/libldap4/common/free.c106
-rw-r--r--usr/src/lib/libldap4/common/friendly.c142
-rw-r--r--usr/src/lib/libldap4/common/getattr.c107
-rw-r--r--usr/src/lib/libldap4/common/getdn.c412
-rw-r--r--usr/src/lib/libldap4/common/getdxbyname.c227
-rw-r--r--usr/src/lib/libldap4/common/getentry.c82
-rw-r--r--usr/src/lib/libldap4/common/getfilter.c447
-rw-r--r--usr/src/lib/libldap4/common/getmsg.c40
-rw-r--r--usr/src/lib/libldap4/common/getref.c79
-rw-r--r--usr/src/lib/libldap4/common/getvalues.c183
-rw-r--r--usr/src/lib/libldap4/common/kbind.c349
-rw-r--r--usr/src/lib/libldap4/common/llib-lldap317
-rw-r--r--usr/src/lib/libldap4/common/mapfile-vers229
-rw-r--r--usr/src/lib/libldap4/common/modify.c246
-rw-r--r--usr/src/lib/libldap4/common/modrdn.c118
-rw-r--r--usr/src/lib/libldap4/common/notif.c106
-rw-r--r--usr/src/lib/libldap4/common/open.c433
-rw-r--r--usr/src/lib/libldap4/common/option.c243
-rw-r--r--usr/src/lib/libldap4/common/os-ip.c614
-rw-r--r--usr/src/lib/libldap4/common/referral.c511
-rw-r--r--usr/src/lib/libldap4/common/regex.c923
-rw-r--r--usr/src/lib/libldap4/common/rename.c176
-rw-r--r--usr/src/lib/libldap4/common/request.c779
-rw-r--r--usr/src/lib/libldap4/common/result.c1657
-rw-r--r--usr/src/lib/libldap4/common/saslbind.c340
-rw-r--r--usr/src/lib/libldap4/common/sbind.c171
-rw-r--r--usr/src/lib/libldap4/common/search.c939
-rw-r--r--usr/src/lib/libldap4/common/sort.c180
-rw-r--r--usr/src/lib/libldap4/common/sortctrl.c426
-rw-r--r--usr/src/lib/libldap4/common/srchpref.c430
-rw-r--r--usr/src/lib/libldap4/common/tmplout.c1176
-rw-r--r--usr/src/lib/libldap4/common/ufn.c594
-rw-r--r--usr/src/lib/libldap4/common/unbind.c216
-rw-r--r--usr/src/lib/libldap4/common/url.c836
-rw-r--r--usr/src/lib/libldap4/common/utils.c28
-rw-r--r--usr/src/lib/libldap4/common/version.c20
-rw-r--r--usr/src/lib/libldap4/common/vlistctrl.c124
53 files changed, 0 insertions, 20249 deletions
diff --git a/usr/src/lib/libldap4/common/Version.c b/usr/src/lib/libldap4/common/Version.c
deleted file mode 100644
index c3fa7df517..0000000000
--- a/usr/src/lib/libldap4/common/Version.c
+++ /dev/null
@@ -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";
diff --git a/usr/src/lib/libldap4/common/abandon.c b/usr/src/lib/libldap4/common/abandon.c
deleted file mode 100644
index 71345186c7..0000000000
--- a/usr/src/lib/libldap4/common/abandon.c
+++ /dev/null
@@ -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 );
-}
-
diff --git a/usr/src/lib/libldap4/common/add.c b/usr/src/lib/libldap4/common/add.c
deleted file mode 100644
index ce3e357b6f..0000000000
--- a/usr/src/lib/libldap4/common/add.c
+++ /dev/null
@@ -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);
-}
diff --git a/usr/src/lib/libldap4/common/addentry.c b/usr/src/lib/libldap4/common/addentry.c
deleted file mode 100644
index f1f0582560..0000000000
--- a/usr/src/lib/libldap4/common/addentry.c
+++ /dev/null
@@ -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;
-}
diff --git a/usr/src/lib/libldap4/common/bind.c b/usr/src/lib/libldap4/common/bind.c
deleted file mode 100644
index 7c5d783f2c..0000000000
--- a/usr/src/lib/libldap4/common/bind.c
+++ /dev/null
@@ -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
-}
diff --git a/usr/src/lib/libldap4/common/cache.c b/usr/src/lib/libldap4/common/cache.c
deleted file mode 100644
index 977e4c6d02..0000000000
--- a/usr/src/lib/libldap4/common/cache.c
+++ /dev/null
@@ -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 */
diff --git a/usr/src/lib/libldap4/common/charset.c b/usr/src/lib/libldap4/common/charset.c
deleted file mode 100644
index e1c9b9d9be..0000000000
--- a/usr/src/lib/libldap4/common/charset.c
+++ /dev/null
@@ -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 */
diff --git a/usr/src/lib/libldap4/common/cldap.c b/usr/src/lib/libldap4/common/cldap.c
deleted file mode 100644
index 809fa4cce7..0000000000
--- a/usr/src/lib/libldap4/common/cldap.c
+++ /dev/null
@@ -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 */
diff --git a/usr/src/lib/libldap4/common/compare.c b/usr/src/lib/libldap4/common/compare.c
deleted file mode 100644
index 8202580a7b..0000000000
--- a/usr/src/lib/libldap4/common/compare.c
+++ /dev/null
@@ -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);
-}
-
diff --git a/usr/src/lib/libldap4/common/controls.c b/usr/src/lib/libldap4/common/controls.c
deleted file mode 100644
index fb61e5e56c..0000000000
--- a/usr/src/lib/libldap4/common/controls.c
+++ /dev/null
@@ -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);
-}
diff --git a/usr/src/lib/libldap4/common/delete.c b/usr/src/lib/libldap4/common/delete.c
deleted file mode 100644
index 287abd8ac8..0000000000
--- a/usr/src/lib/libldap4/common/delete.c
+++ /dev/null
@@ -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);
-}
diff --git a/usr/src/lib/libldap4/common/disptmpl.c b/usr/src/lib/libldap4/common/disptmpl.c
deleted file mode 100644
index ea2413c990..0000000000
--- a/usr/src/lib/libldap4/common/disptmpl.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/dsparse.c b/usr/src/lib/libldap4/common/dsparse.c
deleted file mode 100644
index c14af4e3ea..0000000000
--- a/usr/src/lib/libldap4/common/dsparse.c
+++ /dev/null
@@ -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 ));
-}
diff --git a/usr/src/lib/libldap4/common/error.c b/usr/src/lib/libldap4/common/error.c
deleted file mode 100644
index bbf01622f0..0000000000
--- a/usr/src/lib/libldap4/common/error.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/extensions.c b/usr/src/lib/libldap4/common/extensions.c
deleted file mode 100644
index 247ad2baa5..0000000000
--- a/usr/src/lib/libldap4/common/extensions.c
+++ /dev/null
@@ -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);
-}
-
diff --git a/usr/src/lib/libldap4/common/extop.c b/usr/src/lib/libldap4/common/extop.c
deleted file mode 100644
index a299b1dd61..0000000000
--- a/usr/src/lib/libldap4/common/extop.c
+++ /dev/null
@@ -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));
-}
diff --git a/usr/src/lib/libldap4/common/free.c b/usr/src/lib/libldap4/common/free.c
deleted file mode 100644
index a9d4bd0675..0000000000
--- a/usr/src/lib/libldap4/common/free.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/friendly.c b/usr/src/lib/libldap4/common/friendly.c
deleted file mode 100644
index 1142722970..0000000000
--- a/usr/src/lib/libldap4/common/friendly.c
+++ /dev/null
@@ -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;
-}
diff --git a/usr/src/lib/libldap4/common/getattr.c b/usr/src/lib/libldap4/common/getattr.c
deleted file mode 100644
index 26f7b064f2..0000000000
--- a/usr/src/lib/libldap4/common/getattr.c
+++ /dev/null
@@ -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);
-}
-
diff --git a/usr/src/lib/libldap4/common/getdn.c b/usr/src/lib/libldap4/common/getdn.c
deleted file mode 100644
index d0cb89a213..0000000000
--- a/usr/src/lib/libldap4/common/getdn.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/getdxbyname.c b/usr/src/lib/libldap4/common/getdxbyname.c
deleted file mode 100644
index e6316e0436..0000000000
--- a/usr/src/lib/libldap4/common/getdxbyname.c
+++ /dev/null
@@ -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 */
diff --git a/usr/src/lib/libldap4/common/getentry.c b/usr/src/lib/libldap4/common/getentry.c
deleted file mode 100644
index 346f23e9a8..0000000000
--- a/usr/src/lib/libldap4/common/getentry.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/getfilter.c b/usr/src/lib/libldap4/common/getfilter.c
deleted file mode 100644
index 57ae904801..0000000000
--- a/usr/src/lib/libldap4/common/getfilter.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/getmsg.c b/usr/src/lib/libldap4/common/getmsg.c
deleted file mode 100644
index abd8da6e47..0000000000
--- a/usr/src/lib/libldap4/common/getmsg.c
+++ /dev/null
@@ -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);
-}
diff --git a/usr/src/lib/libldap4/common/getref.c b/usr/src/lib/libldap4/common/getref.c
deleted file mode 100644
index ded453a038..0000000000
--- a/usr/src/lib/libldap4/common/getref.c
+++ /dev/null
@@ -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);
-}
diff --git a/usr/src/lib/libldap4/common/getvalues.c b/usr/src/lib/libldap4/common/getvalues.c
deleted file mode 100644
index b516af78fc..0000000000
--- a/usr/src/lib/libldap4/common/getvalues.c
+++ /dev/null
@@ -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 );
-}
diff --git a/usr/src/lib/libldap4/common/kbind.c b/usr/src/lib/libldap4/common/kbind.c
deleted file mode 100644
index 5cc6928eca..0000000000
--- a/usr/src/lib/libldap4/common/kbind.c
+++ /dev/null
@@ -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 );
- ber_free( ber, 1 );
- ld->ld_errno = LDAP_ENCODING_ERROR;
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- free( cred );
-
-#ifndef NO_CACHE
- if ( ld->ld_cache != NULL ) {
- ldap_flush_cache( ld );
- }
-#endif /* !NO_CACHE */
-
- /* send the message */
-#if defined( SUN ) && defined( _REENTRANT )
- rv = send_initial_request( ld, LDAP_REQ_BIND, dn, ber );
- UNLOCK_LDAP(ld);
- return ( rv );
-#else
- return ( send_initial_request( ld, LDAP_REQ_BIND, dn, ber ));
-#endif
-}
-
-int
-ldap_kerberos_bind1_s( LDAP *ld, char *dn )
-{
- int msgid;
- LDAPMessage *res;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 187, "ldap_kerberos_bind1_s\n"), 0, 0, 0 );
-
- /* initiate the bind */
- if ( (msgid = ldap_kerberos_bind1( ld, dn )) == -1 )
- return( ld->ld_errno );
-
- /* wait for a result */
- if ( ldap_result( ld, ld->ld_msgid, 1, (struct timeval *) 0, &res )
- == -1 ) {
- return( ld->ld_errno ); /* ldap_result sets ld_errno */
- }
-
- return( ldap_result2error( ld, res, 1 ) );
-}
-
-/*
- * ldap_kerberos_bind2 - initiate a bind to the X.500 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_bind2( ld, "cn=manager, o=university of michigan, c=us" )
- */
-int
-ldap_kerberos_bind2( 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 */
-
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 188, "ldap_kerberos_bind2\n"), 0, 0, 0 );
-
- if ( dn == NULL )
- dn = "";
-
- if ( (cred = get_kerberosv4_credentials( ld, dn, "x500dsa", &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_KRBV42, cred, credlen );
-
-
-#ifdef STR_TRANSLATION
- if ( str_translation_on ) { /* restore translation */
- ber->ber_options |= LBER_TRANSLATE_STRINGS;
- }
-#endif /* STR_TRANSLATION */
-
- free( cred );
-
- if ( rc == -1 ) {
- ber_free( ber, 1 );
- ld->ld_errno = LDAP_ENCODING_ERROR;
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- /* send the message */
-#if defined( SUN ) && defined( _REENTRANT )
- rv = send_initial_request( ld, LDAP_REQ_BIND, dn, ber );
- UNLOCK_LDAP(ld);
- return ( rv );
-#endif
- return ( send_initial_request( ld, LDAP_REQ_BIND, dn, ber ));
-}
-
-/* synchronous bind to DSA using kerberos */
-int
-ldap_kerberos_bind2_s( LDAP *ld, char *dn )
-{
- int msgid;
- LDAPMessage *res;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 189, "ldap_kerberos_bind2_s\n"), 0, 0, 0 );
-
- /* initiate the bind */
- if ( (msgid = ldap_kerberos_bind2( ld, dn )) == -1 )
- return( ld->ld_errno );
-
- /* wait for a result */
- if ( ldap_result( ld, ld->ld_msgid, 1, (struct timeval *) 0, &res )
- == -1 ) {
- return( ld->ld_errno ); /* ldap_result sets ld_errno */
- }
-
- return( ldap_result2error( ld, res, 1 ) );
-}
-
-/* synchronous bind to ldap and DSA using kerberos */
-int
-ldap_kerberos_bind_s( LDAP *ld, char *dn )
-{
- int err;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 190, "ldap_kerberos_bind_s\n"), 0, 0, 0 );
-
- if ( (err = ldap_kerberos_bind1_s( ld, dn )) != LDAP_SUCCESS )
- return( err );
-
- return( ldap_kerberos_bind2_s( ld, dn ) );
-}
-
-
-#ifndef AUTHMAN
-/*
- * get_kerberosv4_credentials - obtain kerberos v4 credentials for ldap.
- * The dn of the entry to which to bind is supplied. It's assumed the
- * user already has a tgt.
- */
-
-char *
-get_kerberosv4_credentials( LDAP *ld, char *who, char *service, int *len )
-{
- KTEXT_ST ktxt;
- int err;
- char realm[REALM_SZ], *cred, *krbinstance;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 191, "get_kerberosv4_credentials\n"), 0, 0, 0 );
-
- if ( (err = krb_get_tf_realm( tkt_string(), realm )) != KSUCCESS ) {
-#ifndef NO_USERINTERFACE
- fprintf( stderr, "krb_get_tf_realm failed (%s)\n",
- krb_err_txt[err] );
-#endif /* NO_USERINTERFACE */
- ld->ld_errno = LDAP_INVALID_CREDENTIALS;
- return( NULL );
- }
-
-#ifdef LDAP_REFERRALS
- krbinstance = ld->ld_defconn->lconn_krbinstance;
-#else /* LDAP_REFERRALS */
- krbinstance = ld->ld_host;
-#endif /* LDAP_REFERRALS */
-
- if ( (err = krb_mk_req( &ktxt, service, krbinstance, realm, 0 ))
- != KSUCCESS ) {
-#ifndef NO_USERINTERFACE
- fprintf( stderr, "krb_mk_req failed (%s)\n", krb_err_txt[err] );
-#endif /* NO_USERINTERFACE */
- ld->ld_errno = LDAP_INVALID_CREDENTIALS;
- return( NULL );
- }
-
- if ( ( cred = malloc( ktxt.length )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( NULL );
- }
-
- *len = ktxt.length;
- memcpy( cred, ktxt.dat, ktxt.length );
-
- return( cred );
-}
-
-#endif /* !AUTHMAN */
-#endif /* KERBEROS */
diff --git a/usr/src/lib/libldap4/common/llib-lldap b/usr/src/lib/libldap4/common/llib-lldap
deleted file mode 100644
index 2d0b9e947c..0000000000
--- a/usr/src/lib/libldap4/common/llib-lldap
+++ /dev/null
@@ -1,317 +0,0 @@
-/* LINTLIBRARY */
-/* PROTOLIB1 */
-
-/*
- * Copyright (c) 1997 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <lber.h>
-#include <ldap.h>
-
-/*
- * /usr/src/lib/libldap routines
- */
-
-
-/*
- * in abandon.c:
- */
-int ldap_abandon_ext(LDAP *ld, int msgid, LDAPControl **serverctrls, LDAPControl ** clientctrls);
-int ldap_abandon( LDAP *ld, int msgid );
-
-/*
- * in add.c:
- */
-int ldap_add_ext( LDAP *ld, char *dn, LDAPMod **attrs, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_add_ext_s( LDAP *ld, char *dn, LDAPMod **attrs, LDAPControl ** serverctrls, LDAPControl **clientctrls);
-int ldap_add( LDAP *ld, char *dn, LDAPMod **attrs );
-int ldap_add_s( LDAP *ld, char *dn, LDAPMod **attrs );
-
-/*
- * in bind.c:
- */
-
-/*
- * in sbind.c:
- */
-int ldap_simple_bind( LDAP *ld, char *who, char *passwd );
-int ldap_simple_bind_s( LDAP *ld, char *who, char *passwd );
-
-/*
- * in saslbind.c:
- */
-int ldap_sasl_bind(LDAP *ld, char *dn, char *mechanism, struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_sasl_bind_s(LDAP *ld, char *dn, char *mechanism, struct berval *cred, LDAPControl **serverctrls, LDAPControl **clientctrls, struct berval **servercredp);
-
-/*
- * in kbind.c:
- */
-
-#ifndef NO_CACHE
-/*
- * in cache.c
- */
-int ldap_enable_cache( LDAP *ld, time_t timeout, ssize_t maxmem );
-void ldap_disable_cache( LDAP *ld );
-void ldap_set_cache_options( LDAP *ld, unsigned int opts );
-void ldap_destroy_cache( LDAP *ld );
-void ldap_flush_cache( LDAP *ld );
-void ldap_uncache_entry( LDAP *ld, char *dn );
-void ldap_uncache_request( LDAP *ld, int msgid );
-#endif /* !NO_CACHE */
-
-/*
- * in compare.c:
- */
-int ldap_compare_ext(LDAP *ld, char *dn, char *attr, struct berval *bvalue, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_compare_ext_s(LDAP *ld, char *dn, char *attr, struct berval *bvalue, LDAPControl ** serverctrls, LDAPControl **clientctrls) ;
-int ldap_compare( LDAP *ld, char *dn, char *attr, char *value );
-int ldap_compare_s( LDAP *ld, char *dn, char *attr, char *value );
-
-/*
- * in delete.c:
- */
-int ldap_delete_ext(LDAP *ld, char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_delete_ext_s(LDAP *ld, char *dn, LDAPControl **serverctrls, LDAPControl **clientctrls);
-int ldap_delete( LDAP *ld, char *dn );
-int ldap_delete_s( LDAP *ld, char *dn );
-
-/*
- * in error.c:
- */
-char *ldap_err2string( int err );
-
-
-/*
- * in modify.c:
- */
-int ldap_modify_ext(LDAP *ld, char *dn, LDAPMod **mods, LDAPControl **serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_modify_ext_s(LDAP *ld, char *dn, LDAPMod **mods, LDAPControl **serverctrls, LDAPControl **clientctrls) ;
-int ldap_modify( LDAP *ld, char *dn, LDAPMod **mods );
-int ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods );
-
-/*
- * in modrdn.c:
- */
-
-/*
- * in rename.c:
- */
-int ldap_rename(LDAP *ld, char *dn, char *newrdn, char *newparent, int deleteoldrdn, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp);
-int ldap_rename_s(LDAP *ld, char *dn, char *newrdn, char *newparent, int deleteoldrdn, LDAPControl ** serverctrls, LDAPControl **clientctrls);
-
-/*
- * in open.c:
- */
-LDAP *ldap_init( char *defhost, int defport );
-
-
-#ifdef LDAP_SSL
-LDAP *ldap_ssl_init(char *defhost, int defport, char *keyname );
-#endif
-
-/*
- * in getentry.c:
- */
-LDAPMessage *ldap_first_entry( LDAP *ld, LDAPMessage *res );
-LDAPMessage *ldap_next_entry( LDAP *ld, LDAPMessage *entry );
-int ldap_count_entries( LDAP *ld, LDAPMessage *res );
-
-/*
- * in getmsg.c:
- */
-LDAPMessage *ldap_first_message( LDAP *ld, LDAPMessage *res );
-LDAPMessage *ldap_next_message( LDAP *ld, LDAPMessage *msg );
-int ldap_count_messages( LDAP *ld, LDAPMessage *res );
-
-/*
- * in getref.c:
- */
-LDAPMessage *ldap_first_reference( LDAP *ld, LDAPMessage *res );
-LDAPMessage *ldap_next_reference( LDAP *ld, LDAPMessage *msg );
-int ldap_count_references( LDAP *ld, LDAPMessage *res );
-char ** ldap_get_reference_urls( LDAP *ld, LDAPMessage *res );
-
-/*
- * in addentry.c
- */
-LDAPMessage *ldap_delete_result_entry( LDAPMessage **list,
- LDAPMessage *e );
-void ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e );
-
-/*
- * in getdn.c
- */
-char *ldap_get_dn( LDAP *ld, LDAPMessage *entry );
-char **ldap_explode_dn( char *dn, int notypes );
-char ** ldap_explode_rdn( char *rdn, int notypes );
-char *ldap_dn2ufn( char *dn );
-
-char **ldap_explode_dns( char *dn );
-int ldap_is_dns_dn( char *dn );
-char *ldap_dns_to_dn(char *dns_name, int *nameparts);
-
-/*
- * in getattr.c
- */
-char *ldap_first_attribute( LDAP *ld, LDAPMessage *entry,
- BerElement **ber );
-char *ldap_next_attribute( LDAP *ld, LDAPMessage *entry,
- BerElement *ber );
-void ldap_memfree(char *mem);
-
-/*
- * in getvalues.c
- */
-char **ldap_get_values( LDAP *ld, LDAPMessage *entry, char *target );
-struct berval **ldap_get_values_len( LDAP *ld, LDAPMessage *entry,
- char *target );
-int ldap_count_values( char **vals );
-int ldap_count_values_len( struct berval **vals );
-void ldap_value_free( char **vals );
-void ldap_value_free_len( struct berval **vals );
-
-/*
- * in result.c:
- */
-int ldap_result( LDAP *ld, int msgid, int all,
- struct timeval *timeout, LDAPMessage **result );
-int ldap_msgdelete( LDAP *ld, int msgid );
-int ldap_msgfree( LDAPMessage *lm );
-int ldap_msgtype( LDAPMessage *res );
-int ldap_msgid( LDAPMessage *res );
-int ldap_parse_result(LDAP *ld, LDAPMessage *res, int *errcodep, char **matcheddnp, char **errmsgp, char ***referralsp, LDAPControl ***serverctrlsp, int freeit) ;
-int ldap_parse_sasl_bind_result(LDAP *ld, LDAPMessage *res, struct berval **servercredp, int freeit);
-int ldap_parse_extended_result(LDAP *ld, LDAPMessage *res, char **resultoidp, struct berval **resultdata, int freeit);
-
-/*
- * in search.c:
- */
-int ldap_search_ext(LDAP *ld, char *base, int scope, char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit, int *msgidp);
-int ldap_search_ext_s(LDAP *ld, char *base, int scope, char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit, LDAPMessage **res);
-
-int ldap_search( LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly );
-int ldap_search_s( LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, LDAPMessage **res );
-int ldap_search_st( LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, struct timeval *timeout, LDAPMessage **res );
-
-/*
- * in ufn.c
- */
-int ldap_ufn_search_c( LDAP *ld, char *ufn, char **attrs,
- int attrsonly, LDAPMessage **res, int (*cancelproc)( void *cl ),
- void *cancelparm );
-int ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs,
- int attrsonly, LDAPMessage **res, int (*cancelproc)( void *cl ),
- void *cancelparm, char *tag1, char *tag2, char *tag3 );
-int ldap_ufn_search_s( LDAP *ld, char *ufn, char **attrs,
- int attrsonly, LDAPMessage **res );
-LDAPFiltDesc *ldap_ufn_setfilter( LDAP *ld, char *fname );
-void ldap_ufn_setprefix( LDAP *ld, char *prefix );
-int ldap_ufn_timeout( void *tvparam );
-
-
-/*
- * in unbind.c
- */
-int ldap_unbind( LDAP *ld );
-int ldap_unbind_s( LDAP *ld );
-
-
-/*
- * in getfilter.c
- */
-LDAPFiltDesc *ldap_init_getfilter( char *fname );
-LDAPFiltDesc *ldap_init_getfilter_buf( char *buf, ssize_t buflen );
-LDAPFiltInfo *ldap_getfirstfilter( LDAPFiltDesc *lfdp, char *tagpat,
- char *value );
-LDAPFiltInfo *ldap_getnextfilter( LDAPFiltDesc *lfdp );
-void ldap_setfilteraffixes( LDAPFiltDesc *lfdp, char *prefix, char *suffix );
-void ldap_build_filter( char *buf, size_t buflen,
- char *pattern, char *prefix, char *suffix, char *attr,
- char *value, char **valwords );
-
-/*
- * in free.c
- */
-void ldap_getfilter_free( LDAPFiltDesc *lfdp );
-void ldap_mods_free( LDAPMod **mods, int freemods );
-
-/*
- * in friendly.c
- */
-char *ldap_friendly_name( char *filename, char *uname,
- FriendlyMap **map );
-void ldap_free_friendlymap( FriendlyMap **map );
-
-
-/*
- * in cldap.c
- */
-LDAP *cldap_open( char *host, int port );
-void cldap_close( LDAP *ld );
-int cldap_search_s( LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, LDAPMessage **res, char *logdn );
-void cldap_setretryinfo( LDAP *ld, int tries, time_t timeout );
-
-
-/*
- * in sort.c
- */
-int ldap_sort_entries( LDAP *ld, LDAPMessage **chain, char *attr,
- int (*cmp)() );
-int ldap_sort_values( LDAP *ld, char **vals, int (*cmp)() );
-int ldap_sort_strcasecmp( char **a, char **b );
-
-
-/*
- * in url.c
- */
-int ldap_is_ldap_url( char *url );
-int ldap_url_parse( char *url, LDAPURLDesc **ludpp );
-void ldap_free_urlexts( LDAPURLExt **lues );
-void ldap_free_urldesc( LDAPURLDesc *ludp );
-int ldap_url_search( LDAP *ld, char *url, int attrsonly );
-int ldap_url_search_s( LDAP *ld, char *url, int attrsonly,
- LDAPMessage **res );
-int ldap_url_search_st( LDAP *ld, char *url, int attrsonly,
- struct timeval *timeout, LDAPMessage **res );
-char *ldap_dns_to_url(LDAP *ld, char *dns_name, char *attrs,
-char *scope, char *filter);
-char *ldap_dn_to_url(LDAP *ld, char *dn, int nameparts);
-
-
-/*
- * in charset.c
- */
-#ifdef STR_TRANSLATION
-void ldap_set_string_translators( LDAP *ld,
- BERTranslateProc encode_proc, BERTranslateProc decode_proc );
-int ldap_translate_from_t61( LDAP *ld, char **bufp,
- unsigned int *lenp, int free_input );
-int ldap_translate_to_t61( LDAP *ld, char **bufp,
- unsigned int *lenp, int free_input );
-void ldap_enable_translation( LDAP *ld, LDAPMessage *entry,
- int enable );
-
-#ifdef LDAP_CHARSET_8859
-int ldap_t61_to_8859( char **bufp, unsigned int *buflenp,
- int free_input );
-int ldap_8859_to_t61( char **bufp, unsigned int *buflenp,
- int free_input );
-#endif /* LDAP_CHARSET_8859 */
-#endif /* STR_TRANSLATION */
-
-
-#ifdef WINSOCK
-/*
- * in msdos/winsock/wsa.c
- */
-void ldap_memfree( void *p );
-#endif /* WINSOCK */
diff --git a/usr/src/lib/libldap4/common/mapfile-vers b/usr/src/lib/libldap4/common/mapfile-vers
deleted file mode 100644
index 66b2a61087..0000000000
--- a/usr/src/lib/libldap4/common/mapfile-vers
+++ /dev/null
@@ -1,229 +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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
-#
-
-#
-# MAPFILE HEADER START
-#
-# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
-# Object versioning must comply with the rules detailed in
-#
-# usr/src/lib/README.mapfiles
-#
-# You should not be making modifications here until you've read the most current
-# copy of that file. If you need help, contact a gatekeeper for guidance.
-#
-# MAPFILE HEADER END
-#
-
-$mapfile_version 2
-
-SYMBOL_VERSION SUNW_1.2 {
- global:
- ber_alloc;
- ber_get_int;
-} SUNW_1.1;
-
-SYMBOL_VERSION SUNW_1.1 {
- global:
- ber_alloc_t;
- ber_bvdup;
- ber_bvecfree;
- ber_bvfree;
- ber_first_element;
- ber_flatten;
- ber_free;
- ber_init;
- ber_next_element;
- ber_peek_tag;
- ber_printf;
- ber_scanf;
- ber_skip_tag;
- cldap_close;
- cldap_open;
- cldap_search_s;
- cldap_setretryinfo;
- ldap_abandon;
- ldap_abandon_ext;
- ldap_add;
- ldap_add_ext;
- ldap_add_ext_s;
- ldap_add_s;
- ldap_bind;
- ldap_bind_s;
- ldap_build_filter;
- ldap_compare;
- ldap_compare_ext;
- ldap_compare_ext_s;
- ldap_compare_s;
- ldap_control_free;
- ldap_controls_free;
- ldap_count_entries;
- ldap_count_messages;
- ldap_count_references;
- ldap_count_values;
- ldap_count_values_len;
- ldap_create_sort_control;
- ldap_create_sort_keylist;
- ldap_create_virtuallist_control;
- ldap_delete;
- ldap_delete_ext;
- ldap_delete_ext_s;
- ldap_delete_s;
- ldap_destroy_cache;
- ldap_disable_cache;
- ldap_dn2ufn;
- ldap_dns_to_dn;
- ldap_dns_to_url;
- ldap_dn_to_url;
- ldap_enable_cache;
- ldap_enable_translation;
- ldap_entry2html;
- ldap_entry2html_search;
- ldap_entry2text;
- ldap_entry2text_search;
- ldap_err2string;
- ldap_explode_dn;
- ldap_explode_dns;
- ldap_explode_rdn;
- ldap_extended_operation;
- ldap_extended_operation_s;
- ldap_first_attribute;
- ldap_first_disptmpl;
- ldap_first_entry;
- ldap_first_message;
- ldap_first_reference;
- ldap_first_searchobj;
- ldap_first_tmplcol;
- ldap_first_tmplrow;
- ldap_flush_cache;
- ldap_free_friendlymap;
- ldap_free_searchprefs;
- ldap_free_sort_keylist;
- ldap_free_templates;
- ldap_free_urldesc;
- ldap_friendly_name;
- ldap_get_dn;
- ldap_getfilter_free;
- ldap_getfirstfilter;
- ldap_getnextfilter;
- ldap_get_option;
- ldap_get_values;
- ldap_get_values_len;
- ldap_init;
- ldap_init_getfilter;
- ldap_init_getfilter_buf;
- ldap_init_searchprefs;
- ldap_init_searchprefs_buf;
- ldap_init_templates;
- ldap_init_templates_buf;
- ldap_is_dns_dn;
- ldap_is_ldap_url;
- ldap_memfree;
- ldap_modify;
- ldap_modify_ext;
- ldap_modify_ext_s;
- ldap_modify_s;
- ldap_modrdn;
- ldap_modrdn_s;
- ldap_mods_free;
- ldap_msgfree;
- ldap_msgid;
- ldap_msgtype;
- ldap_next_attribute;
- ldap_next_disptmpl;
- ldap_next_entry;
- ldap_next_message;
- ldap_next_reference;
- ldap_next_searchobj;
- ldap_next_tmplcol;
- ldap_next_tmplrow;
- ldap_oc2template;
- ldap_open;
- ldap_parse_extended_result;
- ldap_parse_result;
- ldap_parse_sasl_bind_result;
- ldap_parse_sort_control;
- ldap_parse_virtuallist_control;
- ldap_perror;
- ldap_rename;
- ldap_rename_s;
- ldap_result;
- ldap_result2error;
- ldap_sasl_bind;
- ldap_sasl_bind_s;
- ldap_sasl_cram_md5_bind_s;
- ldap_search;
- ldap_search_ext;
- ldap_search_ext_s;
- ldap_search_s;
- ldap_search_st;
- ldap_set_cache_options;
- ldap_setfilteraffixes;
- ldap_set_option;
- ldap_set_rebind_proc;
- ldap_set_string_translators;
- ldap_simple_bind;
- ldap_simple_bind_s;
- ldap_sort_entries;
- ldap_sort_strcasecmp;
- ldap_sort_values;
- ldap_tmplattrs;
- ldap_translate_from_t61;
- ldap_translate_to_t61;
- ldap_ufn_search_c;
- ldap_ufn_search_ct;
- ldap_ufn_search_s;
- ldap_ufn_setfilter;
- ldap_ufn_setprefix;
- ldap_ufn_timeout;
- ldap_unbind;
- ldap_unbind_s;
- ldap_uncache_entry;
- ldap_uncache_request;
- ldap_url_parse;
- ldap_url_search;
- ldap_url_search_s;
- ldap_url_search_st;
- ldap_vals2html;
- ldap_vals2text;
- ldap_value_free;
- ldap_value_free_len;
- open_default_ldap_connection;
- set_ber_options;
-};
-
-SYMBOL_VERSION SUNWprivate_1.1 {
- global:
- i18n_catopen;
- ldap_create_page_control;
- ldap_get_reference_urls;
- ldaplogconfigf;
- ldap_parse_page_control;
- ldif_type_and_value;
- slapdcat;
- str_getline;
- str_parse_line;
- local:
- *;
-};
diff --git a/usr/src/lib/libldap4/common/modify.c b/usr/src/lib/libldap4/common/modify.c
deleted file mode 100644
index 4fb1d6c775..0000000000
--- a/usr/src/lib/libldap4/common/modify.c
+++ /dev/null
@@ -1,246 +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.
- *
- * modify.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_modify_req(LDAP *ld, char *dn, LDAPMod ** mods, LDAPControl **serverctrls)
-{
- BerElement *ber;
- int i, rc;
-
- /*
- * A modify request looks like this:
- * ModifyRequest ::= SEQUENCE {
- * object DistinguishedName,
- * modifications SEQUENCE OF SEQUENCE {
- * operation ENUMERATED {
- * add (0),
- * delete (1),
- * replace (2)
- * },
- * modification SEQUENCE {
- * type AttributeType,
- * values SET OF AttributeValue
- * }
- * }
- * }
- */
- /* create a message to send */
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
- return( NULLBER );
- }
- if ( ber_printf( ber, "{it{s{", ++ld->ld_msgid, LDAP_REQ_MODIFY, dn )
- == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULLBER );
- }
-
- /* for each modification to be performed... */
- for ( i = 0; mods[i] != NULL; i++ ) {
- if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) {
- rc = ber_printf( ber, "{e{s[V]}}",
- mods[i]->mod_op & ~LDAP_MOD_BVALUES,
- mods[i]->mod_type, mods[i]->mod_bvalues );
- } else {
- rc = ber_printf( ber, "{e{s[v]}}", mods[i]->mod_op,
- mods[i]->mod_type, mods[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_modify - initiate an ldap (and X.500) modify operation. Parameters:
- *
- * ld LDAP descriptor
- * dn DN of the object to modify
- * mods List of modifications to make. This is null-terminated
- * array of struct ldapmod's, specifying the modifications
- * to perform.
- *
- * Example:
- * LDAPMod *mods[] = {
- * { LDAP_MOD_ADD, "cn", { "babs jensen", "babs", 0 } },
- * { LDAP_MOD_REPLACE, "sn", { "jensen", 0 } },
- * 0
- * }
- * msgid = ldap_modify( ld, dn, mods );
- */
-int
-ldap_modify( LDAP *ld, char *dn, LDAPMod **mods )
-{
- 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_modify_req(ld, dn, mods, NULL)) == NULLBER){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
-
- /* send the message */
- rv = send_initial_request( ld, LDAP_REQ_MODIFY, dn, ber );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return ( rv );
-}
-
-int
-ldap_modify_s( LDAP *ld, char *dn, LDAPMod **mods )
-{
- int msgid;
- LDAPMessage *res;
-
- if ( (msgid = ldap_modify( ld, dn, mods )) == -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_modify_ext(LDAP *ld, char *dn, LDAPMod **mods,
- 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, 192, "ldap_modify\n"), 0, 0, 0 );
-
- if ((ber = ldap_build_modify_req(ld, dn, mods, 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_MODIFY, 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_modify_ext_s(LDAP *ld, char *dn, LDAPMod **mods,
- LDAPControl **serverctrls, LDAPControl **clientctrls)
-{
- int msgid;
- int retcode = LDAP_SUCCESS;
- LDAPMessage *res;
-
- if ((retcode = ldap_modify_ext(ld, dn, mods, 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);
-}
-
diff --git a/usr/src/lib/libldap4/common/modrdn.c b/usr/src/lib/libldap4/common/modrdn.c
deleted file mode 100644
index 3a7e1593f1..0000000000
--- a/usr/src/lib/libldap4/common/modrdn.c
+++ /dev/null
@@ -1,118 +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.
- *
- * modrdn.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"
-
-/*
- * ldap_modrdn - initiate an ldap (and X.500) modifyRDN operation. Parameters:
- *
- * ld LDAP descriptor
- * dn DN of the object to modify
- * newrdn RDN to give the object
- * deleteoldrdn nonzero means to delete old rdn values from the entry
- *
- * Example:
- * msgid = ldap_modrdn( ld, dn, newrdn );
- */
-int
-ldap_modrdn( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
-{
- BerElement *ber;
- int rv;
-
- /*
- * A modify rdn request looks like this:
- * ModifyRDNRequest ::= SEQUENCE {
- * entry DistinguishedName,
- * newrdn RelativeDistinguishedName,
- * deleteoldrdn BOOLEAN
- * }
- */
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 193, "ldap_modrdn\n"), 0, 0, 0 );
-
- /* create a message to send */
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
- newrdn, deleteoldrdn ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- /* send the message */
- rv = send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return ( rv );
-}
-
-int
-ldap_modrdn0( LDAP *ld, char *dn, char *newrdn )
-{
- return( ldap_modrdn( ld, dn, newrdn, 1 ) );
-}
-
-int
-ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
-{
- int msgid;
- LDAPMessage *res;
-
- if ( (msgid = ldap_modrdn( ld, dn, newrdn, deleteoldrdn )) == -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 ) );
-}
-
-int
-ldap_modrdn0_s( LDAP *ld, char *dn, char *newrdn )
-{
- return( ldap_modrdn_s( ld, dn, newrdn, 1 ) );
-}
diff --git a/usr/src/lib/libldap4/common/notif.c b/usr/src/lib/libldap4/common/notif.c
deleted file mode 100644
index f52cd56734..0000000000
--- a/usr/src/lib/libldap4/common/notif.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- *
- * Copyright 13/01/98 Sun Microsystems, Inc. All Rights Reserved
- * 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_notif(LDAP *ld)
-{
- return ld->ld_notifs;
-}
-
-LDAPMessage *ldap_next_notif(LDAP *ld, LDAPMessage *current)
-{
- if ( current == NULLMSG )
- return NULLMSG;
- else
- return current->lm_next;
-}
-
-int ldap_reset_notif(LDAP *ld, int freeit)
-{
- LDAPMessage *L_n=NULLMSG;
- LDAPMessage *L_q=NULLMSG;
-
- if ( freeit )
- {
- for (L_n=ld->ld_notifs; L_n!=NULLMSG; L_n=L_n->lm_next)
- {
- if ( L_n->lm_next != NULLMSG )
- {
- L_q = L_n->lm_next;
- ldap_msgfree(L_n);
- L_n = L_q;
- }
- else
- {
- ldap_msgfree(L_n);
- break;
- }
- }
- }
- ld->ld_notifs = NULLMSG;
-
- return (LDAP_SUCCESS);
-}
-
-int ldap_remove_notif(LDAP *ld, LDAPMessage *notif, int freeit)
-{
- LDAPMessage *L_n=NULLMSG, *L_q=NULLMSG;
-
- for ( L_n=ld->ld_notifs; L_n!=NULLMSG; L_n=L_n->lm_next)
- {
- if ( L_n == notif)
- {
- if ( L_q == NULLMSG )
- ld->ld_notifs = L_n->lm_next;
- else
- L_q->lm_next = L_n->lm_next;
-
- L_n->lm_next = NULLMSG;
- if ( freeit )
- ldap_msgfree(L_n);
-
- break;
- }
- L_q = L_n;
- }
- return (LDAP_SUCCESS);
-}
-
-/* Add in tail */
-int ldap_add_notif(LDAP *ld, LDAPMessage *notif)
-{
- LDAPMessage *L_n=NULLMSG, *L_q=NULLMSG;
-
- for ( L_n=ld->ld_notifs; L_n!=NULLMSG; L_n=L_n->lm_next)
- L_q = L_n;
-
- notif->lm_next = NULLMSG;
- if ( L_q == NULLMSG )
- ld->ld_notifs = notif;
- else
- L_q->lm_next = notif;
-
- return (LDAP_SUCCESS);
-}
-
-/* Add in head */
-int ldap_insert_notif(LDAP *ld, LDAPMessage *notif)
-{
-
- notif->lm_next = ld->ld_notifs;
- ld->ld_notifs = notif;
-
- return (LDAP_SUCCESS);
-}
-
diff --git a/usr/src/lib/libldap4/common/open.c b/usr/src/lib/libldap4/common/open.c
deleted file mode 100644
index 78211659f2..0000000000
--- a/usr/src/lib/libldap4/common/open.c
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * Copyright (c) 1995-2001 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Copyright (c) 1995 Regents of the University of Michigan.
- * All rights reserved.
- *
- * open.c
- */
-
-#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>
-#include <stdlib.h> /* calloc(), free(), atoi() for Solaris */
-#include <locale.h>
-#include <thread.h>
-
-#ifdef MACOS
-#include <stdlib.h>
-#include "macos.h"
-#endif /* MACOS */
-
-#if defined(DOS) || defined(_WIN32)
-#include "msdos.h"
-#include <stdlib.h>
-#endif /* DOS */
-
-#if !defined(MACOS) && !defined(DOS) && !defined(_WIN32)
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#ifndef VMS
-#include <sys/param.h>
-#endif
-#include <netinet/in.h>
-#endif
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-#ifdef LDAP_DEBUG
-int ldap_debug;
-#endif
-
-#ifndef INADDR_LOOPBACK
-#define INADDR_LOOPBACK ((unsigned int) 0x7f000001)
-#endif
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
-#endif
-
-extern int thr_kill(thread_t, int);
-
-/*
- * ldap_open - initialize and connect to an ldap server. A magic cookie to
- * be used for future communication is returned on success, NULL on failure.
- * "host" may be a space-separated list of hosts or IP addresses
- *
- * Example:
- * LDAP *ld;
- * ld = ldap_open( hostname, port );
- */
-
-LDAP *
-ldap_open(char *host, int port)
-{
- LDAP *ld;
- int err;
-
- if ((ld = ldap_init(host, port)) == NULL) {
- return (NULL);
- }
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 113,
- "ldap_open (after ldap_init)\n"), 0, 0, 0);
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ((err = open_default_ldap_connection(ld)) != LDAP_SUCCESS) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- ldap_ld_free(ld, 0);
- Debug(LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1275,
- "ldap_open failed, %s\n"),
- ldap_err2string(err), 0, 0);
- return (NULL);
- }
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 194,
- "ldap_open successful, ld_host is %s\n"),
- (ld->ld_host == NULL) ? "(null)" : ld->ld_host, 0, 0);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (ld);
-
-}
-
-/*
- * Open the default connection
- * ld->ld_defconn MUST be null when calling this function,
- * ie the connection was never established
- * ld should be LOCKed before calling this function
- */
-int
-open_default_ldap_connection(LDAP *ld)
-{
- LDAPServer *srv;
- int err;
-
- if ((srv = (LDAPServer *)calloc(1, sizeof (LDAPServer))) ==
- NULL || (ld->ld_defhost != NULL && (srv->lsrv_host =
- strdup(ld->ld_defhost)) == NULL)) {
- return (LDAP_NO_MEMORY);
- }
- srv->lsrv_port = ld->ld_defport;
-
- if ((ld->ld_defconn = new_connection(ld, &srv, 1, 1, 0)) ==
- NULL) {
- err = ld->ld_errno;
- Debug(LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1276,
- "Default connection to ldap server %s couldn't be "
- "opened (%d)\n"), ld->ld_defhost, err, 0);
-
- if (ld->ld_defhost != NULL)
- free(srv->lsrv_host);
- free((char *)srv);
- return (err);
- }
-
- /* so it never gets closed/freed */
- ++ld->ld_defconn->lconn_refcnt;
-
- return (LDAP_SUCCESS);
-}
-
-static pthread_mutex_t ldap_thr_index_mutex = {0};
-static pthread_t ldap_thr_table[MAX_THREAD_ID] = {0};
-
-int
-ldap_thr_index()
-{
- int i = 0;
- int free = 0;
- pthread_t cur = thr_self();
- for (i = 1; i < MAX_THREAD_ID; ++i) {
- if (ldap_thr_table[i] == cur) {
- return (i);
- } /* end if */
- } /* end for */
- /*
- * not in the table, allocate a new entry
- */
- pthread_mutex_lock(&ldap_thr_index_mutex);
- for (i = 1; i < MAX_THREAD_ID; ++i) {
- if (ldap_thr_table[i] == 0 ||
- thr_kill(ldap_thr_table[i], 0) != 0) {
- ldap_thr_table[i] = cur;
- pthread_mutex_unlock(&ldap_thr_index_mutex);
- return (i);
- } /* end if */
- } /* end for */
- pthread_mutex_unlock(&ldap_thr_index_mutex);
- /* if table is full, return the first entry, so that it */
- /* doesn't core dump */
- return (0);
-}
-
-/*
- * ldap_init - initialize the LDAP library. A magic cookie to be used for
- * future communication is returned on success, NULL on failure.
- * "defhost" may be a space-separated list of hosts or IP addresses
- *
- * Example:
- * LDAP *ld;
- * ld = ldap_init( default_hostname, default_port );
- */
-LDAP *
-ldap_init(char *defhost, int defport)
-{
- LDAP *ld;
- char *locale;
-
- locale = setlocale(LC_ALL, "");
- i18n_catopen("sdserver");
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 195,
- "ldap_init\n"), 0, 0, 0);
-
-
- if ((ld = (LDAP *) calloc(1, sizeof (LDAP))) == NULL) {
- return (NULL);
- }
-
-#ifdef _REENTRANT
- pthread_mutex_init(&ld->ld_ldap_mutex, DEFAULT_TYPE);
- pthread_mutex_init(&ld->ld_response_mutex, DEFAULT_TYPE);
- pthread_mutex_init(&ld->ld_poll_mutex, DEFAULT_TYPE);
- ld->ld_lockthread = 0;
-#endif
-
- if ((ld->ld_selectinfo = new_select_info()) == NULL) {
- free((char *)ld);
- return (NULL);
- }
- ld->ld_follow_referral = 1;
-
- /*
- * default to localhost when hostname is not specified
- * or if null string is passed as hostname
- */
-
- if ((defhost != NULL) && (*defhost != NULL) &&
- (ld->ld_defhost = strdup(defhost)) == NULL) {
- free_select_info(ld->ld_selectinfo);
- free((char *)ld);
- return (NULL);
- }
-
- ld->ld_defport = (defport == 0) ? LDAP_PORT : defport;
- ld->ld_version = LDAP_VERSION;
- ld->ld_lberoptions = LBER_USE_DER;
- ld->ld_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
- ld->ld_connect_timeout = LDAP_X_IO_TIMEOUT_NO_TIMEOUT;
-
-#if defined(STR_TRANSLATION) && defined(LDAP_DEFAULT_CHARSET)
- ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
-#if LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET
- ldap_set_string_translators(ld, ldap_8859_to_t61,
- ldap_t61_to_8859);
-#endif /* LDAP_CHARSET_8859 == LDAP_DEFAULT_CHARSET */
-#endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
-
- return (ld);
-}
-
-
-/* ARGSUSED */
-int
-open_ldap_connection(LDAP *ld, Sockbuf *sb, char *host, int defport,
- char **krbinstancep, int async)
-{
- int rc, port;
- char *p, *q, *r;
- char *curhost, hostname[ 2*MAXHOSTNAMELEN ];
- int bindTimeout;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 196,
- "open_ldap_connection\n"), 0, 0, 0);
-
- defport = htons(defport);
- bindTimeout = ld->ld_connect_timeout;
-
- if (host != NULL) {
- for (p = host; p != NULL && *p != '\0'; p = q) {
- if ((q = strchr(p, ' ')) != NULL) {
- (void) strncpy(hostname, p, q - p);
- hostname[ q - p ] = '\0';
- curhost = hostname;
- while (*q == ' ') {
- ++q;
- }
- } else {
- /* avoid copy if possible */
- curhost = p;
- q = NULL;
- }
-
- if ((r = strchr(curhost, ':')) != NULL) {
- if (curhost != hostname) {
- /* now copy */
- (void) strcpy(hostname, curhost);
- r = hostname + (r - curhost);
- curhost = hostname;
- }
- *r++ = '\0';
- port = htons((short)atoi(r));
- } else {
- port = defport;
- }
-
- if ((rc = connect_to_host(sb, curhost, 0,
- port, async, bindTimeout)) != -1) {
- break;
- }
- }
- } else {
- rc = connect_to_host(sb, NULL, htonl(INADDR_LOOPBACK),
- defport, async, bindTimeout);
- }
-
- if (rc == -1) {
- return (rc);
- }
-
- if (krbinstancep != NULL) {
-#ifdef KERBEROS
- if ((*krbinstancep = host_connected_to(sb)) != NULL &&
- (p = strchr(*krbinstancep, '.')) != NULL) {
- *p = '\0';
- }
-#else /* KERBEROS */
- krbinstancep = NULL;
-#endif /* KERBEROS */
- }
-
- return (0);
-}
-
-/*
- * ldap_ssl_open - initialize and connect to an ssl secured ldap
- * server. First ldap_open() is called and then ssl is layered on top
- * of the socket. A magic cookie to be used for future communication
- * is returned on success, NULL on failure. "host" may be a
- * space-separated list of hosts or IP addresses. CAfile and CApath
- * are used first time through, subsequent calls are ignored and can
- * be NULL.
- *
- * Example:
- * LDAP *ld;
- * ld = ldap_ssl_open( hostname, port, key );
- */
-
-#ifdef LDAP_SSL
-
-#include "security/ssl.h"
-
-int
-establish_ssl_connection(LDAP *ld)
-{
- SSL *ssl = NULL; /* The Client's SSL connection */
-
- /*
- * Creates a new SSL connection. This holds information
- * pertinent to this
- * connection.
- */
- if ((ssl = SSL_new()) == NULL) {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 198,
- "SSL_new() failed: %s\n"),
- SSL_strerr(SSL_errno(ssl)), 0, 0);
- return (-1);
- }
-
- /* if keyname is non-null, set ssl keypackage name from it */
- if (ld->ld_ssl_key != NULL) {
- if (SSL_set_userid(ssl, ld->ld_ssl_key, 0) == NULL) {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 199, "SSL_set_userid() failed: %s\n"),
- SSL_strerr(SSL_errno(ssl)), 0, 0);
- return (-1);
- }
- }
-
- /* Start the SSL connection */
- if (SSL_connect(ssl, ld->ld_sb.sb_sd) < 1) {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 200,
- "SSL_connect() failed: %s\n"),
- SSL_strerr(SSL_errno(ssl)), 0, 0);
- return (-1);
- }
-
- ld->ld_sb.sb_ssl = ssl;
- return (0);
-}
-
-
-LDAP *
-ldap_ssl_open(char *host, int port, char *keyname)
-{
- LDAP *ld;
- int rval;
-
-
- if (port == 0)
- port = SSL_LDAP_PORT;
-
- ld = ldap_open(host, port);
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 197,
- "ldap_ssl_open (after ldap_open)\n"), 0, 0, 0);
-
- if (ld == NULL)
- return (NULL);
-
- ld->ld_use_ssl = 1;
- if (keyname)
- ld->ld_ssl_key = strdup(keyname);
-
- if (establish_ssl_connection(ld) != 0) {
- ldap_ld_free(ld, 1);
- return (NULL);
- }
-
- return (ld);
-}
-
-LDAP *
-ldap_ssl_init(char *defhost, int defport, char *keyname)
-{
- LDAP *ld;
- int rval;
-
-
- if (defport == 0)
- defport = SSL_LDAP_PORT;
-
- ld = ldap_init(defhost, defport);
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 197,
- "ldap_ssl_open (after ldap_open)\n"), 0, 0, 0);
-
- if (ld == NULL)
- return (NULL);
- ld->ld_use_ssl = 1;
- ld->ld_ssl_key = strdup(keyname);
-
- return (ld);
-}
-
-#endif /* LDAP_SSL */
diff --git a/usr/src/lib/libldap4/common/option.c b/usr/src/lib/libldap4/common/option.c
deleted file mode 100644
index b80d6a609c..0000000000
--- a/usr/src/lib/libldap4/common/option.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (c) 1995-2001 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-#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"
-
-extern LDAPControl ** ldap_controls_dup(LDAPControl **ctrls);
-
-/*
- * ldap_get_option()
- */
-int
-ldap_get_option(LDAP *ld, int option, void *outvalue)
-{
- if (ld == NULL)
- return (-1);
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- switch (option) {
- case LDAP_OPT_API_INFO:
- ((LDAPAPIInfo *)outvalue)->ldapai_api_version =
- LDAP_API_VERSION;
- if (((LDAPAPIInfo *)outvalue)->ldapai_info_version !=
- LDAP_API_INFO_VERSION) {
- ((LDAPAPIInfo *)outvalue)->ldapai_info_version =
- LDAP_API_INFO_VERSION;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- ((LDAPAPIInfo *)outvalue)->ldapai_protocol_version =
- LDAP_VERSION_MAX;
- /* No extensions are currently supported */
- ((LDAPAPIInfo *)outvalue)->ldapai_extensions = NULL;
- ((LDAPAPIInfo *)outvalue)->ldapai_vendor_name =
- strdup(LDAP_VENDOR_NAME);
- ((LDAPAPIInfo *)outvalue)->ldapai_vendor_version =
- LDAP_VENDOR_VERSION;
- break;
- case LDAP_OPT_DESC: /* depricated option */
- *(int *)outvalue = ld->ld_sb.sb_sd;
- break;
- case LDAP_OPT_DEREF:
- *(int *)outvalue = ld->ld_deref;
- break;
- case LDAP_OPT_SIZELIMIT:
- *(int *)outvalue = ld->ld_sizelimit;
- break;
- case LDAP_OPT_TIMELIMIT:
- *(int *)outvalue = ld->ld_timelimit;
- break;
- case LDAP_OPT_REBIND_FN: /* depricated option */
- outvalue = (void *)ld->ld_rebindproc;
- break;
- case LDAP_OPT_REBIND_ARG: /* depricated option */
- outvalue = ld->ld_rebind_extra_arg;
- break;
- case LDAP_OPT_REFERRALS:
- *(int *)outvalue = ld->ld_follow_referral;
- break;
- case LDAP_OPT_RESTART:
- *(int *)outvalue = ld->ld_restart;
- break;
- case LDAP_OPT_PROTOCOL_VERSION:
- *(int *)outvalue = ld->ld_version;
- break;
- case LDAP_OPT_SERVER_CONTROLS:
- outvalue = ld->ld_srvctrls;
- break;
- case LDAP_OPT_CLIENT_CONTROLS:
- outvalue = ld->ld_cltctrls;
- break;
- case LDAP_OPT_API_FEATURE_INFO:
- if ((((LDAPAPIFeatureInfo *)outvalue)->ldapaif_info_version !=
- LDAP_FEATURE_INFO_VERSION) ||
- (((LDAPAPIFeatureInfo *)outvalue)->ldapaif_name ==
- NULL)) {
- ((LDAPAPIFeatureInfo *)outvalue)->ldapaif_info_version =
- LDAP_FEATURE_INFO_VERSION;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- /*
- * This option must be completed when optional api's (or
- * (extensions) are supported by this library. Right now
- * there are none, and therefore this section can not be
- * completed.
- */
- break;
- case LDAP_OPT_HOST_NAME:
- *(char **)outvalue = ld->ld_host;
- break;
- case LDAP_OPT_ERROR_NUMBER:
- *(int *)outvalue = ld->ld_errno;
- break;
- case LDAP_OPT_ERROR_STRING:
- *(char **)outvalue = ld->ld_error;
- break;
- case LDAP_OPT_MATCHED_DN:
-/* case LDAP_OPT_ERROR_MATCHED: depricated option */
- *(char **)outvalue = ld->ld_matched;
- break;
- case LDAP_X_OPT_CONNECT_TIMEOUT:
- *((int *)outvalue) = ld->ld_connect_timeout;
- break;
- default:
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (0);
-}
-
-int
-ldap_set_option(LDAP *ld, int option, void *invalue)
-{
- if (ld == NULL)
- return (-1);
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- switch (option) {
- case LDAP_OPT_DESC:
- break;
- case LDAP_OPT_DEREF:
- if (*(int *)invalue != LDAP_DEREF_NEVER &&
- *(int *)invalue != LDAP_DEREF_SEARCHING &&
- *(int *)invalue != LDAP_DEREF_FINDING &&
- *(int *)invalue != LDAP_DEREF_ALWAYS) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- ld->ld_deref = *(int *)invalue;
- break;
- case LDAP_OPT_SIZELIMIT:
- ld->ld_sizelimit = *(int *)invalue;
- break;
- case LDAP_OPT_TIMELIMIT:
- ld->ld_timelimit = *(int *)invalue;
- break;
- case LDAP_OPT_REBIND_FN:
- /* cast needs to be updated when ldap.h gets updated */
- ld->ld_rebindproc = (LDAP_REBIND_FUNCTION *)invalue;
- break;
- case LDAP_OPT_REBIND_ARG:
- ld->ld_rebind_extra_arg = invalue;
- break;
- case LDAP_OPT_REFERRALS:
- if (invalue != LDAP_OPT_ON && invalue != LDAP_OPT_OFF) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- ld->ld_follow_referral = invalue ? 1 : 0;
- break;
- case LDAP_OPT_RESTART:
- if (invalue != LDAP_OPT_ON && invalue != LDAP_OPT_OFF) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- ld->ld_restart = invalue ? 1 : 0;
- break;
- case LDAP_OPT_PROTOCOL_VERSION:
- if (*(int *)invalue < LDAP_VERSION1 ||
- *(int *)invalue > LDAP_VERSION3) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
- ld->ld_version = *(int *)invalue;
- break;
- case LDAP_OPT_SERVER_CONTROLS:
- if (ld->ld_srvctrls != NULL) {
- ldap_controls_free(ld->ld_srvctrls);
- }
- ld->ld_srvctrls = NULL;
- if (invalue != NULL)
- ld->ld_srvctrls = ldap_controls_dup(invalue);
- break;
- case LDAP_OPT_CLIENT_CONTROLS:
- if (ld->ld_cltctrls != NULL) {
- ldap_controls_free(ld->ld_cltctrls);
- }
- ld->ld_cltctrls = NULL;
- if (invalue != NULL)
- ld->ld_cltctrls = ldap_controls_dup(invalue);
- break;
- case LDAP_OPT_HOST_NAME:
- if (ld->ld_host != NULL) {
- free(ld->ld_host);
- }
- ld->ld_host = NULL;
- if ((char *)invalue != NULL)
- ld->ld_host = strdup((char *)invalue);
- break;
- case LDAP_OPT_ERROR_NUMBER:
- break;
- case LDAP_OPT_ERROR_STRING:
- break;
- case LDAP_OPT_MATCHED_DN:
- if (ld->ld_matched)
- free(ld->ld_matched);
- ld->ld_matched = NULL;
- if ((char *)invalue != NULL)
- ld->ld_matched = strdup((char *)invalue);
- break;
- case LDAP_X_OPT_CONNECT_TIMEOUT:
- ld->ld_connect_timeout = *((int *)invalue);
- break;
- default:
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (0);
-}
diff --git a/usr/src/lib/libldap4/common/os-ip.c b/usr/src/lib/libldap4/common/os-ip.c
deleted file mode 100644
index 5f025ee548..0000000000
--- a/usr/src/lib/libldap4/common/os-ip.c
+++ /dev/null
@@ -1,614 +0,0 @@
-/*
- * Copyright (c) 1995-2001 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Copyright (c) 1995 Regents of the University of Michigan.
- * All rights reserved.
- *
- * os-ip.c -- platform-specific TCP & UDP related code
- */
-
-#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>
-#include <errno.h>
-#include <arpa/inet.h>
-
-#ifdef _WIN32
-#include <io.h>
-#include "msdos.h"
-#else /* _WIN32 */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif /* _WIN32 */
-#ifdef _AIX
-#include <sys/select.h>
-#endif /* _AIX */
-#ifdef VMS
-#include "ucx_select.h"
-#endif /* VMS */
-#include "portable.h"
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-#ifdef LDAP_REFERRALS
-#ifdef USE_SYSCONF
-#include <unistd.h>
-#endif /* USE_SYSCONF */
-#ifdef notyet
-#ifdef NEED_FILIO
-#include <sys/filio.h>
-#else /* NEED_FILIO */
-#include <sys/ioctl.h>
-#endif /* NEED_FILIO */
-#endif /* notyet */
-#endif /* LDAP_REFERRALS */
-
-#ifdef MACOS
-#define tcp_close(s) tcpclose(s)
-#else /* MACOS */
-#ifdef DOS
-#ifdef PCNFS
-#define tcp_close(s) close(s)
-#endif /* PCNFS */
-#ifdef NCSA
-#define tcp_close(s) netclose(s); netshut()
-#endif /* NCSA */
-#ifdef WINSOCK
-#define tcp_close(s) closesocket(s); WSACleanup();
-#endif /* WINSOCK */
-#else /* DOS */
-#define tcp_close(s) close(s)
-#endif /* DOS */
-#endif /* MACOS */
-#ifdef SUN
-#include <nss_dbdefs.h>
-#endif
-
-#include <fcntl.h>
-#include <sys/poll.h>
-
-
-/*
- * Do an async connect or blocking connect depending on the timeout
- * value. LDAP_X_IO_TIMEOUT_NO_TIMEOUT means do a blocking connect.
- * Otherwise wait for timeout milliseconds for the connection.
- * Returns 0 on success and -1 on failure.
- */
-static int
-do_connect(int s, struct sockaddr *sin, int timeout)
-{
- int flags, connected = 0;
- int retval, error, n;
- fd_set wfds;
- struct timeval waittime, *sel_timeout;
-
- /* set the socket to do non-blocking i/o */
- flags = fcntl(s, F_GETFL, 0);
- fcntl(s, F_SETFL, flags | O_NONBLOCK);
-
- if (connect(s, sin, sizeof (struct sockaddr_in)) == 0) {
- connected = 1;
- } else if (errno == EINPROGRESS) {
- /* if NO_TIMEOUT is specified do a blocking connect */
- if (timeout <= LDAP_X_IO_TIMEOUT_NO_TIMEOUT) {
- sel_timeout = NULL;
- } else {
- /* set the timeout to the specified value */
- waittime.tv_sec = timeout / MILLISEC;
- waittime.tv_usec = (timeout % MILLISEC) * 1000;
- sel_timeout = &waittime;
- }
-
- FD_ZERO(&wfds);
- FD_SET(s, &wfds);
- n = sizeof (error);
- if (select(s+1, NULL, &wfds, NULL, sel_timeout) > 0 &&
- FD_ISSET(s, &wfds) &&
- getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &n) == 0 &&
- error == 0) {
- connected = 1;
- }
- }
-
- /* if we are connected restore the flags for the socket */
- if (connected) {
- fcntl(s, F_SETFL, flags);
- }
-
- return (connected ? 0 : -1);
-}
-
-
-int
-connect_to_host(Sockbuf *sb, char *host, in_addr_t address,
- int port, int async, int timeout)
-/*
- * if host == NULL, connect using address
- * "address" and "port" must be in network byte order
- * zero is returned upon success, -1 if fatal error, -2 EINPROGRESS
- * async is only used ifdef LDAP_REFERRALS (non-0 means don't wait for connect)
- * XXX async is not used yet!
- */
-{
- int rc, i, s, connected, use_hp;
- struct sockaddr_in sin;
- struct hostent *hp;
-#ifdef notyet
-#ifdef LDAP_REFERRALS
- int status; /* for ioctl call */
-#endif /* LDAP_REFERRALS */
-#endif /* notyet */
-#ifdef SUN
- struct hostent hpret;
- char hpbuf[NSS_BUFLEN_HOSTS];
- int hperrno;
-#endif
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 201, "connect_to_host: "
- "%1$s:%2$d\n"), (host == NULL) ? catgets(slapdcat, 1, 202,
- "(by address)") : host, ntohs(port), 0);
-
- connected = use_hp = 0;
-
- if (host != NULL && (address = inet_addr(host)) == -1) {
-#ifdef SUN
- if ((hp = gethostbyname_r(host, &hpret, hpbuf,
- NSS_BUFLEN_HOSTS, &hperrno)) == NULL) {
-#else
- if ((hp = gethostbyname(host)) == NULL) {
-#endif
- errno = EHOSTUNREACH; /* not exactly right, but... */
- return (-1);
- }
- use_hp = 1;
- }
-
- rc = -1;
- for (i = 0; !use_hp || (hp->h_addr_list[i] != 0); i++) {
- if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- return (-1);
- }
-#ifdef notyet
-#ifdef LDAP_REFERRALS
- status = 1;
- if (async && ioctl(s, FIONBIO, (caddr_t)&status) == -1) {
- Debug(LDAP_DEBUG_ANY, catgets(slapdcat, 1, 203,
- "FIONBIO ioctl failed on %d\n"), s, 0, 0);
- }
-#endif /* LDAP_REFERRALS */
-#endif /* notyet */
- (void) memset((char *)&sin, 0, sizeof (struct sockaddr_in));
- sin.sin_family = AF_INET;
- sin.sin_port = port;
- SAFEMEMCPY((char *) &sin.sin_addr.s_addr,
- (use_hp ? (char *) hp->h_addr_list[i] :
- (char *)&address), sizeof (sin.sin_addr.s_addr));
-
- if (do_connect(s, (struct sockaddr *)&sin, timeout) == 0) {
- connected = 1;
- break;
- }
-
-#ifdef notyet
-#ifdef LDAP_REFERRALS
-#ifdef EAGAIN
- if (errno == EINPROGRESS || errno == EAGAIN) {
-#else /* EAGAIN */
- if (errno == EINPROGRESS) {
-#endif /* EAGAIN */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 204,
- "connect would block...\n"), 0, 0, 0);
- rc = -2;
- break;
- }
-#endif /* LDAP_REFERRALS */
-#endif /* notyet */
-
-#ifdef LDAP_DEBUG
- if (ldap_debug & LDAP_DEBUG_TRACE) {
- perror((char *)inet_ntoa(sin.sin_addr));
- }
-#endif
- close(s);
- if (!use_hp) {
- break;
- }
- }
-
- if (connected) {
- rc = 0;
- sb->sb_sd = s;
-#ifdef notyet
-#ifdef LDAP_REFERRALS
- status = 0;
- if (!async && ioctl(s, FIONBIO, (caddr_t)&on) == -1) {
- Debug(LDAP_DEBUG_ANY, catgets(slapdcat, 1, 203,
- "FIONBIO ioctl failed on %d\n"), s, 0, 0);
- }
-#endif /* LDAP_REFERRALS */
-#endif /* notyet */
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 205,
- "sd %1$d connected to: %2$s\n"), s,
- inet_ntoa(sin.sin_addr), 0);
- }
-
- return (rc);
-}
-
-
-void
-close_ldap_connection( Sockbuf *sb )
-{
-#ifdef LDAP_SSL
- if (sb->sb_ssl){
- SSL_close(sb->sb_ssl);
- SSL_delete(sb->sb_ssl);
- }
- sb->sb_ssl = NULL;
- sb->sb_ssl_tls = 0;
-#endif
- tcp_close( sb->sb_sd );
-}
-
-
-#ifdef KERBEROS
-char *
-host_connected_to( Sockbuf *sb )
-{
- struct hostent *hp;
- char *p;
- int len;
- struct sockaddr_in sin;
-#ifdef SUN
- struct hostent hpret;
- char hpbuf[NSS_BUFLEN_HOSTS];
- int hperrno;
-#endif
-
- (void)memset( (char *)&sin, 0, sizeof( struct sockaddr_in ));
- len = sizeof( sin );
- if ( getpeername( sb->sb_sd, (struct sockaddr *)&sin, &len ) == -1 ) {
- return( NULL );
- }
-
- /*
- * do a reverse lookup on the addr to get the official hostname.
- * this is necessary for kerberos to work right, since the official
- * hostname is used as the kerberos instance.
- */
-#ifdef SUN
- if (( hp = gethostbyaddr_r((char *) &sin.sin_addr,
- sizeof( sin.sin_addr ), AF_INET,
- &hpret, hpbuf, NSS_BUFLEN_HOSTS, &hperrno)) != NULL ) {
-#else
- if (( hp = gethostbyaddr( (char *) &sin.sin_addr,
- sizeof( sin.sin_addr ), AF_INET )) != NULL ) {
-#endif
- if ( hp->h_name != NULL ) {
- return( strdup( hp->h_name ));
- }
- }
-
- return( NULL );
-}
-#endif /* KERBEROS */
-
-
-#ifdef LDAP_REFERRALS
-#ifdef SUN
-/* for UNIX */
-#include <stropts.h>
-#include <poll.h>
-
-struct selectinfo {
- struct pollfd fds[LDAP_DEFAULT_REFHOPLIMIT];
- int nbfds;
-};
-
-
-void
-mark_select_write( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
- int i;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- /* find if sb is in fds */
- for (i=0; i< sip->nbfds; i++) {
- if (sip->fds[i].fd == sb->sb_sd){
- sip->fds[i].events |= POLLOUT;
- return;
- }
- }
- if (sip->nbfds < LDAP_DEFAULT_REFHOPLIMIT) {
- sip->fds[sip->nbfds].fd = sb->sb_sd;
- sip->fds[sip->nbfds].events |= POLLOUT;
- sip->nbfds++;
- }
- else {
- /* Should not happen */
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 206, "Mark for poll : Too many descriptors\n"), 0, 0, 0 );
- }
-}
-
-
-void
-mark_select_read( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
- int i;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- /* find if sb is in fds */
- for (i=0; i< sip->nbfds; i++) {
- if (sip->fds[i].fd == sb->sb_sd) {
- sip->fds[i].events |= POLLIN;
- return;
- }
- }
-
- if (sip->nbfds < LDAP_DEFAULT_REFHOPLIMIT) {
- sip->fds[sip->nbfds].fd = sb->sb_sd;
- sip->fds[sip->nbfds].events |= POLLIN;
- sip->nbfds++;
- }
- else {
- /* Should not happen */
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 206, "Mark for poll : Too many descriptors\n"), 0, 0, 0 );
- }
-}
-
-
-void
-mark_select_clear( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
- int i;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- for (i = 0; i< sip->nbfds; i++) {
- if (sip->fds[i].fd == sb->sb_sd){
- i++;
- for (; i < sip->nbfds; i ++) {
- sip->fds[ i - 1] = sip->fds[i];
- }
- sip->fds[i].fd = -1;
- sip->fds[i].events = -1;
- sip->nbfds--;
- return;
- }
- }
- /* If we reach here, there's a pb. */
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 207, "Clear poll : descriptor not found\n"), 0, 0, 0 );
-}
-
-
-long
-is_write_ready( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
- int i;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- for (i=0; i< sip->nbfds; i++) {
- if (sip->fds[i].fd == sb->sb_sd) {
- if ( sip->fds[i].revents & (POLLERR | POLLHUP | POLLNVAL)) {
- return (-1);
- }
- return( sip->fds[i].revents & POLLOUT );
- }
- }
- return(0);
-}
-
-
-long
-is_read_ready( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
- int i;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- for (i=0; i< sip->nbfds; i++) {
- if (sip->fds[i].fd == sb->sb_sd) {
- if (sip->fds[i].revents & (POLLERR | POLLHUP | POLLNVAL)) {
- return (-1);
- }
- return( sip->fds[i].revents & POLLIN );
- }
- }
- return(0);
-}
-
-void *
-new_select_info()
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)calloc( 1, sizeof( struct selectinfo ));
-
- return( (void *)sip );
-}
-
-
-void
-free_select_info( void *sip )
-{
- free( sip );
-}
-
-
-int
-do_ldap_select( LDAP *ld, struct timeval *timeout )
-{
- struct selectinfo *sip;
- int tim;
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-#endif
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 208, "do_ldap_select\n"), 0, 0, 0 );
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
-/* sip->fds[0].revents = 0; */
-
- if ( timeout ) {
- tim = (timeout->tv_sec*1000)+(timeout->tv_usec/1000);
- } else {
- tim = INFTIM;
- } /* end if */
- errno=0;
-#if defined( SUN ) && defined( _REENTRANT )
-/* UNLOCK_LDAP(ld); */
- LOCK_POLL(ld);
- rv = poll(sip->fds,sip->nbfds,tim);
-/* LOCK_LDAP(ld); */
- UNLOCK_POLL(ld);
- return(rv);
-#else
- return( poll(sip->fds,sip->nbfds,tim) );
-#endif
-}
-#else
-/* for UNIX */
-struct selectinfo {
- fd_set si_readfds;
- fd_set si_writefds;
- fd_set si_use_readfds;
- fd_set si_use_writefds;
-};
-
-
-void
-mark_select_write( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- if ( !FD_ISSET( sb->sb_sd, &sip->si_writefds )) {
- FD_SET( sb->sb_sd, &sip->si_writefds );
- }
-}
-
-
-void
-mark_select_read( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- if ( !FD_ISSET( sb->sb_sd, &sip->si_readfds )) {
- FD_SET( sb->sb_sd, &sip->si_readfds );
- }
-}
-
-
-void
-mark_select_clear( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- FD_CLR( sb->sb_sd, &sip->si_writefds );
- FD_CLR( sb->sb_sd, &sip->si_readfds );
-}
-
-
-long
-is_write_ready( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- return( FD_ISSET( sb->sb_sd, &sip->si_use_writefds ));
-}
-
-
-long
-is_read_ready( LDAP *ld, Sockbuf *sb )
-{
- struct selectinfo *sip;
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
-
- return( FD_ISSET( sb->sb_sd, &sip->si_use_readfds ));
-}
-
-
-void *
-new_select_info()
-{
- struct selectinfo *sip;
-
- if (( sip = (struct selectinfo *)calloc( 1,
- sizeof( struct selectinfo ))) != NULL ) {
- FD_ZERO( &sip->si_readfds );
- FD_ZERO( &sip->si_writefds );
- }
-
- return( (void *)sip );
-}
-
-
-void
-free_select_info( void *sip )
-{
- free( sip );
-}
-
-
-int
-do_ldap_select( LDAP *ld, struct timeval *timeout )
-{
- struct selectinfo *sip;
- static int tblsize;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 208, "do_ldap_select\n"), 0, 0, 0 );
-
-#if defined( SUN ) && defined( _REENTRANT )
- LOCK_LDAP(ld);
-#endif
- if ( tblsize == 0 ) {
-#ifdef USE_SYSCONF
- tblsize = (int)sysconf( _SC_OPEN_MAX );
-#else /* USE_SYSCONF */
- tblsize = getdtablesize();
-#endif /* USE_SYSCONF */
- }
-
- sip = (struct selectinfo *)ld->ld_selectinfo;
- sip->si_use_readfds = sip->si_readfds;
- sip->si_use_writefds = sip->si_writefds;
-
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( select( tblsize, &sip->si_use_readfds, &sip->si_use_writefds,
- NULL, timeout ));
-}
-#endif /* SUN */
-#endif /* LDAP_REFERRALS */
diff --git a/usr/src/lib/libldap4/common/referral.c b/usr/src/lib/libldap4/common/referral.c
deleted file mode 100644
index 173ee2cfe6..0000000000
--- a/usr/src/lib/libldap4/common/referral.c
+++ /dev/null
@@ -1,511 +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 <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/errno.h>
-#include "portable.h"
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-static BerElement *
-re_encode_request( LDAP *ld, BerElement *origber, int msgid, LDAPURLDesc *urldesc );
-static void addFollowedRef(LDAPRequest *lr, char *ref);
-static void addToFollowRef(LDAPRequest *lr, char *ref);
-static int addUnFollowedRef(LDAP *ld, LDAPRequest *lr, char *ref);
-
-char ** ldap_errormsg2referrals(char *errmsg) {
- char ** refs;
- int count;
- size_t len;
- char *p, *ref;
-
- if (errmsg == NULL){
- return (NULL);
- }
- len = strlen( errmsg );
- for ( p = errmsg; len >= LDAP_REF_STR_LEN; ++p, --len ) {
- if (( *p == 'R' || *p == 'r' ) && strncasecmp( p,
- LDAP_REF_STR, LDAP_REF_STR_LEN ) == 0 ) {
- *p = '\0';
- p += LDAP_REF_STR_LEN;
- break;
- }
- }
-
- if ( len < LDAP_REF_STR_LEN ) {
- return( NULL);
- }
- count = 1;
- ref = p;
- while ((ref = strchr(ref, '\n')) != NULL)
- count++;
-
- if ((refs = (char **)calloc(count + 1, sizeof(char *))) == NULL){
- return (NULL);
- }
-
- count = 0;
- for (ref = p; ref != NULL; ref= p){
- if ((p = strchr(ref, '\n')) != NULL){
- *p = '\0';
- }
- refs[count++] = strdup(ref);
- if (p != NULL)
- *p++ = '\n';
- }
- return (refs);
-}
-
-char *ldap_referral2error_msg(char ** refs)
-{
- int i;
- size_t len = 0;
- char *msg = NULL;
-
- if (refs == NULL)
- return (msg);
-
- for (i = 0; refs[i] != NULL; i++){
- len += strlen (refs[i]) + 1;
- }
-
- if ((len > 0) && ((msg = (char *)malloc(len + LDAP_REF_STR_LEN + 2)) != NULL)) {
- strncpy(msg, LDAP_REF_STR, LDAP_REF_STR_LEN);
- for (i = 0; refs[i] != NULL; i++) {
- strcat(msg, refs[i]);
- strcat(msg, "\n");
- }
- }
- return (msg);
-}
-
-
-int
-chase_referrals( LDAP *ld, LDAPRequest *lr, char **refs, int *count, int samerequest )
-{
- int rc, len, newdn, i, j, refcnt, errCode;
- char *p, *ports, *ref, *tmpref, *refdn;
- LDAPRequest *origreq;
- LDAPServer *srv;
- BerElement *ber;
- LDAPURLDesc *ludp;
-
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 215, "=> chase_referrals\n"), 0, 0, 0 );
-
- ld->ld_errno = LDAP_SUCCESS; /* optimistic */
- *count = 0;
- if ( refs == NULL ) {
- return( LDAP_SUCCESS );
- }
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
-
- if ( lr->lr_parentcnt >= ld->ld_refhoplimit ) {
- Debug( LDAP_DEBUG_ANY,
- catgets(slapdcat, 1, 216, "more than %d referral hops (dropping)\n"),
- ld->ld_refhoplimit, 0, 0 );
- /* XXX report as error in ld->ld_errno? */
- rc = ld->ld_errno = (ld->ld_version >= LDAP_VERSION3) ? LDAP_REFERRAL_LIMIT_EXCEEDED : LDAP_OTHER;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( rc );
- }
-
- /* find original request */
- for ( origreq = lr; origreq->lr_parent != NULL;
- origreq = origreq->lr_parent ) {
- ;
- }
-
- for (refcnt = 0; refs[refcnt] != NULL; refcnt++)
- ; /* Count number of referrals */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1277, "%d possible referrals to chase\n"), refcnt, 0,0);
-
- rc = 0;
- /* parse out & follow referrals */
- for (i = 0; rc == 0 && refs[i] != NULL; i++) {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "Try to chase %s\n"), refs[i], 0,0);
-
- /* Parse URL */
- if (ldap_url_parse(refs[i], &ludp) != 0){
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "Bad URL for referral %s\n"), refs[i], 0,0);
- errCode = LDAP_PARAM_ERROR;
- addUnFollowedRef(ld, lr, refs[i]);
- /* try next URL */
- continue;
- }
-
- /* Encode previous request with new URL */
- if (( ber = re_encode_request( ld, origreq->lr_ber, ++ld->ld_msgid, ludp )) == NULL ) {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "Error while encoding request for referral\n"), 0, 0,0);
- ldap_free_urldesc(ludp);
- errCode = ld->ld_errno;
- addUnFollowedRef(ld, lr, refs[i]);
- /* try next URL */
- continue;
- }
-
- if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) == NULL ) {
- ldap_free_urldesc(ludp);
- ber_free( ber, 1 );
- rc = ld->ld_errno = LDAP_NO_MEMORY;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( rc );
- }
-
- if (( srv->lsrv_host = strdup( ludp->lud_host ? ludp->lud_host : ld->ld_defhost)) == NULL ) {
- ldap_free_urldesc(ludp);
- free( (char *)srv );
- ber_free( ber, 1 );
- rc = ld->ld_errno = LDAP_NO_MEMORY;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( rc );
- }
-
- srv->lsrv_port = ludp->lud_port ? ludp->lud_port : LDAP_PORT;
-
- if ( srv != NULL && send_server_request( ld, ber, ld->ld_msgid,
- lr, srv, NULL, 1 ) >= 0 ) {
- ++*count;
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "Request has been forwarded to %s\n"), refs[i], 0,0);
- addFollowedRef(lr, refs[i]);
- for (j = i+1; refs[j] != NULL; j++){
- addToFollowRef(lr, refs[j]);
- }
- ldap_free_urldesc(ludp);
- break;
- } else {
- Debug( LDAP_DEBUG_ANY,
- catgets(slapdcat, 1, 220, "Unable to chase referral (%s)\n"),
- ldap_err2string( ld->ld_errno ), 0, 0 );
- addUnFollowedRef(ld, lr, refs[i]);
- errCode = ld->ld_errno;
- }
- ldap_free_urldesc(ludp); /* So far spawn all requests */
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- if (refs[i] != NULL) {
- rc = LDAP_SUCCESS;
- } else {
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "No referral was successfully chased (last error %d)\n"), errCode, 0, 0);
- rc = errCode;
- }
- Debug ( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1278, "<= chase_referrals --- \n"), 0,0,0);
-
- return( rc );
-}
-
-static void addFollowedRef(LDAPRequest *lr, char *ref)
-{
- int i;
-
- if (lr->lr_ref_followed == NULL){
- if ((lr->lr_ref_followed = (char **)calloc(2, sizeof(char*))) == NULL)
- return;
- i = 0;
- } else {
- for (i = 0; lr->lr_ref_followed[i] != NULL; i++);
- if ((lr->lr_ref_followed = (char **)realloc((char *)lr->lr_ref_followed, (i+2) * sizeof(char *))) == NULL){
- return;
- }
- }
- lr->lr_ref_followed[i++] = strdup(ref);
- lr->lr_ref_followed[i] = NULL;
- return;
-}
-
-static void addToFollowRef(LDAPRequest *lr, char *ref)
-{
- int i;
-
- if (lr->lr_ref_tofollow == NULL){
- if ((lr->lr_ref_tofollow = (char **)calloc(2, sizeof(char*))) == NULL)
- return;
- i = 0;
- } else {
- for (i = 0; lr->lr_ref_tofollow[i] != NULL; i++);
- if ((lr->lr_ref_tofollow = (char **)realloc((char *)lr->lr_ref_tofollow, (i+2) * sizeof(char *))) == NULL){
- return;
- }
- }
- lr->lr_ref_tofollow[i++] = strdup(ref);
- lr->lr_ref_tofollow[i] = NULL;
- return;
-}
-
-static int addUnFollowedRef(LDAP *ld, LDAPRequest *lr, char *ref)
-{
- int i;
-
- if (lr->lr_ref_unfollowed == NULL){
- if ((lr->lr_ref_unfollowed = (char **)calloc(2, sizeof(char*))) == NULL){
- ld->ld_errno = LDAP_NO_MEMORY;
- return (-1);
- }
- i = 0;
- } else {
- for (i = 0; lr->lr_ref_unfollowed[i] != NULL; i++);
- if ((lr->lr_ref_unfollowed = (char **)realloc((char *)lr->lr_ref_unfollowed, (i+2) * sizeof(char *))) == NULL){
- ld->ld_errno = LDAP_NO_MEMORY;
- return (-1);
- }
- }
- lr->lr_ref_unfollowed[i++] = strdup(ref);
- lr->lr_ref_unfollowed[i] = NULL;
- return (0);
-}
-
-
-int
-append_referral( LDAP *ld, char **referralsp, char *s )
-{
- int first;
-
- if ( *referralsp == NULL ) {
- first = 1;
- *referralsp = (char *)malloc( strlen( s ) + LDAP_REF_STR_LEN
- + 1 );
- } else {
- first = 0;
- *referralsp = (char *)realloc( *referralsp,
- strlen( *referralsp ) + strlen( s ) + 2 );
- }
-
- if ( *referralsp == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
-
- if ( first ) {
- strcpy( *referralsp, LDAP_REF_STR );
- } else {
- strcat( *referralsp, "\n" );
- }
- strcat( *referralsp, s );
-
- return( 0 );
-}
-
-
-
-static BerElement *
-re_encode_request( LDAP *ld, BerElement *origber, int msgid, LDAPURLDesc *urldesc )
-{
-/*
- * XXX this routine knows way too much about how the lber library works!
- */
- unsigned int along, tag, len;
- int ver, scope, deref, sizelimit, timelimit, attrsonly;
- int rc, hasCtrls;
- BerElement tmpber, *ber;
- char *dn, *seqstart;
-
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 221, "re_encode_request: new msgid %1$d, new dn <%2$s>\n"),
- msgid, ( urldesc->lud_dn == NULL ) ? "NONE" : urldesc->lud_dn, 0 );
-
- tmpber = *origber;
-
- /*
- * all LDAP requests are sequences that start with a message id,
- * followed by a sequence that is tagged with the operation code
- */
- /* Bad assumption : delete op is not a sequence.
- * So we have a special processing for it : it's much simpler
- */
- if ( ber_scanf( &tmpber, "{i", &along ) != LDAP_TAG_MSGID ||
- ( tag = ber_peek_tag( &tmpber, &along )) == LBER_DEFAULT ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return( NULL );
- }
-
- /* Special case : delete request is not a sequence of... */
- if (tag == LDAP_REQ_EXTENDED){
- /* return error, I don't know how to do it automatically */
- ld->ld_errno = LDAP_NOT_SUPPORTED;
- return (NULL);
- }
-
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
- return (NULL);
- }
-
- if (tag == LDAP_REQ_DELETE) {
- if ( ber_get_stringa( &tmpber, &dn ) == LBER_DEFAULT ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- Debug(LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 1279,"Error in decoding delete DN"),0,0,0);
- ber_free( ber, 1);
- return( NULL );
- }
- /* Check if controls */
- hasCtrls = 0;
- if (ber_peek_tag(&tmpber, &len) == LDAP_TAG_CONTROL_LIST){
- hasCtrls = 1;
- }
-
- if ( urldesc->lud_dn && *urldesc->lud_dn ) {
- free( dn );
- dn = urldesc->lud_dn;
- }
- if ( ber_printf( ber, "{its", msgid, tag, dn ) == -1 ) {
- Debug(LDAP_DEBUG_TRACE, "Error in re_encoding delete request",0,0,0);
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return (NULL);
- }
- /* Now add controls if any */
- if (hasCtrls && ber_write( ber, tmpber.ber_ptr, len, 0 ) != len ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
- if (ber_printf( ber, "}" ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
-
-#ifdef LDAP_DEBUG
- if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 222, "re_encode_request new request is:\n"),
- 0, 0, 0 );
- ber_dump( ber, 0 );
- }
-#endif /* LDAP_DEBUG */
- return (ber);
- }
-
- if (( tag = ber_skip_tag( &tmpber, &along )) == LBER_DEFAULT ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return( NULL );
- }
- /* Keep length and pointer */
- seqstart = tmpber.ber_ptr;
-
- /* bind requests have a version number before the DN & other stuff */
- if ( tag == LDAP_REQ_BIND && ber_get_int( &tmpber, &ver ) ==
- LBER_DEFAULT ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
-
- /* the rest of the request is the DN followed by other stuff */
- if ( ber_get_stringa( &tmpber, &dn ) == LBER_DEFAULT ) {
- ber_free( ber, 1 );
- return( NULL );
- }
- if ( urldesc->lud_dn != NULL ) {
- free( dn );
- dn = urldesc->lud_dn;
- }
-
- /* see what to do with CONTROLS */
-
- if ( tag == LDAP_REQ_BIND ) {
- rc = ber_printf( ber, "{it{is", msgid, tag, ver, dn );
- } else {
- rc = ber_printf( ber, "{it{s", msgid, tag, dn );
- }
-
- if ( rc == -1 ) {
- ber_free( ber, 1 );
- return( NULL );
- }
-
- if (tag == LDAP_REQ_SEARCH) {
- /* Now for SEARCH, decode more of the request */
- if (ber_scanf(&tmpber, "iiiib", &scope, &deref, &sizelimit, &timelimit, &attrsonly) == LBER_DEFAULT){
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
- if (ber_printf(ber, "iiiib", urldesc->lud_scope == LDAP_SCOPE_UNKNOWN ? scope : urldesc->lud_scope,
- deref, sizelimit, timelimit, attrsonly) == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
- /* We should then decode and check the filter as opposed to ludp->lud_filter */
- /* Same for attributes */
- /* Later */
- }
- /* The rest is the same for all requests */
-
- /* Copy Buffer from tmpber.ber_ptr for along - (tmpber.ber_ptr - seqstart) */
- /* It's the rest of the request */
- len = along - ( tmpber.ber_ptr - seqstart);
- if ( ber_write( ber, tmpber.ber_ptr, len, 0) != len ||
- ber_printf( ber, "}" ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
-
- if (seqstart + along < tmpber.ber_end){ /* there's probably some controls, copy them also */
- len = tmpber.ber_end - seqstart - along;
- if ( ber_write( ber, seqstart + along, len, 0) != len ){
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
- }
-
- if ( ber_printf(ber, "}") == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULL );
- }
-
-#ifdef LDAP_DEBUG
- if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 222, "re_encode_request new request is:\n"),
- 0, 0, 0 );
- ber_dump( ber, 0 );
- }
-#endif /* LDAP_DEBUG */
-
- return( ber );
-}
-
-
-LDAPRequest *
-find_request_by_msgid( LDAP *ld, int msgid )
-{
- LDAPRequest *lr;
-
- for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
- if ( msgid == lr->lr_msgid ) {
- break;
- }
- }
-
- return( lr );
-}
diff --git a/usr/src/lib/libldap4/common/regex.c b/usr/src/lib/libldap4/common/regex.c
deleted file mode 100644
index 1e2a00bbb9..0000000000
--- a/usr/src/lib/libldap4/common/regex.c
+++ /dev/null
@@ -1,923 +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 "portable.h"
-#include "stdio.h"
-#include "stdlib.h"
-
-#if defined( MACOS ) || defined( DOS ) || defined( _WIN32 ) || defined( NEED_BSDREGEX )
-#include "regex.h"
-
-/*
- * regex - Regular expression pattern matching and replacement
- *
- * By: Ozan S. Yigit (oz)
- * Dept. of Computer Science
- * York University
- *
- * These routines are the PUBLIC DOMAIN equivalents of regex
- * routines as found in 4.nBSD UN*X, with minor extensions.
- *
- * These routines are derived from various implementations found
- * in software tools books, and Conroy's grep. They are NOT derived
- * from licensed/restricted software.
- * For more interesting/academic/complicated implementations,
- * see Henry Spencer's regexp routines, or GNU Emacs pattern
- * matching module.
- *
- * Modification history:
- *
- * $Log: regex.c,v $
- * Revision 1.12 1996/04/25 16:20:59 mcs
- * make re_exec() match "" with ".*" and similar patterns
- * hopefully this change doesn't break anything else!
- *
- * Revision 1.11 1994/12/14 21:33:45 mcs
- * use new NEED_BSDREGEX
- * fix pmatch() prototype
- *
- * Revision 1.10 1994/12/12 18:16:39 mcs
- * use on NetBSD
- *
- * Revision 1.9 1994/11/15 19:16:35 mcs
- * add (CHAR) cast to make VisualC++ happy
- *
- * Revision 1.8 1994/11/08 21:14:32 mcs
- * WIN32 changes
- *
- * Revision 1.7 1994/07/23 19:51:24 mcs
- * use ANSI-style inline function parameters
- *
- * Revision 1.6 1993/10/18 01:52:32 tim
- * include for VMS
- *
- * Revision 1.5 1993/09/28 21:37:54 mcs
- * HP/UX needs the regex we include (not in its libc)
- *
- * Revision 1.4 1993/08/27 15:59:52 mcs
- * use CHAR for deftab
- *
- * Revision 1.3 1993/08/27 15:49:47 mcs
- * added missing 0 to octal constants
- * use unsigned char for CHAR under DOS
- *
- * Revision 1.2 1993/08/27 14:57:48 mcs
- * add proto. for pmatch
- *
- * Revision 1.1 1993/08/18 21:20:02 mcs
- * Initial revision
- *
- * Revision 1.4 1991/10/17 03:56:42 oz
- * miscellaneous changes, small cleanups etc.
- *
- * Revision 1.3 1989/04/01 14:18:09 oz
- * Change all references to a dfa: this is actually an nfa.
- *
- * Revision 1.2 88/08/28 15:36:04 oz
- * Use a complement bitmap to represent NCL.
- * This removes the need to have seperate
- * code in the pmatch case block - it is
- * just CCL code now.
- *
- * Use the actual CCL code in the CLO
- * section of pmatch. No need for a recursive
- * pmatch call.
- *
- * Use a bitmap table to set char bits in an
- * 8-bit chunk.
- *
- * Interfaces:
- * re_comp: compile a regular expression into a NFA.
- *
- * char *re_comp(s)
- * char *s;
- *
- * re_exec: execute the NFA to match a pattern.
- *
- * int re_exec(s)
- * char *s;
- *
- * re_modw change re_exec's understanding of what a "word"
- * looks like (for \< and \>) by adding into the
- * hidden word-syntax table.
- *
- * void re_modw(s)
- * char *s;
- *
- * re_subs: substitute the matched portions in a new string.
- *
- * int re_subs(src, dst)
- * char *src;
- * char *dst;
- *
- * re_fail: failure routine for re_exec.
- *
- * void re_fail(msg, op)
- * char *msg;
- * char op;
- *
- * Regular Expressions:
- *
- * [1] char matches itself, unless it is a special
- * character (metachar): . \ [ ] * + ^ $
- *
- * [2] . matches any character.
- *
- * [3] \ matches the character following it, except
- * when followed by a left or right round bracket,
- * a digit 1 to 9 or a left or right angle bracket.
- * (see [7], [8] and [9])
- * It is used as an escape character for all
- * other meta-characters, and itself. When used
- * in a set ([4]), it is treated as an ordinary
- * character.
- *
- * [4] [set] matches one of the characters in the set.
- * If the first character in the set is "^",
- * it matches a character NOT in the set, i.e.
- * complements the set. A shorthand S-E is
- * used to specify a set of characters S upto
- * E, inclusive. The special characters "]" and
- * "-" have no special meaning if they appear
- * as the first chars in the set.
- * examples: match:
- *
- * [a-z] any lowercase alpha
- *
- * [^]-] any char except ] and -
- *
- * [^A-Z] any char except uppercase
- * alpha
- *
- * [a-zA-Z] any alpha
- *
- * [5] * any regular expression form [1] to [4], followed by
- * closure char (*) matches zero or more matches of
- * that form.
- *
- * [6] + same as [5], except it matches one or more.
- *
- * [7] a regular expression in the form [1] to [10], enclosed
- * as \(form\) matches what form matches. The enclosure
- * creates a set of tags, used for [8] and for
- * pattern substution. The tagged forms are numbered
- * starting from 1.
- *
- * [8] a \ followed by a digit 1 to 9 matches whatever a
- * previously tagged regular expression ([7]) matched.
- *
- * [9] \< a regular expression starting with a \< construct
- * \> and/or ending with a \> construct, restricts the
- * pattern matching to the beginning of a word, and/or
- * the end of a word. A word is defined to be a character
- * string beginning and/or ending with the characters
- * A-Z a-z 0-9 and _. It must also be preceded and/or
- * followed by any character outside those mentioned.
- *
- * [10] a composite regular expression xy where x and y
- * are in the form [1] to [10] matches the longest
- * match of x followed by a match for y.
- *
- * [11] ^ a regular expression starting with a ^ character
- * $ and/or ending with a $ character, restricts the
- * pattern matching to the beginning of the line,
- * or the end of line. [anchors] Elsewhere in the
- * pattern, ^ and $ are treated as ordinary characters.
- *
- *
- * Acknowledgements:
- *
- * HCR's Hugh Redelmeier has been most helpful in various
- * stages of development. He convinced me to include BOW
- * and EOW constructs, originally invented by Rob Pike at
- * the University of Toronto.
- *
- * References:
- * Software tools Kernighan & Plauger
- * Software tools in Pascal Kernighan & Plauger
- * Grep [rsx-11 C dist] David Conroy
- * ed - text editor Un*x Programmer's Manual
- * Advanced editing on Un*x B. W. Kernighan
- * RegExp routines Henry Spencer
- *
- * Notes:
- *
- * This implementation uses a bit-set representation for character
- * classes for speed and compactness. Each character is represented
- * by one bit in a 128-bit block. Thus, CCL always takes a
- * constant 16 bytes in the internal nfa, and re_exec does a single
- * bit comparison to locate the character in the set.
- *
- * Examples:
- *
- * pattern: foo*.*
- * compile: CHR f CHR o CLO CHR o END CLO ANY END END
- * matches: fo foo fooo foobar fobar foxx ...
- *
- * pattern: fo[ob]a[rz]
- * compile: CHR f CHR o CCL bitset CHR a CCL bitset END
- * matches: fobar fooar fobaz fooaz
- *
- * pattern: foo\\+
- * compile: CHR f CHR o CHR o CHR \ CLO CHR \ END END
- * matches: foo\ foo\\ foo\\\ ...
- *
- * pattern: \(foo\)[1-3]\1 (same as foo[1-3]foo)
- * compile: BOT 1 CHR f CHR o CHR o EOT 1 CCL bitset REF 1 END
- * matches: foo1foo foo2foo foo3foo
- *
- * pattern: \(fo.*\)-\1
- * compile: BOT 1 CHR f CHR o CLO ANY END EOT 1 CHR - REF 1 END
- * matches: foo-foo fo-fo fob-fob foobar-foobar ...
- */
-
-#define MAXNFA 1024
-#define MAXTAG 10
-
-#define OKP 1
-#define NOP 0
-
-#define CHR 1
-#define ANY 2
-#define CCL 3
-#define BOL 4
-#define EOL 5
-#define BOT 6
-#define EOT 7
-#define BOW 8
-#define EOW 9
-#define REF 10
-#define CLO 11
-
-#define END 0
-
-/*
- * The following defines are not meant to be changeable.
- * They are for readability only.
- */
-#define MAXCHR 128
-#define CHRBIT 8
-#define BITBLK MAXCHR/CHRBIT
-#define BLKIND 0170
-#define BITIND 07
-
-#define ASCIIB 0177
-
-#if defined( DOS ) || defined( _WIN32 ) || defined(SUN)
-typedef unsigned char CHAR;
-#else /* DOS */
-typedef /*unsigned*/ char CHAR;
-#endif /* DOS */
-
-static int tagstk[MAXTAG]; /* subpat tag stack..*/
-static CHAR nfa[MAXNFA]; /* automaton.. */
-static int sta = NOP; /* status of lastpat */
-
-static CHAR bittab[BITBLK]; /* bit table for CCL */
- /* pre-set bits... */
-static CHAR bitarr[] = {1,2,4,8,16,32,64,128};
-
-#ifdef DEBUG
-static void nfadump(CHAR *);
-void symbolic(char *);
-#endif
-
-static void
-chset(CHAR c)
-{
- bittab[((c) & BLKIND) >> 3] |= bitarr[(c) & BITIND];
-}
-
-#define badpat(x) (*nfa = END, x)
-#define store(x) *mp++ = x
-
-char *
-re_comp( char *pat )
-{
- register char *p; /* pattern pointer */
- register CHAR *mp=nfa; /* nfa pointer */
- register CHAR *lp; /* saved pointer.. */
- register CHAR *sp=nfa; /* another one.. */
-
- register int tagi = 0; /* tag stack index */
- register int tagc = 1; /* actual tag count */
-
- register int n;
- register CHAR mask; /* xor mask -CCL/NCL */
- int c1, c2;
-
- if (!pat || !*pat)
- if (sta)
- return 0;
- else
- return badpat("No previous regular expression");
- sta = NOP;
-
- for (p = pat; *p; p++) {
- lp = mp;
- switch(*p) {
-
- case '.': /* match any char.. */
- store(ANY);
- break;
-
- case '^': /* match beginning.. */
- if (p == pat)
- store(BOL);
- else {
- store(CHR);
- store(*p);
- }
- break;
-
- case '$': /* match endofline.. */
- if (!*(p+1))
- store(EOL);
- else {
- store(CHR);
- store(*p);
- }
- break;
-
- case '[': /* match char class..*/
- store(CCL);
-
- if (*++p == '^') {
- mask = 0377;
- p++;
- }
- else
- mask = 0;
-
- if (*p == '-') /* real dash */
- chset(*p++);
- if (*p == ']') /* real brac */
- chset(*p++);
- while (*p && *p != ']') {
- if (*p == '-' && *(p+1) && *(p+1) != ']') {
- p++;
- c1 = *(p-2) + 1;
- c2 = *p++;
- while (c1 <= c2)
- chset((CHAR)c1++);
- }
-#ifdef EXTEND
- else if (*p == '\\' && *(p+1)) {
- p++;
- chset(*p++);
- }
-#endif
- else
- chset(*p++);
- }
- if (!*p)
- return badpat("Missing ]");
-
- for (n = 0; n < BITBLK; bittab[n++] = (char) 0)
- store(mask ^ bittab[n]);
-
- break;
-
- case '*': /* match 0 or more.. */
- case '+': /* match 1 or more.. */
- if (p == pat)
- return badpat("Empty closure");
- lp = sp; /* previous opcode */
- if (*lp == CLO) /* equivalence.. */
- break;
- switch(*lp) {
-
- case BOL:
- case BOT:
- case EOT:
- case BOW:
- case EOW:
- case REF:
- return badpat("Illegal closure");
- default:
- break;
- }
-
- if (*p == '+')
- for (sp = mp; lp < sp; lp++)
- store(*lp);
-
- store(END);
- store(END);
- sp = mp;
- while (--mp > lp)
- *mp = mp[-1];
- store(CLO);
- mp = sp;
- break;
-
- case '\\': /* tags, backrefs .. */
- switch(*++p) {
-
- case '(':
- if (tagc < MAXTAG) {
- tagstk[++tagi] = tagc;
- store(BOT);
- store(tagc++);
- }
- else
- return badpat("Too many \\(\\) pairs");
- break;
- case ')':
- if (*sp == BOT)
- return badpat("Null pattern inside \\(\\)");
- if (tagi > 0) {
- store(EOT);
- store(tagstk[tagi--]);
- }
- else
- return badpat("Unmatched \\)");
- break;
- case '<':
- store(BOW);
- break;
- case '>':
- if (*sp == BOW)
- return badpat("Null pattern inside \\<\\>");
- store(EOW);
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- n = *p-'0';
- if (tagi > 0 && tagstk[tagi] == n)
- return badpat("Cyclical reference");
- if (tagc > n) {
- store(REF);
- store(n);
- }
- else
- return badpat("Undetermined reference");
- break;
-#ifdef EXTEND
- case 'b':
- store(CHR);
- store('\b');
- break;
- case 'n':
- store(CHR);
- store('\n');
- break;
- case 'f':
- store(CHR);
- store('\f');
- break;
- case 'r':
- store(CHR);
- store('\r');
- break;
- case 't':
- store(CHR);
- store('\t');
- break;
-#endif
- default:
- store(CHR);
- store(*p);
- }
- break;
-
- default : /* an ordinary char */
- store(CHR);
- store(*p);
- break;
- }
- sp = lp;
- }
- if (tagi > 0)
- return badpat("Unmatched \\(");
- store(END);
- sta = OKP;
- return 0;
-}
-
-
-static char *bol;
-char *bopat[MAXTAG];
-char *eopat[MAXTAG];
-#ifdef NEEDPROTOS
-static char *pmatch( char *lp, CHAR *ap );
-#else /* NEEDPROTOS */
-static char *pmatch();
-#endif /* NEEDPROTOS */
-
-/*
- * re_exec:
- * execute nfa to find a match.
- *
- * special cases: (nfa[0])
- * BOL
- * Match only once, starting from the
- * beginning.
- * CHR
- * First locate the character without
- * calling pmatch, and if found, call
- * pmatch for the remaining string.
- * END
- * re_comp failed, poor luser did not
- * check for it. Fail fast.
- *
- * If a match is found, bopat[0] and eopat[0] are set
- * to the beginning and the end of the matched fragment,
- * respectively.
- *
- */
-
-int
-re_exec( char *lp )
-{
- register char c;
- register char *ep = 0;
- register CHAR *ap = nfa;
-
- bol = lp;
-
- bopat[0] = 0;
- bopat[1] = 0;
- bopat[2] = 0;
- bopat[3] = 0;
- bopat[4] = 0;
- bopat[5] = 0;
- bopat[6] = 0;
- bopat[7] = 0;
- bopat[8] = 0;
- bopat[9] = 0;
-
- switch(*ap) {
-
- case BOL: /* anchored: match from BOL only */
- ep = pmatch(lp,ap);
- break;
- case CHR: /* ordinary char: locate it fast */
- c = *(ap+1);
- while (*lp && *lp != c)
- lp++;
- if (!*lp) /* if EOS, fail, else fall thru. */
- return 0;
- default: /* regular matching all the way. */
- do {
- if ((ep = pmatch(lp,ap)))
- break;
- lp++;
- } while (*lp);
-
- break;
- case END: /* munged automaton. fail always */
- return 0;
- }
- if (!ep)
- return 0;
-
- bopat[0] = lp;
- eopat[0] = ep;
- return 1;
-}
-
-/*
- * pmatch: internal routine for the hard part
- *
- * This code is partly snarfed from an early grep written by
- * David Conroy. The backref and tag stuff, and various other
- * innovations are by oz.
- *
- * special case optimizations: (nfa[n], nfa[n+1])
- * CLO ANY
- * We KNOW .* will match everything upto the
- * end of line. Thus, directly go to the end of
- * line, without recursive pmatch calls. As in
- * the other closure cases, the remaining pattern
- * must be matched by moving backwards on the
- * string recursively, to find a match for xy
- * (x is ".*" and y is the remaining pattern)
- * where the match satisfies the LONGEST match for
- * x followed by a match for y.
- * CLO CHR
- * We can again scan the string forward for the
- * single char and at the point of failure, we
- * execute the remaining nfa recursively, same as
- * above.
- *
- * At the end of a successful match, bopat[n] and eopat[n]
- * are set to the beginning and end of subpatterns matched
- * by tagged expressions (n = 1 to 9).
- *
- */
-
-#ifndef re_fail
-extern void re_fail();
-#endif /* re_fail */
-
-/*
- * character classification table for word boundary operators BOW
- * and EOW. the reason for not using ctype macros is that we can
- * let the user add into our own table. see re_modw. This table
- * is not in the bitset form, since we may wish to extend it in the
- * future for other character classifications.
- *
- * TRUE for 0-9 A-Z a-z _
- */
-static char chrtyp[MAXCHR] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 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, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
- 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 0, 0, 0, 0, 1, 0, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 0, 0, 0, 0, 0
- };
-
-#define inascii(x) (0177&(x))
-#define iswordc(x) chrtyp[inascii(x)]
-#define isinset(x,y) ((x)[((y)&BLKIND)>>3] & bitarr[(y)&BITIND])
-
-/*
- * skip values for CLO XXX to skip past the closure
- */
-
-#define ANYSKIP 2 /* [CLO] ANY END ... */
-#define CHRSKIP 3 /* [CLO] CHR chr END ... */
-#define CCLSKIP 18 /* [CLO] CCL 16bytes END ... */
-
-static char *
-pmatch( char *lp, CHAR *ap)
-{
- register int op, c, n;
- register char *e; /* extra pointer for CLO */
- register char *bp; /* beginning of subpat.. */
- register char *ep; /* ending of subpat.. */
- char *are; /* to save the line ptr. */
-
- while ((op = *ap++) != END)
- switch(op) {
-
- case CHR:
- if (*lp++ != *ap++)
- return 0;
- break;
- case ANY:
- if (!*lp++)
- return 0;
- break;
- case CCL:
- c = *lp++;
- if (!isinset(ap,c))
- return 0;
- ap += BITBLK;
- break;
- case BOL:
- if (lp != bol)
- return 0;
- break;
- case EOL:
- if (*lp)
- return 0;
- break;
- case BOT:
- bopat[*ap++] = lp;
- break;
- case EOT:
- eopat[*ap++] = lp;
- break;
- case BOW:
- if (lp!=bol && iswordc(lp[-1]) || !iswordc(*lp))
- return 0;
- break;
- case EOW:
- if (lp==bol || !iswordc(lp[-1]) || iswordc(*lp))
- return 0;
- break;
- case REF:
- n = *ap++;
- bp = bopat[n];
- ep = eopat[n];
- while (bp < ep)
- if (*bp++ != *lp++)
- return 0;
- break;
- case CLO:
- are = lp;
- switch(*ap) {
-
- case ANY:
- while (*lp)
- lp++;
- n = ANYSKIP;
- break;
- case CHR:
- c = *(ap+1);
- while (*lp && c == *lp)
- lp++;
- n = CHRSKIP;
- break;
- case CCL:
- while ((c = *lp) && isinset(ap+1,c))
- lp++;
- n = CCLSKIP;
- break;
- default:
- re_fail("closure: bad nfa.", *ap);
- return 0;
- }
-
- ap += n;
-
- while (lp >= are) {
- if (e = pmatch(lp, ap))
- return e;
- --lp;
- }
- return 0;
- default:
- re_fail("re_exec: bad nfa.", op);
- return 0;
- }
- return lp;
-}
-
-/*
- * re_modw:
- * add new characters into the word table to change re_exec's
- * understanding of what a word should look like. Note that we
- * only accept additions into the word definition.
- *
- * If the string parameter is 0 or null string, the table is
- * reset back to the default containing A-Z a-z 0-9 _. [We use
- * the compact bitset representation for the default table]
- */
-
-static CHAR deftab[16] = {
- 0, 0, 0, 0, 0, 0, 0377, 003, 0376, 0377, 0377, 0207,
- 0376, 0377, 0377, 007
-};
-
-void
-re_modw( char *s )
-{
- register int i;
-
- if (!s || !*s) {
- for (i = 0; i < MAXCHR; i++)
- if (!isinset(deftab,i))
- iswordc(i) = 0;
- }
- else
- while(*s)
- iswordc(*s++) = 1;
-}
-
-/*
- * re_subs:
- * substitute the matched portions of the src in dst.
- *
- * & substitute the entire matched pattern.
- *
- * \digit substitute a subpattern, with the given tag number.
- * Tags are numbered from 1 to 9. If the particular
- * tagged subpattern does not exist, null is substituted.
- */
-int
-re_subs( char *src, char *dst)
-{
- register char c;
- register int pin;
- register char *bp;
- register char *ep;
-
- if (!*src || !bopat[0])
- return 0;
-
- while (c = *src++) {
- switch(c) {
-
- case '&':
- pin = 0;
- break;
-
- case '\\':
- c = *src++;
- if (c >= '0' && c <= '9') {
- pin = c - '0';
- break;
- }
-
- default:
- *dst++ = c;
- continue;
- }
-
- if ((bp = bopat[pin]) && (ep = eopat[pin])) {
- while (*bp && bp < ep)
- *dst++ = *bp++;
- if (bp < ep)
- return 0;
- }
- }
- *dst = (char) 0;
- return 1;
-}
-
-#ifdef DEBUG
-/*
- * symbolic - produce a symbolic dump of the nfa
- */
-void
-symbolic( char *s )
-{
- (void) printf("pattern: %s\n", s);
- (void) printf("nfacode:\n");
- nfadump(nfa);
-}
-
-static void
-nfadump( CHAR *ap)
-{
- register int n;
-
- while (*ap != END)
- switch(*ap++) {
- case CLO:
- (void) printf("CLOSURE");
- nfadump(ap);
- switch(*ap) {
- case CHR:
- n = CHRSKIP;
- break;
- case ANY:
- n = ANYSKIP;
- break;
- case CCL:
- n = CCLSKIP;
- break;
- }
- ap += n;
- break;
- case CHR:
- (void) printf("\tCHR %c\n",*ap++);
- break;
- case ANY:
- (void) printf("\tANY .\n");
- break;
- case BOL:
- (void) printf("\tBOL -\n");
- break;
- case EOL:
- (void) printf("\tEOL -\n");
- break;
- case BOT:
- (void) printf("BOT: %d\n",*ap++);
- break;
- case EOT:
- (void) printf("EOT: %d\n",*ap++);
- break;
- case BOW:
- (void) printf("BOW\n");
- break;
- case EOW:
- (void) printf("EOW\n");
- break;
- case REF:
- (void) printf("REF: %d\n",*ap++);
- break;
- case CCL:
- (void) printf("\tCCL [");
- for (n = 0; n < MAXCHR; n++)
- if (isinset(ap,(CHAR)n)) {
- if (n < ' ')
- (void) printf("^%c", n ^ 0x040);
- else
- (void) printf("%c", n);
- }
- (void) printf("]\n");
- ap += BITBLK;
- break;
- default:
- (void) printf("bad nfa. opcode %o\n", ap[-1]);
- exit(1);
- break;
- }
-}
-#endif
-#endif /* MACOS or DOS or NEED_BSDREGEX */
diff --git a/usr/src/lib/libldap4/common/rename.c b/usr/src/lib/libldap4/common/rename.c
deleted file mode 100644
index 3a754df30d..0000000000
--- a/usr/src/lib/libldap4/common/rename.c
+++ /dev/null
@@ -1,176 +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 <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_rename_req ( LDAP *ld, char *dn, char *newrdn, char *newparent,
- int deleteoldrdn, LDAPControl **serverctrls)
-{
- BerElement *ber;
- int rc;
-
- /*
- * A modify rdn request looks like this:
- * ModifyRDNRequest ::= SEQUENCE {
- * entry LDAPDN,
- * newrdn RelativeLDAPDN,
- * deleteoldrdn BOOLEAN
- * newSuperior [0] LDAPDN OPTIONAL
- * }
- */
-
- /* create a message to send */
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
- return( NULLBER );
- }
-
- if ( ber_printf( ber, "{it{ssb", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
- newrdn, deleteoldrdn ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULLBER );
- }
-
- if (newparent) {
- if ( ber_printf( ber, "ts}", LDAP_TAG_NEWPARENT, newparent) == -1){
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
- return( NULLBER );
- }
-
- } else 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_rename - Modify the name of an entry.
- * Parameters :
- * ld : LDAP descriptor.
- * dn : DN of the object to rename.
- * newrdn : New RDN to give to the entry.
- * newparent : the parent or superior entry. If NULL only RDN is changed.
- * "" means the root DN.
- * deleteoldrdn : Boolean to indicate wether or not to remove the old RDN value.
- * serverctrls : List of Server controls.
- * clientctrls : List of client controls.
- * msgidp : the msg id return if renamed succeded.
- */
-
-int ldap_rename(LDAP *ld, char *dn, char *newrdn, char *newparent, int deleteoldrdn,
- LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp)
-{
- BerElement *ber;
- int rv;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 87, "ldap_rename\n"), 0, 0, 0 );
-
- if ((ber = ldap_build_rename_req(ld, dn, newrdn, newparent, deleteoldrdn, 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_MODRDN, 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_rename_s(LDAP *ld, char *dn, char *newrdn, char *newparent, int deleteoldrdn,
- LDAPControl ** serverctrls, LDAPControl **clientctrls)
-{
- int msgid;
- int retcode = LDAP_SUCCESS;
- LDAPMessage *res;
-
- if ((retcode = ldap_rename(ld, dn, newrdn, newparent, deleteoldrdn, 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);
-}
diff --git a/usr/src/lib/libldap4/common/request.c b/usr/src/lib/libldap4/common/request.c
deleted file mode 100644
index 7b0af4c0f7..0000000000
--- a/usr/src/lib/libldap4/common/request.c
+++ /dev/null
@@ -1,779 +0,0 @@
-/*
- * Copyright 1998-2002 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.
- *
- * request.c - sending of ldap requests; handling of referrals
- */
-
-#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 <time.h>
-#include "macos.h"
-#else /* MACOS */
-#if defined( DOS ) || defined( _WIN32 )
-#include "msdos.h"
-#include <time.h>
-#include <stdlib.h>
-#ifdef PCNFS
-#include <tklib.h>
-#include <tk_errno.h>
-#include <bios.h>
-#endif /* PCNFS */
-#ifdef NCSA
-#include "externs.h"
-#endif /* NCSA */
-#else /* DOS */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#ifdef _AIX
-#include <sys/select.h>
-#endif /* _AIX */
-#include "portable.h"
-#endif /* DOS */
-#endif /* MACOS */
-#ifdef VMS
-#include "ucx_select.h"
-#endif
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-#ifdef USE_SYSCONF
-#include <unistd.h>
-#endif /* USE_SYSCONF */
-
-#ifdef NEEDPROTOS
-static LDAPConn *find_connection( LDAP *ld, LDAPServer *srv, int any );
-static void use_connection( LDAP *ld, LDAPConn *lc );
-static void free_servers( LDAPServer *srvlist );
-#else /* NEEDPROTOS */
-static LDAPConn *find_connection();
-static void use_connection();
-static void free_servers();
-#endif /* NEEDPROTOS */
-
-
-#ifdef LDAP_DNS
-#ifdef NEEDPROTOS
-static LDAPServer *dn2servers( LDAP *ld, char *dn );
-#else /* NEEDPROTOS */
-static LDAPServer *dn2servers();
-#endif /* NEEDPROTOS */
-#endif /* LDAP_DNS */
-
-
-BerElement *
-alloc_ber_with_options( LDAP *ld )
-{
- BerElement *ber;
-
- if (( ber = ber_alloc_t( ld->ld_lberoptions )) == NULLBER ) {
- ld->ld_errno = LDAP_NO_MEMORY;
-#ifdef STR_TRANSLATION
- } else {
- set_ber_options( ld, ber );
-#endif /* STR_TRANSLATION */
- }
-
- return( ber );
-}
-
-
-void
-set_ber_options( LDAP *ld, BerElement *ber )
-{
- ber->ber_options = ld->ld_lberoptions;
-#ifdef STR_TRANSLATION
- if (( ld->ld_lberoptions & LBER_TRANSLATE_STRINGS ) != 0 ) {
- ber_set_string_translators( ber,
- ld->ld_lber_encode_translate_proc,
- ld->ld_lber_decode_translate_proc );
- }
-#endif /* STR_TRANSLATION */
-}
-
-
-int
-send_initial_request( LDAP *ld, unsigned int msgtype, char *dn,
- BerElement *ber )
-{
- LDAPServer *servers;
- int rv;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 209, "send_initial_request\n"), 0, 0, 0 );
-
-#ifdef LDAP_DNS
- if (( ld->ld_options & LDAP_OPT_DNS ) != 0 && ldap_is_dns_dn( dn )) {
- if (( servers = dn2servers( ld, dn )) == NULL ) {
- ber_free( ber, 1 );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
-#ifdef LDAP_DEBUG
- if ( ldap_debug & LDAP_DEBUG_TRACE ) {
- LDAPServer *srv;
-
- for ( srv = servers; srv != NULL;
- srv = srv->lsrv_next ) {
- fprintf( stderr,
- "LDAP server %s: dn %s, port %d\n",
- srv->lsrv_host, ( srv->lsrv_dn == NULL ) ?
- "(default)" : srv->lsrv_dn,
- srv->lsrv_port );
- }
- }
-#endif /* LDAP_DEBUG */
- } else {
-#endif /* LDAP_DNS */
- /*
- * use of DNS is turned off or this is an X.500 DN...
- * use our default connection
- */
- servers = NULL;
-#ifdef LDAP_DNS
- }
-#endif /* LDAP_DNS */
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- rv = send_server_request( ld, ber, ld->ld_msgid, NULL, servers,
- NULL, 0 );
- return ( rv );
-}
-
-int
-send_server_request( LDAP *ld, BerElement *ber, int msgid, LDAPRequest
- *parentreq, LDAPServer *srvlist, LDAPConn *lc, int bind )
-{
- LDAPRequest *lr;
- int err;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 210, "send_server_request\n"), 0, 0, 0 );
-
- ld->ld_errno = LDAP_SUCCESS; /* optimistic */
- /* Be optimistic : increment parentreq initially.
- If it fails we must decrement it */
- if (parentreq != NULL){
- parentreq->lr_outrefcnt++;
- }
-
- if ( lc == NULL ) {
- if ( srvlist == NULL ) {
- if (ld->ld_defconn == NULL){ /* Not connected yet on the default connection, ie init was called not open */
- if ((err = open_default_ldap_connection(ld)) != LDAP_SUCCESS){
- ld->ld_errno = err;
- ber_free(ber, 1);
- if (parentreq != NULL){
- parentreq->lr_outrefcnt--;
- }
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
- }
-
- lc = ld->ld_defconn;
- } else {
- if (( lc = find_connection( ld, srvlist, 1 )) ==
- NULL ) {
- lc = new_connection( ld, &srvlist, 0, 1, bind );
- }
- free_servers( srvlist );
- }
- }
-
- if ( lc == NULL || lc->lconn_status != LDAP_CONNST_CONNECTED ) {
- ber_free( ber, 1 );
- if ( ld->ld_errno == LDAP_SUCCESS ) {
- ld->ld_errno = LDAP_SERVER_DOWN;
- }
- if (parentreq != NULL){
- parentreq->lr_outrefcnt--;
- }
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- use_connection( ld, lc );
- if (( lr = (LDAPRequest *)calloc( 1, sizeof( LDAPRequest ))) ==
- NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- free_connection( ld, lc, 0, 0 );
- ber_free( ber, 1 );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
- lr->lr_msgid = msgid;
- lr->lr_status = LDAP_REQST_INPROGRESS;
- lr->lr_res_errno = LDAP_SUCCESS; /* optimistic */
- lr->lr_ber = ber;
- lr->lr_conn = lc;
- if ( parentreq != NULL ) { /* sub-request */
-/* ++parentreq->lr_outrefcnt; */
- lr->lr_origid = parentreq->lr_origid;
- lr->lr_parentcnt = parentreq->lr_parentcnt + 1;
- lr->lr_parent = parentreq;
- lr->lr_refnext = parentreq->lr_refnext;
- parentreq->lr_refnext = lr;
- } else { /* original request */
- lr->lr_origid = lr->lr_msgid;
- }
-
- if (( lr->lr_next = ld->ld_requests ) != NULL ) {
- lr->lr_next->lr_prev = lr;
- }
- ld->ld_requests = lr;
- lr->lr_prev = NULL;
-
- if ( ber_flush( lc->lconn_sb, ber, 0 ) != 0 ) {
-#ifdef notyet
- extern int errno;
-
- if ( errno == EWOULDBLOCK ) {
- /* need to continue write later */
- lr->lr_status = LDAP_REQST_WRITING;
- mark_select_write( ld, lc->lconn_sb );
- } else {
-#else /* notyet */
- ld->ld_errno = LDAP_SERVER_DOWN;
- free_request( ld, lr );
- free_connection( ld, lc, 0, 0 );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
-#endif /* notyet */
-#ifdef notyet
- }
-#endif /* notyet */
- } else {
- if ( parentreq == NULL ) {
- ber->ber_end = ber->ber_ptr;
- ber->ber_ptr = ber->ber_buf;
- }
-
- /* sent -- waiting for a response */
- mark_select_read( ld, lc->lconn_sb );
- }
-
- ld->ld_errno = LDAP_SUCCESS;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( msgid );
-}
-
-
-LDAPConn *
-new_connection( LDAP *ld, LDAPServer **srvlistp, int use_ldsb,
- int connect, int bind )
-{
- LDAPConn *lc;
- LDAPServer *prevsrv, *srv;
- Sockbuf *sb;
-
- /*
- * make a new LDAP server connection
- * XXX open connection synchronously for now
- */
- if (( lc = (LDAPConn *)calloc( 1, sizeof( LDAPConn ))) == NULL ||
- ( !use_ldsb && ( sb = (Sockbuf *)calloc( 1, sizeof( Sockbuf )))
- == NULL )) {
- if ( lc != NULL ) {
- free( (char *)lc );
- }
- ld->ld_errno = LDAP_NO_MEMORY;
- return( NULL );
- }
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- lc->lconn_sb = ( use_ldsb ) ? &ld->ld_sb : sb;
-
- if ( connect ) {
- prevsrv = NULL;
-
- for ( srv = *srvlistp; srv != NULL; srv = srv->lsrv_next ) {
- if ( open_ldap_connection( ld, lc->lconn_sb,
- srv->lsrv_host, srv->lsrv_port,
- &lc->lconn_krbinstance, 0 ) != -1 ) {
- break;
- }
- prevsrv = srv;
- }
-
- if ( srv == NULL ) {
- if ( !use_ldsb ) {
- free( (char *)lc->lconn_sb );
- }
- free( (char *)lc );
- ld->ld_errno = LDAP_SERVER_DOWN;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( NULL );
- }
-
- if ( prevsrv == NULL ) {
- *srvlistp = srv->lsrv_next;
- } else {
- prevsrv->lsrv_next = srv->lsrv_next;
- }
- lc->lconn_server = srv;
- }
-
- lc->lconn_status = LDAP_CONNST_CONNECTED;
- lc->lconn_next = ld->ld_conns;
- ld->ld_conns = lc;
-
- /*
- * XXX for now, we always do a synchronous bind. This will have
- * to change in the long run...
- */
- if ( bind ) {
- int err, freepasswd, authmethod;
- char *binddn, *passwd;
- LDAPConn *savedefconn;
-
- freepasswd = err = 0;
-
- if ( ld->ld_version == LDAP_VERSION3 && ld->ld_rebindproc == NULL){
- /* Nothing to do */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1280, "new_connection: bind no needed with ldapv3\n"), 0,0,0);
- } else {
- if ( ld->ld_rebindproc == NULL ) {
- binddn = passwd = "";
- authmethod = LDAP_AUTH_SIMPLE;
- } else {
- if (( err = (*ld->ld_rebindproc)( ld, &binddn, &passwd,
- &authmethod, 0, ld->ld_rebind_extra_arg )) == LDAP_SUCCESS ) {
- freepasswd = 1;
- } else {
- ld->ld_errno = err;
- err = -1;
- }
- }
-
- if ( err == 0 ) {
- savedefconn = ld->ld_defconn;
- ld->ld_defconn = lc;
- ++lc->lconn_refcnt; /* avoid premature free */
-
- if ( ldap_bind_s( ld, binddn, passwd, authmethod ) !=
- LDAP_SUCCESS ) {
- err = -1;
- }
- --lc->lconn_refcnt;
- ld->ld_defconn = savedefconn;
- }
-
- if ( freepasswd ) {
- (*ld->ld_rebindproc)( ld, &binddn, &passwd,
- &authmethod, 1, ld->ld_rebind_extra_arg );
- }
-
- if ( err != 0 ) {
- free_connection( ld, lc, 1, 0 );
- lc = NULL;
- }
- }
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( lc );
-}
-
-
-static LDAPConn *
-find_connection( LDAP *ld, LDAPServer *srv, int any )
-/*
- * return an existing connection (if any) to the server srv
- * if "any" is non-zero, check for any server in the "srv" chain
- */
-{
- LDAPConn *lc;
- LDAPServer *ls;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
- for ( ls = srv; ls != NULL; ls = ls->lsrv_next ) {
- if ( lc->lconn_server->lsrv_host != NULL &&
- ls->lsrv_host != NULL && strcasecmp(
- ls->lsrv_host, lc->lconn_server->lsrv_host ) == 0
- && ls->lsrv_port == lc->lconn_server->lsrv_port ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( lc );
- }
- if ( !any ) {
- break;
- }
- }
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( NULL );
-}
-
-
-
-static void
-use_connection( LDAP *ld, LDAPConn *lc )
-{
- ++lc->lconn_refcnt;
- lc->lconn_lastused = time( 0 );
-}
-
-
-void
-free_connection( LDAP *ld, LDAPConn *lc, int force, int unbind )
-{
- LDAPConn *tmplc, *prevlc;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 211, "free_connection\n"), 0, 0, 0 );
-
- if ( force || --lc->lconn_refcnt <= 0 ) {
- if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) {
- mark_select_clear( ld, lc->lconn_sb );
- if ( unbind ) {
- send_unbind( ld, lc->lconn_sb );
- }
- close_ldap_connection( lc->lconn_sb );
- if ( lc->lconn_sb->sb_ber.ber_buf != NULL ) {
- free( lc->lconn_sb->sb_ber.ber_buf );
- lc->lconn_sb->sb_ber.ber_buf = NULL;
- }
- }
- prevlc = NULL;
- for ( tmplc = ld->ld_conns; tmplc != NULL;
- tmplc = tmplc->lconn_next ) {
- if ( tmplc == lc ) {
- if ( prevlc == NULL ) {
- ld->ld_conns = tmplc->lconn_next;
- } else {
- prevlc->lconn_next = tmplc->lconn_next;
- }
- break;
- }
- }
- free_servers( lc->lconn_server );
- if ( lc->lconn_krbinstance != NULL ) {
- free( lc->lconn_krbinstance );
- }
- if ( lc->lconn_sb != &ld->ld_sb ) {
- free( (char *)lc->lconn_sb );
- }
- free( lc );
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 212, "free_connection: actually freed\n"),
- 0, 0, 0 );
- } else {
- lc->lconn_lastused = time( 0 );
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 213, "free_connection: refcnt %d\n"),
- lc->lconn_refcnt, 0, 0 );
- }
-}
-
-
-#ifdef LDAP_DEBUG
-void
-dump_connection( LDAP *ld, LDAPConn *lconns, int all )
-{
- LDAPConn *lc;
-
- fprintf( stderr, "** Connection%s:\n", all ? "s" : "" );
- for ( lc = lconns; lc != NULL; lc = lc->lconn_next ) {
- if ( lc->lconn_server != NULL ) {
- fprintf( stderr, "* host: %s port: %d%s\n",
- ( lc->lconn_server->lsrv_host == NULL ) ? "(null)"
- : lc->lconn_server->lsrv_host,
- lc->lconn_server->lsrv_port, ( lc->lconn_sb ==
- &ld->ld_sb ) ? " (default)" : "" );
- }
- fprintf( stderr, " refcnt: %d status: %s\n", lc->lconn_refcnt,
- ( lc->lconn_status == LDAP_CONNST_NEEDSOCKET ) ?
- "NeedSocket" : ( lc->lconn_status ==
- LDAP_CONNST_CONNECTING ) ? "Connecting" : "Connected" );
- fprintf( stderr, " last used: %s\n",
- ctime( &lc->lconn_lastused ));
- if ( !all ) {
- break;
- }
- }
-}
-
-
-void
-dump_requests_and_responses( LDAP *ld )
-{
- LDAPRequest *lr;
- LDAPMessage *lm, *l;
-
- fprintf( stderr, "** Outstanding Requests:\n" );
- if (( lr = ld->ld_requests ) == NULL ) {
- fprintf( stderr, " Empty\n" );
- }
- for ( ; lr != NULL; lr = lr->lr_next ) {
- fprintf( stderr, " * msgid %d, origid %d, status %s\n",
- lr->lr_msgid, lr->lr_origid, ( lr->lr_status ==
- LDAP_REQST_INPROGRESS ) ? "InProgress" :
- ( lr->lr_status == LDAP_REQST_CHASINGREFS ) ? "ChasingRefs" :
- ( lr->lr_status == LDAP_REQST_NOTCONNECTED ) ? "NotConnected" :
- "Writing" );
- fprintf( stderr, " outstanding referrals %d, parent count %d\n",
- lr->lr_outrefcnt, lr->lr_parentcnt );
- }
-
- fprintf( stderr, "** Response Queue:\n" );
-#ifdef _REENTRANT
- LOCK_RESPONSE(ld);
-#endif
- if (( lm = ld->ld_responses ) == NULLMSG ) {
- fprintf( stderr, " Empty\n" );
- }
- for ( ; lm != NULLMSG; lm = lm->lm_next ) {
- fprintf( stderr, " * msgid %d, type %d\n",
- lm->lm_msgid, lm->lm_msgtype );
- if (( l = lm->lm_chain ) != NULL ) {
- fprintf( stderr, " chained responses:\n" );
- for ( ; l != NULLMSG; l = l->lm_chain ) {
- fprintf( stderr,
- " * msgid %d, type %d\n",
- l->lm_msgid, l->lm_msgtype );
- }
- }
- }
-#ifdef _REENTRANT
- UNLOCK_RESPONSE(ld);
-#endif
-}
-#endif /* LDAP_DEBUG */
-
-
-void
-free_request( LDAP *ld, LDAPRequest *lr )
-{
- LDAPRequest *tmplr, *nextlr;
- int i;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 214, "free_request (origid %1$d, msgid %2$d)\n"),
- lr->lr_origid, lr->lr_msgid, 0 );
-
- if ( lr->lr_parent != NULL ) {
- --lr->lr_parent->lr_outrefcnt;
- } else {
- /* free all referrals (child requests) */
- for ( tmplr = lr->lr_refnext; tmplr != NULL; tmplr = nextlr ) {
- nextlr = tmplr->lr_refnext;
- free_request( ld, tmplr );
- }
- }
-
- if ( lr->lr_prev == NULL ) {
- ld->ld_requests = lr->lr_next;
- } else {
- lr->lr_prev->lr_next = lr->lr_next;
- }
-
- if ( lr->lr_next != NULL ) {
- lr->lr_next->lr_prev = lr->lr_prev;
- }
-
- if ( lr->lr_ber != NULL ) {
- ber_free( lr->lr_ber, 1 );
- }
-
- if ( lr->lr_res_error != NULL ) {
- free( lr->lr_res_error );
- }
-
- if ( lr->lr_res_matched != NULL ) {
- free( lr->lr_res_matched );
- }
-
- if ( lr->lr_ref_tofollow != NULL ) {
- for (i= 0; lr->lr_ref_tofollow[i] != NULL; i++)
- free(lr->lr_ref_tofollow[i]);
- free(lr->lr_ref_tofollow);
- }
- if ( lr->lr_ref_unfollowed != NULL ) {
- for (i= 0; lr->lr_ref_unfollowed[i] != NULL; i++)
- free(lr->lr_ref_unfollowed[i]);
- free(lr->lr_ref_unfollowed);
- }
- if ( lr->lr_ref_followed != NULL ) {
- for (i= 0; lr->lr_ref_followed[i] != NULL; i++)
- free(lr->lr_ref_followed[i]);
- free(lr->lr_ref_followed);
- }
-
- free( lr );
-}
-
-
-static void
-free_servers( LDAPServer *srvlist )
-{
- LDAPServer *nextsrv;
-
- while ( srvlist != NULL ) {
- nextsrv = srvlist->lsrv_next;
- if ( srvlist->lsrv_dn != NULL ) {
- free( srvlist->lsrv_dn );
- }
- if ( srvlist->lsrv_host != NULL ) {
- free( srvlist->lsrv_host );
- }
- free( srvlist );
- srvlist = nextsrv;
- }
-}
-
-/*
- * nsldapi_connection_lost_nolock() resets "ld" to a non-connected, known
- * state. It should be called whenever a fatal error occurs on the
- * Sockbuf "sb." sb == NULL means we don't know specifically where
- * the problem was so we assume all connections are bad.
- */
-void
-nsldapi_connection_lost_nolock( LDAP *ld, Sockbuf *sb )
-{
- LDAPRequest *lr;
-
- /*
- * change status of all pending requests that are associated with "sb
- * to "connection dead."
- * also change the connection status to "dead" and remove it from
- * the list of sockets we are interested in.
- */
- for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
- if ( sb == NULL ||
- ( lr->lr_conn != NULL && lr->lr_conn->lconn_sb == sb )) {
- lr->lr_status = LDAP_REQST_CONNDEAD;
- if ( lr->lr_conn != NULL ) {
- lr->lr_conn->lconn_status = LDAP_CONNST_DEAD;
- }
- }
- }
-}
-
-#ifdef LDAP_DNS
-static LDAPServer *
-dn2servers( LDAP *ld, char *dn ) /* dn can also be a domain.... */
-{
- char *p, *domain, *host, *server_dn, **dxs;
- int i, port;
- LDAPServer *srvlist, *prevsrv, *srv;
-
- if (( domain = strrchr( dn, '@' )) != NULL ) {
- ++domain;
- } else {
- domain = dn;
- }
-
- if (( dxs = getdxbyname( domain )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( NULL );
- }
-
- srvlist = NULL;
-
- for ( i = 0; dxs[ i ] != NULL; ++i ) {
- port = LDAP_PORT;
- server_dn = NULL;
- if ( strchr( dxs[ i ], ':' ) == NULL ) {
- host = dxs[ i ];
- } else if ( strlen( dxs[ i ] ) >= 7 &&
- strncmp( dxs[ i ], "ldap://", 7 ) == 0 ) {
- host = dxs[ i ] + 7;
- if (( p = strchr( host, ':' )) == NULL ) {
- p = host;
- } else {
- *p++ = '\0';
- port = atoi( p );
- }
- if (( p = strchr( p, '/' )) != NULL ) {
- server_dn = ++p;
- if ( *server_dn == '\0' ) {
- server_dn = NULL;
- }
- }
- } else {
- host = NULL;
- }
-
- if ( host != NULL ) { /* found a server we can use */
- if (( srv = (LDAPServer *)calloc( 1,
- sizeof( LDAPServer ))) == NULL ) {
- free_servers( srvlist );
- srvlist = NULL;
- break; /* exit loop & return */
- }
-
- /* add to end of list of servers */
- if ( srvlist == NULL ) {
- srvlist = srv;
- } else {
- prevsrv->lsrv_next = srv;
- }
- prevsrv = srv;
-
- /* copy in info. */
- if (( srv->lsrv_host = strdup( host )) == NULL ||
- ( server_dn != NULL && ( srv->lsrv_dn =
- strdup( server_dn )) == NULL )) {
- free_servers( srvlist );
- srvlist = NULL;
- break; /* exit loop & return */
- }
- srv->lsrv_port = port;
- }
- }
-
- ldap_value_free( dxs );
-
- if ( srvlist == NULL ) {
- ld->ld_errno = LDAP_SERVER_DOWN;
- }
-
- return( srvlist );
-}
-#endif /* LDAP_DNS */
diff --git a/usr/src/lib/libldap4/common/result.c b/usr/src/lib/libldap4/common/result.c
deleted file mode 100644
index 07b21483c6..0000000000
--- a/usr/src/lib/libldap4/common/result.c
+++ /dev/null
@@ -1,1657 +0,0 @@
-/*
- * Copyright 1998-2003 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.
- *
- * result.c - wait for an ldap result
- */
-
-#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 <time.h>
-#include "macos.h"
-#else /* MACOS */
-#if defined( DOS ) || defined( _WIN32 )
-#include <time.h>
-#include "msdos.h"
-#ifdef PCNFS
-#include <tklib.h>
-#include <tk_errno.h>
-#include <bios.h>
-#endif /* PCNFS */
-#ifdef NCSA
-#include "externs.h"
-#endif /* NCSA */
-#else /* DOS */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#ifdef _AIX
-#include <sys/select.h>
-#endif /* _AIX */
-#include "portable.h"
-#endif /* DOS */
-#endif /* MACOS */
-#ifdef VMS
-#include "ucx_select.h"
-#endif
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-#ifdef USE_SYSCONF
-#include <unistd.h>
-#endif /* USE_SYSCONF */
-
-#ifdef NEEDPROTOS
-static int ldap_abandoned( LDAP *ld, int msgid );
-static int ldap_mark_abandoned( LDAP *ld, int msgid );
-static int wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
- LDAPMessage **result );
-static int read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc,
- LDAPMessage **result );
-static int build_result_ber( LDAP *ld, BerElement *ber, LDAPRequest *lr );
-static void merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr );
-#ifdef CLDAP
-static int ldap_select1( LDAP *ld, struct timeval *timeout );
-#endif
-static int Ref_AddToRequest(LDAPRequest *lr, char **refs);
-static void Ref_FreeAll(LDAPRequest *lr);
-#else /* NEEDPROTOS */
-static int ldap_abandoned();
-static int ldap_mark_abandoned();
-static int wait4msg();
-static int read1msg();
-static int build_result_ber();
-static void merge_error_info();
-#ifdef CLDAP
-static int ldap_select1();
-#endif
-#endif /* NEEDPROTOS */
-
-#if !defined( MACOS ) && !defined( DOS )
-extern int errno;
-#endif
-
-/*
- * ldap_result - wait for an ldap result response to a message from the
- * ldap server. If msgid is -1, any message will be accepted, otherwise
- * ldap_result will wait for a response with msgid.
- * If all is LDAP_MSG_ONE the first message with id msgid will be accepted.
- * If all is LDAP_MSG_RECEIVED, the received messages with the id msgid will
- * be accepted.
- * Otherwise, ldap_result will wait for all responses with id msgid and
- * then return a pointer to the entire list of messages. This is only
- * useful for search responses, which can be of 3 message types (zero or
- * more entries, zero or more references, one or more results). The type
- * of the first message* received is returned.
- * When waiting, any messages that have been abandoned are discarded.
- *
- * Example:
- * ldap_result( s, msgid, all, timeout, result )
- */
-int
-ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout,
- LDAPMessage **result )
-{
- LDAPMessage *lm, *lastlm, *nextlm;
- int rv;
-
- /*
- * First, look through the list of responses we have received on
- * this association and see if the response we're interested in
- * is there. If it is, return it. If not, call wait4msg() to
- * wait until it arrives or timeout occurs.
- */
-
-#ifdef _REENTRANT
- LOCK_RESPONSE(ld);
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 223, "ldap_result\n"), 0, 0, 0 );
-
- *result = NULLMSG;
- lastlm = NULLMSG;
-
- /* look in the received responses */
- for ( lm = ld->ld_responses; lm != NULLMSG; lm = nextlm ) {
- nextlm = lm->lm_next;
-
- /* if the msg has been abandonned, free it */
- if ( ldap_abandoned( ld, lm->lm_msgid ) ) {
- ldap_mark_abandoned( ld, lm->lm_msgid );
-
- if ( lastlm == NULLMSG ) {
- ld->ld_responses = lm->lm_next;
- } else {
- lastlm->lm_next = nextlm;
- }
-
- ldap_msgfree( lm );
-
- continue;
- }
-
- if ( msgid == LDAP_RES_ANY || lm->lm_msgid == msgid ) {
- LDAPMessage *tmp;
-
- /* If return ONE or RECEIVED message(s) or not a search result, return lm */
- if ( all == LDAP_MSG_ONE || all == LDAP_MSG_RECEIVED
- || (lm->lm_msgtype != LDAP_RES_SEARCH_RESULT
- && lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY
- && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) )
- break;
-
- /* Search in the set of messages if one is a search result */
- for ( tmp = lm; tmp != NULLMSG; tmp = tmp->lm_chain ) {
- if ( tmp->lm_msgtype == LDAP_RES_SEARCH_RESULT )
- break;
- }
- /* No, well wait for the result message */
- if ( tmp == NULLMSG ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- rv = wait4msg( ld, msgid, all, timeout, result );
-#ifdef _REENTRANT
- UNLOCK_RESPONSE(ld);
-#endif
- return( rv );
- }
- /* Here we have the Search result pointed by tmp */
- break;
- }
- /* Check next response */
- lastlm = lm;
- }
-
- /* No response matching found : Wait for one */
- if ( lm == NULLMSG ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- rv = wait4msg( ld, msgid, all, timeout, result );
-#ifdef _REENTRANT
- UNLOCK_RESPONSE(ld);
-#endif
- return( rv );
- }
-
- /* lm points to the message (chain) to return */
-
- /* Remove message to return from ld_responses list */
- if ( lastlm == NULLMSG ) {
- if (all == LDAP_MSG_ONE && lm->lm_chain != NULLMSG){
- ld->ld_responses = lm->lm_chain;
- } else {
- ld->ld_responses = lm->lm_next;
- }
- } else {
- if (all == LDAP_MSG_ONE && lm->lm_chain != NULLMSG) {
- lastlm->lm_next = lm->lm_chain;
- } else {
- lastlm->lm_next = lm->lm_next;
- }
- }
-
- if ( all == LDAP_MSG_ONE )
- lm->lm_chain = NULLMSG;
- /* Otherwise return the whole chain */
- /* No reponses attached */
- lm->lm_next = NULLMSG;
-
- *result = lm;
- ld->ld_errno = LDAP_SUCCESS;
- rv = lm->lm_msgtype;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
- UNLOCK_RESPONSE(ld);
-#endif
- return( rv );
-}
-
-static int
-wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
- LDAPMessage **result )
-{
- int rc;
- struct timeval tv, *tvp;
- time_t start_time, tmp_time;
- LDAPConn *lc, *nextlc;
-
-#ifdef LDAP_DEBUG
- if ( timeout == NULL ) {
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 224, "wait4msg (infinite timeout)\n"),
- 0, 0, 0 );
- } else {
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 225, "wait4msg (timeout %1$ld sec, %2$ld usec)\n"),
- timeout->tv_sec, timeout->tv_usec, 0 );
- }
-#endif /* LDAP_DEBUG */
-
- if ( timeout == NULL ) {
- tvp = NULL;
- } else {
- tv = *timeout;
- tvp = &tv;
- start_time = time( NULL );
- }
-
- rc = -2;
- while ( rc == -2 ) {
-#ifdef LDAP_DEBUG
- if ( ldap_debug & LDAP_DEBUG_TRACE ) {
- dump_connection( ld, ld->ld_conns, 1 );
- dump_requests_and_responses( ld );
- }
-#endif /* LDAP_DEBUG */
- for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
- if ( lc->lconn_sb->sb_ber.ber_ptr <
- lc->lconn_sb->sb_ber.ber_end ) {
- /* A Message is available, decode and process it */
- rc = read1msg( ld, msgid, all, lc->lconn_sb,
- lc, result );
- break;
- }
- }
- /* There was no message available : Wait for one */
- if ( lc == NULL ) {
- rc = do_ldap_select( ld, tvp );
-
-
-#if defined( LDAP_DEBUG ) && !defined( MACOS ) && !defined( DOS )
- if ( rc == -1 ) {
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 226, "do_ldap_select returned -1: errno %d\n"),
- errno, 0, 0 );
- }
-#endif
-
-#if !defined( MACOS ) && !defined( DOS )
- if ( rc == 0 || ( rc == -1 && (ld->ld_restart || errno != EINTR ))) {
-#else
- if ( rc == -1 || rc == 0 ) {
-#endif
- ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
- LDAP_TIMEOUT);
- if ( rc == -1 ) {
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- nsldapi_connection_lost_nolock( ld, NULL);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- }
- return( rc );
- }
-
- if ( rc == -1 ) {
- rc = -2; /* select interrupted: Continue the loop */
- } else {
- rc = -2;
- for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
- lc = nextlc ) {
- nextlc = lc->lconn_next;
- if ( lc->lconn_status == LDAP_CONNST_CONNECTED) {
- /* Check on each connection. */
- long is_ready = is_read_ready( ld, lc->lconn_sb );
-
- if (is_ready > 0) {
- /* A Message is available, decode and process it */
- rc = read1msg( ld, msgid, all,
- lc->lconn_sb, lc, result );
- } else if ( is_ready < 0){
- /* Error in the select : what to do in here ? */
- /* So far : */
- rc = -1;
- }
- }
- }
- }
- }
-
- if ( rc == -2 && tvp != NULL ) {
- tmp_time = time( NULL );
- if (( tv.tv_sec -= ( tmp_time - start_time )) <= 0 ) {
- /* At this point if all == LDAP_MSG_RECEIVED, we must
- return all available messages for the msgid */
- if (all == LDAP_MSG_RECEIVED) {
- /* Search in responses if some have the correct id */
- /* if yes return the chain */
- /* Otherwise return timeout */
- break;
- }
-
- rc = 0; /* timed out */
- ld->ld_errno = LDAP_TIMEOUT;
- break;
- }
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 227, "wait4msg: %ld secs to go\n"),
- tv.tv_sec, 0, 0 );
- start_time = tmp_time;
- }
- }
-
- return( rc );
-}
-
-
-static int
-read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
- LDAPConn *lc,
- LDAPMessage **result )
-{
- BerElement ber;
- LDAPMessage *new, *L_res, *l, *prev, *tmp;
- int id;
- unsigned int tag, atag, len;
- int foundit = 0;
- LDAPRequest *lr, *lrparent;
- LDAPRef *theReferences;
- BerElement tmpber;
- int rc, refer_cnt, hadref, simple_request, samereq = 0, total_count;
- int retcode;
- int theErrCode = LDAP_SUCCESS;
- unsigned int lderr;
- char *msgtypestr;
- char ** theRefs = NULL;
- char * theOid = NULL;
- char *lddn, *lderrmsg;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 228, "read1msg\n"), 0, 0, 0 );
-
-read_from_sb:
- lderr = LDAP_SUCCESS; /* Be optimistic */
-
- ber_zero_init( &ber, 0 );
- set_ber_options( ld, &ber );
-
- /* get the next message */
- if ( (tag = ber_get_next( sb, &len, &ber ))
- != LDAP_TAG_MESSAGE ) {
- ld->ld_errno = (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
- LDAP_LOCAL_ERROR);
- if ( tag == LBER_DEFAULT ) {
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- nsldapi_connection_lost_nolock( ld, sb );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- }
- return( -1 );
- }
-
- /* message id */
- if ( ber_get_int( &ber, &id ) == LBER_ERROR ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return( -1 );
- }
-
- /* if it's been abandoned, toss it */
- if ( ldap_abandoned( ld, (int)id ) ) {
- free( ber.ber_buf ); /* gack! */
- return( -2 ); /* continue looking */
- }
-
- /* the message type */
- if ( (tag = ber_peek_tag( &ber, &len )) == LBER_ERROR ) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return( -1 );
- }
-
- /* KE
- * Treat unsolicited notification if we got one!
- * id==0
- * tag==LDAP_RES_EXTENDED
- *
- * resultCode== protocolError
- * strongAuthRequired
- * unavailable
- * tag==LDAP_TAG_EXT_RESPNAME
- * response name (oid)==1.3.6.1.1.4.1.1466.20036
- * no response field
- *
- * Example:
- * --------
- * Ber format: {iaata}
- * which means: returnCode dn errorMessage LDAP_TAG_EXT_RESPNAME "1.3.6.1.1.4.1.1466.20036"
- */
- if ( (id==0) && (tag==LDAP_RES_EXTENDED) )
- {
- tmpber = ber;
- if (ber_scanf( &ber, "{iaa", &lderr, &lddn, &lderrmsg) != LBER_ERROR)
- {
- if (ber_peek_tag ( &ber, &atag) == LDAP_TAG_EXT_RESPNAME)
- {
- if ( ber_get_stringa( &ber, &theOid) == LBER_ERROR )
- {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return(-1);
- }
- }
- else
- {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return(-1);
- }
-
- if (ber_peek_tag ( &ber, &atag) == LDAP_TAG_EXT_RESPONSE)
- {
- /* this field must be absent */
- ld->ld_errno = LDAP_DECODING_ERROR;
- return(-1);
- }
- if ( ber_scanf(&ber, "}")== LBER_ERROR)
- {
- ld->ld_errno = LDAP_DECODING_ERROR;
- return(-1);
- }
-
- /* make a new ldap message to return the result */
- if ( (new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) )) == NULL )
- {
- ld->ld_errno = LDAP_NO_MEMORY;
- return(-1);
- }
- new->lm_msgid = 0;
- new->lm_msgtype = tag;
- new->lm_ber = ber_dup( &tmpber );
-
- if ( (strncmp(theOid, "1.3.6.1.1.4.1.1466.20036", 24)==0) &&
- (lderr==LDAP_PROTOCOL_ERROR) ||
- (lderr==LDAP_STRONG_AUTH_REQUIRED) ||
- (lderr==LDAP_UNAVAILABLE) )
- {
- /* make a new ldap message to return the result */
- if ( (L_res = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) )) == NULL )
- {
- ld->ld_errno = LDAP_NO_MEMORY;
- return(-1);
- }
- L_res->lm_msgid = 0;
- L_res->lm_msgtype = tag;
- L_res->lm_ber = ber_dup( &tmpber );
- *result = L_res;
-
- /* It is a notice of disconnection
- * Return immediatly with an error code to stop
- * reading any new message and to prevent the use
- */
- ld->ld_errno = LDAP_SERVER_DOWN;
- ldap_insert_notif(ld, new); /* in head */
- return(-1);
- }
- else
- {
- /* This is another notification
- * Keep on the processing of received messages
- */
- ldap_add_notif(ld, new); /* in tail */
- goto read_from_sb;
- }
- }
- else
- {
- Debug(LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1673, "Error while decoding Extended Response message"), NULL, NULL, NULL);
- ld->ld_errno = LDAP_DECODING_ERROR;
- return(-1);
- }
- }
- else if (( lr = find_request_by_msgid( ld, id )) == NULL )
- {
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 229, "no request for response with msgid %ld (tossing)\n"), id, 0, 0 );
- free( ber.ber_buf ); /* gack! */
- return( -2 ); /* continue looking */
- }
-
- if (tag == LDAP_RES_SEARCH_ENTRY)
- msgtypestr = catgets(slapdcat, 1, 1281, "search entry");
- else if (tag == LDAP_RES_SEARCH_REFERENCE)
- msgtypestr = catgets(slapdcat, 1, 1282, "search reference");
- else
- msgtypestr = catgets(slapdcat, 1, 1283, "result");
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 230, "got %1$s msgid %2$ld, original id %3$d\n"),
- msgtypestr, id, lr->lr_origid );
-
- id = lr->lr_origid;
-
- /* REFERRALS HANDLING*/
- refer_cnt = 0;
- simple_request = 0;
- hadref = 0;
- rc = -2; /* default is to keep looking (no response found) */
- lr->lr_res_msgtype = tag;
-
- if ( tag != LDAP_RES_SEARCH_ENTRY ) { /* If it's not an entry, ie it's a result or a reference */
- if ( ld->ld_version >= LDAP_VERSION2 &&
- ( lr->lr_parent != NULL ||
- ld->ld_follow_referral /* || ClientControl to follow referral present */ )) {
- tmpber = ber;
- if (tag == LDAP_RES_SEARCH_REFERENCE){
- /* LDAP V3 reference. Decode it */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "LDAP search reference received. Will follow it later\n"),
- 0, 0,0);
- if (ber_scanf(&tmpber, "{v}", &theRefs) == LBER_ERROR){
- Debug ( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1284, "Error while decoding Search Reference Result message\n"),
- NULL, NULL, NULL);
- rc = -1;
- theRefs = NULL;
- } else {
- /* Store the referrals in request. We will follow them when the result arrives */
- Ref_AddToRequest(lr, theRefs);
- theRefs = NULL;
- free( ber.ber_buf ); /* gack! */
- ber.ber_buf = NULL;
- return (rc);
- }
- } else {
- if (ber_scanf( &tmpber, "{iaa", &lderr, &lr->lr_res_matched, &lr->lr_res_error) != LBER_ERROR){
- if (lderr == LDAP_PARTIAL_RESULTS){
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "LDAPv2 partial error received\n"), 0, 0,0);
- /* Ldapv2 referrals */
- theRefs = ldap_errormsg2referrals(lr->lr_res_error);
- ber_scanf(&tmpber, "}");
- } else if (lderr == LDAP_REFERRAL ){
- /* We have some referrals, decode them */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "LDAPv3 referral error received\n"), 0, 0,0);
- if (ber_peek_tag ( &tmpber, &atag) == LDAP_TAG_REFERRAL){
- if (ber_scanf(&tmpber, "{v}}", &theRefs) == LBER_ERROR){
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1285, "Error while decoding referrals in msg\n"),
- NULL, NULL, NULL );
- rc = -1; /* ??? */
- theRefs = NULL;
- }
- } /* else error there should be at least one ref */
- } else if (((lderr == LDAP_NO_SUCH_OBJECT) ||
- (lderr == LDAP_BUSY) ||
- (lderr == LDAP_UNAVAILABLE) ||
- (lderr == LDAP_SERVER_DOWN) ||
- (lderr == LDAP_CONNECT_ERROR)) &&
- (lr->lr_parent != NULL) && /* its subrequest */
- (lr->lr_ref_tofollow != NULL)) { /* And it has some other referral to try */
- samereq = 1;
- theRefs = lr->lr_ref_tofollow;
- lr->lr_ref_tofollow = NULL;
- lrparent = lr->lr_parent;
- /* delete lr */
- free_request(ld, lr);
- /* lr now points on parent request */
- lr = lrparent;
- /* Follow referrals */
- } else {
- /* Here we have a simple result */
- hadref = lr->lr_outrefcnt;
- }
- } else {
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, 1286, "Error while decoding result for request %$1d\n"),
- lr->lr_origid, NULL, NULL);
- rc = -1; /* ??? */
- }
- }
-
- total_count = 0;
- if (tag != LDAP_RES_SEARCH_REFERENCE && lr->lr_references) {
- /* Some search references pending... Let's try to chase them */
- hadref = 1;
- theReferences = lr->lr_references;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, -1, "Now following the search references received\n"),
- 0, 0,0);
-
- while (theReferences != NULL){
- if ((retcode = chase_referrals(ld, lr, theReferences->lref_refs , &refer_cnt, 0)) != LDAP_SUCCESS) {
- /* think about what to do */
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, -1, "Error while chasing referral (%1$d)\n"),
- retcode, NULL, NULL);
- theErrCode = LDAP_REFERRAL;
- }
- if (refer_cnt >= 0)
- total_count += refer_cnt;
- theReferences = theReferences->lref_next;
- }
- Ref_FreeAll(lr);
- if (theErrCode != LDAP_SUCCESS) {
- if (ld->ld_error != NULL && *ld->ld_error) {
- if (lr->lr_res_error)
- free(lr->lr_res_error);
- lr->lr_res_error = strdup(ld->ld_error);
- }
- }
- lr->lr_res_errno = theErrCode;
- }
- /* if theRefs != NULL we have some referrals to chase, do it */
- if (theRefs){
- hadref = 1;
- if ((retcode = chase_referrals(ld, lr, theRefs, &refer_cnt, samereq)) != LDAP_SUCCESS){
- /* think about what to do */
- Debug( LDAP_DEBUG_ANY, catgets(slapdcat, 1, -1, "Error while chasing referral (%1$d)\n"),
- retcode, NULL, NULL);
- }
-
- if (refer_cnt >= 0)
- total_count += refer_cnt;
-
- ldap_value_free(theRefs);
- if (samereq){ /* Just tried another referral for same request */
- free(ber.ber_buf);
- ber.ber_buf = NULL;
- rc = -2;
- /* continue */
- }
- if (retcode != LDAP_SUCCESS) {
- if (ld->ld_version == LDAP_VERSION2){
- if (lr->lr_res_error)
- free(lr->lr_res_error);
- lr->lr_res_error = ldap_referral2error_msg(lr->lr_ref_unfollowed);
- } else if (ld->ld_error != NULL && *ld->ld_error) {
- if (lr->lr_res_error)
- free(lr->lr_res_error);
- lr->lr_res_error = strdup(ld->ld_error);
- }
- }
- lr->lr_res_errno = ld->ld_errno;
-
- } else if (theErrCode == LDAP_SUCCESS) {
- /* no referral have been chased */
- lr->lr_res_errno = (lderr == LDAP_PARTIAL_RESULTS || lderr == LDAP_REFERRAL) ? LDAP_SUCCESS : lderr;
- }
-
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 231, "new result: res_errno: %1$d, res_error: <%2$s>, res_matched: <%3$s>\n"),
- lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
- lr->lr_res_matched ? lr->lr_res_matched : "" );
- }
-
-
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 232, "read1msg: %1$d new referrals\n"), total_count, 0, 0 );
-
- if ( refer_cnt != 0 ) { /* chasing referrals */
- free( ber.ber_buf ); /* gack! */
- ber.ber_buf = NULL;
- if ( refer_cnt < 0 ) {
- return( -1 ); /* fatal error */
- }
- lr->lr_status = LDAP_REQST_CHASINGREFS;
- } else if (tag == LDAP_RES_SEARCH_REFERENCE && !ld->ld_follow_referral) {
- /* We had a ref and we don't follow referral : Do nothing there ?! */
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, -1, "read1msg: returning search reference\n"), 0, 0, 0 );
-
- } else {
- /* No referral chasing */
- if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) {
- /* request without any referrals */
- simple_request = ( hadref ? 0 : 1 );
- } else {
- /* request with referrals or child request */
- free( ber.ber_buf ); /* gack! */
- ber.ber_buf = NULL;
- }
-
-
- while ( lr->lr_parent != NULL ) {
- merge_error_info( ld, lr->lr_parent, lr );
- lr = lr->lr_parent;
- if ( --lr->lr_outrefcnt > 0 ) {
- break; /* not completedly done yet */
- }
- }
-
- if ( lr->lr_outrefcnt <= 0 && lr->lr_parent == NULL ) { /* The main request has no more outstanding refs */
- id = lr->lr_msgid;
- tag = lr->lr_res_msgtype;
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 233, "request %1$ld done\n"),
- id, 0, 0 );
- Debug( LDAP_DEBUG_TRACE,
- catgets(slapdcat, 1, 234, "res_errno: %1$d, res_error: <%2$s>, res_matched: <%3$s>\n"),
- lr->lr_res_errno, lr->lr_res_error ? lr->lr_res_error : "",
- lr->lr_res_matched ? lr->lr_res_matched : "" );
- if ( !simple_request ) { /* We have to rebuild the result */
- if ( ber.ber_buf != NULL ) {
- free( ber.ber_buf ); /* gack! */
- ber.ber_buf = NULL;
- }
- if ( build_result_ber( ld, &ber, lr )
- == LBER_ERROR ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- rc = -1; /* fatal error */
- }
- }
-
- free_request( ld, lr );
- }
-
- if ( lc != NULL ) {
- free_connection( ld, lc, 0, 1 );
- }
- }
- }
-
- if ( ber.ber_buf == NULL ) { /* If the buffer has been freed, return */
- return( rc );
- }
- /* End of REFERRALS */
-
- /* make a new ldap message */
- if ( (new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) ))
- == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
- new->lm_msgid = (int)id;
- new->lm_msgtype = tag;
- new->lm_ber = ber_dup( &ber );
-
-#ifndef NO_CACHE
- if ( ld->ld_cache != NULL ) {
- add_result_to_cache( ld, new );
- }
-#endif /* NO_CACHE */
-
- /* is this the one we're looking for? */
- if ( msgid == LDAP_RES_ANY || id == msgid ) {
- if ( all == LDAP_MSG_ONE /* all apply only to search, so if not a search,return the val */
- || (new->lm_msgtype != LDAP_RES_SEARCH_RESULT
- && new->lm_msgtype != LDAP_RES_SEARCH_ENTRY
- && new->lm_msgtype != LDAP_RES_SEARCH_REFERENCE) ) {
- *result = new;
- ld->ld_errno = LDAP_SUCCESS;
- return( tag );
- } else if ( new->lm_msgtype == LDAP_RES_SEARCH_RESULT) {
- foundit = 1; /* return the chain later */
- }
- }
-
- /*
- * if not, we must add it to the list of responses. if
- * the msgid is already there, it must be part of an existing
- * search response.
- */
-
- prev = NULLMSG;
- for ( l = ld->ld_responses; l != NULLMSG; l = l->lm_next ) {
- if ( l->lm_msgid == new->lm_msgid )
- break;
- prev = l;
- }
-
- /* not part of an existing search response */
- if ( l == NULLMSG ) {
- if ( foundit ) { /* it a search result anyway, so return it */
- *result = new;
- ld->ld_errno = LDAP_SUCCESS;
- return( tag );
- }
-
- new->lm_next = ld->ld_responses;
- ld->ld_responses = new;
- return( -2 ); /* continue looking */
- }
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 235, "adding response id %1$d type %2$d:\n"),
- new->lm_msgid, new->lm_msgtype, 0 );
-
- /* part of a search response - add to end of list of entries or references */
- for ( tmp = l; tmp->lm_chain != NULLMSG &&
- (tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ||
- tmp->lm_chain->lm_msgtype == LDAP_RES_SEARCH_REFERENCE);
- tmp = tmp->lm_chain )
- ; /* NULL */
- tmp->lm_chain = new;
-
- /* return the whole chain if that's what we were looking for */
- if ( foundit ) {
- if ( prev == NULLMSG )
- ld->ld_responses = l->lm_next;
- else
- prev->lm_next = l->lm_next;
- *result = l;
- ld->ld_errno = LDAP_SUCCESS;
- return( l->lm_msgtype ); /* Patch 16 : was return(tag) */
- }
-
- return( -2 ); /* continue looking */
-}
-
-
-static int
-build_result_ber( LDAP *ld, BerElement *ber, LDAPRequest *lr )
-{
- unsigned int len;
- int along;
-
- Debug (LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1287, "=> building_ber_error msgid %ld\n"), lr->lr_msgid, 0,0);
- ber_zero_init( ber, 0 );
- set_ber_options( ld, ber );
- if (ld->ld_version == LDAP_VERSION3){
- if ( ber_printf( ber, "{it{ess",
- lr->lr_msgid,
- lr->lr_res_msgtype,
- lr->lr_res_errno,
- lr->lr_res_matched ? lr->lr_res_matched : "",
- lr->lr_res_error ? lr->lr_res_error : "" ) == LBER_ERROR){
- return (LBER_ERROR);
- }
- if (lr->lr_res_errno == LDAP_REFERRAL &&
- ber_printf(ber, "t{v}", LDAP_TAG_REFERRAL, lr->lr_ref_unfollowed) == LBER_ERROR){
- return (LBER_ERROR);
- }
- if (ber_printf(ber, "}}") == LBER_ERROR){
- return (LBER_ERROR);
- }
- } else {
- if ( ber_printf( ber, "{it{ess}}",
- lr->lr_msgid,
- lr->lr_res_msgtype,
- lr->lr_res_errno,
- lr->lr_res_matched ? lr->lr_res_matched : "",
- lr->lr_res_error ? lr->lr_res_error : "" ) == LBER_ERROR ) {
- return( LBER_ERROR );
- }
- }
-
- ber_reset( ber, 1 );
- if ( ber_skip_tag( ber, &len ) == LBER_ERROR ) {
- return( LBER_ERROR );
- }
-
- if ( ber_get_int( ber, &along ) == LBER_ERROR ) {
- return( LBER_ERROR );
- }
-
- return( ber_peek_tag( ber, &len ));
-}
-
-
-static void
-merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
-{
- int i, j;
-/*
- * Merge error information in "lr" with "parentr" error code and string.
- */
- if ( lr->lr_res_errno == LDAP_PARTIAL_RESULTS ) {
- parentr->lr_res_errno = lr->lr_res_errno;
- if ( lr->lr_res_error != NULL ) {
- (void)append_referral( ld, &parentr->lr_res_error,
- lr->lr_res_error );
- }
- } else if ( lr->lr_res_errno != LDAP_SUCCESS &&
- parentr->lr_res_errno == LDAP_SUCCESS ) {
- parentr->lr_res_errno = lr->lr_res_errno;
- if ( parentr->lr_res_error != NULL ) {
- free( parentr->lr_res_error );
- }
- parentr->lr_res_error = lr->lr_res_error;
- lr->lr_res_error = NULL;
- if ( NAME_ERROR( lr->lr_res_errno )) {
- if ( parentr->lr_res_matched != NULL ) {
- free( parentr->lr_res_matched );
- }
- parentr->lr_res_matched = lr->lr_res_matched;
- lr->lr_res_matched = NULL;
- }
- if (lr->lr_ref_unfollowed != NULL){
- for (i=0;lr->lr_ref_unfollowed[i] != NULL; i++);
- j = 0;
- if (parentr->lr_ref_unfollowed != NULL){
- for (j=0;parentr->lr_ref_unfollowed[j]!= NULL ;j++);
- j++;
- }
- parentr->lr_ref_unfollowed = (char **)realloc (parentr->lr_ref_unfollowed, (j+i+1) * sizeof(char *));
- if (parentr->lr_ref_unfollowed != NULL){
- for (i = 0; lr->lr_ref_unfollowed[i] != NULL; i++){
- parentr->lr_ref_unfollowed[j+i] = lr->lr_ref_unfollowed[i];
- lr->lr_ref_unfollowed[i] = NULL;
- }
- parentr->lr_ref_unfollowed[i+j+1] = NULL;
- } else {
- if (parentr->lr_res_errno == LDAP_SUCCESS)
- parentr->lr_res_errno = LDAP_NO_MEMORY;
- }
- }
- }
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 236, "merged parent (id %1$d) error info: "),
- parentr->lr_msgid, 0, 0 );
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 237, "result errno %1$d, error <%2$s>, matched <%3$s>\n"),
- parentr->lr_res_errno,
- parentr->lr_res_error ? parentr->lr_res_error : "",
- parentr->lr_res_matched ? parentr->lr_res_matched : "" );
-}
-
-#ifdef CLDAP
-#if !defined( MACOS ) && !defined( DOS ) && !defined( _WIN32 )
-static int
-ldap_select1( LDAP *ld, struct timeval *timeout )
-{
- fd_set readfds;
- static int tblsize;
-
- if ( tblsize == 0 ) {
-#ifdef USE_SYSCONF
- tblsize = (int) sysconf( _SC_OPEN_MAX );
-#else /* USE_SYSCONF */
- tblsize = getdtablesize();
-#endif /* USE_SYSCONF */
- }
-
- FD_ZERO( &readfds );
- FD_SET( ld->ld_sb.sb_sd, &readfds );
-
- return( select( tblsize, &readfds, 0, 0, timeout ) );
-}
-#endif /* !MACOS */
-
-
-#ifdef MACOS
-static int
-ldap_select1( LDAP *ld, struct timeval *timeout )
-{
- return( tcpselect( ld->ld_sb.sb_sd, timeout ));
-}
-#endif /* MACOS */
-
-
-#if ( defined( DOS ) && defined( WINSOCK )) || defined( _WIN32 )
-static int
-ldap_select1( LDAP *ld, struct timeval *timeout )
-{
- fd_set readfds;
- int rc;
-
- FD_ZERO( &readfds );
- FD_SET( ld->ld_sb.sb_sd, &readfds );
-
- rc = select( 1, &readfds, 0, 0, timeout );
- return( rc == SOCKET_ERROR ? -1 : rc );
-}
-#endif /* WINSOCK || _WIN32 */
-
-
-#ifdef DOS
-#ifdef PCNFS
-static int
-ldap_select1( LDAP *ld, struct timeval *timeout )
-{
- fd_set readfds;
- int res;
-
- FD_ZERO( &readfds );
- FD_SET( ld->ld_sb.sb_sd, &readfds );
-
- res = select( FD_SETSIZE, &readfds, NULL, NULL, timeout );
- if ( res == -1 && errno == EINTR) {
- /* We've been CTRL-C'ed at this point. It'd be nice to
- carry on but PC-NFS currently won't let us! */
- printf("\n*** CTRL-C ***\n");
- exit(-1);
- }
- return( res );
-}
-#endif /* PCNFS */
-
-#ifdef NCSA
-static int
-ldap_select1( LDAP *ld, struct timeval *timeout )
-{
- int rc;
- clock_t endtime;
-
- if ( timeout != NULL ) {
- endtime = timeout->tv_sec * CLK_TCK +
- timeout->tv_usec * CLK_TCK / 1000000 + clock();
- }
-
- do {
- Stask();
- rc = netqlen( ld->ld_sb.sb_sd );
- } while ( rc <= 0 && ( timeout == NULL || clock() < endtime ));
-
- return( rc > 0 ? 1 : 0 );
-}
-#endif /* NCSA */
-#endif /* DOS */
-#endif /* CLDAP */
-
-
-int
-ldap_msgfree( LDAPMessage *lm )
-{
- LDAPMessage *next;
- int type = 0;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 238, "ldap_msgfree\n"), 0, 0, 0 );
-
- for ( ; lm != NULLMSG; lm = next ) {
- next = lm->lm_chain;
- type = lm->lm_msgtype;
- if (lm->lm_ber)
- ber_free( lm->lm_ber, 1 );
- free( (char *) lm );
- }
-
- return( type );
-}
-
-/*
- * ldap_msgdelete - delete a message. It returns:
- * 0 if the entire message was deleted
- * -1 if the message was not found, or only part of it was found
- */
-int
-ldap_msgdelete( LDAP *ld, int msgid )
-{
- LDAPMessage *lm, *prev;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
- LOCK_RESPONSE(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 239, "ldap_msgdelete\n"), 0, 0, 0 );
-
- prev = NULLMSG;
- for ( lm = ld->ld_responses; lm != NULLMSG; lm = lm->lm_next ) {
- if ( lm->lm_msgid == msgid )
- break;
- prev = lm;
- }
-
- if ( lm == NULLMSG ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
- UNLOCK_RESPONSE(ld);
-#endif
- return( -1 );
- }
-
- if ( prev == NULLMSG )
- ld->ld_responses = lm->lm_next;
- else
- prev->lm_next = lm->lm_next;
-
- if ( ldap_msgfree( lm ) == LDAP_RES_SEARCH_ENTRY ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
- UNLOCK_RESPONSE(ld);
-#endif
- return( -1 );
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
- UNLOCK_RESPONSE(ld);
-#endif
- return( 0 );
-}
-
-
-/*
- * return 1 if message msgid is waiting to be abandoned, 0 otherwise
- */
-static int
-ldap_abandoned( LDAP *ld, int msgid )
-{
- int i;
-
- if ( ld == NULL ) return(1);
- if ( ld->ld_abandoned == NULL )
- return( 0 );
-
- for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
- if ( ld->ld_abandoned[i] == msgid )
- return( 1 );
-
- return( 0 );
-}
-
-
-static int
-ldap_mark_abandoned( LDAP *ld, int msgid )
-{
- int i;
-
- if ( ld->ld_abandoned == NULL )
- return( -1 );
-
- for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
- if ( ld->ld_abandoned[i] == msgid )
- break;
-
- if ( ld->ld_abandoned[i] == -1 )
- return( -1 );
-
- for ( ; ld->ld_abandoned[i] != -1; i++ ) {
- ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];
- }
-
- return( 0 );
-}
-
-
-#ifdef CLDAP
-int
-cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement *ber )
-{
- int rc;
- unsigned int tag, len;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ( ld->ld_sb.sb_ber.ber_ptr >= ld->ld_sb.sb_ber.ber_end ) {
- rc = ldap_select1( ld, timeout );
- if ( rc == -1 || rc == 0 ) {
- ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
- LDAP_TIMEOUT);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( rc );
- }
- }
-
- /* get the next message */
- if ( (tag = ber_get_next( &ld->ld_sb, &len, ber ))
- != LDAP_TAG_MESSAGE ) {
- ld->ld_errno = (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
- LDAP_LOCAL_ERROR);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( tag );
-}
-#endif /* CLDAP */
-
-/* ldapv3 API extensions */
-
-int ldap_msgtype(LDAPMessage *res)
-{
- if (res == NULL)
- return (LDAP_RES_ANY);
- return (res->lm_msgtype);
-}
-
-
-int ldap_msgid(LDAPMessage *res)
-{
- if (res == NULL)
- return (LDAP_RES_ANY);
- return (res->lm_msgid);
-}
-
-int ldap_parse_result(LDAP *ld, LDAPMessage *res, int *errcodep, char **matcheddnp,
- char **errmsgp, char ***referralsp, LDAPControl ***serverctrlsp,
- int freeit)
-{
- LDAPMessage *lm;
- BerElement ber;
- unsigned int alen;
- int along;
- unsigned int tag;
- int i;
- size_t rc;
- char * acharp = NULL, * a2ndcharp = NULL;
- char ** arefs = NULL;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_parse_result\n", 0, 0, 0 );
-
- if (res == NULLMSG)
- return (LDAP_PARAM_ERROR);
-
- if (matcheddnp && *matcheddnp){
- free(*matcheddnp);
- *matcheddnp = NULL;
- }
- if (errmsgp && *errmsgp){
- free(*errmsgp);
- *errmsgp = NULL;
- }
- if (referralsp && *referralsp){
- free_strarray(*referralsp);
- *referralsp = NULL;
- }
-
- if (serverctrlsp && *serverctrlsp){
- ldap_controls_free(*serverctrlsp);
- *serverctrlsp = NULL;
- }
-
- for (lm = res; lm->lm_chain != NULL; lm = lm->lm_chain)
-
- if ( lm->lm_msgtype != LDAP_RES_SEARCH_ENTRY
- && lm->lm_msgtype != LDAP_RES_SEARCH_REFERENCE)
- break;
-
- ber = *(lm->lm_ber);
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if (ld->ld_version == LDAP_VERSION3) {
- rc = ber_scanf( &ber, "{iaa", &along, &acharp, &a2ndcharp);
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- if (matcheddnp) {
- *matcheddnp = acharp;
- } else {
- ldap_memfree(acharp);
- }
- if (errmsgp) {
- *errmsgp = a2ndcharp;
- } else {
- ldap_memfree(a2ndcharp);
- }
-
- if (errcodep) {
- *errcodep = along;
- }
-
- if (along == LDAP_REFERRAL){
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_REFERRAL) {
- rc = ber_scanf(&ber, "{v}", &arefs);
- if (rc == LBER_ERROR){
- /* try to free other stuff */
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- if (referralsp) {
- *referralsp = arefs;
- } else {
- for (i = 0; arefs[i] != NULL; i++)
- ldap_memfree(arefs[i]);
- ldap_memfree((char *)arefs);
- }
- } else {
- /* referral errcode without URL is forbiden */
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- }
- rc = ber_scanf(&ber, "}");
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- /* It's the end of the result but the PDU may have controls */
- if (serverctrlsp && (ber_peek_tag(&ber, &alen) == LDAP_TAG_CONTROL_LIST)) {
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 392, "Controls found in result\n"), 0, 0, 0 );
- *serverctrlsp = ldap_controls_decode(&ber,
- (int *)&rc);
- if (*serverctrlsp == NULL) {
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- } else {
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 393, "NO controls found in result\n"), 0, 0, 0 );
- }
- }
- else if (ld->ld_version == LDAP_VERSION2) {
- rc = ber_scanf( &ber, "{iaa}", &along, &acharp,
- &a2ndcharp );
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- if (matcheddnp) {
- *matcheddnp = acharp;
- } else {
- ldap_memfree(acharp);
- }
- if (errmsgp) {
- *errmsgp = a2ndcharp;
- } else {
- ldap_memfree(a2ndcharp);
- }
- if (errcodep) {
- *errcodep = along;
- }
- }
- else {
- rc = ber_scanf( &ber, "{ia}", &along, &a2ndcharp );
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
-
- if (errmsgp) {
- *errmsgp = a2ndcharp;
- } else {
- ldap_memfree(a2ndcharp);
- }
- if (errcodep) {
- *errcodep = along;
- }
- }
-
- if ( freeit )
- ldap_msgfree(res);
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_SUCCESS);
-}
-
-int ldap_parse_sasl_bind_result(LDAP *ld, LDAPMessage *res, struct berval **servercredp, int freeit)
-{
- LDAPMessage *lm;
- BerElement ber;
- int along;
- unsigned int tag;
- int i;
- size_t rc;
- char * acharp = NULL, *a2ndcharp = NULL;
- char ** arefs = NULL;
- struct berval * creds = NULL;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_parse_extended_result\n", 0, 0, 0 );
-
- if (res == NULLMSG)
- return (LDAP_PARAM_ERROR);
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ((res->lm_msgtype != LDAP_RES_BIND) || (ld->ld_version != LDAP_VERSION3)){
- ld->ld_errno = LDAP_PARAM_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_PARAM_ERROR);
- }
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
-
- ber = *(res->lm_ber);
- rc = ber_scanf( &ber, "{iaa", &along, &acharp, &a2ndcharp);
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = LDAP_DECODING_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- ldap_memfree(acharp);
- ldap_memfree(a2ndcharp);
- if (along == LDAP_SUCCESS || along == LDAP_SASL_BIND_INPROGRESS){
- /* Decode the serverSaslCreds if any */
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_SASLCREDS) {
- rc = ber_get_stringal( &ber, &creds);
- if (rc == LBER_ERROR ){
- if (freeit)
- ldap_msgfree(res);
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = LDAP_DECODING_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- if (servercredp) {
- *servercredp = creds;
- } else {
- ber_bvfree( creds );
- }
- }
- } else if (along == LDAP_REFERRAL) {
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_REFERRAL){
- rc = ber_scanf(&ber, "{v}", &arefs);
- if (rc == LBER_ERROR){
- /* try to free other stuff */
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = LDAP_DECODING_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- for (i = 0; arefs[i] != NULL; i++)
- ldap_memfree(arefs[i]);
- ldap_memfree((char *)arefs);
- } else {
- /* There should be at least one ref */
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = LDAP_DECODING_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
- }
-
- rc = ber_scanf(&ber, "}");
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = LDAP_DECODING_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_DECODING_ERROR);
- }
-
- if ( freeit )
- ldap_msgfree(res);
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- ld->ld_errno = along;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (along);
-}
-
-int ldap_parse_extended_result(LDAP *ld, LDAPMessage *res, char **resultoidp,
- struct berval **resultdata, int freeit)
-{
- LDAPMessage *lm;
- BerElement ber;
- int along;
- unsigned int tag;
- int i;
- size_t rc;
- char * acharp = NULL, *a2ndcharp = NULL, *anoid = NULL;
- char **arefs = NULL;
- struct berval * aresp = NULL;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_parse_sasl_bind_result\n", 0, 0, 0 );
-
- if ( res == NULLMSG )
- return (LDAP_PARAM_ERROR);
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ((res->lm_msgtype != LDAP_RES_EXTENDED) || (ld->ld_version != LDAP_VERSION3))
- {
- if ( res->lm_msgid != 0 )
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_PARAM_ERROR);
- }
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
-
- ber = *(res->lm_ber);
- rc = ber_scanf( &ber, "{iaa", &along, &acharp, &a2ndcharp);
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
- return (LDAP_DECODING_ERROR);
- }
- ldap_memfree(acharp);
- ldap_memfree(a2ndcharp);
-
- if (along == LDAP_REFERRAL) {
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_REFERRAL){
- rc = ber_scanf(&ber, "{v}", &arefs);
- if (rc == LBER_ERROR){
- /* try to free other stuff */
- if (freeit)
- ldap_msgfree( res );
- return (LDAP_DECODING_ERROR);
- }
- for (i = 0; arefs[i] != NULL; i++)
- ldap_memfree(arefs[i]);
- ldap_memfree((char *)arefs);
- } else {
- /* There should be at least one ref */
- if (freeit)
- ldap_msgfree( res );
- return (LDAP_DECODING_ERROR);
- }
- }
-
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_EXT_RESPNAME) {
- rc = ber_get_stringa( &ber, &anoid);
- if (rc == LBER_ERROR ){
- if (freeit)
- ldap_msgfree(res);
- return (LDAP_DECODING_ERROR);
- }
- if (resultoidp) {
- *resultoidp = anoid;
- } else {
- ldap_memfree( anoid );
- }
- }
- if (ber_peek_tag ( &ber, &tag) == LDAP_TAG_EXT_RESPONSE) {
- rc = ber_get_stringal( &ber, &aresp);
- if (rc == LBER_ERROR ){
- if (freeit)
- ldap_msgfree(res);
- return (LDAP_DECODING_ERROR);
- }
- if (resultdata) {
- *resultdata = aresp;
- } else {
- ber_bvfree( aresp );
- }
- }
-
- rc = ber_scanf(&ber, "}");
- if (rc == LBER_ERROR){
- if (freeit)
- ldap_msgfree( res );
- return (LDAP_DECODING_ERROR);
- }
-
- if ( freeit )
- ldap_msgfree(res);
-
- return (along);
-}
-
-
-static int Ref_AddToRequest(LDAPRequest *lr, char **refs) {
- int count;
- LDAPRef *lref;
- LDAPRef *newRef;
-
- if ((newRef = (LDAPRef *)calloc(1, sizeof (LDAPRef))) == NULL){
- return LDAP_NO_MEMORY;
- }
- newRef->lref_refs = refs;
- newRef->lref_next = NULL;
- lref = lr->lr_references;
- if (lref == NULL){
- lr->lr_references = newRef;
- } else {
- while (lref->lref_next != NULL)
- lref = lref->lref_next;
- lref->lref_next = newRef;
- }
- return LDAP_SUCCESS;
-}
-
-static void Ref_FreeAll(LDAPRequest *lr)
-{
- LDAPRef *lref, *next;
- lref = lr->lr_references;
- while (lref != NULL){
- next = lref->lref_next;
- ldap_value_free(lref->lref_refs);
- free (lref);
- lref = next;
- }
- lr->lr_references = NULL;
-}
diff --git a/usr/src/lib/libldap4/common/saslbind.c b/usr/src/lib/libldap4/common/saslbind.c
deleted file mode 100644
index ba8b5b4c3d..0000000000
--- a/usr/src/lib/libldap4/common/saslbind.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- *
- * Copyright 2000 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"
-#include "sec.h"
-#include <strings.h>
-
-BerElement * ldap_build_sasl_bind_req( LDAP *ld, char *dn, char *mechanism, struct berval *creds, LDAPControl ** serverctrls)
-{
- BerElement *ber = NULL;
- int err;
-
- /* Create a Bind Request for SASL authentication.
- * It look like this :
- * BindRequest := [APPLICATION 0] SEQUENCE {
- * version INTEGER,
- * name LDAPDN,
- * authentication CHOICE {
- * sasl [3] SEQUENCE {
- * mechanism LDAPString,
- * credential OCTET STRING OPTIONAL
- * }
- * }
- * }
- * all wrapped up in an LDAPMessage sequence.
- */
-
- if (dn == NULL || *dn == '\0'){
- ld->ld_errno = LDAP_PARAM_ERROR;
- return (NULLBER);
- }
-
-
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
- return (NULLBER);
- }
- if ( ber_printf( ber, "{it{ist{s", ++ld->ld_msgid, LDAP_REQ_BIND, ld->ld_version, dn, LDAP_AUTH_SASL, mechanism) == -1){
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (NULLBER);
- }
- if (creds != NULL && creds->bv_val != NULL) {
- if (ber_printf(ber, "o", creds->bv_val, creds->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_sasl_bind - bind to the ldap server (and X.500).
- * dn, mechanism, cred, serverctrls, and clientctrls are supplied.
- * the message id of the request is returned in msgid
- * Returns LDAP_SUCCESS or an error code.
- */
-
-int ldap_sasl_bind(
- LDAP *ld,
- char *dn,
- char *mechanism,
- struct berval *cred,
- LDAPControl **serverctrls,
- LDAPControl **clientctrls,
- int *msgidp)
-{
- int theErr = LDAP_SUCCESS;
- int rv;
- BerElement *ber = NULL;
-
- Debug ( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1288, "ldap_sasl_bind\n"), 0,0,0);
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if (strcasecmp(mechanism, LDAP_SASL_SIMPLE) == 0){
- /* Simple bind */
- if ( (ber = ldap_build_simple_bind_req(ld, dn, cred->bv_val, serverctrls)) == NULLBER){
- ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (theErr);
- }
- }
-
- if (strcasecmp(mechanism, LDAP_SASL_CRAM_MD5) == 0){
- if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_CRAM_MD5, cred, serverctrls)) == NULLBER) {
- ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (theErr);
- }
- }
-
- if (strcasecmp(mechanism, LDAP_SASL_EXTERNAL) == 0){
- if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_EXTERNAL, cred, serverctrls)) == NULLBER) {
- ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (theErr);
- }
- }
-
- if (strcasecmp(mechanism, LDAP_SASL_X511_PROTECTED) == 0){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_NOT_SUPPORTED);
-/*
- * if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_X511_PROTECTED, cred, serverctrls)) == NULLBER) {
- * ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
- *#ifdef _REENTRANT
- * UNLOCK_LDAP(ld);
- *#endif
- * return (theErr);
- * }
- */
- }
- if (strcasecmp(mechanism, LDAP_SASL_X511_STRONG) == 0){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_NOT_SUPPORTED);
-/*
- * if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_X511_PROTECTED, cred, serverctrls)) == NULLBER) {
- * ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
- *#ifdef _REENTRANT
- * UNLOCK_LDAP(ld);
- *#endif
- * return (theErr);
- * }
- */
- }
- if (strcasecmp(mechanism, LDAP_SASL_KERBEROS_V4) == 0){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_NOT_SUPPORTED);
-/*
- * if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_X511_PROTECTED, cred, serverctrls)) == NULLBER) {
- * ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
- *#ifdef _REENTRANT
- * UNLOCK_LDAP(ld);
- *#endif
- * return (theErr);
- * }
- */
- }
- if (strcasecmp(mechanism, LDAP_SASL_GSSAPI) == 0){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_NOT_SUPPORTED);
-/*
- * if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_X511_PROTECTED, cred, serverctrls)) == NULLBER) {
- * ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
- *#ifdef _REENTRANT
- * UNLOCK_LDAP(ld);
- *#endif
- * return (theErr);
- * }
- */
- }
- if (strcasecmp(mechanism, LDAP_SASL_SKEY) == 0){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_NOT_SUPPORTED);
-/*
- * if (( ber = ldap_build_sasl_bind_req(ld, dn, LDAP_SASL_X511_PROTECTED, cred, serverctrls)) == NULLBER) {
- * ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &theErr);
- *#ifdef _REENTRANT
- * UNLOCK_LDAP(ld);
- *#endif
- * return (theErr);
- * }
- */
- }
- if (ber == NULL){
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (LDAP_PARAM_ERROR);
- }
-
-#ifndef NO_CACHE
- if ( ld->ld_cache != NULL ) {
- ldap_flush_cache( ld );
- }
-#endif /* !NO_CACHE */
-
- /* send the message */
- rv = send_initial_request( ld, LDAP_REQ_BIND, 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 );
-}
-
-/*
- * ldap_sasl_bind_s - bind to the ldap server (and X.500).
- * dn, mechanism, cred, serverctrls, and clientctrls are supplied.
- * the message id of the request is returned in msgid
- * Returns LDAP_SUCCESS or an error code.
- */
-
-int ldap_sasl_bind_s(
- LDAP *ld,
- char *dn,
- char *mechanism,
- struct berval *cred,
- LDAPControl **serverctrls,
- LDAPControl **clientctrls,
- struct berval **servercredp)
-{
- int msgid;
- int retcode;
- LDAPMessage *res;
-
- Debug ( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1288, "ldap_sasl_bind\n"), 0,0,0);
-
- if ((retcode = ldap_sasl_bind(ld, dn, mechanism, cred, 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_sasl_bind_result(ld, res, servercredp, 1));
-}
-
-int ldap_sasl_cram_md5_bind_s(
- LDAP *ld,
- char *dn,
- struct berval *cred,
- LDAPControl **serverctrls,
- LDAPControl **clientctrls )
-{
- int res;
- struct berval *challenge = NULL;
- struct berval resp;
- unsigned char digest[16];
- char *theHDigest;
-
- if (dn == NULL){
- return (LDAP_PARAM_ERROR);
- }
-
- bzero(digest, sizeof (digest));
-
- if ((res = ldap_sasl_bind_s(ld, dn, LDAP_SASL_CRAM_MD5, NULL, serverctrls, clientctrls, &challenge))
- != LDAP_SASL_BIND_INPROGRESS){
- return (res);
- }
- if (challenge == NULL){
- return (LDAP_PARAM_ERROR);
- }
-
- Debug (LDAP_DEBUG_TRACE, "SASL challenge: %s\n", challenge->bv_val, 0, 0);
-
- hmac_md5((unsigned char *)challenge->bv_val, challenge->bv_len,
- (unsigned char *)cred->bv_val, cred->bv_len, digest);
- ber_bvfree(challenge);
- challenge = NULL;
-
- theHDigest = hexa_print(digest, 16);
- if (theHDigest == NULL){
- return (LDAP_NO_MEMORY);
- }
-
- resp.bv_len = (strlen(dn) + 32 + 1);
- if ((resp.bv_val = (char *)malloc(resp.bv_len+1)) == NULL) {
- return(LDAP_NO_MEMORY);
- }
-
- sprintf(resp.bv_val, "%s %s", dn, theHDigest);
- free(theHDigest);
-
- Debug (LDAP_DEBUG_TRACE, "SASL response: %s\n", resp.bv_val, 0, 0);
- res = ldap_sasl_bind_s(ld, dn, LDAP_SASL_CRAM_MD5, &resp, serverctrls, clientctrls, &challenge);
-
- free(resp.bv_val);
- return (res);
-}
diff --git a/usr/src/lib/libldap4/common/sbind.c b/usr/src/lib/libldap4/common/sbind.c
deleted file mode 100644
index 086459b142..0000000000
--- a/usr/src/lib/libldap4/common/sbind.c
+++ /dev/null
@@ -1,171 +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.
- *
- * sbind.c
- */
-
-#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>
-
-#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_simple_bind_req(LDAP *ld, char *dn, char *passwd, LDAPControl **serverctrls)
-{
- /*
- * The bind request looks like this:
- * BindRequest ::= SEQUENCE {
- * version INTEGER,
- * name DistinguishedName, -- who
- * authentication CHOICE {
- * simple [0] OCTET STRING -- passwd
- * }
- * }
- * all wrapped up in an LDAPMessage sequence.
- */
-
- BerElement *ber = NULL;
-
- if ( dn == NULL )
- dn = "";
- if ( passwd == NULL )
- passwd = "";
-
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
- return (NULLBER);
- }
-
- /* fill it in */
- if ( ber_printf( ber, "{it{ists}", ++ld->ld_msgid, LDAP_REQ_BIND, ld->ld_version, dn, LDAP_AUTH_SIMPLE, passwd ) == -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_simple_bind - bind to the ldap server (and X.500). The dn and
- * password of the entry to which to bind are supplied. The message id
- * of the request initiated is returned.
- *
- * Example:
- * ldap_simple_bind( ld, "cn=manager, o=university of michigan, c=us",
- * "secret" )
- */
-
-int
-ldap_simple_bind( LDAP *ld, char *dn, char *passwd )
-{
- BerElement *ber;
- int rv;
-
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 240, "ldap_simple_bind\n"), 0, 0, 0 );
-
- if ( dn == NULL )
- dn = "";
- if ( passwd == NULL )
- passwd = "";
-
- /* create a message to send */
- if ( (ber = ldap_build_simple_bind_req( ld, dn, passwd, NULL )) == NULLBER ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
-#ifndef NO_CACHE
- if ( ld->ld_cache != NULL ) {
- ldap_flush_cache( ld );
- }
-#endif /* !NO_CACHE */
-
- /* send the message */
- rv = send_initial_request( ld, LDAP_REQ_BIND, dn, ber );
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return ( rv );
-}
-
-/*
- * ldap_simple_bind - bind to the ldap server (and X.500) using simple
- * authentication. The dn and password of the entry to which to bind are
- * supplied. LDAP_SUCCESS is returned upon success, the ldap error code
- * otherwise.
- *
- * Example:
- * ldap_simple_bind_s( ld, "cn=manager, o=university of michigan, c=us",
- * "secret" )
- */
-
-int
-ldap_simple_bind_s( LDAP *ld, char *dn, char *passwd )
-{
- int msgid;
- LDAPMessage *result;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 241, "ldap_simple_bind_s\n"), 0, 0, 0 );
-
- if ( (msgid = ldap_simple_bind( ld, dn, passwd )) == -1 )
- return( ld->ld_errno );
-
- if ( ldap_result( ld, msgid, 1, (struct timeval *) 0, &result ) == -1 )
- return( ld->ld_errno ); /* ldap_result sets ld_errno */
-
- return( ldap_result2error( ld, result, 1 ) );
-}
diff --git a/usr/src/lib/libldap4/common/search.c b/usr/src/lib/libldap4/common/search.c
deleted file mode 100644
index ca0910aa6d..0000000000
--- a/usr/src/lib/libldap4/common/search.c
+++ /dev/null
@@ -1,939 +0,0 @@
-/*
- *
- * Copyright (c) 1998-2001 by Sun Microsystems, Inc.
- * All rights reserved.
- *
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Copyright (c) 1990 Regents of the University of Michigan.
- * All rights reserved.
- *
- * search.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>
-#include <ctype.h>
-#include <stdlib.h> /* free() for Solaris */
-
-#ifdef MACOS
-#include <stdlib.h>
-#include "macos.h"
-#endif /* MACOS */
-
-#if defined(DOS) || defined(_WIN32)
-#include "msdos.h"
-#endif /* DOS */
-
-#if !defined(MACOS) && !defined(DOS) && !defined(_WIN32)
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#endif
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-#ifdef NEEDPROTOS
-static char *find_right_paren(char *s);
-static char *put_complex_filter(BerElement *ber, char *str,
- unsigned int tag, int not);
-static int put_filter(BerElement *ber, char *str);
-static int put_simple_filter(BerElement *ber, char *str);
-static int put_substring_filter(BerElement *ber, char *type, char *str);
-static int put_filter_list(BerElement *ber, char *str);
-static char *star_search(char *str);
-static int hex_char2int(char c);
-static int decode_value(char *str);
-#else
-static char *find_right_paren();
-static char *put_complex_filter();
-static int put_filter();
-static int put_simple_filter();
-static int put_substring_filter();
-static int put_filter_list();
-static char *star_search();
-static int hex_char2int();
-static int decode_value();
-#endif /* NEEDPROTOS */
-
-
-BerElement *
-ldap_build_search_req(LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, LDAPControl ** serverctrls,
- struct timeval *timeoutp, int sizelimit)
-{
- BerElement *ber;
- int err;
- int theSizeLimit, theTimeLimit;
- char *theFilter;
-
- /*
- * Create the search request. It looks like this:
- * SearchRequest := [APPLICATION 3] SEQUENCE {
- * baseObject DistinguishedName,
- * scope ENUMERATED {
- * baseObject (0),
- * singleLevel (1),
- * wholeSubtree (2)
- * },
- * derefAliases ENUMERATED {
- * neverDerefaliases (0),
- * derefInSearching (1),
- * derefFindingBaseObj (2),
- * alwaysDerefAliases (3)
- * },
- * sizelimit INTEGER (0 .. 65535),
- * timelimit INTEGER (0 .. 65535),
- * attrsOnly BOOLEAN,
- * filter Filter,
- * attributes SEQUENCE OF AttributeType
- * }
- * wrapped in an ldap message.
- */
-
- if (filter == NULL || *filter == '\0') {
- ld->ld_errno = LDAP_PARAM_ERROR;
- return (NULLBER);
- }
-
- /* create a message to send */
- if ((ber = alloc_ber_with_options(ld)) == NULLBER) {
- return (NULLBER);
- }
-
- if (base == NULL) {
- base = "";
- }
-
- if (timeoutp != NULL) {
- if (timeoutp->tv_sec > 0) {
- theTimeLimit = (int)(timeoutp->tv_sec +
- (timeoutp->tv_usec / 1000000));
- } else if (timeoutp->tv_usec > 0) {
- theTimeLimit = 1; /* minimum we can express in LDAP */
- } else {
- theTimeLimit = 0; /* no limit */
- }
- } else {
- theTimeLimit = ld->ld_timelimit;
- }
-
-#ifdef CLDAP
- if (ld->ld_sb.sb_naddr > 0) {
- err = ber_printf(ber, "{ist{seeiib", ++ld->ld_msgid,
- ld->ld_cldapdn, LDAP_REQ_SEARCH, base, scope, ld->ld_deref,
- sizelimit == -1 ? ld->ld_sizelimit : sizelimit, theTimeLimit,
- attrsonly);
- } else {
-#endif /* CLDAP */
- err = ber_printf(ber, "{it{seeiib", ++ld->ld_msgid,
- LDAP_REQ_SEARCH, base, scope, ld->ld_deref,
- sizelimit == -1 ? ld->ld_sizelimit : sizelimit,
- theTimeLimit, attrsonly);
-#ifdef CLDAP
- }
-#endif /* CLDAP */
-
- if (err == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (NULLBER);
- }
-
- theFilter = filter;
- while (*theFilter == ' ') theFilter++;
- if ((*theFilter == '&') || (*theFilter == '|') || (*theFilter == '!')) {
- char *ptr = theFilter;
- theFilter = (char *)calloc(1, strlen(ptr) + 3);
- sprintf(theFilter, "(%s)", ptr);
- } else {
- theFilter = strdup(filter);
- }
- err = put_filter(ber, theFilter);
- free(theFilter);
-
- if (err == -1) {
- ld->ld_errno = LDAP_FILTER_ERROR;
- ber_free(ber, 1);
- return (NULLBER);
- }
-
- if (ber_printf(ber, "{v}}", attrs) == -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_search - initiate an ldap (and X.500) search operation. Parameters:
- *
- * ld LDAP descriptor
- * base DN of the base object
- * scope the search scope - one of LDAP_SCOPE_BASE,
- * LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE
- * filter a string containing the search filter
- * (e.g., "(|(cn=bob)(sn=bob))")
- * attrs list of attribute types to return for matches
- * attrsonly 1 => attributes only 0 => attributes and values
- *
- * Example:
- * char *attrs[] = { "mail", "title", 0 };
- * msgid = ldap_search( ld, "c=us@o=UM", LDAP_SCOPE_SUBTREE, "cn~=bob",
- * attrs, attrsonly );
- */
-int
-ldap_search(LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly)
-{
- BerElement *ber;
-
-#if defined(SUN) && defined(_REENTRANT)
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 242, "ldap_search\n"),
- 0, 0, 0);
-
- if ((ber = ldap_build_search_req(ld, base, scope, filter, attrs,
- attrsonly, NULL, NULL, -1)) == NULLBER) {
-#if defined(SUN) && defined(_REENTRANT)
- UNLOCK_LDAP(ld);
-#endif
- return (-1);
- }
-
-#ifndef NO_CACHE
- if (ld->ld_cache != NULL) {
- if (check_cache(ld, LDAP_REQ_SEARCH, ber) == 0) {
- ber_free(ber, 1);
- ld->ld_errno = LDAP_SUCCESS;
- rv = ld->ld_msgid;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (rv);
- }
- add_request_to_cache(ld, LDAP_REQ_SEARCH, ber);
- }
-#endif /* NO_CACHE */
-
- /* send the message */
- rv = send_initial_request(ld, LDAP_REQ_SEARCH, base, ber);
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (rv);
-}
-
-
-static char *
-find_right_paren(char *s)
-{
- int balance, escape;
-
- balance = 1;
- escape = 0;
- while (*s && balance) {
- if (escape == 0) {
- if (*s == '(')
- balance++;
- else if (*s == ')')
- balance--;
- }
- if (*s == '\\' && ! escape)
- escape = 1;
- else
- escape = 0;
- if (balance)
- s++;
- }
-
- return (*s ? s : NULL);
-}
-
-static char *
-put_complex_filter(BerElement *ber, char *str, unsigned int tag, int not)
-{
- char *next;
-
- /*
- * We have (x(filter)...) with str sitting on
- * the x. We have to find the paren matching
- * the one before the x and put the intervening
- * filters by calling put_filter_list().
- */
-
- /* put explicit tag */
- if (ber_printf(ber, "t{", tag) == -1)
- return (NULL);
-/*
- if (!not && ber_printf(ber, "{") == -1)
- return (NULL);
-*/
-
- str++;
- if ((next = find_right_paren(str)) == NULL)
- return (NULL);
-
- *next = '\0';
- if (put_filter_list(ber, str) == -1)
- return (NULL);
- *next++ = ')';
-
- /* flush explicit tagged thang */
- if (ber_printf(ber, "}") == -1)
- return (NULL);
-/*
- if (!not && ber_printf(ber, "}") == -1)
- return (NULL);
-*/
-
- return (next);
-}
-
-static int
-put_filter(BerElement *ber, char *str)
-{
- char *next, *tmp, *s, *d;
- int parens, balance, escape;
- int multipleparen = 0;
-
- /*
- * A Filter looks like this:
- * Filter ::= CHOICE {
- * and [0] SET OF Filter,
- * or [1] SET OF Filter,
- * not [2] Filter,
- * equalityMatch [3] AttributeValueAssertion,
- * substrings [4] SubstringFilter,
- * greaterOrEqual [5] AttributeValueAssertion,
- * lessOrEqual [6] AttributeValueAssertion,
- * present [7] AttributeType,
- * approxMatch [8] AttributeValueAssertion,
- * extensibleMatch [9] MatchingRuleAssertion
- * }
- *
- * SubstringFilter ::= SEQUENCE {
- * type AttributeType,
- * SEQUENCE OF CHOICE {
- * initial [0] IA5String,
- * any [1] IA5String,
- * final [2] IA5String
- * }
- * }
- * MatchingRuleAssertion ::= SEQUENCE {
- * matchingRule [1] MatchingRuleId OPTIONAL,
- * type [2] AttributeDescription OPTIONAL,
- * matchValue [3] AssertionValue,
- * dnAttributes [4] BOOLEAN DEFAULT FALSE
- * }
- *
- * Note: tags in a choice are always explicit
- */
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 243,
- "put_filter \"%s\"\n"), str, 0, 0);
-
- parens = 0;
- while (*str) {
- switch (*str) {
- case '(':
- str++;
- parens++;
- switch (*str) {
- case '&':
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 244, "put_filter: AND\n"), 0, 0, 0);
-
- if ((str = put_complex_filter(ber, str,
- LDAP_FILTER_AND, 0)) == NULL)
- return (-1);
-
- parens--;
- break;
-
- case '|':
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 245, "put_filter: OR\n"), 0, 0, 0);
-
- if ((str = put_complex_filter(ber, str,
- LDAP_FILTER_OR, 0)) == NULL)
- return (-1);
-
- parens--;
- break;
-
- case '!':
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 246, "put_filter: NOT\n"), 0, 0, 0);
-
- if ((str = put_complex_filter(ber, str,
- LDAP_FILTER_NOT, 1)) == NULL)
- return (-1);
-
- parens--;
- break;
-
- case '(':
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 402, "put_filter: Double Parentheses\n"),
- 0, 0, 0);
- multipleparen++;
- continue;
-
- default:
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1,
- 247, "put_filter: simple\n"), 0, 0, 0);
-
- balance = 1;
- escape = 0;
- next = str;
- while (*next && balance) {
- if (escape == 0) {
- if (*next == '(')
- balance++;
- else if (*next == ')')
- balance--;
- }
- if (*next == '\\' && ! escape)
- escape = 1;
- else
- escape = 0;
- if (balance)
- next++;
- }
- if (balance != 0)
- return (-1);
-
- *next = '\0';
- if (put_simple_filter(ber, str) == -1)
- return (-1);
- *next++ = ')';
- str = next;
- parens--;
- break;
- }
- break;
-
- case ')':
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 248,
- "put_filter: end\n"), 0, 0, 0);
- if (multipleparen) {
- multipleparen--;
- } else {
- if (ber_printf(ber, "]") == -1)
- return (-1);
- }
-
- str++;
- parens--;
- break;
-
- case ' ':
- str++;
- break;
-
- default: /* assume it's a simple type=value filter */
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 249,
- "put_filter: default\n"), 0, 0, 0);
- next = strchr(str, '\0');
- if (put_simple_filter(ber, str) == -1) {
- return (-1);
- }
- str = next;
- break;
- }
- }
-
- return (parens ? -1 : 0);
-}
-
-/*
- * Put a list of filters like this "(filter1)(filter2)..."
- */
-
-static int
-put_filter_list(BerElement *ber, char *str)
-{
- char *next;
- char save;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 250,
- "put_filter_list \"%s\"\n"), str, 0, 0);
-
- while (*str) {
- while (*str && isspace(*str))
- str++;
- if (*str == '\0')
- break;
-
- if ((next = find_right_paren(str + 1)) == NULL)
- return (-1);
- save = *++next;
-
- /* now we have "(filter)" with str pointing to it */
- *next = '\0';
- if (put_filter(ber, str) == -1)
- return (-1);
- *next = save;
-
- str = next;
- }
-
- return (0);
-}
-
-static int
-put_simple_filter(BerElement *ber, char *str)
-{
- char *s;
- char *value, savechar;
- unsigned int ftype;
- int rc;
- int len;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 251,
- "put_simple_filter \"%s\"\n"), str, 0, 0);
-
- if ((s = strchr(str, '=')) == NULL)
- return (-1);
- value = s + 1;
- *s-- = '\0';
- savechar = *s;
-
- switch (*s) {
- case '<':
- ftype = LDAP_FILTER_LE;
- *s = '\0';
- break;
- case '>':
- ftype = LDAP_FILTER_GE;
- *s = '\0';
- break;
- case '~':
- ftype = LDAP_FILTER_APPROX;
- *s = '\0';
- break;
- /* LDAP V3 : New extensible matching */
- case ':':
- rc = put_extensible_filter(ber, str, value);
- *(value -1) = '=';
- return (rc);
- default:
- if (star_search(value) == NULL) {
- ftype = LDAP_FILTER_EQUALITY;
- } else if (strcmp(value, "*") == 0) {
- ftype = LDAP_FILTER_PRESENT;
- } else {
- rc = put_substring_filter(ber, str, value);
- *(value-1) = '=';
- return (rc);
- }
- break;
- }
-
- if (*(value -1) == '=')
- return (rc);
- if (ftype == LDAP_FILTER_PRESENT) {
- rc = ber_printf(ber, "ts", ftype, str);
- } else {
- if ((len = decode_value(value)) >= 0)
- rc = ber_printf(ber, "t{so}", ftype, str, value, len);
- }
-
- *s = savechar;
- *(value-1) = '=';
- return (rc == -1 ? rc : 0);
-}
-
-static int
-put_substring_filter(BerElement *ber, char *type, char *val)
-{
- char *nextstar, gotstar = 0;
- unsigned int ftype;
- int len;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 252,
- "put_substring_filter \"%1$s=%2$s\"\n"), type, val, 0);
-
- if (ber_printf(ber, "t{s{", LDAP_FILTER_SUBSTRINGS, type) == -1)
- return (-1);
-
- while (val != NULL) {
- if ((nextstar = star_search(val)) != NULL)
- *nextstar++ = '\0';
-
- if (gotstar == 0) {
- ftype = LDAP_SUBSTRING_INITIAL;
- } else if (nextstar == NULL) {
- ftype = LDAP_SUBSTRING_FINAL;
- } else {
- ftype = LDAP_SUBSTRING_ANY;
- }
- if (*val != '\0') {
- if ((len = decode_value(val)) == -1 ||
- ber_printf(ber, "to", ftype, val, len) == -1)
- return (-1);
- }
-
- gotstar = 1;
- if (nextstar != NULL)
- *(nextstar-1) = '*';
- val = nextstar;
- }
-
- if (ber_printf(ber, "}}") == -1)
- return (-1);
-
- return (0);
-}
-
-static int
-put_extensible_filter(BerElement *ber, char *type, char *val)
-{
- char *ptr, *ptype;
- char *dn, *rule;
- int len;
-
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 252,
- "put_extensible_filter \"%1$s=%2$s\"\n"), type, val, 0);
-
- /* type is off form : attr:dn:matchingrule: or :dn:matchingrule: */
- /* type ends with ':', suppress it */
- ptr = strdup(type);
- ptype = ptr;
- while (*ptype) {
- *ptype = tolower(*ptype);
- ptype++;
- }
-
- len = strlen(ptr);
- if (len > 0 && ptr[len -1] == ':')
- ptr [len - 1] = '\0';
- else {
- return (-1);
- }
-
- ptype = ptr;
- /* Search first ':dn' */
- if ((dn = strstr(ptype, ":dn")) == NULL) {
- /* No dn */
- /* if there's a : its separating type and matching rule */
- rule = strchr(ptype, ':');
- if (rule == ptype) {
- ptype = NULL;
- }
- } else {
- if (dn == ptype) {
- ptype = NULL;
- } else {
- *dn = '\0';
- }
-
- rule = dn + 3;
- }
-
- if (rule && rule[0] == ':') {
- rule[0] = '\0';
- rule++;
- } else {
- rule = NULL;
- }
-
- if ((ptype == NULL || *ptype == '\0') && rule == NULL) {
- free(ptr);
- return (-1);
- }
-
- if (ber_printf(ber, "t{", LDAP_FILTER_EXTENSIBLE) == -1) {
- free(ptr);
- return (-1);
- }
-
- if (rule && *rule && (ber_printf(ber, "ts",
- LDAP_TAG_FEXT_RULE, rule) == -1)) {
- free(ptr);
- return (-1);
- }
-
- if (ptype && *ptype && (ber_printf(ber, "ts",
- LDAP_TAG_FEXT_TYPE, ptype) == -1)) {
- free(ptr);
- return (-1);
- }
-
- /* Code value */
- if ((len = decode_value(val)) == -1 ||
- ber_printf(ber, "to", LDAP_TAG_FEXT_VAL, val, len) == -1) {
- free(ptr);
- return (-1);
- }
-
- if (dn && (ber_printf(ber, "tb", LDAP_TAG_FEXT_DN, 1) == -1)) {
- free(ptr);
- return (-1);
- }
-
- free(ptr);
-
- if (ber_printf(ber, "}") == -1)
- return (-1);
-
- return (0);
-}
-
-int
-ldap_search_st(LDAP *ld, char *base, int scope, char *filter, char **attrs,
- int attrsonly, struct timeval *timeout, LDAPMessage **res)
-{
- int msgid;
-
- if ((msgid = ldap_search(ld, base, scope, filter, attrs, attrsonly))
- == -1)
- return (ld->ld_errno);
-
- if (ldap_result(ld, msgid, 1, timeout, res) == -1)
- return (ld->ld_errno);
-
- if (ld->ld_errno == LDAP_TIMEOUT) {
- (void) ldap_abandon(ld, msgid);
- ld->ld_errno = LDAP_TIMEOUT;
- return (ld->ld_errno);
- }
-
- return (ldap_result2error(ld, *res, 0));
-}
-
-int
-ldap_search_s(LDAP *ld, char *base, int scope, char *filter, char **attrs,
- int attrsonly, LDAPMessage **res)
-{
- int msgid;
-
- if ((msgid = ldap_search(ld, base, scope, filter, attrs, attrsonly))
- == -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, 0));
-}
-
-/* LDAPv3 API EXTENSIONS */
-int ldap_search_ext(LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, LDAPControl **serverctrls,
- LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit,
- int *msgidp)
-{
- BerElement *ber;
- int rv;
-
- if (timeoutp != NULL && timeoutp->tv_sec == 0 &&
- timeoutp->tv_usec == 0) {
- timeoutp = NULL;
- }
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- Debug(LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 242,
- "ldap_search\n"), 0, 0, 0);
-
- if ((ber = ldap_build_search_req(ld, base, scope, filter, attrs,
- attrsonly, serverctrls, timeoutp, sizelimit)) == 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_SEARCH, 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_SEARCH, ber);
- }
-#endif /* NO_CACHE */
-
- /* send the message */
- rv = send_initial_request(ld, LDAP_REQ_SEARCH, base, 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_search_ext_s(LDAP *ld, char *base, int scope, char *filter,
- char **attrs, int attrsonly, LDAPControl **serverctrls,
- LDAPControl **clientctrls, struct timeval *timeoutp, int sizelimit,
- LDAPMessage **res)
-{
- int msgid;
- int retcode = LDAP_SUCCESS;
-
- if ((retcode = ldap_search_ext(ld, base, scope, filter, attrs,
- attrsonly, serverctrls, clientctrls, timeoutp, sizelimit,
- &msgid)) != LDAP_SUCCESS)
- return (retcode);
- if (ldap_result(ld, msgid, 1, timeoutp, res) == -1)
- return (ld->ld_errno);
-
-
-#if _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, 0);
- if (retcode == LDAP_SUCCESS)
- retcode = ld->ld_errno;
-#if _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return (retcode);
-}
-
-/*
- * Search string for ascii '*' (asterisk) character.
- * RFC 1960 permits an escaped asterisk to pass through.
- * RFC 2254 adds the definition of encoded characters:
- *
- * Character ASCII value
- * ---------------------------
- * * 0x2a
- * ( 0x28
- * ) 0x29
- * \ 0x5c
- * NUL 0x00
- *
- * No distinction of escaped characters is made here.
- */
-static char *
-star_search(char *str)
-{
- for (; *str; str++) {
- switch (*str) {
- case '*':
- return (str);
- case '\\':
- if (str[1] == '\0')
- break; /* input string exahausted */
- ++str; /* Assume RFC 1960 escaped character */
- /* Check for RFC 2254 hex encoding */
- if (hex_char2int(str[0]) >= 0 &&
- hex_char2int(str[1]) >= 0) {
- str++; /* skip over RFC 2254 hex encoding */
- }
- default:
- break;
- }
- }
- return (NULL);
-}
-
-/*
- * Return integer value of hexadecimal character or (-1) if character is
- * not a hexadecimal digit [0-9A-Fa-f].
- */
-static int
-hex_char2int(char c)
-{
- if (c >= '0' && c <= '9') {
- return (c-'0');
- } else if (c >= 'A' && c <= 'F') {
- return (c-'A'+10);
- } else if (c >= 'a' && c <= 'f') {
- return (c-'a'+10);
- }
- return (-1);
-}
-
-/*
- * Modifys passed string converting escaped hexadecimal characters as
- * per RFC 2254 and un-escapes escaped characters. Returns length of
- * modified string as it may contain null characters as per RFC 2254.
- */
-static int
-decode_value(char *start)
-{
- char *read, *write;
- int hn, ln;
-
- for (read = write = start; *read; *write++ = *read++) {
- if (*read == '\\') {
- if (*++read == '\0')
- break; /* input string exahausted */
- /*
- * Assume *read is simple RFC 1960 escaped character.
- * However check for RFC 2254 hex encoding.
- */
- if ((hn = hex_char2int(read[0])) >= 0 &&
- (ln = hex_char2int(read[1])) >= 0) {
- read++;
- *read = (hn<<4)+ln;
- }
- }
- }
- *write = '\0';
- return (write-start);
-}
-
diff --git a/usr/src/lib/libldap4/common/sort.c b/usr/src/lib/libldap4/common/sort.c
deleted file mode 100644
index 881fe01510..0000000000
--- a/usr/src/lib/libldap4/common/sort.c
+++ /dev/null
@@ -1,180 +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.
- *
- * 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.
- *
- * sort.c: LDAP library entry and value sort routines
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#ifdef MACOS
-#include "macos.h"
-#else /* MACOS */
-#ifdef DOS
-#include <malloc.h>
-#include "msdos.h"
-#endif /* DOS */
-#endif /* MACOS */
-
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-struct entrything {
- char **et_vals;
- LDAPMessage *et_msg;
-};
-
-#ifndef NEEDPROTOS
-static int (*et_cmp_fn)();
-static int et_cmp();
-#else /* !NEEDPROTOS */
-static int (*et_cmp_fn)( char *a, char *b );
-#ifdef SUN
-static int et_cmp( const void *aa, const void *bb);
-#else
-static int et_cmp( void *aa, void *bb);
-#endif
-#endif /* !NEEDPROTOS */
-
-int
-ldap_sort_strcasecmp(
- char **a,
- char **b
-)
-{
- return( strcasecmp( *a, *b ) );
-}
-
-static int
-et_cmp(
-#ifdef SUN
- const void *aa,
- const void *bb
-#else
- void *aa,
- void *bb
-#endif
-)
-{
- int i, rc;
- struct entrything *a = (struct entrything *)aa;
- struct entrything *b = (struct entrything *)bb;
-
- if ( a->et_vals == NULL && b->et_vals == NULL )
- return( 0 );
- if ( a->et_vals == NULL )
- return( -1 );
- if ( b->et_vals == NULL )
- return( 1 );
-
- for ( i = 0; a->et_vals[i] && b->et_vals[i]; i++ ) {
- if ( (rc = (*et_cmp_fn)( a->et_vals[i], b->et_vals[i] ))
- != 0 ) {
- return( rc );
- }
- }
-
- if ( a->et_vals[i] == NULL && b->et_vals[i] == NULL )
- return( 0 );
- if ( a->et_vals[i] == NULL )
- return( -1 );
- return( 1 );
-}
-
-int
-ldap_sort_entries(
- LDAP *ld,
- LDAPMessage **chain,
- char *attr, /* NULL => sort by DN */
- int (*cmp)()
-)
-{
- int i;
- size_t count;
- struct entrything *et;
- LDAPMessage *e, *last;
- LDAPMessage **ep;
-
- count = ldap_count_entries( ld, *chain );
-
- if ( (et = (struct entrything *) malloc( count *
- sizeof(struct entrything) )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
-
- e = *chain;
- for ( i = 0; i < count; i++ ) {
- et[i].et_msg = e;
- if ( attr == NULL ) {
- char *dn;
-
- dn = ldap_get_dn( ld, e );
- et[i].et_vals = ldap_explode_dn( dn, 1 );
- free( dn );
- } else {
- et[i].et_vals = ldap_get_values( ld, e, attr );
- }
-
- e = e->lm_chain;
- }
- last = e;
-
- et_cmp_fn = cmp;
-#ifdef SUN
- qsort( et, count, sizeof(struct entrything), et_cmp );
-#else
- qsort( et, count, sizeof(struct entrything), (void *) et_cmp );
-#endif
-
- ep = chain;
- for ( i = 0; i < count; i++ ) {
- *ep = et[i].et_msg;
- ep = &(*ep)->lm_chain;
-
- ldap_value_free( et[i].et_vals );
- }
- *ep = last;
- free( (char *) et );
-
- return( 0 );
-}
-
-/* ARGSUSED */
-int
-ldap_sort_values(
- LDAP *ld,
- char **vals,
- int (*cmp)()
-)
-{
- size_t nel;
-
- for ( nel = 0; vals[nel] != NULL; nel++ )
- ; /* NULL */
-
- qsort( vals, nel, sizeof(char *), cmp );
-
- return( 0 );
-}
diff --git a/usr/src/lib/libldap4/common/sortctrl.c b/usr/src/lib/libldap4/common/sortctrl.c
deleted file mode 100644
index d21a01e33f..0000000000
--- a/usr/src/lib/libldap4/common/sortctrl.c
+++ /dev/null
@@ -1,426 +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 <ctype.h>
-
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-static int count_tokens(char *s);
-static int isattrdescchar(char c);
-static int read_next_token(char **s, LDAPsortkey **key);
-
-
-int ldap_create_sort_control(LDAP *ld, LDAPsortkey **sortKeyList,
- const char ctl_iscritical, LDAPControl **ctrlp)
-{
- BerElement *ber;
- int i, rc;
-
- if (NULL == ld) {
- return (LDAP_PARAM_ERROR);
- }
-
- if (sortKeyList == NULL || ctrlp == NULL) {
- ld->ld_errno = LDAP_PARAM_ERROR;
- return (LDAP_PARAM_ERROR);
- }
-
- /* create a ber package to hold the controlValue */
- if ((ber = alloc_ber_with_options(ld)) == NULLBER) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return (LDAP_NO_MEMORY);
- }
-
- /* encode the start of the sequence of sequences into the ber */
- if (ber_printf(ber, "{") == -1) {
- goto encoding_error_exit;
- }
-
- /*
- * the sort control value will be encoded as a sequence of sequences
- * which are each encoded as one of the following: {s} or {sts} or
- * {stb} or {ststb} since the orderingRule and reverseOrder flag are
- * both optional
- */
- for (i = 0; sortKeyList[i] != NULL; i++) {
-
- /* encode the attributeType into the ber */
- if (ber_printf(ber, "{s", (sortKeyList[i])->sk_attrtype)
- == -1) {
- goto encoding_error_exit;
- }
-
- /* encode the optional orderingRule into the ber */
- if ((sortKeyList[i])->sk_matchruleoid != NULL) {
- if (ber_printf(ber, "ts", LDAP_TAG_SK_MATCHRULE,
- (sortKeyList[i])->sk_matchruleoid)
- == -1) {
- goto encoding_error_exit;
- }
- }
-
- /* Encode the optional reverseOrder flag into the ber. */
- /* If the flag is false, it should be absent. */
- if ((sortKeyList[i])->sk_reverseorder) {
- if (ber_printf(ber, "tb}", LDAP_TAG_SK_REVERSE,
- (sortKeyList[i])->sk_reverseorder) == -1) {
- goto encoding_error_exit;
- }
- } else {
- if (ber_printf(ber, "}") == -1) {
- goto encoding_error_exit;
- }
- }
- }
-
- /* encode the end of the sequence of sequences into the ber */
- if (ber_printf(ber, "}") == -1) {
- goto encoding_error_exit;
- }
-
- rc = ldap_build_control(LDAP_CONTROL_SORTREQUEST, ber, 1,
- ctl_iscritical, ctrlp);
- ld->ld_errno = rc;
- return (rc);
-
-encoding_error_exit:
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_ENCODING_ERROR);
-}
-
-
-int ldap_parse_sort_control(LDAP *ld, LDAPControl **ctrlp,
- unsigned long *result, char **attribute)
-{
- BerElement *ber;
- int i, foundSortControl;
- LDAPControl *sortCtrlp;
- unsigned int len;
- char *attr;
- int tag;
-
- if ((NULL == ld) || (result == NULL) ||
- (attribute == NULL)) {
- return (LDAP_PARAM_ERROR);
- }
-
-
- /* find the sortControl in the list of controls if it exists */
- if (ctrlp == NULL) {
- ld->ld_errno = LDAP_CONTROL_NOT_FOUND;
- return (LDAP_CONTROL_NOT_FOUND);
- }
- foundSortControl = 0;
- for (i = 0; ((ctrlp[i] != NULL) && (!foundSortControl)); i++) {
- foundSortControl = !(strcmp(ctrlp[i]->ldctl_oid,
- LDAP_CONTROL_SORTRESPONSE));
- }
- if (!foundSortControl) {
- ld->ld_errno = LDAP_CONTROL_NOT_FOUND;
- return (LDAP_CONTROL_NOT_FOUND);
- } else {
- /* let local var point to the sortControl */
- sortCtrlp = ctrlp[i-1];
- }
-
- /*
- * allocate a Ber element with the contents of the sort_control's
- * struct berval
- */
- if ((ber = ber_init(&sortCtrlp->ldctl_value)) == NULL) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return (LDAP_NO_MEMORY);
- }
-
- /* decode the result from the Berelement */
- if (ber_scanf(ber, "{i", result) == LBER_ERROR) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_DECODING_ERROR);
- }
-
- /*
- * if the server returned one, decode the attribute from the Ber element
- */
- if (ber_peek_tag(ber, &len) == LDAP_TAG_SR_ATTRTYPE) {
- if (ber_scanf(ber, "ta", &tag, &attr) == LBER_ERROR) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_DECODING_ERROR);
- }
- *attribute = attr;
- } else {
- *attribute = NULL;
- }
-
- if (ber_scanf(ber, "}") == LBER_ERROR) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_DECODING_ERROR);
- }
-
- /* the ber encoding is no longer needed */
- ber_free(ber, 1);
- return (LDAP_SUCCESS);
-}
-
-
-/*
- * Routines for the manipulation of string-representations of sort control
- * keylists
- */
-static int count_tokens(char *s)
-{
- int count = 0;
- char *p = s;
- int whitespace = 1;
- /*
- * Loop along the string counting the number of times we see the
- * beginning of non-whitespace. This tells us
- * the number of tokens in the string
- */
- while (*p != '\0') {
- if (whitespace) {
- if (!isspace(*p)) {
- whitespace = 0;
- count++;
- }
- } else {
- if (isspace(*p)) {
- whitespace = 1;
- }
- }
- p++;
- }
- return (count);
-}
-
-
-/* Is this character a valid attribute description character ? */
-static int isattrdescchar(char c)
-{
- /* Alphanumeric chars are in */
- if (isalnum(c)) {
- return (1);
- }
- /* As is ';' */
- if (';' == c) {
- return (1);
- }
- /* Everything else is out */
- return (0);
-}
-
-
-static int read_next_token(char **s, LDAPsortkey **key)
-{
- char c = 0;
- char *pos = *s;
- int retval = 0;
- LDAPsortkey *new_key = NULL;
-
- char *matchrule_source = NULL;
- int matchrule_size = 0;
- char *attrdesc_source = NULL;
- int attrdesc_size = 0;
- int reverse = 0;
-
- int state = 0;
-
- while (((c = *pos++) != '\0') && (state != 4)) {
- switch (state) {
- case 0:
- /* case where we've not seen the beginning of the attr yet */
- /* If we still see whitespace, nothing to do */
- if (!isspace(c)) {
- /* Otherwise, something to look at */
- /* Is it a minus sign ? */
- if ('-' == c) {
- reverse = 1;
- } else {
- attrdesc_source = pos - 1;
- state = 1;
- }
- }
- break;
- case 1:
- /*
- * case where we've seen the beginning of the attr, but not
- * the end
- */
- /* Is this char either whitespace or a ':' ? */
- if (isspace(c) || (':' == c)) {
- attrdesc_size = (pos - attrdesc_source) - 1;
- if (':' == c) {
- state = 2;
- } else {
- state = 4;
- }
- }
- break;
- case 2:
- /*
- * case where we've seen the end of the attr and want the
- * beginning of match rule
- */
- if (!isspace(c)) {
- matchrule_source = pos - 1;
- state = 3;
- } else {
- state = 4;
- }
- break;
- case 3:
- /*
- * case where we've seen the beginning of match rule and
- * want to find the end
- */
- if (isspace(c)) {
- matchrule_size = (pos - matchrule_source) - 1;
- state = 4;
- }
- break;
- default:
- break;
- }
- }
-
- if (3 == state) {
- /*
- * means we fell off the end of the string looking for the
- * end of the marching rule
- */
- matchrule_size = (pos - matchrule_source) - 1;
- }
-
- if (1 == state) {
- /*
- * means we fell of the end of the string looking for the
- * end of the attribute
- */
- attrdesc_size = (pos - attrdesc_source) - 1;
- }
-
- if (NULL == attrdesc_source) {
- /* Didn't find anything */
- return (-1);
- }
-
- new_key = (LDAPsortkey*)malloc(sizeof (LDAPsortkey));
- if (0 == new_key) {
- return (LDAP_NO_MEMORY);
- }
-
- /* Allocate the strings */
- new_key->sk_attrtype = (char *)malloc(attrdesc_size + 1);
- if (NULL != matchrule_source) {
- new_key->sk_matchruleoid = (char *)malloc(matchrule_size + 1);
- } else {
- new_key->sk_matchruleoid = NULL;
- }
- /* Copy over the strings */
- memcpy(new_key->sk_attrtype, attrdesc_source, attrdesc_size);
- *(new_key->sk_attrtype + attrdesc_size) = '\0';
- if (NULL != matchrule_source) {
- memcpy(new_key->sk_matchruleoid, matchrule_source,
- matchrule_size);
- *(new_key->sk_matchruleoid + matchrule_size) = '\0';
- }
-
- new_key->sk_reverseorder = reverse;
-
- *s = pos - 1;
- *key = new_key;
- return (retval);
-}
-
-
-int
-ldap_create_sort_keylist(LDAPsortkey ***sortKeyList, char *string_rep)
-{
- int count = 0;
- LDAPsortkey **pointer_array = NULL;
- char *current_position = NULL;
- char *s = NULL;
- int retval = 0;
- int i = 0;
-
- /* Figure out how many there are */
- if (NULL == string_rep) {
- return (LDAP_PARAM_ERROR);
- }
- if (NULL == sortKeyList) {
- return (LDAP_PARAM_ERROR);
- }
- count = count_tokens(string_rep);
- if (0 == count) {
- *sortKeyList = NULL;
- return (LDAP_PARAM_ERROR);
- }
- /* Allocate enough memory for the pointers */
- pointer_array = (LDAPsortkey**)malloc(sizeof (LDAPsortkey*)
- * (count + 1));
- if (NULL == pointer_array) {
- return (LDAP_NO_MEMORY);
- }
- /*
- * Now walk along the string, allocating and filling in the
- * LDAPsearchkey structure
- */
- current_position = string_rep;
-
- for (i = 0; i < count; i++) {
- if (0 != (retval = read_next_token(&current_position,
- &(pointer_array[i])))) {
- pointer_array[count] = NULL;
- ldap_free_sort_keylist(pointer_array);
- *sortKeyList = NULL;
- return (retval);
- }
- }
- pointer_array[count] = NULL;
- *sortKeyList = pointer_array;
- return (LDAP_SUCCESS);
-}
-
-
-void
-ldap_free_sort_keylist(LDAPsortkey **sortKeyList)
-{
- LDAPsortkey *this_one = NULL;
- int i = 0;
-
- if (NULL == sortKeyList) {
- return;
- }
-
- /* Walk down the list freeing the LDAPsortkey structures */
- for (this_one = sortKeyList[0]; this_one;
- this_one = sortKeyList[++i]) {
- /* Free the strings, if present */
- if (NULL != this_one->sk_attrtype) {
- free(this_one->sk_attrtype);
- }
- if (NULL != this_one->sk_matchruleoid) {
- free(this_one->sk_matchruleoid);
- }
- free(this_one);
- }
- /* Free the pointer list */
- free(sortKeyList);
-}
diff --git a/usr/src/lib/libldap4/common/srchpref.c b/usr/src/lib/libldap4/common/srchpref.c
deleted file mode 100644
index c8a5f3d205..0000000000
--- a/usr/src/lib/libldap4/common/srchpref.c
+++ /dev/null
@@ -1,430 +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.
- *
- * searchpref.c: search preferences library routines for LDAP clients
- * 17 May 1994 by Gordon Good
- */
-
-#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"
-
-#ifndef NEEDPROTOS
-int next_line_tokens();
-void free_strarray();
-static void free_searchobj();
-static int read_next_searchobj();
-#else /* !NEEDPROTOS */
-int next_line_tokens( char **bufp, ssize_t *blenp, char ***toksp );
-void free_strarray( char **sap );
-static void free_searchobj( struct ldap_searchobj *so );
-static int read_next_searchobj( char **bufp, ssize_t *blenp,
- struct ldap_searchobj **sop, int soversion );
-#endif /* !NEEDPROTOS */
-
-
-static char *sobjoptions[] = {
- "internal",
- NULL
-};
-
-
-static unsigned int sobjoptvals[] = {
- LDAP_SEARCHOBJ_OPT_INTERNAL,
-};
-
-
-int
-ldap_init_searchprefs( char *file, struct ldap_searchobj **solistp )
-{
- FILE *fp;
- char *buf;
- ssize_t rlen, len;
- int rc, eof;
-
- if (( fp = fopen( file, "r" )) == NULL ) {
- return( LDAP_SEARCHPREF_ERR_FILE );
- }
-
- if ( fseek( fp, 0L, SEEK_END ) != 0 ) { /* move to end to get len */
- fclose( fp );
- return( LDAP_SEARCHPREF_ERR_FILE );
- }
-
- len = ftell( fp );
-
- if ( fseek( fp, 0L, SEEK_SET ) != 0 ) { /* back to start of file */
- fclose( fp );
- return( LDAP_SEARCHPREF_ERR_FILE );
- }
-
- if (( buf = malloc( (size_t)len )) == NULL ) {
- fclose( fp );
- return( LDAP_SEARCHPREF_ERR_MEM );
- }
-
- rlen = fread( buf, (size_t) 1, (size_t)len, fp );
- eof = feof( fp );
- fclose( fp );
-
- if ( rlen != len && !eof ) { /* error: didn't get the whole file */
- free( buf );
- return( LDAP_SEARCHPREF_ERR_FILE );
- }
-
- rc = ldap_init_searchprefs_buf( buf, rlen, solistp );
- free( buf );
-
- return( rc );
-}
-
-
-int
-ldap_init_searchprefs_buf( char *buf, ssize_t buflen,
- struct ldap_searchobj **solistp )
-{
- int rc, version;
- char **toks;
- struct ldap_searchobj *prevso, *so;
-
- *solistp = prevso = NULLSEARCHOBJ;
-
- if ( next_line_tokens( &buf, &buflen, &toks ) != 2 ||
- strcasecmp( toks[ 0 ], "version" ) != 0 ) {
- free_strarray( toks );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- version = atoi( toks[ 1 ] );
- free_strarray( toks );
- if ( version != LDAP_SEARCHPREF_VERSION &&
- version != LDAP_SEARCHPREF_VERSION_ZERO ) {
- return( LDAP_SEARCHPREF_ERR_VERSION );
- }
-
- while ( buflen > 0 && ( rc = read_next_searchobj( &buf, &buflen, &so,
- version )) == 0 && so != NULLSEARCHOBJ ) {
- if ( prevso == NULLSEARCHOBJ ) {
- *solistp = so;
- } else {
- prevso->so_next = so;
- }
- prevso = so;
- }
-
- if ( rc != 0 ) {
- ldap_free_searchprefs( *solistp );
- }
-
- return( rc );
-}
-
-
-
-void
-ldap_free_searchprefs( struct ldap_searchobj *solist )
-{
- struct ldap_searchobj *so, *nextso;
-
- if ( solist != NULL ) {
- for ( so = solist; so != NULL; so = nextso ) {
- nextso = so->so_next;
- free_searchobj( so );
- }
- }
- /* XXX XXX need to do some work here */
-}
-
-
-static void
-free_searchobj( struct ldap_searchobj *so )
-{
- if ( so != NULL ) {
- if ( so->so_objtypeprompt != NULL ) {
- free( so->so_objtypeprompt );
- }
- if ( so->so_prompt != NULL ) {
- free( so->so_prompt );
- }
- if ( so->so_filterprefix != NULL ) {
- free( so->so_filterprefix );
- }
- if ( so->so_filtertag != NULL ) {
- free( so->so_filtertag );
- }
- if ( so->so_defaultselectattr != NULL ) {
- free( so->so_defaultselectattr );
- }
- if ( so->so_defaultselecttext != NULL ) {
- free( so->so_defaultselecttext );
- }
- if ( so->so_salist != NULL ) {
- struct ldap_searchattr *sa, *nextsa;
- for ( sa = so->so_salist; sa != NULL; sa = nextsa ) {
- nextsa = sa->sa_next;
- if ( sa->sa_attrlabel != NULL ) {
- free( sa->sa_attrlabel );
- }
- if ( sa->sa_attr != NULL ) {
- free( sa->sa_attr );
- }
- if ( sa->sa_selectattr != NULL ) {
- free( sa->sa_selectattr );
- }
- if ( sa->sa_selecttext != NULL ) {
- free( sa->sa_selecttext );
- }
- free( sa );
- }
- }
- if ( so->so_smlist != NULL ) {
- struct ldap_searchmatch *sm, *nextsm;
- for ( sm = so->so_smlist; sm != NULL; sm = nextsm ) {
- nextsm = sm->sm_next;
- if ( sm->sm_matchprompt != NULL ) {
- free( sm->sm_matchprompt );
- }
- if ( sm->sm_filter != NULL ) {
- free( sm->sm_filter );
- }
- free( sm );
- }
- }
- free( so );
- }
-}
-
-
-
-struct ldap_searchobj *
-ldap_first_searchobj( struct ldap_searchobj *solist )
-{
- return( solist );
-}
-
-
-struct ldap_searchobj *
-ldap_next_searchobj( struct ldap_searchobj *solist, struct ldap_searchobj *so )
-{
- return( so == NULLSEARCHOBJ ? so : so->so_next );
-}
-
-
-
-static int
-read_next_searchobj( char **bufp, ssize_t *blenp, struct ldap_searchobj **sop,
- int soversion )
-{
- int i, j, tokcnt;
- char **toks;
- struct ldap_searchobj *so;
- struct ldap_searchattr **sa;
- struct ldap_searchmatch **sm;
-
- *sop = NULL;
-
- /*
- * Object type prompt comes first
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- return( tokcnt == 0 ? 0 : LDAP_SEARCHPREF_ERR_SYNTAX );
- }
-
- if (( so = (struct ldap_searchobj *)calloc( (size_t) 1,
- sizeof( struct ldap_searchobj ))) == NULL ) {
- free_strarray( toks );
- return( LDAP_SEARCHPREF_ERR_MEM );
- }
- so->so_objtypeprompt = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * if this is post-version zero, options come next
- */
- if ( soversion > LDAP_SEARCHPREF_VERSION_ZERO ) {
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) < 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- for ( i = 0; toks[ i ] != NULL; ++i ) {
- for ( j = 0; sobjoptions[ j ] != NULL; ++j ) {
- if ( strcasecmp( toks[ i ], sobjoptions[ j ] ) == 0 ) {
- so->so_options |= sobjoptvals[ j ];
- }
- }
- }
- free_strarray( toks );
- }
-
- /*
- * "Fewer choices" prompt is next
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- so->so_prompt = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * Filter prefix for "More Choices" searching is next
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- so->so_filterprefix = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * "Fewer Choices" filter tag comes next
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- so->so_filtertag = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * Selection (disambiguation) attribute comes next
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- so->so_defaultselectattr = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * Label for selection (disambiguation) attribute
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- so->so_defaultselecttext = toks[ 0 ];
- free( (char *)toks );
-
- /*
- * Search scope is next
- */
- if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- if ( !strcasecmp(toks[ 0 ], "subtree" )) {
- so->so_defaultscope = LDAP_SCOPE_SUBTREE;
- } else if ( !strcasecmp(toks[ 0 ], "onelevel" )) {
- so->so_defaultscope = LDAP_SCOPE_ONELEVEL;
- } else if ( !strcasecmp(toks[ 0 ], "base" )) {
- so->so_defaultscope = LDAP_SCOPE_BASE;
- } else {
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- free_strarray( toks );
-
-
- /*
- * "More Choices" search option list comes next
- */
- sa = &( so->so_salist );
- while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
- if ( tokcnt < 5 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- if (( *sa = ( struct ldap_searchattr * ) calloc( (size_t) 1,
- sizeof( struct ldap_searchattr ))) == NULL ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_MEM );
- }
- ( *sa )->sa_attrlabel = toks[ 0 ];
- ( *sa )->sa_attr = toks[ 1 ];
- ( *sa )->sa_selectattr = toks[ 3 ];
- ( *sa )->sa_selecttext = toks[ 4 ];
- /* Deal with bitmap */
- ( *sa )->sa_matchtypebitmap = 0;
- for ( i = (int) strlen( toks[ 2 ] ) - 1, j = 0; i >= 0; i--, j++ ) {
- if ( toks[ 2 ][ i ] == '1' ) {
- ( *sa )->sa_matchtypebitmap |= (1 << j);
- }
- }
- free( toks[ 2 ] );
- free( ( char * ) toks );
- sa = &(( *sa )->sa_next);
- }
- *sa = NULL;
-
- /*
- * Match types are last
- */
- sm = &( so->so_smlist );
- while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
- if ( tokcnt < 2 ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_SYNTAX );
- }
- if (( *sm = ( struct ldap_searchmatch * ) calloc( (size_t) 1,
- sizeof( struct ldap_searchmatch ))) == NULL ) {
- free_strarray( toks );
- ldap_free_searchprefs( so );
- return( LDAP_SEARCHPREF_ERR_MEM );
- }
- ( *sm )->sm_matchprompt = toks[ 0 ];
- ( *sm )->sm_filter = toks[ 1 ];
- free( ( char * ) toks );
- sm = &(( *sm )->sm_next );
- }
- *sm = NULL;
-
- *sop = so;
- return( 0 );
-}
diff --git a/usr/src/lib/libldap4/common/tmplout.c b/usr/src/lib/libldap4/common/tmplout.c
deleted file mode 100644
index a887efa705..0000000000
--- a/usr/src/lib/libldap4/common/tmplout.c
+++ /dev/null
@@ -1,1176 +0,0 @@
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * tmplout.c: display template library output routines for LDAP clients
- * 12 April 1994 by Mark C Smith
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-#include <tzfile.h>
-#include <stdlib.h>
-#ifdef MACOS
-#include "macos.h"
-#else /* MACOS */
-#ifdef DOS
-#include <malloc.h>
-#include "msdos.h"
-#else /* DOS */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#endif /* DOS */
-#endif /* MACOS */
-
-#ifdef VMS
-#include <sys/socket.h>
-#endif /* VMS */
-
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-#ifdef SUN
-/*
- * to include definition of FILTERFILE and or TEMPLATEFILE
- */
-#include "ldapconfig.h"
-#endif
-
-#ifdef NEEDPROTOS
-static int do_entry2text( LDAP *ld, char *buf, char *base, LDAPMessage *entry,
- struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
- writeptype writeproc, void *writeparm, char *eol, int rdncount,
- unsigned int opts, char *urlprefix );
-static int do_entry2text_search( LDAP *ld, char *dn, char *base,
- LDAPMessage *entry, struct ldap_disptmpl *tmpllist, char **defattrs,
- char ***defvals, writeptype writeproc, void *writeparm, char *eol,
- int rdncount, unsigned int opts, char *urlprefix );
-static int do_vals2text( LDAP *ld, char *buf, char **vals, char *label,
- int labelwidth, unsigned int syntaxid, writeptype writeproc,
- void *writeparm, char *eol, int rdncount, char *urlprefix );
-static int max_label_len( struct ldap_disptmpl *tmpl );
-static int output_label( char *buf, char *label, int width,
- writeptype writeproc, void *writeparm, char *eol, int html );
-static int output_dn( char *buf, char *dn, int width, int rdncount,
- writeptype writeproc, void *writeparm, char *eol, char *urlprefix );
-static void strcat_escaped( char *s1, char *s2 );
-static char *time2text( char *ldtimestr, int dateonly );
-static time_t gtime( struct tm *tm );
-static int searchaction( LDAP *ld, char *buf, char *base, LDAPMessage *entry,
- char *dn, struct ldap_tmplitem *tip, int labelwidth, int rdncount,
- writeptype writeproc, void *writeparm, char *eol, char *urlprefix );
-#else /* NEEDPROTOS */
-static int do_entry2text();
-static int do_entry2text_search();
-static int do_vals2text();
-static int max_label_len();
-static int output_label();
-static int output_dn();
-static void strcat_escaped();
-static char *time2text();
-static time_t gtime();
-static int searchaction();
-#endif /* NEEDPROTOS */
-
-#define DEF_LABEL_WIDTH 15
-#define SEARCH_TIMEOUT_SECS 120
-#define OCATTRNAME "objectClass"
-
-
-#define NONFATAL_LDAP_ERR( err ) ( err == LDAP_SUCCESS || \
- err == LDAP_TIMELIMIT_EXCEEDED || err == LDAP_SIZELIMIT_EXCEEDED )
-
-#define DEF_LDAP_URL_PREFIX "ldap:///"
-
-
-int
-ldap_entry2text(
- LDAP *ld,
- char *buf, /* NULL for "use internal" */
- LDAPMessage *entry,
- struct ldap_disptmpl *tmpl,
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount,
- unsigned int opts
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 253, "ldap_entry2text\n"), 0, 0, 0 );
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_entry2text( ld, buf, NULL, entry, tmpl, defattrs, defvals,
- writeproc, writeparm, eol, rdncount, opts, NULL );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_entry2text( ld, buf, NULL, entry, tmpl, defattrs, defvals,
- writeproc, writeparm, eol, rdncount, opts, NULL ));
-#endif
-}
-
-
-
-int
-ldap_entry2html(
- LDAP *ld,
- char *buf, /* NULL for "use internal" */
- LDAPMessage *entry,
- struct ldap_disptmpl *tmpl,
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount,
- unsigned int opts,
- char *base,
- char *urlprefix
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 254, "ldap_entry2html\n"), 0, 0, 0 );
-
- if ( urlprefix == NULL ) {
- urlprefix = DEF_LDAP_URL_PREFIX;
- }
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_entry2text( ld, buf, base, entry, tmpl, defattrs, defvals,
- writeproc, writeparm, eol, rdncount, opts, urlprefix );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_entry2text( ld, buf, base, entry, tmpl, defattrs, defvals,
- writeproc, writeparm, eol, rdncount, opts, urlprefix ));
-#endif
-}
-
-
-static int
-do_entry2text(
- LDAP *ld,
- char *buf, /* NULL for use-internal */
- char *base, /* used for search actions */
- LDAPMessage *entry,
- struct ldap_disptmpl *tmpl,
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount,
- unsigned int opts,
- char *urlprefix /* if non-NULL, do HTML */
-)
-{
- int i, err, html, show, labelwidth;
- int freebuf, freevals;
- char *dn, **vals;
- struct ldap_tmplitem *rowp, *colp;
-
- if (( dn = ldap_get_dn( ld, entry )) == NULL ) {
- return( ld->ld_errno );
- }
-
- if ( buf == NULL ) {
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- free( dn );
- return( ld->ld_errno );
- }
- freebuf = 1;
- } else {
- freebuf = 0;
- }
-
- html = ( urlprefix != NULL );
-
- if ( html ) {
- /*
- * add HTML intro. and title
- */
- if (!(( opts & LDAP_DISP_OPT_HTMLBODYONLY ) != 0 )) {
- sprintf( buf, "<HTML>%s<HEAD>%s<TITLE>%s%s - ", eol, eol, eol,
- ( tmpl == NULL ) ? "Entry" : tmpl->dt_name );
- (*writeproc)( writeparm, buf, strlen( buf ));
- output_dn( buf, dn, 0, rdncount, writeproc, writeparm, "", NULL );
- sprintf( buf, "%s</TITLE>%s</HEAD>%s<BODY>%s<H3>%s - ", eol, eol,
- eol, eol, ( tmpl == NULL ) ? "Entry" : tmpl->dt_name );
- (*writeproc)( writeparm, buf, strlen( buf ));
- output_dn( buf, dn, 0, rdncount, writeproc, writeparm, "", NULL );
- sprintf( buf, "</H3>%s", eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
-
- if (( opts & LDAP_DISP_OPT_NONLEAF ) != 0 &&
- ( vals = ldap_explode_dn( dn, 0 )) != NULL ) {
- char *untagged;
-
- /*
- * add "Move Up" link
- */
- sprintf( buf, "<A HREF=\"%s", urlprefix );
- for ( i = 1; vals[ i ] != NULL; ++i ) {
- if ( i > 1 ) {
- strcat_escaped( buf, ", " );
- }
- strcat_escaped( buf, vals[ i ] );
- }
- if ( vals[ 1 ] != NULL ) {
- untagged = strchr( vals[ 1 ], '=' );
- } else {
- untagged = "=The World";
- }
- sprintf( buf + strlen( buf ),
- "%s\">Move Up To <EM>%s</EM></A>%s<BR>",
- ( vals[ 1 ] == NULL ) ? "??one" : "",
- ( untagged != NULL ) ? untagged + 1 : vals[ 1 ], eol, eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
-
- /*
- * add "Browse" link
- */
- untagged = strchr( vals[ 0 ], '=' );
- sprintf( buf, "<A HREF=\"%s", urlprefix );
- strcat_escaped( buf, dn );
- sprintf( buf + strlen( buf ), "??one?(!(objectClass=dsa))\">Browse Below <EM>%s</EM></A>%s%s",
- ( untagged != NULL ) ? untagged + 1 : vals[ 0 ], eol, eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
-
- ldap_value_free( vals );
- }
-
- (*writeproc)( writeparm, "<HR>", 4 ); /* horizontal rule */
- } else {
- (*writeproc)( writeparm, "\"", 1 );
- output_dn( buf, dn, 0, rdncount, writeproc, writeparm, "", NULL );
- sprintf( buf, "\"%s", eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
-
- if ( tmpl != NULL && ( opts & LDAP_DISP_OPT_AUTOLABELWIDTH ) != 0 ) {
- labelwidth = max_label_len( tmpl ) + 3;
- } else {
- labelwidth = DEF_LABEL_WIDTH;;
- }
-
- err = LDAP_SUCCESS;
-
- if ( tmpl == NULL ) {
- BerElement *ber;
- char *attr;
-
- ber = NULL;
- for ( attr = ldap_first_attribute( ld, entry, &ber );
- NONFATAL_LDAP_ERR( err ) && attr != NULL;
- attr = ldap_next_attribute( ld, entry, ber )) {
- if (( vals = ldap_get_values( ld, entry, attr )) == NULL ) {
- freevals = 0;
- if ( defattrs != NULL ) {
- for ( i = 0; defattrs[ i ] != NULL; ++i ) {
- if ( strcasecmp( attr, defattrs[ i ] ) == 0 ) {
- break;
- }
- }
- if ( defattrs[ i ] != NULL ) {
- vals = defvals[ i ];
- }
- }
- } else {
- freevals = 1;
- }
-
- if ( islower( *attr )) { /* cosmetic -- upcase attr. name */
- *attr = toupper( *attr );
- }
-
- err = do_vals2text( ld, buf, vals, attr, labelwidth,
- LDAP_SYN_CASEIGNORESTR, writeproc, writeparm, eol,
- rdncount, urlprefix );
- if ( freevals ) {
- ldap_value_free( vals );
- }
- }
- } else {
- for ( rowp = ldap_first_tmplrow( tmpl );
- NONFATAL_LDAP_ERR( err ) && rowp != NULLTMPLITEM;
- rowp = ldap_next_tmplrow( tmpl, rowp )) {
- for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULLTMPLITEM;
- colp = ldap_next_tmplcol( tmpl, rowp, colp )) {
- vals = NULL;
- if ( colp->ti_attrname == NULL || ( vals = ldap_get_values( ld,
- entry, colp->ti_attrname )) == NULL ) {
- freevals = 0;
- if ( !LDAP_IS_TMPLITEM_OPTION_SET( colp,
- LDAP_DITEM_OPT_HIDEIFEMPTY ) && defattrs != NULL
- && colp->ti_attrname != NULL ) {
- for ( i = 0; defattrs[ i ] != NULL; ++i ) {
- if ( strcasecmp( colp->ti_attrname, defattrs[ i ] )
- == 0 ) {
- break;
- }
- }
- if ( defattrs[ i ] != NULL ) {
- vals = defvals[ i ];
- }
- }
- } else {
- freevals = 1;
- if ( LDAP_IS_TMPLITEM_OPTION_SET( colp,
- LDAP_DITEM_OPT_SORTVALUES ) && vals[ 0 ] != NULL
- && vals[ 1 ] != NULL ) {
- ldap_sort_values( ld, vals, ldap_sort_strcasecmp );
- }
- }
-
- /*
- * don't bother even calling do_vals2text() if no values
- * or boolean with value false and "hide if false" option set
- */
- show = ( vals != NULL && vals[ 0 ] != NULL );
- if ( show && LDAP_GET_SYN_TYPE( colp->ti_syntaxid )
- == LDAP_SYN_TYPE_BOOLEAN && LDAP_IS_TMPLITEM_OPTION_SET(
- colp, LDAP_DITEM_OPT_HIDEIFFALSE ) &&
- toupper( vals[ 0 ][ 0 ] ) != 'T' ) {
- show = 0;
- }
-
- if ( colp->ti_syntaxid == LDAP_SYN_SEARCHACTION ) {
- if (( opts & LDAP_DISP_OPT_DOSEARCHACTIONS ) != 0 ) {
- if ( colp->ti_attrname == NULL || ( show &&
- toupper( vals[ 0 ][ 0 ] ) == 'T' )) {
- err = searchaction( ld, buf, base, entry, dn, colp,
- labelwidth, rdncount, writeproc,
- writeparm, eol, urlprefix );
- }
- }
- show = 0;
- }
-
- if ( show ) {
- err = do_vals2text( ld, buf, vals, colp->ti_label,
- labelwidth, colp->ti_syntaxid, writeproc, writeparm,
- eol, rdncount, urlprefix );
- }
-
- if ( freevals ) {
- ldap_value_free( vals );
- }
- }
- }
- }
-
- if ( html && !(( opts & LDAP_DISP_OPT_HTMLBODYONLY ) != 0 )) {
- sprintf( buf, "</BODY>%s</HTML>%s", eol, eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
-
- free( dn );
- if ( freebuf ) {
- free( buf );
- }
-
- return( err );
-}
-
-
-int
-ldap_entry2text_search(
- LDAP *ld,
- char *dn, /* if NULL, use entry */
- char *base, /* if NULL, no search actions */
- LDAPMessage *entry, /* if NULL, use dn */
- struct ldap_disptmpl* tmpllist, /* if NULL, load default file */
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount, /* if 0, display full DN */
- unsigned int opts
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 255, "ldap_entry2text_search\n"), 0, 0, 0 );
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_entry2text_search( ld, dn, base, entry, tmpllist, defattrs,
- defvals, writeproc, writeparm, eol, rdncount, opts, NULL );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_entry2text_search( ld, dn, base, entry, tmpllist, defattrs,
- defvals, writeproc, writeparm, eol, rdncount, opts, NULL ));
-#endif
-}
-
-
-
-int
-ldap_entry2html_search(
- LDAP *ld,
- char *dn, /* if NULL, use entry */
- char *base, /* if NULL, no search actions */
- LDAPMessage *entry, /* if NULL, use dn */
- struct ldap_disptmpl* tmpllist, /* if NULL, load default file */
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount, /* if 0, display full DN */
- unsigned int opts,
- char *urlprefix
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 256, "ldap_entry2html_search\n"), 0, 0, 0 );
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_entry2text_search( ld, dn, base, entry, tmpllist, defattrs,
- defvals, writeproc, writeparm, eol, rdncount, opts, urlprefix );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_entry2text_search( ld, dn, base, entry, tmpllist, defattrs,
- defvals, writeproc, writeparm, eol, rdncount, opts, urlprefix ));
-#endif
-}
-
-
-static int
-do_entry2text_search(
- LDAP *ld,
- char *dn, /* if NULL, use entry */
- char *base, /* if NULL, no search actions */
- LDAPMessage *entry, /* if NULL, use dn */
- struct ldap_disptmpl* tmpllist, /* if NULL, load default file */
- char **defattrs,
- char ***defvals,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount, /* if 0, display full DN */
- unsigned int opts,
- char *urlprefix
-)
-{
- int err, freedn, freetmpls, html;
- char *buf, **fetchattrs, **vals;
- LDAPMessage *ldmp;
- struct ldap_disptmpl *tmpl;
- struct timeval timeout;
-
- if ( dn == NULL && entry == NULLMSG ) {
- ld->ld_errno = LDAP_PARAM_ERROR;
- return( ld->ld_errno );
- }
-
- html = ( urlprefix != NULL );
-
- timeout.tv_sec = SEARCH_TIMEOUT_SECS;
- timeout.tv_usec = 0;
-
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( ld->ld_errno );
- }
-
- freedn = freetmpls = 0;
- tmpl = NULL;
-
- if ( tmpllist == NULL ) {
- if (( err = ldap_init_templates( TEMPLATEFILE, &tmpllist )) != 0 ) {
- sprintf( buf, "%sUnable to read template file %s (error %d)%s%s",
- html ? "<!-- " : "", TEMPLATEFILE, err,
- html ? "-->" : "", eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
- freetmpls = 1;
- }
-
- if ( dn == NULL ) {
- if (( dn = ldap_get_dn( ld, entry )) == NULL ) {
- free( buf );
- if ( freetmpls ) {
- ldap_free_templates( tmpllist );
- }
- return( ld->ld_errno );
- }
- freedn = 1;
- }
-
-
- if ( tmpllist != NULL ) {
- ldmp = NULLMSG;
-
- if ( entry == NULL ) {
- char *ocattrs[2];
-
- ocattrs[0] = OCATTRNAME;
- ocattrs[1] = NULL;
-#ifdef CLDAP
- if ( LDAP_IS_CLDAP( ld ))
- err = cldap_search_s( ld, dn, LDAP_SCOPE_BASE,
- "objectClass=*", ocattrs, 0, &ldmp, NULL );
- else
-#endif /* CLDAP */
- err = ldap_search_st( ld, dn, LDAP_SCOPE_BASE,
- "objectClass=*", ocattrs, 0, &timeout, &ldmp );
-
- if ( err == LDAP_SUCCESS ) {
- entry = ldap_first_entry( ld, ldmp );
- }
- }
-
- if ( entry != NULL ) {
- vals = ldap_get_values( ld, entry, OCATTRNAME );
- tmpl = ldap_oc2template( vals, tmpllist );
- if ( vals != NULL ) {
- ldap_value_free( vals );
- }
- }
- if ( ldmp != NULL ) {
- ldap_msgfree( ldmp );
- }
- }
-
- entry = NULL;
-
- if ( tmpl == NULL ) {
- fetchattrs = NULL;
- } else {
- fetchattrs = ldap_tmplattrs( tmpl, NULL, 1, LDAP_SYN_OPT_DEFER );
- }
-
-#ifdef CLDAP
- if ( LDAP_IS_CLDAP( ld ))
- err = cldap_search_s( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
- fetchattrs, 0, &ldmp, NULL );
- else
-#endif /* CLDAP */
- err = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, "objectClass=*",
- fetchattrs, 0, &timeout, &ldmp );
-
- if ( freedn ) {
- free( dn );
- }
- if ( fetchattrs != NULL ) {
- ldap_value_free( fetchattrs );
- }
-
- if ( err != LDAP_SUCCESS ||
- ( entry = ldap_first_entry( ld, ldmp )) == NULL ) {
- if ( freetmpls ) {
- ldap_free_templates( tmpllist );
- }
- free( buf );
- return( ld->ld_errno );
- }
-
- err = do_entry2text( ld, buf, base, entry, tmpl, defattrs, defvals,
- writeproc, writeparm, eol, rdncount, opts, urlprefix );
-
- free( buf );
- if ( freetmpls ) {
- ldap_free_templates( tmpllist );
- }
- ldap_msgfree( ldmp );
- return( err );
-}
-
-
-int
-ldap_vals2text(
- LDAP *ld,
- char *buf, /* NULL for "use internal" */
- char **vals,
- char *label,
- int labelwidth, /* 0 means use default */
- unsigned int syntaxid,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 257, "ldap_vals2text\n"), 0, 0, 0 );
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_vals2text( ld, buf, vals, label, labelwidth, syntaxid,
- writeproc, writeparm, eol, rdncount, NULL );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_vals2text( ld, buf, vals, label, labelwidth, syntaxid,
- writeproc, writeparm, eol, rdncount, NULL ));
-#endif
-}
-
-
-int
-ldap_vals2html(
- LDAP *ld,
- char *buf, /* NULL for "use internal" */
- char **vals,
- char *label,
- int labelwidth, /* 0 means use default */
- unsigned int syntaxid,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount,
- char *urlprefix
-)
-{
-#if defined( SUN ) && defined( _REENTRANT )
- int rv;
-
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 258, "ldap_vals2html\n"), 0, 0, 0 );
-
- if ( urlprefix == NULL ) {
- urlprefix = DEF_LDAP_URL_PREFIX;
- }
-
-#if defined( SUN ) && defined( _REENTRANT )
- rv = do_vals2text( ld, buf, vals, label, labelwidth, syntaxid,
- writeproc, writeparm, eol, rdncount, urlprefix );
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( do_vals2text( ld, buf, vals, label, labelwidth, syntaxid,
- writeproc, writeparm, eol, rdncount, urlprefix ));
-#endif
-}
-
-
-static int
-do_vals2text(
- LDAP *ld,
- char *buf, /* NULL for "use internal" */
- char **vals,
- char *label,
- int labelwidth, /* 0 means use default */
- unsigned int syntaxid,
- writeptype writeproc,
- void *writeparm,
- char *eol,
- int rdncount,
- char *urlprefix
-)
-{
- int i, html, writeoutval, freebuf, notascii;
- char *p, *s, *outval;
-
-
- if ( vals == NULL ) {
- return( LDAP_SUCCESS );
- }
-
- html = ( urlprefix != NULL );
-
- switch( LDAP_GET_SYN_TYPE( syntaxid )) {
- case LDAP_SYN_TYPE_TEXT:
- case LDAP_SYN_TYPE_BOOLEAN:
- break; /* we only bother with these two types... */
- default:
- return( LDAP_SUCCESS );
- }
-
- if ( labelwidth == 0 || labelwidth < 0 ) {
- labelwidth = DEF_LABEL_WIDTH;
- }
-
- if ( buf == NULL ) {
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( ld->ld_errno );
- }
- freebuf = 1;
- } else {
- freebuf = 0;
- }
-
- output_label( buf, label, labelwidth, writeproc, writeparm, eol, html );
-
- for ( i = 0; vals[ i ] != NULL; ++i ) {
- for ( p = vals[ i ]; *p != '\0'; ++p ) {
- if ( !isascii( *p )) {
- break;
- }
- }
- notascii = ( *p != '\0' );
- outval = notascii ? "(unable to display non-ASCII text value)"
- : vals[ i ];
-
- writeoutval = 0; /* if non-zero, write outval after switch */
-
- switch( syntaxid ) {
- case LDAP_SYN_CASEIGNORESTR:
- ++writeoutval;
- break;
-
- case LDAP_SYN_RFC822ADDR:
- if ( html ) {
- strcpy( buf, "<DD><A HREF=\"mailto:" );
- strcat_escaped( buf, outval );
- sprintf( buf + strlen( buf ), "\">%s</A><BR>%s", outval, eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- } else {
- ++writeoutval;
- }
- break;
-
- case LDAP_SYN_DN: /* for now */
- output_dn( buf, outval, labelwidth, rdncount, writeproc,
- writeparm, eol, urlprefix );
- break;
-
- case LDAP_SYN_MULTILINESTR:
- if ( i > 0 && !html ) {
- output_label( buf, label, labelwidth, writeproc,
- writeparm, eol, html );
- }
-
- p = s = outval;
- while (( s = strchr( s, '$' )) != NULL ) {
- *s++ = '\0';
- while ( isspace( *s )) {
- ++s;
- }
- if ( html ) {
- sprintf( buf, "<DD>%s<BR>%s", p, eol );
- } else {
- sprintf( buf, "%-*s%s%s", labelwidth, " ", p, eol );
- }
- (*writeproc)( writeparm, buf, strlen( buf ));
- p = s;
- }
- outval = p;
- ++writeoutval;
- break;
-
- case LDAP_SYN_BOOLEAN:
- outval = toupper( outval[ 0 ] ) == 'T' ? "TRUE" : "FALSE";
- ++writeoutval;
- break;
-
- case LDAP_SYN_TIME:
- case LDAP_SYN_DATE:
- outval = time2text( outval, syntaxid == LDAP_SYN_DATE );
- ++writeoutval;
- break;
-
- case LDAP_SYN_LABELEDURL:
- if ( !notascii && ( p = strchr( outval, '$' )) != NULL ) {
- *p++ = '\0';
- while ( isspace( *p )) {
- ++p;
- }
- s = outval;
- } else if ( !notascii && ( s = strchr( outval, ' ' )) != NULL ) {
- *s++ = '\0';
- while ( isspace( *s )) {
- ++s;
- }
- p = outval;
- } else {
- s = "URL";
- p = outval;
- }
-
- /*
- * at this point `s' points to the label & `p' to the URL
- */
- if ( html ) {
- sprintf( buf, "<DD><A HREF=\"%s\">%s</A><BR>%s", p, s, eol );
- } else {
- sprintf( buf, "%-*s%s%s%-*s%s%s", labelwidth, " ",
- s, eol, labelwidth + 2, " ",p , eol );
- }
- (*writeproc)( writeparm, buf, strlen( buf ));
- break;
-
- default:
- sprintf( buf, " Can't display item type %ld%s",
- syntaxid, eol );
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
-
- if ( writeoutval ) {
- if ( html ) {
- sprintf( buf, "<DD>%s<BR>%s", outval, eol );
- } else {
- sprintf( buf, "%-*s%s%s", labelwidth, " ", outval, eol );
- }
- (*writeproc)( writeparm, buf, strlen( buf ));
- }
- }
-
- if ( freebuf ) {
- free( buf );
- }
-
- return( LDAP_SUCCESS );
-}
-
-
-static int
-max_label_len( struct ldap_disptmpl *tmpl )
-{
- struct ldap_tmplitem *rowp, *colp;
- int len, maxlen;
-
- maxlen = 0;
-
- for ( rowp = ldap_first_tmplrow( tmpl ); rowp != NULLTMPLITEM;
- rowp = ldap_next_tmplrow( tmpl, rowp )) {
- for ( colp = ldap_first_tmplcol( tmpl, rowp ); colp != NULLTMPLITEM;
- colp = ldap_next_tmplcol( tmpl, rowp, colp )) {
- if (( len = strlen( colp->ti_label )) > maxlen ) {
- maxlen = len;
- }
- }
- }
-
- return( maxlen );
-}
-
-
-static int
-output_label( char *buf, char *label, int width, writeptype writeproc,
- void *writeparm, char *eol, int html )
-{
- char *p;
-
- if ( html ) {
- sprintf( buf, "<DT><B>%s</B>", label );
- } else {
- sprintf( buf, " %s:", label );
- p = buf + strlen( buf );
-
- while ( p - buf < width ) {
- *p++ = ' ';
- }
-
- *p = '\0';
- strcat( buf, eol );
- }
-
- return ((*writeproc)( writeparm, buf, strlen( buf )));
-}
-
-
-static int
-output_dn( char *buf, char *dn, int width, int rdncount,
- writeptype writeproc, void *writeparm, char *eol, char *urlprefix )
-{
- char **dnrdns;
- int i;
-
- if (( dnrdns = ldap_explode_dn( dn, 1 )) == NULL ) {
- return( -1 );
- }
-
- if ( urlprefix != NULL ) {
- sprintf( buf, "<DD><A HREF=\"%s", urlprefix );
- strcat_escaped( buf, dn );
- strcat( buf, "\">" );
- } else if ( width > 0 ) {
- sprintf( buf, "%-*s", width, " " );
- } else {
- *buf = '\0';
- }
-
- for ( i = 0; dnrdns[ i ] != NULL && ( rdncount == 0 || i < rdncount );
- ++i ) {
- if ( i > 0 ) {
- strcat( buf, ", " );
- }
- strcat( buf, dnrdns[ i ] );
- }
-
- if ( urlprefix != NULL ) {
- strcat( buf, "</A><BR>" );
- }
-
- ldap_value_free( dnrdns );
-
- strcat( buf, eol );
-
- return ((*writeproc)( writeparm, buf, strlen( buf )));
-}
-
-
-
-#define HREF_CHAR_ACCEPTABLE( c ) (( c >= '-' && c <= '9' ) || \
- ( c >= '@' && c <= 'Z' ) || \
- ( c == '_' ) || \
- ( c >= 'a' && c <= 'z' ))
-
-static void
-strcat_escaped( char *s1, char *s2 )
-{
- char *p, *q;
- char *hexdig = "0123456789ABCDEF";
-
- p = s1 + strlen( s1 );
- for ( q = s2; *q != '\0'; ++q ) {
- if ( HREF_CHAR_ACCEPTABLE( *q )) {
- *p++ = *q;
- } else {
- *p++ = '%';
- *p++ = hexdig[ *q >> 4 ];
- *p++ = hexdig[ *q & 0x0F ];
- }
- }
-
- *p = '\0';
-}
-
-
-#define GET2BYTENUM( p ) (( *p - '0' ) * 10 + ( *(p+1) - '0' ))
-
-static char *
-time2text( char *ldtimestr, int dateonly )
-{
- struct tm t;
- char *p, zone, *fmterr = "badly formatted time";
- time_t gmttime;
- int century;
- static char timestr[128];
-
- memset( (char *)&t, 0, sizeof( struct tm ));
- if ( (int) strlen( ldtimestr ) < 13 ) {
- return( fmterr );
- }
-
- for ( p = ldtimestr; p - ldtimestr < 12; ++p ) {
- if ( !isdigit( *p )) {
- return( fmterr );
- }
- }
-
- p = ldtimestr;
- century = GET2BYTENUM( p ) * 100; p += 2;
- century += GET2BYTENUM( p ); p += 2;
- /* tm_year is the offset of number of years from TM_YEAR_BASE */
- t.tm_year = century - TM_YEAR_BASE;
- t.tm_mon = GET2BYTENUM( p ) - 1; p += 2;
- t.tm_mday = GET2BYTENUM( p ); p += 2;
- t.tm_hour = GET2BYTENUM( p ); p += 2;
- t.tm_min = GET2BYTENUM( p ); p += 2;
- t.tm_sec = GET2BYTENUM( p ); p += 2;
-
- /*strftime will return for e.g. Thu Aug 19 2001 */
- if (strftime(timestr, sizeof(timestr), "%a %b %d %Y", &t) == 0) {
- return( fmterr );
- }
- if (dateonly) {
- strcpy(timestr + 11, timestr + 20);
- }
- return( timestr );
-}
-
-
-
-/* gtime.c - inverse gmtime */
-
-#if !defined( MACOS ) && !defined( _WIN32 ) && !defined( DOS )
-#include <sys/time.h>
-#endif /* !MACOS */
-
-/* gtime(): the inverse of localtime().
- This routine was supplied by Mike Accetta at CMU many years ago.
- */
-
-static int dmsize[] = {
- 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-#define dysize(y) \
- (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366)))
-
-#define YEAR(y) ((y) >= 100 ? (y) : (y) + 1900)
-
-/* */
-
-static time_t gtime ( struct tm *tm )
-{
- register int i,
- sec,
- mins,
- hour,
- mday,
- mon,
- year;
- register time_t result;
-
- if ((sec = tm -> tm_sec) < 0 || sec > 59
- || (mins = tm -> tm_min) < 0 || mins > 59
- || (hour = tm -> tm_hour) < 0 || hour > 24
- || (mday = tm -> tm_mday) < 1 || mday > 31
- || (mon = tm -> tm_mon + 1) < 1 || mon > 12)
- return ((time_t) -1);
- if (hour == 24) {
- hour = 0;
- mday++;
- }
- year = YEAR (tm -> tm_year);
-
- result = 0L;
- for (i = 1970; i < year; i++)
- result += dysize (i);
- if (dysize (year) == 366 && mon >= 3)
- result++;
- while (--mon)
- result += dmsize[mon - 1];
- result += mday - 1;
- result = 24 * result + hour;
- result = 60 * result + mins;
- result = 60 * result + sec;
-
- return result;
-}
-
-static int
-searchaction( LDAP *ld, char *buf, char *base, LDAPMessage *entry, char *dn,
- struct ldap_tmplitem *tip, int labelwidth, int rdncount,
- writeptype writeproc, void *writeparm, char *eol, char *urlprefix )
-{
- int err, lderr, i, count, html;
- char **vals, **members;
- char *value, *filtpattern, *attr, *selectname;
- char *retattrs[2], filter[ 256 ];
- LDAPMessage *ldmp;
- struct timeval timeout;
-
- html = ( urlprefix != NULL );
-
- for ( i = 0; tip->ti_args != NULL && tip->ti_args[ i ] != NULL; ++i ) {
- ;
- }
- if ( i < 3 ) {
- return( LDAP_PARAM_ERROR );
- }
- attr = tip->ti_args[ 0 ];
- filtpattern = tip->ti_args[ 1 ];
- retattrs[ 0 ] = tip->ti_args[ 2 ];
- retattrs[ 1 ] = NULL;
- selectname = tip->ti_args[ 3 ];
-
- vals = NULL;
- if ( attr == NULL ) {
- value = NULL;
- } else if ( strcasecmp( attr, "-dnb" ) == 0 ) {
- return( LDAP_PARAM_ERROR );
- } else if ( strcasecmp( attr, "-dnt" ) == 0 ) {
- value = dn;
- } else if (( vals = ldap_get_values( ld, entry, attr )) != NULL ) {
- value = vals[ 0 ];
- } else {
- value = NULL;
- }
-
- ldap_build_filter( filter, sizeof( filter ), filtpattern, NULL, NULL, NULL,
- value, NULL );
-
- if ( html ) {
- /*
- * if we are generating HTML, we add an HREF link that embodies this
- * search action as an LDAP URL, instead of actually doing the search
- * now.
- */
- sprintf( buf, "<DT><A HREF=\"%s", urlprefix );
- if ( base != NULL ) {
- strcat_escaped( buf, base );
- }
- strcat( buf, "??sub?" );
- strcat_escaped( buf, filter );
- sprintf( buf + strlen( buf ), "\"><B>%s</B></A><DD><BR>%s",
- tip->ti_label, eol );
- if ((*writeproc)( writeparm, buf, strlen( buf )) < 0 ) {
- return( LDAP_LOCAL_ERROR );
- }
- return( LDAP_SUCCESS );
- }
-
- timeout.tv_sec = SEARCH_TIMEOUT_SECS;
- timeout.tv_usec = 0;
-
-#ifdef CLDAP
- if ( LDAP_IS_CLDAP( ld ))
- lderr = cldap_search_s( ld, base, LDAP_SCOPE_SUBTREE, filter, retattrs,
- 0, &ldmp, NULL );
- else
-#endif /* CLDAP */
- lderr = ldap_search_st( ld, base, LDAP_SCOPE_SUBTREE, filter, retattrs,
- 0, &timeout, &ldmp );
-
- if ( lderr == LDAP_SUCCESS || NONFATAL_LDAP_ERR( lderr )) {
- if (( count = ldap_count_entries( ld, ldmp )) > 0 ) {
- if (( members = (char **)malloc( (count + 1) * sizeof(char *)))
- == NULL ) {
- err = LDAP_NO_MEMORY;
- } else {
- for ( i = 0, entry = ldap_first_entry( ld, ldmp );
- entry != NULL;
- entry = ldap_next_entry( ld, entry ), ++i ) {
- members[ i ] = ldap_get_dn( ld, entry );
- }
- members[ i ] = NULL;
-
- ldap_sort_values( ld, members, ldap_sort_strcasecmp );
-
- err = do_vals2text( ld, NULL, members, tip->ti_label,
- html ? -1 : 0, LDAP_SYN_DN, writeproc, writeparm,
- eol, rdncount, urlprefix );
-
- ldap_value_free( members );
- }
- }
- ldap_msgfree( ldmp );
- }
-
-
- if ( vals != NULL ) {
- ldap_value_free( vals );
- }
-
- return(( err == LDAP_SUCCESS ) ? lderr : err );
-}
diff --git a/usr/src/lib/libldap4/common/ufn.c b/usr/src/lib/libldap4/common/ufn.c
deleted file mode 100644
index 37c9ed3138..0000000000
--- a/usr/src/lib/libldap4/common/ufn.c
+++ /dev/null
@@ -1,594 +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.
- *
- * ufn.c
- */
-
-#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>
-#include <stdlib.h> /* malloc(), realloc(), free() */
-
-#ifdef MACOS
-#include <stdlib.h>
-#include "macos.h"
-#else /* MACOS */
-#if defined( DOS ) || defined( _WIN32 )
-#include "msdos.h"
-#else /* DOS */
-#include <sys/time.h>
-#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 SUN
-/*
- * to include definition of FILTERFILE and or TEMPLATEFILE
- */
-#include "ldapconfig.h"
-#endif
-
-#ifdef NEEDPROTOS
-typedef int (*cancelptype)( void *cancelparm );
-#else /* NEEDPROTOS */
-typedef int (*cancelptype)();
-#endif /* NEEDPROTOS */
-
-#ifdef NEEDPROTOS
-static int ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp,
- char *prefix, char **attrs, int attrsonly, LDAPMessage **res,
- cancelptype cancelproc, void *cancelparm, char *tag1, char *tag2,
- char *tag3 );
-static LDAPMessage *ldap_msg_merge( LDAP *ld, LDAPMessage *a, LDAPMessage *b );
-static LDAPMessage *ldap_ufn_expand( LDAP *ld, cancelptype cancelproc,
- void *cancelparm, char **dns, char *filter, int scope,
- char **attrs, int aonly, int *err );
-LDAPFiltDesc *ldap_ufn_setfilter( LDAP *ld, char *fname );
-#else /* NEEDPROTOS */
-static LDAPMessage *ldap_msg_merge();
-static LDAPMessage *ldap_ufn_expand();
-LDAPFiltDesc *ldap_ufn_setfilter();
-#endif /* NEEDPROTOS */
-static LDAPMessage *ldap_msg_merge();
-static LDAPMessage *ldap_ufn_expand();
-
-/*
- * ldap_ufn_search_ctx - do user friendly searching; provide cancel feature;
- * specify ldapfilter.conf tags for each phase of search
- *
- * ld LDAP descriptor
- * ufncomp the exploded user friendly name to look for
- * ncomp number of elements in ufncomp
- * prefix where to start searching
- * attrs list of attribute types to return for matches
- * attrsonly 1 => attributes only 0 => attributes and values
- * res will contain the result of the search
- * cancelproc routine that returns non-zero if operation should be
- * cancelled. This can be NULL. If it is non-NULL, the
- * routine will be called periodically.
- * cancelparm void * that is passed to cancelproc
- * tag[123] the ldapfilter.conf tag that will be used in phases
- * 1, 2, and 3 of the search, respectively
- *
- * Example:
- * char *attrs[] = { "mail", "title", 0 };
- * char *ufncomp[] = { "howes", "umich", "us", 0 }
- * LDAPMessage *res;
- * error = ldap_ufn_search_ctx( ld, ufncomp, 3, NULL, attrs, attrsonly,
- * &res, acancelproc, along, "ufn first",
- * "ufn intermediate", "ufn last" );
- */
-
-static int
-ldap_ufn_search_ctx( LDAP *ld, char **ufncomp, int ncomp, char *prefix,
- char **attrs, int attrsonly, LDAPMessage **res, cancelptype cancelproc,
- void *cancelparm, char *tag1, char *tag2, char *tag3 )
-{
- char *dn, *ftag;
- char **dns;
- int max, i, err, scope, phase, tries;
- LDAPFiltInfo *fi;
- LDAPMessage *tmpcand;
- LDAPMessage *candidates;
- /* LDAPMessage *ldap_msg_merge(), *ldap_ufn_expand(); */
- static char *objattrs[] = { "objectClass", NULL };
-
- /*
- * look up ufn components from most to least significant.
- * there are 3 phases.
- * phase 1 search the root for orgs or countries
- * phase 2 search for orgs
- * phase 3 search for a person
- * in phases 1 and 2, we are building a list of candidate DNs,
- * below which we will search for the final component of the ufn.
- * for each component we try the filters listed in the
- * filterconfig file, first one-level (except the last compoment),
- * then subtree. if any of them produce any results, we go on to
- * the next component.
- */
-
-#if defined( SUN ) && defined( _REENTRANT )
- LOCK_LDAP(ld);
-#endif
- *res = NULL;
- candidates = NULL;
- phase = 1;
- for ( ncomp--; ncomp != -1; ncomp-- ) {
- if ( *ufncomp[ncomp] == '"' ) {
- char *quote;
-
- if ( (quote = strrchr( ufncomp[ncomp], '"' )) != NULL )
- *quote = '\0';
- (void) strcpy( ufncomp[ncomp], ufncomp[ncomp] + 1 );
- }
- if ( ncomp == 0 )
- phase = 3;
-
- switch ( phase ) {
- case 1:
- ftag = tag1;
- scope = LDAP_SCOPE_ONELEVEL;
- break;
- case 2:
- ftag = tag2;
- scope = LDAP_SCOPE_ONELEVEL;
- break;
- case 3:
- ftag = tag3;
- scope = LDAP_SCOPE_SUBTREE;
- break;
- }
-
- /*
- * construct an array of DN's to search below from the
- * list of candidates.
- */
-
- if ( candidates == NULL ) {
- if ( prefix != NULL ) {
- if ( (dns = (char **) malloc( sizeof(char *)
- * 2 )) == NULL ) {
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno = LDAP_NO_MEMORY );
- }
- dns[0] = strdup( prefix );
- dns[1] = NULL;
- } else {
- dns = NULL;
- }
- } else {
- i = 0, max = 0;
- for ( tmpcand = candidates; tmpcand != NULL &&
- tmpcand->lm_msgtype != LDAP_RES_SEARCH_RESULT;
- tmpcand = tmpcand->lm_chain )
- {
- if ( (dn = ldap_get_dn( ld, tmpcand )) == NULL )
- continue;
-
- if ( dns == NULL ) {
- if ( (dns = (char **) malloc(
- sizeof(char *) * 8 )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( LDAP_NO_MEMORY );
- }
- max = 8;
- } else if ( i >= max ) {
- if ( (dns = (char **) realloc( dns,
- sizeof(char *) * 2 * max ))
- == NULL )
- {
- ld->ld_errno = LDAP_NO_MEMORY;
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( LDAP_NO_MEMORY );
- }
- max *= 2;
- }
- dns[i++] = dn;
- dns[i] = NULL;
- }
- ldap_msgfree( candidates );
- candidates = NULL;
- }
- tries = 0;
- tryagain:
- tries++;
- for ( fi = ldap_getfirstfilter( ld->ld_filtd, ftag,
- ufncomp[ncomp] ); fi != NULL;
- fi = ldap_getnextfilter( ld->ld_filtd ) )
- {
- if ( (candidates = ldap_ufn_expand( ld, cancelproc,
- cancelparm, dns, fi->lfi_filter, scope,
- phase == 3 ? attrs : objattrs,
- phase == 3 ? attrsonly : 1, &err )) != NULL )
- {
- break;
- }
-
- if ( err == -1 || err == LDAP_USER_CANCELLED ) {
- if ( dns != NULL ) {
- ldap_value_free( dns );
- dns = NULL;
- }
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
- }
- }
-
- if ( candidates == NULL ) {
- if ( tries < 2 && phase != 3 ) {
- scope = LDAP_SCOPE_SUBTREE;
- goto tryagain;
- } else {
- if ( dns != NULL ) {
- ldap_value_free( dns );
- dns = NULL;
- }
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
- }
- }
-
- /* go on to the next component */
- if ( phase == 1 )
- phase++;
- if ( dns != NULL ) {
- ldap_value_free( dns );
- dns = NULL;
- }
- }
- *res = candidates;
-
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
-}
-
-int
-ldap_ufn_search_ct( LDAP *ld, char *ufn, char **attrs, int attrsonly,
- LDAPMessage **res, cancelptype cancelproc, void *cancelparm,
- char *tag1, char *tag2, char *tag3 )
-{
- char **ufncomp, **prefixcomp;
- char *pbuf;
- int ncomp, pcomp, i, err;
-
-#if defined( SUN ) && defined( _REENTRANT )
- LOCK_LDAP(ld);
-#endif
- /* initialize the getfilter stuff if it's not already */
- if ( ld->ld_filtd == NULL && ldap_ufn_setfilter( ld, FILTERFILE )
- == NULL ) {
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno = LDAP_LOCAL_ERROR );
- }
-
- /* call ldap_explode_dn() to break the ufn into its components */
- if ( (ufncomp = ldap_explode_dn( ufn, 0 )) == NULL ) {
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno = LDAP_LOCAL_ERROR );
- }
- for ( ncomp = 0; ufncomp[ncomp] != NULL; ncomp++ )
- ; /* NULL */
-
- /* more than two components => try it fully qualified first */
- if ( ncomp > 2 || ld->ld_ufnprefix == NULL ) {
- err = ldap_ufn_search_ctx( ld, ufncomp, ncomp, NULL, attrs,
- attrsonly, res, cancelproc, cancelparm, tag1, tag2, tag3 );
-
- if ( ldap_count_entries( ld, *res ) > 0 ) {
- ldap_value_free( ufncomp );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
- } else {
- ldap_msgfree( *res );
- *res = NULL;
- }
- }
-
- if ( ld->ld_ufnprefix == NULL ) {
- ldap_value_free( ufncomp );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
- }
-
- /* if that failed, or < 2 components, use the prefix */
- if ( (prefixcomp = ldap_explode_dn( ld->ld_ufnprefix, 0 )) == NULL ) {
- ldap_value_free( ufncomp );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno = LDAP_LOCAL_ERROR );
- }
- for ( pcomp = 0; prefixcomp[pcomp] != NULL; pcomp++ )
- ; /* NULL */
- if ( (pbuf = (char *) malloc( strlen( ld->ld_ufnprefix ) + 1 ))
- == NULL ) {
- ldap_value_free( ufncomp );
- ldap_value_free( prefixcomp );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno = LDAP_NO_MEMORY );
- }
-
- for ( i = 0; i < pcomp; i++ ) {
- int j;
-
- *pbuf = '\0';
- for ( j = i; j < pcomp; j++ ) {
- (void) strcat( pbuf, prefixcomp[j] );
- if ( j + 1 < pcomp )
- (void) strcat( pbuf, "," );
- }
- err = ldap_ufn_search_ctx( ld, ufncomp, ncomp, pbuf, attrs,
- attrsonly, res, cancelproc, cancelparm, tag1, tag2, tag3 );
-
- if ( ldap_count_entries( ld, *res ) > 0 ) {
- break;
- } else {
- ldap_msgfree( *res );
- *res = NULL;
- }
- }
-
- ldap_value_free( ufncomp );
- ldap_value_free( prefixcomp );
- free( pbuf );
-
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( err );
-}
-
-/*
- * same as ldap_ufn_search_ct, except without the ability to specify
- * ldapfilter.conf tags.
- */
-int
-ldap_ufn_search_c( LDAP *ld, char *ufn, char **attrs, int attrsonly,
- LDAPMessage **res, cancelptype cancelproc, void *cancelparm )
-{
- return( ldap_ufn_search_ct( ld, ufn, attrs, attrsonly, res, cancelproc,
- cancelparm, "ufn first", "ufn intermediate", "ufn last" ) );
-}
-
-/*
- * same as ldap_ufn_search_c without the cancel function
- */
-int
-ldap_ufn_search_s( LDAP *ld, char *ufn, char **attrs, int attrsonly,
- LDAPMessage **res )
-{
- struct timeval tv;
-
- tv.tv_sec = ld->ld_timelimit;
-
- return( ldap_ufn_search_ct( ld, ufn, attrs, attrsonly, res,
- ld->ld_timelimit ? ldap_ufn_timeout : NULL,
- ld->ld_timelimit ? (void *) &tv : NULL,
- "ufn first", "ufn intermediate", "ufn last" ) );
-}
-
-
-/*
- * ldap_msg_merge - merge two ldap search result chains. the more
- * serious of the two error result codes is kept.
- */
-
-static LDAPMessage *
-ldap_msg_merge( LDAP *ld, LDAPMessage *a, LDAPMessage *b )
-{
- LDAPMessage *end, *aprev, *aend, *bprev, *bend;
-
- if ( a == NULL )
- return( b );
-
- if ( b == NULL )
- return( a );
-
- /* find the ends of the a and b chains */
- aprev = NULL;
- for ( aend = a; aend->lm_chain != NULL; aend = aend->lm_chain )
- aprev = aend;
- bprev = NULL;
- for ( bend = b; bend->lm_chain != NULL; bend = bend->lm_chain )
- bprev = bend;
-
- /* keep result a */
- if ( ldap_result2error( ld, aend, 0 ) != LDAP_SUCCESS ) {
- /* remove result b */
- ldap_msgfree( bend );
- if ( bprev != NULL )
- bprev->lm_chain = NULL;
- else
- b = NULL;
- end = aend;
- if ( aprev != NULL )
- aprev->lm_chain = NULL;
- else
- a = NULL;
- /* keep result b */
- } else {
- /* remove result a */
- ldap_msgfree( aend );
- if ( aprev != NULL )
- aprev->lm_chain = NULL;
- else
- a = NULL;
- end = bend;
- if ( bprev != NULL )
- bprev->lm_chain = NULL;
- else
- b = NULL;
- }
-
- if ( (a == NULL && b == NULL) || (a == NULL && bprev == NULL) ||
- (b == NULL && aprev == NULL) )
- return( end );
-
- if ( a == NULL ) {
- bprev->lm_chain = end;
- return( b );
- } else if ( b == NULL ) {
- aprev->lm_chain = end;
- return( a );
- } else {
- bprev->lm_chain = end;
- aprev->lm_chain = b;
- return( a );
- }
-}
-
-static LDAPMessage *
-ldap_ufn_expand( LDAP *ld, cancelptype cancelproc, void *cancelparm,
- char **dns, char *filter, int scope, char **attrs, int aonly,
- int *err )
-{
- LDAPMessage *tmpcand, *tmpres;
- char *dn;
- int i, msgid;
- struct timeval tv;
-
- /* search for this component below the current candidates */
- tmpcand = NULL;
- i = 0;
- do {
- if ( dns != NULL )
- dn = dns[i];
- else
- dn = "";
-
- if (( msgid = ldap_search( ld, dn, scope, filter, attrs,
- aonly )) == -1 ) {
- ldap_msgfree( tmpcand );
- *err = ld->ld_errno;
- return( NULL );
- }
-
- tv.tv_sec = 0;
- tv.tv_usec = 100000; /* 1/10 of a second */
-
- do {
- *err = ldap_result( ld, msgid, 1, &tv, &tmpres );
- if ( *err == 0 && cancelproc != NULL &&
- (*cancelproc)( cancelparm ) != 0 ) {
- ldap_abandon( ld, msgid );
- *err = LDAP_USER_CANCELLED;
- ld->ld_errno = LDAP_USER_CANCELLED;
- }
- } while ( *err == 0 );
-
- if ( *err == LDAP_USER_CANCELLED || *err < 0 ||
- ( *err = ldap_result2error( ld, tmpres, 0 )) == -1 ) {
- ldap_msgfree( tmpcand );
- return( NULL );
- }
-
- tmpcand = ldap_msg_merge( ld, tmpcand, tmpres );
-
- i++;
- } while ( dns != NULL && dns[i] != NULL );
-
- if ( ldap_count_entries( ld, tmpcand ) > 0 ) {
- return( tmpcand );
- } else {
- ldap_msgfree( tmpcand );
- return( NULL );
- }
-}
-
-/*
- * ldap_ufn_setfilter - set the filter config file used in ufn searching
- */
-
-LDAPFiltDesc *
-ldap_ufn_setfilter( LDAP *ld, char *fname )
-{
-#if defined( SUN ) && defined( _REENTRANT )
- LDAPFiltDesc *rv;
-
- LOCK_LDAP(ld);
-#endif
- if ( ld->ld_filtd != NULL )
- ldap_getfilter_free( ld->ld_filtd );
-
-#if defined( SUN ) && defined( _REENTRANT )
- ld->ld_filtd = ldap_init_getfilter( fname );
- rv = ld->ld_filtd;
- UNLOCK_LDAP(ld);
- return( rv );
-#else
- return( ld->ld_filtd = ldap_init_getfilter( fname ) );
-#endif
-}
-
-void
-ldap_ufn_setprefix( LDAP *ld, char *prefix )
-{
-#if defined( SUN ) && defined( _REENTRANT )
- LOCK_LDAP(ld);
-#endif
- if ( ld->ld_ufnprefix != NULL )
- free( ld->ld_ufnprefix );
-
- ld->ld_ufnprefix = strdup( prefix );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
-}
-
-int
-ldap_ufn_timeout( void *tvparam )
-{
- struct timeval *tv;
-
- tv = (struct timeval *)tvparam;
-
- if ( tv->tv_sec != 0 ) {
- tv->tv_usec = tv->tv_sec * 1000000; /* sec => micro sec */
- tv->tv_sec = 0;
- }
- tv->tv_usec -= 100000; /* 1/10 of a second */
-
- return( tv->tv_usec <= 0 ? 1 : 0 );
-}
diff --git a/usr/src/lib/libldap4/common/unbind.c b/usr/src/lib/libldap4/common/unbind.c
deleted file mode 100644
index 7c1fe8a333..0000000000
--- a/usr/src/lib/libldap4/common/unbind.c
+++ /dev/null
@@ -1,216 +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) 1990 Regents of the University of Michigan.
- * All rights reserved.
- *
- * unbind.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 */
-#if defined( DOS ) || defined( _WIN32 )
-#include "msdos.h"
-#ifdef NCSA
-#include "externs.h"
-#endif /* NCSA */
-#else /* DOS */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#endif /* DOS */
-#endif /* MACOS */
-
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-
-int
-ldap_unbind( LDAP *ld )
-{
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 259, "ldap_unbind\n"), 0, 0, 0 );
-
- return( ldap_ld_free( ld, 1 ));
-}
-
-
-int
-ldap_ld_free( LDAP *ld, int close )
-{
- LDAPMessage *lm, *next;
- int err = LDAP_SUCCESS;
- LDAPRequest *lr, *nextlr;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ( ld->ld_sb.sb_naddr == 0 ) {
- /* free LDAP structure and outstanding requests/responses */
- for ( lr = ld->ld_requests; lr != NULL; lr = nextlr ) {
- nextlr = lr->lr_next;
- free_request( ld, lr );
- }
-
- /* free and unbind from all open connections */
- while ( ld->ld_conns != NULL ) {
- free_connection( ld, ld->ld_conns, 1, close );
- }
- } else {
- int i;
-
- for ( i = 0; i < ld->ld_sb.sb_naddr; ++i ) {
- free( ld->ld_sb.sb_addrs[ i ] );
- }
- free( ld->ld_sb.sb_addrs );
- free( ld->ld_sb.sb_fromaddr );
-#ifdef LDAP_SSL
- if (ld->ld_sb.sb_ssl){
- SSL_delete(ld->ld_sb.sb_ssl);
- }
- ld->ld_sb.sb_ssl = NULL;
- ld->ld_sb.sb_ssl_tls = 0;
-#endif
- }
-
- if (ld->ld_sb.sb_ber.ber_buf) {
- free(ld->ld_sb.sb_ber.ber_buf);
- ld->ld_sb.sb_ber.ber_buf = NULL;
- }
-
-#ifdef _REENTRANT
- LOCK_RESPONSE(ld);
-#endif
- for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
- next = lm->lm_next;
- ldap_msgfree( lm );
- }
-
-#ifdef _REENTRANT
- UNLOCK_RESPONSE(ld);
-#endif
-
-#ifndef NO_CACHE
- if ( ld->ld_cache != NULL )
- ldap_destroy_cache( ld );
-#endif /* !NO_CACHE */
- if ( ld->ld_error != NULL )
- free( ld->ld_error );
- if ( ld->ld_matched != NULL )
- free( ld->ld_matched );
- if ( ld->ld_host != NULL )
- free( ld->ld_host );
- if ( ld->ld_ufnprefix != NULL )
- free( ld->ld_ufnprefix );
- if ( ld->ld_filtd != NULL )
- ldap_getfilter_free( ld->ld_filtd );
- if ( ld->ld_abandoned != NULL )
- free( ld->ld_abandoned );
-
- if ( ld->ld_selectinfo != NULL )
- free_select_info( ld->ld_selectinfo );
-
- if ( ld->ld_defhost != NULL )
- free( ld->ld_defhost );
-
-#ifdef LDAP_SSL
- if (ld->ld_ssl_key != NULL)
- free(ld->ld_ssl_key);
-#endif
-
-#undef ld_attrbuffer
- {
- /* free thread-specific attr buffers */
- int i;
-
- for (i = 0; i < MAX_THREAD_ID; i++)
- if (ld->ld_attrbuffer[i] != NULL) {
- free(ld->ld_attrbuffer[i]);
- ld->ld_attrbuffer[i] = NULL;
- }
- }
-/* free ldapv3 stuff */
- if (ld->ld_srvctrls != NULL)
- ldap_controls_free(ld->ld_srvctrls);
- if (ld->ld_cltctrls != NULL)
- ldap_controls_free(ld->ld_cltctrls);
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-
- if (ld->ld_lockcount != 0)
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 260, "Mutex problem: ld_lockcount not equal to zero when freeing context\n"), 0, 0, 0 );
-#endif
-
- free( (char *) ld );
-
- return( err );
-}
-
-int
-ldap_unbind_s( LDAP *ld )
-{
- return( ldap_ld_free( ld, 1 ));
-}
-
-
-int
-send_unbind( LDAP *ld, Sockbuf *sb )
-{
- BerElement *ber;
-
-#if defined( SUN ) && defined( _REENTRANT )
- LOCK_LDAP(ld);
-#endif
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 261, "send_unbind\n"), 0, 0, 0 );
-
- /* create a message to send */
- if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno );
- }
-
- /* fill it in */
- if ( ber_printf( ber, "{itn}", ++ld->ld_msgid,
- LDAP_REQ_UNBIND ) == -1 ) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free( ber, 1 );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno );
- }
-
- /* send the message */
- if ( ber_flush( sb, ber, 1 ) == -1 ) {
- ld->ld_errno = LDAP_SERVER_DOWN;
- ber_free( ber, 1 );
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( ld->ld_errno );
- }
-
-#if defined( SUN ) && defined( _REENTRANT )
- UNLOCK_LDAP(ld);
-#endif
- return( LDAP_SUCCESS );
-}
diff --git a/usr/src/lib/libldap4/common/url.c b/usr/src/lib/libldap4/common/url.c
deleted file mode 100644
index dab3cfb258..0000000000
--- a/usr/src/lib/libldap4/common/url.c
+++ /dev/null
@@ -1,836 +0,0 @@
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * Copyright (c) 1996 Regents of the University of Michigan.
- * All rights reserved.
- *
- * LIBLDAP url.c -- LDAP URL related routines
- *
- * LDAP URLs look like this:
- * l d a p : / / hostport / dn [ ? attributes [ ? scope [ ? filter [ ? extensions ] ] ] ]
- *
- * where:
- * attributes is a comma separated list
- * scope is one of these three strings: base one sub (default=base)
- * filter is an string-represented filter as in RFC 1558
- * extensions is a comma separated list of extension
- * and extension is like this: [ ! ] oid/x-oid [ = value ]
- *
- * e.g., ldap://ldap.itd.umich.edu/c=US?o,description?one?o=umich
- *
- * We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
- */
-
-#ifndef lint
-static char copyright[] = "@(#) Copyright (c) 1996 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"
-#endif /* MACOS */
-
-#if defined( DOS ) || defined( _WIN32 )
-#include <stdlib.h>
-#include <malloc.h>
-#include "msdos.h"
-#endif /* DOS || _WIN32 */
-
-#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 )
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#endif /* !MACOS && !DOS && !_WIN32 */
-
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-private.h"
-#include "ldap-int.h"
-
-
-#ifdef NEEDPROTOS
-static int skip_url_prefix( char **urlp, int *enclosedp );
-static void hex_unescape( char *s );
-static int unhex( char c );
-#else /* NEEDPROTOS */
-static int skip_url_prefix();
-static void hex_unescape();
-static int unhex();
-#endif /* NEEDPROTOS */
-
-
-int
-ldap_is_ldap_url( char *url )
-{
- int enclosed;
-
- return( url != NULL && skip_url_prefix( &url, &enclosed ));
-}
-
-
-static int
-skip_url_prefix( char **urlp, int *enclosedp )
-{
-/*
- * return non-zero if this looks like a LDAP URL; zero if not
- * if non-zero returned, *urlp will be moved past "ldap://" part of URL
- */
- if ( *urlp == NULL ) {
- return( 0 );
- }
-
- /* skip leading '<' (if any) */
- if ( **urlp == '<' ) {
- *enclosedp = 1;
- ++*urlp;
- } else {
- *enclosedp = 0;
- }
-
- /* skip leading "URL:" (if any) */
- if ( strlen( *urlp ) >= LDAP_URL_URLCOLON_LEN && strncasecmp(
- *urlp, LDAP_URL_URLCOLON, LDAP_URL_URLCOLON_LEN ) == 0 ) {
- *urlp += LDAP_URL_URLCOLON_LEN;
- }
-
- /* check for missing "ldap://" prefix */
- if ( strlen( *urlp ) < LDAP_URL_PREFIX_LEN ||
- strncasecmp( *urlp, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) != 0 ) {
- return( 0 );
- }
-
- /* skip over "ldap://" prefix and return success */
- *urlp += LDAP_URL_PREFIX_LEN;
- return( 1 );
-}
-
-int ldap_url_extension_parse( char *exts, LDAPURLExt *** lueppp)
-{
- /* Pick apart the pieces of an LDAP URL Extensions */
- /* No copy of exts is made, LDAPURLExt's points to exts string */
- LDAPURLExt ** lues;
- LDAPURLExt *luep;
- int i = 0;
- char *p = exts;
- char *ptr, *ptr2;
-
- *lueppp = NULL;
-
- /* Count the number of , in extensions */
- while ( (p = strchr (p, ',')) != NULL){
- i++;
- }
- /* There are at most i+1 extensions */
- if ((lues = (LDAPURLExt **)calloc(i+2, sizeof(LDAPURLExt *))) == NULL){
- return (LDAP_URL_ERR_MEM);
- }
-
- p = exts;
- i = 0;
-
- while ( p ) {
- if ((ptr = strchr(p, ',')) != NULL)
- *ptr++ = '\0';
- else
- ptr = NULL;
-
- if ((luep = (LDAPURLExt *)calloc(1, sizeof(LDAPURLExt))) == NULL){
- ldap_free_urlexts(lues);
- return (LDAP_URL_ERR_MEM);
- }
- lues[i] = luep;
-
- if (*p == '!'){
- luep->lue_iscritical = 1;
- p++;
- }
- luep->lue_type = p;
-
- if (( ptr2 = strchr(p, '=')) != NULL) {
- *ptr2++ = '\0';
- luep->lue_value = ptr2;
- hex_unescape(ptr2);
- }
-
- i++;
- p = ptr;
- }
- *lueppp = lues;
-
- return( 0 );
-}
-
-
-int
-ldap_url_parse( char *url, LDAPURLDesc **ludpp )
-{
-/*
- * Pick apart the pieces of an LDAP URL.
- */
-
- LDAPURLDesc *ludp;
- char *attrs = NULL;
- char *p = NULL;
- char *q = NULL;
- char *x = NULL;
- int enclosed, i, nattrs, errcode;
-
- Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 262, "ldap_url_parse(%s)\n"), url, 0, 0 );
-
- *ludpp = NULL; /* pessimistic */
-
- if ( !skip_url_prefix( &url, &enclosed )) {
- return( LDAP_URL_ERR_NOTLDAP );
- }
-
- /* allocate return struct */
- if (( ludp = (LDAPURLDesc *)calloc( 1, sizeof( LDAPURLDesc )))
- == NULLLDAPURLDESC ) {
- return( LDAP_URL_ERR_MEM );
- }
-
- ludp->lud_port = LDAP_PORT;
-
- /* make working copy of the remainder of the URL */
- if (( url = strdup( url )) == NULL ) {
- ldap_free_urldesc( ludp );
- return( LDAP_URL_ERR_MEM );
- }
-
- if ( enclosed && *((p = url + strlen( url ) - 1)) == '>' ) {
- *p = '\0';
- }
-
- /* set defaults */
- /* LP By default don't set them... Then we can check if they are present or not in URL */
- ludp->lud_scope = LDAP_SCOPE_UNKNOWN;
- ludp->lud_filter = NULL;
-
-
- /* lud_string is the only malloc'd string space we use */
- ludp->lud_string = url;
-
- /* scan forward for '/' that marks end of hostport and begin. of dn */
- if (( ludp->lud_dn = strchr( url, '/' )) != NULL ) {
- *ludp->lud_dn++ = '\0';
- }
-
- /* terminate hostport; point to start of dn */
-
- if (( p = strchr( url, ':' )) != NULL ) {
- *p++ = '\0';
- ludp->lud_port = atoi( p );
- }
-
- if ( *url == '\0' ) {
- ludp->lud_host = NULL;
- } else {
- ludp->lud_host = url;
- hex_unescape( ludp->lud_host );
- }
-
- if (ludp->lud_dn != NULL){
- /* scan for '?' that marks end of dn and beginning of attributes */
- if (( attrs = strchr( ludp->lud_dn, '?' )) != NULL ) {
- /* terminate dn; point to start of attrs. */
- *attrs++ = '\0';
-
- /* scan for '?' that marks end of attrs and begin. of scope */
- if (( p = strchr( attrs, '?' )) != NULL ) {
- /*
- * terminate attrs; point to start of scope and scan for
- * '?' that marks end of scope and begin. of filter
- */
- *p++ = '\0';
-
- if (( q = strchr( p, '?' )) != NULL ) {
- /* terminate scope; point to start of filter */
- *q++ = '\0';
-
- if (( x = strchr(q, '?')) != NULL ) {
- /* terminate filter; point to start of extension */
- *x++ = '\0';
-
- if (*x != '\0'){
- /* parse extensions */
- }
- }
-
- if ( *q != '\0' ) {
- ludp->lud_filter = q;
- hex_unescape( ludp->lud_filter );
- }
- }
-
- if ( strcasecmp( p, "one" ) == 0 ) {
- ludp->lud_scope = LDAP_SCOPE_ONELEVEL;
- } else if ( strcasecmp( p, "base" ) == 0 ) {
- ludp->lud_scope = LDAP_SCOPE_BASE;
- } else if ( strcasecmp( p, "sub" ) == 0 ) {
- ludp->lud_scope = LDAP_SCOPE_SUBTREE;
- } else if ( *p != '\0' ) {
- ldap_free_urldesc( ludp );
- return( LDAP_URL_ERR_BADSCOPE );
- }
- }
- }
- if ( *ludp->lud_dn == '\0' ) {
- ludp->lud_dn = NULL;
- } else {
- hex_unescape( ludp->lud_dn );
- }
-
- /*
- * if attrs list was included, turn it into a null-terminated array
- */
- if ( attrs != NULL && *attrs != '\0' ) {
- for ( nattrs = 1, p = attrs; *p != '\0'; ++p ) {
- if ( *p == ',' ) {
- ++nattrs;
- }
- }
-
- if (( ludp->lud_attrs = (char **)calloc( nattrs + 1,
- sizeof( char * ))) == NULL ) {
- ldap_free_urldesc( ludp );
- return( LDAP_URL_ERR_MEM );
- }
-
- for ( i = 0, p = attrs; i < nattrs; ++i ) {
- ludp->lud_attrs[ i ] = p;
- if (( p = strchr( p, ',' )) != NULL ) {
- *p++ ='\0';
- }
- hex_unescape( ludp->lud_attrs[ i ] );
- }
- }
-
- if (x != NULL && *x != '\0'){
- if (errcode = ldap_url_extension_parse(x, &ludp->lud_extensions)){
- ldap_free_urldesc(ludp);
- return ( errcode );
- }
- }
- }
-
- *ludpp = ludp;
-
- return( 0 );
-}
-
-void ldap_free_urlexts( LDAPURLExt ** lues)
-{
- int i;
- for (i = 0; lues[i] != NULL; i++){
- free(lues[i]);
- }
- free(lues);
-}
-
-
-void
-ldap_free_urldesc( LDAPURLDesc *ludp )
-{
- if ( ludp != NULLLDAPURLDESC ) {
- if ( ludp->lud_string != NULL ) {
- free( ludp->lud_string );
- }
- if ( ludp->lud_attrs != NULL ) {
- free( ludp->lud_attrs );
- }
- if (ludp->lud_extensions != NULL) {
- ldap_free_urlexts(ludp->lud_extensions);
- }
- free( ludp );
- }
-}
-
-
-
-int
-ldap_url_search( LDAP *ld, char *url, int attrsonly )
-{
- int err;
- LDAPURLDesc *ludp;
- BerElement *ber;
- LDAPServer *srv = NULL;
-
-#ifdef _REENTRANT
- LOCK_LDAP(ld);
-#endif
- if ( ldap_url_parse( url, &ludp ) != 0 ) {
- ld->ld_errno = LDAP_PARAM_ERROR;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- if (( ber = ldap_build_search_req( ld, ludp->lud_dn,
- ludp->lud_scope == LDAP_SCOPE_UNKNOWN ? LDAP_SCOPE_BASE : ludp->lud_scope,
- ludp->lud_filter ? ludp->lud_filter : "(objectclass=*)",
- ludp->lud_attrs, attrsonly, NULL, NULL, -1 )) == NULLBER ) {
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( -1 );
- }
-
- err = 0;
-
- if ( ludp->lud_host != NULL || ludp->lud_port != 0 ) {
- if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer )))
- == NULL || ( srv->lsrv_host = strdup( ludp->lud_host ==
- NULL ? ld->ld_defhost : ludp->lud_host )) == NULL ) {
- if ( srv != NULL ) {
- free( srv );
- }
- ld->ld_errno = LDAP_NO_MEMORY;
- err = -1;
- } else {
- if ( ludp->lud_port == 0 ) {
- srv->lsrv_port = LDAP_PORT;
- } else {
- srv->lsrv_port = ludp->lud_port;
- }
- }
- }
-
- if ( err != 0 ) {
- ber_free( ber, 1 );
- } else {
- err = send_server_request( ld, ber, ld->ld_msgid, NULL, srv, NULL, 1 );
- }
-
- ldap_free_urldesc( ludp );
-
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
- return( err );
-}
-
-
-int
-ldap_url_search_st( LDAP *ld, char *url, int attrsonly,
- struct timeval *timeout, LDAPMessage **res )
-{
- int msgid;
- int retcode = LDAP_SUCCESS;
-
- if (( msgid = ldap_url_search( ld, url, attrsonly )) == -1 ) {
- return( ld->ld_errno );
- }
-
- if ( ldap_result( ld, msgid, 1, timeout, res ) == -1 ) {
- return( ld->ld_errno );
- }
-
- if ( ld->ld_errno == LDAP_TIMEOUT ) {
- (void) ldap_abandon( ld, msgid );
- ld->ld_errno = LDAP_TIMEOUT;
- 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, 0);
- if (retcode == LDAP_SUCCESS)
- retcode = ld->ld_errno;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
-
- return (retcode);
-}
-
-
-int
-ldap_url_search_s( LDAP *ld, char *url, int attrsonly, LDAPMessage **res )
-{
- int msgid;
- int retcode = LDAP_SUCCESS;
-
- if (( msgid = ldap_url_search( ld, url, attrsonly )) == -1 ) {
- return( ld->ld_errno );
- }
-
- 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, 0);
- if (retcode == LDAP_SUCCESS)
- retcode = ld->ld_errno;
-#ifdef _REENTRANT
- UNLOCK_LDAP(ld);
-#endif
-
- return (retcode);
-}
-
-
-static void
-hex_unescape( char *s )
-{
-/*
- * Remove URL hex escapes from s... done in place. The basic concept for
- * this routine is borrowed from the WWW library HTUnEscape() routine.
- */
- char *p;
-
- for ( p = s; *s != '\0'; ++s ) {
- if ( *s == '%' ) {
- if ( *++s != '\0' ) {
- *p = unhex( *s ) << 4;
- }
- if ( *++s != '\0' ) {
- *p++ += unhex( *s );
- }
- } else {
- *p++ = *s;
- }
- }
-
- *p = '\0';
-}
-
-
-static int
-unhex( char c )
-{
- return( c >= '0' && c <= '9' ? c - '0'
- : c >= 'A' && c <= 'F' ? c - 'A' + 10
- : c - 'a' + 10 );
-}
-
-
-/*
- * Locate the LDAP URL associated with a DNS domain name.
- *
- * The supplied DNS domain name is converted into a distinguished
- * name. The directory entry specified by that distinguished name
- * is searched for a labeledURI attribute. If successful then the
- * LDAP URL is returned. If unsuccessful then that entry's parent
- * is searched and so on until the target distinguished name is
- * reduced to only two nameparts.
- *
- * For example, if 'ny.eng.wiz.com' is the DNS domain then the
- * following entries are searched until one succeeds:
- * dc=ny,dc=eng,dc=wiz,dc=com
- * dc=eng,dc=wiz,dc=com
- * dc=wiz,dc=com
- *
- * If dns_name is NULL then the environment variable LOCALDOMAIN is used.
- * If attrs is not NULL then it is appended to the URL's attribute list.
- * If scope is not NULL then it overrides the URL's scope.
- * If filter is not NULL then it is merged with the URL's filter.
- *
- * If an error is encountered then zero is returned, otherwise a string
- * URL is returned. The caller should free the returned string if it is
- * non-zero.
- */
-
-char *
-ldap_dns_to_url(
- LDAP *ld,
- char *dns_name,
- char *attrs,
- char *scope,
- char *filter
-)
-{
- char *dn;
- char *url = 0;
- char *url2 = 0;
- LDAPURLDesc *urldesc;
- char *cp;
- char *cp2;
- size_t attrs_len = 0;
- size_t scope_len = 0;
- size_t filter_len = 0;
- int nameparts;
- int no_attrs = 0;
- int no_scope = 0;
-
- if (dns_name == 0) {
- dns_name = (char *)getenv("LOCALDOMAIN");
- }
-
- if ((ld == NULL) || ((dn = ldap_dns_to_dn(dns_name, &nameparts)) ==
- NULL))
- return (0);
-
- if ((url = ldap_dn_to_url(ld, dn, nameparts)) == NULL) {
- free(dn);
- return (0);
- }
- free(dn);
-
- /* merge filter and/or scope and/or attributes with URL */
- if (attrs || scope || filter) {
-
- if (attrs)
- attrs_len = strlen(attrs) + 2; /* for comma and NULL */
-
- if (scope)
- scope_len = strlen(scope) + 1; /* for NULL */
-
- if (filter)
- filter_len = strlen(filter) + 4;
- /* for ampersand, parentheses and NULL */
-
- if (ldap_is_ldap_url(url)) {
-
- if ((url2 = (char *)malloc(attrs_len + scope_len +
- filter_len + strlen(url) + 1)) == NULL) {
- return (0);
- }
- cp = url;
- cp2 = url2;
-
- /* copy URL scheme, hostname, port number and DN */
- while (*cp && (*cp != '?')) {
- *cp2++ = *cp++;
- }
-
- /* handle URL attributes */
-
- if (*cp == '?') { /* test first '?' */
- *cp2++ = *cp++; /* copy first '?' */
-
- if (*cp == '?') { /* test second '?' */
-
- /* insert supplied attributes */
- if (attrs) {
- while (*attrs) {
- *cp2++ = *attrs++;
- }
- } else {
- no_attrs = 1;
- }
-
- } else {
-
- /* copy URL attributes */
- while (*cp && (*cp != '?')) {
- *cp2++ = *cp++;
- }
-
- /* append supplied attributes */
- if (attrs) {
- *cp2++ = ',';
- while (*attrs) {
- *cp2++ = *attrs++;
- }
- }
- }
-
- } else {
- /* append supplied attributes */
- if (attrs) {
- *cp2++ = '?';
- while (*attrs) {
- *cp2++ = *attrs++;
- }
- } else {
- no_attrs = 1;
- }
- }
-
- /* handle URL scope */
-
- if (*cp == '?') { /* test second '?' */
- *cp2++ = *cp++; /* copy second '?' */
-
- if (*cp == '?') { /* test third '?' */
-
- /* insert supplied scope */
- if (scope) {
- while (*scope) {
- *cp2++ = *scope++;
- }
- } else {
- no_scope = 1;
- }
-
- } else {
-
- if (scope) {
- /* skip over URL scope */
- while (*cp && (*cp != '?')) {
- *cp++;
- }
- /* insert supplied scope */
- while (*scope) {
- *cp2++ = *scope++;
- }
- } else {
-
- /* copy URL scope */
- while (*cp && (*cp != '?')) {
- *cp2++ = *cp++;
- }
- }
- }
-
- } else {
- /* append supplied scope */
- if (scope) {
- if (no_attrs) {
- *cp2++ = '?';
- }
- *cp2++ = '?';
- while (*scope) {
- *cp2++ = *scope++;
- }
- } else {
- no_scope = 1;
- }
- }
-
- /* handle URL filter */
-
- if (*cp == '?') { /* test third '?' */
- *cp2++ = *cp++; /* copy third '?' */
-
- if (filter) {
-
- /* merge URL and supplied filters */
-
- *cp2++ = '(';
- *cp2++ = '&';
- /* copy URL filter */
- while (*cp) {
- *cp2++ = *cp++;
- }
- /* append supplied filter */
- while (*filter) {
- *cp2++ = *filter++;
- }
- *cp2++ = ')';
- } else {
-
- /* copy URL filter */
- while (*cp) {
- *cp2++ = *cp++;
- }
- }
-
- } else {
- /* append supplied filter */
- if (filter) {
- if (no_scope) {
- if (no_attrs) {
- *cp2++ = '?';
- }
- *cp2++ = '?';
- }
- *cp2++ = '?';
- while (*filter) {
- *cp2++ = *filter++;
- }
- }
- }
-
- *cp2++ = '\0';
- free (url);
- url = url2;
-
- } else {
- return (0); /* not an LDAP URL */
- }
- }
- return (url);
-}
-
-
-/*
- * Locate the LDAP URL associated with a distinguished name.
- *
- * The number of nameparts in the supplied distinguished name must be
- * provided. The specified directory entry is searched for a labeledURI
- * attribute. If successful then the LDAP URL is returned. If unsuccessful
- * then that entry's parent is searched and so on until the target
- * distinguished name is reduced to only two nameparts.
- *
- * For example, if 'l=ny,ou=eng,o=wiz,c=us' is the distinguished name
- * then the following entries are searched until one succeeds:
- * l=ny,ou=eng,o=wiz,c=us
- * ou=eng,o=wiz,c=us
- * o=wiz,c=us
- *
- * If an error is encountered then zero is returned, otherwise a string
- * URL is returned. The caller should free the returned string if it is
- * non-zero.
- */
-
-char *
-ldap_dn_to_url(
- LDAP *ld,
- char *dn,
- int nameparts
-)
-{
- char *next_dn = dn;
- char *url = 0;
- char *attrs[2] = {"labeledURI", 0};
- LDAPMessage *res, *e;
- char **vals;
-
- /*
- * Search for a URL in the named entry or its parent entry.
- * Continue until only 2 nameparts remain.
- */
- while (dn && (nameparts > 1) && (! url)) {
-
- /* search for the labeledURI attribute */
- if (ldap_search_s(ld, dn, LDAP_SCOPE_BASE,
- "(objectClass=*)", attrs, 0, &res) == LDAP_SUCCESS) {
-
- /* locate the first entry returned */
- if ((e = ldap_first_entry(ld, res)) != NULL) {
-
- /* locate the labeledURI attribute */
- if ((vals =
- ldap_get_values(ld, e, "labeledURI")) !=
- NULL) {
-
- /* copy the attribute value */
- if ((url = strdup((char *)vals[0])) !=
- NULL) {
- ldap_value_free(vals);
- }
- }
- }
- /* free the search results */
- ldap_msgfree(res);
- }
-
- if (! url) {
- /* advance along the DN by one namepart */
- if (next_dn = strchr(dn, ',')) {
- next_dn++;
- dn = next_dn;
- nameparts--;
- }
- }
- }
-
- return (url);
-}
diff --git a/usr/src/lib/libldap4/common/utils.c b/usr/src/lib/libldap4/common/utils.c
deleted file mode 100644
index 922e648ab7..0000000000
--- a/usr/src/lib/libldap4/common/utils.c
+++ /dev/null
@@ -1,28 +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 <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-void free_strarray( char **sap )
-{
- int i;
-
- if ( sap != NULL ) {
- for ( i = 0; sap[ i ] != NULL; ++i ) {
- free( sap[ i ] );
- }
- free( (char *)sap );
- }
-}
diff --git a/usr/src/lib/libldap4/common/version.c b/usr/src/lib/libldap4/common/version.c
deleted file mode 100644
index de22e03f02..0000000000
--- a/usr/src/lib/libldap4/common/version.c
+++ /dev/null
@@ -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[] = VERSIONNAME": libldap.a 4.0";
diff --git a/usr/src/lib/libldap4/common/vlistctrl.c b/usr/src/lib/libldap4/common/vlistctrl.c
deleted file mode 100644
index 779df251d0..0000000000
--- a/usr/src/lib/libldap4/common/vlistctrl.c
+++ /dev/null
@@ -1,124 +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"
-
-
-int ldap_create_virtuallist_control(LDAP *ld, LDAPVirtualList *ldvlistp,
- LDAPControl **ctrlp)
-{
- BerElement *ber;
- int rc;
-
- if (NULL == ld)
- return (LDAP_PARAM_ERROR);
-
- if (NULL == ctrlp || NULL == ldvlistp)
- return (LDAP_PARAM_ERROR);
-
- if ((ber = alloc_ber_with_options(ld)) == NULLBER) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return (LDAP_NO_MEMORY);
- }
-
- if (ber_printf(ber, "{ii", ldvlistp->ldvlist_before_count,
- ldvlistp->ldvlist_after_count) == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_ENCODING_ERROR);
- }
-
- if (NULL == ldvlistp->ldvlist_attrvalue) {
- if (ber_printf(ber, "t{ii}}", LDAP_TAG_VLV_BY_INDEX,
- ldvlistp->ldvlist_index,
- ldvlistp->ldvlist_size) == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_ENCODING_ERROR);
- }
- } else {
- if (ber_printf(ber, "to}", LDAP_TAG_VLV_BY_VALUE,
- ldvlistp->ldvlist_attrvalue,
- strlen(ldvlistp->ldvlist_attrvalue)) == -1) {
- ld->ld_errno = LDAP_ENCODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_ENCODING_ERROR);
- }
- }
-
- rc = ldap_build_control(LDAP_CONTROL_VLVREQUEST, ber, 1, 1, ctrlp);
- ld->ld_errno = rc;
- return (rc);
-}
-
-
-int ldap_parse_virtuallist_control(LDAP *ld, LDAPControl **ctrls,
- unsigned long *target_posp, unsigned long *list_sizep, int *errcodep)
-{
- BerElement *ber;
- int i, foundListControl;
- LDAPControl *listCtrlp;
-
- if (NULL == ld)
- return (LDAP_PARAM_ERROR);
-
- /* only ldapv3 or higher can do virtual lists. */
- if (ld->ld_version != LDAP_VERSION3) {
- ld->ld_errno = LDAP_NOT_SUPPORTED;
- return (LDAP_NOT_SUPPORTED);
- }
-
- /* find the listControl in the list of controls if it exists */
- if (ctrls == NULL) {
- ld->ld_errno = LDAP_NOT_SUPPORTED;
- return (LDAP_NOT_SUPPORTED);
- }
-
- foundListControl = 0;
- for (i = 0; ((ctrls[i] != NULL) && (!foundListControl)); i++) {
- foundListControl = !(strcmp(ctrls[i]->ldctl_oid,
- LDAP_CONTROL_VLVRESPONSE));
- }
- if (!foundListControl) {
- ld->ld_errno = LDAP_CONTROL_NOT_FOUND;
- return (LDAP_CONTROL_NOT_FOUND);
- } else {
- /* let local var point to the listControl */
- listCtrlp = ctrls[i-1];
- }
-
- /* allocate a Ber element with the contents of the list_control's */
- /* struct berval */
- if ((ber = ber_init(&listCtrlp->ldctl_value)) == NULL) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return (LDAP_NO_MEMORY);
- }
-
- /* decode the result from the Berelement */
- if (LBER_ERROR == ber_scanf(ber, "{iie}", target_posp, list_sizep,
- errcodep)) {
- ld->ld_errno = LDAP_DECODING_ERROR;
- ber_free(ber, 1);
- return (LDAP_DECODING_ERROR);
- }
-
- /* the ber encoding is no longer needed */
- ber_free(ber, 1);
-
- return (LDAP_SUCCESS);
-}