* ldap_op.c - routines to perform LDAP operations
*/
-#define DISABLE_BRIDGE
#include "portable.h"
#include <stdio.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/errno.h>
#include <ac/string.h>
+#include <ac/ctype.h>
#include <ac/time.h>
-#include <sys/types.h>
+#include <ac/unistd.h>
-#ifdef KERBEROS
-#ifdef KERBEROS_V
-#include <kerberosIV/krb.h>
-#else
-#include <krb.h>
-#endif /* KERBEROS_V */
-#endif /* KERBEROS */
+#include <ac/krb.h>
#include <lber.h>
#include <ldap.h>
#include "slurp.h"
/* Forward references */
-static int get_changetype LDAP_P(( char * ));
static struct berval **make_singlevalued_berval LDAP_P(( char *, int ));
static int op_ldap_add LDAP_P(( Ri *, Re *, char ** ));
static int op_ldap_modify LDAP_P(( Ri *, Re *, char ** ));
static int op_ldap_delete LDAP_P(( Ri *, Re *, char ** ));
static int op_ldap_modrdn LDAP_P(( Ri *, Re *, char ** ));
-static LDAPMod *alloc_ldapmod LDAP_P(());
+static LDAPMod *alloc_ldapmod LDAP_P(( void ));
static void free_ldapmod LDAP_P(( LDAPMod * ));
static void free_ldmarr LDAP_P(( LDAPMod ** ));
static int getmodtype LDAP_P(( char * ));
static int do_unbind LDAP_P(( Ri * ));
-/* External references */
-#ifndef DECL_SYS_ERRLIST
-extern char *sys_errlist[];
-#endif /* DECL_SYS_ERRLIST */
-
-extern char *ch_malloc( unsigned long );
-
static char *kattrs[] = {"kerberosName", NULL };
static struct timeval kst = {30L, 0L};
int rc = 0;
int lderr = LDAP_SUCCESS;
int retry = 2;
- char *msg;
*errmsg = NULL;
Debug( LDAP_DEBUG_ARGS, "replica %s:%d - add dn \"%s\"\n",
ri->ri_hostname, ri->ri_port, re->re_dn );
rc = ldap_add_s( ri->ri_ldp, re->re_dn, ldmarr );
- lderr = ri->ri_ldp->ld_errno;
+
+ ldap_get_option( ri->ri_ldp, LDAP_OPT_ERROR_NUMBER, &lderr);
+
} else {
*errmsg = "No modifications to do";
Debug( LDAP_DEBUG_ANY,
- "Error: op_ldap_add: no mods to do (%s)!", re->re_dn, 0, 0 );
+ "Error: op_ldap_add: no mods to do (%s)!\n", re->re_dn, 0, 0 );
}
free_ldmarr( ldmarr );
return( lderr );
int state; /* This code is a simple-minded state machine */
int nvals; /* Number of values we're modifying */
int nops; /* Number of LDAPMod structs in ldmarr */
- LDAPMod *ldm, *nldm, **ldmarr;
+ LDAPMod *ldm, **ldmarr;
int i, len;
char *type, *value;
int rc = 0;
int rc = 0;
Mi *mi;
int i;
+ int lderr = 0;
int state = 0;
int drdnflag = -1;
char *newrdn;
/* Do the modrdn */
rc = ldap_modrdn2_s( ri->ri_ldp, re->re_dn, mi->mi_val, drdnflag );
- return( ri->ri_ldp->ld_errno );
+ ldap_get_option( ri->ri_ldp, LDAP_OPT_ERROR_NUMBER, &lderr);
+ return( lderr );
}
* Allocate and initialize an ldapmod struct.
*/
static LDAPMod *
-alloc_ldapmod()
+alloc_ldapmod( void )
{
LDAPMod *ldm;
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"Error: do_unbind: ldap_unbind failed for %s:%d: %s\n",
- ldap_err2string( rc ), ri->ri_hostname, ri->ri_port );
+ ri->ri_hostname, ri->ri_port, ldap_err2string( rc ) );
}
ri->ri_ldp = NULL;
}
int *lderr
)
{
- int rc;
int ldrc;
- char msgbuf[ 1024];
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
+ int rc;
int retval = 0;
int kni, got_tgt;
char **krbnames;
char realm[ REALM_SZ ];
char name[ ANAME_SZ ];
char instance[ INST_SZ ];
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
*lderr = 0;
return( BIND_ERR_OPEN );
}
+ /*
+ * Disable string translation if enabled by default.
+ * The replication log is written in the internal format,
+ * so this would do another translation, breaking havoc.
+ */
+#if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
+ ri->ri_ldp->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
+#endif /* STR_TRANSLATION && LDAP_DEFAULT_CHARSET */
+
/*
* Set ldap library options to (1) not follow referrals, and
* (2) restart the select() system call.
*/
-#ifdef LDAP_REFERRALS
- ri->ri_ldp->ld_options &= ~LDAP_OPT_REFERRALS;
-#endif /* LDAP_REFERRALS */
- ri->ri_ldp->ld_options |= LDAP_OPT_RESTART;
+ ldap_set_option(ri->ri_ldp, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
+ ldap_set_option(ri->ri_ldp, LDAP_OPT_RESTART, LDAP_OPT_ON);
switch ( ri->ri_bind_method ) {
case AUTH_KERBEROS:
-#ifndef KERBEROS
+#ifndef HAVE_KERBEROS
Debug( LDAP_DEBUG_ANY,
"Error: Kerberos bind for %s:%d, but not compiled w/kerberos\n",
ri->ri_hostname, ri->ri_port, 0 );
return( BIND_ERR_KERBEROS_FAILED );
-#else /* KERBEROS */
+#else /* HAVE_KERBEROS */
/*
* Bind using kerberos.
* If "bindprincipal" was given in the config file, then attempt
}
return( retval);
break;
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
case AUTH_SIMPLE:
/*
* Bind with a plaintext password.
*/
static void
dump_ldm_array(
-LDAPMod **ldmarr )
+ LDAPMod **ldmarr
+)
{
int i, j;
LDAPMod *ldm;
for ( i = 0; ldmarr[ i ] != NULL; i++ ) {
ldm = ldmarr[ i ];
Debug( LDAP_DEBUG_TRACE,
- "Trace (%d): *** ldmarr[ %d ] contents:\n",
- getpid(), i, 0 );
+ "Trace (%ld): *** ldmarr[ %d ] contents:\n",
+ (long) getpid(), i, 0 );
Debug( LDAP_DEBUG_TRACE,
- "Trace (%d): *** ldm->mod_op: %d\n",
- getpid(), ldm->mod_op, 0 );
+ "Trace (%ld): *** ldm->mod_op: %d\n",
+ (long) getpid(), ldm->mod_op, 0 );
Debug( LDAP_DEBUG_TRACE,
- "Trace (%d): *** ldm->mod_type: %s\n",
- getpid(), ldm->mod_type, 0 );
+ "Trace (%ld): *** ldm->mod_type: %s\n",
+ (long) getpid(), ldm->mod_type, 0 );
if ( ldm->mod_bvalues != NULL ) {
for ( j = 0; ( b = ldm->mod_bvalues[ j ] ) != NULL; j++ ) {
msgbuf = ch_malloc( b->bv_len + 512 );
- sprintf( msgbuf, "***** bv[ %d ] len = %d, val = <%s>",
+ sprintf( msgbuf, "***** bv[ %d ] len = %ld, val = <%s>",
j, b->bv_len, b->bv_val );
Debug( LDAP_DEBUG_TRACE,
- "Trace (%d):%s\n", getpid(), msgbuf, 0 );
+ "Trace (%ld):%s\n", (long) getpid(), msgbuf, 0 );
free( msgbuf );
}
}
*/
static void
upcase(
-char *s )
+ char *s
+)
{
char *p;
for ( p = s; ( p != NULL ) && ( *p != '\0' ); p++ ) {
- if ( islower( *p )) {
- *p = toupper( *p );
- }
+ *p = TOUPPER( (unsigned char) *p );
}
}