svn commit: samba r11410 - in branches/SAMBA_4_0/source/libnet: .

abartlet at samba.org abartlet at samba.org
Mon Oct 31 03:44:30 GMT 2005


Author: abartlet
Date: 2005-10-31 03:44:29 +0000 (Mon, 31 Oct 2005)
New Revision: 11410

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

Log:
Fix rejoin as a BDC by modifying, rather than trying to recreate, the
server reference.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/libnet/libnet_join.c


Changeset:
Modified: branches/SAMBA_4_0/source/libnet/libnet_join.c
===================================================================
--- branches/SAMBA_4_0/source/libnet/libnet_join.c	2005-10-31 03:06:13 UTC (rev 11409)
+++ branches/SAMBA_4_0/source/libnet/libnet_join.c	2005-10-31 03:44:29 UTC (rev 11410)
@@ -26,6 +26,7 @@
 #include "librpc/gen_ndr/ndr_lsa.h"
 #include "librpc/gen_ndr/ndr_drsuapi.h"
 #include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
 #include "libcli/cldap/cldap.h"
 #include "include/secrets.h"
 #include "librpc/gen_ndr/drsuapi.h"
@@ -138,10 +139,44 @@
 	}
 
 	msg->dn = server_dn; 
-	msg->elements->flags = LDB_FLAG_MOD_ADD;
 
 	rtn = ldb_add(remote_ldb, msg);
-	if (rtn != 0) {
+	if (rtn == LDB_ERR_ENTRY_ALREADY_EXISTS) {
+		int i;
+		
+		/* make a 'modify' msg, and only for serverReference */
+		msg = ldb_msg_new(tmp_ctx);
+		if (!msg) {
+			libnet_r->out.error_string = NULL;
+			talloc_free(tmp_ctx);
+			return NT_STATUS_NO_MEMORY;
+		}
+		msg->dn = server_dn; 
+
+		rtn = ldb_msg_add_string(msg, "serverReference",libnet_r->out.account_dn_str);
+		if (rtn != 0) {
+			libnet_r->out.error_string = NULL;
+			talloc_free(tmp_ctx);
+			return NT_STATUS_NO_MEMORY;
+		}
+		
+		/* mark all the message elements (should be just one)
+		   as LDB_FLAG_MOD_REPLACE */
+		for (i=0;i<msg->num_elements;i++) {
+			msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
+		}
+
+		rtn = ldb_modify(remote_ldb, msg);
+		if (rtn != 0) {
+			libnet_r->out.error_string
+				= talloc_asprintf(libnet_r,
+						  "Failed to modify server entry %s: %s: %d",
+						  server_dn_str,
+						  ldb_errstring(remote_ldb), rtn);
+			talloc_free(tmp_ctx);
+			return NT_STATUS_INTERNAL_DB_CORRUPTION;
+		}
+	} else if (rtn != 0) {
 		libnet_r->out.error_string
 			= talloc_asprintf(libnet_r,
 				"Failed to add server entry %s: %s: %d",



More information about the samba-cvs mailing list