As this value is calculated new each time, we need to give it a context to live on.
If the value is the forced value during provision, a reference is taken.
This was responsible for the memory leak in the replication process. In the
example I was given, this DN appeared in memory 13596 times!
Andrew Bartlett
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Aug 14 10:05:14 CEST 2012 on sn-devel-104
14 files changed:
/*
work out the ntds settings dn for the current open ldb
*/
/*
work out the ntds settings dn for the current open ldb
*/
-struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb)
+struct ldb_dn *samdb_ntds_settings_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx)
{
TALLOC_CTX *tmp_ctx;
const char *root_attrs[] = { "dsServiceName", NULL };
{
TALLOC_CTX *tmp_ctx;
const char *root_attrs[] = { "dsServiceName", NULL };
/* see if we have a cached copy */
settings_dn = (struct ldb_dn *)ldb_get_opaque(ldb, "forced.ntds_settings_dn");
if (settings_dn) {
/* see if we have a cached copy */
settings_dn = (struct ldb_dn *)ldb_get_opaque(ldb, "forced.ntds_settings_dn");
if (settings_dn) {
+ return talloc_reference(mem_ctx, settings_dn);
- tmp_ctx = talloc_new(ldb);
+ tmp_ctx = talloc_new(mem_ctx);
if (tmp_ctx == NULL) {
goto failed;
}
if (tmp_ctx == NULL) {
goto failed;
}
* we could not handle server renames at runtime. Only
* provision sets up forced.ntds_settings_dn */
* we could not handle server renames at runtime. Only
* provision sets up forced.ntds_settings_dn */
- talloc_steal(ldb, settings_dn);
+ talloc_steal(mem_ctx, settings_dn);
talloc_free(tmp_ctx);
return settings_dn;
talloc_free(tmp_ctx);
return settings_dn;
- ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL);
+ ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL);
if (ret) {
goto failed;
}
if (ret) {
goto failed;
}
- ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL);
+ ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL);
if (ret) {
goto failed;
}
if (ret) {
goto failed;
}
*/
struct ldb_dn *samdb_server_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx)
{
*/
struct ldb_dn *samdb_server_dn(struct ldb_context *ldb, TALLOC_CTX *mem_ctx)
{
- return ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb));
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ struct ldb_dn *dn;
+ if (!tmp_ctx) {
+ return NULL;
+ }
+ dn = ldb_dn_get_parent(mem_ctx, samdb_ntds_settings_dn(ldb, tmp_ctx));
+ talloc_free(tmp_ctx);
+ return dn;
+
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc) == 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), pdc) == 0) {
is_pdc = true;
} else {
is_pdc = false;
is_pdc = true;
} else {
is_pdc = false;
- ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL);
+ ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL);
if (ret != LDB_SUCCESS) {
goto failed;
}
if (ret != LDB_SUCCESS) {
goto failed;
}
int ret;
struct ldb_result *res;
int ret;
struct ldb_result *res;
- ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, attrs, NULL);
+ ret = ldb_search(ldb, tmp_ctx, &res, samdb_ntds_settings_dn(ldb, tmp_ctx), LDB_SCOPE_BASE, attrs, NULL);
if (ret != LDB_SUCCESS) {
goto failed;
}
if (ret != LDB_SUCCESS) {
goto failed;
}
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
}
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
}
- new_dn = samdb_ntds_settings_dn(s->samdb);
+ new_dn = samdb_ntds_settings_dn(s->samdb, tmp_ctx);
if (!new_dn) {
DEBUG(0, ("failed to find NTDS settings\n"));
ret = LDB_ERR_OPERATIONS_ERROR;
if (!new_dn) {
DEBUG(0, ("failed to find NTDS settings\n"));
ret = LDB_ERR_OPERATIONS_ERROR;
- base_dn = samdb_ntds_settings_dn(s->samdb);
+ base_dn = samdb_ntds_settings_dn(s->samdb, tmp_ctx);
if (!base_dn) {
DEBUG(0, ("failed to find our own NTDS settings DN\n"));
talloc_free(tmp_ctx);
if (!base_dn) {
DEBUG(0, ("failed to find our own NTDS settings DN\n"));
talloc_free(tmp_ctx);
}
/* get a list of what NCs we are already replicating */
}
/* get a list of what NCs we are already replicating */
- ret = dsdb_search_dn(s->samdb, tmp_ctx, &res2, samdb_ntds_settings_dn(s->samdb), attrs2, 0);
+ ret = dsdb_search_dn(s->samdb, tmp_ctx, &res2, samdb_ntds_settings_dn(s->samdb, tmp_ctx), attrs2, 0);
if (ret != LDB_SUCCESS) {
DEBUG(1,("Failed to get our NC list attributes for GC update - %s\n", ldb_errstring(s->samdb)));
talloc_free(tmp_ctx);
if (ret != LDB_SUCCESS) {
DEBUG(1,("Failed to get our NC list attributes for GC update - %s\n", ldb_errstring(s->samdb)));
talloc_free(tmp_ctx);
tmp_ctx = talloc_new(ldb);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
tmp_ctx = talloc_new(ldb);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- settings_dn = samdb_ntds_settings_dn(ldb);
+ settings_dn = samdb_ntds_settings_dn(ldb, tmp_ctx);
if (!settings_dn) {
DEBUG(1, (__location__ ": failed to find our own NTDS Settings "
"DN\n"));
if (!settings_dn) {
DEBUG(1, (__location__ ": failed to find our own NTDS Settings "
"DN\n"));
enum drepl_role_master role = r->in.role;
struct fsmo_role_state *fsmo;
enum drepl_role_master role = r->in.role;
struct fsmo_role_state *fsmo;
- ntds_dn = samdb_ntds_settings_dn(service->samdb);
+ ntds_dn = samdb_ntds_settings_dn(service->samdb, tmp_ctx);
r->out.result = WERR_DS_DRA_INTERNAL_ERROR;
return NT_STATUS_OK;
}
r->out.result = WERR_DS_DRA_INTERNAL_ERROR;
return NT_STATUS_OK;
}
werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
&fsmo_role_dn, &role_owner_dn);
if (!W_ERROR_IS_OK(werr)) {
werr = dsdb_get_fsmo_role_info(tmp_ctx, service->samdb, role,
&fsmo_role_dn, &role_owner_dn);
if (!W_ERROR_IS_OK(werr)) {
r->out.result = werr;
return NT_STATUS_OK;
}
r->out.result = werr;
return NT_STATUS_OK;
}
DEBUG(2,("Unknown role %u in role transfer\n",
(unsigned)role));
r->out.result = WERR_DS_DRA_INTERNAL_ERROR;
DEBUG(2,("Unknown role %u in role transfer\n",
(unsigned)role));
r->out.result = WERR_DS_DRA_INTERNAL_ERROR;
ldb_dn_get_linearized(fsmo_role_dn),
ldb_dn_get_linearized(role_owner_dn)));
r->out.result = WERR_OK;
ldb_dn_get_linearized(fsmo_role_dn),
ldb_dn_get_linearized(role_owner_dn)));
r->out.result = WERR_OK;
fsmo);
if (!W_ERROR_IS_OK(werr)) {
r->out.result = werr;
fsmo);
if (!W_ERROR_IS_OK(werr)) {
r->out.result = werr;
return NT_STATUS_OK;
}
/* mark this message to be answered later */
msg->defer_reply = true;
dreplsrv_run_pending_ops(service);
return NT_STATUS_OK;
}
/* mark this message to be answered later */
msg->defer_reply = true;
dreplsrv_run_pending_ops(service);
tmp_ctx = talloc_new(s);
W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
tmp_ctx = talloc_new(s);
W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
- ntds_dn = samdb_ntds_settings_dn(s->samdb);
+ ntds_dn = samdb_ntds_settings_dn(s->samdb, tmp_ctx);
if (!ntds_dn) {
DEBUG(1,(__location__ ": Unable to find ntds_dn: %s\n", ldb_errstring(s->samdb)));
talloc_free(tmp_ctx);
if (!ntds_dn) {
DEBUG(1,(__location__ ": Unable to find ntds_dn: %s\n", ldb_errstring(s->samdb)));
talloc_free(tmp_ctx);
*exhausted = false;
*_alloc_pool = UINT64_MAX;
*exhausted = false;
*_alloc_pool = UINT64_MAX;
- server_dn = ldb_dn_get_parent(tmp_ctx, samdb_ntds_settings_dn(ldb));
+ server_dn = ldb_dn_get_parent(tmp_ctx, samdb_ntds_settings_dn(ldb, tmp_ctx));
if (!server_dn) {
talloc_free(tmp_ctx);
return ldb_operr(ldb);
if (!server_dn) {
talloc_free(tmp_ctx);
return ldb_operr(ldb);
return WERR_DS_DRA_INTERNAL_ERROR;
}
return WERR_DS_DRA_INTERNAL_ERROR;
}
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) == 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), fsmo_role_dn) == 0) {
/* we are the RID Manager - no need to do a
DRSUAPI_EXOP_FSMO_RID_ALLOC */
talloc_free(tmp_ctx);
/* we are the RID Manager - no need to do a
DRSUAPI_EXOP_FSMO_RID_ALLOC */
talloc_free(tmp_ctx);
}
/* DC's ntDSDSA object */
}
/* DC's ntDSDSA object */
- if (ldb_dn_compare(ac->req->op.del.dn, samdb_ntds_settings_dn(ldb)) == 0) {
+ if (ldb_dn_compare(ac->req->op.del.dn, samdb_ntds_settings_dn(ldb, ac)) == 0) {
ldb_asprintf_errstring(ldb, "objectclass: Cannot delete %s, it's the DC's ntDSDSA object!",
ldb_dn_get_linearized(ac->req->op.del.dn));
return LDB_ERR_UNWILLING_TO_PERFORM;
ldb_asprintf_errstring(ldb, "objectclass: Cannot delete %s, it's the DC's ntDSDSA object!",
ldb_dn_get_linearized(ac->req->op.del.dn));
return LDB_ERR_UNWILLING_TO_PERFORM;
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), fsmo_role_dn) != 0) {
ridalloc_poke_rid_manager(module);
ldb_asprintf_errstring(ldb, "Remote RID Set allocation needs refresh");
talloc_free(tmp_ctx);
ridalloc_poke_rid_manager(module);
ldb_asprintf_errstring(ldb, "Remote RID Set allocation needs refresh");
talloc_free(tmp_ctx);
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), fsmo_role_dn) != 0) {
ridalloc_poke_rid_manager(module);
ldb_asprintf_errstring(ldb, "Remote RID Set allocation needs refresh");
talloc_free(tmp_ctx);
ridalloc_poke_rid_manager(module);
ldb_asprintf_errstring(ldb, "Remote RID Set allocation needs refresh");
talloc_free(tmp_ctx);
- *master = (ldb_dn_compare(owner_dn, samdb_ntds_settings_dn(ldb_module_get_ctx(module))) == 0);
+ *master = (ldb_dn_compare(owner_dn, samdb_ntds_settings_dn(ldb_module_get_ctx(module), tmp_ctx)) == 0);
talloc_free(tmp_ctx);
return LDB_SUCCESS;
}
talloc_free(tmp_ctx);
return LDB_SUCCESS;
}
}
tmp_ctx = talloc_new(mem_ctx);
}
tmp_ctx = talloc_new(mem_ctx);
- ntds_settings_dn = samdb_ntds_settings_dn(ldb);
+ ntds_settings_dn = samdb_ntds_settings_dn(ldb, tmp_ctx);
if (!ntds_settings_dn) {
talloc_free(tmp_ctx);
return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR, "Failed to find NTDS settings DN");
if (!ntds_settings_dn) {
talloc_free(tmp_ctx);
return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR, "Failed to find NTDS settings DN");
struct ldb_message_element *el;
struct ldb_dn *feature_dn;
struct ldb_message_element *el;
struct ldb_dn *feature_dn;
- feature_dn = samdb_ntds_settings_dn(ldb_module_get_ctx(module));
+ tmp_ctx = talloc_new(ldb);
+
+ feature_dn = samdb_ntds_settings_dn(ldb_module_get_ctx(module), tmp_ctx);
if (feature_dn == NULL) {
if (feature_dn == NULL) {
return ldb_operr(ldb_module_get_ctx(module));
}
*feature_enabled = false;
return ldb_operr(ldb_module_get_ctx(module));
}
*feature_enabled = false;
- tmp_ctx = talloc_new(ldb);
-
ret = dsdb_module_search_dn(module, tmp_ctx, &res, feature_dn, attrs, DSDB_FLAG_NEXT_MODULE, NULL);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb,
ret = dsdb_module_search_dn(module, tmp_ctx, &res, feature_dn, attrs, DSDB_FLAG_NEXT_MODULE, NULL);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb,
}
schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
}
schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, tmp_ctx), schema->fsmo.master_dn) == 0) {
schema->fsmo.we_are_master = true;
} else {
schema->fsmo.we_are_master = false;
schema->fsmo.we_are_master = true;
} else {
schema->fsmo.we_are_master = false;
/*
* lookup the local servers Replication Epoch
*/
/*
* lookup the local servers Replication Epoch
*/
- ntds_dn = samdb_ntds_settings_dn(b_state->sam_ctx);
+ ntds_dn = samdb_ntds_settings_dn(b_state->sam_ctx, mem_ctx);
W_ERROR_HAVE_NO_MEMORY(ntds_dn);
ret = ldb_search(b_state->sam_ctx, mem_ctx, &ntds_res,
W_ERROR_HAVE_NO_MEMORY(ntds_dn);
ret = ldb_search(b_state->sam_ctx, mem_ctx, &ntds_res,
return WERR_DS_DRA_INTERNAL_ERROR;
}
return WERR_DS_DRA_INTERNAL_ERROR;
}
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, mem_ctx), fsmo_role_dn) != 0) {
/* we're not the RID Manager - go away */
DEBUG(0,(__location__ ": RID Alloc request when not RID Manager\n"));
ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
/* we're not the RID Manager - go away */
DEBUG(0,(__location__ ": RID Alloc request when not RID Manager\n"));
ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
return WERR_DS_DRA_INTERNAL_ERROR;
}
return WERR_DS_DRA_INTERNAL_ERROR;
}
- if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), fsmo_role_dn) != 0) {
+ if (ldb_dn_compare(samdb_ntds_settings_dn(ldb, mem_ctx), fsmo_role_dn) != 0) {
/* we're not the current owner - go away */
DEBUG(0,(__location__ ": FSMO transfer request when not owner\n"));
ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;
/* we're not the current owner - go away */
DEBUG(0,(__location__ ": FSMO transfer request when not owner\n"));
ctr6->extended_ret = DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER;