From 60cbc98051b430fc09358a09866c69a54cc726bc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Sep 2011 11:04:29 +1000 Subject: s4-dsdb: added new control DSDB_MODIFY_PARTIAL_REPLICA this control tells the partition module that the DN being created is a partial replica, so it should modify the @PARTITION object to add the partialReplica attribute Pair-Programmed-With: Andrew Bartlett --- source4/dsdb/common/util.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ source4/dsdb/common/util.h | 1 + 2 files changed, 67 insertions(+) (limited to 'source4/dsdb/common') diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index cf28f1dd01..3a55a55306 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -3751,6 +3751,13 @@ int dsdb_request_add_controls(struct ldb_request *req, uint32_t dsdb_flags) } } + if (dsdb_flags & DSDB_MODIFY_PARTIAL_REPLICA) { + ret = ldb_request_add_control(req, DSDB_CONTROL_PARTIAL_REPLICA, false, NULL); + if (ret != LDB_SUCCESS) { + return ret; + } + } + return LDB_SUCCESS; } @@ -4467,3 +4474,62 @@ NTSTATUS dsdb_ldb_err_to_ntstatus(int err) } return NT_STATUS_UNSUCCESSFUL; } + + +/* + create a new naming context that will hold a partial replica + */ +int dsdb_create_partial_replica_NC(struct ldb_context *ldb, struct ldb_dn *dn) +{ + TALLOC_CTX *tmp_ctx = talloc_new(ldb); + struct ldb_message *msg; + int ret; + + msg = ldb_msg_new(tmp_ctx); + if (msg == NULL) { + talloc_free(tmp_ctx); + return ldb_oom(ldb); + } + + msg->dn = dn; + ret = ldb_msg_add_string(msg, "objectClass", "top"); + if (ret != LDB_SUCCESS) { + talloc_free(tmp_ctx); + return ldb_oom(ldb); + } + + /* [MS-DRSR] implies that we should only add the 'top' + * objectclass, but that would cause lots of problems with our + * objectclass code as top is not structural, so we add + * 'domainDNS' as well to keep things sane. We're expecting + * this new NC to be of objectclass domainDNS after + * replication anyway + */ + ret = ldb_msg_add_string(msg, "objectClass", "domainDNS"); + if (ret != LDB_SUCCESS) { + talloc_free(tmp_ctx); + return ldb_oom(ldb); + } + + ret = ldb_msg_add_fmt(msg, "instanceType", "%u", + INSTANCE_TYPE_IS_NC_HEAD| + INSTANCE_TYPE_NC_ABOVE| + INSTANCE_TYPE_UNINSTANT); + if (ret != LDB_SUCCESS) { + talloc_free(tmp_ctx); + return ldb_oom(ldb); + } + + ret = dsdb_add(ldb, msg, DSDB_MODIFY_PARTIAL_REPLICA); + if (ret != LDB_SUCCESS) { + DEBUG(0,("Failed to create new NC for %s - %s\n", + ldb_dn_get_linearized(dn), ldb_errstring(ldb))); + talloc_free(tmp_ctx); + return ret; + } + + DEBUG(1,("Created new NC for %s\n", ldb_dn_get_linearized(dn))); + + talloc_free(tmp_ctx); + return LDB_SUCCESS; +} diff --git a/source4/dsdb/common/util.h b/source4/dsdb/common/util.h index 75ef49e1c3..b2f7aa5b32 100644 --- a/source4/dsdb/common/util.h +++ b/source4/dsdb/common/util.h @@ -37,6 +37,7 @@ #define DSDB_PROVISION 0x0800 #define DSDB_BYPASS_PASSWORD_HASH 0x1000 #define DSDB_SEARCH_NO_GLOBAL_CATALOG 0x2000 +#define DSDB_MODIFY_PARTIAL_REPLICA 0x4000 bool is_attr_in_list(const char * const * attrs, const char *attr); -- cgit