1 /* nops.c - Overlay to filter idempotent operations */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2008-2012 The OpenLDAP Foundation.
6 * Copyright 2008 Emmanuel Dreyfus.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was originally developed by the Emmanuel Dreyfus for
19 * inclusion in OpenLDAP Software.
23 #ifdef SLAPD_OVER_NOPS
27 #include <ac/string.h>
28 #include <ac/socket.h>
34 static ConfigDriver nops_cf_gen;
36 static int nops_cf_gen( ConfigArgs *c ) { return 0; }
39 nops_rm_mod( Modifications **mods, Modifications *mod ) {
40 Modifications *next, *m;
48 for (m = *mods; m; m = m->sml_next) {
49 if (m->sml_next == mod) {
57 slap_mods_free(mod, 1);
63 nops_modify( Operation *op, SlapReply *rs )
65 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
66 Backend *be = op->o_bd;
67 Entry *target_entry = NULL;
71 if ((m = op->orm_modlist) == NULL) {
72 op->o_bd->bd_info = (BackendInfo *)(on->on_info);
73 send_ldap_error(op, rs, LDAP_INVALID_SYNTAX,
74 "nops() got null orm_modlist");
78 op->o_bd = on->on_info->oi_origdb;
79 rc = be_entry_get_rw(op, &op->o_req_ndn, NULL, NULL, 0, &target_entry);
82 if (rc != 0 || target_entry == NULL)
86 * For each attribute modification, check if the
87 * modification and the old entry are the same.
100 /* Check only replace sub-operations */
101 if ((mc->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)
104 /* If there is no values, skip */
105 if (((bm = mc->sml_values ) == NULL ) || (bm[0].bv_val == NULL))
108 /* If the attribute does not exist in old entry, skip */
109 if ((a = attr_find(target_entry->e_attrs, mc->sml_desc)) == NULL)
111 if ((bt = a->a_vals) == NULL)
114 /* For each value replaced, do we find it in old entry? */
116 for (i = 0; bm[i].bv_val; i++) {
117 for (j = 0; bt[j].bv_val; j++) {
118 if (bm[i].bv_len != bt[j].bv_len)
120 if (memcmp(bm[i].bv_val, bt[j].bv_val, bt[j].bv_len) != 0)
128 /* Did we find as many values as we had in old entry? */
129 if (i != a->a_numvals || found != a->a_numvals)
132 /* This is a nop, remove it */
133 Debug(LDAP_DEBUG_TRACE, "removing nop on %s%s%s",
134 a->a_desc->ad_cname.bv_val, "", "");
136 nops_rm_mod(&op->orm_modlist, mc);
139 op->o_bd = on->on_info->oi_origdb;
140 be_entry_release_r(op, target_entry);
144 if ((m = op->orm_modlist) == NULL) {
145 slap_callback *cb = op->o_callback;
147 op->o_bd->bd_info = (BackendInfo *)(on->on_info);
148 op->o_callback = NULL;
149 send_ldap_error(op, rs, LDAP_SUCCESS, "");
155 return SLAP_CB_CONTINUE;
158 static slap_overinst nops_ovl;
160 #if SLAPD_OVER_NOPS == SLAPD_MOD_DYNAMIC
164 nops_initialize( void ) {
165 nops_ovl.on_bi.bi_type = "nops";
166 nops_ovl.on_bi.bi_op_modify = nops_modify;
167 return overlay_register( &nops_ovl );
170 #if SLAPD_OVER_NOPS == SLAPD_MOD_DYNAMIC
171 int init_module(int argc, char *argv[]) {
172 return nops_initialize();
176 #endif /* defined(SLAPD_OVER_NOPS) */