The branch, master has been updated
       via  9e92899... s4:selftest: run RPC-SAMR-LARGE-DC against the 
vampire_dc to test the rid alloc code
       via  de632de... selftest/Samba4: set dreplsrv:periodic_startup_interval 
= 0
       via  538bb9b... s4:dsdb/repl: expose drsuapi_DsExtendedError to the 
caller (e.g. the ridalloc client)
       via  49deed5... s4:drepl_out_helpers: don't return NT_STATUS_OK, if an 
extended operation doesn't return success
       via  658a0f9... s4:drepl_ridalloc: only ask the rid master for a new rid 
pool if we need to.
       via  afba620... s4:dsdb:ridalloc: use ridalloc_ridset_values 
infrastructure in ridalloc_allocate_rid_pool_fsmo()
       via  cd8d8df... s4:dsdb:ridalloc: use ridalloc_ridset_values 
infrastructure in ridalloc_allocate_rid()
       via  3b8c927... s4:dsdb:ridalloc: use ridalloc_ridset_values 
infrastructure in ridalloc_create_rid_set_ntds()
       via  12d26d5... s4:dsdb:ridalloc: add ridalloc_ridset_values 
infrastructure
       via  bbed1fd... s4:dsdb:ridalloc: use 
dsdb_module_constrainted_update_uint64() to update rIDAvailablePool
       via  ad17333... s4:dsdb:ridalloc.c: fix C++ warning
       via  217177a... s4:dsdb: add dsdb_module_constrainted_update_uint32/64() 
wrapper functions
       via  65ca5a3... s4:dsdb: add dsdb_msg_constrainted_update_uint32/64() 
wrapper functions
       via  1d6f321... s4:dsdb: add dsdb_module_constrainted_update_int32/64() 
functions
       via  388e955... s4:dsdb: add dsdb_msg_constrainted_update_int32/64() 
functions
      from  514c596... ldb:common/ldb_dn.c - "ldb_dn_get_parent" - no need to 
manipulate the real DN

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 9e928995f0289fcf56bfa60a7541a829e2d67a38
Author: Stefan Metzmacher <[email protected]>
Date:   Fri Jul 9 09:24:30 2010 +0200

    s4:selftest: run RPC-SAMR-LARGE-DC against the vampire_dc to test the rid 
alloc code
    
    metze

commit de632de6ef10cba5fd2591f1d01ab447dae595c8
Author: Stefan Metzmacher <[email protected]>
Date:   Fri Jul 9 09:23:04 2010 +0200

    selftest/Samba4: set dreplsrv:periodic_startup_interval = 0
    
    metze

commit 538bb9b3ec2d3250bb97fe6f6f01e6917399fd01
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 16:20:11 2010 +0200

    s4:dsdb/repl: expose drsuapi_DsExtendedError to the caller (e.g. the 
ridalloc client)
    
    metze

commit 49deed5a77af0a774cf186c2332416fbf6bba05b
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 16:18:21 2010 +0200

    s4:drepl_out_helpers: don't return NT_STATUS_OK, if an extended operation 
doesn't return success
    
    metze

commit 658a0f9ef84aa16c270d715283f38b9bb9e683c1
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 15:38:16 2010 +0200

    s4:drepl_ridalloc: only ask the rid master for a new rid pool if we need to.
    
    if we are at least half-exhausted then ask for a new pool.
    
    This fixes a bug where we're sending unintialized alloc_pool
    variable as exop->fsmo_info to the rid master and get back
    DRSUAPI_EXOP_ERR_PARAM_ERROR.
    
    metze

commit afba6204a31908396f4bebb7b5885e48670bda73
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 15:14:59 2010 +0200

    s4:dsdb:ridalloc: use ridalloc_ridset_values infrastructure in 
ridalloc_allocate_rid_pool_fsmo()
    
    metze

commit cd8d8dfe1445879d91d922abef83dbea8f1eed26
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 21:38:28 2010 +0200

    s4:dsdb:ridalloc: use ridalloc_ridset_values infrastructure in 
ridalloc_allocate_rid()
    
    metze

commit 3b8c9276dcfa349013450c18d09bfd1b78e6224e
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 15:10:07 2010 +0200

    s4:dsdb:ridalloc: use ridalloc_ridset_values infrastructure in 
