]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/modrdn.c
Fix prev commit, return generated passwd
[openldap] / servers / slapd / back-meta / modrdn.c
index d7b3068ef2dcbca0d24f006e0307c2c9d85995f1..f5c75af238e8f2caad631ffa833ca238b76b2819 100644 (file)
@@ -1,7 +1,24 @@
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati.
+ */
+/* This is an altered version */
+/*
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
  *
  * This work has been developed to fulfill the requirements
@@ -94,8 +111,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
        struct metaconn         *lc;
        int                     rc = 0;
        int                     candidate = -1;
-       char                    *mdn = NULL,
-                               *mnewSuperior = NULL;
+       struct berval           mdn = { 0, NULL },
+                               mnewSuperior = { 0, NULL };
+       dncookie                dc;
 
        lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
                        &op->o_req_ndn, &candidate );
@@ -111,6 +129,9 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
                goto cleanup;
        }
 
+       dc.conn = op->o_conn;
+       dc.rs = rs;
+
        if ( op->oq_modrdn.rs_newSup ) {
                int nsCandidate, version = LDAP_VERSION3;
 
@@ -137,40 +158,13 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
 
                ldap_set_option( lc->conns[ nsCandidate ].ld,
                                LDAP_OPT_PROTOCOL_VERSION, &version );
-               
+
                /*
                 * Rewrite the new superior, if defined and required
                 */
-               switch ( rewrite_session( li->targets[ nsCandidate ]->rwmap.rwm_rw,
-                                       "newSuperiorDn",
-                                       op->oq_modrdn.rs_newSup->bv_val, 
-                                       op->o_conn, 
-                                       &mnewSuperior ) ) {
-               case REWRITE_REGEXEC_OK:
-                       if ( mnewSuperior == NULL ) {
-                               mnewSuperior = ( char * )op->oq_modrdn.rs_newSup;
-                       }
-#ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] newSuperiorDn: \"%s\" -> \"%s\"\n",
-                               op->oq_modrdn.rs_newSup, mnewSuperior, 0 );
-#else /* !NEW_LOGGING */
-                       Debug( LDAP_DEBUG_ARGS, "rw> newSuperiorDn:"
-                                       " \"%s\" -> \"%s\"\n",
-                                       op->oq_modrdn.rs_newSup->bv_val,
-                                       mnewSuperior, 0 );
-#endif /* !NEW_LOGGING */
-                       break;
-
-               case REWRITE_REGEXEC_UNWILLING:
-                       rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       rs->sr_text = "Operation not allowed";
-                       rc = -1;
-                       goto cleanup;
-
-               case REWRITE_REGEXEC_ERR:
-                       rs->sr_err = LDAP_OTHER;
-                       rs->sr_text = "Rewrite error";
+               dc.rwmap = &li->targets[ nsCandidate ]->rwmap;
+               dc.ctx = "newSuperiorDN";
+               if ( ldap_back_dn_massage( &dc, op->oq_modrdn.rs_newSup, &mnewSuperior ) ) {
                        rc = -1;
                        goto cleanup;
                }
@@ -179,48 +173,26 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
        /*
         * Rewrite the modrdn dn, if required
         */
-       switch ( rewrite_session( li->targets[ candidate ]->rwmap.rwm_rw,
-                               "modrDn", op->o_req_dn.bv_val,
-                               op->o_conn, &mdn ) ) {
-       case REWRITE_REGEXEC_OK:
-               if ( mdn == NULL ) {
-                       mdn = ( char * )op->o_req_dn.bv_val;
-               }
-#ifdef NEW_LOGGING
-               LDAP_LOG( BACK_META, DETAIL1,
-                               "[rw] modrDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#else /* !NEW_LOGGING */
-               Debug( LDAP_DEBUG_ARGS, "rw> modrDn: \"%s\" -> \"%s\"\n",
-                               op->o_req_dn.bv_val, mdn, 0 );
-#endif /* !NEW_LOGGING */
-               break;
-               
-       case REWRITE_REGEXEC_UNWILLING:
-               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-               rs->sr_text = "Operation not allowed";
-               rc = -1;
-               goto cleanup;
-
-       case REWRITE_REGEXEC_ERR:
-               rs->sr_err = LDAP_OTHER;
-               rs->sr_text = "Rewrite error";
+       dc.rwmap = &li->targets[ candidate ]->rwmap;
+       dc.ctx = "modrDN";
+       if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
                rc = -1;
                goto cleanup;
        }
 
-       ldap_rename2_s( lc->conns[ candidate ].ld, mdn,
+       ldap_rename2_s( lc->conns[ candidate ].ld, mdn.bv_val,
                        op->oq_modrdn.rs_newrdn.bv_val,
-                       mnewSuperior, op->oq_modrdn.rs_deleteoldrdn );
+                       mnewSuperior.bv_val,
+                       op->oq_modrdn.rs_deleteoldrdn );
 
 cleanup:;
-       if ( mdn != op->o_req_dn.bv_val ) {
-               free( mdn );
+       if ( mdn.bv_val != op->o_req_dn.bv_val ) {
+               free( mdn.bv_val );
        }
        
-       if ( mnewSuperior != NULL 
-                       && mnewSuperior != op->oq_modrdn.rs_newSup->bv_val ) {
-               free( mnewSuperior );
+       if ( mnewSuperior.bv_val != NULL 
+                       && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
+               free( mnewSuperior.bv_val );
        }
 
        if ( rc == 0 ) {