svn commit: samba r26648 - in branches/SAMBA_4_0/source: dsdb/common ldap_server

abartlet at samba.org abartlet at samba.org
Thu Jan 3 04:40:25 GMT 2008


Author: abartlet
Date: 2008-01-03 04:40:24 +0000 (Thu, 03 Jan 2008)
New Revision: 26648

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26648

Log:
Move detection of global catalog captability to a central function, so
this can be shared with the CLDAP server (for the netlogon reply).

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/dsdb/common/util.c
   branches/SAMBA_4_0/source/ldap_server/ldap_server.c


Changeset:
Modified: branches/SAMBA_4_0/source/dsdb/common/util.c
===================================================================
--- branches/SAMBA_4_0/source/dsdb/common/util.c	2008-01-03 03:31:14 UTC (rev 26647)
+++ branches/SAMBA_4_0/source/dsdb/common/util.c	2008-01-03 04:40:24 UTC (rev 26648)
@@ -1367,7 +1367,43 @@
 	return false;
 }
 
+/*
+  work out if we are a Global Catalog server for the domain of the current open ldb
+*/
+bool samdb_is_gc(struct ldb_context *ldb)
+{
+	const char *attrs[] = { "options", NULL };
+	int ret, options;
+	struct ldb_result *res;
+	TALLOC_CTX *tmp_ctx;
 
+	tmp_ctx = talloc_new(ldb);
+	if (tmp_ctx == NULL) {
+		DEBUG(1, ("talloc_new failed in samdb_is_pdc"));
+		return false;
+	}
+
+	/* Query cn=ntds settings,.... */
+	ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res);
+	if (ret) {
+		return false;
+	}
+	if (res->count != 1) {
+		talloc_free(res);
+		return false;
+	}
+
+	options = ldb_msg_find_attr_as_int(res->msgs[0], "options", 0);
+	talloc_free(res);
+	talloc_free(ldb);
+
+	/* if options attribute has the 0x00000001 flag set, then enable the global catlog */
+	if (options & 0x000000001) {
+		return true;
+	}
+	return false;
+}
+
 /* Find a domain object in the parents of a particular DN.  */
 int samdb_search_for_parent_domain(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_dn *dn,
 				   struct ldb_dn **parent_dn, const char **errstring)

Modified: branches/SAMBA_4_0/source/ldap_server/ldap_server.c
===================================================================
--- branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2008-01-03 03:31:14 UTC (rev 26647)
+++ branches/SAMBA_4_0/source/ldap_server/ldap_server.c	2008-01-03 04:40:24 UTC (rev 26648)
@@ -447,11 +447,7 @@
 {
 	uint16_t port = 389;
 	NTSTATUS status;
-	const char *attrs[] = { "options", NULL };
-	int ret;
-	struct ldb_result *res;
 	struct ldb_context *ldb;
-	int options;
 
 	status = stream_setup_socket(event_context, model_ops, &ldap_stream_ops, 
 				     "ipv4", address, &port, 
@@ -481,22 +477,7 @@
 		return NT_STATUS_INTERNAL_DB_CORRUPTION;
 	}
 	
-	/* Query cn=ntds settings,.... */
-	ret = ldb_search(ldb, samdb_ntds_settings_dn(ldb), LDB_SCOPE_BASE, NULL, attrs, &res);
-	if (ret) {
-		return NT_STATUS_INTERNAL_DB_CORRUPTION;
-	}
-	if (res->count != 1) {
-		talloc_free(res);
-		return NT_STATUS_NOT_FOUND;
-	}
-
-	options = ldb_msg_find_attr_as_int(res->msgs[0], "options", 0);
-	talloc_free(res);
-	talloc_free(ldb);
-
-	/* if options attribute has the 0x00000001 flag set, then enable the global catlog */
-	if (options & 0x000000001) {
+	if (samdb_is_gc(ldb)) {
 		port = 3268;
 		status = stream_setup_socket(event_context, model_ops, &ldap_stream_ops, 
 					     "ipv4", address, &port, 



More information about the samba-cvs mailing list