ridalloc_create_rid_set_ntds()
    
    metze

commit 12d26d59bddaa7d3469b4e9ecab4146a9ea67180
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 12:32:33 2010 +0200

    s4:dsdb:ridalloc: add ridalloc_ridset_values infrastructure
    
    metze

commit bbed1fdfcdcc0d270bb861bf06b509a1655a13a2
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 12:34:15 2010 +0200

    s4:dsdb:ridalloc: use dsdb_module_constrainted_update_uint64() to update 
rIDAvailablePool
    
    metze

commit ad173331148a9fdd793cc5fa4776bdfd53bb4727
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 12:06:39 2010 +0200

    s4:dsdb:ridalloc.c: fix C++ warning
    
    metze

commit 217177a4df55439cec1d2563ab1af8fbdfe4a991
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 12:02:42 2010 +0200

    s4:dsdb: add dsdb_module_constrainted_update_uint32/64() wrapper functions
    
    metze

commit 65ca5a3542cb1ccb07da0831c61c043f4632ffa8
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 12:01:44 2010 +0200

    s4:dsdb: add dsdb_msg_constrainted_update_uint32/64() wrapper functions
    
    metze

commit 1d6f321a918699906cabbe3ee2970bd0a635180b
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 11:32:59 2010 +0200

    s4:dsdb: add dsdb_module_constrainted_update_int32/64() functions
    
    metze

commit 388e955f28a578e5421182c0aa3afe9da27a6c34
Author: Stefan Metzmacher <[email protected]>
Date:   Thu Jul 8 11:32:26 2010 +0200

    s4:dsdb: add dsdb_msg_constrainted_update_int32/64() functions
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 selftest/target/Samba4.pm                 |    1 +
 source4/dsdb/repl/drepl_out_helpers.c     |   17 +-
 source4/dsdb/repl/drepl_out_pull.c        |    4 +-
 source4/dsdb/repl/drepl_ridalloc.c        |   55 +++-
 source4/dsdb/repl/drepl_service.h         |    5 +-
 source4/dsdb/samdb/ldb_modules/ridalloc.c |  435 +++++++++++++++++------------
 source4/dsdb/samdb/ldb_modules/util.c     |  198 +++++++++++++
 source4/selftest/tests.sh                 |    5 +
 8 files changed, 528 insertions(+), 192 deletions(-)


Changeset truncated at 500 lines:

diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index b574623..f0da581 100644
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -589,6 +589,7 @@ sub provision_raw_step1($$)
         dns update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_dnsupdate 
--all-interfaces --use-file=$ctx->{dns_host_file}
         spn update command = $ENV{SRCDIR_ABS}/scripting/bin/samba_spnupdate
         resolv:host file = $ctx->{dns_host_file}
+       dreplsrv:periodic_startup_interval = 0
 ";
 
        if (defined($ctx->{sid_generator}) && $ctx->{sid_generator} ne 
"internal") {
diff --git a/source4/dsdb/repl/drepl_out_helpers.c 
b/source4/dsdb/repl/drepl_out_helpers.c
index 56e1257..2411052 100644
--- a/source4/dsdb/repl/drepl_out_helpers.c
+++ b/source4/dsdb/repl/drepl_out_helpers.c
@@ -365,7 +365,7 @@ static void dreplsrv_op_pull_source_get_changes_done(struct 
tevent_req *subreq)
        uint32_t ctr_level = 0;
        struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
        struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
-
+       enum drsuapi_DsExtendedError extended_ret;
        state->ndr_struct_ptr = NULL;
 
        status = dcerpc_drsuapi_DsGetNCChanges_r_recv(subreq, r);
@@ -420,6 +420,21 @@ static void 
dreplsrv_op_pull_source_get_changes_done(struct tevent_req *subreq)
                        tevent_req_nterror(req, status);
                        return;
                }
