s4-dsdb: added samdb_rodc() and samdb_ntds_options()
authorAndrew Tridgell <tridge@samba.org>
Tue, 13 Oct 2009 08:48:13 +0000 (19:48 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 14 Oct 2009 21:20:37 +0000 (08:20 +1100)
Later we will need to make samdb_rodc() look in the database, but for
now we should at least have the function in a central place

source4/dsdb/common/util.c
source4/dsdb/repl/drepl_out_helpers.c

index f86a842fb4aeb244dc5df934e744c533c0b69dfe..c9562b0de73187824476d6aac888a9616e50cc8e 100644 (file)
@@ -2528,3 +2528,53 @@ int drsuapi_DsReplicaCursor2_compare(const struct drsuapi_DsReplicaCursor2 *c1,
 {
        return GUID_compare(&c1->source_dsa_invocation_id, &c2->source_dsa_invocation_id);
 }
+
+/*
+  see if we are a RODC
+
+  TODO: This should take a sam_ctx, and lookup the right object (with
+  a cache)
+*/
+bool samdb_rodc(struct loadparm_context *lp_ctx)
+{
+       return lp_parm_bool(lp_ctx, NULL, "repl", "RODC", false);
+}
+
+
+/*
+  return NTDS options flags. See MS-ADTS 7.1.1.2.2.1.2.1.1 
+
+  flags are DS_NTDS_OPTION_*
+*/
+int samdb_ntds_options(struct ldb_context *ldb, uint32_t *options)
+{
+       TALLOC_CTX *tmp_ctx;
+       const char *attrs[] = { "options", NULL };
+       int ret;
+       struct ldb_result *res;
+
+       tmp_ctx = talloc_new(ldb);
+       if (tmp_ctx == NULL) {
+               goto failed;
+       }
+
+       ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL);
+       if (ret) {
+               goto failed;
+       }
+
+       if (res->count != 1) {
+               goto failed;
+       }
+
+       *options = samdb_result_uint(res->msgs[0], "options", 0);
+
+       talloc_free(tmp_ctx);
+
+       return LDB_SUCCESS;
+
+failed:
+       DEBUG(1,("Failed to find our own NTDS Settings objectGUID in the ldb!\n"));
+       talloc_free(tmp_ctx);
+       return LDB_ERR_NO_SUCH_OBJECT;
+}
index 598ceb58b9a668704b7a2e3f73f26e7dd5738daf..c86956c42f5d5b38baf3d120e2fed2c596de0c87 100644 (file)
@@ -519,7 +519,7 @@ static void dreplsrv_update_refs_send(struct dreplsrv_op_pull_source_state *st)
        r->in.req.req1.options            = 
                DRSUAPI_DS_REPLICA_UPDATE_ADD_REFERENCE |
                DRSUAPI_DS_REPLICA_UPDATE_DELETE_REFERENCE;
-       if (!lp_parm_bool(service->task->lp_ctx, NULL, "repl", "RODC", false)) {
+       if (!samdb_rodc(service->task->lp_ctx)) {
                r->in.req.req1.options |= DRSUAPI_DS_REPLICA_UPDATE_WRITEABLE;
        }