From: Tim Beale Date: Fri, 9 Nov 2018 01:29:14 +0000 (+1300) Subject: replmd: Split some code out into create_la_entry() helper function X-Git-Tag: tdb-1.3.17~728 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=062ac12a31010436953ebe0b31351f7ec0844415;p=samba.git replmd: Split some code out into create_la_entry() helper function replmd_store_linked_attributes() has gotten in szie and complexity. This refactors some code out into a separate function to make things a bit more manageable. This patch should not alter functionality. Signed-off-by: Tim Beale Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c index f1f9487fae1..fb1f6f5d847 100644 --- a/source4/dsdb/samdb/ldb_modules/repl_meta_data.c +++ b/source4/dsdb/samdb/ldb_modules/repl_meta_data.c @@ -6567,6 +6567,43 @@ static bool la_entry_matches_group(struct la_entry *la_entry, &prev->la->identifier->guid)); } +/** + * Creates a new la_entry to store replication info for a single + * linked attribute. + */ +static struct la_entry * +create_la_entry(struct replmd_private *replmd_private, + struct drsuapi_DsReplicaLinkedAttribute *la, + uint32_t dsdb_repl_flags) +{ + struct la_entry *la_entry; + + if (replmd_private->la_ctx == NULL) { + replmd_private->la_ctx = talloc_new(replmd_private); + } + la_entry = talloc(replmd_private->la_ctx, struct la_entry); + if (la_entry == NULL) { + return NULL; + } + la_entry->la = talloc(la_entry, + struct drsuapi_DsReplicaLinkedAttribute); + if (la_entry->la == NULL) { + talloc_free(la_entry); + return NULL; + } + *la_entry->la = *la; + la_entry->dsdb_repl_flags = dsdb_repl_flags; + + /* + * we need to steal the non-scalars so they stay + * around until the end of the transaction + */ + talloc_steal(la_entry->la, la_entry->la->identifier); + talloc_steal(la_entry->la, la_entry->la->value.blob); + + return la_entry; +} + /** * Stores the linked attributes received in the replication chunk - these get * applied at the end of the transaction. We also check that each linked @@ -6594,27 +6631,14 @@ static int replmd_store_linked_attributes(struct replmd_replicated_request *ar) struct la_entry *la_entry; bool new_srcobj; - if (replmd_private->la_ctx == NULL) { - replmd_private->la_ctx = talloc_new(replmd_private); - } - la_entry = talloc(replmd_private->la_ctx, struct la_entry); + /* create an entry to store the received link attribute info */ + la_entry = create_la_entry(replmd_private, + &ar->objs->linked_attributes[i], + ar->objs->dsdb_repl_flags); if (la_entry == NULL) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - la_entry->la = talloc(la_entry, struct drsuapi_DsReplicaLinkedAttribute); - if (la_entry->la == NULL) { - talloc_free(la_entry); - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - *la_entry->la = ar->objs->linked_attributes[i]; - la_entry->dsdb_repl_flags = ar->objs->dsdb_repl_flags; - - /* we need to steal the non-scalars so they stay - around until the end of the transaction */ - talloc_steal(la_entry->la, la_entry->la->identifier); - talloc_steal(la_entry->la, la_entry->la->value.blob); /* * check if we're still dealing with the same source object