ldb_tdb: Give LDB_ERR_ENTRY_ALREADY_EXISTS when a duplicate DN index is detected
authorAndrew Bartlett <abartlet@samba.org>
Fri, 25 Aug 2017 10:21:00 +0000 (22:21 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:21 +0000 (21:20 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index 916d39ce8bbae08607861c438713f2d331c02c36..6d97fa7b75586171b3e3fece2f757f685dd35c69 100644 (file)
@@ -1511,6 +1511,7 @@ static int ltdb_write_index_dn_guid(struct ldb_module *module,
                                    const struct ldb_message *msg,
                                    int add)
 {
+       int ret;
        struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module),
                                                    struct ltdb_private);
 
@@ -1519,8 +1520,16 @@ static int ltdb_write_index_dn_guid(struct ldb_module *module,
                return LDB_SUCCESS;
        }
 
-       return ltdb_modify_index_dn(module, ltdb, msg, msg->dn,
-                                   LTDB_IDXDN, add);
+       ret = ltdb_modify_index_dn(module, ltdb, msg, msg->dn,
+                                  LTDB_IDXDN, add);
+
+       if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
+               ldb_asprintf_errstring(ldb_module_get_ctx(module),
+                                      "Entry %s already exists",
+                                      ldb_dn_get_linearized(msg->dn));
+               ret = LDB_ERR_ENTRY_ALREADY_EXISTS;
+       }
+       return ret;
 }
 
 /*