]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapmodrdn.c
ITS#3755 silence strict-aliasing warnings
[openldap] / clients / tools / ldapmodrdn.c
index 827a372d251377e78bdd1420c66d64a3c99fcd00..2841d7e087534a9f1dbcd6bd27df94f7585f02db 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
  * Portions Copyright 1998-2001 Net Boolean Incorporated.
  * Portions Copyright 2001-2003 IBM Corporation.
@@ -52,6 +52,8 @@
 #include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/unistd.h>
+#include <ac/socket.h>
+#include <ac/time.h>
 
 #include <ldap.h>
 #include "lutil.h"
@@ -153,7 +155,7 @@ main(int argc, char **argv)
     LDAP               *ld;
        int             rc, retval, havedn;
 
-    tool_init();
+    tool_init( TOOL_MODRDN );
     prog = lutil_progname( "ldapmodrdn", argc, argv );
 
        tool_args( argc, argv );
@@ -197,15 +199,13 @@ main(int argc, char **argv)
 
        tool_bind( ld );
 
-       if ( assertion || authzid || manageDSAit || noop ) {
-               tool_server_controls( ld, NULL, 0 );
-       }
+       tool_server_controls( ld, NULL, 0 );
 
     retval = rc = 0;
     if (havedn)
        retval = domodrdn( ld, entrydn, rdn, newSuperior, remove_old_RDN );
     else while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) {
-       if ( *buf != '\0' ) {   /* blank lines optional, skip */
+       if ( *buf != '\n' ) {   /* blank lines optional, skip */
            buf[ strlen( buf ) - 1 ] = '\0';    /* remove nl */
 
            if ( havedn ) {     /* have DN, get RDN */
@@ -227,8 +227,8 @@ main(int argc, char **argv)
        }
     }
 
-       ldap_unbind_ext( ld, NULL, NULL );
-
+       tool_unbind( ld );
+       tool_destroy();
     return( retval );
 }
 
@@ -252,7 +252,7 @@ static int domodrdn(
                }
        }
 
-       if( not ) return LDAP_SUCCESS;
+       if( dont ) return LDAP_SUCCESS;
 
        rc = ldap_rename( ld, dn, rdn, newSuperior, remove,
                NULL, NULL, &id );
@@ -263,10 +263,25 @@ static int domodrdn(
                return rc;
        }
 
-       rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, NULL, &res );
-       if ( rc < 0 ) {
-               ldap_perror( ld, "ldapmodrdn: ldap_result" );
-               return rc;
+       for ( ; ; ) {
+               struct timeval  tv = { 0, 0 };
+
+               if ( tool_check_abandon( ld, id ) ) {
+                       return LDAP_CANCELLED;
+               }
+
+               tv.tv_sec = 0;
+               tv.tv_usec = 100000;
+
+               rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ALL, &tv, &res );
+               if ( rc < 0 ) {
+                       tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
+                       return rc;
+               }
+
+               if ( rc != 0 ) {
+                       break;
+               }
        }
 
        rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );