r25048: From the archives (patch found in one of my old working trees):
[kai/samba.git] / source4 / libnet / libnet_samsync_ldb.c
index 2c30128b16bc11ab356b4f1e6a3e75f2be7f0baf..1fa4aece19c76d3b0d3d9d581b5225b2900c4e2b 100644 (file)
@@ -432,14 +432,21 @@ static NTSTATUS samsync_ldb_handle_user(TALLOC_CTX *mem_ctx,
                if (ret != 0) {
                        struct ldb_dn *first_try_dn = msg->dn;
                        /* Try again with the default DN */
-                       msg->dn = talloc_steal(msg, msgs[0]->dn);
-                       ret = samdb_add(state->sam_ldb, mem_ctx, msg);
-                       if (ret != 0) {
-                               *error_string = talloc_asprintf(mem_ctx, "Failed to create user record.  Tried both %s and %s: %s",
+                       if (!remote_msgs) {
+                               *error_string = talloc_asprintf(mem_ctx, "Failed to create user record.  Tried %s: %s",
                                                                ldb_dn_get_linearized(first_try_dn),
-                                                               ldb_dn_get_linearized(msg->dn),
                                                                ldb_errstring(state->sam_ldb));
                                return NT_STATUS_INTERNAL_DB_CORRUPTION;
+                       } else {
+                               msg->dn = talloc_steal(msg, remote_msgs[0]->dn);
+                               ret = samdb_add(state->sam_ldb, mem_ctx, msg);
+                               if (ret != 0) {
+                                       *error_string = talloc_asprintf(mem_ctx, "Failed to create user record.  Tried both %s and %s: %s",
+                                                                       ldb_dn_get_linearized(first_try_dn),
+                                                                       ldb_dn_get_linearized(msg->dn),
+                                                                       ldb_errstring(state->sam_ldb));
+                                       return NT_STATUS_INTERNAL_DB_CORRUPTION;
+                               }
                        }
                }
        } else {