+               extended_ret = ctr6->extended_ret;
+       }
+
+       if (ctr_level == 1) {
+               extended_ret = ctr1->extended_ret;
+       }
+
+       if (state->op->extended_op != DRSUAPI_EXOP_NONE) {
+               state->op->extended_ret = extended_ret;
+
+               if (extended_ret != DRSUAPI_EXOP_ERR_SUCCESS) {
+                       status = NT_STATUS_UNSUCCESSFUL;
+                       tevent_req_nterror(req, status);
+                       return;
+               }
        }
 
        dreplsrv_op_pull_source_apply_changes_trigger(req, r, ctr_level, ctr1, 
ctr6);
diff --git a/source4/dsdb/repl/drepl_out_pull.c 
b/source4/dsdb/repl/drepl_out_pull.c
index c82b48d..e9b57a1 100644
--- a/source4/dsdb/repl/drepl_out_pull.c
+++ b/source4/dsdb/repl/drepl_out_pull.c
@@ -154,13 +154,13 @@ static void dreplsrv_pending_op_callback(struct 
tevent_req *subreq)
 
        DEBUG(1,("dreplsrv_op_pull_source(%s/%s) for %s failures[%u]\n",
                 win_errstr(rf->result_last_attempt),
-                win_errstr(rf->result_last_attempt),
+                nt_errstr(werror_to_ntstatus(rf->result_last_attempt)),
                 ldb_dn_get_linearized(op->source_dsa->partition->dn),
                 rf->consecutive_sync_failures));
 
 done:
        if (op->callback) {
-               op->callback(s, rf->result_last_attempt);
+               op->callback(s, rf->result_last_attempt, op->extended_ret);
        }
        talloc_free(op);
        s->ops.current = NULL;
