#include "dsdb/samdb/samdb.h"
#include "lib/messaging/irpc.h"
#include "librpc/gen_ndr/ndr_misc.h"
+#include "dsdb/kcc/kcc_service.h"
#define FLAG_CR_NTDS_NC 0x00000001
#define FLAG_CR_NTDS_DOMAIN 0x00000002
/**
* get all bridgehead DCs satisfying the given criteria.
*/
-static NTSTATUS kcctpl_get_all_bridgehead_dcs(struct ldb_context *ldb,
+static NTSTATUS kcctpl_get_all_bridgehead_dcs(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct GUID site_guid,
struct ldb_message *cross_ref,
tmp_ctx = talloc_new(mem_ctx);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- sites_dn = samdb_sites_dn(ldb, tmp_ctx);
+ sites_dn = samdb_sites_dn(service->samdb, tmp_ctx);
if (!sites_dn) {
DEBUG(1, (__location__ ": failed to find our own Sites DN\n"));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- ret = ldb_search(ldb, tmp_ctx, &res, sites_dn, LDB_SCOPE_ONELEVEL,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, sites_dn, LDB_SCOPE_ONELEVEL,
attrs, "(&(objectClass=site)(objectGUID=%s))",
GUID_string(tmp_ctx, &site_guid));
if (ret != LDB_SUCCESS) {
}
site = res->msgs[0];
- schemas_dn = ldb_get_schema_basedn(ldb);
+ schemas_dn = ldb_get_schema_basedn(service->samdb);
if (!schemas_dn) {
DEBUG(1, (__location__ ": failed to find our own Schemas DN\n"));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- ret = ldb_search(ldb, tmp_ctx, &res, schemas_dn, LDB_SCOPE_SUBTREE,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, schemas_dn, LDB_SCOPE_SUBTREE,
NULL,
"(&(lDAPDisplayName=nTDSDSA)(objectClass=classSchema))");
if (ret != LDB_SUCCESS) {
ZERO_STRUCT(all_dcs_in_site);
- ret = ldb_search(ldb, tmp_ctx, &res, site->dn, LDB_SCOPE_SUBTREE,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, site->dn, LDB_SCOPE_SUBTREE,
dc_attrs, "objectCategory=%s",
ldb_dn_get_linearized(schema->dn));
if (ret != LDB_SUCCESS) {
val = el->values[j];
- dn = ldb_dn_from_ldb_val(tmp_ctx, ldb, &val);
+ dn = ldb_dn_from_ldb_val(tmp_ctx, service->samdb, &val);
if (!dn) {
DEBUG(1, (__location__ ": failed to read a DN "
"from bridgeheadServerListBL "
behavior_version = samdb_result_int64(dc,
"msDS-Behavior-Version", 0);
/* TODO: cr!nCName corresponds to default NC */
- if (rodc && true && behavior_version < DS_BEHAVIOR_WIN2008) {
+ if (service->am_rodc && true && behavior_version < DS_BEHAVIOR_WIN2008) {
continue;
}
- ret = ldb_search(ldb, tmp_ctx, &parent_res, parent_dn,
+ ret = ldb_search(service->samdb, tmp_ctx, &parent_res, parent_dn,
LDB_SCOPE_BASE, parent_attrs , NULL);
dc_transport_address = samdb_result_string(parent_res->msgs[0],
dc_guid = samdb_result_guid(dc, "objectGUID");
- status = kcctpl_bridgehead_dc_failed(ldb, dc_guid,
+ status = kcctpl_bridgehead_dc_failed(service->samdb, dc_guid,
detect_failed_dcs,
&failed);
if (NT_STATUS_IS_ERR(status)) {
/**
* get a bridgehead DC.
*/
-static NTSTATUS kcctpl_get_bridgehead_dc(struct ldb_context *ldb,
+static NTSTATUS kcctpl_get_bridgehead_dc(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct GUID site_guid,
struct ldb_message *cross_ref,
struct message_list dsa_list;
NTSTATUS status;
- status = kcctpl_get_all_bridgehead_dcs(ldb, mem_ctx,
+ status = kcctpl_get_all_bridgehead_dcs(service, mem_ctx,
site_guid, cross_ref, transport,
partial_replica_okay,
detect_failed_dcs, &dsa_list);
/*
* color each vertex to indicate which kinds of NC replicas it contains.
*/
-static NTSTATUS kcctpl_color_vertices(struct ldb_context *ldb,
+static NTSTATUS kcctpl_color_vertices(struct kccsrv_service *service,
struct kcctpl_graph *graph,
struct ldb_message *cross_ref,
bool detect_failed_dcs,
found_failed_dcs = false;
- tmp_ctx = talloc_new(ldb);
+ tmp_ctx = talloc_new(service);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- sites_dn = samdb_sites_dn(ldb, tmp_ctx);
+ sites_dn = samdb_sites_dn(service->samdb, tmp_ctx);
if (!sites_dn) {
DEBUG(1, (__location__ ": failed to find our own Sites DN\n"));
vertex = &graph->vertices.data[i];
- ret = ldb_search(ldb, tmp_ctx, &res, sites_dn,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, sites_dn,
LDB_SCOPE_SUBTREE, attrs, "objectGUID=%s",
GUID_string(tmp_ctx, &vertex->id));
if (ret != LDB_SUCCESS) {
}
site = res->msgs[0];
- nc_name = samdb_result_dn(ldb, tmp_ctx, cross_ref,
+ nc_name = samdb_result_dn(service->samdb, tmp_ctx, cross_ref,
"nCName", NULL);
if (!nc_name) {
DEBUG(1, (__location__ ": failed to find nCName "
}
}
- site = kcctpl_local_site(ldb, tmp_ctx);
+ site = kcctpl_local_site(service->samdb, tmp_ctx);
if (!site) {
DEBUG(1, (__location__ ": failed to find our own local DC's "
"site\n"));
vertex = &graph->vertices.data[i];
- transports_dn = kcctpl_transports_dn(ldb, tmp_ctx);
+ transports_dn = kcctpl_transports_dn(service->samdb, tmp_ctx);
if (!transports_dn) {
DEBUG(1, (__location__ ": failed to find our own "
"Inter-Site Transports DN\n"));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- ret = ldb_search(ldb, tmp_ctx, &res, transports_dn,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, transports_dn,
LDB_SCOPE_ONELEVEL, attrs,
"objectClass=interSiteTransport");
if (ret != LDB_SUCCESS) {
continue;
}
- status = kcctpl_get_bridgehead_dc(ldb, tmp_ctx,
+ status = kcctpl_get_bridgehead_dc(service, tmp_ctx,
site_vertex->id,
cross_ref, transport,
partial_replica_okay,
* copy all spanning tree edges from 'output_edges' that contain the vertex for
* DCs in the local DC's site.
*/
-static NTSTATUS kcctpl_copy_output_edges(struct ldb_context *ldb,
+static NTSTATUS kcctpl_copy_output_edges(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct kcctpl_graph *graph,
struct kcctpl_multi_edge_list output_edges,
ZERO_STRUCT(copy);
- tmp_ctx = talloc_new(ldb);
+ tmp_ctx = talloc_new(service);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- site = kcctpl_local_site(ldb, tmp_ctx);
+ site = kcctpl_local_site(service->samdb, tmp_ctx);
if (!site) {
DEBUG(1, (__location__ ": failed to find our own local DC's "
"site\n"));
* calculate the spanning tree and return the edges that include the vertex for
* the local site.
*/
-static NTSTATUS kcctpl_get_spanning_tree_edges(struct ldb_context *ldb,
+static NTSTATUS kcctpl_get_spanning_tree_edges(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct kcctpl_graph *graph,
uint32_t *_component_count,
component_count = kcctpl_count_components(graph);
- status = kcctpl_copy_output_edges(ldb, tmp_ctx, graph, output_edges,
+ status = kcctpl_copy_output_edges(service, tmp_ctx, graph, output_edges,
&st_edge_list);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(1, (__location__ ": failed to copy edge list: %s\n",
* creat an nTDSConnection object with the given parameters if one does not
* already exist.
*/
-static NTSTATUS kcctpl_create_connection(struct ldb_context *ldb,
+static NTSTATUS kcctpl_create_connection(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct ldb_message *cross_ref,
struct ldb_message *r_bridgehead,
unsigned int i, valid_connections;
struct GUID_list keep_connections;
- tmp_ctx = talloc_new(ldb);
+ tmp_ctx = talloc_new(service);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
r_site_dn = ldb_dn_copy(tmp_ctx, r_bridgehead->dn);
return NT_STATUS_NO_MEMORY;
}
- ret = dsdb_find_guid_by_dn(ldb, r_site_dn, &r_site_guid);
+ ret = dsdb_find_guid_by_dn(service->samdb, r_site_dn, &r_site_guid);
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to find objectGUID for object "
"%s: %s\n", ldb_dn_get_linearized(r_site_dn),
return NT_STATUS_NO_MEMORY;
}
- ret = dsdb_find_guid_by_dn(ldb, l_site_dn, &l_site_guid);
+ ret = dsdb_find_guid_by_dn(service->samdb, l_site_dn, &l_site_guid);
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to find objectGUID for object "
"%s: %s\n", ldb_dn_get_linearized(l_site_dn),
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- status = kcctpl_get_all_bridgehead_dcs(ldb, tmp_ctx,
+ status = kcctpl_get_all_bridgehead_dcs(service, tmp_ctx,
r_site_guid, cross_ref,
transport, partial_replica_okay,
false, &r_bridgeheads_all);
return status;
}
- status = kcctpl_get_all_bridgehead_dcs(ldb, tmp_ctx,
+ status = kcctpl_get_all_bridgehead_dcs(service->samdb, tmp_ctx,
r_site_guid, cross_ref,
transport, partial_replica_okay,
detect_failed_dcs,
return status;
}
- status = kcctpl_get_all_bridgehead_dcs(ldb, tmp_ctx,
+ status = kcctpl_get_all_bridgehead_dcs(service, tmp_ctx,
l_site_guid, cross_ref,
transport, partial_replica_okay,
false, &l_bridgeheads_all);
return status;
}
- status = kcctpl_get_all_bridgehead_dcs(ldb, tmp_ctx,
+ status = kcctpl_get_all_bridgehead_dcs(service, tmp_ctx,
l_site_guid, cross_ref,
transport, partial_replica_okay,
detect_failed_dcs,
return status;
}
- servers_dn = samdb_sites_dn(ldb, tmp_ctx);
+ servers_dn = samdb_sites_dn(service->samdb, tmp_ctx);
if (!servers_dn) {
DEBUG(1, (__location__ ": failed to find our own Sites DN\n"));
return NT_STATUS_NO_MEMORY;
}
- ret = ldb_search(ldb, tmp_ctx, &res, servers_dn, LDB_SCOPE_SUBTREE,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, servers_dn, LDB_SCOPE_SUBTREE,
attrs, "objectClass=nTDSConnection");
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to find nTDSConnection "
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- from_server = samdb_result_dn(ldb, tmp_ctx, connection,
+ from_server = samdb_result_dn(service->samdb, tmp_ctx, connection,
"fromServer", NULL);
if (!from_server) {
DEBUG(1, (__location__ ": failed to find fromServer "
conn_opts = samdb_result_int64(connection,
"options", 0);
- conn_transport_type = samdb_result_dn(ldb, tmp_ctx,
+ conn_transport_type = samdb_result_dn(service->samdb, tmp_ctx,
connection,
"transportType",
NULL);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- from_server = samdb_result_dn(ldb, tmp_ctx, connection,
+ from_server = samdb_result_dn(service->samdb, tmp_ctx, connection,
"fromServer", NULL);
if (!from_server) {
DEBUG(1, (__location__ ": failed to find fromServer "
conn_opts = samdb_result_int64(connection,
"options", 0);
- conn_transport_type = samdb_result_dn(ldb, tmp_ctx,
+ conn_transport_type = samdb_result_dn(service->samdb, tmp_ctx,
connection,
"transportType",
NULL);
struct GUID r_guid, l_guid, conn_guid;
bool failed_state_r, failed_state_l;
- ret = dsdb_find_guid_by_dn(ldb, from_server,
+ ret = dsdb_find_guid_by_dn(service->samdb, from_server,
&r_guid);
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to "
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- ret = dsdb_find_guid_by_dn(ldb, parent_dn,
+ ret = dsdb_find_guid_by_dn(service->samdb, parent_dn,
&l_guid);
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to "
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- status = kcctpl_bridgehead_dc_failed(ldb,
+ status = kcctpl_bridgehead_dc_failed(service->samdb,
r_guid,
detect_failed_dcs,
&failed_state_r);
return status;
}
- status = kcctpl_bridgehead_dc_failed(ldb,
+ status = kcctpl_bridgehead_dc_failed(service->samdb,
l_guid,
detect_failed_dcs,
&failed_state_l);
* construct an NC replica graph for the NC identified by the given 'cross_ref',
* then create any additional nTDSConnection objects required.
*/
-static NTSTATUS kcctpl_create_connections(struct ldb_context *ldb,
+static NTSTATUS kcctpl_create_connections(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct kcctpl_graph *graph,
struct ldb_message *cross_ref,
connected = true;
- status = kcctpl_color_vertices(ldb, graph, cross_ref, detect_failed_dcs,
+ status = kcctpl_color_vertices(service, graph, cross_ref, detect_failed_dcs,
&found_failed_dcs);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(1, (__location__ ": failed to color vertices: %s\n",
tmp_ctx = talloc_new(mem_ctx);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- site = kcctpl_local_site(ldb, tmp_ctx);
+ site = kcctpl_local_site(service->samdb, tmp_ctx);
if (!site) {
DEBUG(1, (__location__ ": failed to find our own local DC's "
"site\n"));
return NT_STATUS_OK;
}
- status = kcctpl_get_spanning_tree_edges(ldb, tmp_ctx, graph,
+ status = kcctpl_get_spanning_tree_edges(service, tmp_ctx, graph,
&component_count,
&st_edge_list);
if (NT_STATUS_IS_ERR(status)) {
partial_replica_okay = (site_vertex->color == BLACK);
- transports_dn = kcctpl_transports_dn(ldb, tmp_ctx);
+ transports_dn = kcctpl_transports_dn(service->samdb, tmp_ctx);
if (!transports_dn) {
DEBUG(1, (__location__ ": failed to find our own Inter-Site "
"Transports DN\n"));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- ret = ldb_search(ldb, tmp_ctx, &res, transports_dn,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, transports_dn,
LDB_SCOPE_ONELEVEL, attrs,
"(&(objectClass=interSiteTransport)"
"(objectGUID=%s))", GUID_string(tmp_ctx,
}
transport = res->msgs[0];
- status = kcctpl_get_bridgehead_dc(ldb, tmp_ctx,
+ status = kcctpl_get_bridgehead_dc(service, tmp_ctx,
other_site_vertex->id,
cross_ref, transport,
partial_replica_okay,
if (rodc) {
/* TODO: l_bridgehad = nTDSDSA of local DC */
} else {
- status = kcctpl_get_bridgehead_dc(ldb, tmp_ctx,
+ status = kcctpl_get_bridgehead_dc(service, tmp_ctx,
site_vertex->id,
cross_ref, transport,
partial_replica_okay,
schedule[j] = 1;
}
- status = kcctpl_create_connection(ldb, mem_ctx, cross_ref,
+ status = kcctpl_create_connection(service, mem_ctx, cross_ref,
r_bridgehead, transport,
l_bridgehead, edge->repl_info,
schedule, detect_failed_dcs,
* in another site, the KCC creates and nTDSConnection object to imply that edge
* if one does not already exist.
*/
-static NTSTATUS kcctpl_create_intersite_connections(struct ldb_context *ldb,
+static NTSTATUS kcctpl_create_intersite_connections(struct kccsrv_service *service,
TALLOC_CTX *mem_ctx,
struct GUID_list *_keep_connections,
bool *_all_connected)
tmp_ctx = talloc_new(mem_ctx);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- partitions_dn = samdb_partitions_dn(ldb, tmp_ctx);
+ partitions_dn = samdb_partitions_dn(service->samdb, tmp_ctx);
NT_STATUS_HAVE_NO_MEMORY_AND_FREE(partitions_dn, tmp_ctx);
- ret = ldb_search(ldb, tmp_ctx, &res, partitions_dn, LDB_SCOPE_ONELEVEL,
+ ret = ldb_search(service->samdb, tmp_ctx, &res, partitions_dn, LDB_SCOPE_ONELEVEL,
attrs, "objectClass=crossRef");
if (ret != LDB_SUCCESS) {
DEBUG(1, (__location__ ": failed to find crossRef objects: "
continue;
}
- status = kcctpl_setup_graph(ldb, tmp_ctx, &graph);
+ status = kcctpl_setup_graph(service->samdb, tmp_ctx, &graph);
if (NT_STATUS_IS_ERR(status)) {
DEBUG(1, (__location__ ": failed to create a graph: "
"%s\n", nt_errstr(status)));
return status;
}
- status = kcctpl_create_connections(ldb, mem_ctx, graph,
+ status = kcctpl_create_connections(service, mem_ctx, graph,
cross_ref, true,
keep_connections,
&found_failed_dc,
all_connected = false;
if (found_failed_dc) {
- status = kcctpl_create_connections(ldb, mem_ctx,
+ status = kcctpl_create_connections(service, mem_ctx,
graph,
cross_ref,
true,
return NT_STATUS_OK;
}
-NTSTATUS kcctpl_test(struct ldb_context *ldb)
+NTSTATUS kcctpl_test(struct kccsrv_service *service)
{
NTSTATUS status;
- TALLOC_CTX *tmp_ctx = talloc_new(ldb);
+ TALLOC_CTX *tmp_ctx = talloc_new(service);
struct GUID_list keep;
bool all_connected;
DEBUG(0, ("Testing kcctpl_create_intersite_connections\n"));
- status = kcctpl_create_intersite_connections(ldb, tmp_ctx, &keep,
+ status = kcctpl_create_intersite_connections(service, tmp_ctx, &keep,
&all_connected);
DEBUG(4, ("%s\n", nt_errstr(status)));
if (NT_STATUS_IS_OK(status)) {