]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/ldap_op.c
Kill lber_debug
[openldap] / servers / slurpd / ldap_op.c
index 29dddb55baee4e83bed7f08d2b532372c382c363..8dfc7e157baa18d1f3cc02183778f1e6296ebd4d 100644 (file)
 
 #include <stdio.h>
 
+#include <ac/stdlib.h>
+
 #include <ac/errno.h>
 #include <ac/string.h>
 #include <ac/ctype.h>
 #include <ac/time.h>
+#include <ac/unistd.h>
 
 #include <ac/krb.h>
 
@@ -36,7 +39,7 @@ 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 * ));
@@ -47,9 +50,6 @@ static int do_bind LDAP_P(( Ri *, int * ));
 static int do_unbind LDAP_P(( Ri * ));
 
 
-/* External references */
-extern char *ch_malloc LDAP_P(( unsigned long ));
-
 static char *kattrs[] = {"kerberosName", NULL };
 static struct timeval kst = {30L, 0L};
 
@@ -199,7 +199,7 @@ op_ldap_add(
     } 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 ); 
@@ -350,9 +350,12 @@ op_ldap_delete(
 /*
  * Perform an ldap modrdn operation.
  */
-#define        GOT_NEWRDN              1
-#define        GOT_DRDNFLAGSTR         2
-#define        GOT_ALLNEWRDNFLAGS      ( GOT_NEWRDN | GOT_DRDNFLAGSTR )
+#define        GOT_NEWRDN              0x1
+#define        GOT_DELOLDRDN   0x2
+#define GOT_NEWSUP             0x4
+
+#define GOT_MODDN_REQ  (GOT_NEWRDN|GOT_DELOLDRDN)
+#define        GOT_ALL_MODDN(f)        (((f) & GOT_MODDN_REQ) == GOT_MODDN_REQ)
 static int
 op_ldap_modrdn(
     Ri         *ri,
@@ -367,6 +370,7 @@ op_ldap_modrdn(
     int                state = 0;
     int                drdnflag = -1;
     char       *newrdn;
+       char    *newsup = NULL;
 
     if ( re->re_mods == NULL ) {
        *errmsg = "No arguments given";
@@ -380,10 +384,27 @@ op_ldap_modrdn(
      */
     for ( mi = re->re_mods, i = 0; mi[ i ].mi_type != NULL; i++ ) {
        if ( !strcmp( mi[ i ].mi_type, T_NEWRDNSTR )) {
+               if( state & GOT_NEWRDN ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: op_ldap_modrdn: multiple newrdn arg \"%s\"\n",
+                       mi[ i ].mi_val, 0, 0 );
+               *errmsg = "Multiple newrdn argument";
+               return -1;
+               }
+
            newrdn = mi[ i ].mi_val;
            state |= GOT_NEWRDN;
-       } else if ( !strcmp( mi[ i ].mi_type, T_DRDNFLAGSTR )) {
-           state |= GOT_DRDNFLAGSTR;
+
+       } else if ( !strcmp( mi[ i ].mi_type, T_DELOLDRDNSTR )) {
+               if( state & GOT_DELOLDRDN ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: op_ldap_modrdn: multiple deleteoldrdn arg \"%s\"\n",
+                       mi[ i ].mi_val, 0, 0 );
+               *errmsg = "Multiple newrdn argument";
+               return -1;
+               }
+
+           state |= GOT_DELOLDRDN;
            if ( !strcmp( mi[ i ].mi_val, "0" )) {
                drdnflag = 0;
            } else if ( !strcmp( mi[ i ].mi_val, "1" )) {
@@ -395,6 +416,19 @@ op_ldap_modrdn(
                *errmsg = "Incorrect argument to deleteoldrdn";
                return -1;
            }
+
+       } else if ( !strcmp( mi[ i ].mi_type, T_NEWSUPSTR )) {
+               if( state & GOT_NEWSUP ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: op_ldap_modrdn: multiple newsuperior arg \"%s\"\n",
+                       mi[ i ].mi_val, 0, 0 );
+               *errmsg = "Multiple newrdn argument";
+               return -1;
+               }
+
+               newrdn = mi[ i ].mi_val;
+           state |= GOT_NEWSUP;
+
        } else {
            Debug( LDAP_DEBUG_ANY, "Error: op_ldap_modrdn: bad type \"%s\"\n",
                    mi[ i ].mi_type, 0, 0 );
@@ -406,7 +440,7 @@ op_ldap_modrdn(
     /*
      * Punt if we don't have all the args.
      */
-    if ( state != GOT_ALLNEWRDNFLAGS ) {
+    if ( GOT_ALL_MODDN(state) ) {
        Debug( LDAP_DEBUG_ANY, "Error: op_ldap_modrdn: missing arguments\n",
                0, 0, 0 );
        *errmsg = "Missing argument: requires \"newrdn\" and \"deleteoldrdn\"";
@@ -429,7 +463,7 @@ op_ldap_modrdn(
 #endif /* LDAP_DEBUG */
 
     /* Do the modrdn */
-    rc = ldap_modrdn2_s( ri->ri_ldp, re->re_dn, mi->mi_val, drdnflag );
+    rc = ldap_rename2_s( ri->ri_ldp, re->re_dn, mi->mi_val, drdnflag, newsup );
 
        ldap_get_option( ri->ri_ldp, LDAP_OPT_ERROR_NUMBER, &lderr);
     return( lderr );
@@ -441,7 +475,7 @@ op_ldap_modrdn(
  * Allocate and initialize an ldapmod struct.
  */
 static LDAPMod *
-alloc_ldapmod()
+alloc_ldapmod( void )
 {
     LDAPMod    *ldm;
 
@@ -556,7 +590,7 @@ do_unbind(
        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;
     }
@@ -611,11 +645,11 @@ do_bind(
        ri->ri_ldp = NULL;
     }
 
-    Debug( LDAP_DEBUG_ARGS, "Open connection to %s:%d\n",
+    Debug( LDAP_DEBUG_ARGS, "Initializing session to %s:%d\n",
            ri->ri_hostname, ri->ri_port, 0 );
-    ri->ri_ldp = ldap_open( ri->ri_hostname, ri->ri_port );
+    ri->ri_ldp = ldap_init( ri->ri_hostname, ri->ri_port );
     if ( ri->ri_ldp == NULL ) {
-       Debug( LDAP_DEBUG_ANY, "Error: ldap_open(%s, %d) failed: %s\n",
+       Debug( LDAP_DEBUG_ANY, "Error: ldap_init(%s, %d) failed: %s\n",
                ri->ri_hostname, ri->ri_port, sys_errlist[ errno ] );
        return( BIND_ERR_OPEN );
     }
@@ -755,7 +789,8 @@ kexit:      if ( krbnames != NULL ) {
  */
 static void
 dump_ldm_array(
-LDAPMod **ldmarr )
+    LDAPMod **ldmarr
+)
 {
     int                         i, j;
     LDAPMod            *ldm;
@@ -765,21 +800,21 @@ LDAPMod **ldmarr )
     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 = %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 );
            }
        }
@@ -851,7 +886,8 @@ read_krbnames(
  */
 static void
 upcase(
-char *s )
+    char *s
+)
 {
     char *p;