diff --git a/source4/dsdb/repl/drepl_ridalloc.c 
b/source4/dsdb/repl/drepl_ridalloc.c
index 7b225d5..eaff581 100644
--- a/source4/dsdb/repl/drepl_ridalloc.c
+++ b/source4/dsdb/repl/drepl_ridalloc.c
@@ -100,11 +100,13 @@ static WERROR drepl_create_rid_manager_source_dsa(struct 
dreplsrv_service *servi
 /*
   called when a rid allocation request has completed
  */
-static void drepl_new_rid_pool_callback(struct dreplsrv_service *service, 
WERROR werr)
+static void drepl_new_rid_pool_callback(struct dreplsrv_service *service,
+                                       WERROR werr,
+                                       enum drsuapi_DsExtendedError ext_err)
 {
        if (!W_ERROR_IS_OK(werr)) {
-               DEBUG(0,(__location__ ": RID Manager failed RID allocation - 
%s\n",
-                        win_errstr(werr)));
+               DEBUG(0,(__location__ ": RID Manager failed RID allocation - %s 
- extended_ret[0x%X]\n",
+                        win_errstr(werr), ext_err));
        } else {
                DEBUG(3,(__location__ ": RID Manager completed RID allocation 
OK\n"));
        }
@@ -145,15 +147,28 @@ static WERROR drepl_request_new_rid_pool(struct 
dreplsrv_service *service,
 /*
   see if we are on the last pool we have
  */
-static int drepl_ridalloc_pool_exhausted(struct ldb_context *ldb, bool 
*exhausted, uint64_t *alloc_pool)
+static int drepl_ridalloc_pool_exhausted(struct ldb_context *ldb,
+                                        bool *exhausted,
+                                        uint64_t *_alloc_pool)
 {
        struct ldb_dn *server_dn, *machine_dn, *rid_set_dn;
        TALLOC_CTX *tmp_ctx = talloc_new(ldb);
-       uint64_t prev_alloc_pool;
-       const char *attrs[] = { "rIDPreviousAllocationPool", 
"rIDAllocationPool", NULL };
+       uint64_t alloc_pool;
+       uint64_t prev_pool;
+       uint32_t prev_pool_lo, prev_pool_hi;
+       uint32_t next_rid;
+       static const char * const attrs[] = {
+               "rIDAllocationPool",
+               "rIDPreviousAllocationPool",
+               "rIDNextRid",
+               NULL
+       };
        int ret;
        struct ldb_result *res;
 
+       *exhausted = false;
+       *_alloc_pool = UINT64_MAX;
+
        server_dn = ldb_dn_get_parent(tmp_ctx, samdb_ntds_settings_dn(ldb));
        if (!server_dn) {
                talloc_free(tmp_ctx);
@@ -171,6 +186,7 @@ static int drepl_ridalloc_pool_exhausted(struct ldb_context 
*ldb, bool *exhauste
        ret = samdb_reference_dn(ldb, tmp_ctx, machine_dn, "rIDSetReferences", 
&rid_set_dn);
        if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE) {
                *exhausted = true;
+               *_alloc_pool = 0;
                talloc_free(tmp_ctx);
                return LDB_SUCCESS;
        }
@@ -189,15 +205,24 @@ static int drepl_ridalloc_pool_exhausted(struct 
ldb_context *ldb, bool *exhauste
                return ret;
        }
 
-       *alloc_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDAllocationPool", 0);
-       prev_alloc_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDPreviousAllocationPool", 0);
+       alloc_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDAllocationPool", 0);
+       prev_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDPreviousAllocationPool", 0);
+       prev_pool_lo = prev_pool & 0xFFFFFFFF;
+       prev_pool_hi = prev_pool >> 32;
+       next_rid = ldb_msg_find_attr_as_uint(res->msgs[0], "rIDNextRid", 0);
 
-       if (*alloc_pool != prev_alloc_pool) {
-               *exhausted = false;
-       } else {
-               *exhausted = true;
+       if (alloc_pool != prev_pool) {
+               talloc_free(tmp_ctx);
+               return LDB_SUCCESS;
+       }
+
+       if (next_rid < (prev_pool_hi + prev_pool_lo)/2) {
+               talloc_free(tmp_ctx);
+               return LDB_SUCCESS;
        }
 
+       *exhausted = true;
+       *_alloc_pool = alloc_pool;
        talloc_free(tmp_ctx);
        return LDB_SUCCESS;
 }
@@ -265,6 +290,12 @@ WERROR dreplsrv_ridalloc_check_rid_pool(struct 
dreplsrv_service *service)
                return WERR_DS_DRA_INTERNAL_ERROR;
        }
 
+       if (!exhausted) {
+               /* don't need a new pool */
+               talloc_free(tmp_ctx);
+               return WERR_OK;
+       }
+
        DEBUG(2,(__location__ ": Requesting more RIDs from RID Manager\n"));
 
        werr = drepl_request_new_rid_pool(service, rid_manager_dn, 
fsmo_role_dn, alloc_pool);
diff --git a/source4/dsdb/repl/drepl_service.h 
b/source4/dsdb/repl/drepl_service.h
index 88be769..eefd4da 100644
--- a/source4/dsdb/repl/drepl_service.h
+++ b/source4/dsdb/repl/drepl_service.h
@@ -101,7 +101,9 @@ struct dreplsrv_partition {
        struct dreplsrv_partition_source_dsa *sources;
 };
 
-typedef void (*dreplsrv_fsmo_callback_t)(struct dreplsrv_service *, WERROR );
+typedef void (*dreplsrv_fsmo_callback_t)(struct dreplsrv_service *,
+                                        WERROR,
+                                        enum drsuapi_DsExtendedError);
 
 struct dreplsrv_out_operation {
        struct dreplsrv_out_operation *prev, *next;
@@ -113,6 +115,7 @@ struct dreplsrv_out_operation {
        enum drsuapi_DsExtendedOperation extended_op;
        uint64_t fsmo_info;
        dreplsrv_fsmo_callback_t callback;
+       enum drsuapi_DsExtendedError extended_ret;
 };
 
 struct dreplsrv_notify_operation {
diff --git a/source4/dsdb/samdb/ldb_modules/ridalloc.c 
b/source4/dsdb/samdb/ldb_modules/ridalloc.c
index 91d48ba..2b0c4b9 100644
--- a/source4/dsdb/samdb/ldb_modules/ridalloc.c
+++ b/source4/dsdb/samdb/ldb_modules/ridalloc.c
@@ -68,7 +68,8 @@ static void ridalloc_poke_rid_manager(struct ldb_module 
*module)
        struct messaging_context *msg;
        struct server_id *server;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
-       struct loadparm_context *lp_ctx = ldb_get_opaque(ldb, "loadparm");
+       struct loadparm_context *lp_ctx =
+               (struct loadparm_context *)ldb_get_opaque(ldb, "loadparm");
        TALLOC_CTX *tmp_ctx = talloc_new(module);
 
        msg = messaging_client_init(tmp_ctx, lp_messaging_path(tmp_ctx, lp_ctx),
@@ -93,6 +94,89 @@ static void ridalloc_poke_rid_manager(struct ldb_module 
*module)
 }
 
 
+static const char * const ridalloc_ridset_attrs[] = {
+       "rIDAllocationPool",
+       "rIDPreviousAllocationPool",
+       "rIDNextRID",
+       "rIDUsedPool",
+       NULL
+};
+
+struct ridalloc_ridset_values {
+       uint64_t alloc_pool;
+       uint64_t prev_pool;
+       uint32_t next_rid;
+       uint32_t used_pool;
+};
+
+static void ridalloc_get_ridset_values(struct ldb_message *msg, struct 
ridalloc_ridset_values *v)
+{
+       v->alloc_pool = ldb_msg_find_attr_as_uint64(msg, "rIDAllocationPool", 
UINT64_MAX);
+       v->prev_pool = ldb_msg_find_attr_as_uint64(msg, 
"rIDPreviousAllocationPool", UINT64_MAX);
+       v->next_rid = ldb_msg_find_attr_as_uint(msg, "rIDNextRID", UINT32_MAX);
+       v->used_pool = ldb_msg_find_attr_as_uint(msg, "rIDUsedPool", 
UINT32_MAX);
+}
+
+static int ridalloc_set_ridset_values(struct ldb_module *module,
+                                     struct ldb_message *msg,
+                                     const struct ridalloc_ridset_values *o,
+                                     const struct ridalloc_ridset_values *n)
+{
+       const uint32_t *o32, *n32;
+       const uint64_t *o64, *n64;
+       int ret;
+
+#define SETUP_PTRS(field, optr, nptr, max) do { \
+       optr = &o->field; \
+       nptr = &n->field; \
+       if (o->field == max) { \
+               optr = NULL; \
+       } \
+       if (n->field == max) { \
+               nptr = NULL; \
+       } \
+       if (o->field == n->field) { \
+               optr = NULL; \
+               nptr = NULL; \
+       } \
+} while(0)
+
+       SETUP_PTRS(alloc_pool, o64, n64, UINT64_MAX);
+       ret = dsdb_msg_constrainted_update_uint64(module, msg,
+                                                 "rIDAllocationPool",
+                                                 o64, n64);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       SETUP_PTRS(prev_pool, o64, n64, UINT64_MAX);
+       ret = dsdb_msg_constrainted_update_uint64(module, msg,
+                                                 "rIDPreviousAllocationPool",
+                                                 o64, n64);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       SETUP_PTRS(next_rid, o32, n32, UINT32_MAX);
+       ret = dsdb_msg_constrainted_update_uint32(module, msg,
+                                                 "rIDNextRID",
+                                                 o32, n32);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       SETUP_PTRS(used_pool, o32, n32, UINT32_MAX);
+       ret = dsdb_msg_constrainted_update_uint32(module, msg,
+                                                 "rIDUsedPool",
+                                                 o32, n32);
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+#undef SETUP_PTRS
+
+       return LDB_SUCCESS;
+}
+
 /*
   allocate a new range of RIDs in the RID Manager object
  */
@@ -138,8 +222,8 @@ static int ridalloc_rid_manager_allocate(struct ldb_module 
*module, struct ldb_d
        /* and new rIDAvailablePool value */
        new_rid_pool = rid_pool_lo | (((uint64_t)rid_pool_hi)<<32);
 
-       ret = dsdb_module_constrainted_update_integer(module, rid_manager_dn, 
"rIDAvailablePool",
-                                                     rid_pool, new_rid_pool);
+       ret = dsdb_module_constrainted_update_uint64(module, rid_manager_dn, 
"rIDAvailablePool",
+                                                    &rid_pool, &new_rid_pool);
        if (ret != LDB_SUCCESS) {
                ldb_asprintf_errstring(ldb, "Failed to update rIDAvailablePool 
- %s",
                                       ldb_errstring(ldb));
@@ -162,9 +246,20 @@ static int ridalloc_create_rid_set_ntds(struct ldb_module 
*module, TALLOC_CTX *m
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
        struct ldb_dn *server_dn, *machine_dn, *rid_set_dn;
        int ret;
-       uint64_t dc_pool;
        struct ldb_message *msg;
        struct ldb_context *ldb = ldb_module_get_ctx(module);
+       static const struct ridalloc_ridset_values o = {
+               .alloc_pool     = UINT64_MAX,
+               .prev_pool      = UINT64_MAX,
+               .next_rid       = UINT32_MAX,
+               .used_pool      = UINT32_MAX,
+       };
+       struct ridalloc_ridset_values n = {
+               .alloc_pool     = 0,
+               .prev_pool      = 0,
+               .next_rid       = 0,
+               .used_pool      = 0,
+       };
 
        /*
          steps:
@@ -203,7 +298,7 @@ static int ridalloc_create_rid_set_ntds(struct ldb_module 
*module, TALLOC_CTX *m
        }
 
        /* grab a pool from the RID Manager object */
-       ret = ridalloc_rid_manager_allocate(module, rid_manager_dn, &dc_pool);
+       ret = ridalloc_rid_manager_allocate(module, rid_manager_dn, 
&n.alloc_pool);
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
                return ret;
@@ -218,24 +313,8 @@ static int ridalloc_create_rid_set_ntds(struct ldb_module 
*module, TALLOC_CTX *m
                talloc_free(tmp_ctx);
                return ret;
        }
-       ret = ldb_msg_add_fmt(msg, "rIDAllocationPool", "%llu", (unsigned long 
long)dc_pool);
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
 
-       /* w2k8-r2 sets these to zero when first created */
-       ret = ldb_msg_add_fmt(msg, "rIDPreviousAllocationPool", "0");
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-       ret = ldb_msg_add_fmt(msg, "rIDUsedPool", "0");
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-       ret = ldb_msg_add_fmt(msg, "rIDNextRID", "0");
+       ret = ridalloc_set_ridset_values(module, msg, &o, &n);
        if (ret != LDB_SUCCESS) {
                talloc_free(tmp_ctx);
                return ret;
@@ -322,65 +401,10 @@ static int ridalloc_create_own_rid_set(struct ldb_module 
*module, TALLOC_CTX *me
 }
 
 /*
-  refresh a RID Set object for the specified DC
-  also returns the first RID for the new pool
- */
-static int ridalloc_refresh_rid_set_ntds(struct ldb_module *module,
-                                        struct ldb_dn *rid_manager_dn,
-                                        struct ldb_dn *ntds_dn, uint64_t 
*new_pool)
-{
-       TALLOC_CTX *tmp_ctx = talloc_new(module);
-       struct ldb_dn *server_dn, *machine_dn, *rid_set_dn;
-       struct ldb_context *ldb = ldb_module_get_ctx(module);
-       int ret;
-
-       /* grab a pool from the RID Manager object */
-       ret = ridalloc_rid_manager_allocate(module, rid_manager_dn, new_pool);
-       if (ret != LDB_SUCCESS) {
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-
-       server_dn = ldb_dn_get_parent(tmp_ctx, ntds_dn);
-       if (!server_dn) {
-               talloc_free(tmp_ctx);
-               return ldb_module_oom(module);
-       }
-
-       ret = dsdb_module_reference_dn(module, tmp_ctx, server_dn, 
"serverReference", &machine_dn);
-       if (ret != LDB_SUCCESS) {
-               ldb_asprintf_errstring(ldb, "Failed to find serverReference in 
%s - %s",
-                                      ldb_dn_get_linearized(server_dn), 
ldb_errstring(ldb));
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-
-       ret = dsdb_module_reference_dn(module, tmp_ctx, machine_dn, 
"rIDSetReferences", &rid_set_dn);
-       if (ret != LDB_SUCCESS) {
-               ldb_asprintf_errstring(ldb, "Failed to find rIDSetReferences in 
%s - %s",
-                                      ldb_dn_get_linearized(machine_dn), 
ldb_errstring(ldb));
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-
-       ret = dsdb_module_set_integer(module, rid_set_dn, "rIDAllocationPool", 
*new_pool);
-       if (ret != LDB_SUCCESS) {
-               ldb_asprintf_errstring(ldb, "Failed to modify RID Set object %s 
- %s",
-                                      ldb_dn_get_linearized(rid_set_dn), 
ldb_errstring(ldb));
-               talloc_free(tmp_ctx);
-               return ret;
-       }
-
-       talloc_free(tmp_ctx);
-       return LDB_SUCCESS;
-}
-
-
-/*
   get a new RID pool for ourselves
   also returns the first rid for the new pool
  */
-static int ridalloc_refresh_own_pool(struct ldb_module *module, uint64_t 
*new_pool)
+static int ridalloc_new_own_pool(struct ldb_module *module, uint64_t *new_pool)
 {
        TALLOC_CTX *tmp_ctx = talloc_new(module);
        struct ldb_dn *rid_manager_dn, *fsmo_role_dn;
@@ -412,7 +436,13 @@ static int ridalloc_refresh_own_pool(struct ldb_module 
*module, uint64_t *new_po
                return LDB_ERR_UNWILLING_TO_PERFORM;
        }
 
-       ret = ridalloc_refresh_rid_set_ntds(module, rid_manager_dn, 
fsmo_role_dn, new_pool);
+       /* grab a pool from the RID Manager object */
+       ret = ridalloc_rid_manager_allocate(module, rid_manager_dn, new_pool);
+       if (ret != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
        talloc_free(tmp_ctx);
        return ret;
 }
@@ -425,15 +455,13 @@ static int ridalloc_refresh_own_pool(struct ldb_module 
*module, uint64_t *new_po
 int ridalloc_allocate_rid(struct ldb_module *module, uint32_t *rid)
 {
        struct ldb_context *ldb;
-       static const char * const attrs[] = { "rIDAllocationPool", 
"rIDPreviousAllocationPool",
-                                             "rIDNextRID" , "rIDUsedPool", 
NULL };
        int ret;
        struct ldb_dn *rid_set_dn;
        struct ldb_result *res;
-       uint64_t alloc_pool, prev_alloc_pool;
-       uint32_t prev_alloc_pool_lo, prev_alloc_pool_hi;
-       uint32_t rid_used_pool;
-       int prev_rid;
+       struct ldb_message *msg;
+       struct ridalloc_ridset_values oridset;
+       struct ridalloc_ridset_values nridset;
+       uint32_t prev_pool_lo, prev_pool_hi;
        TALLOC_CTX *tmp_ctx = talloc_new(module);
 
        (*rid) = 0;
@@ -451,7 +479,7 @@ int ridalloc_allocate_rid(struct ldb_module *module, 
uint32_t *rid)
        }
 
        ret = dsdb_module_search_dn(module, tmp_ctx, &res, rid_set_dn,
-                                   attrs, DSDB_FLAG_NEXT_MODULE);
+                                   ridalloc_ridset_attrs, 
DSDB_FLAG_NEXT_MODULE);
        if (ret != LDB_SUCCESS) {
                ldb_asprintf_errstring(ldb, __location__ ": No RID Set %s",
                                       ldb_dn_get_linearized(rid_set_dn));
@@ -459,107 +487,125 @@ int ridalloc_allocate_rid(struct ldb_module *module, 
uint32_t *rid)
                return ret;
        }
 
-       prev_alloc_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDPreviousAllocationPool", 0);
-       alloc_pool = ldb_msg_find_attr_as_uint64(res->msgs[0], 
"rIDAllocationPool", 0);
-       prev_rid = ldb_msg_find_attr_as_int(res->msgs[0], "rIDNextRID", 0);
-       rid_used_pool = ldb_msg_find_attr_as_int(res->msgs[0], "rIDUsedPool", 
0);
-       if (alloc_pool == 0) {
+       ridalloc_get_ridset_values(res->msgs[0], &oridset);
+       if (oridset.alloc_pool == UINT64_MAX) {
                ldb_asprintf_errstring(ldb, __location__ ": Bad RID Set %s",
                                       ldb_dn_get_linearized(rid_set_dn));
                talloc_free(tmp_ctx);
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       prev_alloc_pool_lo = prev_alloc_pool & 0xFFFFFFFF;
-       prev_alloc_pool_hi = prev_alloc_pool >> 32;
-       if (prev_rid >= prev_alloc_pool_hi) {
-               if (prev_alloc_pool == 0) {
-                       ret = dsdb_module_set_integer(module, rid_set_dn, 
"rIDPreviousAllocationPool", alloc_pool);


-- 
Samba Shared Repository

Reply via email to