From f996252b2c095ccd2e477eb7d930f8a1f04ae238 Mon Sep 17 00:00:00 2001
From: Kurt Zeilenga <kurt@openldap.org>
Date: Tue, 9 Oct 2001 21:12:17 +0000
Subject: [PATCH] Add better root dse error reporting

---
 servers/slapd/add.c    | 12 +++++++++++-
 servers/slapd/delete.c | 10 ++++++++++
 servers/slapd/modify.c | 10 ++++++++++
 servers/slapd/modrdn.c |  9 +++++++++
 servers/slapd/result.c |  3 +++
 5 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/servers/slapd/add.c b/servers/slapd/add.c
index 190070feeb..8f3b3082ff 100644
--- a/servers/slapd/add.c
+++ b/servers/slapd/add.c
@@ -146,8 +146,18 @@ do_add( Connection *conn, Operation *op )
 	if( e->e_ndn == NULL || *e->e_ndn == '\0' ) {
 		/* protocolError may be a more appropriate error */
 		send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
-			NULL, "root DSE exists", NULL, NULL );
+			NULL, "root DSE already exists",
+			NULL, NULL );
 		goto done;
+
+#if defined( SLAPD_SCHEMA_DN )
+	} else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+		/* protocolError may be a more appropriate error */
+		send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS,
+			NULL, "subschema subentry already exists",
+			NULL, NULL );
+		goto done;
+#endif
 	}
 
 	manageDSAit = get_manageDSAit( op );
diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c
index 4b6caecdfc..3696769962 100644
--- a/servers/slapd/delete.c
+++ b/servers/slapd/delete.c
@@ -72,6 +72,16 @@ do_delete(
 		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
 			NULL, "cannot delete the root DSE", NULL, NULL );
 		goto cleanup;
+
+#ifdef SLAPD_SCHEMA_DN
+	} else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+		Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
+		/* protocolError would likely be a more appropriate error */
+		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
+			NULL, "cannot delete the root DSE", NULL, NULL );
+		goto cleanup;
+
+#endif
 	}
 
 	Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c
index f2b31234b5..8c4957543c 100644
--- a/servers/slapd/modify.c
+++ b/servers/slapd/modify.c
@@ -158,6 +158,16 @@ do_modify(
 		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
 			NULL, "modify upon the root DSE not supported", NULL, NULL );
 		goto cleanup;
+
+#if defined( SLAPD_SCHEMA_DN )
+	} else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+		Debug( LDAP_DEBUG_ANY, "do_modify: subschema subentry!\n", 0, 0, 0 );
+
+		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
+			NULL, "modification of subschema subentry not supported",
+			NULL, NULL );
+		goto cleanup;
+#endif
 	}
 
 #ifdef LDAP_DEBUG
diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c
index c4fffbbf84..fc8d3964eb 100644
--- a/servers/slapd/modrdn.c
+++ b/servers/slapd/modrdn.c
@@ -156,6 +156,15 @@ do_modrdn(
 		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
 			NULL, "cannot rename the root DSE", NULL, NULL );
 		goto cleanup;
+
+#ifdef SLAPD_SCHEMA_DN
+	} else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
+		Debug( LDAP_DEBUG_ANY, "do_modrdn: subschema subentry!\n", 0, 0, 0 );
+
+		send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
+			NULL, "cannot rename subschema subentry", NULL, NULL );
+		goto cleanup;
+#endif
 	}
 
 	Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
diff --git a/servers/slapd/result.c b/servers/slapd/result.c
index 2164ec08d6..64f04464f0 100644
--- a/servers/slapd/result.c
+++ b/servers/slapd/result.c
@@ -730,6 +730,7 @@ send_search_entry(
 			ber_free( ber, 1 );
 			send_ldap_result( conn, op, LDAP_OTHER,
 			    NULL, "encoding description error", NULL, NULL );
+			attrs_free( aa );
 			goto error_return;
 		}
 
@@ -751,6 +752,7 @@ send_search_entry(
 					ber_free( ber, 1 );
 					send_ldap_result( conn, op, LDAP_OTHER,
 						NULL, "encoding values error", NULL, NULL );
+					attrs_free( aa );
 					goto error_return;
 				}
 			}
@@ -761,6 +763,7 @@ send_search_entry(
 			ber_free( ber, 1 );
 			send_ldap_result( conn, op, LDAP_OTHER,
 			    NULL, "encode end error", NULL, NULL );
+			attrs_free( aa );
 			goto error_return;
 		}
 	}
-- 
GitLab