retrocl_po.c 21 KB

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