retrocl_po.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. #include "retrocl.h"
  42. static int
  43. entry2reple( Slapi_Entry *e, Slapi_Entry *oe, int optype );
  44. static int
  45. mods2reple( Slapi_Entry *e, LDAPMod **ldm );
  46. static int
  47. modrdn2reple( Slapi_Entry *e, const char *newrdn, int deloldrdn,
  48. LDAPMod **ldm, const char *newsup );
  49. /******************************/
  50. const char *attr_changenumber = "changenumber";
  51. const char *attr_targetdn = "targetdn";
  52. const char *attr_changetype = "changetype";
  53. const char *attr_newrdn = "newrdn";
  54. const char *attr_deleteoldrdn = "deleteoldrdn";
  55. const char *attr_changes = "changes";
  56. const char *attr_newsuperior = "newsuperior";
  57. const char *attr_changetime = "changetime";
  58. const char *attr_objectclass = "objectclass";
  59. const char *attr_nsuniqueid = "nsuniqueid";
  60. const char *attr_isreplicated = "isreplicated";
  61. /*
  62. * Function: make_changes_string
  63. *
  64. * Returns:
  65. *
  66. * Arguments:
  67. *
  68. * Description:
  69. * loop through the LDAPMod struct and construct the changes attribute/
  70. *
  71. */
  72. static lenstr *make_changes_string(LDAPMod **ldm, const char **includeattrs)
  73. {
  74. lenstr *l;
  75. int i, j, len;
  76. int skip;
  77. l = lenstr_new();
  78. for ( i = 0; ldm[ i ] != NULL; i++ ) {
  79. /* If a list of explicit attributes was given, only add those */
  80. if ( NULL != includeattrs ) {
  81. skip = 1;
  82. for ( j = 0; includeattrs[ j ] != NULL; j++ ) {
  83. if ( strcasecmp( includeattrs[ j ], ldm[ i ]->mod_type ) == 0 ) {
  84. skip = 0;
  85. break;
  86. }
  87. }
  88. if ( skip ) {
  89. continue;
  90. }
  91. }
  92. switch ( ldm[ i ]->mod_op & ~LDAP_MOD_BVALUES ) {
  93. case LDAP_MOD_ADD:
  94. addlenstr( l, "add: " );
  95. addlenstr( l, ldm[ i ]->mod_type );
  96. addlenstr( l, "\n" );
  97. break;
  98. case LDAP_MOD_DELETE:
  99. addlenstr( l, "delete: " );
  100. addlenstr( l, ldm[ i ]->mod_type );
  101. addlenstr( l, "\n" );
  102. break;
  103. case LDAP_MOD_REPLACE:
  104. addlenstr( l, "replace: " );
  105. addlenstr( l, ldm[ i ]->mod_type );
  106. addlenstr( l, "\n" );
  107. break;
  108. }
  109. for ( j = 0; ldm[ i ]->mod_bvalues != NULL &&
  110. ldm[ i ]->mod_bvalues[ j ] != NULL; j++ ) {
  111. char *buf = NULL;
  112. char *bufp = NULL;
  113. len = strlen( ldm[ i ]->mod_type );
  114. len = LDIF_SIZE_NEEDED( len,
  115. ldm[ i ]->mod_bvalues[ j ]->bv_len ) + 1;
  116. buf = slapi_ch_malloc( len );
  117. bufp = buf;
  118. slapi_ldif_put_type_and_value_with_options( &bufp, ldm[ i ]->mod_type,
  119. ldm[ i ]->mod_bvalues[ j ]->bv_val,
  120. ldm[ i ]->mod_bvalues[ j ]->bv_len, 0 );
  121. *bufp = '\0';
  122. addlenstr( l, buf );
  123. slapi_ch_free_string( &buf );
  124. }
  125. addlenstr( l, "-\n" );
  126. }
  127. return l;
  128. }
  129. /*
  130. * Function: write_replog_db
  131. * Arguments: be - backend to which this change is being applied
  132. * optype - type of LDAP operation being logged
  133. * dn - distinguished name of entry being changed
  134. * log_m - pointer to the actual change operation on a modify
  135. * flag - only used by modrdn operations - value of deleteoldrdn
  136. * curtime - the current time
  137. * Returns: error code
  138. * Description: Given a change, construct an entry which is to be added to the
  139. * changelog database.
  140. */
  141. static int
  142. write_replog_db(
  143. Slapi_PBlock *pb,
  144. int optype,
  145. char *dn,
  146. LDAPMod **log_m,
  147. int flag,
  148. time_t curtime,
  149. Slapi_Entry *log_e,
  150. const char *newrdn,
  151. LDAPMod **modrdn_mods,
  152. const char *newsuperior
  153. )
  154. {
  155. Slapi_PBlock *newPb = NULL;
  156. changeNumber changenum;
  157. struct berval *vals[ 2 ];
  158. struct berval val;
  159. Slapi_Entry *e;
  160. char chnobuf[ 20 ];
  161. char *edn;
  162. int extensibleObject = 0;
  163. int err = 0;
  164. int ret = LDAP_SUCCESS;
  165. int i;
  166. if (!dn) {
  167. slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME, "write_replog_db: NULL dn\n");
  168. return ret;
  169. }
  170. PR_Lock(retrocl_internal_lock);
  171. changenum = retrocl_assign_changenumber();
  172. PR_ASSERT( changenum > 0UL );
  173. slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  174. "write_replog_db: write change record %lu for dn: \"%s\"\n",
  175. changenum, dn );
  176. /* Construct the dn of this change record */
  177. edn = slapi_ch_smprintf( "%s=%lu,%s", attr_changenumber, changenum, RETROCL_CHANGELOG_DN);
  178. /*
  179. * Create the entry struct, and fill in fields common to all types
  180. * of change records.
  181. */
  182. vals[ 0 ] = &val;
  183. vals[ 1 ] = NULL;
  184. e = slapi_entry_alloc();
  185. slapi_entry_set_dn( e, slapi_ch_strdup( edn ));
  186. /* Set the objectclass attribute */
  187. val.bv_val = "top";
  188. val.bv_len = 3;
  189. slapi_entry_add_values( e, "objectclass", vals );
  190. val.bv_val = "changelogentry";
  191. val.bv_len = 14;
  192. slapi_entry_add_values( e, "objectclass", vals );
  193. for ( i=0; i<retrocl_nattributes; i++ ) {
  194. char* attributeName = retrocl_attributes[i];
  195. char* attributeAlias = retrocl_aliases[i];
  196. if ( attributeAlias == NULL ) {
  197. attributeAlias = attributeName;
  198. }
  199. if ( strcasecmp( attributeName, attr_nsuniqueid ) == 0 ) {
  200. Slapi_Entry *entry = NULL;
  201. const char *uniqueId = NULL;
  202. slapi_pblock_get( pb, SLAPI_ENTRY_POST_OP, &entry );
  203. if ( entry == NULL ) {
  204. slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &entry );
  205. }
  206. if ( entry == NULL ) continue;
  207. uniqueId = slapi_entry_get_uniqueid( entry );
  208. slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  209. "write_replog_db: add %s: \"%s\"\n", attributeAlias, uniqueId );
  210. val.bv_val = (char *)uniqueId;
  211. val.bv_len = strlen( uniqueId );
  212. slapi_entry_add_values( e, attributeAlias, vals );
  213. extensibleObject = 1;
  214. } else if ( strcasecmp( attributeName, attr_isreplicated ) == 0 ) {
  215. int isReplicated = 0;
  216. char *attributeValue = NULL;
  217. slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &isReplicated );
  218. attributeValue = isReplicated ? "TRUE" : "FALSE";
  219. slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  220. "write_replog_db: add %s: \"%s\"\n", attributeAlias, attributeValue );
  221. val.bv_val = attributeValue;
  222. val.bv_len = strlen( attributeValue );
  223. slapi_entry_add_values( e, attributeAlias, vals );
  224. extensibleObject = 1;
  225. } else {
  226. Slapi_Entry *entry = NULL;
  227. Slapi_ValueSet *valueSet = NULL;
  228. int type_name_disposition = 0;
  229. char *actual_type_name = NULL;
  230. int flags = 0;
  231. int buffer_flags = 0;
  232. slapi_pblock_get( pb, SLAPI_ENTRY_POST_OP, &entry );
  233. if ( entry != NULL ) {
  234. slapi_vattr_values_get( entry, attributeName, &valueSet,
  235. &type_name_disposition, &actual_type_name, flags, &buffer_flags );
  236. }
  237. if ( valueSet == NULL ) {
  238. slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &entry );
  239. if ( entry != NULL ) {
  240. slapi_vattr_values_get( entry, attributeName, &valueSet,
  241. &type_name_disposition, &actual_type_name, flags, &buffer_flags );
  242. }
  243. }
  244. if ( valueSet == NULL ) continue;
  245. slapi_log_error( SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
  246. "write_replog_db: add %s\n", attributeAlias );
  247. slapi_entry_add_valueset( e, attributeAlias, valueSet );
  248. slapi_vattr_values_free( &valueSet, &actual_type_name, buffer_flags );
  249. extensibleObject = 1;
  250. }
  251. }
  252. if ( extensibleObject ) {
  253. val.bv_val = "extensibleObject";
  254. val.bv_len = 16;
  255. slapi_entry_add_values( e, "objectclass", vals );
  256. }
  257. /* Set the changeNumber attribute */
  258. sprintf( chnobuf, "%lu", changenum );
  259. val.bv_val = chnobuf;
  260. val.bv_len = strlen( chnobuf );
  261. slapi_entry_add_values( e, attr_changenumber, vals );
  262. /* Set the targetentrydn attribute */
  263. val.bv_val = dn;
  264. val.bv_len = strlen( dn );
  265. slapi_entry_add_values( e, attr_targetdn, vals );
  266. /* Set the changeTime attribute */
  267. val.bv_val = format_genTime (curtime);
  268. val.bv_len = strlen( val.bv_val );
  269. slapi_entry_add_values( e, attr_changetime, vals );
  270. slapi_ch_free( (void **)&val.bv_val );
  271. /*
  272. * Finish constructing the entry. How to do it depends on the type
  273. * of modification being logged.
  274. */
  275. switch ( optype ) {
  276. case OP_ADD:
  277. if ( entry2reple( e, log_e, OP_ADD ) != 0 ) {
  278. err = SLAPI_PLUGIN_FAILURE;
  279. }
  280. break;
  281. case OP_MODIFY:
  282. if ( mods2reple( e, log_m ) != 0 ) {
  283. err = SLAPI_PLUGIN_FAILURE;
  284. }
  285. break;
  286. case OP_MODRDN:
  287. if ( modrdn2reple( e, newrdn, flag, modrdn_mods, newsuperior ) != 0 ) {
  288. err = SLAPI_PLUGIN_FAILURE;
  289. }
  290. break;
  291. case OP_DELETE:
  292. if (log_e) {
  293. /* we have to log the full entry */
  294. if ( entry2reple( e, log_e, OP_DELETE ) != 0 ) {
  295. err = SLAPI_PLUGIN_FAILURE;
  296. }
  297. } else {
  298. /* Set the changetype attribute */
  299. val.bv_val = "delete";
  300. val.bv_len = 6;
  301. slapi_entry_add_values( e, attr_changetype, vals );
  302. }
  303. break;
  304. default:
  305. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
  306. "replog: Unknown LDAP operation type %d.\n", optype );
  307. err = SLAPI_PLUGIN_FAILURE;
  308. }
  309. /* Call the repl backend to add this entry */
  310. if ( 0 == err ) {
  311. newPb = slapi_pblock_new ();
  312. slapi_add_entry_internal_set_pb( newPb, e, NULL /* controls */,
  313. g_plg_identity[PLUGIN_RETROCL],
  314. /* dont leave entry in cache if main oparation is aborted */
  315. SLAPI_OP_FLAG_NEVER_CACHE);
  316. slapi_add_internal_pb (newPb);
  317. slapi_pblock_get( newPb, SLAPI_PLUGIN_INTOP_RESULT, &ret );
  318. slapi_pblock_destroy(newPb);
  319. if ( 0 != ret ) {
  320. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
  321. "replog: an error occured while adding change "
  322. "number %lu, dn = %s: %s. \n",
  323. changenum, edn, ldap_err2string( ret ));
  324. retrocl_release_changenumber();
  325. } else {
  326. /* Tell the change numbering system this one's committed to disk */
  327. retrocl_commit_changenumber();
  328. }
  329. } else {
  330. slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME,
  331. "An error occurred while constructing "
  332. "change record number %ld.\n", changenum );
  333. retrocl_release_changenumber();
  334. ret = err;
  335. }
  336. PR_Unlock(retrocl_internal_lock);
  337. if ( NULL != edn ) {
  338. slapi_ch_free((void **) &edn);
  339. }
  340. return ret;
  341. }
  342. /*
  343. * Function: entry2reple
  344. * Arguments: e - a partially-constructed Slapi_Entry structure
  345. * oe - the original entry (an entry being added by a client).
  346. * Returns: 0 on success.
  347. * Description: Given an Slapi_Entry struct, construct a changelog entry which will be
  348. * added to the replication database. It is assumed that e points
  349. * to an entry obtained from slapi_entry_alloc().
  350. */
  351. static int
  352. entry2reple( Slapi_Entry *e, Slapi_Entry *oe, int optype )
  353. {
  354. char *p, *estr;
  355. struct berval *vals[ 2 ];
  356. struct berval val;
  357. int len;
  358. vals[ 0 ] = &val;
  359. vals[ 1 ] = NULL;
  360. /* Set the changetype attribute */
  361. if ( optype == OP_ADD ) {
  362. val.bv_val = "add";
  363. val.bv_len = 3;
  364. } else if ( optype == OP_DELETE) {
  365. val.bv_val = "delete";
  366. val.bv_len = 6;
  367. } else {
  368. return (1);
  369. }
  370. slapi_entry_add_values( e, attr_changetype, vals );
  371. estr = slapi_entry2str( oe, &len );
  372. p = estr;
  373. /* Skip over the dn: line */
  374. while (( p = strchr( p, '\n' )) != NULL ) {
  375. p++;
  376. if ( !ldap_utf8isspace( p )) {
  377. break;
  378. }
  379. }
  380. val.bv_val = p;
  381. val.bv_len = len - ( p - estr ); /* length + terminating \0 */
  382. slapi_entry_add_values( e, attr_changes, vals );
  383. slapi_ch_free_string( &estr );
  384. return 0;
  385. }
  386. /*
  387. * Function: mods2reple
  388. * Arguments: e - a partially-constructed Slapi_Entry structure
  389. * ldm - an array of pointers to LDAPMod structures describing the
  390. * change applied.
  391. * Returns: 0 on success.
  392. * Description: Given a pointer to an LDAPMod struct and a dn, construct
  393. * a new entry which will be added to the replication database.
  394. * It is assumed that e points to an entry obtained from
  395. * slapi_entry_alloc().
  396. */
  397. static int
  398. mods2reple( Slapi_Entry *e, LDAPMod **ldm )
  399. {
  400. struct berval val;
  401. struct berval *vals[ 2 ];
  402. lenstr *l;
  403. vals[ 0 ] = &val;
  404. vals[ 1 ] = NULL;
  405. /* Set the changetype attribute */
  406. val.bv_val = "modify";
  407. val.bv_len = 6;
  408. slapi_entry_add_values( e, "changetype", vals );
  409. if (NULL != ldm) {
  410. l = make_changes_string( ldm, NULL );
  411. if ( NULL != l ) {
  412. val.bv_val = l->ls_buf;
  413. val.bv_len = l->ls_len + 1; /* string + terminating \0 */
  414. slapi_entry_add_values( e, attr_changes, vals );
  415. lenstr_free( &l );
  416. }
  417. }
  418. return 0;
  419. }
  420. /*
  421. * Function: modrdn2reple
  422. * Arguments: e - a partially-constructed Slapi_Entry structure
  423. * newrdn - the new relative distinguished name for the entry
  424. * deloldrdn - the "deleteoldrdn" flag provided by the client
  425. * ldm - any modifications applied as a side-effect of the modrdn
  426. * Returns: 0 on success
  427. * Description: Given a dn, a new rdn, and a deleteoldrdn flag, construct
  428. * a new entry which will be added to the replication database reflecting a
  429. * completed modrdn operation. The entry has the same form as above.
  430. * It is assumed that e points to an entry obtained from slapi_entry_alloc().
  431. */
  432. static int
  433. modrdn2reple(
  434. Slapi_Entry *e,
  435. const char *newrdn,
  436. int deloldrdn,
  437. LDAPMod **ldm,
  438. const char *newsuperior
  439. )
  440. {
  441. struct berval val;
  442. struct berval *vals[ 2 ];
  443. lenstr *l;
  444. static const char *lastmodattrs[] = {"modifiersname", "modifytimestamp",
  445. "creatorsname", "createtimestamp",
  446. NULL };
  447. vals[ 0 ] = &val;
  448. vals[ 1 ] = NULL;
  449. val.bv_val = "modrdn";
  450. val.bv_len = 6;
  451. slapi_entry_add_values( e, attr_changetype, vals );
  452. if (newrdn) {
  453. val.bv_val = (char *)newrdn; /* cast away const */
  454. val.bv_len = strlen( newrdn );
  455. slapi_entry_add_values( e, attr_newrdn, vals );
  456. }
  457. if ( deloldrdn == 0 ) {
  458. val.bv_val = "FALSE";
  459. val.bv_len = 5;
  460. } else {
  461. val.bv_val = "TRUE";
  462. val.bv_len = 4;
  463. }
  464. slapi_entry_add_values( e, attr_deleteoldrdn, vals );
  465. if (newsuperior) {
  466. val.bv_val = (char *)newsuperior; /* cast away const */
  467. val.bv_len = strlen(newsuperior);
  468. slapi_entry_add_values(e, attr_newsuperior,vals);
  469. }
  470. if (NULL != ldm) {
  471. l = make_changes_string( ldm, lastmodattrs );
  472. if ( NULL != l ) {
  473. if (l->ls_len) {
  474. val.bv_val = l->ls_buf;
  475. val.bv_len = l->ls_len;
  476. slapi_entry_add_values( e, attr_changes, vals );
  477. }
  478. lenstr_free( &l );
  479. }
  480. }
  481. return 0;
  482. }
  483. /*
  484. * Function: retrocl_postob
  485. *
  486. * Returns: 0 on success
  487. *
  488. * Arguments: pblock, optype (add, del, modify etc)
  489. *
  490. * Description: called from retrocl.c op-specific plugins.
  491. *
  492. * Please be aware that operation threads may be scheduled out between their
  493. * being performed inside of the LDBM database and the changelog plugin
  494. * running. For example, suppose MA and MB are two modify operations on the
  495. * same entry. MA may be performed on the LDBM database, and then block
  496. * before the changelog runs. MB then runs against the LDBM database and then
  497. * is written to the changelog. MA starts running. In the changelog, MB will
  498. * appear to have been performed before MA, but in the LDBM database the
  499. * opposite will have occured.
  500. *
  501. *
  502. */
  503. int retrocl_postob (Slapi_PBlock *pb, int optype)
  504. {
  505. char *dn;
  506. LDAPMod **log_m = NULL;
  507. int flag = 0;
  508. Slapi_Entry *te = NULL;
  509. Slapi_Operation *op = NULL;
  510. LDAPMod **modrdn_mods = NULL;
  511. char *newrdn = NULL;
  512. Slapi_DN *newsuperior = NULL;
  513. Slapi_Backend *be = NULL;
  514. time_t curtime;
  515. int rc = SLAPI_PLUGIN_SUCCESS;
  516. /*
  517. * Check to see if the change was made to the replication backend db.
  518. * If so, don't try to log it to the db (otherwise, we'd get in a loop).
  519. */
  520. (void)slapi_pblock_get( pb, SLAPI_BACKEND, &be );
  521. if (slapi_be_logchanges(be) == 0) {
  522. LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if not logging\n");
  523. return SLAPI_PLUGIN_SUCCESS;
  524. }
  525. if (retrocl_be_changelog == NULL || be == retrocl_be_changelog) {
  526. LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no/cl be\n");
  527. return SLAPI_PLUGIN_SUCCESS;
  528. }
  529. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  530. if (rc != LDAP_SUCCESS) {
  531. LDAPDebug1Arg(LDAP_DEBUG_TRACE,"not applying change if op failed %d\n",rc);
  532. /* this could also mean that the changenumber is no longer correct
  533. * set a flag to check at next assignment
  534. */
  535. retrocl_set_check_changenumber();
  536. return SLAPI_PLUGIN_SUCCESS;
  537. }
  538. if (slapi_op_abandoned(pb)) {
  539. LDAPDebug0Args(LDAP_DEBUG_PLUGIN,"not applying change if op abandoned\n");
  540. return SLAPI_PLUGIN_SUCCESS;
  541. }
  542. curtime = current_time();
  543. (void)slapi_pblock_get( pb, SLAPI_ORIGINAL_TARGET_DN, &dn );
  544. /* change number could be retrieved from Operation extension stored in
  545. * the pblock, or else it needs to be made dynamically. */
  546. /* get the operation extension and retrieve the change number */
  547. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  548. if (op == NULL) {
  549. LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change if no op\n");
  550. return SLAPI_PLUGIN_SUCCESS;
  551. }
  552. if (operation_is_flag_set(op, OP_FLAG_TOMBSTONE_ENTRY)){
  553. LDAPDebug0Args(LDAP_DEBUG_TRACE,"not applying change for nsTombstone entries\n");
  554. return SLAPI_PLUGIN_SUCCESS;
  555. }
  556. switch ( optype ) {
  557. case OP_MODIFY:
  558. (void)slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &log_m );
  559. break;
  560. case OP_ADD:
  561. /*
  562. * For adds, we want the unnormalized dn, so we can preserve
  563. * spacing, case, when replicating it.
  564. */
  565. (void)slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &te );
  566. if ( NULL != te ) {
  567. dn = slapi_entry_get_dn( te );
  568. }
  569. break;
  570. case OP_DELETE:
  571. if (retrocl_log_deleted)
  572. (void)slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &te);
  573. break;
  574. case OP_MODRDN:
  575. /* newrdn is used just for logging; no need to be normalized */
  576. (void)slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn );
  577. (void)slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &flag );
  578. (void)slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &modrdn_mods );
  579. (void)slapi_pblock_get( pb, SLAPI_MODRDN_NEWSUPERIOR_SDN, &newsuperior );
  580. break;
  581. }
  582. /* check if we should log change to retro changelog, and
  583. * if so, do it here */
  584. if((rc = write_replog_db( pb, optype, dn, log_m, flag, curtime, te,
  585. newrdn, modrdn_mods, slapi_sdn_get_dn(newsuperior) )))
  586. {
  587. slapi_log_error(SLAPI_LOG_FATAL, "retrocl-plugin",
  588. "retrocl_postob: operation failure [%d]\n", rc);
  589. if(rc < 0){
  590. rc = LDAP_OPERATIONS_ERROR;
  591. }
  592. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
  593. rc = SLAPI_PLUGIN_FAILURE;
  594. }
  595. return rc;
  596. }