modrdn.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /*
  42. * Copyright (c) 1995 Regents of the University of Michigan.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms are permitted
  46. * provided that this notice is preserved and that due credit is given
  47. * to the University of Michigan at Ann Arbor. The name of the University
  48. * may not be used to endorse or promote products derived from this
  49. * software without specific prior written permission. This software
  50. * is provided ``as is'' without express or implied warranty.
  51. */
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <sys/types.h>
  55. #ifndef _WIN32
  56. #include <sys/socket.h>
  57. #endif
  58. #include "slap.h"
  59. #include "pratom.h"
  60. /* Forward declarations */
  61. static int rename_internal_pb (Slapi_PBlock *pb);
  62. static void op_shared_rename (Slapi_PBlock *pb, int passin_args );
  63. static int check_rdn_for_created_attrs(const char *newrdn);
  64. /* This function is called to process operation that come over external connections */
  65. void
  66. do_modrdn( Slapi_PBlock *pb )
  67. {
  68. Slapi_Operation *operation;
  69. BerElement *ber;
  70. char *dn = NULL, *newsuperior = NULL;
  71. char *newrdn = NULL;
  72. int err = 0, deloldrdn = 0;
  73. ber_len_t len = 0;
  74. LDAPDebug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
  75. /* count the modrdn request */
  76. slapi_counter_increment(g_get_global_snmp_vars()->ops_tbl.dsModifyRDNOps);
  77. slapi_pblock_get( pb, SLAPI_OPERATION, &operation);
  78. ber = operation->o_ber;
  79. /*
  80. * Parse the modrdn request. It looks like this:
  81. *
  82. * ModifyRDNRequest := SEQUENCE {
  83. * entry DistinguishedName,
  84. * newrdn RelativeDistinguishedName,
  85. * deleteoldrdn BOOLEAN,
  86. * newSuperior [0] LDAPDN OPTIONAL -- v3 only
  87. * }
  88. */
  89. if ( ber_scanf( ber, "{aab", &dn, &newrdn, &deloldrdn )
  90. == LBER_ERROR ) {
  91. LDAPDebug( LDAP_DEBUG_ANY,
  92. "ber_scanf failed (op=ModRDN; params=DN,newRDN,deleteOldRDN)\n",
  93. 0, 0, 0 );
  94. op_shared_log_error_access (pb, "MODRDN", "???", "decoding error");
  95. send_ldap_result( pb, LDAP_PROTOCOL_ERROR, NULL,
  96. "unable to decode DN, newRDN, or deleteOldRDN parameters",
  97. 0, NULL );
  98. goto free_and_return;
  99. }
  100. if ( ber_peek_tag( ber, &len ) == LDAP_TAG_NEWSUPERIOR ) {
  101. if ( pb->pb_conn->c_ldapversion < LDAP_VERSION3 ) {
  102. LDAPDebug( LDAP_DEBUG_ANY,
  103. "got newSuperior in LDAPv2 modrdn op\n", 0, 0, 0 );
  104. op_shared_log_error_access (pb, "MODRDN", dn, "decoding error");
  105. send_ldap_result( pb, LDAP_PROTOCOL_ERROR, NULL,
  106. "received newSuperior in LDAPv2 modrdn", 0, NULL );
  107. goto free_and_return;
  108. }
  109. if ( ber_scanf( ber, "a", &newsuperior ) == LBER_ERROR ) {
  110. LDAPDebug( LDAP_DEBUG_ANY,
  111. "ber_scanf failed (op=ModRDN; params=newSuperior)\n",
  112. 0, 0, 0 );
  113. op_shared_log_error_access (pb, "MODRDN", dn, "decoding error");
  114. send_ldap_result( pb, LDAP_PROTOCOL_ERROR, NULL,
  115. "unable to decode newSuperior parameter", 0, NULL );
  116. goto free_and_return;
  117. }
  118. }
  119. /*
  120. * in LDAPv3 there can be optional control extensions on
  121. * the end of an LDAPMessage. we need to read them in and
  122. * pass them to the backend.
  123. */
  124. if ( (err = get_ldapmessage_controls( pb, ber, NULL )) != 0 ) {
  125. op_shared_log_error_access (pb, "MODRDN", dn, "failed to decode LDAP controls");
  126. send_ldap_result( pb, err, NULL, NULL, 0, NULL );
  127. goto free_and_return;
  128. }
  129. LDAPDebug( LDAP_DEBUG_ARGS,
  130. "do_moddn: dn (%s) newrdn (%s) deloldrdn (%d)\n", dn, newrdn,
  131. deloldrdn );
  132. slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, &pb->pb_op->o_isroot );
  133. slapi_pblock_set( pb, SLAPI_ORIGINAL_TARGET, dn );
  134. slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, newrdn );
  135. slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, newsuperior );
  136. slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, &deloldrdn );
  137. op_shared_rename(pb, 1 /* pass in ownership of string arguments */ );
  138. return;
  139. free_and_return:
  140. slapi_ch_free((void **) &dn );
  141. slapi_ch_free((void **) &newrdn );
  142. slapi_ch_free((void **) &newsuperior );
  143. return;
  144. }
  145. /* This function is used to issue internal modrdn operation
  146. This is an old style API. Its use is discoraged because it is not extendable and
  147. because it does not allow to check whether plugin has right to access part of the
  148. tree it is trying to modify. Use slapi_modrdn_internal_pb instead */
  149. Slapi_PBlock *
  150. slapi_modrdn_internal(const char *iodn, const char *inewrdn, int deloldrdn, LDAPControl **controls, int dummy)
  151. {
  152. return slapi_rename_internal(iodn, inewrdn, NULL, deloldrdn, controls, dummy);
  153. }
  154. Slapi_PBlock *
  155. slapi_rename_internal(const char *iodn, const char *inewrdn, const char *inewsuperior, int deloldrdn, LDAPControl **controls, int dummy)
  156. {
  157. Slapi_PBlock pb;
  158. Slapi_PBlock *result_pb = NULL;
  159. int opresult= 0;
  160. pblock_init (&pb);
  161. slapi_rename_internal_set_pb (&pb, iodn, inewrdn, inewsuperior, deloldrdn,
  162. controls, NULL, plugin_get_default_component_id(), 0);
  163. rename_internal_pb (&pb);
  164. result_pb = slapi_pblock_new();
  165. if (result_pb)
  166. {
  167. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &opresult);
  168. slapi_pblock_set(result_pb, SLAPI_PLUGIN_INTOP_RESULT, &opresult);
  169. }
  170. pblock_done(&pb);
  171. return result_pb;
  172. }
  173. /* This is new style API to issue internal add operation.
  174. pblock should contain the following data (can be set via call to slapi_rename_internal_set_pb):
  175. For uniqueid based operation:
  176. SLAPI_TARGET_DN set to dn that allows to select right backend, can be stale
  177. SLAPI_TARGET_UNIQUEID set to the uniqueid of the entry we are looking for
  178. SLAPI_MODRDN_NEWRDN set to new rdn of the entry
  179. SLAPI_MODRDN_DELOLDRDN tells whether old rdn should be kept in the entry
  180. LAPI_CONTROLS_ARG set to request controls if present
  181. For dn based search:
  182. SLAPI_TARGET_DN set to the entry dn
  183. SLAPI_MODRDN_NEWRDN set to new rdn of the entry
  184. SLAPI_MODRDN_DELOLDRDN tells whether old rdn should be kept in the entry
  185. SLAPI_CONTROLS_ARG set to request controls if present
  186. */
  187. int slapi_modrdn_internal_pb (Slapi_PBlock *pb)
  188. {
  189. if (pb == NULL)
  190. return -1;
  191. return rename_internal_pb (pb);
  192. }
  193. /* Initialize a pblock for a call to slapi_modrdn_internal_pb() */
  194. void slapi_rename_internal_set_pb (Slapi_PBlock *pb, const char *olddn, const char *newrdn, const char *newsuperior, int deloldrdn,
  195. LDAPControl **controls, const char *uniqueid, Slapi_ComponentId *plugin_identity, int operation_flags)
  196. {
  197. Operation *op;
  198. PR_ASSERT (pb != NULL);
  199. if (pb == NULL || olddn == NULL || newrdn == NULL)
  200. {
  201. slapi_log_error(SLAPI_LOG_FATAL, NULL,
  202. "slapi_rename_internal_set_pb: NULL parameter\n");
  203. return;
  204. }
  205. op= internal_operation_new(SLAPI_OPERATION_MODRDN,operation_flags);
  206. slapi_pblock_set(pb, SLAPI_OPERATION, op);
  207. slapi_pblock_set(pb, SLAPI_ORIGINAL_TARGET, (void*)olddn);
  208. slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, (void*)newrdn);
  209. slapi_pblock_set(pb, SLAPI_MODRDN_NEWSUPERIOR, (void*)newsuperior);
  210. slapi_pblock_set(pb, SLAPI_MODRDN_DELOLDRDN, &deloldrdn);
  211. slapi_pblock_set(pb, SLAPI_CONTROLS_ARG, controls);
  212. slapi_pblock_set(pb, SLAPI_MODIFY_MODS, NULL);
  213. if (uniqueid)
  214. {
  215. slapi_pblock_set(pb, SLAPI_TARGET_UNIQUEID, (void*)uniqueid);
  216. }
  217. slapi_pblock_set(pb, SLAPI_PLUGIN_IDENTITY, plugin_identity);
  218. }
  219. /* Helper functions */
  220. static int rename_internal_pb (Slapi_PBlock *pb)
  221. {
  222. LDAPControl **controls;
  223. Operation *op;
  224. int opresult = 0;
  225. PR_ASSERT (pb != NULL);
  226. slapi_pblock_get(pb, SLAPI_CONTROLS_ARG, &controls);
  227. slapi_pblock_get(pb, SLAPI_OPERATION, &op);
  228. op->o_handler_data = &opresult;
  229. op->o_result_handler = internal_getresult_callback;
  230. slapi_pblock_set(pb, SLAPI_REQCONTROLS, controls);
  231. /* set parameters common for all internal operations */
  232. set_common_params (pb);
  233. /* set actions taken to process the operation */
  234. set_config_params (pb);
  235. op_shared_rename (pb, 0 /* not passing ownership of args */ );
  236. slapi_pblock_set(pb, SLAPI_PLUGIN_INTOP_RESULT, &opresult);
  237. return 0;
  238. }
  239. /*
  240. * op_shared_rename() -- common frontend code for modDN operations.
  241. *
  242. * Beware: this function resets the following pblock elements that were
  243. * set by the caller:
  244. *
  245. * SLAPI_MODRDN_TARGET
  246. * SLAPI_MODRDN_NEWRDN
  247. * SLAPI_MODRDN_NEWSUPERIOR
  248. */
  249. static void
  250. op_shared_rename(Slapi_PBlock *pb, int passin_args)
  251. {
  252. char *dn, *newsuperior, *newrdn, *newdn = NULL;
  253. char **rdns;
  254. int deloldrdn;
  255. Slapi_Backend *be = NULL;
  256. Slapi_DN sdn;
  257. Slapi_Mods smods;
  258. char dnbuf[BUFSIZ];
  259. char newrdnbuf[BUFSIZ];
  260. char newsuperiorbuf[BUFSIZ];
  261. int internal_op, repl_op, lastmod;
  262. Slapi_Operation *operation;
  263. Slapi_Entry *referral;
  264. char errorbuf[BUFSIZ];
  265. int err;
  266. slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET, &dn);
  267. slapi_pblock_get(pb, SLAPI_MODRDN_NEWRDN, &newrdn);
  268. slapi_pblock_get(pb, SLAPI_MODRDN_NEWSUPERIOR, &newsuperior);
  269. slapi_pblock_get(pb, SLAPI_MODRDN_DELOLDRDN, &deloldrdn);
  270. slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
  271. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  272. internal_op= operation_is_flag_set(operation, OP_FLAG_INTERNAL);
  273. /*
  274. * If ownership has not been passed to this function, we replace the
  275. * string input fields within the pblock with strdup'd copies. Why?
  276. * Because some pre- and post-op plugins may change them, and the
  277. * convention is that plugins should place a malloc'd string in the
  278. * pblock. Therefore, we need to be able to retrieve and free them
  279. * later. But the callers of the internal modrdn calls are promised
  280. * that we will not free these parameters... so if passin_args is
  281. * zero, we need to make copies.
  282. *
  283. * In the case of SLAPI_MODRDN_TARGET and SLAPI_MODRDN_NEWSUPERIOR, we
  284. * replace the existing values with normalized values (because plugins
  285. * expect these DNs to be normalized).
  286. */
  287. if ( passin_args ) {
  288. slapi_sdn_init_dn_passin(&sdn,dn); /* freed by slapi_sdn_done() */
  289. } else {
  290. slapi_sdn_init_dn_byref(&sdn,dn);
  291. }
  292. if ( !passin_args ) {
  293. newrdn = slapi_ch_strdup( newrdn );
  294. newsuperior = slapi_ch_strdup( newsuperior );
  295. }
  296. if ( NULL != newsuperior ) {
  297. slapi_dn_normalize_case( newsuperior ); /* normalize in place */
  298. }
  299. slapi_pblock_set (pb, SLAPI_MODRDN_TARGET,
  300. (void*)slapi_ch_strdup(slapi_sdn_get_ndn (&sdn)));
  301. slapi_pblock_set(pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn );
  302. slapi_pblock_set(pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)newsuperior);
  303. /*
  304. * first, log the operation to the access log,
  305. * then check rdn and newsuperior,
  306. * and - if applicable - log reason of any error to the errors log
  307. */
  308. if (operation_is_flag_set(operation,OP_FLAG_ACTION_LOG_ACCESS))
  309. {
  310. if ( !internal_op )
  311. {
  312. slapi_log_access(LDAP_DEBUG_STATS,
  313. "conn=%" NSPRIu64 " op=%d MODRDN dn=\"%s\" newrdn=\"%s\" newsuperior=\"%s\"\n",
  314. pb->pb_conn->c_connid,
  315. pb->pb_op->o_opid,
  316. escape_string(dn, dnbuf),
  317. (NULL == newrdn) ? "(null)" : escape_string(newrdn, newrdnbuf),
  318. (NULL == newsuperior) ? "(null)" : escape_string(newsuperior, newsuperiorbuf));
  319. }
  320. else
  321. {
  322. slapi_log_access(LDAP_DEBUG_ARGS,
  323. "conn=%s op=%d MODRDN dn=\"%s\" newrdn=\"%s\" newsuperior=\"%s\"\n",
  324. LOG_INTERNAL_OP_CON_ID,
  325. LOG_INTERNAL_OP_OP_ID,
  326. escape_string(dn, dnbuf),
  327. (NULL == newrdn) ? "(null)" : escape_string(newrdn, newrdnbuf),
  328. (NULL == newsuperior) ? "(null)" : escape_string(newsuperior, newsuperiorbuf));
  329. }
  330. }
  331. /* check that the rdn is formatted correctly */
  332. if ((rdns = ldap_explode_rdn(newrdn, 0)) == NULL)
  333. {
  334. if ( !internal_op ) {
  335. slapi_log_error(SLAPI_LOG_ARGS, NULL,
  336. "conn=%" NSPRIu64 " op=%d MODRDN invalid new RDN (\"%s\")\n",
  337. pb->pb_conn->c_connid,
  338. pb->pb_op->o_opid,
  339. (NULL == newrdn) ? "(null)" : newrdn);
  340. } else {
  341. slapi_log_error(SLAPI_LOG_ARGS, NULL,
  342. "conn=%s op=%d MODRDN invalid new RDN (\"%s\")\n",
  343. LOG_INTERNAL_OP_CON_ID,
  344. LOG_INTERNAL_OP_OP_ID,
  345. (NULL == newrdn) ? "(null)" : newrdn);
  346. }
  347. send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX, NULL, "invalid RDN", 0, NULL);
  348. goto free_and_return_nolock;
  349. }
  350. else
  351. {
  352. slapi_ldap_value_free(rdns);
  353. }
  354. /* check if created attributes are used in the new RDN */
  355. if (check_rdn_for_created_attrs((const char *)newrdn)) {
  356. send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX, NULL, "invalid attribute in RDN", 0, NULL);
  357. goto free_and_return_nolock;
  358. }
  359. /* check that the dn is formatted correctly */
  360. err = slapi_dn_syntax_check(pb, newsuperior, 1);
  361. if (err)
  362. {
  363. LDAPDebug0Args(LDAP_DEBUG_ARGS, "Syntax check of newSuperior failed\n");
  364. if (!internal_op) {
  365. slapi_log_error(SLAPI_LOG_ARGS, NULL,
  366. "conn=%" NSPRIu64 " op=%d MODRDN invalid new superior (\"%s\")",
  367. pb->pb_conn->c_connid,
  368. pb->pb_op->o_opid,
  369. (NULL == newsuperior) ? "(null)" : newsuperiorbuf);
  370. } else {
  371. slapi_log_error(SLAPI_LOG_ARGS, NULL,
  372. "conn=%s op=%d MODRDN invalid new superior (\"%s\")",
  373. LOG_INTERNAL_OP_CON_ID,
  374. LOG_INTERNAL_OP_OP_ID,
  375. (NULL == newsuperior) ? "(null)" : newsuperiorbuf);
  376. }
  377. send_ldap_result(pb, LDAP_INVALID_DN_SYNTAX, NULL,
  378. "newSuperior does not look like a DN", 0, NULL);
  379. goto free_and_return_nolock;
  380. }
  381. if (newsuperior != NULL)
  382. {
  383. LDAPDebug(LDAP_DEBUG_ARGS, "do_moddn: newsuperior (%s)\n", newsuperior, 0, 0);
  384. }
  385. /* target spec is used to decide which plugins are applicable for the operation */
  386. operation_set_target_spec (pb->pb_op, &sdn);
  387. /*
  388. * Construct the new DN (code copied from backend
  389. * and modified to handle newsuperior)
  390. */
  391. newdn = slapi_moddn_get_newdn(&sdn,newrdn,newsuperior);
  392. /*
  393. * We could be serving multiple database backends. Select the
  394. * appropriate one, or send a referral to our "referral server"
  395. * if we don't hold it.
  396. */
  397. if ((err = slapi_mapping_tree_select_and_check(pb, newdn, &be, &referral, errorbuf)) != LDAP_SUCCESS)
  398. {
  399. send_ldap_result(pb, err, NULL, errorbuf, 0, NULL);
  400. goto free_and_return_nolock;
  401. }
  402. if (referral)
  403. {
  404. int managedsait;
  405. slapi_pblock_get(pb, SLAPI_MANAGEDSAIT, &managedsait);
  406. if (managedsait)
  407. {
  408. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL,
  409. "cannot update referral", 0, NULL);
  410. slapi_entry_free(referral);
  411. goto free_and_return;
  412. }
  413. send_referrals_from_entry(pb,referral);
  414. slapi_entry_free(referral);
  415. goto free_and_return;
  416. }
  417. slapi_pblock_set(pb, SLAPI_BACKEND, be);
  418. /* can get lastmod only after backend is selected */
  419. slapi_pblock_get(pb, SLAPI_BE_LASTMOD, &lastmod);
  420. /* if it is a replicated operation - leave lastmod attributes alone */
  421. slapi_mods_init (&smods, 2);
  422. if (!repl_op && lastmod)
  423. {
  424. modify_update_last_modified_attr(pb, &smods);
  425. slapi_pblock_set(pb, SLAPI_MODIFY_MODS, (void*)slapi_mods_get_ldapmods_passout(&smods));
  426. }
  427. else {
  428. slapi_mods_done (&smods);
  429. }
  430. /*
  431. * call the pre-modrdn plugins. if they succeed, call
  432. * the backend modrdn function. then call the
  433. * post-modrdn plugins.
  434. */
  435. if (plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN :
  436. SLAPI_PLUGIN_PRE_MODRDN_FN) == 0)
  437. {
  438. int rc= LDAP_OPERATIONS_ERROR;
  439. slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
  440. set_db_default_result_handlers(pb);
  441. if (be->be_modrdn != NULL)
  442. {
  443. if ((rc = (*be->be_modrdn)(pb)) == 0)
  444. {
  445. Slapi_Entry *pse;
  446. Slapi_Entry *ecopy;
  447. /* we don't perform acl check for internal operations */
  448. /* dont update aci store for remote acis */
  449. if ((!internal_op) &&
  450. (!slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA)))
  451. plugin_call_acl_mods_update (pb, SLAPI_OPERATION_MODRDN);
  452. if (operation_is_flag_set(operation,OP_FLAG_ACTION_LOG_AUDIT))
  453. write_audit_log_entry(pb); /* Record the operation in the audit log */
  454. slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &pse);
  455. slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &ecopy);
  456. /* GGOODREPL persistent search system needs the changenumber, oops. */
  457. do_ps_service(pse, ecopy, LDAP_CHANGETYPE_MODDN, 0);
  458. }
  459. }
  460. else
  461. {
  462. send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, NULL, "Function not implemented", 0, NULL);
  463. }
  464. slapi_pblock_set(pb, SLAPI_PLUGIN_OPRETURN, &rc);
  465. plugin_call_plugins(pb, internal_op ? SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN :
  466. SLAPI_PLUGIN_POST_MODRDN_FN);
  467. }
  468. free_and_return:
  469. if (be)
  470. slapi_be_Unlock(be);
  471. free_and_return_nolock:
  472. {
  473. /* Free up everything left in the PBlock */
  474. Slapi_Entry *pse;
  475. Slapi_Entry *ecopy;
  476. LDAPMod **mods;
  477. char *s;
  478. slapi_ch_free((void **) &newdn);
  479. slapi_sdn_done(&sdn);
  480. slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &ecopy);
  481. slapi_entry_free(ecopy);
  482. slapi_pblock_get(pb, SLAPI_ENTRY_POST_OP, &pse);
  483. slapi_entry_free(pse);
  484. slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods );
  485. ldap_mods_free( mods, 1 );
  486. /* retrieve these in case a pre- or post-op plugin has changed them */
  487. slapi_pblock_get(pb, SLAPI_MODRDN_TARGET, &s);
  488. slapi_ch_free((void **)&s);
  489. slapi_pblock_get(pb, SLAPI_MODRDN_NEWRDN, &s);
  490. slapi_ch_free((void **)&s);
  491. slapi_pblock_get(pb, SLAPI_MODRDN_NEWSUPERIOR, &s);
  492. slapi_ch_free((void **)&s);
  493. slapi_pblock_get(pb, SLAPI_URP_NAMING_COLLISION_DN, &s);
  494. slapi_ch_free((void **)&s);
  495. }
  496. }
  497. /* Checks if created attributes are used in the RDN.
  498. * Returns 1 if created attrs are in the RDN, and
  499. * 0 if created attrs are not in the RDN. Returns
  500. * -1 if an error occurs.
  501. */
  502. static int check_rdn_for_created_attrs(const char *newrdn)
  503. {
  504. int i, rc = 0;
  505. Slapi_RDN *rdn = NULL;
  506. char *value = NULL;
  507. char *type[] = {"modifytimestamp", "createtimestamp",
  508. "creatorsname", "modifiersname", 0};
  509. if (newrdn && *newrdn && (rdn = slapi_rdn_new())) {
  510. slapi_rdn_init_dn(rdn, newrdn);
  511. for (i = 0; type[i] != NULL; i++) {
  512. if (slapi_rdn_contains_attr(rdn, type[i], &value)) {
  513. LDAPDebug(LDAP_DEBUG_TRACE, "Invalid DN. RDN contains %s attribute\n", type[i], 0, 0);
  514. rc = 1;
  515. break;
  516. }
  517. }
  518. slapi_rdn_free(&rdn);
  519. } else {
  520. LDAPDebug(LDAP_DEBUG_TRACE, "check_rdn_for_created_attrs: Error allocating RDN\n", 0, 0, 0);
  521. rc = -1;
  522. }
  523. return rc;
  524. }