From d094cf2cb5ffd28195ac42dbe631db43c47762af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= <ondra@mistotebe.net>
Date: Tue, 7 Dec 2021 12:06:15 +0000
Subject: [PATCH] ITS#9759 Honour requested insert position in olcRetcodeItem

---
 servers/slapd/overlays/retcode.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/servers/slapd/overlays/retcode.c b/servers/slapd/overlays/retcode.c
index e0f5b8e04..8b94b4711 100644
--- a/servers/slapd/overlays/retcode.c
+++ b/servers/slapd/overlays/retcode.c
@@ -1237,10 +1237,14 @@ rc_cf_gen( ConfigArgs *c )
 		}
 		*--next = '\0';
 		
-		for ( rdip = &rd->rd_item; *rdip; rdip = &(*rdip)->rdi_next )
-			/* go to last */ ;
+		/* We're marked X-ORDERED 'VALUES', valx might be valid */
+		for ( i = 0, rdip = &rd->rd_item;
+			*rdip && (c->valx < 0 || i < c->valx);
+			rdip = &(*rdip)->rdi_next, i++ )
+			/* go to position */ ;
 
 		
+		rdi.rdi_next = *rdip;
 		*rdip = ( retcode_item_t * )ch_malloc( sizeof( retcode_item_t ) );
 		*(*rdip) = rdi;
 
-- 
2.33.0

