ldb_tdb: Re-add of both existing DN and GUID must gives LDB_ERR_ENTRY_ALREADY_EXISTS
authorAndrew Bartlett <abartlet@samba.org>
Wed, 13 Sep 2017 00:37:51 +0000 (12:37 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:23 +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_tdb.c

index f8d80e9e49069c55dacf6d0039502e342c3c471f..ea391850b27066898b504277edc26341957a081e 100644 (file)
@@ -540,6 +540,24 @@ static int ltdb_add_internal(struct ldb_module *module,
 
        ret = ltdb_store(module, msg, TDB_INSERT);
        if (ret != LDB_SUCCESS) {
+               /*
+                * Try really hard to get the right error code for
+                * a re-add situation, as this can matter!
+                */
+               if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
+                       int ret2;
+                       struct ldb_dn *dn2 = NULL;
+                       TALLOC_CTX *mem_ctx = talloc_new(module);
+                       if (mem_ctx == NULL) {
+                               return ldb_module_operr(module);
+                       }
+                       ret2 = ltdb_search_base(module, module,
+                                               msg->dn, &dn2);
+                       TALLOC_FREE(mem_ctx);
+                       if (ret2 == LDB_SUCCESS) {
+                               ret = LDB_ERR_ENTRY_ALREADY_EXISTS;
+                       }
+               }
                if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
                        ldb_asprintf_errstring(ldb,
                                               "Entry %s already exists",