struct ldb_message *msg1,
struct ldb_message *msg2)
{
+ int ldb_ret;
struct ldb_message *mod;
- struct ldb_message_element *el;
- unsigned int i;
- mod = ldb_msg_new(ldb);
- if (mod == NULL) {
+ /* allocate mod message in NULL context
+ * so it should appear as 'leaked' in talloc reports */
+ ldb_ret = ldb_msg_diff_ex(ldb, msg1, msg2,
+ (TALLOC_CTX*)NULL, &mod);
+ if (ldb_ret != LDB_SUCCESS) {
return NULL;
}
- mod->dn = msg1->dn;
- mod->num_elements = 0;
- mod->elements = NULL;
-
- msg2 = ldb_msg_canonicalize(ldb, msg2);
- if (msg2 == NULL) {
- talloc_free(mod);
- return NULL;
- }
-
- /* look in msg2 to find elements that need to be added
- or modified */
- for (i=0;i<msg2->num_elements;i++) {
- el = ldb_msg_find_element(msg1, msg2->elements[i].name);
-
- if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) {
- continue;
- }
-
- if (ldb_msg_add(mod,
- &msg2->elements[i],
- el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != LDB_SUCCESS) {
- talloc_free(mod);
- return NULL;
- }
- }
-
- /* look in msg1 to find elements that need to be deleted */
- for (i=0;i<msg1->num_elements;i++) {
- el = ldb_msg_find_element(msg2, msg1->elements[i].name);
- if (el == NULL) {
- if (ldb_msg_add_empty(mod,
- msg1->elements[i].name,
- LDB_FLAG_MOD_DELETE, NULL) != LDB_SUCCESS) {
- talloc_free(mod);
- return NULL;
- }
- }
- }
-
return mod;
}