dsdb-linked_attributes: Do not crash if the target GUID can not be found
authorAndrew Bartlett <abartlet@samba.org>
Thu, 16 May 2013 03:52:51 +0000 (13:52 +1000)
committerStefan Metzmacher <metze@samba.org>
Tue, 28 May 2013 14:20:08 +0000 (16:20 +0200)
Note that we must not give an error when we cannot find the object
that should hold the backlink, there really isn't anything we can do
in this case.

Andrew Bartlett

Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/samdb/ldb_modules/linked_attributes.c

index a55ec87f0fd7fc6e21939a9d095883455c3dcd04..eb57f91e6d84a24f0f4428b3b93e507839681d33 100644 (file)
@@ -4,6 +4,7 @@
    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2007
    Copyright (C) Simo Sorce <idra@samba.org> 2008
    Copyright (C) Matthieu Patou <mat@matws.net> 2011
+   Copyright (C) Andrew Tridgell 2009
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -729,6 +730,20 @@ static int linked_attributes_fix_links(struct ldb_module *module,
                        talloc_free(tmp_ctx);
                        return ret;
                }
+               if (res->count == 0) {
+                       /* Forward link without backlink object remaining - nothing to do here */
+                       continue;
+               }
+               if (res->count != 1) {
+                       ldb_asprintf_errstring(ldb, "Linked attribute %s->%s between %s and %s - target GUID %s found more than once!",
+                                              el->name, target->lDAPDisplayName,
+                                              ldb_dn_get_linearized(old_dn),
+                                              ldb_dn_get_linearized(dsdb_dn->dn),
+                                              GUID_string(tmp_ctx, &link_guid));
+                       talloc_free(tmp_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+
                msg = res->msgs[0];
 
                if (msg->num_elements == 0) {