/* writes the current cookie into dse.ldif under the replication agreement entry returns: ldap result code of the operation. */ int windows_private_save_dirsync_cookie(const Repl_Agmt *ra) { Dirsync_Private *dp = NULL; Slapi_PBlock *pb = NULL; Slapi_DN* sdn = NULL; int rc = 0; Slapi_Mods *mods = NULL; LDAPDebug0Args( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n" ); PR_ASSERT(ra); dp = (Dirsync_Private *) agmt_get_priv(ra); PR_ASSERT (dp); pb = slapi_pblock_new (); mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE); sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) ); slapi_modify_internal_set_pb_ext (pb, sdn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL, repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0); slapi_modify_internal_pb (pb); slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); if (rc == LDAP_NO_SUCH_ATTRIBUTE) { /* try again, but as an add instead */ slapi_mods_free(&mods); mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD); slapi_modify_internal_set_pb_ext (pb, sdn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL, repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0); slapi_modify_internal_pb (pb); slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); } slapi_pblock_destroy (pb); slapi_mods_free(&mods); slapi_sdn_free(&sdn); LDAPDebug0Args( LDAP_DEBUG_TRACE, "<= windows_private_save_dirsync_cookie\n" ); return rc; }
int oath_update_token(Slapi_Entry *e, long i) { char *dn, value[22], *values[2] = {value, NULL}; int rc = LDAP_SUCCESS; Slapi_PBlock *pb; snprintf(value, 22, "%d", i); LDAPMod mod = { .mod_op = LDAP_MOD_REPLACE, .mod_type = "tokenCounter", .mod_values = values }; LDAPMod *mods[] = {&mod, NULL}; dn = slapi_entry_get_dn(e); pb = slapi_pblock_new(); slapi_modify_internal_set_pb(pb, dn, mods, NULL, NULL, oath_preop_plugin_id, 0); if (slapi_modify_internal_pb(pb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, "oath", "oath_update_token: Failed to update token\n"); slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); } slapi_pblock_destroy(pb); return rc; }
int urp_fixup_modify_entry (const char *uniqueid, const Slapi_DN *sdn, CSN *opcsn, Slapi_Mods *smods, int opflags) { Slapi_PBlock *newpb; Slapi_Operation *op; int op_result; newpb = slapi_pblock_new(); slapi_modify_internal_set_pb_ext ( newpb, sdn, slapi_mods_get_ldapmods_byref (smods), NULL, /* Controls */ uniqueid, repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION), OP_FLAG_REPLICATED | OP_FLAG_REPL_FIXUP | opflags); /* set operation csn */ slapi_pblock_get (newpb, SLAPI_OPERATION, &op); operation_set_csn (op, opcsn); /* do modify */ slapi_modify_internal_pb (newpb); slapi_pblock_get (newpb, SLAPI_PLUGIN_INTOP_RESULT, &op_result); slapi_pblock_destroy(newpb); return op_result; }
void pw_apply_mods(const Slapi_DN *sdn, Slapi_Mods *mods) { Slapi_PBlock pb; int res; if (mods && (slapi_mods_get_num_mods(mods) > 0)) { pblock_init(&pb); /* We don't want to overwrite the modifiersname, etc. attributes, * so we set a flag for this operation */ slapi_modify_internal_set_pb_ext (&pb, sdn, slapi_mods_get_ldapmods_byref(mods), NULL, /* Controls */ NULL, /* UniqueID */ pw_get_componentID(), /* PluginID */ OP_FLAG_SKIP_MODIFIED_ATTRS); /* Flags */ slapi_modify_internal_pb (&pb); slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &res); if (res != LDAP_SUCCESS){ LDAPDebug2Args(LDAP_DEBUG_ANY, "WARNING: passwordPolicy modify error %d on entry '%s'\n", res, slapi_sdn_get_dn(sdn)); } pblock_done(&pb); } return; }
static int linked_attrs_remove_backlinks_callback(Slapi_Entry *e, void *callback_data) { int rc = 0; Slapi_DN *sdn = slapi_entry_get_sdn(e); char *type = (char *)callback_data; Slapi_PBlock *pb = slapi_pblock_new(); char *val[1]; LDAPMod mod; LDAPMod *mods[2]; /* Remove all values of the passed in type. */ val[0] = 0; mod.mod_op = LDAP_MOD_DELETE; mod.mod_type = type; mod.mod_values = val; mods[0] = &mod; mods[1] = 0; slapi_log_error(SLAPI_LOG_PLUGIN, LINK_PLUGIN_SUBSYSTEM, "Removing backpointer attribute (%s) from entry (%s)\n", type, slapi_sdn_get_dn(sdn)); /* Perform the operation. */ slapi_modify_internal_set_pb_ext(pb, sdn, mods, 0, 0, linked_attrs_get_plugin_id(), 0); slapi_modify_internal_pb(pb); slapi_pblock_destroy(pb); return rc; }
/* Function : slapi_modify_internal * * Description: Plugin functions call this routine to modify an entry * in the backend directly * Return values : LDAP_SUCCESS * LDAP_PARAM_ERROR * LDAP_NO_MEMORY * LDAP_OTHER * LDAP_UNWILLING_TO_PERFORM */ Slapi_PBlock * slapi_modify_internal( char *ldn, LDAPMod **mods, LDAPControl **controls, int log_change ) { Slapi_PBlock *pb; pb = slapi_pblock_new(); slapi_modify_internal_set_pb( pb, ldn, mods, controls, NULL, NULL, 0 ); slapi_pblock_set( pb, SLAPI_LOG_OPERATION, (void *)&log_change ); slapi_modify_internal_pb( pb ); return pb; }
static int _do_modify(Slapi_PBlock *mod_pb, Slapi_DN *entrySDN, LDAPMod **mods) { int rc = 0; slapi_pblock_init(mod_pb); if(allow_repl){ /* Must set as a replicated operation */ slapi_modify_internal_set_pb_ext(mod_pb, entrySDN, mods, NULL, NULL, referint_plugin_identity, OP_FLAG_REPLICATED); } else { slapi_modify_internal_set_pb_ext(mod_pb, entrySDN, mods, NULL, NULL, referint_plugin_identity, 0); } slapi_modify_internal_pb(mod_pb); slapi_pblock_get(mod_pb, SLAPI_PLUGIN_INTOP_RESULT, &rc); return rc; }
/* Construct Mods pblock and perform the modify operation * Sets result of operation in SLAPI_PLUGIN_INTOP_RESULT */ int ipapwd_apply_mods(const char *dn, Slapi_Mods *mods) { Slapi_PBlock *pb; int ret; LOG_TRACE("=>\n"); if (!mods || (slapi_mods_get_num_mods(mods) == 0)) { return -1; } pb = slapi_pblock_new(); slapi_modify_internal_set_pb(pb, dn, slapi_mods_get_ldapmods_byref(mods), NULL, /* Controls */ NULL, /* UniqueID */ ipapwd_plugin_id, /* PluginID */ 0); /* Flags */ ret = slapi_modify_internal_pb(pb); if (ret) { LOG_TRACE("WARNING: modify error %d on entry '%s'\n", ret, dn); } else { slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret); if (ret != LDAP_SUCCESS){ LOG_TRACE("WARNING: modify error %d on entry '%s'\n", ret, dn); } else { LOG_TRACE("<= Successful\n"); } } slapi_pblock_destroy(pb); return ret; }
static int linked_attrs_add_backlinks_callback(Slapi_Entry *e, void *callback_data) { int rc = 0; char *linkdn = slapi_entry_get_dn(e); struct configEntry *config = (struct configEntry *)callback_data; Slapi_PBlock *pb = slapi_pblock_new(); int i = 0; char **targets = NULL; char *val[2]; LDAPMod mod; LDAPMod *mods[2]; /* Setup the modify operation. Only the target will * change, so we only need to do this once. */ val[0] = linkdn; val[1] = 0; mod.mod_op = LDAP_MOD_ADD; mod.mod_type = config->managedtype; mod.mod_values = val; mods[0] = &mod; mods[1] = 0; targets = slapi_entry_attr_get_charray(e, config->linktype); for (i = 0; targets && targets[i]; ++i) { char *targetdn = (char *)targets[i]; int perform_update = 0; Slapi_DN *targetsdn = NULL; if (slapi_is_shutting_down()) { rc = -1; goto done; } targetsdn = slapi_sdn_new_normdn_byref(targetdn); if (config->scope) { /* Check if the target is within the scope. */ perform_update = slapi_dn_issuffix(targetdn, config->scope); } else { /* Find out the root suffix that the linkdn is in * and see if the target is in the same backend. */ Slapi_Backend *be = NULL; Slapi_DN *linksdn = slapi_sdn_new_normdn_byref(linkdn); if ((be = slapi_be_select(linksdn))) { perform_update = slapi_sdn_issuffix(targetsdn, slapi_be_getsuffix(be, 0)); } slapi_sdn_free(&linksdn); } if (perform_update) { slapi_log_error(SLAPI_LOG_PLUGIN, LINK_PLUGIN_SUBSYSTEM, "Adding backpointer (%s) in entry (%s)\n", linkdn, targetdn); /* Perform the modify operation. */ slapi_modify_internal_set_pb_ext(pb, targetsdn, mods, 0, 0, linked_attrs_get_plugin_id(), 0); slapi_modify_internal_pb(pb); /* Initialize the pblock so we can reuse it. */ slapi_pblock_init(pb); } slapi_sdn_free(&targetsdn); } done: slapi_ch_array_free(targets); slapi_pblock_destroy(pb); return rc; }