/*********************************************************************** * ldap_modrdnW (WLDAP32.@) * * Change the RDN of a directory entry (asynchronous operation). * * PARAMS * ld [I] Pointer to an LDAP context. * dn [I] DN of the entry to change. * newdn [I] New DN for the entry. * * RETURNS * Success: Message ID of the modrdn operation. * Failure: An LDAP error code. * * NOTES * Call ldap_result with the message ID to get the result of * the operation. Cancel the operation by calling ldap_abandon * with the message ID. */ ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn ) { ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; #ifdef HAVE_LDAP char *dnU = NULL, *newdnU = NULL; int msg; ret = WLDAP32_LDAP_NO_MEMORY; TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) ); if (!ld || !newdn) return ~0u; if (dn) { dnU = strWtoU( dn ); if (!dnU) goto exit; } newdnU = strWtoU( newdn ); if (!newdnU) goto exit; ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg ); if (ret == LDAP_SUCCESS) ret = msg; else ret = ~0u; exit: strfreeU( dnU ); strfreeU( newdnU ); #endif return ret; }
int ldap_rename_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn, LDAP_CONST char *newSuperior, int deleteoldrdn, LDAPControl **sctrls, LDAPControl **cctrls ) { int rc; int msgid; LDAPMessage *res; rc = ldap_rename( ld, dn, newrdn, newSuperior, deleteoldrdn, sctrls, cctrls, &msgid ); if( rc != LDAP_SUCCESS ) { return rc; } rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &res ); if( rc == -1 || !res ) { return ld->ld_errno; } return ldap_result2error( ld, res, 1 ); }
/* ** Change the distinguished name of an entry. */ static int lualdap_rename (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2); ldap_pchar_t rdn = (ldap_pchar_t) luaL_checkstring (L, 3); ldap_pchar_t par = (ldap_pchar_t) luaL_optlstring (L, 4, NULL, NULL); const int del = luaL_optnumber (L, 5, 0); ldap_int_t msgid; ldap_int_t rc = ldap_rename (conn->ld, dn, rdn, par, del, NULL, NULL, &msgid); return create_future (L, rc, 1, msgid, LDAP_RES_MODDN); }
/* ARGSUSED */ int _ns_ldap_rename(char *service, int flags, char *dn, char *newrdn, char *newparent, int deleteoldrdn, LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp) { LDAP *ld = __s_api_getLDAPconn(flags); return (ldap_rename(ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls, msgidp)); }
/* rename a record */ static int lldb_rename(struct lldb_context *lldb_ac) { struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; const char *rdn_name; const struct ldb_val *rdn_val; char *old_dn; char *newrdn; char *parentdn; int ret; ldb = ldb_module_get_ctx(module); ldb_request_set_state(req, LDB_ASYNC_PENDING); old_dn = ldb_dn_alloc_linearized(lldb_ac, req->op.rename.olddn); if (old_dn == NULL) { return LDB_ERR_OPERATIONS_ERROR; } rdn_name = ldb_dn_get_rdn_name(req->op.rename.newdn); rdn_val = ldb_dn_get_rdn_val(req->op.rename.newdn); if ((rdn_name != NULL) && (rdn_val != NULL)) { newrdn = talloc_asprintf(lldb_ac, "%s=%s", rdn_name, rdn_val->length > 0 ? ldb_dn_escape_value(lldb, *rdn_val) : ""); } else { newrdn = talloc_strdup(lldb_ac, ""); } if (!newrdn) { return LDB_ERR_OPERATIONS_ERROR; } parentdn = ldb_dn_alloc_linearized(lldb_ac, ldb_dn_get_parent(lldb_ac, req->op.rename.newdn)); if (!parentdn) { return LDB_ERR_OPERATIONS_ERROR; } ret = ldap_rename(lldb->ldap, old_dn, newrdn, parentdn, 1, NULL, NULL, &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); }
static int lua_apr_ldap_rename(lua_State *L) { lua_apr_ldap_object *object; ldap_pchar_t dn, rdn, par; ldap_int_t msgid; ldap_int_t rc; int del; object = check_ldap_connection(L, 1); dn = (ldap_pchar_t) luaL_checkstring(L, 2); rdn = (ldap_pchar_t) luaL_checkstring(L, 3); par = (ldap_pchar_t) luaL_optstring(L, 4, NULL); del = luaL_optint(L, 5, 0); rc = ldap_rename(object->ldap, dn, rdn, par, del, NULL, NULL, &msgid); return create_future(L, rc, 1, msgid, LDAP_RES_MODDN); }
// wrappers for ldap_rename // nsresult nsLDAPOperation::Rename(const char *base, const char *newRDn, const char *newParent, bool deleteOldRDn, LDAPControl **serverctrls, LDAPControl **clientctrls) { if (mMessageListener == 0) { NS_ERROR("nsLDAPOperation::Rename(): mMessageListener not set"); return NS_ERROR_NOT_INITIALIZED; } return TranslateLDAPErrorToNSError(ldap_rename(mConnectionHandle, base, newRDn, newParent, deleteOldRDn, serverctrls, clientctrls, &mMsgID)); }
int ldap_rename2( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn, LDAP_CONST char *newSuperior, int deleteoldrdn ) { int msgid; int rc; Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 ); rc = ldap_rename( ld, dn, newrdn, newSuperior, deleteoldrdn, NULL, NULL, &msgid ); return rc == LDAP_SUCCESS ? msgid : -1; }
STDMETHODIMP CLDAPQuery::rename( /* [in] */ LONG connect_id, /* [in] */ BSTR dn, /* [in] */ BSTR newRDN, /* [in] */ BSTR newParent, /* [in] */ BOOL deleteOldRdn) { m_errorCode = 0L; const int id = m_connections.FindKey(connect_id); if(id > -1) { const ÑConnectInfo* const cinfo = m_connections.GetValueAt(id); ldap_rename(cinfo->ld(), CComBSTR(dn), CComBSTR(newRDN), CComBSTR(newParent), deleteOldRdn ? 1 : 0, NULL, NULL, NULL); m_errorCode = LdapGetLastError(); } return S_OK; }
static int dorename( const struct berval *dn, const struct berval *newrdn, const struct berval *newsup, int deleteoldrdn, LDAPControl **pctrls ) { int rc; int msgid; assert( dn != NULL ); assert( dn->bv_val != NULL ); assert( newrdn != NULL ); assert( newrdn->bv_val != NULL ); printf( _("%smodifying rdn of entry \"%s\"\n"), dont ? "!" : "", dn->bv_val ); if ( verbose ) { printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"), newrdn->bv_val, deleteoldrdn ? _("do not ") : "" ); } if ( !dont ) { rc = ldap_rename( ld, dn->bv_val, newrdn->bv_val, ( newsup && newsup->bv_val ) ? newsup->bv_val : NULL, deleteoldrdn, pctrls, NULL, &msgid ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn->bv_val ); tool_perror( "ldap_rename", rc, NULL, NULL, NULL, NULL ); goto done; } rc = process_response( ld, msgid, LDAP_RES_RENAME, dn ); if ( verbose && rc == LDAP_SUCCESS ) { printf( _("rename complete\n") ); } } else { rc = LDAP_SUCCESS; } done: putchar( '\n' ); return( rc ); }
int ldap_rename2( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn, LDAP_CONST char *newSuperior, int deleteoldrdn ) { int msgid; int rc; #ifdef NEW_LOGGING LDAP_LOG ( OPERATION, ENTRY, "ldap_rename2\n", 0, 0, 0 ); #else Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 ); #endif rc = ldap_rename( ld, dn, newrdn, newSuperior, deleteoldrdn, NULL, NULL, &msgid ); return rc == LDAP_SUCCESS ? msgid : -1; }
static int domodrdn( LDAP *ld, char *dn, char *rdn, char *newSuperior, int remove ) /* flag: remove old RDN */ { int rc, code, id; char *matcheddn=NULL, *text=NULL, **refs=NULL; LDAPMessage *res; if ( verbose ) { printf( "Renaming \"%s\"\n", dn ); printf( "\tnew rdn=\"%s\" (%s old rdn)\n", rdn, remove ? "delete" : "keep" ); if( newSuperior != NULL ) { printf("\tnew parent=\"%s\"\n", newSuperior); } } if( not ) return LDAP_SUCCESS; rc = ldap_rename( ld, dn, rdn, newSuperior, remove, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: ldap_rename: %s (%d)\n", prog, ldap_err2string( rc ), rc ); 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; } rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 ); if( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n", prog, ldap_err2string( rc ), rc ); return rc; } if( verbose || code != LDAP_SUCCESS || (matcheddn && *matcheddn) || (text && *text) || (refs && *refs) ) { printf( "Rename Result: %s (%d)\n", ldap_err2string( code ), code ); if( text && *text ) { printf( "Additional info: %s\n", text ); } if( matcheddn && *matcheddn ) { printf( "Matched DN: %s\n", matcheddn ); } if( refs ) { int i; for( i=0; refs[i]; i++ ) { printf("Referral: %s\n", refs[i] ); } } } ber_memfree( text ); ber_memfree( matcheddn ); ber_memvfree( (void **) refs ); return code; }
static int domodrdn( LDAP *ld, char *dn, char *rdn, char *newSuperior, int remove ) /* flag: remove old RDN */ { int rc, code, id; char *matcheddn=NULL, *text=NULL, **refs=NULL; LDAPControl **ctrls = NULL; LDAPMessage *res; if ( verbose ) { printf( _("Renaming \"%s\"\n"), dn ); printf( _("\tnew rdn=\"%s\" (%s old rdn)\n"), rdn, remove ? _("delete") : _("keep") ); if( newSuperior != NULL ) { printf(_("\tnew parent=\"%s\"\n"), newSuperior); } } if( dont ) return LDAP_SUCCESS; rc = ldap_rename( ld, dn, rdn, newSuperior, remove, NULL, NULL, &id ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: ldap_rename: %s (%d)\n", prog, ldap_err2string( rc ), rc ); 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, &ctrls, 1 ); if( rc != LDAP_SUCCESS ) { fprintf( stderr, "%s: ldap_parse_result: %s (%d)\n", prog, ldap_err2string( rc ), rc ); return rc; } if( verbose || code != LDAP_SUCCESS || (matcheddn && *matcheddn) || (text && *text) || (refs && *refs) ) { printf( _("Rename Result: %s (%d)\n"), ldap_err2string( code ), code ); if( text && *text ) { printf( _("Additional info: %s\n"), text ); } if( matcheddn && *matcheddn ) { printf( _("Matched DN: %s\n"), matcheddn ); } if( refs ) { int i; for( i=0; refs[i]; i++ ) { printf(_("Referral: %s\n"), refs[i] ); } } } if (ctrls) { tool_print_ctrls( ld, ctrls ); ldap_controls_free( ctrls ); } ber_memfree( text ); ber_memfree( matcheddn ); ber_memvfree( (void **) refs ); return code; }
int ldap_back_modrdn( Operation *op, SlapReply *rs ) { ldapinfo_t *li = (ldapinfo_t *)op->o_bd->be_private; ldapconn_t *lc = NULL; ber_int_t msgid; LDAPControl **ctrls = NULL; ldap_back_send_t retrying = LDAP_BACK_RETRYING; int rc = LDAP_SUCCESS; char *newSup = NULL; struct berval newrdn = BER_BVNULL; if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) { return rs->sr_err; } if ( op->orr_newSup ) { /* needs LDAPv3 */ switch ( li->li_version ) { case LDAP_VERSION3: break; case 0: if ( op->o_protocol == 0 || op->o_protocol == LDAP_VERSION3 ) { break; } /* fall thru */ default: /* op->o_protocol cannot be anything but LDAPv3, * otherwise wouldn't be here */ rs->sr_err = LDAP_UNWILLING_TO_PERFORM; send_ldap_result( op, rs ); goto cleanup; } newSup = op->orr_newSup->bv_val; } /* NOTE: we need to copy the newRDN in case it was formed * from a DN by simply changing the length (ITS#5397) */ newrdn = op->orr_newrdn; if ( newrdn.bv_val[ newrdn.bv_len ] != '\0' ) { ber_dupbv_x( &newrdn, &op->orr_newrdn, op->o_tmpmemctx ); } retry: ctrls = op->o_ctrls; rc = ldap_back_controls_add( op, rs, lc, &ctrls ); if ( rc != LDAP_SUCCESS ) { send_ldap_result( op, rs ); rc = -1; goto cleanup; } rs->sr_err = ldap_rename( lc->lc_ld, op->o_req_dn.bv_val, newrdn.bv_val, newSup, op->orr_deleteoldrdn, ctrls, NULL, &msgid ); rc = ldap_back_op_result( lc, op, rs, msgid, li->li_timeout[ SLAP_OP_MODRDN ], ( LDAP_BACK_SENDRESULT | retrying ) ); if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) { retrying &= ~LDAP_BACK_RETRYING; if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { /* if the identity changed, there might be need to re-authz */ (void)ldap_back_controls_free( op, rs, &ctrls ); goto retry; } } cleanup: (void)ldap_back_controls_free( op, rs, &ctrls ); if ( newrdn.bv_val != op->orr_newrdn.bv_val ) { op->o_tmpfree( newrdn.bv_val, op->o_tmpmemctx ); } if ( lc != NULL ) { ldap_back_release_conn( li, lc ); } return rc; }
int meta_back_modrdn( Operation *op, SlapReply *rs ) { metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; metatarget_t *mt; metaconn_t *mc; int candidate = -1; struct berval mdn = BER_BVNULL, mnewSuperior = BER_BVNULL; dncookie dc; int msgid; ldap_back_send_t retrying = LDAP_BACK_RETRYING; LDAPControl **ctrls = NULL; struct berval newrdn = BER_BVNULL; mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR ); if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) { return rs->sr_err; } assert( mc->mc_conns[ candidate ].msc_ld != NULL ); mt = mi->mi_targets[ candidate ]; dc.target = mt; dc.conn = op->o_conn; dc.rs = rs; if ( op->orr_newSup ) { /* * NOTE: the newParent, if defined, must be on the * same target as the entry to be renamed. This check * has been anticipated in meta_back_getconn() */ /* * FIXME: one possibility is to delete the entry * from one target and add it to the other; * unfortunately we'd need write access to both, * which is nearly impossible; for administration * needs, the rootdn of the metadirectory could * be mapped to an administrative account on each * target (the binddn?); we'll see. */ /* * NOTE: we need to port the identity assertion * feature from back-ldap */ /* needs LDAPv3 */ switch ( mt->mt_version ) { case LDAP_VERSION3: break; case 0: if ( op->o_protocol == 0 || op->o_protocol == LDAP_VERSION3 ) { break; } /* fall thru */ default: /* op->o_protocol cannot be anything but LDAPv3, * otherwise wouldn't be here */ rs->sr_err = LDAP_UNWILLING_TO_PERFORM; send_ldap_result( op, rs ); goto cleanup; } /* * Rewrite the new superior, if defined and required */ dc.ctx = "newSuperiorDN"; if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) { rs->sr_err = LDAP_OTHER; send_ldap_result( op, rs ); goto cleanup; } } /* * Rewrite the modrdn dn, if required */ dc.ctx = "modrDN"; if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) { rs->sr_err = LDAP_OTHER; send_ldap_result( op, rs ); goto cleanup; } /* NOTE: we need to copy the newRDN in case it was formed * from a DN by simply changing the length (ITS#5397) */ newrdn = op->orr_newrdn; if ( newrdn.bv_val[ newrdn.bv_len ] != '\0' ) { ber_dupbv_x( &newrdn, &op->orr_newrdn, op->o_tmpmemctx ); } retry:; ctrls = op->o_ctrls; if ( meta_back_controls_add( op, rs, mc, candidate, &ctrls ) != LDAP_SUCCESS ) { send_ldap_result( op, rs ); goto cleanup; } rs->sr_err = ldap_rename( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val, newrdn.bv_val, mnewSuperior.bv_val, op->orr_deleteoldrdn, ctrls, NULL, &msgid ); rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid, mt->mt_timeout[ SLAP_OP_MODRDN ], ( LDAP_BACK_SENDRESULT | retrying ) ); if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) { retrying &= ~LDAP_BACK_RETRYING; if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) { /* if the identity changed, there might be need to re-authz */ (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls ); goto retry; } } cleanup:; (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls ); if ( mdn.bv_val != op->o_req_dn.bv_val ) { free( mdn.bv_val ); BER_BVZERO( &mdn ); } if ( !BER_BVISNULL( &mnewSuperior ) && mnewSuperior.bv_val != op->orr_newSup->bv_val ) { free( mnewSuperior.bv_val ); BER_BVZERO( &mnewSuperior ); } if ( newrdn.bv_val != op->orr_newrdn.bv_val ) { op->o_tmpfree( newrdn.bv_val, op->o_tmpmemctx ); } if ( mc ) { meta_back_release_conn( mi, mc ); } return rs->sr_err; }